Search in sources :

Example 11 with Statement

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;
}
Also used : Statement(org.apache.synapse.message.store.impl.jdbc.util.Statement) ResultSet(java.sql.ResultSet) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 12 with Statement

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;
}
Also used : Statement(org.apache.synapse.message.store.impl.jdbc.util.Statement)

Example 13 with Statement

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;
}
Also used : SQLException(java.sql.SQLException) Statement(org.apache.synapse.message.store.impl.jdbc.util.Statement) PreparedStatement(java.sql.PreparedStatement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) HashMap(java.util.HashMap) Map(java.util.Map) SQLException(java.sql.SQLException) NoSuchElementException(java.util.NoSuchElementException) SynapseException(org.apache.synapse.SynapseException) IOException(java.io.IOException)

Example 14 with Statement

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);
}
Also used : Statement(org.apache.synapse.message.store.impl.jdbc.util.Statement) PreparedStatement(java.sql.PreparedStatement) ResultSet(java.sql.ResultSet) HashMap(java.util.HashMap) Map(java.util.Map)

Example 15 with 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;
    }
}
Also used : Statement(org.apache.synapse.message.store.impl.jdbc.util.Statement) PreparedStatement(java.sql.PreparedStatement) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) 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