remove some javadoc
[cdmlib.git] / cdmlib-io / src / main / java / eu / etaxonomy / cdm / io / common / DbImportStateBase.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
9 */
10
11 package eu.etaxonomy.cdm.io.common;
12
13 import java.util.HashMap;
14 import java.util.Map;
15
16 import org.apache.log4j.Logger;
17
18 import eu.etaxonomy.cdm.api.service.IReferenceService;
19 import eu.etaxonomy.cdm.model.common.CdmBase;
20 import eu.etaxonomy.cdm.model.common.User;
21 import eu.etaxonomy.cdm.model.reference.Reference;
22
23 /**
24 * @author a.mueller
25 * @created 11.05.2009
26 * @version 1.0
27 */
28 public abstract class DbImportStateBase<CONFIG extends DbImportConfiguratorBase, STATE extends DbImportStateBase> extends ImportStateBase<CONFIG, CdmImportBase> implements IPartitionedState {
29 @SuppressWarnings("unused")
30 private static final Logger logger = Logger.getLogger(DbImportStateBase.class);
31
32 public static final String CURRENT_OBJECT_NAMESPACE = "CurrentObjectNamespace";
33 public static final String CURRENT_OBJECT_ID = "CurrentObjectId";
34
35 private Map<String, User> usernameMap = new HashMap<String, User>();
36
37
38 private Reference<?> partitionSourceReference;
39
40 private RelatedObjectsHelper relatedObjectsHelper = new RelatedObjectsHelper();;
41 //holds the classifications needed for this partition, the key is a value that differentiate classifications
42 //like the taxons reference (secundum)
43
44
45 /**
46 * @param config
47 */
48 protected DbImportStateBase(CONFIG config) {
49 super(config);
50 }
51
52 /* (non-Javadoc)
53 * @see eu.etaxonomy.cdm.io.common.IPartitionedState#addRelatedObject(java.lang.Object, java.lang.String, eu.etaxonomy.cdm.model.common.CdmBase)
54 */
55 public void addRelatedObject(Object namespace, String id, CdmBase relatedObject) {
56 this.relatedObjectsHelper.addRelatedObjet(namespace, id, relatedObject);
57 }
58
59
60 /* (non-Javadoc)
61 * @see eu.etaxonomy.cdm.io.common.IPartitionedState#getRelatedObject(java.lang.Object, java.lang.String)
62 */
63 public CdmBase getRelatedObject(Object namespace, String id) {
64 return relatedObjectsHelper.getRelatedObject(namespace, id);
65 }
66
67 /* (non-Javadoc)
68 * @see eu.etaxonomy.cdm.io.common.IPartitionedState#getRelatedObject(java.lang.Object, java.lang.String)
69 */
70 public<T extends CdmBase> T getRelatedObject(Object namespace, String id, Class<T> clazz) {
71 CdmBase cdmBase = relatedObjectsHelper.getRelatedObject(namespace, id);
72 T result = CdmBase.deproxy(cdmBase, clazz);
73 return result;
74 }
75
76 /* (non-Javadoc)
77 * @see eu.etaxonomy.cdm.io.common.IPartitionedState#setRelatedObjects(java.util.Map)
78 */
79 public void setRelatedObjects(Map<Object, Map<String, CdmBase>> relatedObjects) {
80 relatedObjectsHelper.setRelatedObjects(relatedObjects);
81 }
82
83
84 /**
85 * Stores the source reference for the time of a transaction. Needs to be
86 * deleted manually after transaction finishes to avoid memory leaks.
87 * @return
88 */
89 public Reference getTransactionalSourceReference() {
90 return partitionSourceReference;
91 }
92
93
94 public void resetTransactionalSourceReference(){
95 this.partitionSourceReference = null;
96 }
97
98 public void makeTransactionalSourceReference(IReferenceService service){
99 //TODO handle undefined sourceRefUuid
100 this.partitionSourceReference = service.find(this.getConfig().getSourceRefUuid());
101 if (this.partitionSourceReference == null){
102 this.partitionSourceReference = this.getConfig().getSourceReference();
103 service.saveOrUpdate(this.partitionSourceReference);
104 }
105 }
106
107 public User getUser(String username){
108 return usernameMap.get(username);
109 }
110
111 public void putUser(String username, User user){
112 usernameMap.put(username, user);
113 }
114
115
116 }