Search in sources :

Example 6 with KeyNotFoundException

use of com.sun.messaging.bridge.api.KeyNotFoundException 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 7 with KeyNotFoundException

use of com.sun.messaging.bridge.api.KeyNotFoundException 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 8 with KeyNotFoundException

use of com.sun.messaging.bridge.api.KeyNotFoundException 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 9 with KeyNotFoundException

use of com.sun.messaging.bridge.api.KeyNotFoundException 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

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