Search in sources :

Example 6 with JdbcRepositoryException

use of uk.gov.justice.services.jdbc.persistence.JdbcRepositoryException 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);
    }
}
Also used : SQLException(java.sql.SQLException) PreparedStatementWrapper(uk.gov.justice.services.jdbc.persistence.PreparedStatementWrapper) JdbcRepositoryException(uk.gov.justice.services.jdbc.persistence.JdbcRepositoryException)

Example 7 with JdbcRepositoryException

use of uk.gov.justice.services.jdbc.persistence.JdbcRepositoryException 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);
    }
}
Also used : SQLException(java.sql.SQLException) PreparedStatementWrapper(uk.gov.justice.services.jdbc.persistence.PreparedStatementWrapper) JdbcRepositoryException(uk.gov.justice.services.jdbc.persistence.JdbcRepositoryException)

Example 8 with JdbcRepositoryException

use of uk.gov.justice.services.jdbc.persistence.JdbcRepositoryException 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);
    }
}
Also used : SQLException(java.sql.SQLException) PreparedStatementWrapper(uk.gov.justice.services.jdbc.persistence.PreparedStatementWrapper) JdbcRepositoryException(uk.gov.justice.services.jdbc.persistence.JdbcRepositoryException)

Example 9 with JdbcRepositoryException

use of uk.gov.justice.services.jdbc.persistence.JdbcRepositoryException 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);
    }
}
Also used : SQLException(java.sql.SQLException) PreparedStatementWrapper(uk.gov.justice.services.jdbc.persistence.PreparedStatementWrapper) JdbcRepositoryException(uk.gov.justice.services.jdbc.persistence.JdbcRepositoryException)

Example 10 with JdbcRepositoryException

use of uk.gov.justice.services.jdbc.persistence.JdbcRepositoryException 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);
    }
}
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)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