Search in sources :

Example 11 with DBManager

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

the class JMSBGDAOImpl method deleteAll.

/**
 * Delete all entries for this broker
 *
 * @param conn database connection
 */
@Override
public void deleteAll(Connection conn) throws BrokerException {
    DBManager dbMgr = DBManager.getDBManager();
    String whereClause = new StringBuilder(128).append(BROKER_ID_COLUMN).append(" = '").append(dbMgr.getBrokerID()).append('\'').toString();
    deleteAll(conn, whereClause, null, 0);
}
Also used : DBManager(com.sun.messaging.jmq.jmsserver.persist.jdbc.DBManager)

Example 12 with DBManager

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

the class JMSBGDAOImpl method getCreatedTime.

/**
 * @param conn database connection
 * @param name jmsbridge name
 * @param logger_ can be null;
 * @throws KeyNotFoundException if not found else Exception on error
 */
@Override
public long getCreatedTime(Connection conn, String name, java.util.logging.Logger logger_) throws KeyNotFoundException, Exception {
    long createdTime = -1;
    Connection myconn = conn;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    Exception myex = null;
    try {
        DBManager dbMgr = DBManager.getDBManager();
        if (conn == null) {
            conn = dbMgr.getConnection(true);
            myconn = conn;
        }
        pstmt = dbMgr.createPreparedStatement(conn, selectCreatedTimeSQL);
        pstmt.setString(1, name);
        rs = pstmt.executeQuery();
        if (!rs.next()) {
            throw new KeyNotFoundException("Name " + name + " not found in store");
        }
        createdTime = rs.getLong(1);
    } catch (Exception e) {
        myex = e;
        try {
            if ((conn != null) && !conn.getAutoCommit()) {
                conn.rollback();
            }
        } catch (SQLException rbe) {
            logger.log(Logger.ERROR, BrokerResources.X_DB_ROLLBACK_FAILED + "[" + selectCreatedTimeSQL + "]", rbe);
        }
        throw e;
    } finally {
        closeSQL(rs, pstmt, myconn, myex, logger_);
    }
    return createdTime;
}
Also used : DBManager(com.sun.messaging.jmq.jmsserver.persist.jdbc.DBManager) KeyNotFoundException(com.sun.messaging.bridge.api.KeyNotFoundException) StoreBeingTakenOverException(com.sun.messaging.jmq.jmsserver.util.StoreBeingTakenOverException) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) DupKeyException(com.sun.messaging.bridge.api.DupKeyException) KeyNotFoundException(com.sun.messaging.bridge.api.KeyNotFoundException)

Example 13 with DBManager

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

the class JMSBGDAOImpl method updateBrokerId.

/**
 * @param conn database connection
 * @param name jmsbridge name
 * @param logger_ can be null
 * @throws KeyNotFoundException if not found StoreBeingTakenOverException if being takeover Exception on any other error
 */
@Override
public void updateBrokerId(Connection conn, String name, String newBrokerId, String expectedBrokerId, java.util.logging.Logger logger_) throws KeyNotFoundException, StoreBeingTakenOverException, Exception {
    Connection myconn = null;
    PreparedStatement pstmt = null;
    Exception myex = null;
    try {
        DBManager dbMgr = DBManager.getDBManager();
        if (conn == null) {
            conn = dbMgr.getConnection(true);
            myconn = conn;
        }
        pstmt = dbMgr.createPreparedStatement(conn, updateBrokerIdSQL);
        pstmt.setString(1, newBrokerId);
        pstmt.setLong(2, System.currentTimeMillis());
        pstmt.setString(3, name);
        pstmt.setString(4, expectedBrokerId);
        if (Globals.getHAEnabled()) {
            pstmt.setString(5, dbMgr.getBrokerID());
        }
        if (pstmt.executeUpdate() == 0) {
            Util.checkBeingTakenOver(conn, dbMgr, logger, logger_);
            throw new KeyNotFoundException("Name " + name + " not found in store");
        }
    } catch (Exception e) {
        myex = e;
        try {
            if ((conn != null) && !conn.getAutoCommit()) {
                conn.rollback();
            }
        } catch (SQLException e1) {
            String emsg = BrokerResources.X_DB_ROLLBACK_FAILED;
            logger.log(Logger.ERROR, emsg, e1);
            Util.logExt(logger_, java.util.logging.Level.SEVERE, emsg, e1);
        }
        throw e;
    } finally {
        closeSQL(null, pstmt, myconn, myex, logger_);
    }
}
Also used : DBManager(com.sun.messaging.jmq.jmsserver.persist.jdbc.DBManager) KeyNotFoundException(com.sun.messaging.bridge.api.KeyNotFoundException) StoreBeingTakenOverException(com.sun.messaging.jmq.jmsserver.util.StoreBeingTakenOverException) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) DupKeyException(com.sun.messaging.bridge.api.DupKeyException) KeyNotFoundException(com.sun.messaging.bridge.api.KeyNotFoundException)

Example 14 with DBManager

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

the class JMSBGDAOImpl method insert.

/**
 * @param conn database connection
 * @param name to identify the TM
 * @param logger_ can be null
 * @throws DupKeyException if already exist else Exception on error
 */
@Override
public void insert(Connection conn, String name, java.util.logging.Logger logger_) throws DupKeyException, Exception {
    Connection myconn = null;
    PreparedStatement pstmt = null;
    Exception myex = null;
    try {
        DBManager dbMgr = DBManager.getDBManager();
        if (conn == null) {
            conn = dbMgr.getConnection(true);
            myconn = conn;
        }
        try {
            pstmt = dbMgr.createPreparedStatement(conn, insertSQL);
            pstmt.setString(1, name);
            pstmt.setString(2, dbMgr.getBrokerID());
            pstmt.setLong(3, System.currentTimeMillis());
            pstmt.setLong(4, 0L);
            pstmt.executeUpdate();
        } catch (Exception e) {
            myex = e;
            try {
                if ((conn != null) && !conn.getAutoCommit()) {
                    conn.rollback();
                }
            } catch (SQLException e1) {
                String emsg = BrokerResources.X_DB_ROLLBACK_FAILED;
                logger.log(Logger.ERROR, emsg, e1);
                Util.logExt(logger_, java.util.logging.Level.SEVERE, emsg, e1);
            }
            checkDupKeyOnException(conn, name, logger_);
            throw e;
        }
    } catch (Exception e) {
        myex = e;
        throw e;
    } finally {
        closeSQL(null, pstmt, myconn, myex, logger_);
    }
}
Also used : DBManager(com.sun.messaging.jmq.jmsserver.persist.jdbc.DBManager) KeyNotFoundException(com.sun.messaging.bridge.api.KeyNotFoundException) StoreBeingTakenOverException(com.sun.messaging.jmq.jmsserver.util.StoreBeingTakenOverException) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) DupKeyException(com.sun.messaging.bridge.api.DupKeyException)

Example 15 with DBManager

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

the class TMLogRecordDAOJMSBG method getLogRecordsByNameByBroker.

/**
 * @param conn database connection
 * @param name the jmsbridge name
 * @param logger_ can be null;
 * @return a list of log records
 * @throws Exception if error
 */
@Override
public List getLogRecordsByNameByBroker(Connection conn, String name, String brokerID, java.util.logging.Logger logger_) throws Exception {
    List list = new ArrayList();
    Connection myconn = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    Exception myex = null;
    try {
        DBManager dbMgr = DBManager.getDBManager();
        if (conn == null) {
            conn = dbMgr.getConnection(true);
            myconn = conn;
        }
        pstmt = dbMgr.createPreparedStatement(conn, selectLogRecordsByNameByBrokerSQL);
        pstmt.setString(1, name);
        pstmt.setString(2, brokerID);
        rs = pstmt.executeQuery();
        while (rs.next()) {
            list.add(Util.readBytes(rs, 2));
        }
    } catch (Exception e) {
        myex = e;
        try {
            if ((conn != null) && !conn.getAutoCommit()) {
                conn.rollback();
            }
        } catch (SQLException rbe) {
            logger.log(Logger.ERROR, BrokerResources.X_DB_ROLLBACK_FAILED + "[" + selectLogRecordsByNameByBrokerSQL + "]", rbe);
        }
        throw e;
    } finally {
        closeSQL(rs, pstmt, myconn, myex, logger_);
    }
    return list;
}
Also used : DBManager(com.sun.messaging.jmq.jmsserver.persist.jdbc.DBManager) DupKeyException(com.sun.messaging.bridge.api.DupKeyException) KeyNotFoundException(com.sun.messaging.bridge.api.KeyNotFoundException) StoreBeingTakenOverException(com.sun.messaging.jmq.jmsserver.util.StoreBeingTakenOverException) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException)

Aggregations

DBManager (com.sun.messaging.jmq.jmsserver.persist.jdbc.DBManager)18 DupKeyException (com.sun.messaging.bridge.api.DupKeyException)15 KeyNotFoundException (com.sun.messaging.bridge.api.KeyNotFoundException)15 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)15 StoreBeingTakenOverException (com.sun.messaging.jmq.jmsserver.util.StoreBeingTakenOverException)15