Search in sources :

Example 1 with PreparedStatementWrapper

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

the class EventJdbcRepository method findByStreamIdFromPositionOrderByPositionAsc.

/**
 * Returns a Stream of {@link Event} for the given stream streamId starting from the given
 * version.
 *
 * @param streamId    streamId of the stream.
 * @param position the position to read from.
 * @return a stream of {@link Event}. Never returns null.
 */
public Stream<Event> findByStreamIdFromPositionOrderByPositionAsc(final UUID streamId, final Long position) {
    try {
        final PreparedStatementWrapper ps = jdbcRepositoryHelper.preparedStatementWrapperOf(dataSource, SQL_FIND_BY_STREAM_ID_AND_POSITION);
        ps.setObject(1, streamId);
        ps.setLong(2, position);
        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);
    }
}
Also used : SQLException(java.sql.SQLException) PreparedStatementWrapper(uk.gov.justice.services.jdbc.persistence.PreparedStatementWrapper) JdbcRepositoryException(uk.gov.justice.services.jdbc.persistence.JdbcRepositoryException)

Example 2 with PreparedStatementWrapper

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

the class EventStreamJdbcRepository method markActive.

public void markActive(final UUID streamId, final boolean active) {
    try (final PreparedStatementWrapper ps = eventStreamJdbcRepositoryHelper.preparedStatementWrapperOf(dataSource, SQL_UPDATE_EVENT_STREAM_ACTIVE)) {
        ps.setBoolean(1, active);
        ps.setObject(2, streamId);
        ps.executeUpdate();
    } catch (final SQLException e) {
        throw new JdbcRepositoryException(format("Exception while update stream %s active status to %s", streamId, active), e);
    }
}
Also used : SQLException(java.sql.SQLException) PreparedStatementWrapper(uk.gov.justice.services.jdbc.persistence.PreparedStatementWrapper) JdbcRepositoryException(uk.gov.justice.services.jdbc.persistence.JdbcRepositoryException)

Example 3 with PreparedStatementWrapper

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

the class EventStreamJdbcRepository method findEventStreamWithPositionFrom.

public Stream<EventStream> findEventStreamWithPositionFrom(final long position) {
    try {
        final PreparedStatementWrapper preparedStatementWrapper = eventStreamJdbcRepositoryHelper.preparedStatementWrapperOf(dataSource, SQL_FIND_BY_POSITION);
        preparedStatementWrapper.setLong(1, position);
        return eventStreamJdbcRepositoryHelper.streamOf(preparedStatementWrapper, entityFromFunction());
    } catch (SQLException e) {
        throw new JdbcRepositoryException(READING_STREAM_EXCEPTION, e);
    }
}
Also used : SQLException(java.sql.SQLException) PreparedStatementWrapper(uk.gov.justice.services.jdbc.persistence.PreparedStatementWrapper) JdbcRepositoryException(uk.gov.justice.services.jdbc.persistence.JdbcRepositoryException)

Example 4 with PreparedStatementWrapper

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

the class StreamBufferJdbcRepository method remove.

public void remove(final StreamBufferEvent streamBufferEvent) {
    try (final PreparedStatementWrapper ps = jdbcRepositoryHelper.preparedStatementWrapperOf(dataSource, DELETE_BY_STREAM_ID_VERSION)) {
        ps.setObject(1, streamBufferEvent.getStreamId());
        ps.setLong(2, streamBufferEvent.getVersion());
        ps.setString(3, streamBufferEvent.getSource());
        ps.executeUpdate();
    } catch (SQLException e) {
        throw new JdbcRepositoryException(format("Exception while removing event from the buffer: %s", streamBufferEvent), e);
    }
}
Also used : SQLException(java.sql.SQLException) PreparedStatementWrapper(uk.gov.justice.services.jdbc.persistence.PreparedStatementWrapper) JdbcRepositoryException(uk.gov.justice.services.jdbc.persistence.JdbcRepositoryException)

Example 5 with PreparedStatementWrapper

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

the class StreamStatusJdbcRepository method update.

/**
 * Insert the given StreamStatus into the stream status table.
 *
 * @param streamStatus the event to insert
 */
public void update(final StreamStatus streamStatus) {
    try (final PreparedStatementWrapper ps = jdbcRepositoryHelper.preparedStatementWrapperOf(dataSource, UPDATE)) {
        ps.setLong(1, streamStatus.getVersion());
        ps.setString(2, streamStatus.getSource());
        ps.setObject(3, streamStatus.getStreamId());
        ps.executeUpdate();
    } catch (SQLException e) {
        throw new JdbcRepositoryException(format("Exception while updating status of the stream: %s", streamStatus), e);
    }
}
Also used : SQLException(java.sql.SQLException) PreparedStatementWrapper(uk.gov.justice.services.jdbc.persistence.PreparedStatementWrapper) JdbcRepositoryException(uk.gov.justice.services.jdbc.persistence.JdbcRepositoryException)

Aggregations

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