Search in sources :

Example 6 with BounceProxyEntity

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

the class BounceProxyDatabase method updateBounceProxy.

@Override
public void updateBounceProxy(BounceProxyRecord bpRecord) throws IllegalArgumentException {
    logger.trace("updateBounceProxy(bpid={})", bpRecord.getBounceProxyId());
    EntityManager em = emf.createEntityManager();
    EntityTransaction tx = em.getTransaction();
    try {
        tx.begin();
        BounceProxyEntity bpEntity = new BounceProxyEntity(bpRecord);
        bpEntity.setFreshness(timestampProvider.getCurrentTime());
        em.merge(bpEntity);
        tx.commit();
    } catch (RuntimeException ex) {
        logger.error("Bounce proxy {} could not be updated. error: {}", bpRecord.getBounceProxyId(), 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)

Example 7 with BounceProxyEntity

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

the class BounceProxyDatabase method getBounceProxyEntityList.

private List<BounceProxyEntity> getBounceProxyEntityList(String sqlWhereClause) {
    String query;
    if (sqlWhereClause == null) {
        query = String.format("SELECT x FROM %s x", BounceProxyEntity.class.getSimpleName());
    } else {
        query = String.format("SELECT x FROM %s x WHERE %s", BounceProxyEntity.class.getSimpleName(), sqlWhereClause);
    }
    EntityManager em = emf.createEntityManager();
    Query getBounceProxiesQuery = em.createQuery(query);
    @SuppressWarnings("unchecked") List<BounceProxyEntity> queryResults = getBounceProxiesQuery.getResultList();
    return queryResults;
}
Also used : EntityManager(javax.persistence.EntityManager) BounceProxyEntity(io.joynr.messaging.bounceproxy.controller.directory.jdbc.entities.BounceProxyEntity) Query(javax.persistence.Query)

Example 8 with BounceProxyEntity

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

the class BounceProxyDatabase method getAssignableBounceProxies.

@Override
public List<BounceProxyRecord> getAssignableBounceProxies() {
    logger.trace("getAssignableBounceProxies()");
    List<BounceProxyRecord> bounceProxyList = new LinkedList<BounceProxyRecord>();
    for (BounceProxyEntity entity : getBounceProxyEntityList(getSqlWhereClauseForAssignableBounceProxies())) {
        bounceProxyList.add(entity.convertToBounceProxyRecord());
    }
    logger.debug("found {} assignable bounce proxies", bounceProxyList.size());
    return bounceProxyList;
}
Also used : BounceProxyEntity(io.joynr.messaging.bounceproxy.controller.directory.jdbc.entities.BounceProxyEntity) BounceProxyRecord(io.joynr.messaging.bounceproxy.controller.directory.BounceProxyRecord) LinkedList(java.util.LinkedList)

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