use of org.apache.synapse.message.store.impl.jdbc.util.Statement in project wso2-synapse by wso2.
the class JDBCMessageStore method removeMessageStatement.
/**
* Statement to remove the message once a response is received.
*
* @param msgId message id of the statement which should be removed.
* @return the sql remove message statement.
*/
protected List<Statement> removeMessageStatement(String msgId) {
ArrayList<Statement> statements = new ArrayList<>();
Statement statement = new Statement("DELETE FROM " + jdbcConfiguration.getTableName() + " WHERE msg_id=?") {
@Override
public List<Map> getResult(ResultSet resultSet) throws SQLException {
throw new UnsupportedOperationException();
}
};
statement.addParameter(msgId);
statements.add(statement);
return statements;
}
use of org.apache.synapse.message.store.impl.jdbc.util.Statement in project wso2-synapse by wso2.
the class JDBCMessageStore method peek.
/**
* Select and return the first element in current table
*
* @return - Select and return the first element from the table
*/
public MessageContext peek() throws SynapseException {
MessageContext msg;
try {
Statement statement = new Statement("SELECT message FROM " + jdbcConfiguration.getTableName() + " WHERE indexId=(SELECT min(indexId) from " + jdbcConfiguration.getTableName() + ")") {
@Override
public List<Map> getResult(ResultSet resultSet) throws SQLException {
return messageContentResultSet(resultSet, this.getStatement());
}
};
msg = getResultMessageContextFromDatabase(statement);
} catch (SynapseException se) {
throw new SynapseException("Error while peek the message", se);
}
return msg;
}
use of org.apache.synapse.message.store.impl.jdbc.util.Statement in project wso2-synapse by wso2.
the class JDBCMessageStore method getStoreMessageStatement.
/**
* <p>
* Generates the statement to store message in database.
* </p>
* <p>
* If the sequence id is specified the corresponding sequence id will be stored, sequence id will be specified if
* re-sequence message store is being used. In other times this value will be null.
* </p>
*
* @param messageContext the content of the message.
* @param sequenceId the sequence id of the message (optional).
* @return SQL statement for insertion of value to store.
* @throws StoreException at an event there's an exception when generating the statement.
* @see org.apache.synapse.message.store.impl.resequencer.ResequenceMessageStore
*/
protected Statement getStoreMessageStatement(MessageContext messageContext, Long sequenceId) throws StoreException {
StorableMessage persistentMessage = MessageConverter.toStorableMessage(messageContext);
String msgId = persistentMessage.getAxis2message().getMessageID();
Statement statement;
if (null == sequenceId) {
String insertMessageStatement = "INSERT INTO " + jdbcConfiguration.getTableName() + " (msg_id,message) VALUES (?,?)";
statement = new Statement(insertMessageStatement) {
@Override
public List<Map> getResult(ResultSet resultSet) {
throw new UnsupportedOperationException();
}
};
statement.addParameter(msgId);
statement.addParameter(persistentMessage);
} else {
String insertMessageWithSequenceIdStatement = "INSERT INTO " + jdbcConfiguration.getTableName() + " (msg_id,seq_id,message) VALUES (?,?,?)";
statement = new Statement(insertMessageWithSequenceIdStatement) {
@Override
public List<Map> getResult(ResultSet resultSet) {
throw new UnsupportedOperationException();
}
};
statement.addParameter(msgId);
statement.addParameter(sequenceId);
statement.addParameter(persistentMessage);
}
return statement;
}
use of org.apache.synapse.message.store.impl.jdbc.util.Statement in project wso2-synapse by wso2.
the class ResequenceMessageStore method getNextMessage.
/**
* Will get the next message belonging to a sequence.
*
* @return the next message in the sequence.
*/
private MessageContext getNextMessage() {
MessageContext msg = null;
final int firstRowIndex = 0;
try {
String tableName = getJdbcConfiguration().getTableName();
String selectMessageStatement = "SELECT message FROM " + tableName + " WHERE " + ResequenceMessageStoreConstants.SEQ_ID + "= ?";
Statement statement = new Statement(selectMessageStatement) {
@Override
public List<Map> getResult(ResultSet resultSet) throws SQLException {
return messageContentResultSet(resultSet, this.getStatement());
}
};
statement.addParameter(nextSequenceId);
List<Map> processedRows = getProcessedRows(statement);
if (!processedRows.isEmpty()) {
msg = getMessageContext(processedRows, firstRowIndex);
nextSequenceId++;
if (log.isTraceEnabled()) {
log.trace("Message with id " + msg.getMessageID() + " returned for sequence " + nextSequenceId);
}
} else {
if (log.isTraceEnabled()) {
log.trace("Sequences not returned from DB, next sequence will be:" + nextSequenceId);
}
}
} catch (SynapseException ex) {
throw new SynapseException("Error while peek the message", ex);
}
return msg;
}
use of org.apache.synapse.message.store.impl.jdbc.util.Statement in project wso2-synapse by wso2.
the class ResequenceMessageStore method getMessageWithMinimumSequence.
/**
* <p>
* Retrieve the minimum sequence number of the available sequence ids in the DB
* </p>
* <p>
* This operation should call when there's a gap and a timeout occurs.
* </p>
* <p>
* <b>Note : </b> This operation would reset the "nextSequenceId" to the minimum sequence id generated from the
* DB.
* </p>
*
* @return the message context of the next sequence
*/
private MessageContext getMessageWithMinimumSequence() {
String tableName = getJdbcConfiguration().getTableName();
String selectMinimumSequenceIdStatement = "SELECT message,seq_id FROM " + tableName + " WHERE " + ResequenceMessageStoreConstants.SEQ_ID + "=(SELECT min(" + ResequenceMessageStoreConstants.SEQ_ID + ")" + " from " + tableName + ")";
Statement stmt = new Statement(selectMinimumSequenceIdStatement) {
@Override
public List<Map> getResult(ResultSet resultSet) throws SQLException {
return getMessageWithMinimumId(resultSet, this.getStatement());
}
};
MessageContext msg = null;
final int firstRowIndex = 0;
try {
List<Map> processedRows = getProcessedRows(stmt);
if (!processedRows.isEmpty()) {
msg = getMessageContext(processedRows, firstRowIndex);
long sequenceId = getSequenceId(processedRows, firstRowIndex);
nextSequenceId = sequenceId + 1;
if (log.isTraceEnabled()) {
log.trace("Message with id " + msg.getMessageID() + " returned as the minimum, the minimum " + "sequence " + "will be marked as " + nextSequenceId);
}
}
} catch (SynapseException ex) {
throw new SynapseException("Error while peek the message", ex);
}
return msg;
}
Aggregations