private boolean messageTableAlreadyExists(TransactionContext transactionContext) { boolean alreadyExists = false; ResultSet rs = null; try { rs = transactionContext.getConnection().getMetaData().getTables(null, null, this.statements.getFullMessageTableName(), new String[] { "TABLE" }); alreadyExists = rs.next(); } catch (Throwable ignore) { } finally { close(rs); } return alreadyExists; }
@Override public void doCommitAddOp(TransactionContext c, long preparedSequence, long sequence) throws SQLException, IOException { PreparedStatement s = null; try { s = c.getConnection().prepareStatement(this.statements.getClearXidFlagStatement()); s.setLong(1, sequence); s.setLong(2, preparedSequence); if (s.executeUpdate() != 1) { throw new IOException("Could not remove prepared transaction state from message add for sequenceId: " + sequence); } } finally { close(s); } }
@Override public void doDeleteSubscription(TransactionContext c, ActiveMQDestination destination, String clientId, String subscriptionName) throws SQLException, IOException { PreparedStatement s = null; try { s = c.getConnection().prepareStatement(this.statements.getDeleteSubscriptionStatement()); s.setString(1, destination.getQualifiedName()); s.setString(2, clientId); s.setString(3, subscriptionName); s.executeUpdate(); } finally { close(s); } }
try { if (s == null) { s = c.getConnection().prepareStatement(xid == null ? this.statements.getRemoveMessageStatement() : this.statements.getUpdateXidFlagStatement()); if (this.batchStatements) { xidVal[0] = '-'; String xidString = printBase64Binary(xidVal); s.setString(1, xidString); s.setLong(2, seq);
@Override public void doClearLastAck(TransactionContext c, ActiveMQDestination destination, byte priority, String clientId, String subName) throws SQLException, IOException { PreparedStatement s = null; try { s = c.getConnection().prepareStatement(this.statements.getClearDurableLastAckInTxStatement()); s.setString(1, destination.getQualifiedName()); s.setString(2, clientId); s.setString(3, subName); s.setLong(4, priority); if (s.executeUpdate() != 1) { throw new IOException("Could not remove prepared transaction state from message ack for: " + clientId + ":" + subName); } } finally { close(s); } }
@Override public String doGetMessageReference(TransactionContext c, long seq) throws SQLException, IOException { PreparedStatement s = null; ResultSet rs = null; try { s = c.getConnection().prepareStatement(this.statements.getFindMessageStatement()); s.setLong(1, seq); rs = s.executeQuery(); if (!rs.next()) { return null; } return rs.getString(1); } finally { close(rs); close(s); } }
@Override public void doAddMessage(TransactionContext c, long sequence, MessageId messageID, ActiveMQDestination destination, byte[] data, long expiration, byte priority, XATransactionId xid) throws SQLException, IOException { PreparedStatement s = null; try { // Add the Blob record. s = c.getConnection().prepareStatement(statements.getAddMessageStatement()); s.setLong(1, sequence); s.setString(2, messageID.getProducerId().toString()); s.setLong(3, messageID.getProducerSequenceId()); s.setString(4, destination.getQualifiedName()); s.setLong(5, expiration); s.setLong(6, priority); if (s.executeUpdate() != 1) { throw new IOException("Failed to add broker message: " + messageID + " in container."); } s.close(); // Select the blob record so that we can update it. updateBlob(c.getConnection(), statements.getFindMessageByIdStatement(), sequence, data); if (xid != null) { byte[] xidVal = xid.getEncodedXidBytes(); xidVal[0] = '+'; updateBlob(c.getConnection(), statements.getFindXidByIdStatement(), sequence, xidVal); } } finally { close(s); } }
private boolean messageTableAlreadyExists(TransactionContext transactionContext) { boolean alreadyExists = false; ResultSet rs = null; try { rs = transactionContext.getConnection().getMetaData().getTables(null, null, this.statements.getFullMessageTableName(), new String[] { "TABLE" }); alreadyExists = rs.next(); } catch (Throwable ignore) { } finally { close(rs); } return alreadyExists; }
@Override public long doGetLastProducerSequenceId(TransactionContext c, ProducerId id) throws SQLException, IOException { PreparedStatement s = null; ResultSet rs = null; try { s = c.getConnection().prepareStatement(this.statements.getLastProducerSequenceIdStatement()); s.setString(1, id.toString()); rs = s.executeQuery(); long seq = -1; if (rs.next()) { seq = rs.getLong(1); } return seq; } finally { close(rs); close(s); } }
@Override public Set<ActiveMQDestination> doGetDestinations(TransactionContext c) throws SQLException, IOException { HashSet<ActiveMQDestination> rc = new HashSet<ActiveMQDestination>(); PreparedStatement s = null; ResultSet rs = null; try { s = c.getConnection().prepareStatement(this.statements.getFindAllDestinationsStatement()); rs = s.executeQuery(); while (rs.next()) { rc.add(ActiveMQDestination.createDestination(rs.getString(1), ActiveMQDestination.QUEUE_TYPE)); } } finally { close(rs); close(s); } return rc; }
@Override public void doAddMessageReference(TransactionContext c, long sequence, MessageId messageID, ActiveMQDestination destination, long expirationTime, String messageRef) throws SQLException, IOException { PreparedStatement s = c.getAddMessageStatement(); try { if (s == null) { s = c.getConnection().prepareStatement(this.statements.getAddMessageStatement()); if (this.batchStatements) { c.setAddMessageStatement(s); } } s.setLong(1, messageID.getBrokerSequenceId()); s.setString(2, messageID.getProducerId().toString()); s.setLong(3, messageID.getProducerSequenceId()); s.setString(4, destination.getQualifiedName()); s.setLong(5, expirationTime); s.setString(6, messageRef); if (this.batchStatements) { s.addBatch(); } else if (s.executeUpdate() != 1) { throw new SQLException("Failed add a message"); } } finally { if (!this.batchStatements) { s.close(); } } }
private boolean messageTableAlreadyExists(TransactionContext transactionContext) { boolean alreadyExists = false; ResultSet rs = null; try { rs = transactionContext.getConnection().getMetaData().getTables(null, null, this.statements.getFullMessageTableName(), new String[] { "TABLE" }); alreadyExists = rs.next(); } catch (Throwable ignore) { } finally { close(rs); } return alreadyExists; }
@Override public void doRemoveAllMessages(TransactionContext c, ActiveMQDestination destinationName) throws SQLException, IOException { PreparedStatement s = null; try { s = c.getConnection().prepareStatement(this.statements.getRemoveAllMessagesStatement()); s.setString(1, destinationName.getQualifiedName()); s.executeUpdate(); s.close(); s = c.getConnection().prepareStatement(this.statements.getRemoveAllSubscriptionsStatement()); s.setString(1, destinationName.getQualifiedName()); s.executeUpdate(); } finally { close(s); } }
@Override public byte[] doGetMessageById(TransactionContext c, long storeSequenceId) throws SQLException, IOException { PreparedStatement s = null; ResultSet rs = null; try { s = c.getConnection().prepareStatement( this.statements.getFindMessageByIdStatement()); s.setLong(1, storeSequenceId); rs = s.executeQuery(); if (!rs.next()) { return null; } return getBinaryData(rs, 1); } finally { close(rs); close(s); } }
@Override public byte[] doGetMessage(TransactionContext c, MessageId id) throws SQLException, IOException { PreparedStatement s = null; ResultSet rs = null; try { s = c.getConnection().prepareStatement(statements.getFindMessageStatement()); s.setString(1, id.getProducerId().toString()); s.setLong(2, id.getProducerSequenceId()); rs = s.executeQuery(); if (!rs.next()) { return null; } Blob blob = rs.getBlob(1); try(InputStream is = blob.getBinaryStream(); ByteArrayOutputStream os = new ByteArrayOutputStream((int)blob.length())) { int ch; while ((ch = is.read()) >= 0) { os.write(ch); } return os.toByteArray(); } } finally { close(rs); close(s); } }
private boolean messageTableAlreadyExists(TransactionContext transactionContext) { boolean alreadyExists = false; ResultSet rs = null; try { rs = transactionContext.getConnection().getMetaData().getTables(null, null, this.statements.getFullMessageTableName(), new String[] { "TABLE" }); alreadyExists = rs.next(); } catch (Throwable ignore) { } finally { close(rs); } return alreadyExists; }
@Override public int doGetMessageCount(TransactionContext c, ActiveMQDestination destination) throws SQLException, IOException { PreparedStatement s = null; ResultSet rs = null; int result = 0; try { s = c.getConnection().prepareStatement(this.statements.getDestinationMessageCountStatement()); s.setString(1, destination.getQualifiedName()); rs = s.executeQuery(); if (rs.next()) { result = rs.getInt(1); } } finally { close(rs); close(s); } return result; }
@Override public long doGetLastMessageStoreSequenceId(TransactionContext c) throws SQLException, IOException { PreparedStatement s = null; ResultSet rs = null; try { s = c.getConnection().prepareStatement(this.statements.getFindLastSequenceIdInMsgsStatement()); rs = s.executeQuery(); long seq1 = 0; if (rs.next()) { seq1 = rs.getLong(1); } rs.close(); s.close(); s = c.getConnection().prepareStatement(this.statements.getFindLastSequenceIdInAcksStatement()); rs = s.executeQuery(); long seq2 = 0; if (rs.next()) { seq2 = rs.getLong(1); } long seq = Math.max(seq1, seq2); return seq; } finally { close(rs); close(s); } }
try { if (s == null) { s = c.getConnection().prepareStatement(this.statements.getAddMessageStatement()); if (this.batchStatements) { c.setAddMessageStatement(s); s.setString(2, messageID.getProducerId().toString()); s.setLong(3, messageID.getProducerSequenceId()); s.setString(4, destination.getQualifiedName()); s.setLong(5, expiration); s.setLong(6, priority); xidVal[0] = '+'; String xidString = printBase64Binary(xidVal); s.setString(8, xidString); } else { s.setString(8, null);
@Override public long doGetLastAckedDurableSubscriberMessageId(TransactionContext c, ActiveMQDestination destination, String clientId, String subscriberName) throws SQLException, IOException { PreparedStatement s = null; ResultSet rs = null; long result = -1; try { s = c.getConnection().prepareStatement(this.statements.getLastAckedDurableSubscriberMessageStatement()); s.setString(1, destination.getQualifiedName()); s.setString(2, clientId); s.setString(3, subscriberName); rs = s.executeQuery(); if (rs.next()) { result = rs.getLong(1); if (result == 0 && rs.wasNull()) { result = -1; } } } finally { close(rs); close(s); } return result; }