diff options
author | Ram Koya <rk541m@att.com> | 2018-09-13 15:06:10 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-09-13 15:06:10 +0000 |
commit | 7f9ff86b3d14722357a01c433b6c3ca592cdf94d (patch) | |
tree | bd8cd66d7874f5e123b423ff4e57546674694afc /src/main/java/org/onap | |
parent | a2deb2a1b61febbf64d22f5317c00da2b4f7c875 (diff) | |
parent | 6b64932dc81c7c23e0affe58815b7c5cd3c35bd9 (diff) |
Merge "DBFieldHandler.java: Fixed sonar issue"
Diffstat (limited to 'src/main/java/org/onap')
-rw-r--r-- | src/main/java/org/onap/dmaap/dbcapi/database/DBFieldHandler.java | 70 |
1 files changed, 36 insertions, 34 deletions
diff --git a/src/main/java/org/onap/dmaap/dbcapi/database/DBFieldHandler.java b/src/main/java/org/onap/dmaap/dbcapi/database/DBFieldHandler.java index 072c548..59d610c 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/database/DBFieldHandler.java +++ b/src/main/java/org/onap/dmaap/dbcapi/database/DBFieldHandler.java @@ -24,7 +24,6 @@ import java.lang.reflect.*; import java.sql.*; import java.util.*; -import org.apache.log4j.Logger; import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; @@ -33,7 +32,40 @@ import org.onap.dmaap.dbcapi.logging.DmaapbcLogMessageEnum; public class DBFieldHandler { - static final EELFLogger errorLogger = EELFManager.getInstance().getErrorLogger(); + static final EELFLogger errorLogger = EELFManager.getInstance().getErrorLogger(); + + public DBFieldHandler(Class<?> c, String fieldname, int fieldnum) throws Exception { + this(c, fieldname, fieldnum, null); + } + public DBFieldHandler(Class<?> c, String fieldname, int fieldnum, SqlOp op) throws Exception { + this.fieldnum = fieldnum; + StringBuilder sb = new StringBuilder(); + for (String s: fieldname.split("_")) { + sb.append(s.substring(0, 1).toUpperCase()).append(s.substring(1)); + } + String camelcase = sb.toString(); + try { + objget = c.getMethod("is" + camelcase); + } catch (Exception e) { + errorLogger.error("Error", e); + objget = c.getMethod("get" + camelcase); + } + objset = c.getMethod("set" + camelcase, objget.getReturnType()); + sqlop = op; + if (sqlop != null) { + return; + } + Class<?> x = objget.getReturnType(); + if (x.isEnum()) { + sqlop = new EnumSql(x); + return; + } + sqlop = sqltypes.get(x.getName()); + if (sqlop != null) { + return; + } + errorLogger.error(DmaapbcLogMessageEnum.DB_NO_FIELD_HANDLER, c.getName(), fieldname, Integer.toString(fieldnum), x.getName()); + } public static interface SqlOp { public Object get(ResultSet rs, int index) throws Exception; @@ -121,7 +153,7 @@ public class DBFieldHandler { } private static Map<String, SqlOp> sqltypes; static { - sqltypes = new HashMap<String, SqlOp>(); + sqltypes = new HashMap<>(); sqltypes.put("[Ljava.lang.String;", new AofString()); sqltypes.put("java.util.Date", new SqlDate()); try { @@ -134,6 +166,7 @@ public class DBFieldHandler { new SqlType("Short"); new SqlType("String"); } catch (Exception e) { + errorLogger.error("Error", e); errorLogger.error(DmaapbcLogMessageEnum.DB_ACCESS_INIT_ERROR, e.getMessage() ); } } @@ -156,37 +189,6 @@ public class DBFieldHandler { public void fromSQL(ResultSet r, Object o) throws Exception { objset.invoke(o, sqlop.get(r, fieldnum)); } - public DBFieldHandler(Class<?> c, String fieldname, int fieldnum) throws Exception { - this(c, fieldname, fieldnum, null); - } - public DBFieldHandler(Class<?> c, String fieldname, int fieldnum, SqlOp op) throws Exception { - this.fieldnum = fieldnum; - StringBuffer sb = new StringBuffer(); - for (String s: fieldname.split("_")) { - sb.append(s.substring(0, 1).toUpperCase()).append(s.substring(1)); - } - String camelcase = sb.toString(); - try { - objget = c.getMethod("is" + camelcase); - } catch (Exception e) { - objget = c.getMethod("get" + camelcase); - } - objset = c.getMethod("set" + camelcase, objget.getReturnType()); - sqlop = op; - if (sqlop != null) { - return; - } - Class<?> x = objget.getReturnType(); - if (x.isEnum()) { - sqlop = new EnumSql(x); - return; - } - sqlop = sqltypes.get(x.getName()); - if (sqlop != null) { - return; - } - errorLogger.error(DmaapbcLogMessageEnum.DB_NO_FIELD_HANDLER, c.getName(), fieldname, Integer.toString(fieldnum), x.getName()); - } public static String fesc(String s) { if (s == null) { return(s); |