Search in sources :

Example 1 with BounceProxyInformationEntity

use of io.joynr.messaging.bounceproxy.controller.directory.jdbc.entities.BounceProxyInformationEntity in project joynr by bmwcarit.

the class ChannelDatabase method addChannel.

@Override
public void addChannel(Channel channel) {
    logger.trace("add channel {}", channel);
    EntityManager em = emf.createEntityManager();
    EntityTransaction tx = em.getTransaction();
    try {
        tx.begin();
        BounceProxyInformationEntity bpInfoEntity = em.find(BounceProxyInformationEntity.class, channel.getBounceProxy().getId());
        if (bpInfoEntity == null) {
            tx.rollback();
            logger.error("No bounce proxy with ID {} registered for channel {}", channel.getBounceProxy().getId(), channel.getChannelId());
            throw new IllegalArgumentException("No bounce proxy with ID '" + channel.getBounceProxy().getId() + "' registered for channel '" + channel.getChannelId() + "'");
        }
        ChannelEntity entity = new ChannelEntity(channel.getChannelId(), bpInfoEntity, channel.getLocation().toString());
        em.persist(entity);
        tx.commit();
    } catch (RuntimeException ex) {
        logger.error("Error persisting channel with ID {}: error: {}", channel.getChannelId(), ex.getMessage());
        if (tx != null && tx.isActive())
            tx.rollback();
        throw ex;
    }
}
Also used : EntityTransaction(javax.persistence.EntityTransaction) EntityManager(javax.persistence.EntityManager) ChannelEntity(io.joynr.messaging.bounceproxy.controller.directory.jdbc.entities.ChannelEntity) BounceProxyInformationEntity(io.joynr.messaging.bounceproxy.controller.directory.jdbc.entities.BounceProxyInformationEntity)

Aggregations

BounceProxyInformationEntity (io.joynr.messaging.bounceproxy.controller.directory.jdbc.entities.BounceProxyInformationEntity)1 ChannelEntity (io.joynr.messaging.bounceproxy.controller.directory.jdbc.entities.ChannelEntity)1 EntityManager (javax.persistence.EntityManager)1 EntityTransaction (javax.persistence.EntityTransaction)1