use of org.apache.synapse.message.store.impl.jdbc.util.Statement in project wso2-synapse by wso2.
the class ResequenceMessageStore method readStartId.
/**
* <p>
* This method should be called at the start of the store.
* </p>
* <p>
* Will read from the DB and identify the id which should be processed.
* </p>
*
* @return the start id of the store.
*/
private long readStartId() {
Long sequenceId = 0L;
final int minimumRowCount = 0;
String storeName = this.getName();
final String lastProcessIdSelectStatement = "SELECT " + ResequenceMessageStoreConstants.SEQ_ID + " FROM " + ResequenceMessageStoreConstants.LAST_PROCESS_ID_TABLE_NAME + " WHERE " + ResequenceMessageStoreConstants.STATEMENT_COLUMN + "=" + "\"" + storeName + "\"";
Statement statement = new Statement(lastProcessIdSelectStatement) {
@Override
public List<Map> getResult(ResultSet resultSet) throws SQLException {
return startIdSelectionResult(resultSet);
}
};
List<Map> processedRows = getProcessedRows(statement);
if (processedRows.size() > minimumRowCount) {
final int firstIndex = 0;
Map processedRowMap = processedRows.get(firstIndex);
sequenceId = (Long) processedRowMap.get(ResequenceMessageStoreConstants.SEQUENCE_ID_COLUMN);
log.info("Starting sequence id recorded as:" + sequenceId);
}
return sequenceId;
}
use of org.apache.synapse.message.store.impl.jdbc.util.Statement in project wso2-synapse by wso2.
the class ResequenceMessageStore method getStoreMessageStatement.
/**
* <p>
* Stores message in database by providing the correct sequence id.
* </p>
* <p>
* {@inheritDoc}
*/
@Override
protected Statement getStoreMessageStatement(MessageContext context, Long sequenceId) throws StoreException {
Statement storeMessageStatement;
sequenceId = getMessageSequenceId(context);
storeMessageStatement = super.getStoreMessageStatement(context, sequenceId);
return storeMessageStatement;
}
use of org.apache.synapse.message.store.impl.jdbc.util.Statement in project wso2-synapse by wso2.
the class JDBCMessageStore method size.
/**
* Return number of messages in the store
*
* @return size - Number of messages
*/
@Override
public int size() {
Connection con = null;
ResultSet rs = null;
PreparedStatement ps = null;
int size = 0;
Statement statement = new Statement("SELECT COUNT(*) FROM " + jdbcConfiguration.getTableName()) {
@Override
public List<Map> getResult(ResultSet resultSet) throws SQLException {
return messageContentResultSet(resultSet, this.getStatement());
}
};
try {
con = jdbcConfiguration.getConnection();
ps = con.prepareStatement(statement.getStatement());
con = ps.getConnection();
rs = ps.executeQuery();
while (rs.next()) {
try {
size = rs.getInt(1);
} catch (Exception e) {
logger.error("Error executing statement : " + statement.getStatement() + " against DataSource : " + jdbcConfiguration.getDSName(), e);
break;
}
}
} catch (SQLException e) {
logger.error("Error executing statement : " + statement.getStatement() + " against DataSource : " + jdbcConfiguration.getDSName(), e);
} finally {
close(con, ps, rs);
}
return size;
}
use of org.apache.synapse.message.store.impl.jdbc.util.Statement in project wso2-synapse by wso2.
the class JDBCMessageStore method get.
/**
* Return the first element with given msg_id
*
* @param msgId - Message ID
* @return - returns the first result found else null
*/
@Override
public MessageContext get(String msgId) {
Statement statement = new Statement("SELECT indexId,message FROM " + jdbcConfiguration.getTableName() + " WHERE msg_id=?") {
@Override
public List<Map> getResult(ResultSet resultSet) throws SQLException {
return messageContentResultSet(resultSet, this.getStatement());
}
};
statement.addParameter(msgId);
return getResultMessageContextFromDatabase(statement);
}
use of org.apache.synapse.message.store.impl.jdbc.util.Statement in project wso2-synapse by wso2.
the class JDBCMessageStore method getAll.
/**
* Get all messages in the table
*
* @return - List containing all message contexts in the store
*/
@Override
public List<MessageContext> getAll() {
if (logger.isDebugEnabled()) {
logger.debug(getNameString() + " retrieving all messages from the store.");
}
Statement statement = new Statement("SELECT message FROM " + jdbcConfiguration.getTableName()) {
@Override
public List<Map> getResult(ResultSet resultSet) throws SQLException {
return messageContentResultSet(resultSet, this.getStatement());
}
};
MessageContext result = getResultMessageContextFromDatabase(statement);
if (result != null) {
List<MessageContext> msgs = new ArrayList<>();
msgs.add(result);
return msgs;
} else {
return null;
}
}
Aggregations