use of uk.gov.justice.services.jdbc.persistence.JdbcRepositoryException in project microservice_framework by CJSCommonPlatform.
the class EventJdbcRepository method clear.
public void clear(final UUID streamId) {
final long eventCount = getStreamSize(streamId);
try (final PreparedStatementWrapper ps = jdbcRepositoryHelper.preparedStatementWrapperOf(dataSource, SQL_DELETE_STREAM)) {
ps.setObject(1, streamId);
final int deletedRows = ps.executeUpdate();
if (deletedRows != eventCount) {
// Rollback, something went wrong
throw new JdbcRepositoryException(format(DELETING_STREAM_EXCEPTION_DETAILS, streamId, eventCount, deletedRows));
}
} catch (final SQLException e) {
throw new JdbcRepositoryException(format(DELETING_STREAM_EXCEPTION, streamId), e);
}
}
use of uk.gov.justice.services.jdbc.persistence.JdbcRepositoryException in project microservice_framework by CJSCommonPlatform.
the class EventJdbcRepository method getStreamSize.
/**
* Returns the current position for the given stream streamId.
*
* @param streamId streamId of the stream.
* @return current position streamId for the stream. Returns 0 if stream doesn't exist.
*/
public long getStreamSize(final UUID streamId) {
try (final PreparedStatementWrapper ps = jdbcRepositoryHelper.preparedStatementWrapperOf(dataSource, SQL_FIND_LATEST_POSITION)) {
ps.setObject(1, streamId);
ResultSet resultSet = ps.executeQuery();
if (resultSet.next()) {
return resultSet.getLong(1);
}
} catch (final SQLException e) {
logger.warn(FAILED_TO_READ_STREAM, streamId, e);
throw new JdbcRepositoryException(format(READING_STREAM_EXCEPTION, streamId), e);
}
return NO_EXISTING_VERSION;
}
use of uk.gov.justice.services.jdbc.persistence.JdbcRepositoryException in project microservice_framework by CJSCommonPlatform.
the class EventJdbcRepository method findByStreamIdOrderByPositionAsc.
/**
* Returns a Stream of {@link Event} for the given stream streamId.
*
* @param streamId streamId of the stream.
* @return a stream of {@link Event}. Never returns null.
*/
public Stream<Event> findByStreamIdOrderByPositionAsc(final UUID streamId) {
try {
final PreparedStatementWrapper ps = jdbcRepositoryHelper.preparedStatementWrapperOf(dataSource, SQL_FIND_BY_STREAM_ID);
ps.setObject(1, streamId);
return jdbcRepositoryHelper.streamOf(ps, entityFromFunction());
} catch (final SQLException e) {
logger.warn(FAILED_TO_READ_STREAM, streamId, e);
throw new JdbcRepositoryException(format(READING_STREAM_EXCEPTION, streamId), e);
}
}
use of uk.gov.justice.services.jdbc.persistence.JdbcRepositoryException in project microservice_framework by CJSCommonPlatform.
the class EventStreamJdbcRepository method delete.
public void delete(final UUID streamId) {
try (final PreparedStatementWrapper ps = eventStreamJdbcRepositoryHelper.preparedStatementWrapperOf(dataSource, SQL_DELETE_EVENT_STREAM)) {
ps.setObject(1, streamId);
ps.executeUpdate();
} catch (final SQLException e) {
throw new JdbcRepositoryException(format(EVENT_STREAM_EXCEPTION_MESSAGE, streamId), e);
}
}
use of uk.gov.justice.services.jdbc.persistence.JdbcRepositoryException 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);
}
}
Aggregations