Package org.cyclos.bootstrap
Class DatabaseManager
- java.lang.Object
-
- org.cyclos.bootstrap.DatabaseManager
-
@Component("databaseManager") public class DatabaseManager extends Object
Applies the checks / automatic upgrade on the cyclos database. This class cannot inject either theJpaTransactionManagerorTransactionTemplatebecause it is used in the middle of theEntityManagerFactorycreation, and theJpaTransactionManagerrequires theEntityManagerFactoryto be ready.
-
-
Field Summary
Fields Modifier and Type Field Description static StringUNLOCK_DATABASESQL command to manually unlock the database
-
Constructor Summary
Constructors Constructor Description DatabaseManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddoWithCyclosInstanceLock(Runnable action)Prevents 2 Cyclos instances (even in a cluster) to execute the given action concurrentlyvoidinitialize()booleanisDatabaseLocked()Returns whether some Cyclos instance is currently locking this databasevoidlockDatabase(String hostId)Locks the applicationvoidmanageDatabase(javax.persistence.EntityManagerFactory emf)Apply the database management checksvoidprepareDatabaseLock()Makes sure that the database lock mechanism has the required database objectsvoidunlockDatabase()Updates the database to mark it as no Cyclos instance running
-
-
-
Field Detail
-
UNLOCK_DATABASE
public static final String UNLOCK_DATABASE
SQL command to manually unlock the database- See Also:
- Constant Field Values
-
-
Method Detail
-
doWithCyclosInstanceLock
public void doWithCyclosInstanceLock(Runnable action)
Prevents 2 Cyclos instances (even in a cluster) to execute the given action concurrently
-
initialize
@PostConstruct public void initialize()
-
isDatabaseLocked
public boolean isDatabaseLocked()
Returns whether some Cyclos instance is currently locking this database
-
lockDatabase
public void lockDatabase(String hostId)
Locks the application
-
manageDatabase
public void manageDatabase(javax.persistence.EntityManagerFactory emf) throws SQLExceptionApply the database management checks- Throws:
SQLException
-
prepareDatabaseLock
public void prepareDatabaseLock()
Makes sure that the database lock mechanism has the required database objects
-
unlockDatabase
public void unlockDatabase()
Updates the database to mark it as no Cyclos instance running
-
-