Search in sources :

Example 1 with DupKeyException

use of com.sun.messaging.bridge.api.DupKeyException in project openmq by eclipse-ee4j.

the class TMLogRecordDAOJMSBG method checkDupKeyOnException.

/**
 * To be called when exception occurred on a connection
 *
 * @Exception DupKeyException if xid already exists
 */
private void checkDupKeyOnException(Connection conn, String xid, java.util.logging.Logger logger_) throws DupKeyException {
    if (conn == null) {
        return;
    }
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    Exception myex = null;
    try {
        pstmt = DBManager.getDBManager().createPreparedStatement(conn, selectCreatedTimeSQL);
        pstmt.setString(1, xid);
        rs = pstmt.executeQuery();
        if (rs.next()) {
            throw new DupKeyException("Xid " + xid + " already exists in DB");
        }
    } catch (Exception e) {
        myex = e;
        try {
            if (!conn.getAutoCommit()) {
                conn.rollback();
            }
        } catch (SQLException rbe) {
            logger.log(Logger.ERROR, BrokerResources.X_DB_ROLLBACK_FAILED + "[" + selectCreatedTimeSQL + "]", rbe);
        }
        if (e instanceof DupKeyException) {
            throw (DupKeyException) e;
        }
        String emsg = br.getKString(BrokerResources.X_INTERNAL_EXCEPTION, "Exception on checkDupKey for xid " + xid);
        logger.log(Logger.WARNING, emsg, e);
        Util.logExt(logger_, java.util.logging.Level.WARNING, emsg, e);
    } finally {
        closeSQL(rs, pstmt, null, myex, logger_);
    }
}
Also used : DupKeyException(com.sun.messaging.bridge.api.DupKeyException) 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 2 with DupKeyException

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

use of com.sun.messaging.bridge.api.DupKeyException in project openmq by eclipse-ee4j.

the class BridgeServiceManagerImpl method init.

/**
 * Initialize the bridge service manager
 */
@Override
public synchronized void init(BridgeBaseContext ctx) throws Exception {
    com.sun.messaging.jmq.jmsclient.Debug.setUseLogger(true);
    FaultInjection.setBridgeBaseContext(ctx);
    _bc = ctx;
    Properties props = _bc.getBridgeConfig();
    String activekey = props.getProperty(BridgeBaseContext.PROP_PREFIX) + ".activelist";
    List<String> alist = BridgeUtil.getListProperty(activekey, props);
    int size = alist.size();
    String name = null;
    Iterator<String> itr = alist.iterator();
    while (itr.hasNext()) {
        name = itr.next();
        try {
            loadBridge(name);
        } catch (BridgeException e) {
            if (e.getStatus() == Status.NOT_MODIFIED) {
                continue;
            }
            _bc.logError(_bmr.getKString(_bmr.E_LOAD_BRIDGE_FAILED, name, e.getMessage()), null);
            throw e;
        }
    }
    if (_bc.isHAEnabled()) {
        JMSBridgeStore store = (JMSBridgeStore) _bc.getJDBCStore();
        if (store == null) {
            throw new BridgeException("null JDBC store");
        }
        List jmsbridges = store.getJMSBridges(null);
        name = null;
        itr = alist.iterator();
        while (itr.hasNext()) {
            name = itr.next();
            String type = props.getProperty(props.getProperty(BridgeBaseContext.PROP_PREFIX) + "." + name + ".type");
            if (type == null) {
                throw new BridgeException(_bmr.getString(_bmr.X_BRIDGE_NO_TYPE, name));
            }
            if (!type.trim().toUpperCase(_bmr.getLocale()).equals(Bridge.JMS_TYPE)) {
                continue;
            }
            if (jmsbridges.contains(name)) {
                continue;
            }
            try {
                store.addJMSBridge(name, true, null);
            } catch (DupKeyException e) {
                _bc.logInfo(_bmr.getKString(_bmr.I_JMSBRIDGE_NOT_OWNER, name), null);
                itr.remove();
            }
        }
        jmsbridges = store.getJMSBridges(null);
        itr = jmsbridges.iterator();
        while (itr.hasNext()) {
            name = itr.next();
            if (alist.contains(name)) {
                continue;
            }
            alist.add(name);
            try {
                loadBridge(name);
            } catch (BridgeException e) {
                _bc.logError(_bmr.getKString(_bmr.E_LOAD_BRIDGE_FAILED, name, e.getMessage()), null);
                throw e;
            }
        }
        if (alist.size() != size) {
            StringBuilder sb = new StringBuilder();
            int i = 0;
            itr = alist.iterator();
            while (itr.hasNext()) {
                if (i > 0) {
                    sb.append(',');
                }
                sb.append(itr.next());
                i++;
            }
            Properties p = new Properties();
            p.setProperty(activekey, sb.toString());
            _bc.updateBridgeConfig(p);
        }
    }
    String keyu = props.getProperty(BridgeBaseContext.PROP_PREFIX) + ctx.PROP_ADMIN_USER_SUFFIX;
    String keyp = props.getProperty(BridgeBaseContext.PROP_PREFIX) + ctx.PROP_ADMIN_PASSWORD_SUFFIX;
    _user = props.getProperty(keyu);
    _passwd = props.getProperty(keyp);
    if (_user == null || _user.trim().length() == 0) {
        throw new JMSException(_bmr.getString(_bmr.X_BRIDGE_NO_ADMIN_USER, keyu));
    }
    _user = _user.trim();
    if (_passwd == null || _passwd.trim().length() == 0) {
        throw new JMSException(_bmr.getString(_bmr.X_BRIDGE_NO_ADMIN_PASSWORD, keyp));
    }
    _passwd = _passwd.trim();
    _adminHandler = new AdminMessageHandler(this);
    _state = State.STOPPED;
}
Also used : BridgeException(com.sun.messaging.bridge.api.BridgeException) AdminMessageHandler(com.sun.messaging.bridge.admin.handlers.AdminMessageHandler) DupKeyException(com.sun.messaging.bridge.api.DupKeyException) JMSBridgeStore(com.sun.messaging.bridge.api.JMSBridgeStore) ArrayList(java.util.ArrayList) List(java.util.List) Properties(java.util.Properties)

Example 4 with DupKeyException

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

Aggregations

DupKeyException (com.sun.messaging.bridge.api.DupKeyException)4 KeyNotFoundException (com.sun.messaging.bridge.api.KeyNotFoundException)3 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)3 StoreBeingTakenOverException (com.sun.messaging.jmq.jmsserver.util.StoreBeingTakenOverException)3 DBManager (com.sun.messaging.jmq.jmsserver.persist.jdbc.DBManager)2 AdminMessageHandler (com.sun.messaging.bridge.admin.handlers.AdminMessageHandler)1 BridgeException (com.sun.messaging.bridge.api.BridgeException)1 JMSBridgeStore (com.sun.messaging.bridge.api.JMSBridgeStore)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Properties (java.util.Properties)1