Search in sources :

Example 6 with BaseDAO

use of com.sun.messaging.jmq.jmsserver.persist.jdbc.comm.BaseDAO in project openmq by eclipse-ee4j.

the class DBTool method createTables.

// if tableDAOs != null, only create these tables
// else create current version of persist store
static void createTables(Connection conn, boolean continueOnError, ArrayList tableDAOs, CommDBManager mgrArg) throws BrokerException {
    CommDBManager mgr = mgrArg;
    if (mgr == null) {
        mgr = DBManager.getDBManager();
    }
    Iterator itr = null;
    if (tableDAOs != null) {
        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);
                    // table created so break from retry loop
                    break;
                } 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)) {
                // 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) {
                // Re-throw the exception
                throw be;
            }
        } else {
            // Re-throw the exception
            throw be;
        }
    }
    // 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.TRUE);
    if (JDBCStore.ENABLE_STORED_PROC) {
        createStoredProcs(conn);
    }
}
Also used : BaseDAO(com.sun.messaging.jmq.jmsserver.persist.jdbc.comm.BaseDAO) StringUtil(com.sun.messaging.jmq.util.StringUtil) CommDBManager(com.sun.messaging.jmq.jmsserver.persist.jdbc.comm.CommDBManager) ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID) DestinationUID(com.sun.messaging.jmq.jmsserver.core.DestinationUID) UID(com.sun.messaging.jmq.util.UID) TransactionUID(com.sun.messaging.jmq.jmsserver.data.TransactionUID) ShareConfigChangeDBManager(com.sun.messaging.jmq.jmsserver.persist.jdbc.sharecc.ShareConfigChangeDBManager) CommDBManager(com.sun.messaging.jmq.jmsserver.persist.jdbc.comm.CommDBManager) ShareConfigChangeDBManager(com.sun.messaging.jmq.jmsserver.persist.jdbc.sharecc.ShareConfigChangeDBManager)

Aggregations

BaseDAO (com.sun.messaging.jmq.jmsserver.persist.jdbc.comm.BaseDAO)6 CommDBManager (com.sun.messaging.jmq.jmsserver.persist.jdbc.comm.CommDBManager)5 StringUtil (com.sun.messaging.jmq.util.StringUtil)4 ShareConfigChangeDBManager (com.sun.messaging.jmq.jmsserver.persist.jdbc.sharecc.ShareConfigChangeDBManager)2 DupKeyException (com.sun.messaging.bridge.api.DupKeyException)1 KeyNotFoundException (com.sun.messaging.bridge.api.KeyNotFoundException)1 ConsumerUID (com.sun.messaging.jmq.jmsserver.core.ConsumerUID)1 DestinationUID (com.sun.messaging.jmq.jmsserver.core.DestinationUID)1 TransactionUID (com.sun.messaging.jmq.jmsserver.data.TransactionUID)1 UID (com.sun.messaging.jmq.util.UID)1