Search in sources :

Example 6 with InconsistentStateException

use of org.zalando.nakadi.exceptions.runtime.InconsistentStateException 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

InconsistentStateException (org.zalando.nakadi.exceptions.runtime.InconsistentStateException)6 Subscription (org.zalando.nakadi.domain.Subscription)3 InternalNakadiException (org.zalando.nakadi.exceptions.InternalNakadiException)3 RepositoryProblemException (org.zalando.nakadi.exceptions.runtime.RepositoryProblemException)3 Date (java.util.Date)2 EventType (org.zalando.nakadi.domain.EventType)2 ItemsWrapper (org.zalando.nakadi.domain.ItemsWrapper)2 SubscriptionEventTypeStats (org.zalando.nakadi.domain.SubscriptionEventTypeStats)2 Timeline (org.zalando.nakadi.domain.Timeline)2 NoSuchEventTypeException (org.zalando.nakadi.exceptions.NoSuchEventTypeException)2 ServiceUnavailableException (org.zalando.nakadi.exceptions.ServiceUnavailableException)2 DuplicatedSubscriptionException (org.zalando.nakadi.exceptions.runtime.DuplicatedSubscriptionException)2 TopicRepository (org.zalando.nakadi.repository.TopicRepository)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 List (java.util.List)1