Skip to content

Commit

Permalink
Replace DatabaseSourceLoaderWithCommit with a simple constructor switch
Browse files Browse the repository at this point in the history
on the original DatabaseSourceLoader class. Rename loader tag for
builder to DatabaseSourceImplicitCommit
  • Loading branch information
MikeHeyes committed May 4, 2017
1 parent ba92f58 commit e2b1a4e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 77 deletions.
4 changes: 2 additions & 2 deletions src/com/fivium/scriptrunner2/loader/BuiltInLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public abstract class BuiltInLoader
implements Loader {

public static final String LOADER_NAME_DB_SOURCE = "DatabaseSource";
public static final String LOADER_NAME_DB_SOURCE_WITH_COMMIT = "DatabaseSourceWithCommit";
public static final String LOADER_NAME_DB_SOURCE_WITH_COMMIT = "DatabaseSourceImplicitCommit";
public static final String LOADER_NAME_SCRIPTRUNNER_UTIL = "ScriptRunnerUtil";
public static final String LOADER_NAME_PATCH = "Patch";
/** Special loader name for the builder only - files associated with this loader are ignored when constructing the manifest. */
Expand All @@ -21,7 +21,7 @@ public abstract class BuiltInLoader
static {
gBuiltInLoaderMap = new HashMap<String, Loader>();
gBuiltInLoaderMap.put(LOADER_NAME_DB_SOURCE, new DatabaseSourceLoader());
gBuiltInLoaderMap.put(LOADER_NAME_DB_SOURCE_WITH_COMMIT, new DatabaseSourceWithCommitLoader());
gBuiltInLoaderMap.put(LOADER_NAME_DB_SOURCE_WITH_COMMIT, new DatabaseSourceLoader(true));
gBuiltInLoaderMap.put(LOADER_NAME_SCRIPTRUNNER_UTIL, UtilLoader.getInstance());
gBuiltInLoaderMap.put(LOADER_NAME_PATCH, new PatchScriptLoader());
}
Expand Down
26 changes: 24 additions & 2 deletions src/com/fivium/scriptrunner2/loader/DatabaseSourceLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,29 @@
*/
public class DatabaseSourceLoader
extends SourceLoader {


private boolean implicitCommit = false;

/**
* Default Constructor
*/
public DatabaseSourceLoader(){
super();
}

/**
* Constructor to force commit of active transaction once file has been loaded
* @param pImplicitCommit
*/
public DatabaseSourceLoader(boolean pImplicitCommit){
super();
this.implicitCommit = pImplicitCommit;
}

@Override
public void doPromote(ScriptRunner pScriptRunner, PromotionFile pFile)
throws ExPromote {

long lStart = System.currentTimeMillis();
Logger.logInfo("\nPromote DatabaseSource " + pFile.getFilePath());
//Read the DBSource file in
Expand Down Expand Up @@ -62,6 +80,10 @@ public void doPromote(ScriptRunner pScriptRunner, PromotionFile pFile)
for(ScriptExecutable lExecutable : lExecutableList){
lExecutable.execute(pScriptRunner.getDatabaseConnection());
}
// if the transaction is still active at the end of the script AND loader has implicitCommit flag set, perform a commit.
if (implicitCommit)
pScriptRunner.getDatabaseConnection().unsafelyCommit();

}
catch (Throwable th){
throw new ExPromote("Failed to promote DatabaseSource " + pFile.getFilePath() + ": " + th.getMessage(), th);
Expand Down

This file was deleted.

0 comments on commit e2b1a4e

Please sign in to comment.