Package liquibase.integration.cdi
Class CDILiquibase
java.lang.Object
liquibase.integration.cdi.CDILiquibase
- All Implemented Interfaces:
javax.enterprise.inject.spi.Extension
@ApplicationScoped
public class CDILiquibase
extends Object
implements javax.enterprise.inject.spi.Extension
A CDI wrapper for Liquibase.
Example Configuration:
This CDI configuration example will cause liquibase to run
automatically when the CDI container is initialized. It will load
db-changelog.xml
from the classpath and apply it against
myDataSource
.
Various producers methods are required to resolve the dependencies, i.e.
public class CDILiquibaseProducer {
@literal @Produces @LiquibaseType
public CDILiquibaseConfig createConfig() {
CDILiquibaseConfig config = new CDILiquibaseConfig();
config.setChangeLog("liquibase/parser/core/xml/simpleChangeLog.xml");
return config;
}
@literal @Produces @LiquibaseType
public DataSource createDataSource() throws SQLException {
jdbcDataSource ds = new jdbcDataSource();
ds.setDatabase("jdbc:hsqldb:mem:test");
ds.setUser("sa");
ds.setPassword("");
return ds;
}
@literal @Produces @LiquibaseType
public ResourceAccessor create() {
return new ClassLoaderResourceAccessor(getClass().getClassLoader());
}
}
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected Database
Creates and returns aDatabase
object retrieved from theDatabaseFactory
.protected Liquibase
boolean
boolean
void
protected void
-
Field Details
-
config
-
-
Constructor Details
-
CDILiquibase
public CDILiquibase()
-
-
Method Details
-
isInitialized
public boolean isInitialized() -
isUpdateSuccessful
public boolean isUpdateSuccessful() -
onStartup
-
performUpdate
- Throws:
LiquibaseException
-
createLiquibase
- Throws:
LiquibaseException
-
createDatabase
Creates and returns aDatabase
object retrieved from theDatabaseFactory
. Subclasses may override this method to change some database settings, such as default schema, before returning the database object.- Parameters:
c
- theJDBC
connection to use for creating the database- Returns:
- a
Database
implementation retrieved from theDatabaseFactory
- Throws:
DatabaseException
- if there is an error accessing the database
-