Package org.caffinitas.mapper.core

Examples of org.caffinitas.mapper.core.PersistenceSession


        createSchemaDo(Arrays.<Class<?>>asList(MapOneEntity.class, MapSimpleEntity.class, MapSimpleKeyEntity.class, MapSimpleValueEntity.class));
    }

    @Test(dependsOnMethods = "createSchema")
    public void mapEntity_one() throws Exception {
        PersistenceSession session = persistenceManager.createSession();
        try {
            MapOneEntity inst = new MapOneEntity();
            inst.setPkInt(11);
            inst.setPkText("pk");
            MapOneKey k1 = new MapOneKey();
            k1.setCkAscii("key");
            k1.setCkLong(1L);
            MapOneValue v = new MapOneValue();
            v.setStr("hello world");
            inst.put(k1, v);
            MapOneKey k2 = new MapOneKey();
            k2.setCkAscii("dog");
            k2.setCkLong(1L);
            v = new MapOneValue();
            v.setStr("Ursus");
            inst.put(k2, v);
            session.insert(inst);

            MapOneEntity loaded = session.loadOne(MapOneEntity.class, 11, "pk");
            Assert.assertNotNull(loaded);
            Assert.assertEquals(loaded.getPkInt(), 11);
            Assert.assertEquals(loaded.getPkText(), "pk");
            Assert.assertEquals(loaded.size(), 2);
            v = loaded.get(k1);
            Assert.assertNotNull(v);
            Assert.assertEquals(v.getStr(), "hello world");
            v = loaded.get(k2);
            Assert.assertNotNull(v);
            Assert.assertEquals(v.getStr(), "Ursus");
        } finally {session.close();}
    }
View Full Code Here


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

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

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

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

            inst.setMapCompA(new HashMap<UserTypeComposite, String>());
            inst.getMapCompA().put(buildComposite("array#0", 0), "str#0");
            inst.getMapCompA().put(buildComposite("array#1", 1), "str#1");
            inst.getMapCompA().put(buildComposite("array#2", 2), "str#2");
            inst.getMapCompA().put(buildComposite("array#3", 3), "str#3");
            inst.getMapCompA().put(buildComposite("array#4", 4), "str#4");

            session.insert(inst);

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

            assertMapUT(inst.getMapCompA(), loaded.getMapCompA());
        } finally {session.close();}
    }
View Full Code Here

        } finally {session.close();}
    }

    @Test(dependsOnMethods = "createSchema")
    public void mapEntity_simple() throws Exception {
        PersistenceSession session = persistenceManager.createSession();
        try {
            MapSimpleEntity inst = new MapSimpleEntity();
            inst.setPkInt(11);
            inst.setPkText("pk");
            inst.put("key", ByteBuffer.wrap("hello world".getBytes()));
            inst.put("dog", ByteBuffer.wrap("Ursus".getBytes()));
            session.insert(inst);

            MapSimpleEntity loaded = session.loadOne(MapSimpleEntity.class, 11, "pk");
            Assert.assertNotNull(loaded);
            Assert.assertEquals(loaded.getPkInt(), 11);
            Assert.assertEquals(loaded.getPkText(), "pk");
            Assert.assertEquals(loaded.size(), 2);
            ByteBuffer v = loaded.get("key");
            Assert.assertNotNull(v);
            Assert.assertEquals(v, ByteBuffer.wrap("hello world".getBytes()));
            v = loaded.get("dog");
            Assert.assertNotNull(v);
            Assert.assertEquals(v, ByteBuffer.wrap("Ursus".getBytes()));
        } finally {session.close();}
    }
View Full Code Here

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

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

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

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

            inst.setMapCompA(new HashMap<String, UserTypeComposite>());
            inst.getMapCompA().put("str#0", buildComposite("array#0", 0));
            inst.getMapCompA().put("str#1", buildComposite("array#1", 1));
            inst.getMapCompA().put("str#2", buildComposite("array#2", 2));
            inst.getMapCompA().put("str#3", buildComposite("array#3", 3));
            inst.getMapCompA().put("str#4", buildComposite("array#4", 4));

            session.insert(inst);

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

            assertMapUT(inst.getMapCompA(), loaded.getMapCompA());
        } finally {session.close();}
    }
View Full Code Here

    }

    @Test
    public void lazyComposite() throws Exception {

        PersistenceSession session = persistenceManager.createSession();
        try {

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

            session.insert(inst);

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

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

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

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

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

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

    }
View Full Code Here

        } finally {session.close();}
    }

    @Test(dependsOnMethods = "createSchema")
    public void mapEntity_simpleKey() throws Exception {
        PersistenceSession session = persistenceManager.createSession();
        try {
            MapSimpleKeyEntity inst = new MapSimpleKeyEntity();
            inst.setPkInt(11);
            inst.setPkText("pk");
            MapSimpleKeyValue v = new MapSimpleKeyValue();
            v.setValue("hello world");
            inst.put("key", v);
            v = new MapSimpleKeyValue();
            v.setValue("Ursus");
            inst.put("dog", v);
            session.insert(inst);

            MapSimpleKeyEntity loaded = session.loadOne(MapSimpleKeyEntity.class, 11, "pk");
            Assert.assertNotNull(loaded);
            Assert.assertEquals(loaded.getPkInt(), 11);
            Assert.assertEquals(loaded.getPkText(), "pk");
            Assert.assertEquals(loaded.size(), 2);
            v = loaded.get("key");
            Assert.assertNotNull(v);
            Assert.assertEquals(v.getValue(), "hello world");
            v = loaded.get("dog");
            Assert.assertNotNull(v);
            Assert.assertEquals(v.getValue(), "Ursus");
        } finally {session.close();}
    }
View Full Code Here

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

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

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

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

            inst.setMapCompA(new HashMap<UserTypeComposite, UserTypeComposite>());
            inst.getMapCompA().put(buildComposite("key#0", 0), buildComposite("val#0", 0));
            inst.getMapCompA().put(buildComposite("key#1", 1), buildComposite("val#1", 1));
            inst.getMapCompA().put(buildComposite("key#2", 2), buildComposite("val#2", 2));
            inst.getMapCompA().put(buildComposite("key#3", 3), buildComposite("val#3", 3));
            inst.getMapCompA().put(buildComposite("key#4", 4), buildComposite("val#4", 4));

            session.insert(inst);

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

            assertMapUT(inst.getMapCompA(), loaded.getMapCompA());
        } finally {session.close();}
    }
View Full Code Here

        } finally {session.close();}
    }

    @Test(dependsOnMethods = "createSchema")
    public void mapEntity_simpleValue() throws Exception {
        PersistenceSession session = persistenceManager.createSession();
        try {
            MapSimpleValueEntity inst = new MapSimpleValueEntity();
            inst.setPkInt(11);
            inst.setPkText("pk");
            MapSimpleValueKey k1 = new MapSimpleValueKey();
            k1.setCkAscii("key");
            k1.setCkLong(0L);
            inst.put(k1, "hello world");
            MapSimpleValueKey k2 = new MapSimpleValueKey();
            k2.setCkAscii("dog");
            k2.setCkLong(0L);
            inst.put(k2, "Ursus");
            session.insert(inst);

            MapSimpleValueEntity loaded = session.loadOne(MapSimpleValueEntity.class, 11, "pk");
            Assert.assertNotNull(loaded);
            Assert.assertEquals(loaded.getPkInt(), 11);
            Assert.assertEquals(loaded.getPkText(), "pk");
            Assert.assertEquals(loaded.size(), 2);
            Assert.assertEquals(loaded.get(k1), "hello world");
            Assert.assertEquals(loaded.get(k2), "Ursus");
        } finally {session.close();}
    }
View Full Code Here

    }

    @Test
    public void lazy_tpc() throws Exception {

        PersistenceSession session = persistenceManager.createSession();
        try {
            TpcInheritA instA = new TpcInheritA();
            instA.setId(1);
            instA.setInhA(Arrays.asList("one", "two", "three"));
            session.insert(instA);

            TpcInheritB instB = new TpcInheritB();
            instB.setId(2);
            instB.setInhB(new HashSet<String>(Arrays.asList("one", "two", "three")));
            session.insert(instB);

            TpcInheritB2 instB2 = new TpcInheritB2();
            instB2.setId(3);
            instB2.setInhB2(Arrays.asList("one", "two", "three"));
            session.insert(instB2);

            TpcInheritC instC = new TpcInheritC();
            instC.setId(4);
            instC.setInhC(new HashMap<String, String>());
            instC.getInhC().put("one", "1");
            instC.getInhC().put("two", "2");
            instC.getInhC().put("three", "3");
            session.insert(instC);

            TpcInheritA loadedA = (TpcInheritA) session.loadOne(TpcBaseEntity.class, 1);
            Assert.assertTrue(loadedA.getInhA() instanceof LazyList);
            Assert.assertEquals(loadedA.getInhA(), Arrays.asList("one", "two", "three"));
            loadedA = session.loadOne(TpcInheritA.class, 1);
            Assert.assertTrue(loadedA.getInhA() instanceof LazyList);
            Assert.assertEquals(loadedA.getInhA(), Arrays.asList("one", "two", "three"));

            TpcInheritB loadedB = (TpcInheritB) session.loadOne(TpcBaseEntity.class, 2);
            Assert.assertTrue(loadedB.getInhB() instanceof LazySet);
            Assert.assertEquals(loadedB.getInhB(), new HashSet<String>(Arrays.asList("one", "two", "three")));
            loadedB = session.loadOne(TpcInheritB.class, 2);
            Assert.assertTrue(loadedB.getInhB() instanceof LazySet);
            Assert.assertEquals(loadedB.getInhB(), new HashSet<String>(Arrays.asList("one", "two", "three")));

            TpcInheritB2 loadedB2 = (TpcInheritB2) session.loadOne(TpcBaseEntity.class, 3);
            Assert.assertTrue(loadedB2.getInhB2() instanceof LazyList);
            Assert.assertEquals(loadedB2.getInhB2(), Arrays.asList("one", "two", "three"));
            loadedB2 = session.loadOne(TpcInheritB2.class, 3);
            Assert.assertTrue(loadedB2.getInhB2() instanceof LazyList);
            Assert.assertEquals(loadedB2.getInhB2(), Arrays.asList("one", "two", "three"));

            TpcInheritC loadedC = (TpcInheritC) session.loadOne(TpcBaseEntity.class, 4);
            Assert.assertTrue(loadedC.getInhC() instanceof LazyMap);
            Assert.assertEquals(loadedC.getInhC().keySet(), new HashSet<String>(Arrays.asList("one", "two", "three")));
            loadedC = session.loadOne(TpcInheritC.class, 4);
            Assert.assertTrue(loadedC.getInhC() instanceof LazyMap);
            Assert.assertEquals(loadedC.getInhC().keySet(), new HashSet<String>(Arrays.asList("one", "two", "three")));

        }finally {session.close();}
    }
View Full Code Here

    }

    @Test
    public void lazy_st() throws Exception {

        PersistenceSession session = persistenceManager.createSession();
        try {
            StInheritA instA = new StInheritA();
            instA.setId(1);
            instA.setInhA(Arrays.asList("one", "two", "three"));
            session.insert(instA);

            StInheritB instB = new StInheritB();
            instB.setId(2);
            instB.setInhB(new HashSet<String>(Arrays.asList("one", "two", "three")));
            session.insert(instB);

            StInheritB2 instB2 = new StInheritB2();
            instB2.setId(3);
            instB2.setInhB2(Arrays.asList("one", "two", "three"));
            session.insert(instB2);

            StInheritC instC = new StInheritC();
            instC.setId(4);
            instC.setInhC(new HashMap<String, String>());
            instC.getInhC().put("one", "1");
            instC.getInhC().put("two", "2");
            instC.getInhC().put("three", "3");
            session.insert(instC);

            StInheritA loadedA = (StInheritA) session.loadOne(StBaseEntity.class, 1);
            Assert.assertTrue(loadedA.getInhA() instanceof LazyList);
            Assert.assertEquals(loadedA.getInhA(), Arrays.asList("one", "two", "three"));
            loadedA = session.loadOne(StInheritA.class, 1);
            Assert.assertTrue(loadedA.getInhA() instanceof LazyList);
            Assert.assertEquals(loadedA.getInhA(), Arrays.asList("one", "two", "three"));

            StInheritB loadedB = (StInheritB) session.loadOne(StBaseEntity.class, 2);
            Assert.assertTrue(loadedB.getInhB() instanceof LazySet);
            Assert.assertEquals(loadedB.getInhB(), new HashSet<String>(Arrays.asList("one", "two", "three")));
            loadedB = session.loadOne(StInheritB.class, 2);
            Assert.assertTrue(loadedB.getInhB() instanceof LazySet);
            Assert.assertEquals(loadedB.getInhB(), new HashSet<String>(Arrays.asList("one", "two", "three")));

            StInheritB2 loadedB2 = (StInheritB2) session.loadOne(StBaseEntity.class, 3);
            Assert.assertTrue(loadedB2.getInhB2() instanceof LazyList);
            Assert.assertEquals(loadedB2.getInhB2(), Arrays.asList("one", "two", "three"));
            loadedB2 = session.loadOne(StInheritB2.class, 3);
            Assert.assertTrue(loadedB2.getInhB2() instanceof LazyList);
            Assert.assertEquals(loadedB2.getInhB2(), Arrays.asList("one", "two", "three"));

            StInheritC loadedC = (StInheritC) session.loadOne(StBaseEntity.class, 4);
            Assert.assertTrue(loadedC.getInhC() instanceof LazyMap);
            Assert.assertEquals(loadedC.getInhC().keySet(), new HashSet<String>(Arrays.asList("one", "two", "three")));
            loadedC = session.loadOne(StInheritC.class, 4);
            Assert.assertTrue(loadedC.getInhC() instanceof LazyMap);
            Assert.assertEquals(loadedC.getInhC().keySet(), new HashSet<String>(Arrays.asList("one", "two", "three")));

        }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.