NIFI-655:

- Fixing issue detecting the presence of DN column
This commit is contained in:
Matt Gilman 2015-11-23 08:45:24 -05:00
parent 48c65e0498
commit 91573cb807
2 changed files with 8 additions and 28 deletions

View File

@ -19,7 +19,6 @@ package org.apache.nifi.admin;
import java.io.File;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import org.apache.commons.lang3.StringUtils;
@ -176,10 +175,11 @@ public class AuditDataSourceFactoryBean implements FactoryBean {
statement.execute(CREATE_PURGE_DETAILS_TABLE);
} else {
logger.info("Existing database found and connected to at: " + databaseUrl);
RepositoryUtils.closeQuietly(rs);
// get the RS metadata to see if we need to transform the table
final ResultSetMetaData rsMetadata = rs.getMetaData();
if (hasDnColumn(rsMetadata)) {
// check if the DN column exists to see if we need to transform the table
rs = connection.getMetaData().getColumns(null, null, "ACTION", "USER_DN");
if (rs.next()) {
statement.execute(RENAME_DN_COLUMN);
statement.execute(RESIZE_IDENTITY_COLUMN);
statement.execute(RESIZE_USER_NAME_COLUMN);
@ -201,16 +201,6 @@ public class AuditDataSourceFactoryBean implements FactoryBean {
return connectionPool;
}
private boolean hasDnColumn(final ResultSetMetaData rsMetadata) throws SQLException {
boolean hasDn = false;
for (int i = 1; i <= rsMetadata.getColumnCount() && !hasDn; i++) {
if ("USER_DN".equals(rsMetadata.getColumnName(i))) {
hasDn = true;
}
}
return hasDn;
}
@Override
public Class getObjectType() {
return JdbcConnectionPool.class;

View File

@ -19,7 +19,6 @@ package org.apache.nifi.admin;
import java.io.File;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashSet;
@ -151,10 +150,11 @@ public class UserDataSourceFactoryBean implements FactoryBean {
statement.execute(INSERT_ANONYMOUS_USER);
} else {
logger.info("Existing database found and connected to at: " + databaseUrl);
RepositoryUtils.closeQuietly(rs);
// get the RS metadata to see if we need to transform the table
final ResultSetMetaData rsMetadata = rs.getMetaData();
if (hasDnColumn(rsMetadata)) {
// if the DN column exists, transform the table
rs = connection.getMetaData().getColumns(null, null, "USER", "DN");
if (rs.next()) {
statement.execute(RENAME_DN_COLUMN);
statement.execute(RESIZE_IDENTITY_COLUMN);
statement.execute(RESIZE_USER_NAME_COLUMN);
@ -184,16 +184,6 @@ public class UserDataSourceFactoryBean implements FactoryBean {
return connectionPool;
}
private boolean hasDnColumn(final ResultSetMetaData rsMetadata) throws SQLException {
boolean hasDn = false;
for (int i = 1; i <= rsMetadata.getColumnCount() && !hasDn; i++) {
if ("DN".equals(rsMetadata.getColumnName(i))) {
hasDn = true;
}
}
return hasDn;
}
private String getDatabaseUrl(File databaseFile) {
String databaseUrl = "jdbc:h2:" + databaseFile + ";AUTOCOMMIT=OFF;DB_CLOSE_ON_EXIT=FALSE;LOCK_MODE=3";
String databaseUrlAppend = properties.getProperty(NiFiProperties.H2_URL_APPEND);