select.setParameter("endpointToken", endpointToken);
final List<ChannelDTO> resultList = select.getResultList();
if (resultList.isEmpty()) {
return null;
}
final ChannelDTO channelDTO = resultList.get(0);
if (channelDTO != null) {
if (version > channelDTO.getVersion()) {
channelDTO.setVersion(version);
em.merge(channelDTO);
} else {
throw new VersionException("New version [" + version + "] must be greater than current version [" + channelDTO.getVersion() + "]");
}
}
return channelDTO;
}
};
try {
final ChannelDTO channelDto = jpaExecutor.execute(updateVersion);
if (channelDto == null) {
throw new ChannelNotFoundException("No Channel for endpointToken [" + endpointToken + "] was found", endpointToken);
}
return channelDto.getChannelId();
} catch (final JpaException e) {
final Throwable cause = e.getCause();
if (cause instanceof VersionException) {
throw (VersionException) cause;
}