use of uk.gov.justice.services.jdbc.persistence.PreparedStatementWrapper in project microservice_framework by CJSCommonPlatform.
the class StreamStatusJdbcRepository method insertOrDoNothing.
/**
* Tries to insert if database is PostgresSQL and version>=9.5. Uses PostgreSQl-specific sql
* clause. Does not fail if status for the given stream already exists
*
* @param streamStatus the status of the stream to insert
*/
public void insertOrDoNothing(final StreamStatus streamStatus) {
try (final PreparedStatementWrapper ps = jdbcRepositoryHelper.preparedStatementWrapperOf(dataSource, INSERT_ON_CONFLICT_DO_NOTHING)) {
ps.setLong(1, streamStatus.getVersion());
ps.setObject(2, streamStatus.getStreamId());
ps.setString(3, streamStatus.getSource());
ps.executeUpdate();
} catch (SQLException e) {
throw new JdbcRepositoryException(format("Exception while storing status of the stream in PostgreSQL: %s", streamStatus), e);
}
}
use of uk.gov.justice.services.jdbc.persistence.PreparedStatementWrapper in project microservice_framework by CJSCommonPlatform.
the class StreamBufferJdbcRepository method findStreamByIdAndSource.
public Stream<StreamBufferEvent> findStreamByIdAndSource(final UUID id, final String source) {
try {
final PreparedStatementWrapper ps = jdbcRepositoryHelper.preparedStatementWrapperOf(dataSource, SELECT_STREAM_BUFFER_BY_STREAM_ID_AND_SOURCE);
ps.setObject(1, id);
ps.setString(2, source);
return jdbcRepositoryHelper.streamOf(ps, entityFromFunction());
} catch (SQLException e) {
throw new JdbcRepositoryException(format("Exception while returning buffered events, streamId: %s", id), e);
}
}
use of uk.gov.justice.services.jdbc.persistence.PreparedStatementWrapper in project microservice_framework by CJSCommonPlatform.
the class StreamBufferJdbcRepository method insert.
public void insert(final StreamBufferEvent bufferedEvent) {
try (final PreparedStatementWrapper ps = jdbcRepositoryHelper.preparedStatementWrapperOf(dataSource, INSERT)) {
ps.setObject(1, bufferedEvent.getStreamId());
ps.setLong(2, bufferedEvent.getVersion());
ps.setString(3, bufferedEvent.getEvent());
ps.setString(4, bufferedEvent.getSource());
ps.executeUpdate();
} catch (SQLException e) {
throw new JdbcRepositoryException(format("Exception while storing event in the buffer: %s", bufferedEvent), e);
}
}
use of uk.gov.justice.services.jdbc.persistence.PreparedStatementWrapper in project microservice_framework by CJSCommonPlatform.
the class StreamStatusJdbcRepository method insert.
/**
* Insert the given StreamStatus into the stream status table.
*
* @param streamStatus the status of the stream to insert
*/
public void insert(final StreamStatus streamStatus) {
try (final PreparedStatementWrapper ps = jdbcRepositoryHelper.preparedStatementWrapperOf(dataSource, INSERT)) {
ps.setLong(1, streamStatus.getVersion());
ps.setObject(2, streamStatus.getStreamId());
ps.setString(3, streamStatus.getSource());
ps.executeUpdate();
} catch (SQLException e) {
throw new JdbcRepositoryException(format("Exception while storing status of the stream: %s", streamStatus), e);
}
}
use of uk.gov.justice.services.jdbc.persistence.PreparedStatementWrapper in project microservice_framework by CJSCommonPlatform.
the class StreamStatusJdbcRepository method findByStreamIdAndSource.
/**
* Returns a Stream of {@link StreamStatus} for the given stream streamId.
*
* @param streamId streamId of the stream.
* @return a {@link StreamStatus}.
*/
public Optional<StreamStatus> findByStreamIdAndSource(final UUID streamId, final String source) {
try (final PreparedStatementWrapper ps = jdbcRepositoryHelper.preparedStatementWrapperOf(dataSource, SELECT_BY_STREAM_ID_AND_SOURCE)) {
ps.setObject(1, streamId);
ps.setObject(2, source);
return streamStatusFrom(ps);
} catch (SQLException e) {
throw new JdbcRepositoryException(format("Exception while looking up status of the stream: %s", streamId), e);
}
}
Aggregations