Skip to content

Commit

Permalink
@Fixes #kripton-109 create datasource in writemode only and never clo…
Browse files Browse the repository at this point in the history
…se db
  • Loading branch information
xcesco committed Sep 30, 2022
1 parent 566ddeb commit 2635bbb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ public SQLContext getContext() {
return context;
}


/*
* (non-Javadoc)
*
Expand Down Expand Up @@ -457,10 +458,21 @@ protected void endLock() {
}

/**
* Force close.
* Force close. It's a dangerous command. It closes the database.
*/
void forceClose() {
public void forceClose() {
openCounter.set(0);

if (!this.options.inMemory) {
// Closing database
if (database != null) {
clearCompiledStatements();
sqliteHelper.close();
}
database = null;
}
if (logEnabled)
Logger.info("database %s IS FORCED TO BE CLOSED (%s) (connections: %s)", name, status.get(), openCounter.intValue());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,7 @@ private void generateInstanceOrBuild(SQLiteDatabaseSchema schema, String schemaN
//ASSERT: we are in build
methodBuilder.beginControlFlow("if (options.forceBuild && instance!=null)");
methodBuilder.addStatement("$T.info(\"Datasource $L is forced to be (re)builded\")", Logger.class, schemaName);
methodBuilder.addStatement("instance.forceClose()");
methodBuilder.addStatement("instance=null");
methodBuilder.endControlFlow();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -551,10 +551,7 @@ public static <H extends AbstractDataSource> void clearDataSource(H dataSource)
dataSource.openWritableDatabase();
File file = new File(dataSource.database.getPath(), dataSource.name);

if (dataSource.isOpen()) {
dataSource.forceClose();
dataSource.close();
}
dataSource.forceClose();

Logger.info("Clear database file %s", file.getAbsolutePath());
if (!file.delete()) {
Expand Down

0 comments on commit 2635bbb

Please sign in to comment.