VIVO-863 get rid of GuardAgainstUnmigratedRDB

It was only useful for the transition from 1.6 to 1.7, and it was a problem when someone used a triple-store other than SDB.
This commit is contained in:
Jim Blake 2014-12-11 16:12:42 -05:00
parent 73b76a6e90
commit f339f1864f
2 changed files with 0 additions and 120 deletions

View file

@ -1,117 +0,0 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.servlet.setup;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
/**
* If there are RDB tables in the database that have not been converted to TDB,
* throw an error.
*
* The ConfigurationPropertiesSmokeTests has already run, so we know we can
* access the database. A table named "jena_graph", means that the database
* contains RDB. A table named "vivo_rdb_migrated" means that the conversion
* utility has been run.
*/
public class GuardAgainstUnmigratedRDB implements ServletContextListener {
private static final String PROPERTY_DB_URL = "VitroConnection.DataSource.url";
private static final String PROPERTY_DB_USERNAME = "VitroConnection.DataSource.username";
private static final String PROPERTY_DB_PASSWORD = "VitroConnection.DataSource.password";
private static final String PROPERTY_DB_DRIVER_CLASS_NAME = "VitroConnection.DataSource.driver";
private static final String DEFAULT_DRIVER_CLASS = "com.mysql.jdbc.Driver";
private static final String TABLE_NAME_RDB = "jena_graph";
private static final String TABLE_NAME_CONVERSION = "vivo_rdb_migrated";
private static final String MESSAGE_PROBLEM = "The database at %s"
+ " contains data from an earlier VIVO (before 1.7). "
+ "It does not appear that this data has been migrated. "
+ "The upgrade guide has instructions on migrating "
+ "this data to the current VIVO.";
private static final String MESSAGE_TECHNICAL = "More technically: "
+ "the database contains tables used by Jena RDB ('jena_graph' and "
+ "others). It does not contain the table 'vivo_rdb_migrated', "
+ "which is created when the data is migrated to Jena TDB files.";
private static final String MESSAGE_WHAT_NOW = "You must either migrate "
+ "the obsolete RDB data or remove it from your database.";
@Override
public void contextInitialized(ServletContextEvent sce) {
ServletContext ctx = sce.getServletContext();
ConfigurationProperties props = ConfigurationProperties.getBean(ctx);
StartupStatus ss = StartupStatus.getBean(ctx);
String url = props.getProperty(PROPERTY_DB_URL);
String username = props.getProperty(PROPERTY_DB_USERNAME);
String password = props.getProperty(PROPERTY_DB_PASSWORD);
String driverClassName = props.getProperty(
PROPERTY_DB_DRIVER_CLASS_NAME, DEFAULT_DRIVER_CLASS);
try {
Class.forName(driverClassName).newInstance();
Properties connectionProps = new Properties();
connectionProps.put("user", username);
connectionProps.put("password", password);
try (Connection conn = DriverManager.getConnection(url,
connectionProps)) {
boolean hasRdb = checkForRdbTables(conn);
boolean hasBeenConverted = checkForConversionTable(conn);
if (hasRdb && !hasBeenConverted) {
ss.fatal(this, String.format(MESSAGE_PROBLEM, url));
ss.fatal(this, String.format(MESSAGE_TECHNICAL, url));
ss.fatal(this, String.format(MESSAGE_WHAT_NOW, url));
}
} catch (SQLException e) {
ss.fatal(this, "Can't connect to the database: "
+ PROPERTY_DB_URL + "='" + url + "', "
+ PROPERTY_DB_USERNAME + "='" + username + "'", e);
}
} catch (InstantiationException | IllegalAccessException
| ClassNotFoundException e) {
ss.fatal(this, "Can't load the database driver: " + driverClassName);
}
}
private boolean checkForRdbTables(Connection conn) throws SQLException {
DatabaseMetaData md = conn.getMetaData();
try (ResultSet rs = md.getTables(null, null, TABLE_NAME_RDB, null);) {
while (rs.next()) {
return true;
}
}
return false;
}
private boolean checkForConversionTable(Connection conn)
throws SQLException {
DatabaseMetaData md = conn.getMetaData();
try (ResultSet rs = md.getTables(null, null, TABLE_NAME_CONVERSION,
null);) {
while (rs.next()) {
return true;
}
}
return false;
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
// Nothing to tear down.
}
}

View file

@ -13,9 +13,6 @@ edu.cornell.mannlib.vitro.webapp.config.ConfigurationPropertiesSetup
edu.cornell.mannlib.vitro.webapp.config.ConfigurationPropertiesSmokeTests edu.cornell.mannlib.vitro.webapp.config.ConfigurationPropertiesSmokeTests
# For the conversion from 1.6 or earlier (RDB) to 1.7 or later (TDB)
edu.cornell.mannlib.vitro.webapp.servlet.setup.GuardAgainstUnmigratedRDB
edu.cornell.mannlib.vitro.webapp.utils.developer.DeveloperSettings$Setup edu.cornell.mannlib.vitro.webapp.utils.developer.DeveloperSettings$Setup
edu.cornell.mannlib.vitro.webapp.application.ApplicationImpl$ComponentsSetup edu.cornell.mannlib.vitro.webapp.application.ApplicationImpl$ComponentsSetup