Project

General

Profile

Revision 32eec7cd

ID32eec7cdeee34bbe5eac71e54952bd9f37696fa5
Parent c3be000f
Child a077e729

Added by Andreas Müller about 3 years ago

cleanup

View differences:

cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/common/CdmIoBase.java
303 303
        fire(event);
304 304
    }
305 305

  
306
    protected boolean isBlank(String str){
306
    protected static boolean isBlank(String str){
307 307
        return StringUtils.isBlank(str);
308 308
    }
309 309

  
310
    protected boolean isNotBlank(String str){
310
    protected static boolean isNotBlank(String str){
311 311
        return StringUtils.isNotBlank(str);
312 312
    }
313 313

  
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/common/mapping/DbSingleAttributeImportMapperBase.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
*/
......
29 29
 */
30 30
public abstract class DbSingleAttributeImportMapperBase<STATE extends DbImportStateBase<?,?>, CDM_BASE extends CdmBase> extends CdmSingleAttributeMapperBase implements IDbImportMapper<STATE, CDM_BASE>  {
31 31
	private static final Logger logger = Logger.getLogger(DbSingleAttributeImportMapperBase.class);
32
	
32

  
33 33
	protected DbImportMapperBase<STATE> importMapperHelper = new DbImportMapperBase<STATE>();
34 34
//	private Integer precision = null;
35 35
	protected boolean obligatory = true;
......
37 37

  
38 38
	protected Method destinationMethod = null;
39 39
	protected Class<?> targetClass;
40
	
40

  
41 41
	/**
42 42
	 * @param dbAttributString
43 43
	 * @param cdmAttributeString
......
45 45
	protected DbSingleAttributeImportMapperBase(String dbAttributString, String cdmAttributeString) {
46 46
		super(dbAttributString, cdmAttributeString);
47 47
	}
48
	
49
	
48

  
49

  
50 50
	/**
51 51
	 * @param dbAttributString
52 52
	 * @param cdmAttributeString
......
54 54
	protected DbSingleAttributeImportMapperBase(String dbAttributString, String cdmAttributeString, Object defaultValue) {
55 55
		super(dbAttributString, cdmAttributeString, defaultValue);
56 56
	}
57
	
57

  
58 58
	/**
59 59
	 * @param dbAttributString
60 60
	 * @param cdmAttributeString
......
63 63
		super(dbAttributeString, cdmAttributeString, defaultValue);
64 64
		this.obligatory = obligatory;
65 65
	}
66
	
67
	/* (non-Javadoc)
68
	 * @see eu.etaxonomy.cdm.io.common.mapping.IDbImportMapper#initialize(eu.etaxonomy.cdm.io.common.DbImportStateBase, java.lang.String)
69
	 */
70
	public void initialize(STATE state, Class<? extends CdmBase> destinationClass) {
66

  
67

  
68
	@Override
69
    public void initialize(STATE state, Class<? extends CdmBase> destinationClass) {
71 70
		importMapperHelper.initialize(state, destinationClass);
72 71
		try {
73 72
			targetClass = getTargetClass(destinationClass);
......
85 84
	/**
86 85
	 * @param destinationClass
87 86
	 * @return
88
		 * @throws NoSuchMethodException 
89
		 * @throws SecurityException 
90
		 * @throws NoSuchMethodException 
87
		 * @throws NoSuchMethodException
88
		 * @throws SecurityException
89
		 * @throws NoSuchMethodException
91 90
	 */
92 91
	protected Class getTargetClass(Class<?> destinationClass) throws SecurityException, NoSuchMethodException{
93 92
		Class result = destinationClass;
......
96 95
			return null;
97 96
		}
98 97
		String[] splits = destinationAttribute.split("\\.");
99
		//for all prefixes 
98
		//for all prefixes
100 99
		for (int i = 0; i < splits.length - 1; i++){
101 100
			String split = splits[i];
102 101
			String castedResultClass = getCastedResultClass(split);
......
118 117
				} catch (ClassNotFoundException e) {
119 118
					e.printStackTrace();
120 119
					//result = null;
121
				} 
120
				}
122 121
			}
123 122
		}
124 123
		return result;
......
157 156

  
158 157

  
159 158
	/**
160
	 * @param clazz 
159
	 * @param clazz
161 160
	 * @return
162 161
	 */
163 162
	private String getMethodName(Class clazz) {
......
184 183
	/* (non-Javadoc)
185 184
	 * @see eu.etaxonomy.cdm.io.berlinModel.out.mapper.IDbExportMapper#invoke(eu.etaxonomy.cdm.model.common.CdmBase)
186 185
	 */
187
	public CDM_BASE invoke(ResultSet rs, CDM_BASE cdmBase) throws SQLException {
186
	@Override
187
    public CDM_BASE invoke(ResultSet rs, CDM_BASE cdmBase) throws SQLException {
188 188
		if (ignore){
189 189
			return cdmBase;
190 190
		}
191 191
		Object dbValue = getValue(rs);
192
		
192

  
193 193
//		String dbValue = rs.getString(getSourceAttribute());
194 194
		return doInvoke(cdmBase, dbValue);
195 195
	}
196
	
196

  
197 197
	protected CDM_BASE doInvoke(CDM_BASE cdmBase, Object value) throws SQLException {
198 198
		Method method = getMethod();
199 199
		try {
......
217 217
		}
218 218
		throw new RuntimeException("Problems when invoking target method");
219 219
	}
220
	
220

  
221 221
	/**
222 222
	 * @param cdmBase
223 223
	 * @return
224
	 * @throws NoSuchMethodException 
225
	 * @throws SecurityException 
226
	 * @throws InvocationTargetException 
227
	 * @throws IllegalAccessException 
228
	 * @throws IllegalArgumentException 
224
	 * @throws NoSuchMethodException
225
	 * @throws SecurityException
226
	 * @throws InvocationTargetException
227
	 * @throws IllegalAccessException
228
	 * @throws IllegalArgumentException
229 229
	 */
230 230
	private Object getObjectToInvoke(CDM_BASE cdmBase) throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
231 231
		Object objectToInvoke = cdmBase;
......
257 257
	protected Object getValue(ResultSet rs) throws SQLException{
258 258
		return getDbValue(rs);
259 259
	}
260
	
260

  
261 261
	/**
262 262
	 * Returns the database value for the attribute
263 263
	 * @param rs
......
270 270
		return value;
271 271
	}
272 272

  
273
	
273

  
274 274
//	/**
275 275
//	 * @return the index
276 276
//	 */
277 277
//	public int getIndex() {
278 278
//		return exportMapperHelper.getIndex();
279 279
//	}
280
	
280

  
281 281
	/**
282 282
	 * @return the state
283 283
	 */
284 284
	protected STATE getState() {
285 285
		return importMapperHelper.getState();
286 286
	}
287
	
288
	
287

  
288

  
289 289
	/**
290 290
	 * @return the state
291 291
	 */
292 292
	protected String getTableName() {
293 293
		return importMapperHelper.getTableName();
294 294
	}
295
	
295

  
296 296
	protected boolean checkDbColumnExists() throws DatabaseTypeNotSupportedException{
297 297
//		//TODO remove cast
298 298
//		Source source = (Source)getState().getConfig().getSource();
......
302 302
		//TODO not possible as long as tableName is not initialized
303 303
		return true;
304 304
	}
305
	
305

  
306 306
//	protected int getPrecision(){
307 307
//		return this.precision;
308 308
//	}
309
	
309

  
310 310
	protected int getDbColumnIntegerInfo(String selectPart){
311 311
		//TODO remove cast
312
		Source source = (Source)getState().getConfig().getSource();
312
		Source source = getState().getConfig().getSource();
313 313
		String strQuery = "SELECT  " + selectPart + " as result" +
314 314
				" FROM sysobjects AS t " +
315 315
				" INNER JOIN syscolumns AS c ON t.id = c.id " +
316
				" WHERE (t.xtype = 'U') AND " + 
317
				" (t.name = '" + getTableName() + "') AND " + 
316
				" WHERE (t.xtype = 'U') AND " +
317
				" (t.name = '" + getTableName() + "') AND " +
318 318
				" (c.name = '" + getSourceAttribute() + "')";
319
		ResultSet rs = source.getResultSet(strQuery) ;		
319
		ResultSet rs = source.getResultSet(strQuery) ;
320 320
		int n;
321 321
		try {
322 322
			rs.next();
......
326 326
			e.printStackTrace();
327 327
			return -1;
328 328
		}
329
			
329

  
330 330
	}
331
	
331

  
332 332

  
333 333
	/**
334 334
	 * @param rs
......
345 345
//		String destAtt = CdmUtils.Nz(getDestinationAttribute());
346 346
//		return this.getClass().getSimpleName() +"[" + sourceAtt + "->" + destAtt + "]";
347 347
//	}
348
	
348

  
349 349
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)