Class CDILiquibase
- java.lang.Object
-
- liquibase.integration.jakarta.cdi.CDILiquibase
-
- All Implemented Interfaces:
jakarta.enterprise.inject.spi.Extension
@ApplicationScoped public class CDILiquibase extends Object implements jakarta.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
Various producers methods are required to resolve the dependencies, i.e.db-changelog.xml
from the classpath and apply it againstmyDataSource
.@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()); } }
-
-
Field Summary
Fields Modifier and Type Field Description protected CDILiquibaseConfig
config
-
Constructor Summary
Constructors Constructor Description CDILiquibase()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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()
-
-
-
Field Detail
-
config
@Inject protected CDILiquibaseConfig config
-
-
Method Detail
-
isInitialized
public boolean isInitialized()
-
isUpdateSuccessful
public boolean isUpdateSuccessful()
-
onStartup
@PostConstruct public void onStartup()
-
performUpdate
protected void performUpdate() throws LiquibaseException
- Throws:
LiquibaseException
-
createLiquibase
protected Liquibase createLiquibase(Connection c) throws LiquibaseException
- Throws:
LiquibaseException
-
createDatabase
protected Database createDatabase(Connection c) throws DatabaseException
Subclasses may override this method add change some database settings such as default schema before returning the database object.- Parameters:
c
-- Returns:
- a Database implementation retrieved from the
DatabaseFactory
. - Throws:
DatabaseException
-
-