Search in sources :

Example 1 with BounceProxyEntity

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

the class BounceProxyDatabase method getBounceProxyStatusInformation.

@Override
public List<BounceProxyStatusInformation> getBounceProxyStatusInformation() {
    logger.trace("getBounceProxyStatusInformation()");
    List<BounceProxyStatusInformation> result = new LinkedList<BounceProxyStatusInformation>();
    for (BounceProxyEntity bp : getBounceProxyEntityList()) {
        result.add(bp.convertToBounceProxyRecord());
    }
    logger.debug("found {} bounce proxies", result.size());
    return result;
}
Also used : BounceProxyEntity(io.joynr.messaging.bounceproxy.controller.directory.jdbc.entities.BounceProxyEntity) BounceProxyStatusInformation(io.joynr.messaging.info.BounceProxyStatusInformation) LinkedList(java.util.LinkedList)

Example 2 with BounceProxyEntity

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

the class BounceProxyDatabase method getBounceProxy.

@Override
public BounceProxyRecord getBounceProxy(String bpId) throws IllegalArgumentException {
    logger.trace("getBounceProxy(bpid={})", bpId);
    EntityManager em = emf.createEntityManager();
    BounceProxyEntity bounceProxyEntity = em.find(BounceProxyEntity.class, bpId);
    if (bounceProxyEntity == null) {
        logger.error("No bounce proxy with ID {} in bounce proxy database", bpId);
        throw new IllegalArgumentException("No bounce proxy with ID '" + bpId + "' in bounce proxy database");
    }
    return bounceProxyEntity.convertToBounceProxyRecord();
}
Also used : EntityManager(javax.persistence.EntityManager) BounceProxyEntity(io.joynr.messaging.bounceproxy.controller.directory.jdbc.entities.BounceProxyEntity)

Example 3 with BounceProxyEntity

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

the class BounceProxyDatabase method containsBounceProxy.

@Override
public boolean containsBounceProxy(String bpId) {
    logger.trace("containsBounceProxy(bpid={})", bpId);
    EntityManager em = emf.createEntityManager();
    BounceProxyEntity bounceProxyEntity = em.find(BounceProxyEntity.class, bpId);
    return bounceProxyEntity != null;
}
Also used : EntityManager(javax.persistence.EntityManager) BounceProxyEntity(io.joynr.messaging.bounceproxy.controller.directory.jdbc.entities.BounceProxyEntity)

Example 4 with BounceProxyEntity

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

the class BounceProxyDatabase method updateChannelAssignment.

@Override
public void updateChannelAssignment(String ccid, BounceProxyInformation bpInfo) throws IllegalArgumentException {
    logger.trace("updateChannelAssignment(ccid={}, bpId={})", ccid, bpInfo.getId());
    EntityManager em = emf.createEntityManager();
    EntityTransaction tx = em.getTransaction();
    try {
        tx.begin();
        BounceProxyEntity bpEntity = em.find(BounceProxyEntity.class, bpInfo.getId());
        if (bpEntity == null) {
            logger.error("No bounce proxy with ID {} registered", bpInfo.getId());
            throw new IllegalArgumentException("No bounce proxy with ID '" + bpInfo.getId() + "' registered");
        }
        ChannelEntity channelEntity = em.find(ChannelEntity.class, ccid);
        if (channelEntity == null) {
            logger.error("No channel with ID {} was registered before.", ccid);
            throw new IllegalArgumentException("No channel with ID '" + ccid + "' was registered before.");
        }
        // TODO what to do if channel with the same ID is added, but
        // different other properties?
        bpEntity.addChannel(channelEntity);
        em.merge(bpEntity);
        tx.commit();
    } catch (RuntimeException ex) {
        logger.error("Channel assignment could not be persisted. error: {}", ex.getMessage());
        if (tx != null && tx.isActive())
            tx.rollback();
        throw ex;
    }
}
Also used : EntityTransaction(javax.persistence.EntityTransaction) EntityManager(javax.persistence.EntityManager) BounceProxyEntity(io.joynr.messaging.bounceproxy.controller.directory.jdbc.entities.BounceProxyEntity) ChannelEntity(io.joynr.messaging.bounceproxy.controller.directory.jdbc.entities.ChannelEntity)

Example 5 with BounceProxyEntity

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

the class BounceProxyDatabase method addBounceProxy.

@Override
public void addBounceProxy(ControlledBounceProxyInformation bpInfo) throws IllegalArgumentException {
    logger.trace("addBounceProxy(bpid={})", bpInfo.getId());
    BounceProxyRecord record = new BounceProxyRecord(bpInfo);
    record.setFreshness(timestampProvider.getCurrentTime());
    BounceProxyEntity bpEntity = new BounceProxyEntity(record);
    EntityManager em = emf.createEntityManager();
    EntityTransaction tx = em.getTransaction();
    try {
        tx.begin();
        em.persist(bpEntity);
        tx.commit();
    } catch (RuntimeException ex) {
        logger.error("Bounce proxy {} could not be persisted. error: {}", bpInfo.getId(), ex.getMessage());
        if (tx != null && tx.isActive())
            tx.rollback();
        throw ex;
    }
}
Also used : EntityTransaction(javax.persistence.EntityTransaction) EntityManager(javax.persistence.EntityManager) BounceProxyEntity(io.joynr.messaging.bounceproxy.controller.directory.jdbc.entities.BounceProxyEntity) BounceProxyRecord(io.joynr.messaging.bounceproxy.controller.directory.BounceProxyRecord)

Aggregations

BounceProxyEntity (io.joynr.messaging.bounceproxy.controller.directory.jdbc.entities.BounceProxyEntity)8 EntityManager (javax.persistence.EntityManager)6 EntityTransaction (javax.persistence.EntityTransaction)3 BounceProxyRecord (io.joynr.messaging.bounceproxy.controller.directory.BounceProxyRecord)2 LinkedList (java.util.LinkedList)2 ChannelEntity (io.joynr.messaging.bounceproxy.controller.directory.jdbc.entities.ChannelEntity)1 BounceProxyStatusInformation (io.joynr.messaging.info.BounceProxyStatusInformation)1 Query (javax.persistence.Query)1