Search in sources :

Example 6 with DBManager

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

the class TMLogRecordDAOJMSBG method insert.

/**
 * @param conn database connection
 * @param xid the global XID
 * @param logRecord log record data
 * @param name the jmsbridge name
 * @param logger_ can be null
 * @throws DupKeyException if already exist else Exception on error
 */
@Override
public void insert(Connection conn, String xid, byte[] logRecord, 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, xid);
            pstmt.setBytes(2, logRecord);
            pstmt.setString(3, name);
            pstmt.setString(4, dbMgr.getBrokerID());
            pstmt.setLong(5, System.currentTimeMillis());
            pstmt.setLong(6, 0L);
            pstmt.executeUpdate();
        } catch (Exception e) {
            myex = e;
            try {
                if (!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, xid, 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) 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 7 with DBManager

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

the class TMLogRecordDAOJMSBG method getUpdatedTime.

/**
 * @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 getUpdatedTime(Connection conn, String xid, 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, xid);
        rs = pstmt.executeQuery();
        if (!rs.next()) {
            throw new KeyNotFoundException("TM Log record not found in store for xid " + xid);
        }
        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) 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 8 with DBManager

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

the class JMSBGDAOImpl method getBrokerId.

/**
 * @param conn database connection
 * @param name jmsbridge name
 * @param logger_ can be null;
 * @throws KeyNotFoundException if not found else Exception on error
 */
@Override
public String getBrokerId(Connection conn, String name, java.util.logging.Logger logger_) throws Exception {
    String brokerId = 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, selectBrokerIdSQL);
        pstmt.setString(1, name);
        rs = pstmt.executeQuery();
        if (!rs.next()) {
            throw new KeyNotFoundException("Name " + name + " not found in store");
        }
        brokerId = 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 + "[" + selectBrokerIdSQL + "]", rbe);
        }
        throw e;
    } finally {
        closeSQL(rs, pstmt, myconn, myex, logger_);
    }
    return brokerId;
}
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 9 with DBManager

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

the class JMSBGDAOImpl method delete.

/**
 * @param conn database connection
 * @param name to identify the TM
 * @param logger_ can be null;
 * @throws KeyNotFoundException if not found else Exception on error
 */
@Override
public void delete(Connection conn, String name, java.util.logging.Logger logger_) throws 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, name);
        pstmt.setString(2, dbMgr.getBrokerID());
        if (pstmt.executeUpdate() == 0) {
            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 10 with DBManager

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

the class JMSBGDAOImpl method getNamesByBroker.

/**
 * @param conn database connection
 * @param logger_ can be null;
 * @return list of names
 */
@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, selectNamesByBrokerIdSQL);
        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 + "[" + selectNamesByBrokerIdSQL + "]", rbe);
        }
        throw e;
    } finally {
        closeSQL(rs, pstmt, myconn, myex, logger_);
    }
    return list;
}
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)

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