}
- public PreparedStatement getTarget() {
+ public synchronized PreparedStatement getTarget() {
return target;
}
}
- public static final int CURRENT_SCHEMA_VERSION = 6;
+ public static final int CURRENT_SCHEMA_VERSION = 10;
public static final int CONNECTION_TIMEOUT = 24 * 60 * 60;
lastAction = System.currentTimeMillis();
}
- private static DatabaseConnection instance;
+ private static volatile DatabaseConnection instance;
- public static DatabaseConnection getInstance() {
+ public static synchronized DatabaseConnection getInstance() {
if (instance == null) {
- synchronized (DatabaseConnection.class) {
- if (instance == null) {
- instance = new DatabaseConnection();
- }
- }
+ instance = new DatabaseConnection();
}
return instance;
}
upgrade(version);
}
- public void beginTransaction() throws SQLException {
- c.setAutoCommit(false);
- }
-
private static void upgrade(int version) {
try {
Statement s = getInstance().c.createStatement();
try {
while (version < CURRENT_SCHEMA_VERSION) {
- try (InputStream resourceAsStream = DatabaseConnection.class.getResourceAsStream("upgrade/from_" + version + ".sql")) {
- if (resourceAsStream == null) {
- throw new Error("Upgrade script from version " + version + " was not found.");
- }
- SQLFileManager.addFile(s, resourceAsStream, ImportType.PRODUCTION);
- }
+ addUpgradeScript(Integer.toString(version), s);
version++;
}
s.addBatch("UPDATE \"schemeVersion\" SET version='" + version + "'");
}
}
- public void commitTransaction() throws SQLException {
- c.commit();
- c.setAutoCommit(true);
- }
-
- public void quitTransaction() {
- try {
- if ( !c.getAutoCommit()) {
- c.rollback();
- c.setAutoCommit(true);
+ private static void addUpgradeScript(String version, Statement s) throws Error, IOException, SQLException {
+ try (InputStream resourceAsStream = DatabaseConnection.class.getResourceAsStream("upgrade/from_" + version + ".sql")) {
+ if (resourceAsStream == null) {
+ throw new Error("Upgrade script from version " + version + " was not found.");
}
- } catch (SQLException e) {
- e.printStackTrace();
+ SQLFileManager.addFile(s, resourceAsStream, ImportType.PRODUCTION);
}
}
return underUse.size();
}
- public void lockedStatements(PrintWriter writer) {
+ public synchronized void lockedStatements(PrintWriter writer) {
writer.println(underUse.size());
for (PreparedStatement ps : underUse) {
for (Entry<StatementDescriptor, PreparedStatement> e : statements.entrySet()) {