Package org.caffinitas.mapper.core

Examples of org.caffinitas.mapper.core.PersistenceSession


        persistenceManager.createSchemaGenerator().generateLiveAlterDDL().execute(persistenceManager.driverSession());
    }

    @Test(dependsOnMethods = "createSchema")
    public void insert_with_ttl() throws Exception {
        PersistenceSession session = persistenceManager.createSession();
        try {
            IfNotExistsEntity inst = new IfNotExistsEntity();
            inst.setPk(2);
            inst.setCk(1);
            inst.setValue("2-1");
            session.insert(inst, new PersistOption.TTLOption(86400));
        } finally {session.close();}
    }
View Full Code Here


        } finally {session.close();}
    }

    @Test(dependsOnMethods = "createSchema")
    public void insert_if_not_exists_first() throws Exception {
        PersistenceSession session = persistenceManager.createSession();
        try {
            IfNotExistsEntity inst = new IfNotExistsEntity();
            inst.setPk(1);
            inst.setCk(1);
            inst.setValue("1-1");
            session.insert(inst, PersistOption.IfNotExistsOption.INSTANCE);
        } finally {session.close();}
    }
View Full Code Here

        } finally {session.close();}
    }

    @Test(dependsOnMethods = "insert_if_not_exists_first", expectedExceptions = CasNotAppliedException.class)
    public void insert_if_not_exists_fail() throws Exception {
        PersistenceSession session = persistenceManager.createSession();
        try {
            IfNotExistsEntity inst = new IfNotExistsEntity();
            inst.setPk(1);
            inst.setCk(1);
            inst.setValue("1-1");
            session.insert(inst, PersistOption.IfNotExistsOption.INSTANCE);
        } finally {session.close();}
    }
View Full Code Here

        } finally {session.close();}
    }

    @Test(dependsOnMethods = "createSchema")
    public void update_if() throws Exception {
        PersistenceSession session = persistenceManager.createSession();
        try {
            IfNotExistsEntity inst = new IfNotExistsEntity();
            inst.setPk(3);
            inst.setCk(5);
            inst.setValue("oldVal");
            session.insert(inst);

            inst = new IfNotExistsEntity();
            inst.setPk(3);
            inst.setCk(5);
            inst.setValue("1-1-update");
            session.update(inst, PersistOption.ifValue("value", "oldVal"));

            IfNotExistsEntity loaded = session.loadOne(IfNotExistsEntity.class, 3, 5);
            Assert.assertEquals(loaded.getValue(), "1-1-update");
        } finally {session.close();}
    }
View Full Code Here

        } finally {session.close();}
    }

    @Test(dependsOnMethods = "insert_if_not_exists_fail")
    public void delete_if_exists_success() throws Exception {
        PersistenceSession session = persistenceManager.createSession();
        try {
            IfNotExistsEntity inst = new IfNotExistsEntity();
            inst.setPk(1);
            inst.setCk(1);
            inst.setValue("1-1-update");
            session.delete(inst, PersistOption.IfExistsOption.INSTANCE);
        } finally {session.close();}
    }
View Full Code Here

        inst.setId(11);
        UserTypeComposite utComposite = buildComposite("some string value", 42);
        Date date = utComposite.getNext().getTs();
        inst.setUserTypeComposite(utComposite);

        PersistenceSession session = persistenceManager.createSession();
        try {
            session.insert(inst);

            UserTypeCompEntity loaded = session.loadOne(UserTypeCompEntity.class, 11);

            Assert.assertNotNull(loaded);
            Assert.assertEquals(loaded.getId(), 11);

            utComposite = loaded.getUserTypeComposite();
            assertUT(utComposite, "some string value", 42);

            NextUserTypeComposite next = utComposite.getNext();
            Assert.assertNotNull(next);
            Assert.assertEquals(next.getValA(), 7.51973d, .01d);
            Assert.assertEquals(next.getTs(), date);
        } finally {session.close();}
    }
View Full Code Here

        } finally {session.close();}
    }

    @Test(dependsOnMethods = "delete_if_exists_success", expectedExceptions = CasNotAppliedException.class)
    public void delete_if_exists_fail() throws Exception {
        PersistenceSession session = persistenceManager.createSession();
        try {
            IfNotExistsEntity inst = new IfNotExistsEntity();
            inst.setPk(99);
            inst.setCk(99);
            inst.setValue("fail");
            session.delete(inst, PersistOption.IfExistsOption.INSTANCE);
        } finally {session.close();}
    }
View Full Code Here

        Assert.assertNull(entity.getAttributeByPath("listCompA.innerA.valCompIA"));

        Assert.assertEquals(entity.getAttributeNames().size(), 3);
        Assert.assertEquals(entity.getAllColumns().length, 3);

        PersistenceSession session = persistenceManager.createSession();
        try {
            UserTypeCompInListEntity inst = new UserTypeCompInListEntity();
            inst.setId(11);

            UserTypeComposite comp = buildComposite("some string value", 42);
            inst.setCompB(comp);

            inst.setListCompA(Arrays.asList(
                buildComposite("array#0", 0),
                buildComposite("array#1", 1),
                buildComposite("array#2", 2),
                buildComposite("array#3", 3),
                buildComposite("array#4", 4)
            ));

            session.insert(inst);

            UserTypeCompInListEntity loaded = session.loadOne(UserTypeCompInListEntity.class, 11);
            Assert.assertNotNull(loaded);
            comp = loaded.getCompB();
            assertUT(comp, "some string value", 42);

            List<UserTypeComposite> actual = inst.getListCompA();
            List<UserTypeComposite> expected = loaded.getListCompA();
            Assert.assertNotNull(actual);
            Assert.assertEquals(actual.size(), expected.size());
            Assert.assertEquals(actual, expected);
        } finally {session.close();}
    }
View Full Code Here

    }

    @Test(dependsOnMethods = "createSchema")
    public void lazySimple() throws Exception {

        PersistenceSession session = persistenceManager.createSession();
        try {

            LazySimpleEntity inst = new LazySimpleEntity();
            inst.setId(1);
            inst.setStrList(Arrays.asList("one", "two", "three"));
            inst.setLazyStrList(Arrays.asList("one", "two", "three"));
            inst.setStrSet(new HashSet<String>(inst.getStrList()));
            inst.setLazyStrSet(new HashSet<String>(inst.getStrList()));
            inst.getStrMap().put("one", "1");
            inst.getStrMap().put("two", "2");
            inst.getStrMap().put("three", "3");
            inst.getLazyStrMap().put("one", "1");
            inst.getLazyStrMap().put("two", "2");
            inst.getLazyStrMap().put("three", "3");

            session.insert(inst);

            LazySimpleEntity loaded = session.loadOneWithOptions(LazySimpleEntity.class, PersistOption.single(PersistOption.loadEager()), 1);

            Assert.assertNotNull(loaded);
            Assert.assertEquals(loaded.getId(), 1);
            Assert.assertNotNull(loaded.getStrList());
            Assert.assertNotNull(loaded.getStrSet());
            Assert.assertNotNull(loaded.getStrMap());
            Assert.assertNotNull(loaded.getLazyStrList());
            Assert.assertNotNull(loaded.getLazyStrSet());
            Assert.assertNotNull(loaded.getLazyStrMap());
            Assert.assertTrue(loaded.getStrList() instanceof ArrayList);
            Assert.assertTrue(loaded.getStrSet() instanceof HashSet);
            Assert.assertTrue(loaded.getStrMap() instanceof HashMap);
            Assert.assertFalse(loaded.getLazyStrList() instanceof LazyList);
            Assert.assertFalse(loaded.getLazyStrSet() instanceof LazySet);
            Assert.assertFalse(loaded.getLazyStrMap() instanceof LazyMap);
            Assert.assertEquals(loaded.getStrList(), Arrays.asList("one", "two", "three"));
            Assert.assertEquals(loaded.getLazyStrList(), Arrays.asList("one", "two", "three"));
            Assert.assertEquals(loaded.getStrSet(), new HashSet<String>(Arrays.asList("one", "two", "three")));
            Assert.assertEquals(loaded.getLazyStrSet(), new HashSet<String>(Arrays.asList("one", "two", "three")));
            Assert.assertEquals(loaded.getStrMap().keySet(), new HashSet<String>(Arrays.asList("one", "two", "three")));
            Assert.assertEquals(loaded.getLazyStrMap().keySet(), new HashSet<String>(Arrays.asList("one", "two", "three")));

            loaded = session.loadOne(LazySimpleEntity.class, 1);

            session.update(loaded);

            Assert.assertNotNull(loaded);
            Assert.assertEquals(loaded.getId(), 1);
            Assert.assertNotNull(loaded.getStrList());
            Assert.assertNotNull(loaded.getStrSet());
            Assert.assertNotNull(loaded.getStrMap());
            Assert.assertNotNull(loaded.getLazyStrList());
            Assert.assertNotNull(loaded.getLazyStrSet());
            Assert.assertNotNull(loaded.getLazyStrMap());
            Assert.assertTrue(loaded.getStrList() instanceof ArrayList);
            Assert.assertTrue(loaded.getStrSet() instanceof HashSet);
            Assert.assertTrue(loaded.getStrMap() instanceof HashMap);
            Assert.assertTrue(loaded.getLazyStrList() instanceof LazyList);
            Assert.assertTrue(loaded.getLazyStrSet() instanceof LazySet);
            Assert.assertTrue(loaded.getLazyStrMap() instanceof LazyMap);
            Assert.assertFalse(((AbstractLazy) loaded.getLazyStrList()).isLoaded());
            Assert.assertFalse(((AbstractLazy) loaded.getLazyStrSet()).isLoaded());
            Assert.assertFalse(((AbstractLazy) loaded.getLazyStrMap()).isLoaded());
            Assert.assertEquals(loaded.getStrList(), Arrays.asList("one", "two", "three"));
            Assert.assertEquals(loaded.getLazyStrList(), Arrays.asList("one", "two", "three"));
            Assert.assertEquals(loaded.getStrSet(), new HashSet<String>(Arrays.asList("one", "two", "three")));
            Assert.assertEquals(loaded.getLazyStrSet(), new HashSet<String>(Arrays.asList("one", "two", "three")));
            Assert.assertEquals(loaded.getStrMap().keySet(), new HashSet<String>(Arrays.asList("one", "two", "three")));
            Assert.assertEquals(loaded.getLazyStrMap().keySet(), new HashSet<String>(Arrays.asList("one", "two", "three")));
            Assert.assertFalse(loaded.getLazyStrList() instanceof LazyList);
            Assert.assertFalse(loaded.getLazyStrSet() instanceof LazySet);
            Assert.assertFalse(loaded.getLazyStrMap() instanceof LazyMap);

            loaded = session.loadOne(LazySimpleEntity.class, 1);

            Assert.assertNotNull(loaded);
            Assert.assertEquals(loaded.getId(), 1);
            Assert.assertNotNull(loaded.getStrList());
            Assert.assertNotNull(loaded.getStrSet());
            Assert.assertNotNull(loaded.getStrMap());
            Assert.assertNotNull(loaded.getLazyStrList());
            Assert.assertNotNull(loaded.getLazyStrSet());
            Assert.assertNotNull(loaded.getLazyStrMap());
            Assert.assertTrue(loaded.getStrList() instanceof ArrayList);
            Assert.assertTrue(loaded.getStrSet() instanceof HashSet);
            Assert.assertTrue(loaded.getStrMap() instanceof HashMap);
            Assert.assertTrue(loaded.getLazyStrList() instanceof LazyList);
            Assert.assertTrue(loaded.getLazyStrSet() instanceof LazySet);
            Assert.assertTrue(loaded.getLazyStrMap() instanceof LazyMap);
            Assert.assertFalse(((AbstractLazy) loaded.getLazyStrList()).isLoaded());
            Assert.assertFalse(((AbstractLazy) loaded.getLazyStrSet()).isLoaded());
            Assert.assertFalse(((AbstractLazy) loaded.getLazyStrMap()).isLoaded());
            session.loadLazy(loaded);
            Assert.assertFalse(loaded.getLazyStrList() instanceof LazyList);
            Assert.assertFalse(loaded.getLazyStrSet() instanceof LazySet);
            Assert.assertFalse(loaded.getLazyStrMap() instanceof LazyMap);
            Assert.assertEquals(loaded.getStrList(), Arrays.asList("one", "two", "three"));
            Assert.assertEquals(loaded.getLazyStrList(), Arrays.asList("one", "two", "three"));
            Assert.assertEquals(loaded.getStrSet(), new HashSet<String>(Arrays.asList("one", "two", "three")));
            Assert.assertEquals(loaded.getLazyStrSet(), new HashSet<String>(Arrays.asList("one", "two", "three")));
            Assert.assertEquals(loaded.getStrMap().keySet(), new HashSet<String>(Arrays.asList("one", "two", "three")));
            Assert.assertEquals(loaded.getLazyStrMap().keySet(), new HashSet<String>(Arrays.asList("one", "two", "three")));

        }finally {session.close();}

    }
View Full Code Here

        Assert.assertNull(entity.getAttributeByPath("setCompA.innerA.valCompIA"));

        Assert.assertEquals(entity.getAttributeNames().size(), 3);
        Assert.assertEquals(entity.getAllColumns().length, 3);

        PersistenceSession session = persistenceManager.createSession();
        try {
            UserTypeCompInSetEntity inst = new UserTypeCompInSetEntity();
            inst.setId(11);

            UserTypeComposite comp = buildComposite("some string value", 42);
            inst.setCompB(comp);

            inst.setSetCompA(new HashSet<UserTypeComposite>(Arrays.asList(
                buildComposite("array#0", 0),
                buildComposite("array#1", 1),
                buildComposite("array#2", 2),
                buildComposite("array#3", 3),
                buildComposite("array#4", 4)
            )));

            session.insert(inst);

            UserTypeCompInSetEntity loaded = session.loadOne(UserTypeCompInSetEntity.class, 11);
            Assert.assertNotNull(loaded);
            comp = loaded.getCompB();
            assertUT(comp, "some string value", 42);

            Set<UserTypeComposite> actual = inst.getSetCompA();
            Set<UserTypeComposite> expected = loaded.getSetCompA();
            Assert.assertNotNull(actual);
            Assert.assertEquals(actual.size(), expected.size());
            Assert.assertEquals(actual, expected);
        } finally {session.close();}
    }
View Full Code Here

TOP

Related Classes of org.caffinitas.mapper.core.PersistenceSession

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.