@ApplicationScoped public class CDILiquibase extends Object implements jakarta.enterprise.inject.spi.Extension
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.
@Dependent
public class CDILiquibaseProducer {
@Produces @LiquibaseType
public CDILiquibaseConfig createConfig() {
CDILiquibaseConfig config = new CDILiquibaseConfig();
config.setChangeLog("liquibase/parser/core/xml/simpleChangeLog.xml");
return config;
}
@Produces @LiquibaseType
public DataSource createDataSource() throws SQLException {
jdbcDataSource ds = new jdbcDataSource();
ds.setDatabase("jdbc:hsqldb:mem:test");
ds.setUser("sa");
ds.setPassword("");
return ds;
}
@Produces @LiquibaseType
public ResourceAccessor createResourceAccessor() {
return new ClassLoaderResourceAccessor(getClass().getClassLoader());
}
}
| Modifier and Type | Field and Description |
|---|---|
protected CDILiquibaseConfig |
config |
| Constructor and Description |
|---|
CDILiquibase() |
| Modifier and Type | Method and Description |
|---|---|
protected Database |
createDatabase(Connection c)
Subclasses may override this method add change some database settings such as
default schema before returning the database object.
|
protected Liquibase |
createLiquibase(Connection c) |
boolean |
isInitialized() |
boolean |
isUpdateSuccessful() |
void |
onStartup() |
protected void |
performUpdate() |
@Inject protected CDILiquibaseConfig config
public boolean isInitialized()
public boolean isUpdateSuccessful()
@PostConstruct public void onStartup()
protected void performUpdate()
throws LiquibaseException
LiquibaseExceptionprotected Liquibase createLiquibase(Connection c) throws LiquibaseException
LiquibaseExceptionprotected Database createDatabase(Connection c) throws DatabaseException
c - DatabaseFactory.DatabaseExceptionCopyright © 2023 Liquibase.org. All rights reserved.