diff options
author | Arundathi Patil <arundpil@in.ibm.com> | 2018-09-05 18:54:54 +0530 |
---|---|---|
committer | IBM602-PC0F1E3C\Arundathi <arundpil@in.ibm.com> | 2018-09-05 18:55:05 +0530 |
commit | e949bab0978f7c1d9822d4030d9a00f72c2ee266 (patch) | |
tree | a8905625637ba9efd7997dd7b4c7d0faa3872cdb /src/main/java/org/onap | |
parent | dde5c600507bd746b6978ab5e1058a894fb6bef7 (diff) |
TableHandler.java: Fixed sonar issues
Fixed sonar code-smells/issues across this file
Issue-ID: DMAAP-733
Change-Id: Ibea07e1f3904d66dc4d3ef31567472eb5ba2a3f8
Signed-off-by: Arundathi Patil <arundpil@in.ibm.com>
Diffstat (limited to 'src/main/java/org/onap')
-rw-r--r-- | src/main/java/org/onap/dmaap/dbcapi/database/TableHandler.java | 51 |
1 files changed, 28 insertions, 23 deletions
diff --git a/src/main/java/org/onap/dmaap/dbcapi/database/TableHandler.java b/src/main/java/org/onap/dmaap/dbcapi/database/TableHandler.java index c83b6be..fc68aa2 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/database/TableHandler.java +++ b/src/main/java/org/onap/dmaap/dbcapi/database/TableHandler.java @@ -40,22 +40,10 @@ class TableHandler<C> { protected String initstmt; protected Class<C> cls; protected DBFieldHandler[] fields; - private static Map<String, Map<String, DBFieldHandler.SqlOp>> exceptions = new HashMap<String, Map<String, DBFieldHandler.SqlOp>>(); - public static void setSpecialCase(String dbtabname, String dbfldname, DBFieldHandler.SqlOp handler) { - Map<String, DBFieldHandler.SqlOp> m = exceptions.get(dbtabname); - if (m == null) { - m = new HashMap<String, DBFieldHandler.SqlOp>(); - exceptions.put(dbtabname, m); - } - m.put(dbfldname, handler); - } - public static DBFieldHandler.SqlOp getSpecialCase(String dbtabname, String dbfldname) { - Map<String, DBFieldHandler.SqlOp> m = exceptions.get(dbtabname); - if (m != null) { - return(m.get(dbfldname)); - } - return(null); - } + private static Map<String, Map<String, DBFieldHandler.SqlOp>> exceptions = new HashMap<>(); + private String select = "SELECT "; + private String from = " FROM "; + protected TableHandler(Class<C> cls, String tabname, String keyname) throws Exception { this(ConnectionFactory.getDefaultInstance(), cls, tabname, keyname); } @@ -71,14 +59,31 @@ class TableHandler<C> { } } } + + public static void setSpecialCase(String dbtabname, String dbfldname, DBFieldHandler.SqlOp handler) { + Map<String, DBFieldHandler.SqlOp> m = exceptions.get(dbtabname); + if (m == null) { + m = new HashMap<>(); + exceptions.put(dbtabname, m); + } + m.put(dbfldname, handler); + } + public static DBFieldHandler.SqlOp getSpecialCase(String dbtabname, String dbfldname) { + Map<String, DBFieldHandler.SqlOp> m = exceptions.get(dbtabname); + if (m != null) { + return(m.get(dbfldname)); + } + return(null); + } + private void setup(DatabaseMetaData dmd, Class<C> cls, String tabname, String keyname) throws Exception { this.cls = cls; - Vector<DBFieldHandler> h = new Vector<DBFieldHandler>(); + Vector<DBFieldHandler> h = new Vector<>(); String qualifiedTableName = String.format( "%s.%s", cf.getSchema(), tabname ); ResultSet rs = dmd.getColumns("", cf.getSchema(), tabname, null); - StringBuffer sb1 = new StringBuffer(); - StringBuffer sb2 = new StringBuffer(); - StringBuffer sb3 = new StringBuffer(); + StringBuilder sb1 = new StringBuilder(); + StringBuilder sb2 = new StringBuilder(); + StringBuilder sb3 = new StringBuilder(); int count = 0; while (rs.next()) { if (!rs.getString(3).equals(tabname)) { @@ -109,13 +114,13 @@ class TableHandler<C> { h.add(new DBFieldHandler(cls, keyname, count, getSpecialCase(tabname, keyname))); delstmt = "DELETE FROM " + qualifiedTableName + " WHERE " + keyname + " = ?"; insorreplstmt = "INSERT INTO " + qualifiedTableName + " (" + clist + ", " + keyname + ") VALUES (" + qlist + ", ?) ON CONFLICT(" + keyname + ") DO UPDATE SET (" + clist + ") = (" + elist + ")"; - getstmt = "SELECT " + clist + ", " + keyname + " FROM " + qualifiedTableName + " WHERE " + keyname + " = ?"; - liststmt = "SELECT " + clist + ", " + keyname + " FROM " + qualifiedTableName; + getstmt = select + clist + ", " + keyname + from + qualifiedTableName + " WHERE " + keyname + " = ?"; + liststmt = select + clist + ", " + keyname + from + qualifiedTableName; } else { delstmt = "DELETE FROM " + qualifiedTableName; initstmt = "INSERT INTO " + qualifiedTableName + " (" + clist + ") VALUES (" + qlist + ")"; insorreplstmt = "UPDATE " + qualifiedTableName + " SET (" + clist + ") = (" + qlist + ")"; - getstmt = "SELECT " + clist + ", " + keyname + " FROM " + qualifiedTableName; + getstmt = select + clist + ", " + keyname + from + qualifiedTableName; } fields = h.toArray(new DBFieldHandler[h.size()]); } |