Project

General

Profile

« Previous | Next » 

Revision 8422c0cd

Added by Andreas Müller almost 8 years ago

Remove generics from Reference in cdmlib-app #5830

View differences:

app-import/src/main/java/eu/etaxonomy/cdm/io/berlinModel/in/BerlinModelOccurrenceSourceImport.java
1 1
/**
2 2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy 
3
* European Distributed Institute of Taxonomy
4 4
* http://www.e-taxonomy.eu
5
* 
5
*
6 6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7 7
* See LICENSE.TXT at the top of this package for the full license terms.
8 8
*/
......
47 47
	private static int modCount = 5000;
48 48
	private static final String pluralString = "occurrence sources";
49 49
	private static final String dbTableName = "emOccurrenceSource";  //??
50
	
51
	
50

  
51

  
52 52
	private Map<String, Integer> sourceNumberRefIdMap;
53 53
	private Set<String> unfoundReferences = new HashSet<String>();
54
	
54

  
55 55

  
56 56
	public BerlinModelOccurrenceSourceImport(){
57 57
		super(dbTableName, pluralString);
58 58
	}
59
	
59

  
60 60
	@Override
61 61
	protected String getIdQuery(BerlinModelImportState state) {
62 62
		String result = "SELECT occurrenceSourceId FROM " + getTableName();
......
68 68

  
69 69
	@Override
70 70
	protected String getRecordQuery(BerlinModelImportConfigurator config) {
71
			String strQuery =   //DISTINCT because otherwise emOccurrenceSource creates multiple records for a single distribution 
72
            " SELECT * " + 
73
                " FROM emOccurrenceSource " +  
74
            " WHERE (OccurrenceSourceId IN (" + ID_LIST_TOKEN + ")  )" +  
71
			String strQuery =   //DISTINCT because otherwise emOccurrenceSource creates multiple records for a single distribution
72
            " SELECT * " +
73
                " FROM emOccurrenceSource " +
74
            " WHERE (OccurrenceSourceId IN (" + ID_LIST_TOKEN + ")  )" +
75 75
             "";
76 76
		return strQuery;
77 77
	}
78
	
79
	
78

  
79

  
80 80

  
81 81
	@Override
82 82
	protected void doInvoke(BerlinModelImportState state) {
83 83
		unfoundReferences = new HashSet<String>();
84
		
84

  
85 85
		try {
86 86
			sourceNumberRefIdMap = makeSourceNumberReferenceIdMap(state);
87 87
		} catch (SQLException e) {
......
91 91
		super.doInvoke(state);
92 92
		sourceNumberRefIdMap = null;
93 93
		if (unfoundReferences.size()>0){
94
			String unfound = "'" + CdmUtils.concat("','", unfoundReferences.toArray(new String[]{})) + "'"; 
94
			String unfound = "'" + CdmUtils.concat("','", unfoundReferences.toArray(new String[]{})) + "'";
95 95
			logger.warn("Not found references: " + unfound);
96 96
		}
97 97
		return;
......
102 102
		boolean success = true;
103 103
		ResultSet rs = partitioner.getResultSet();
104 104
		Map<String, Reference> refMap = partitioner.getObjectMap(BerlinModelReferenceImport.REFERENCE_NAMESPACE);
105
		
105

  
106 106
		Set<DescriptionElementBase> objectsToSave = new HashSet<DescriptionElementBase>();
107 107
		try {
108 108
			int i = 0;
109 109
			//for each reference
110 110
            while (rs.next()){
111
                
111

  
112 112
                if ((i++ % modCount) == 0 && i!= 1 ){ logger.info("occurrence sources handled: " + (i-1));}
113
                
113

  
114 114
                Integer occurrenceSourceId = rs.getInt("OccurrenceSourceId");
115 115
                Integer occurrenceFk =nullSafeInt(rs, "OccurrenceFk");
116 116
    			String sourceNumber = rs.getString("SourceNumber");
117 117
    			String oldName = rs.getString("OldName");
118 118
    			Integer oldNameFk = nullSafeInt(rs, "OldNameFk");
119
    			
119

  
120 120
    			Distribution distribution = (Distribution)state.getRelatedObject(BerlinModelOccurrenceImport.NAMESPACE, String.valueOf(occurrenceFk));
121
                
121

  
122 122
    			if (distribution == null){
123 123
    				//distribution = duplicateMap.get(occurrenceFk);
124 124
    			}
125 125
    			if (distribution != null){
126 126
    				Integer refId = sourceNumberRefIdMap.get(sourceNumber);
127
    				Reference<?> ref = refMap.get(String.valueOf(refId));
127
    				Reference ref = refMap.get(String.valueOf(refId));
128 128

  
129 129
    				if (ref != null){
130 130
    					DescriptionElementSource originalSource = DescriptionElementSource.NewInstance(OriginalSourceType.PrimaryTaxonomicSource);
......
144 144
    			}else{
145 145
    				logger.warn("distribution ("+occurrenceFk+") for occurrence source (" + occurrenceSourceId + ") could not be found." );
146 146
    			}
147
                
147

  
148 148
            }
149 149
			logger.info("Distributions to save: " + objectsToSave.size());
150
			getDescriptionService().saveDescriptionElement(objectsToSave);	
151
			
150
			getDescriptionService().saveDescriptionElement(objectsToSave);
151

  
152 152
			return success;
153 153
		} catch (SQLException e) {
154 154
			logger.error("SQLException:" +  e);
......
163 163
		Class<?> cdmClass;
164 164
		Set<String> idSet;
165 165
		Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<Object, Map<String, ? extends CdmBase>>();
166
		
166

  
167 167
		try{
168 168
			Set<String> occurrenceIdSet = new HashSet<String>();
169 169
			Set<String> referenceIdSet = new HashSet<String>();
......
174 174
				handleForeignKey(rs, nameIdSet, "oldNameFk");
175 175
				sourceNumberSet.add(CdmUtils.NzTrim(rs.getString("SourceNumber")));
176 176
			}
177
			
177

  
178 178
			sourceNumberSet.remove("");
179 179
			referenceIdSet = handleSourceNumber(rs, sourceNumberSet, result);
180
			
181
			
180

  
181

  
182 182
			//occurrence map
183 183
			nameSpace = BerlinModelOccurrenceImport.NAMESPACE;
184 184
			cdmClass = Distribution.class;
......
192 192
			idSet =nameIdSet;
193 193
			Map<String, TaxonNameBase> nameMap = (Map<String, TaxonNameBase>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
194 194
			result.put(nameSpace, nameMap);
195
			
195

  
196 196
			//reference map
197 197
			nameSpace = BerlinModelReferenceImport.REFERENCE_NAMESPACE;
198 198
			cdmClass = Reference.class;
......
209 209
	private Set<String> handleSourceNumber(ResultSet rs, Set<String> sourceNumberSet, Map<Object, Map<String, ? extends CdmBase>> result) {
210 210
		Map<String, Integer> sourceNumberReferenceIdMap = this.sourceNumberRefIdMap;
211 211
		Set<String> referenceIdSet = new HashSet<String>();
212
		
212

  
213 213
		for(String sourceNumber : sourceNumberSet){
214 214
			Integer refId = sourceNumberReferenceIdMap.get(sourceNumber);
215
			referenceIdSet.add(String.valueOf(refId));		
215
			referenceIdSet.add(String.valueOf(refId));
216 216
		}
217 217
		return referenceIdSet;
218 218
	}
219 219

  
220
	
221
	
220

  
221

  
222 222
	/**
223 223
	 * @param state
224 224
	 * @param oldName
......
252 252
	 * Creates a map which maps source numbers on references
253 253
	 * @param state
254 254
	 * @return
255
     * @throws SQLException 
255
     * @throws SQLException
256 256
	 */
257 257
	private Map<String, Integer> makeSourceNumberReferenceIdMap(BerlinModelImportState state) throws SQLException {
258 258
		Map<String, Integer> result = new HashMap<String, Integer>();
259
		
259

  
260 260
		Source source = state.getConfig().getSource();
261
		String strQuery = " SELECT RefId, IdInSource " +  
262
						  " FROM Reference " + 
261
		String strQuery = " SELECT RefId, IdInSource " +
262
						  " FROM Reference " +
263 263
						  " WHERE     (IdInSource IS NOT NULL) AND (IdInSource NOT LIKE '') ";
264
		
264

  
265 265
		ResultSet rs = source.getResultSet(strQuery) ;
266 266
		while (rs.next()){
267 267
			int refId = rs.getInt("RefId");
......
296 296
			}
297 297
		}
298 298
	}
299
	
299

  
300 300
}

Also available in: Unified diff