@Test public void saveChannels() { final String uaid = UUIDUtil.newUAID(); final String channelId = UUID.randomUUID().toString(); assertThat(jpaDataStore.saveChannel(newChannel(uaid, channelId, 1L)), is(true)); assertThat(jpaDataStore.saveChannel(newChannel(uaid, channelId, 10L)), is(true)); }
@Override public boolean saveChannel(final Channel channel) { final JpaOperation<Boolean> saveChannel = new JpaOperation<Boolean>() { @Override public Boolean perform(final EntityManager em) { UserAgentDTO userAgent = em.find(UserAgentDTO.class, channel.getUAID()); if (userAgent == null) { userAgent = new UserAgentDTO(channel.getUAID()); } userAgent.addChannel(channel.getChannelId(), channel.getVersion(), channel.getEndpointToken()); em.merge(userAgent); return Boolean.TRUE; } }; try { return jpaExecutor.execute(saveChannel); } catch (final Exception e) { logger.error("Could not save channel [" + channel.getChannelId() + "]", e); return false; } }
JpaDataStore implements DataStore { @Override public boolean saveChannel(final Channel channel) { final JpaOperation<Boolean> saveChannel = new JpaOperation<Boolean>() { @Override public Boolean perform(final EntityManager em) { UserAgentDTO userAgent = em.find(UserAgentDTO.class, channel.getUAID()); if (userAgent == null) { userAgent = new UserAgentDTO(channel.getUAID()); } userAgent.addChannel(channel.getChannelId(), channel.getVersion(), channel.getEndpointToken()); em.merge(userAgent); return Boolean.TRUE; } }; try { return jpaExecutor.execute(saveChannel); } catch (final Exception e) { logger.error("Could not save channel [" + channel.getChannelId() + "]", e); return false; } } }
JpaDataStore implements DataStore { @Override public boolean saveChannel(final Channel channel) { final JpaOperation<Boolean> saveChannel = new JpaOperation<Boolean>() { @Override public Boolean perform(final EntityManager em) { UserAgentDTO userAgent = em.find(UserAgentDTO.class, channel.getUAID()); if (userAgent == null) { userAgent = new UserAgentDTO(channel.getUAID()); } userAgent.addChannel(channel.getChannelId(), channel.getVersion(), channel.getEndpointToken()); em.merge(userAgent); return Boolean.TRUE; } }; try { return jpaExecutor.execute(saveChannel); } catch (final Exception e) { logger.error("Could not save channel [" + channel.getChannelId() + "]", e); return false; } } JpaDataStore(final String persistenceUnit); }
JpaDataStore implements DataStore { @Override public boolean saveChannel(final Channel channel) { final JpaOperation<Boolean> saveChannel = new JpaOperation<Boolean>() { @Override public Boolean perform(final EntityManager em) { UserAgentDTO userAgent = em.find(UserAgentDTO.class, channel.getUAID()); if (userAgent == null) { userAgent = new UserAgentDTO(channel.getUAID()); } userAgent.addChannel(channel.getChannelId(), channel.getVersion(), channel.getEndpointToken()); em.merge(userAgent); return Boolean.TRUE; } }; try { return jpaExecutor.execute(saveChannel); } catch (final Exception e) { logger.error("Could not save channel [" + channel.getChannelId() + "]", e); return false; } } JpaDataStore(final String persistenceUnit); @Override void savePrivateKeySalt(final byte[] salt); @Override byte[] getPrivateKeySalt(); @Override boolean saveChannel(final Channel channel); @Override Channel getChannel(final String channelId); @Override void removeChannels(final Set<String> channelIds); @Override Set<String> getChannelIds(final String uaid); @Override void removeChannels(final String uaid); @Override String updateVersion(final String endpointToken, final long version); @Override String saveUnacknowledged(final String channelId, final long version); @Override Set<Ack> getUnacknowledged(final String uaid); @Override Set<Ack> removeAcknowledged(final String uaid, final Set<Ack> acked); }
JpaDataStore implements DataStore { @Override public boolean saveChannel(final Channel channel) { final JpaOperation<Boolean> saveChannel = new JpaOperation<Boolean>() { @Override public Boolean perform(final EntityManager em) { UserAgentDTO userAgent = em.find(UserAgentDTO.class, channel.getUAID()); if (userAgent == null) { userAgent = new UserAgentDTO(channel.getUAID()); } userAgent.addChannel(channel.getChannelId(), channel.getVersion(), channel.getEndpointToken()); em.merge(userAgent); return Boolean.TRUE; } }; try { return jpaExecutor.execute(saveChannel); } catch (final Exception e) { logger.error("Could not save channel [" + channel.getChannelId() + "]", e); return false; } } JpaDataStore(final String persistenceUnit); @Override void savePrivateKeySalt(final byte[] salt); @Override byte[] getPrivateKeySalt(); @Override boolean saveChannel(final Channel channel); @Override Channel getChannel(final String channelId); @Override void removeChannels(final Set<String> channelIds); @Override Set<String> getChannelIds(final String uaid); @Override void removeChannels(final String uaid); @Override String updateVersion(final String endpointToken, final long version); @Override String saveUnacknowledged(final String channelId, final long version); @Override Set<Ack> getUnacknowledged(final String uaid); @Override Set<Ack> removeAcknowledged(final String uaid, final Set<Ack> acked);  }