Search in sources :

Example 6 with StoreException

use of org.apache.qpid.server.store.StoreException in project qpid-broker-j by apache.

the class AbstractJDBCConfigurationStore method openConfigurationStore.

@Override
public boolean openConfigurationStore(ConfiguredObjectRecordHandler handler, final ConfiguredObjectRecord... initialRecords) {
    changeState(CONFIGURED, OPEN);
    _deleteActions.clear();
    try {
        Collection<? extends ConfiguredObjectRecord> records = doVisitAllConfiguredObjectRecords(handler);
        boolean isNew = records.isEmpty();
        if (isNew) {
            records = Arrays.asList(initialRecords);
            try {
                try (Connection conn = newConnection()) {
                    for (ConfiguredObjectRecord record : records) {
                        updateConfiguredObject(record, true, conn);
                    }
                    conn.commit();
                }
            } catch (SQLException e) {
                throw new StoreException("Error updating configured objects in database: " + e.getMessage(), e);
            }
        }
        for (ConfiguredObjectRecord record : records) {
            handler.handle(record);
        }
        return isNew;
    } catch (SQLException e) {
        throw new StoreException("Cannot visit configured object records", e);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ConfiguredObjectRecord(org.apache.qpid.server.store.ConfiguredObjectRecord) StoreException(org.apache.qpid.server.store.StoreException)

Example 7 with StoreException

use of org.apache.qpid.server.store.StoreException in project qpid-broker-j by apache.

the class AbstractJDBCMessageStore method removeXid.

private void removeXid(ConnectionWrapper connWrapper, long format, byte[] globalId, byte[] branchId) throws StoreException {
    Connection conn = connWrapper.getConnection();
    try {
        try (PreparedStatement stmt = conn.prepareStatement("DELETE FROM " + getXidTableName() + " WHERE format = ? and global_id = ? and branch_id = ?")) {
            stmt.setLong(1, format);
            stmt.setBytes(2, globalId);
            stmt.setBytes(3, branchId);
            int results = stmt.executeUpdate();
            if (results != 1) {
                throw new StoreException("Unable to find message with xid");
            }
        }
        try (PreparedStatement stmt = conn.prepareStatement("DELETE FROM " + getXidActionsTableName() + " WHERE format = ? and global_id = ? and branch_id = ?")) {
            stmt.setLong(1, format);
            stmt.setBytes(2, globalId);
            stmt.setBytes(3, branchId);
            int results = stmt.executeUpdate();
        }
    } catch (SQLException e) {
        getLogger().error("Failed to remove xid", e);
        throw new StoreException("Error deleting enqueued message with xid", e);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) StoreException(org.apache.qpid.server.store.StoreException)

Example 8 with StoreException

use of org.apache.qpid.server.store.StoreException in project qpid-broker-j by apache.

the class AbstractJDBCMessageStore method commitTran.

private void commitTran(ConnectionWrapper connWrapper) throws StoreException {
    try {
        Connection conn = connWrapper.getConnection();
        conn.commit();
        getLogger().debug("commit tran completed");
        conn.close();
    } catch (SQLException e) {
        throw new StoreException("Error commit tx", e);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) StoreException(org.apache.qpid.server.store.StoreException)

Example 9 with StoreException

use of org.apache.qpid.server.store.StoreException in project qpid-broker-j by apache.

the class AbstractJDBCMessageStore method addContent.

private void addContent(final Connection conn, long messageId, QpidByteBuffer contentBody) {
    getLogger().debug("Adding content for message {}", messageId);
    try (PreparedStatement stmt = conn.prepareStatement("INSERT INTO " + getMessageContentTableName() + "( message_id, content ) values (?, ?)");
        QpidByteBuffer bodyDuplicate = contentBody.duplicate();
        InputStream inputStream = bodyDuplicate.asInputStream()) {
        stmt.setLong(1, messageId);
        stmt.setBinaryStream(2, inputStream, contentBody.remaining());
        stmt.executeUpdate();
    } catch (SQLException | IOException e) {
        JdbcUtils.closeConnection(conn, getLogger());
        throw new StoreException("Error adding content for message " + messageId + ": " + e.getMessage(), e);
    }
}
Also used : SQLException(java.sql.SQLException) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) PreparedStatement(java.sql.PreparedStatement) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) IOException(java.io.IOException) StoreException(org.apache.qpid.server.store.StoreException)

Example 10 with StoreException

use of org.apache.qpid.server.store.StoreException in project qpid-broker-j by apache.

the class AbstractJDBCMessageStore method setMaximumMessageId.

protected void setMaximumMessageId() {
    try (Connection conn = newAutoCommitConnection()) {
        setMaxMessageId(conn, "SELECT max(message_id) FROM " + getMessageContentTableName(), 1);
        setMaxMessageId(conn, "SELECT max(message_id) FROM " + getMetaDataTableName(), 1);
        setMaxMessageId(conn, "SELECT queue_id, max(message_id) FROM " + getQueueEntryTableName() + " GROUP BY queue_id ", 2);
    } catch (SQLException e) {
        throw new StoreException("Failed to determine maximum ids", e);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) StoreException(org.apache.qpid.server.store.StoreException)

Aggregations

StoreException (org.apache.qpid.server.store.StoreException)70 SQLException (java.sql.SQLException)28 Connection (java.sql.Connection)23 PreparedStatement (java.sql.PreparedStatement)21 DatabaseEntry (com.sleepycat.je.DatabaseEntry)20 IOException (java.io.IOException)18 OperationStatus (com.sleepycat.je.OperationStatus)13 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)10 ResultSet (java.sql.ResultSet)10 UUID (java.util.UUID)8 Database (com.sleepycat.je.Database)7 ByteArrayInputStream (java.io.ByteArrayInputStream)7 HashMap (java.util.HashMap)7 Map (java.util.Map)7 ModelVersion (org.apache.qpid.server.model.ModelVersion)7 LinkKey (org.apache.qpid.server.protocol.v1_0.LinkKey)7 HashSet (java.util.HashSet)5 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)5 Cursor (com.sleepycat.je.Cursor)4 DatabaseConfig (com.sleepycat.je.DatabaseConfig)4