Search in sources :

Example 1 with DuplicatedSubscriptionException

use of org.zalando.nakadi.exceptions.runtime.DuplicatedSubscriptionException in project nakadi by zalando.

the class SubscriptionDbRepository method createSubscription.

public Subscription createSubscription(final SubscriptionBase subscriptionBase) throws InconsistentStateException, DuplicatedSubscriptionException, RepositoryProblemException {
    try {
        final String newId = uuidGenerator.randomUUID().toString();
        final String keyFieldsHash = hashGenerator.generateSubscriptionKeyFieldsHash(subscriptionBase);
        final DateTime createdAt = new DateTime(DateTimeZone.UTC);
        final Subscription subscription = new Subscription(newId, createdAt, subscriptionBase);
        jdbcTemplate.update("INSERT INTO zn_data.subscription (s_id, s_subscription_object, s_key_fields_hash) " + "VALUES (?, ?::JSONB, ?)", subscription.getId(), jsonMapper.writer().writeValueAsString(subscription), keyFieldsHash);
        return subscription;
    } catch (final JsonProcessingException e) {
        throw new InconsistentStateException("Serialization problem during persistence of event type", e);
    } catch (final DuplicateKeyException e) {
        throw new DuplicatedSubscriptionException("Subscription with the same key properties already exists", e);
    } catch (final DataAccessException e) {
        throw new RepositoryProblemException("Error occurred when running database request", e);
    }
}
Also used : DuplicatedSubscriptionException(org.zalando.nakadi.exceptions.runtime.DuplicatedSubscriptionException) RepositoryProblemException(org.zalando.nakadi.exceptions.runtime.RepositoryProblemException) Subscription(org.zalando.nakadi.domain.Subscription) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) InconsistentStateException(org.zalando.nakadi.exceptions.runtime.InconsistentStateException) DateTime(org.joda.time.DateTime) DuplicateKeyException(org.springframework.dao.DuplicateKeyException) DataAccessException(org.springframework.dao.DataAccessException) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 DateTime (org.joda.time.DateTime)1 DataAccessException (org.springframework.dao.DataAccessException)1 DuplicateKeyException (org.springframework.dao.DuplicateKeyException)1 EmptyResultDataAccessException (org.springframework.dao.EmptyResultDataAccessException)1 Subscription (org.zalando.nakadi.domain.Subscription)1 DuplicatedSubscriptionException (org.zalando.nakadi.exceptions.runtime.DuplicatedSubscriptionException)1 InconsistentStateException (org.zalando.nakadi.exceptions.runtime.InconsistentStateException)1 RepositoryProblemException (org.zalando.nakadi.exceptions.runtime.RepositoryProblemException)1