use of io.joynr.messaging.bounceproxy.controller.directory.jdbc.entities.ChannelEntity 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;
}
}
use of io.joynr.messaging.bounceproxy.controller.directory.jdbc.entities.ChannelEntity in project joynr by bmwcarit.
the class ChannelDatabase method getChannel.
@Override
@CheckForNull
public Channel getChannel(String ccid) {
logger.trace("getChannel({})", ccid);
EntityManager em = emf.createEntityManager();
ChannelEntity channelEntity = em.find(ChannelEntity.class, ccid);
if (channelEntity == null) {
logger.debug("no channel found for ID {}", ccid);
return null;
}
return channelEntity.convertToChannel();
}
use of io.joynr.messaging.bounceproxy.controller.directory.jdbc.entities.ChannelEntity in project joynr by bmwcarit.
the class ChannelDatabase method getChannels.
@Override
public List<Channel> getChannels() {
logger.trace("getChannels()");
List<Channel> channels = new LinkedList<Channel>();
EntityManager em = emf.createEntityManager();
String sqlQueryString = String.format("SELECT x FROM %s x", ChannelEntity.class.getSimpleName());
Query query = em.createQuery(sqlQueryString);
@SuppressWarnings("unchecked") List<ChannelEntity> resultList = query.getResultList();
for (ChannelEntity result : resultList) {
channels.add(result.convertToChannel());
}
logger.debug("retrieved {} channels", channels.size());
return channels;
}
use of io.joynr.messaging.bounceproxy.controller.directory.jdbc.entities.ChannelEntity 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;
}
}
Aggregations