itr = tableDAOs.iterator();
} else {
itr = mgr.allDAOIterator();
}
while ( itr.hasNext() ) {
BaseDAO dao = (BaseDAO)itr.next();
try {
Util.RetryStrategy retry = null;
do {
try {
dao.createTable( conn );
break; // table created so break from retry loop
} catch ( Exception e ) {
// Exception will be log & re-throw if operation cannot be retry
if ( retry == null ) {
retry = new Util.RetryStrategy(mgr);
}
retry.assertShouldRetry( e );
}
} while ( true );
} catch (BrokerException be) {
if ( Globals.getHAEnabled() ||
(mgr instanceof ShareConfigChangeDBManager) ) {
// Paused for a few secs to prevent race condition when two
// or more brokers try to create the tables at the same time
try {
Thread.sleep(5000);
} catch (InterruptedException e) {}
}
// Verify if the store has already been created
if ( mgr.checkStoreExists( conn ) > 0 ) {
if (tableDAOs == null) {
Globals.getLogger().log(Logger.WARNING,
BrokerResources.E_CREATE_DATABASE_TABLE_FAILED,
Globals.getBrokerResources().getString(
BrokerResources.E_DATABASE_TABLE_ALREADY_CREATED));
continueOnError = true;
} else {
Globals.getLogger().log(Logger.WARNING,
BrokerResources.E_CREATE_DATABASE_TABLE_FAILED,
Globals.getBrokerResources().getString(
BrokerResources.E_THE_DATABASE_TABLE_ALREADY_CREATED, dao.getTableName()));
}
break;
} else if (continueOnError) {
// Just log msg and continue
Globals.getLogger().log(Logger.WARNING, be.toString(), be.getCause());
} else {
throw be;
}
}
}
if ( tableDAOs != null || !(mgr instanceof DBManager) ) {
return;
}
DAOFactory daoFactory = ((DBManager)mgr).getDAOFactory();
// Insert version info in the version table
VersionDAO versionDAO = daoFactory.getVersionDAO();
try {
if ( continueOnError ) {
// Do this only if version is missing from version table
int storeVersion = versionDAO.getStoreVersion( conn );
if ( storeVersion != JDBCStore.STORE_VERSION ) {
versionDAO.insert( conn, JDBCStore.STORE_VERSION );
}
} else {
versionDAO.insert( conn, JDBCStore.STORE_VERSION );
}
} catch (BrokerException be) {
if ( Globals.getHAEnabled() ) {
// Re-check if version info has been added by another broker
int storeVersion = versionDAO.getStoreVersion( conn );
if ( storeVersion != JDBCStore.STORE_VERSION ) {
throw be; // Re-throw the exception
}
} else {
throw be; // Re-throw the exception
}
}
// Insert a unique store session for the stand-alone broker
if ( !Globals.getHAEnabled() ) {
// Do this only if store session is missing from session table
String brokerID = Globals.getBrokerID();
StoreSessionDAO sessionDAO = daoFactory.getStoreSessionDAO();
if ( sessionDAO.getStoreSession( conn, brokerID ) <= 0 ) {
sessionDAO.insert( conn, brokerID, new UID().longValue(), true );
}
}
PropertyDAO dao = daoFactory.getPropertyDAO();
dao.update( conn, STORE_PROPERTY_SUPPORT_JMSBRIDGE, Boolean.valueOf(true));
}