Package org.jboss.aerogear.simplepush.server.datastore.model

Examples of org.jboss.aerogear.simplepush.server.datastore.model.UserAgentDTO


    @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 {
View Full Code Here


    public Set<String> getChannelIds(final String uaid) {
        final JpaOperation<Set<String>> getChannelIds = new JpaOperation<Set<String>>() {
            @Override
            public Set<String> perform(final EntityManager em) {
                final Set<String> channels = new HashSet<String>();
                final UserAgentDTO userAgent = em.find(UserAgentDTO.class, uaid);
                if (userAgent != null) {
                    for (ChannelDTO dto : userAgent.getChannels()) {
                        channels.add(dto.getChannelId());
                    }
                }
                return channels;
            }
View Full Code Here

    @Override
    public void removeChannels(final String uaid) {
        final JpaOperation<Void> removeChannels = new JpaOperation<Void>() {
            @Override
            public Void perform(final EntityManager em) {
                final UserAgentDTO userAgent = em.find(UserAgentDTO.class, uaid);
                if (userAgent != null) {
                    final Set<ChannelDTO> channels = userAgent.getChannels();
                    for (ChannelDTO channelDTO : channels) {
                        em.remove(channelDTO);
                    }
                    channels.clear();
                    userAgent.setChannels(channels);
                }
                return null;
            }
        };
        jpaExecutor.execute(removeChannels);
View Full Code Here

    public String saveUnacknowledged(final String channelId, final long version) throws ChannelNotFoundException {
        final JpaOperation<String> saveAcks = new JpaOperation<String>() {
            @Override
            public String perform(final EntityManager em) {
                final ChannelDTO channel = em.find(ChannelDTO.class, channelId);
                final UserAgentDTO userAgent = channel.getUserAgent();
                final Set<AckDTO> dtos = new HashSet<AckDTO>();
                dtos.add(new AckDTO(userAgent, channel.getChannelId(), version));
                userAgent.setAcks(dtos);
                em.merge(userAgent);
                return userAgent.getUaid();
            }
        };
        return jpaExecutor.execute(saveAcks);
    }
View Full Code Here

    @Override
    public Set<Ack> getUnacknowledged(final String uaid) {
        final JpaOperation<Set<Ack>> getUnacks = new JpaOperation<Set<Ack>>() {
            @Override
            public Set<Ack> perform(final EntityManager em) {
                final UserAgentDTO userAgent = em.find(UserAgentDTO.class, uaid);
                if (userAgent == null) {
                    return Collections.emptySet();
                }
                final HashSet<Ack> acks = new HashSet<Ack>();
                for (AckDTO ackDTO : userAgent.getAcks()) {
                    acks.add(new AckImpl(ackDTO.getChannelId(), ackDTO.getVersion()));
                }
                return acks;
            }
        };
View Full Code Here

                    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;
View Full Code Here

    @Test
    public void persistUserAgent() {
        final String channelId = UUID.randomUUID().toString();
        final String uaid = UUIDUtil.newUAID();
        final UserAgentDTO userAgent = persist(uaid, channelId, 1, "/endpoint/" + channelId);
        assertThat(entityManager.contains(userAgent), is(true));

        entityManager.getTransaction().begin();
        final UserAgentDTO ua = entityManager.find(UserAgentDTO.class, userAgent.getUaid());
        assertThat(ua.getUaid(), equalTo(uaid.toString()));
        assertThat(ua.getChannels().size(), is(1));
        assertThat(ua.getChannels().iterator().next().getChannelId(), equalTo(channelId));
        assertThat(ua.getChannels().iterator().next().getVersion(), equalTo(1L));
        entityManager.getTransaction().commit();
    }
View Full Code Here

    @Test
    public void removeUserAgent() {
        final String channelId = UUID.randomUUID().toString();
        final String uaid = UUIDUtil.newUAID();
        final UserAgentDTO userAgent = persist(uaid, channelId, 1, "/endpoint/" + channelId);
        assertThat(entityManager.contains(userAgent), is(true));
        entityManager.getTransaction().begin();
        entityManager.remove(userAgent);
        entityManager.getTransaction().commit();
        final UserAgentDTO ua = entityManager.find(UserAgentDTO.class, userAgent.getUaid());
        assertThat(ua, is(nullValue()));
        final ChannelDTO channel = entityManager.find(ChannelDTO.class, channelId);
        assertThat(channel, is(nullValue()));
    }
View Full Code Here

    @Test
    public void persistUpdate() {
        final String channelId = UUID.randomUUID().toString();
        final String uaid = UUIDUtil.newUAID();
        final UserAgentDTO userAgent = persist(uaid, channelId, 10, "/endpoint/" + channelId);

        entityManager.getTransaction().begin();
        final AckDTO update = new AckDTO(userAgent, channelId, 10);
        entityManager.persist(update);
        entityManager.getTransaction().commit();
View Full Code Here

    @Test
    public void persistUpdateToSameChannel() {
        final String channelId = UUID.randomUUID().toString();
        final String uaid = UUIDUtil.newUAID();
        final UserAgentDTO userAgent = persist(uaid, channelId, 10, "/endpoint/" + channelId);

        entityManager.getTransaction().begin();
        final AckDTO update = new AckDTO(userAgent, channelId, 10);
        entityManager.persist(update);
        entityManager.getTransaction().commit();

        entityManager.getTransaction().begin();
        final UserAgentDTO userAgentToUpdate = entityManager.find(UserAgentDTO.class, uaid);
        final AckDTO newUpdate = new AckDTO(userAgent, channelId, 11);
        userAgentToUpdate.setAcks(new HashSet<AckDTO>(Arrays.asList(newUpdate)));
        entityManager.merge(userAgentToUpdate);
        entityManager.getTransaction().commit();

        entityManager.getTransaction().begin();
        final AckDTO updated = entityManager.find(AckDTO.class, channelId);
View Full Code Here

TOP

Related Classes of org.jboss.aerogear.simplepush.server.datastore.model.UserAgentDTO

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.