This is an automated email from the ASF dual-hosted git repository.
doebele pushed a commit to branch version3
in repository https://gitbox.apache.org/repos/asf/empire-db.git
The following commit(s) were added to refs/heads/version3 by this push:
new aa14fa2 EMPIREDB-364 codegen class cleanup
aa14fa2 is described below
commit aa14fa285e21bfb5779601d36a46fcbd0381b6bc
Author: Rainer Döbele <[email protected]>
AuthorDate: Tue Feb 1 17:36:48 2022 +0100
EMPIREDB-364 codegen class cleanup
---
.../apache/empire/db/codegen/CodeGenParser.java | 42 ++++++++++++--
.../org/apache/empire/db/codegen/util/DBUtil.java | 67 ----------------------
.../apache/empire/db/codegen/util/DBUtilTest.java | 54 -----------------
3 files changed, 36 insertions(+), 127 deletions(-)
diff --git
a/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenParser.java
b/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenParser.java
index b4325fc..d46c5fe 100644
---
a/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenParser.java
+++
b/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenParser.java
@@ -39,7 +39,6 @@ import org.apache.empire.db.DBTable;
import org.apache.empire.db.DBTableColumn;
import org.apache.empire.db.DBView;
import org.apache.empire.db.DBView.DBViewColumn;
-import org.apache.empire.db.codegen.util.DBUtil;
import org.apache.empire.exceptions.ItemNotFoundException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -108,7 +107,7 @@ public class CodeGenParser {
}
finally
{
- DBUtil.close(con, log);
+ close(con);
}
return db;
}
@@ -216,7 +215,7 @@ public class CodeGenParser {
log.info("Available schemata: " +
getSchemata(dbMeta));
}
} finally {
- DBUtil.close(tables, log);
+ close(tables);
}
}
@@ -345,7 +344,7 @@ public class CodeGenParser {
t.setPrimaryKey(keys);
}
} finally {
- DBUtil.close(rs, log);
+ close(rs);
}
}
@@ -363,7 +362,7 @@ public class CodeGenParser {
addColumn(v, rs);
}
} finally {
- DBUtil.close(rs, log);
+ close(rs);
}
}
@@ -382,7 +381,7 @@ public class CodeGenParser {
cols.add(rs.getString("COLUMN_NAME"));
}
} finally {
- DBUtil.close(rs, log);
+ close(rs);
}
return cols;
}
@@ -556,4 +555,35 @@ public class CodeGenParser {
return empireType;
}
+ /**
+ * Closes a sql resultset and logs exceptions.
+ *
+ * @param rs the resultset to close
+ * @param log the logger instance to use for logging
+ * @return true on succes
+ */
+ protected boolean close(ResultSet rs)
+ { try {
+ if (rs != null)
+ rs.close();
+ return true;
+ } catch (SQLException e) {
+ log.error("The resultset could not be closed!", e);
+ return false;
+ }
+ }
+
+ /**
+ * Closes a JDBC-Connection and logs exceptions.
+ */
+ protected void close(Connection conn)
+ { try {
+ log.info("Closing database connection");
+ if (conn != null)
+ conn.close();
+ } catch (Exception e) {
+ log.error("Error closing connection", e);
+ }
+ }
+
}
diff --git
a/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/util/DBUtil.java
b/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/util/DBUtil.java
deleted file mode 100644
index d482765..0000000
---
a/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/util/DBUtil.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.empire.db.codegen.util;
-
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-
-import org.slf4j.Logger;
-
-
-public final class DBUtil {
-
- private DBUtil()
- {
- // Utility class
- }
-
- /**
- * Closes a sql resultset and logs exceptions.
- *
- * @param rs the resultset to close
- * @param log the logger instance to use for logging
- * @return true on succes
- */
- public static boolean close(ResultSet rs, Logger log) {
- boolean b = false;
- try {
- if(rs!=null)
- rs.close();
- b = true;
- } catch (SQLException e) {
- log.error("The resultset could not be closed!", e);
- }
- return b;
- }
-
- /**
- * Closes a JDBC-Connection and logs exceptions.
- */
- public static void close(Connection conn, Logger log) {
- if(conn != null){
- log.info("Closing database connection");
- try {
- conn.close();
- } catch (Exception e) {
- log.error("Error closing connection", e);
- }
- }
- }
-}
diff --git
a/empire-db-codegen/src/test/java/org/apache/empire/db/codegen/util/DBUtilTest.java
b/empire-db-codegen/src/test/java/org/apache/empire/db/codegen/util/DBUtilTest.java
deleted file mode 100644
index c63c17c..0000000
---
a/empire-db-codegen/src/test/java/org/apache/empire/db/codegen/util/DBUtilTest.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.empire.db.codegen.util;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import java.sql.ResultSet;
-import java.sql.SQLException;
-
-import org.slf4j.Logger;
-import org.junit.Test;
-import org.mockito.Mockito;
-
-public class DBUtilTest {
-
- @Test
- public void testCloseResultSet() throws SQLException {
- // null
- Logger log = Mockito.mock(Logger.class);
- boolean succes = DBUtil.close((ResultSet)null, log);
- assertTrue(succes);
-
- // normal
- ResultSet rs = Mockito.mock(ResultSet.class);
- boolean succes2 = DBUtil.close(rs, log);
- assertTrue(succes2);
-
- // exception
- ResultSet rsFail = Mockito.mock(ResultSet.class);
- Exception exception = new SQLException("test");
- Mockito.doThrow(exception).when(rsFail).close();
- boolean succes3 = DBUtil.close(rsFail, log);
- assertFalse(succes3);
- Mockito.verify(log).error("The resultset could not be closed!",
exception);
- }
-
-}