de.viaboxx.dbmigrate.spring.DBMigrateBean Maven / Gradle / Ivy
package de.viaboxx.dbmigrate.spring;
import com.agimatec.dbmigrate.AutoMigrationTool;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.InitializingBean;
import javax.sql.DataSource;
import java.util.Map;
/**
* Description:
* Bean to integrate and configure dbmigrate via spring.
*
*
*
* Supports spring access common options of AutoMigrationTool:
* - sim: simulation (false)
* - exitJVM: exit Java VM after migration (false)
* - stopOnException: true: log and re-throw exception to stop startup,
* false: log exception and continue(true)
* - migrateConfigFileName: xml setup file (migration.xml)
*
*
Currently not supported features via spring-configuration:
* - script: ScriptAction
* - op: OperationAction
*
* User: roman.stumm
* Date: 03.11.2011
* Time: 08:06:42
* viaboxx GmbH, 2011
*/
public class DBMigrateBean implements InitializingBean, BeanNameAware {
private final AutoMigrationTool tool;
protected String beanName;
protected DBCPAdapter dataSourceConfigurator;
/**
* disable running the tool
*/
private boolean disabled = false;
private boolean stopOnException = true;
public DBMigrateBean() {
tool = new AutoMigrationTool();
tool.setExitJVM(false);
}
/**
* @param fileName - default is "migration.xml", see BaseMigrationTool#migrateConfigFileName
*/
public void setConfigFile(String fileName) {
getTool().setMigrateConfigFileName(fileName);
}
public boolean isDisabled() {
return disabled;
}
public void setDisabled(boolean disabled) {
this.disabled = disabled;
}
public boolean isStopOnException() {
return stopOnException;
}
public void setStopOnException(boolean stopOnException) {
this.stopOnException = stopOnException;
}
public void setExitJVM(boolean exitJVM) {
getTool().setExitJVM(exitJVM);
}
public boolean isExitJVM() {
return getTool().isExitJVM();
}
/**
* @param sim - default is 'false'
*/
public void setSimulation(boolean sim) {
getTool().setSim(sim);
}
public void setConfigRootUrl(String configRoot) {
getTool().setConfigRootUrl(configRoot);
}
@SuppressWarnings({"unchecked"})
public void setToVersion(String version) {
getTool().getEnvironment().put("to-version", version);
}
@SuppressWarnings({"unchecked"})
public void setFromVersion(String version) {
getTool().getEnvironment().put("from-version", version);
}
public void setEnvironment(Map env) {
for (Map.Entry entry : env.entrySet()) {
if (null == System.getProperty(entry.getKey())) { // do not overwrite System properties
//noinspection unchecked
getTool().getEnvironment().put(entry.getKey(), entry.getValue());
}
}
}
public void setMigrateConfig(Map
© 2015 - 2025 Weber Informatics LLC | Privacy Policy