Search in sources :

Example 16 with JdbcRepositoryException

use of uk.gov.justice.services.jdbc.persistence.JdbcRepositoryException in project microservice_framework by CJSCommonPlatform.

the class EventStreamJdbcRepository method insert.

public void insert(final UUID streamId, final boolean active) {
    if (!isExistingStream(streamId)) {
        try (final PreparedStatementWrapper ps = eventStreamJdbcRepositoryHelper.preparedStatementWrapperOf(dataSource, SQL_INSERT_EVENT_STREAM)) {
            ps.setObject(1, streamId);
            ps.setTimestamp(2, toSqlTimestamp(clock.now()));
            ps.setBoolean(3, active);
            ps.executeUpdate();
        } catch (SQLException e) {
            throw new JdbcRepositoryException(format("Exception while storing stream %s", streamId), e);
        }
    }
}
Also used : SQLException(java.sql.SQLException) PreparedStatementWrapper(uk.gov.justice.services.jdbc.persistence.PreparedStatementWrapper) JdbcRepositoryException(uk.gov.justice.services.jdbc.persistence.JdbcRepositoryException)

Example 17 with JdbcRepositoryException

use of uk.gov.justice.services.jdbc.persistence.JdbcRepositoryException in project microservice_framework by CJSCommonPlatform.

the class SnapshotJdbcRepository method getLatestSnapshotVersion.

@Override
public <T extends Aggregate> long getLatestSnapshotVersion(final UUID streamId, final Class<T> clazz) {
    try (final Connection connection = dataSource.getConnection();
        final PreparedStatement preparedStatement = connection.prepareStatement(SQL_CURRENT_SNAPSHOT_VERSION_ID)) {
        preparedStatement.setObject(1, streamId);
        preparedStatement.setObject(2, clazz.getName());
        try (final ResultSet resultSet = preparedStatement.executeQuery()) {
            if (resultSet.next()) {
                return resultSet.getLong(1);
            }
            return 0;
        }
    } catch (final SQLException e) {
        throw new JdbcRepositoryException(format(READING_STREAM_EXCEPTION, streamId), e);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) JdbcRepositoryException(uk.gov.justice.services.jdbc.persistence.JdbcRepositoryException)

Aggregations

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