Search in sources :

Example 16 with Statement

use of org.apache.synapse.message.store.impl.jdbc.util.Statement in project wso2-synapse by wso2.

the class ResequenceMessageStore method removeMessageStatement.

/**
 * <p>
 * Remove message statement.
 * </p>
 * <p>
 * When re-sequenced we need to maintain the last processed id along with the removal. So that at an event the node
 * crashes we know where to start from.
 * </p>
 * <p>
 * <p>
 * {@inheritDoc}
 */
@Override
protected List<Statement> removeMessageStatement(String msgId) {
    Long messageSequenceId = sequenceIdMapper.remove(msgId);
    String messageStoreName = this.getName();
    if (messageSequenceId == null) {
        log.error("The message with id " + msgId + " is not tracked within the memory.");
    }
    ArrayList<Statement> statements = new ArrayList<>();
    final String deleteMessageStatement = "DELETE FROM " + getJdbcConfiguration().getTableName() + " WHERE msg_id=?";
    final String insertLastProcessIdStatement = "INSERT INTO " + ResequenceMessageStoreConstants.LAST_PROCESS_ID_TABLE_NAME + " (statement,seq_id) VALUES (?,?) ON DUPLICATE KEY UPDATE seq_id = ?";
    Statement sequenceIdUpdateStatement = new Statement(insertLastProcessIdStatement) {

        @Override
        public List<Map> getResult(ResultSet resultSet) throws SQLException {
            throw new UnsupportedOperationException();
        }
    };
    Statement deleteMessage = new Statement(deleteMessageStatement) {

        @Override
        public List<Map> getResult(ResultSet resultSet) throws SQLException {
            throw new UnsupportedOperationException();
        }
    };
    deleteMessage.addParameter(msgId);
    sequenceIdUpdateStatement.addParameter(messageStoreName);
    sequenceIdUpdateStatement.addParameter(messageSequenceId);
    sequenceIdUpdateStatement.addParameter(messageSequenceId);
    statements.add(deleteMessage);
    statements.add(sequenceIdUpdateStatement);
    if (log.isDebugEnabled()) {
        log.debug("Removing message with id:" + msgId + " and last process id:" + messageSequenceId);
    }
    return statements;
}
Also used : Statement(org.apache.synapse.message.store.impl.jdbc.util.Statement) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Statement (org.apache.synapse.message.store.impl.jdbc.util.Statement)16 ResultSet (java.sql.ResultSet)12 PreparedStatement (java.sql.PreparedStatement)11 HashMap (java.util.HashMap)11 Map (java.util.Map)11 SynapseException (org.apache.synapse.SynapseException)8 ArrayList (java.util.ArrayList)6 IOException (java.io.IOException)5 SQLException (java.sql.SQLException)5 MessageContext (org.apache.synapse.MessageContext)5 NoSuchElementException (java.util.NoSuchElementException)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)3 Connection (java.sql.Connection)2 StorableMessage (org.apache.synapse.message.store.impl.commons.StorableMessage)2 List (java.util.List)1