Search in sources :

Example 1 with DBManager

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

the class JMSBGDAOImpl method getUpdatedTime.

/**
 * @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 getUpdatedTime(Connection conn, String name, java.util.logging.Logger logger_) throws KeyNotFoundException, Exception {
    long updatedTime = -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, selectUpdatedTimeSQL);
        pstmt.setString(1, name);
        rs = pstmt.executeQuery();
        if (!rs.next()) {
            throw new KeyNotFoundException("Name " + name + " not found in store");
        }
        updatedTime = 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 + "[" + selectUpdatedTimeSQL + "]", rbe);
        }
        throw e;
    } finally {
        closeSQL(rs, pstmt, myconn, myex, logger_);
    }
    return updatedTime;
}
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 2 with DBManager

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

the class TMLogRecordDAOJMSBG 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 3 with DBManager

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

the class TMLogRecordDAOJMSBG method getLogRecord.

/**
 * @param conn database connection
 * @param xid the global xid
 * @param name the jmsbridge name
 * @param logger_ can be null;
 * @return null if not found
 */
@Override
public byte[] getLogRecord(Connection conn, String xid, String name, java.util.logging.Logger logger_) throws Exception {
    byte[] logRecord = null;
    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, selectLogRecordSQL);
        pstmt.setString(1, xid);
        pstmt.setString(2, dbMgr.getBrokerID());
        rs = pstmt.executeQuery();
        if (!rs.next()) {
            return null;
        }
        logRecord = Util.readBytes(rs, 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 + "[" + selectLogRecordSQL + "]", rbe);
        }
        throw e;
    } finally {
        closeSQL(rs, pstmt, myconn, myex, logger_);
    }
    return logRecord;
}
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)

Example 4 with DBManager

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

the class TMLogRecordDAOJMSBG method getCreatedTime.

/**
 * @param conn database connection
 * @param xid the global xid
 * @param name the jmsbridge name
 * @param logger_ can be null;
 * @throws KeyNotFoundException if not found else Exception on error
 */
@Override
public long getCreatedTime(Connection conn, String xid, 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, xid);
        rs = pstmt.executeQuery();
        if (!rs.next()) {
            throw new KeyNotFoundException("TM Log record not found in store for xid " + xid);
        }
        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) 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) KeyNotFoundException(com.sun.messaging.bridge.api.KeyNotFoundException)

Example 5 with DBManager

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

the class TMLogRecordDAOJMSBG method getNamesByBroker.

/**
 * @param conn database connection
 * @param logger_ can be null;
 * @return a list of names in all log records owned by the brokerID
 */
@Override
public List getNamesByBroker(Connection conn, 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, selectTMNamesByBrokerSQL);
        pstmt.setString(1, brokerID);
        rs = pstmt.executeQuery();
        while (rs.next()) {
            list.add(rs.getString(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 + "[" + selectTMNamesByBrokerSQL + "]", 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