Class MongoBumblebee

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 Details

    • MB_PREFIX

      public static final String 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_TIME
      Waiting time (in minutes)
      See Also:
    • DEFAULT_CHANGE_LOG_LOCK_POLL_RATE

      public static final long DEFAULT_CHANGE_LOG_LOCK_POLL_RATE
      Time 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

      public MongoBumblebee(@NonNull com.mongodb.client.MongoClient mongoClient, @NonNull String dbName)

      Constructor takes MongoClient object as a parameter.

      For more details about MongoClient please see com.mongodb.client.MongoClient docs

      Parameters:
      mongoClient - database connection client
      dbName - Database name
      See Also:
      • MongoClient
    • MongoBumblebee

      public MongoBumblebee(@NonNull String mongoURI, @NonNull String dbName)

      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 prefix
      • username: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.
      • host1 Required. It identifies a server address to connect to. More than one host can be provided.
      • :portX is optional and defaults to :27017 if not provided.
      • /database the name of the database to login to and thus is only relevant if the username: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).
      • ?options are 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

      public void afterPropertiesSet() throws Exception
      For Spring users: executing MongoBumblebee after bean is created in the Spring context
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
      Throws:
      Exception - exception
    • execute

      public void execute() throws MongoBumblebeeException
      Executing migration
      Throws:
      MongoBumblebeeException - exception
    • isExecutionInProgress

      public boolean isExecutionInProgress() throws MongoBumblebeeConnectionException
      Returns:
      true if an execution is in progress, in any process.
      Throws:
      MongoBumblebeeConnectionException - exception
    • setChangeLogsScanPackage

      public MongoBumblebee setChangeLogsScanPackage(String changeLogsScanPackage)
      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

      public MongoBumblebee setEnabled(boolean enabled)
      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

      public MongoBumblebee setWaitForLock(boolean waitForLock)
      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

      public MongoBumblebee setChangeLogLockWaitTime(long changeLogLockWaitTime)
      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

      public MongoBumblebee setChangeLogLockPollRate(long changeLogLockPollRate)
      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

      public MongoBumblebee setThrowExceptionIfCannotObtainLock(boolean throwExceptionIfCannotObtainLock)
      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

      public MongoBumblebee setSpringEnvironment(org.springframework.core.env.Environment environment)
      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

      public MongoBumblebee setChangelogCollectionName(String changelogCollectionName)
      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

      public MongoBumblebee setLockCollectionName(String lockCollectionName)
      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.