Package org.apache.cayenne

Examples of org.apache.cayenne.ObjectId


        obj.setPkAttribute(new Integer(2000));
        context.commitChanges();

        // assert that object id got fixed
        ObjectId id = obj.getObjectId();
        assertEquals(new Integer(2000), id.getIdSnapshot().get("PK_ATTRIBUTE"));
    }
View Full Code Here


    public void testRegisteredObjectsCount() throws Exception {
        DataContext context = createDataContext();
        assertEquals(0, context.getObjectStore().registeredObjectsCount());

        DataObject o1 = new MockDataObject();
        o1.setObjectId(new ObjectId("T", "key1", "v1"));
        context.getObjectStore().registerNode(o1.getObjectId(), o1);
        assertEquals(1, context.getObjectStore().registeredObjectsCount());

        // test object with same id
        DataObject o2 = new MockDataObject();
        o2.setObjectId(new ObjectId("T", "key1", "v1"));
        context.getObjectStore().registerNode(o2.getObjectId(), o2);
        assertEquals(1, context.getObjectStore().registeredObjectsCount());

        // test new object
        DataObject o3 = new MockDataObject();
        o3.setObjectId(new ObjectId("T", "key3", "v3"));
        context.getObjectStore().registerNode(o3.getObjectId(), o3);
        assertEquals(2, context.getObjectStore().registeredObjectsCount());
    }
View Full Code Here

        DataRow row = new DataRow(10);
        row.put("ARTIST_ID", new Integer(1));
        row.put("ARTIST_NAME", "ArtistXYZ");
        row.put("DATE_OF_BIRTH", new Date());
        DataObject object = context.objectFromDataRow(Artist.class, row);
        ObjectId oid = object.getObjectId();

        // insert object into the ObjectStore
        context.getObjectStore().registerNode(oid, object);
        assertSame(object, context.getObjectStore().getNode(oid));
        assertNotNull(context.getObjectStore().getCachedSnapshot(oid));
View Full Code Here

    }

    public void testObjectQueryStringMapBoolean() throws Exception {
        createTwoArtistsAndTwoPaintingsDataSet();

        Artist a = (Artist) context.localObject(new ObjectId(
                "Artist",
                Artist.ARTIST_ID_PK_COLUMN,
                11), null);
        Map<String, Artist> parameters = Collections.singletonMap("artist", a);
View Full Code Here

        assertNotNull(counts);
        assertEquals(1, counts.length);
        assertEquals(1, counts[0]);

        Painting p = (Painting) context.localObject(new ObjectId(
                "Painting",
                Painting.PAINTING_ID_PK_COLUMN,
                512), null);
        assertEquals("No Painting Like This", p.getPaintingTitle());
    }
View Full Code Here

        assertNotNull(counts);
        assertEquals(1, counts.length);
        assertEquals(1, counts[0]);

        Painting p = (Painting) context.localObject(new ObjectId(
                "Painting",
                Painting.PAINTING_ID_PK_COLUMN,
                300), null);
        assertEquals("Go Figure", p.getPaintingTitle());
    }
View Full Code Here

        object.setName("o1");
        object.setDecimalPK(new BigDecimal("1.25"));
        context.commitChanges();

        Map map = Collections.singletonMap("DECIMAL_PK", new BigDecimal("1.25"));
        ObjectId syntheticId = new ObjectId("DecimalPKTestEntity", map);
        assertSame(object, context.localObject(syntheticId, null));
    }
View Full Code Here

        object.setName("o2");
        object.setDecimalPK(new Double(1.25));
        context.commitChanges();

        Map map = Collections.singletonMap("DECIMAL_PK", new Double(1.25));
        ObjectId syntheticId = new ObjectId("DecimalPKTest1", map);
        assertSame(object, context.localObject(syntheticId, null));
    }
View Full Code Here

        ClassDescriptor classDescriptor = descriptorResolutionStrategy
                .descriptorForRow(row);

        // not using DataRow.createObjectId for performance reasons - ObjectResolver
        // has all needed metadata already cached.
        ObjectId anId = createObjectId(row, classDescriptor.getEntity(), null);
        return objectFromDataRow(row, anId, classDescriptor);
    }
View Full Code Here

            if (val == null) {
                return null;
            }

            // PUT without a prefix
            return new ObjectId(objEntity.getName(), attribute.getName(), val);
        }

        // ... handle generic case - PK.size > 1

        Map<String, Object> idMap = new HashMap<String, Object>(pk.size() * 2);
        for (final DbAttribute attribute : pk) {

            String key = (prefix) ? namePrefix + attribute.getName() : attribute
                    .getName();

            Object val = dataRow.get(key);

            // this is possible when processing left outer joint prefetches
            if (val == null) {
                return null;
            }

            // PUT without a prefix
            idMap.put(attribute.getName(), val);
        }

        return new ObjectId(objEntity.getName(), idMap);
    }
View Full Code Here

TOP

Related Classes of org.apache.cayenne.ObjectId

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.