4 package eu
.etaxonomy
.cdm
.io
.berlinModel
;
6 import java
.lang
.reflect
.InvocationTargetException
;
7 import java
.lang
.reflect
.Method
;
8 import java
.sql
.ResultSet
;
9 import java
.sql
.SQLException
;
11 import org
.apache
.log4j
.Logger
;
13 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
14 import eu
.etaxonomy
.cdm
.model
.name
.BotanicalName
;
19 public class ImportHelper
{
20 private static final Logger logger
= Logger
.getLogger(ImportHelper
.class);
23 public static boolean addStringValue(ResultSet rs
, CdmBase cdmBase
, String dbAttrName
, String cdmAttrName
){
24 return addValue(rs
, cdmBase
, dbAttrName
, cdmAttrName
, String
.class);
28 public static boolean addBooleanValue(ResultSet rs
, CdmBase cdmBase
, String dbAttrName
, String cdmAttrName
){
29 return addValue(rs
, cdmBase
, dbAttrName
, cdmAttrName
, boolean.class);
32 public static boolean addValue(ResultSet rs
, CdmBase cdmBase
, String dbAttrName
, String cdmAttrName
, Class clazz
){
35 Object strValue
= rs
.getObject(dbAttrName
);
36 if (logger
.isDebugEnabled()) { logger
.debug("addValue: " + strValue
);}
37 if (clazz
== boolean.class || clazz
== Boolean
.class){
38 if (cdmAttrName
== null || cdmAttrName
.length() < 1 ){
39 throw new IllegalArgumentException("boolean CdmAttributeName should have atleast 3 characters");
41 methodName
= "set" + cdmAttrName
.substring(2, 3).toUpperCase() + cdmAttrName
.substring(3) ;
42 }else if(clazz
== String
.class) {
43 if (cdmAttrName
== null || cdmAttrName
.length() < 1 ){
44 throw new IllegalArgumentException("CdmAttributeName should have atleast 1 character");
46 methodName
= "set" + cdmAttrName
.substring(0, 1).toUpperCase() + cdmAttrName
.substring(1) ;
48 logger
.error("Class not supported: " + clazz
.toString());
51 Method cdmMethod
= cdmBase
.getClass().getMethod(methodName
, clazz
);
52 cdmMethod
.invoke(cdmBase
, strValue
);
54 } catch (IllegalArgumentException e
) {
55 logger
.error("IllegalArgumentException: " + e
.getMessage());
57 } catch (IllegalAccessException e
) {
58 logger
.error("IllegalAccessException: " + e
.getMessage());
60 } catch (InvocationTargetException e
) {
61 logger
.error("InvocationTargetException: " + e
.getMessage());
63 }catch (SecurityException e
) {
64 logger
.error("SecurityException: " + e
.getMessage());
66 } catch (NoSuchMethodException e
) {
67 logger
.error("NoSuchMethod: " + e
.getMessage());
69 }catch (SQLException e
) {
70 logger
.error("SQLException: " + e
);