Skip to content

Commit

Permalink
#2674 fixing several resource handling misses (#2896)
Browse files Browse the repository at this point in the history
* added closing resources from sonar advices

* fixing several resource handling misses

* fixing several resource handling misses

* fixing several resource handling misses

* fixing several more resource handling misses

* fixing test which was relying on badly spelled 'progres' property

* reverted comment and throws clause
  • Loading branch information
svendiedrichsen authored and lprimak committed Jun 29, 2018
1 parent fb780ca commit eaeea99
Show file tree
Hide file tree
Showing 28 changed files with 1,042 additions and 1,145 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/*
* Copyright (c) 2016 Payara Foundation. All rights reserved.
* Copyright (c) 2016 - 2018 Payara Foundation. All rights reserved.
* The contents of this file are subject to the terms of the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*/
Expand All @@ -35,7 +35,7 @@
import javax.sql.DataSource;

/**
*
*
* DB2 Persistence Manager
*/

Expand All @@ -47,7 +47,7 @@ public class DB2PersistenceManager extends JBatchJDBCPersistenceManager implemen
private final static Logger logger = Logger.getLogger(CLASSNAME);

private IBatchConfig batchConfig = null;

// db2 create table strings
protected Map<String, String> createDB2Strings;

Expand All @@ -61,7 +61,7 @@ public void init(IBatchConfig batchConfig)
schema = batchConfig.getDatabaseConfigurationBean().getSchema();

jndiName = batchConfig.getDatabaseConfigurationBean().getJndiName();

try {
Context ctx = new InitialContext();
dataSource = (DataSource) ctx.lookup(jndiName);
Expand Down Expand Up @@ -98,7 +98,7 @@ public void init(IBatchConfig batchConfig)
"JNDI name is not defined.");
}


try {
if (!isDB2SchemaValid()) {
setDefaultSchema();
Expand All @@ -112,7 +112,7 @@ public void init(IBatchConfig batchConfig)

logger.config("Exiting CLASSNAME.init()");
}

/**
* Check the schema exists
* @return
Expand Down Expand Up @@ -150,7 +150,7 @@ private boolean isDB2SchemaValid() throws SQLException {
return result;

}

/**
* Check the relevant db2 tables exist in the relevant schema
* @throws SQLException
Expand Down Expand Up @@ -192,28 +192,25 @@ protected void createDB2TableNotExists(String tableName,
logger.entering(CLASSNAME, "createDB2TableNotExists", new Object[] {
tableName, createTableStatement });
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
PreparedStatement ps = null;

try {
conn = getConnection();
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
String query = "select name from sysibm.systables where name ="
+ "\'" + tableName.toUpperCase() + "\'" + "and type = 'T'";
;
rs = stmt.executeQuery(query);

int rowcount = getTableRowCount(rs);

// Create table if it does not exist
if (rowcount == 0) {
if (!rs.next()) {
logger.log(Level.INFO, tableName
+ " table does not exists. Trying to create it.");
ps = conn.prepareStatement(createTableStatement);
ps.executeUpdate();
try (Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY)) {
String query = "select name from sysibm.systables where name ="
+ "\'" + tableName.toUpperCase() + "\'" + "and type = 'T'";
rs = stmt.executeQuery(query);
int rowcount = getTableRowCount(rs);
// Create table if it does not exist
if (rowcount == 0) {
if (!rs.next()) {
logger.log(Level.INFO, tableName
+ " table does not exists. Trying to create it.");
ps = conn.prepareStatement(createTableStatement);
ps.executeUpdate();
}
}
}
} catch (SQLException e) {
Expand All @@ -225,7 +222,7 @@ protected void createDB2TableNotExists(String tableName,

logger.exiting(CLASSNAME, "createDB2TableNotExists");
}

/**
* Method invoked to insert the DB2 create table strings into a hashmap
**/
Expand Down
Loading

0 comments on commit eaeea99

Please sign in to comment.