Search in sources :

Example 16 with DBManager

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

the class TMLogRecordDAOJMSBG method deleteAllByName.

/**
 * Delete all by jmsbridge name for this broker
 *
 * @param conn database connection
 * @param name the jmsbridge name
 * @param logger_ can be null;
 * @throws KeyNotFoundException if not found else Exception on error
 */
@Override
public void deleteAllByName(Connection conn, String name, java.util.logging.Logger logger_) throws KeyNotFoundException, Exception {
    DBManager dbMgr = DBManager.getDBManager();
    String whereClause = new StringBuilder(128).append(BROKER_ID_COLUMN).append(" = '").append(dbMgr.getBrokerID()).append('\'').append(" AND ").append(NAME_COLUMN).append(" = '").append(name).append('\'').toString();
    deleteAll(conn, whereClause, null, 0);
}
Also used : DBManager(com.sun.messaging.jmq.jmsserver.persist.jdbc.DBManager)

Example 17 with DBManager

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

the class TMLogRecordDAOJMSBG method updateLogRecord.

/**
 * @param conn database connection
 * @param xid the global xid
 * @param logRecord log record data
 * @param name the jmsbridge name
 * @param callback to obtain updated data
 * @param logger_ can be null
 * @throws KeyNotFoundException if not found and addIfNotExist false StoreBeingTakenOverException if being takeover else
 * Exception on error
 */
@Override
public void updateLogRecord(Connection conn, String xid, byte[] logRecord, String name, UpdateOpaqueDataCallback callback, boolean addIfNotExist, 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(false);
            myconn = conn;
        }
        if (conn.getAutoCommit()) {
            throw new BrokerException("Broker Internal Error: Unexpected auto commit SQL connection for update TM log record: " + xid);
        }
        byte[] currLogRecord = null;
        currLogRecord = getLogRecord(conn, xid, name, logger_);
        if (currLogRecord == null) {
            if (addIfNotExist) {
                insert(conn, xid, logRecord, name, logger_);
                return;
            }
            throw new KeyNotFoundException("TM log record not found for " + xid);
        }
        byte[] newLogRecord = (byte[]) callback.update(currLogRecord);
        pstmt = dbMgr.createPreparedStatement(conn, updateLogRecordSQL);
        pstmt.setBytes(1, newLogRecord);
        pstmt.setLong(2, System.currentTimeMillis());
        pstmt.setString(3, xid);
        pstmt.setString(4, dbMgr.getBrokerID());
        if (pstmt.executeUpdate() == 0) {
            Util.checkBeingTakenOver(conn, dbMgr, logger, logger_);
            throw new BrokerException(br.getKString("TM Log record not found in store for " + xid), Status.NOT_FOUND);
        }
        if (myconn != null) {
            conn.commit();
        }
    } 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) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) 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 18 with DBManager

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

the class TMLogRecordDAOJMSBG method delete.

/**
 * @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 void delete(Connection conn, String xid, String name, java.util.logging.Logger logger_) throws KeyNotFoundException, 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, deleteSQL);
        pstmt.setString(1, xid);
        pstmt.setString(2, dbMgr.getBrokerID());
        if (pstmt.executeUpdate() == 0) {
            throw new KeyNotFoundException("TM log record not found in store for " + xid);
        }
    } 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) 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)

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