Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
47 changed files
with
348 additions
and
549 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
...whirl-app-server/src/main/java/org/whirlplatform/server/evolution/EvolutionException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.whirlplatform.server.evolution; | ||
|
||
public class EvolutionException extends Exception { | ||
|
||
public EvolutionException(Throwable cause) { | ||
super(cause); | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
...p/whirl-app-server/src/main/java/org/whirlplatform/server/evolution/EvolutionManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.whirlplatform.server.evolution; | ||
|
||
public interface EvolutionManager { | ||
|
||
void applyApplicationEvolution(String alias, String scriptPath) throws EvolutionException; | ||
|
||
void applyMetadataEvolution(String alias, String scriptPath) throws EvolutionException; | ||
|
||
} |
67 changes: 67 additions & 0 deletions
67
...pp-server/src/main/java/org/whirlplatform/server/evolution/LiquibaseEvolutionManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package org.whirlplatform.server.evolution; | ||
|
||
import liquibase.Contexts; | ||
import liquibase.LabelExpression; | ||
import liquibase.Liquibase; | ||
import liquibase.database.Database; | ||
import liquibase.database.DatabaseFactory; | ||
import liquibase.database.jvm.JdbcConnection; | ||
import liquibase.exception.LiquibaseException; | ||
import liquibase.resource.ClassLoaderResourceAccessor; | ||
import liquibase.resource.FileSystemResourceAccessor; | ||
import liquibase.resource.ResourceAccessor; | ||
import org.whirlplatform.server.config.Configuration; | ||
import org.whirlplatform.server.db.ConnectException; | ||
import org.whirlplatform.server.db.ConnectionProvider; | ||
import org.whirlplatform.server.db.ConnectionWrapper; | ||
import org.whirlplatform.server.log.Logger; | ||
import org.whirlplatform.server.log.LoggerFactory; | ||
|
||
import javax.inject.Inject; | ||
import java.sql.SQLException; | ||
|
||
public class LiquibaseEvolutionManager implements EvolutionManager { | ||
|
||
private static Logger _log = LoggerFactory.getLogger(LiquibaseEvolutionManager.class); | ||
|
||
private ConnectionProvider connectionProvider; | ||
private Configuration configuration; | ||
|
||
@Inject | ||
public LiquibaseEvolutionManager(ConnectionProvider connectionProvider, Configuration configuration) { | ||
this.connectionProvider = connectionProvider; | ||
this.configuration = configuration; | ||
} | ||
|
||
@Override | ||
public void applyApplicationEvolution(String alias, String scriptPath) throws EvolutionException { | ||
applyEvolution(alias, scriptPath, new FileSystemResourceAccessor()); | ||
} | ||
|
||
@Override | ||
public void applyMetadataEvolution(String alias, String scriptPath) throws EvolutionException { | ||
applyEvolution(alias, scriptPath, new ClassLoaderResourceAccessor()); | ||
} | ||
|
||
private void applyEvolution(String alias, String scriptPath, ResourceAccessor resourceAccessor) throws EvolutionException { | ||
Boolean applyEvolutions = configuration.<Boolean>lookup("Whirl/ds/" + alias | ||
+ "/evolutions/enabled"); | ||
if (applyEvolutions == null || !applyEvolutions) { | ||
return; | ||
} | ||
|
||
try (ConnectionWrapper connection = connectionProvider.getConnection(alias)) { | ||
Database database = DatabaseFactory.getInstance() | ||
.findCorrectDatabaseImplementation(new JdbcConnection(connection)); | ||
|
||
Liquibase liquibase = new liquibase.Liquibase(scriptPath, resourceAccessor, | ||
database); | ||
|
||
liquibase.update(new Contexts(), new LabelExpression()); | ||
} catch (LiquibaseException | SQLException | ConnectException e) { | ||
_log.error(e); | ||
throw new EvolutionException(e); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.