java.lang.Object
de.hdi.mongobumblebee.MongoBumblebee
- All Implemented Interfaces:
org.springframework.beans.factory.InitializingBean
public class MongoBumblebee
extends Object
implements org.springframework.beans.factory.InitializingBean
MongoBumblebee runner
- Since:
- 26/07/2014
- Author:
- lstolowski
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longTime between two polls to aquire the lock (in seconds)static final longWaiting time (in minutes)static final booleanstatic final booleanstatic final String -
Constructor Summary
ConstructorsConstructorDescriptionMongoBumblebee(com.mongodb.client.MongoClient mongoClient, String dbName) Constructor takes MongoClient object as a parameter.MongoBumblebee(String mongoURI, String dbName) MongoBumblebee runner. -
Method Summary
Modifier and TypeMethodDescriptionvoidFor Spring users: executing MongoBumblebee after bean is created in the Spring contextvoidclose()Closes the Mongo instance used by MongoBumblebee.voidexecute()Executing migrationbooleanbooleansetChangelogCollectionName(String changelogCollectionName) Overwrites a default MongoBumblebee changelog collection hardcoded in DEFAULT_CHANGELOG_COLLECTION_NAME.setChangeLogLockPollRate(long changeLogLockPollRate) Poll rate for acquiring lock if waitForLock is truesetChangeLogLockWaitTime(long changeLogLockWaitTime) Waiting time for acquiring lock if waitForLock is truesetChangeLogsScanPackage(String changeLogsScanPackage) Package name where @ChangeLog-annotated classes are kept.setEnabled(boolean enabled) Feature which enables/disables MongoBumblebee runner executionsetLockCollectionName(String lockCollectionName) Overwrites a default MongoBumblebee lock collection hardcoded in DEFAULT_LOCK_COLLECTION_NAMEsetSpringEnvironment(org.springframework.core.env.Environment environment) Set Environment object for Spring Profiles (@Profile) integrationsetThrowExceptionIfCannotObtainLock(boolean throwExceptionIfCannotObtainLock) Feature which enables/disables throwing MongoBumblebeeLockException if MongoBumblebee can not obtain locksetWaitForLock(boolean waitForLock) Feature which enables/disables waiting for lock if it's already obtained
-
Field Details
-
MB_PREFIX
- See Also:
-
DEFAULT_WAIT_FOR_LOCK
public static final boolean DEFAULT_WAIT_FOR_LOCK- See Also:
-
DEFAULT_CHANGE_LOG_LOCK_WAIT_TIME
public static final long DEFAULT_CHANGE_LOG_LOCK_WAIT_TIMEWaiting time (in minutes)- See Also:
-
DEFAULT_CHANGE_LOG_LOCK_POLL_RATE
public static final long DEFAULT_CHANGE_LOG_LOCK_POLL_RATETime between two polls to aquire the lock (in seconds)- See Also:
-
DEFAULT_THROW_EXCEPTION_IF_CANNOT_OBTAIN_LOCK
public static final boolean DEFAULT_THROW_EXCEPTION_IF_CANNOT_OBTAIN_LOCK- See Also:
-
-
Constructor Details
-
MongoBumblebee
Constructor takes MongoClient object as a parameter.
For more details about
MongoClientplease see com.mongodb.client.MongoClient docs- Parameters:
mongoClient- database connection clientdbName- Database name- See Also:
-
MongoClient
-
MongoBumblebee
MongoBumblebee runner. Correct MongoDB URI should be provided.
The format of the URI is:
mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database[.collection]][?options]]
mongodb://Required prefixusername:password@are optional. If given, the driver will attempt to login to a database after connecting to a database server. For some authentication mechanisms, only the username is specified and the password is not, in which case the ":" after the username is left off as well.host1Required. It identifies a server address to connect to. More than one host can be provided.:portXis optional and defaults to :27017 if not provided./databasethe name of the database to login to and thus is only relevant if theusername:password@syntax is used. If not specified the "admin" database will be used by default. MongoBumblebee will operate on the database provided here or on the database overriden by setter setDbName(String).?optionsare connection options. For list of options please see com.mongodb.MongoClientURI docs
For details, please see com.mongodb.MongoClientURI
- Parameters:
mongoURI- with correct format
-
-
Method Details
-
afterPropertiesSet
For Spring users: executing MongoBumblebee after bean is created in the Spring context- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Throws:
Exception- exception
-
execute
Executing migration- Throws:
MongoBumblebeeException- exception
-
isExecutionInProgress
- Returns:
- true if an execution is in progress, in any process.
- Throws:
MongoBumblebeeConnectionException- exception
-
setChangeLogsScanPackage
Package name where @ChangeLog-annotated classes are kept.- Parameters:
changeLogsScanPackage- package where your changelogs are- Returns:
- MongoBumblebee object for fluent interface
-
isEnabled
public boolean isEnabled()- Returns:
- true if MongoBumblebee runner is enabled and able to run, otherwise false
-
setEnabled
Feature which enables/disables MongoBumblebee runner execution- Parameters:
enabled- MongoBumblebee will run only if this option is set to true- Returns:
- MongoBumblebee object for fluent interface
-
setWaitForLock
Feature which enables/disables waiting for lock if it's already obtained- Parameters:
waitForLock- MongoBumblebee will be waiting for lock if it's already obtained if this option is set to true- Returns:
- MongoBumblebee object for fluent interface
-
setChangeLogLockWaitTime
Waiting time for acquiring lock if waitForLock is true- Parameters:
changeLogLockWaitTime- Waiting time in minutes for acquiring lock- Returns:
- MongoBumblebee object for fluent interface
-
setChangeLogLockPollRate
Poll rate for acquiring lock if waitForLock is true- Parameters:
changeLogLockPollRate- Poll rate in seconds for acquiring lock- Returns:
- MongoBumblebee object for fluent interface
-
setThrowExceptionIfCannotObtainLock
Feature which enables/disables throwing MongoBumblebeeLockException if MongoBumblebee can not obtain lock- Parameters:
throwExceptionIfCannotObtainLock- MongoBumblebee will throw MongoBumblebeeLockException if lock can not be obtained- Returns:
- MongoBumblebee object for fluent interface
-
setSpringEnvironment
Set Environment object for Spring Profiles (@Profile) integration- Parameters:
environment- org.springframework.core.env.Environment object to inject- Returns:
- MongoBumblebee object for fluent interface
-
setChangelogCollectionName
Overwrites a default MongoBumblebee changelog collection hardcoded in DEFAULT_CHANGELOG_COLLECTION_NAME. CAUTION! Use this method carefully - when changing the name on a existing system, your changelogs will be executed again on your MongoDB instance- Parameters:
changelogCollectionName- a new changelog collection name- Returns:
- MongoBumblebee object for fluent interface
-
setLockCollectionName
Overwrites a default MongoBumblebee lock collection hardcoded in DEFAULT_LOCK_COLLECTION_NAME- Parameters:
lockCollectionName- a new lock collection name- Returns:
- MongoBumblebee object for fluent interface
-
close
public void close()Closes the Mongo instance used by MongoBumblebee. This will close either the connection MongoBumblebee was initiated with or that which was internally created.
-