Search in sources :

Example 1 with InvalidStreamIdException

use of uk.gov.justice.services.eventsourcing.repository.jdbc.exception.InvalidStreamIdException in project microservice_framework by CJSCommonPlatform.

the class EventStreamJdbcRepository method getPosition.

public long getPosition(final UUID streamId) {
    try (final PreparedStatementWrapper psquery = eventStreamJdbcRepositoryHelper.preparedStatementWrapperOf(dataSource, SQL_FIND_POSITION_BY_STREAM)) {
        psquery.setObject(1, streamId);
        ResultSet resultSet = psquery.executeQuery();
        if (resultSet.next()) {
            return resultSet.getLong(1);
        }
        throw new InvalidStreamIdException("Invalid Stream Id: " + streamId.toString());
    } catch (final SQLException e) {
        throw new JdbcRepositoryException(format(EVENT_STREAM_EXCEPTION_MESSAGE, streamId), e);
    }
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatementWrapper(uk.gov.justice.services.jdbc.persistence.PreparedStatementWrapper) JdbcRepositoryException(uk.gov.justice.services.jdbc.persistence.JdbcRepositoryException) InvalidStreamIdException(uk.gov.justice.services.eventsourcing.repository.jdbc.exception.InvalidStreamIdException)

Aggregations

ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 InvalidStreamIdException (uk.gov.justice.services.eventsourcing.repository.jdbc.exception.InvalidStreamIdException)1 JdbcRepositoryException (uk.gov.justice.services.jdbc.persistence.JdbcRepositoryException)1 PreparedStatementWrapper (uk.gov.justice.services.jdbc.persistence.PreparedStatementWrapper)1