public class Database extends org.splat.dal.dao.kernel.AbstractDatabase {
- private int uplevel = 0; // Level of database upgrade
+ public final static Logger LOG = org.splat.dal.dao.som.Database.LOG;
+
+ private transient int _uplevel = 0; // Level of database upgrade
private RepositoryService _repositoryService;
private IndexService _indexService;
private UserService _userService;
protected class CheckVersion implements Work {
/**
* {@inheritDoc}
+ * @throws SQLException
* @see org.hibernate.jdbc.Work#execute(java.sql.Connection)
*/
public void execute(final Connection connex) throws SQLException {
DatabaseMetaData dbmdata = connex.getMetaData();
String dbname = connex.getCatalog();
- ResultSet table;
+ ResultSet table = null;
- table = dbmdata.getTables(dbname, null, "study", null);
- if (table.next()) {
- return;
+ try {
+ table = dbmdata.getTables(dbname, null, "study", null);
+ if (table.next()) {
+ return;
+ }
+ } catch (SQLException e) {
+ LOG.debug("Can't check the database version: ", e);
+ throw e;
+ } finally {
+ if (table != null) {
+ table.close();
+ }
}
- uplevel = -1; // Database not initialized
+ _uplevel = -1; // Database not initialized
}
}
- public final static Logger logger = org.splat.dal.dao.som.Database.logger;
-
// ==============================================================================================================================
// Construction
// ==============================================================================================================================
- private static Database myDB;
+ private static Database myDB = new Database();
public static Database getInstance() {
- if (myDB == null) {
- myDB = new Database();
- }
return myDB;
}
my = this;
my.checkVersion();
} catch (Exception error) {
- logger.fatal("Could not access the database, reason:", error);
+ LOG.fatal("Could not access the database, reason:", error);
}
}
return my;
// ==============================================================================================================================
public boolean isInitialized() {
- return (uplevel >= 0);
+ return (_uplevel >= 0);
}
public void initialize() throws IOException, SQLException {
- logger.info("Creation of the database.");
+ LOG.info("Creation of the database.");
// Creation of the Lucene index
getIndexService().create(); // May throw IOException if the index repository is improperly configured
// Population of the database with customized data
this.populate();
- uplevel = 0; // The database is now up-to-date
+ _uplevel = 0; // The database is now up-to-date
}
// ==============================================================================================================================
getUserService().createUser(uprop);
} catch (Exception e) {
// Let's continue, hoping the best...
+ LOG.debug(e.getMessage(), e);
}
}