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);
}
}
}
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);
}
}
Aggregations