Package com.impetus.client.entities

Examples of com.impetus.client.entities.PersonRedis


        purge(em);

        final String originalName = "vivek";

        // persist record.
        PersonRedis object = new PersonRedis();
        object.setAge(32);
        object.setPersonId(ROW_KEY);
        object.setPersonName(originalName);

        em.persist(object);

        object.setAge(34);
        object.setPersonId(ROW_KEY + 1);
        object.setPersonName(originalName);

        em.persist(object);

        object.setAge(29);
        object.setPersonId(ROW_KEY + 3);
        object.setPersonName(originalName);

        em.persist(object);

        // Find without where clause.
        String findWithOutWhereClause = "Select p from PersonRedis p";
View Full Code Here


        final String originalName = "vivek";

        for (int i = 0; i < 9; i++)
        {
            PersonRedis object = new PersonRedis();
            object.setAge(32);
            object.setPersonId(ROW_KEY + i);
            object.setPersonName(originalName);
            em.persist(object);

            if (i >= 5)
            {
                PersonRedis result = (PersonRedis) client.find(PersonRedis.class, ROW_KEY + i);
                Assert.assertNull(result);
            }
            else if (i > 0 && i % 4 == 0)
            {
                PersonRedis result = (PersonRedis) client.find(PersonRedis.class, ROW_KEY + i);
                Assert.assertNotNull(result);
                Assert.assertEquals(result.getPersonId(), object.getPersonId());
                Assert.assertEquals(result.getAge(), object.getAge());
                Assert.assertEquals(result.getPersonName(), object.getPersonName());
            }
        }
        em.flush();
        em.clear();
        em.close();
View Full Code Here

     * @param client
     *            Redis client instance.
     */
    private void onUpdate(RedisClient client)
    {
        PersonRedis result = (PersonRedis) client.find(PersonRedis.class, ROW_KEY);
        Assert.assertNotNull(result);

        String updatedName = "Updated";
        result.setPersonName(updatedName);
        result.setAge(33);
        Assert.assertNotNull(result);
        Assert.assertEquals(result.getAge(), new Integer(33));
        Assert.assertEquals(result.getPersonName(), updatedName);
    }
View Full Code Here

     * @param client
     *            Redis client instance.
     */
    private void onDelete(RedisClient client)
    {
        PersonRedis result = (PersonRedis) client.find(PersonRedis.class, ROW_KEY);
        Assert.assertNotNull(result);
        client.delete(result, ROW_KEY);
        result = (PersonRedis) client.find(PersonRedis.class, ROW_KEY);
        Assert.assertNull(result);
    }
View Full Code Here

    private void onInsert(RedisClient client)
    {
        // RedisClient client = (RedisClient) clients.get(REDIS_PU);
        final String nodeId = "node1";
        final String originalName = "vivek";
        PersonRedis object = new PersonRedis();
        object.setAge(32);
        object.setPersonId(ROW_KEY);
        object.setPersonName(originalName);
        object.setDay(Day.TUESDAY);
        object.setMonth(Month.JAN);

        Node node = new Node(nodeId, PersonRedis.class, new TransientState(), null, ROW_KEY, null);
        node.setData(object);
        client.persist(node);

        PersonRedis result = (PersonRedis) client.find(PersonRedis.class, ROW_KEY);

        Assert.assertNotNull(result);
        Assert.assertEquals(result.getPersonId(), object.getPersonId());
        Assert.assertEquals(result.getAge(), object.getAge());
        Assert.assertEquals(result.getPersonName(), object.getPersonName());
        Assert.assertEquals(result.getDay(), object.getDay());
        Assert.assertEquals(result.getMonth(), object.getMonth());
    }
View Full Code Here

        em.persist(p2);
        em.persist(p3);

        // roll back.
        em.getTransaction().rollback();
        PersonRedis p = em.find(PersonRedis.class, "1");
        Assert.assertNull(p);

        // on commit.

        // Still no record should be flushed as already rollback!
View Full Code Here

        // on commit.
        em.getTransaction().commit();

        em.getTransaction().begin();

        PersonRedis p = em.find(PersonRedis.class, "1");
        Assert.assertNotNull(p);

        ((PersonRedis) p2).setPersonName("rollback");
        em.merge(p2);

        // roll back, should roll back person name for p2!
        em.getTransaction().rollback();

        p = em.find(PersonRedis.class, "1");
        Assert.assertNotNull(p);

        p = em.find(PersonRedis.class, "2");
        Assert.assertNotNull(p);
        Assert.assertEquals("vivek", p.getPersonName());
        Assert.assertNotSame("rollback", p.getPersonName());

        em.getTransaction().begin();
        em.getTransaction().commit();
    }
View Full Code Here

     *             the schema disagreement exception
     */
    @Test
    public void rollbackOnError() throws Exception
    {
        PersonRedis p = null;
        try
        {
            Object p1 = prepareData("1", 10);
            Object p2 = prepareData("2", 20);
            em.persist(p1);
            em.persist(p2);

            p = em.find(PersonRedis.class, "1");
            Assert.assertNotNull(p);

            Object p3 = prepareData("3", 15);
            em.persist(p3);

            // Assert on rollback on error.
            ((PersonRedis) p2).setPersonName("rollback");
            em.merge(p2);
            em.merge(null);

            // As this is a runtime exception so rollback should happen and
            // delete out commited data.
        }
        catch (Exception ex)
        {

            p = em.find(PersonRedis.class, "1");
            Assert.assertNull(p);

            p = em.find(PersonRedis.class, "2");
            Assert.assertNull(p);

            p = em.find(PersonRedis.class, "3");
            Assert.assertNull(p);
        }
        em.clear();
        // persist with 1 em
        EntityManager em1 = emf.createEntityManager();
        // em1.setFlushMode(FlushModeType.COMMIT);
        em1.getTransaction().begin();
        Object p3 = prepareData("4", 15);
        em1.persist(p3);
        em1.getTransaction().commit();

        try
        {
            // remove with another em with auto flush.
            EntityManager em2 = emf.createEntityManager();
            PersonRedis person = em2.find(PersonRedis.class, "4");
            em2.remove(person);
            em2.merge(null);
        }
        catch (Exception ex)
        {
View Full Code Here

        // another em instance
        EntityManager em2 = emf.createEntityManager();
        // em2.setFlushMode(FlushModeType.COMMIT);

        // begin transaction.
        PersonRedis found = em2.find(PersonRedis.class, "11");

        em2.getTransaction().begin();
        found.setPersonName("merged");
        em2.merge(found);

        // // commit p1 after modification.
        em2.getTransaction().commit();

        // open another entity manager.
        EntityManager em3 = emf.createEntityManager();
        found = em3.find(PersonRedis.class, "11");
        found.setPersonName("lastemerge");
        try
        {
            em3.merge(found);
            em3.merge(null);
        }
        catch (Exception ex)
        {
            PersonRedis finalFound = em2.find(PersonRedis.class, "11");
            Assert.assertNotNull(finalFound);
            Assert.assertEquals("merged", finalFound.getPersonName());
        }
    }
View Full Code Here

     *            the age
     * @return the person
     */
    private PersonRedis prepareData(String rowKey, int age)
    {
        PersonRedis o = new PersonRedis();
        o.setPersonId(rowKey);
        o.setPersonName("vivek");
        o.setAge(age);
        return o;
    }
View Full Code Here

TOP

Related Classes of com.impetus.client.entities.PersonRedis

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.