@Test public void removeAcknowledged() throws ChannelNotFoundException { final String uaid = UUIDUtil.newUAID(); final Channel channel1 = newChannel(uaid, UUID.randomUUID().toString(), 10); final Channel channel2 = newChannel(uaid, UUID.randomUUID().toString(), 2); jpaDataStore.saveChannel(channel1); jpaDataStore.saveChannel(channel2); jpaDataStore.saveUnacknowledged(channel1.getChannelId(), 11); jpaDataStore.saveUnacknowledged(channel2.getChannelId(), 3); final Set<Ack> storedUpdates = jpaDataStore.getUnacknowledged(uaid); assertThat(storedUpdates.size(), is(2)); jpaDataStore.removeAcknowledged(uaid, acks(new AckImpl(channel1.getChannelId(), 11))); assertThat(jpaDataStore.getUnacknowledged(uaid).size(), is(1)); }
@Override public Set<Ack> removeAcknowledged(final String uaid, final Set<Ack> acked) { final JpaOperation<Set<Ack>> removeAck = new JpaOperation<Set<Ack>>() { @Override public Set<Ack> perform(final EntityManager em) { final List<String> channelIds = new ArrayList<String>(acked.size()); for (Ack ack : acked) { channelIds.add(ack.getChannelId()); } final Query delete = em.createQuery("DELETE from AckDTO c where c.channelId in (:channelIds)"); delete.setParameter("channelIds", channelIds); delete.executeUpdate(); final UserAgentDTO userAgent = em.find(UserAgentDTO.class, uaid); final Set<AckDTO> acks = userAgent.getAcks(); final Set<Ack> unacked = new HashSet<Ack>(acks.size()); for (AckDTO ackDto : acks) { unacked.add(new AckImpl(ackDto.getChannelId(), ackDto.getVersion())); } return unacked; } }; return jpaExecutor.execute(removeAck); }
JpaDataStore implements DataStore { @Override public Set<Ack> removeAcknowledged(final String uaid, final Set<Ack> acked) { final JpaOperation<Set<Ack>> removeAck = new JpaOperation<Set<Ack>>() { @Override public Set<Ack> perform(final EntityManager em) { final List<String> channelIds = new ArrayList<String>(acked.size()); for (Ack ack : acked) { channelIds.add(ack.getChannelId()); } final Query delete = em.createQuery("DELETE from AckDTO c where c.channelId in (:channelIds)"); delete.setParameter("channelIds", channelIds); delete.executeUpdate(); final UserAgentDTO userAgent = em.find(UserAgentDTO.class, uaid); final Set<AckDTO> acks = userAgent.getAcks(); final Set<Ack> unacked = new HashSet<Ack>(acks.size()); for (AckDTO ackDto : acks) { unacked.add(new AckImpl(ackDto.getChannelId(), ackDto.getVersion())); } return unacked; } }; return jpaExecutor.execute(removeAck); } }
JpaDataStore implements DataStore { @Override public Set<Ack> removeAcknowledged(final String uaid, final Set<Ack> acked) { final JpaOperation<Set<Ack>> removeAck = new JpaOperation<Set<Ack>>() { @Override public Set<Ack> perform(final EntityManager em) { final List<String> channelIds = new ArrayList<String>(acked.size()); for (Ack ack : acked) { channelIds.add(ack.getChannelId()); } final Query delete = em.createQuery("DELETE from AckDTO c where c.channelId in (:channelIds)"); delete.setParameter("channelIds", channelIds); delete.executeUpdate(); final UserAgentDTO userAgent = em.find(UserAgentDTO.class, uaid); final Set<AckDTO> acks = userAgent.getAcks(); final Set<Ack> unacked = new HashSet<Ack>(acks.size()); for (AckDTO ackDto : acks) { unacked.add(new AckImpl(ackDto.getChannelId(), ackDto.getVersion())); } return unacked; } }; return jpaExecutor.execute(removeAck); } JpaDataStore(final String persistenceUnit); }
JpaDataStore implements DataStore { @Override public Set<Ack> removeAcknowledged(final String uaid, final Set<Ack> acked) { final JpaOperation<Set<Ack>> removeAck = new JpaOperation<Set<Ack>>() { @Override public Set<Ack> perform(final EntityManager em) { final List<String> channelIds = new ArrayList<String>(acked.size()); for (Ack ack : acked) { channelIds.add(ack.getChannelId()); } final Query delete = em.createQuery("DELETE from AckDTO c where c.channelId in (:channelIds)"); delete.setParameter("channelIds", channelIds); delete.executeUpdate(); final UserAgentDTO userAgent = em.find(UserAgentDTO.class, uaid); final Set<AckDTO> acks = userAgent.getAcks(); final Set<Ack> unacked = new HashSet<Ack>(acks.size()); for (AckDTO ackDto : acks) { unacked.add(new AckImpl(ackDto.getChannelId(), ackDto.getVersion())); } return unacked; } }; return jpaExecutor.execute(removeAck); } 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 Set<Ack> removeAcknowledged(final String uaid, final Set<Ack> acked) { final JpaOperation<Set<Ack>> removeAck = new JpaOperation<Set<Ack>>() { @Override public Set<Ack> perform(final EntityManager em) { final List<String> channelIds = new ArrayList<String>(acked.size()); for (Ack ack : acked) { channelIds.add(ack.getChannelId()); } final Query delete = em.createQuery("DELETE from AckDTO c where c.channelId in (:channelIds)"); delete.setParameter("channelIds", channelIds); delete.executeUpdate(); final UserAgentDTO userAgent = em.find(UserAgentDTO.class, uaid); final Set<AckDTO> acks = userAgent.getAcks(); final Set<Ack> unacked = new HashSet<Ack>(acks.size()); for (AckDTO ackDto : acks) { unacked.add(new AckImpl(ackDto.getChannelId(), ackDto.getVersion())); } return unacked; } }; return jpaExecutor.execute(removeAck); } 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);  }