Mercurial > dive4elements > framework
comparison artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java @ 41:5e4bc24ea438
Made serilization more flexible. DB update required!!!
Fixed problem with touching artifacts in database.
artifacts/trunk@119 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 23 Sep 2009 16:55:12 +0000 |
parents | f7d2cd59a0d5 |
children | 4ae4dc99127d |
comparison
equal
deleted
inserted
replaced
40:af22d4de275c | 41:5e4bc24ea438 |
---|---|
22 | 22 |
23 /** | 23 /** |
24 * @author Sascha L. Teichmann | 24 * @author Sascha L. Teichmann |
25 */ | 25 */ |
26 public class ArtifactDatabaseImpl | 26 public class ArtifactDatabaseImpl |
27 implements ArtifactDatabase, Id.Filter | 27 implements ArtifactDatabase, Id.Filter, Backend.FactoryLookup |
28 { | 28 { |
29 private static Logger logger = | 29 private static Logger logger = |
30 Logger.getLogger(ArtifactDatabaseImpl.class); | 30 Logger.getLogger(ArtifactDatabaseImpl.class); |
31 | 31 |
32 public static final String NO_SUCH_FACTORY = | 32 public static final String NO_SUCH_FACTORY = |
137 protected HashSet backgroundIds; | 137 protected HashSet backgroundIds; |
138 | 138 |
139 public ArtifactDatabaseImpl() { | 139 public ArtifactDatabaseImpl() { |
140 } | 140 } |
141 | 141 |
142 public ArtifactDatabaseImpl(FactoryBootstrap bootstrap) { | |
143 this(bootstrap, null); | |
144 } | |
145 | |
142 public ArtifactDatabaseImpl(FactoryBootstrap bootstrap, Backend backend) { | 146 public ArtifactDatabaseImpl(FactoryBootstrap bootstrap, Backend backend) { |
143 | 147 |
144 backgroundIds = new HashSet(); | 148 backgroundIds = new HashSet(); |
145 name2factory = new HashMap(); | 149 name2factory = new HashMap(); |
146 | 150 |
160 name2factory.put(name, factory); | 164 name2factory.put(name, factory); |
161 } | 165 } |
162 | 166 |
163 context = bootstrap.getContext(); | 167 context = bootstrap.getContext(); |
164 | 168 |
165 this.backend = backend; | 169 wireWithBackend(backend); |
170 } | |
171 | |
172 public void wireWithBackend(Backend backend) { | |
173 if (backend != null) { | |
174 this.backend = backend; | |
175 backend.setFactoryLookup(this); | |
176 } | |
166 } | 177 } |
167 | 178 |
168 protected void fromBackground(PersistentArtifact artifact, int action) { | 179 protected void fromBackground(PersistentArtifact artifact, int action) { |
169 logger.warn("BACKGROUND processing is not fully implemented, yet!"); | 180 logger.warn("BACKGROUND processing is not fully implemented, yet!"); |
170 switch (action) { | 181 switch (action) { |
210 | 221 |
211 public String [][] artifactFactoryNamesAndDescriptions() { | 222 public String [][] artifactFactoryNamesAndDescriptions() { |
212 return factoryNamesAndDescription; | 223 return factoryNamesAndDescription; |
213 } | 224 } |
214 | 225 |
226 public ArtifactFactory getArtifactFactory(String factoryName) { | |
227 return (ArtifactFactory)name2factory.get(factoryName); | |
228 } | |
229 | |
215 public Document createArtifactWithFactory(String factoryName) | 230 public Document createArtifactWithFactory(String factoryName) |
216 throws ArtifactDatabaseException | 231 throws ArtifactDatabaseException |
217 { | 232 { |
218 ArtifactFactory factory = (ArtifactFactory)name2factory.get( | 233 ArtifactFactory factory = getArtifactFactory(factoryName); |
219 factoryName); | |
220 | 234 |
221 if (factory == null) { | 235 if (factory == null) { |
222 throw new ArtifactDatabaseException(NO_SUCH_FACTORY); | 236 throw new ArtifactDatabaseException(NO_SUCH_FACTORY); |
223 } | 237 } |
224 | 238 |
233 PersistentArtifact persistentArtifact; | 247 PersistentArtifact persistentArtifact; |
234 | 248 |
235 try { | 249 try { |
236 persistentArtifact = backend.storeInitially( | 250 persistentArtifact = backend.storeInitially( |
237 artifact, | 251 artifact, |
252 factory, | |
238 factory.timeToLiveUntouched(artifact, context)); | 253 factory.timeToLiveUntouched(artifact, context)); |
239 } | 254 } |
240 catch (Exception e) { | 255 catch (Exception e) { |
241 logger.error(e.getLocalizedMessage(), e); | 256 logger.error(e.getLocalizedMessage(), e); |
242 throw new ArtifactDatabaseException(CREATION_FAILED); | 257 throw new ArtifactDatabaseException(CREATION_FAILED); |