Package org.apache.cayenne.map

Examples of org.apache.cayenne.map.ObjEntity


    public void registerNewObject(Object object) {
        if (object == null) {
            throw new NullPointerException("Can't register null object.");
        }

        ObjEntity entity = getEntityResolver().lookupObjEntity(object);
        if (entity == null) {
            throw new IllegalArgumentException(
                    "Can't find ObjEntity for Persistent class: "
                            + object.getClass().getName()
                            + ", class is likely not mapped.");
        }

        final Persistent persistent = (Persistent) object;

        // sanity check - maybe already registered
        if (persistent.getObjectId() != null) {
            if (persistent.getObjectContext() == this) {
                // already registered, just ignore
                return;
            }
            else if (persistent.getObjectContext() != null) {
                throw new IllegalStateException(
                        "Persistent is already registered with another DataContext. "
                                + "Try using 'localObjects()' instead.");
            }
        }
        else {
            persistent.setObjectId(new ObjectId(entity.getName()));
        }

        ClassDescriptor descriptor = getEntityResolver().getClassDescriptor(
                entity.getName());
        if (descriptor == null) {
            throw new IllegalArgumentException("Invalid entity name: " + entity.getName());
        }

        injectInitialValue(object);

        // now we need to find all arc changes, inject missing value holders and pull in
View Full Code Here


import org.apache.cayenne.unit.CayenneCase;

public class SelectQueryPrefetchRouterActionTest extends CayenneCase {

    public void testPaintings1() {
        ObjEntity paintingEntity = getDomain().getEntityResolver().lookupObjEntity(
                Painting.class);
        SelectQuery q = new SelectQuery(Artist.class, ExpressionFactory.matchExp(
                "artistName",
                "abc"));
        q.addPrefetch(Artist.PAINTING_ARRAY_PROPERTY);
View Full Code Here

        assertEquals(Expression.fromString("db:toArtist.ARTIST_NAME = 'abc'"), prefetch
                .getQualifier());
    }

    public void testPrefetchPaintings2() {
        ObjEntity paintingEntity = getDomain().getEntityResolver().lookupObjEntity(
                Painting.class);

        SelectQuery q = new SelectQuery(Artist.class, Expression
                .fromString("artistName = 'abc' or artistName = 'xyz'"));
        q.addPrefetch(Artist.PAINTING_ARRAY_PROPERTY);
View Full Code Here

                        .fromString("db:toArtist.ARTIST_NAME = 'abc' or db:toArtist.ARTIST_NAME = 'xyz'"),
                prefetch.getQualifier());
    }

    public void testGalleries() {
        ObjEntity galleryEntity = getDomain().getEntityResolver().lookupObjEntity(
                Gallery.class);
        SelectQuery q = new SelectQuery(Artist.class, ExpressionFactory.matchExp(
                "artistName",
                "abc"));
        q.addPrefetch("paintingArray.toGallery");
View Full Code Here

        map.addDbEntity(dbEntity);

        assertTokensAndExecute(node, map, 1, 0);
        assertTokensAndExecute(node, map, 0, 0);

        ObjEntity objEntity = new ObjEntity("NewTable");
        objEntity.setDbEntity(dbEntity);
        ObjAttribute oatr1 = new ObjAttribute("name");
        oatr1.setDbAttributePath(column2.getName());
        oatr1.setType("java.lang.String");
        objEntity.addAttribute(oatr1);
        map.addObjEntity(objEntity);

        // try to insert some rows to check that pk stuff is working
        DataContext ctxt = createDataContext();
        DataMap sourceMap = map;//ctxt.getEntityResolver().getDataMap("testmap");

        try {
            sourceMap.addDbEntity(dbEntity);
            sourceMap.addObjEntity(objEntity);

            for (int i = 0; i < 5; i++) {
                CayenneDataObject dao = (CayenneDataObject) ctxt.newObject(objEntity
                        .getName());
                dao.writeProperty(oatr1.getName(), "test " + i);
            }
            ctxt.commitChanges();
        }
        finally {
            sourceMap.removeObjEntity(objEntity.getName(), true);
            sourceMap.removeDbEntity(dbEntity.getName(), true);
        }

        // clear up
        map.removeObjEntity(objEntity.getName(), true);
        map.removeDbEntity(dbEntity.getName(), true);
        ctxt.getEntityResolver().clearCache();
        assertNull(map.getObjEntity(objEntity.getName()));
        assertNull(map.getDbEntity(dbEntity.getName()));
        assertFalse(map.getDbEntities().contains(dbEntity));

        assertTokensAndExecute(node, map, 1, 0);
        assertTokensAndExecute(node, map, 0, 0);
View Full Code Here

        }
        assertTrue(token.getClass().getName(), token instanceof CreateTableToModel);
        logTokens(Collections.singletonList(token));
        execute(token);

        ObjEntity objEntity = null;
        for (ObjEntity candiate : map.getObjEntities()) {
            if (candiate.getDbEntity() == null) {
                continue;
            }
            if (candiate.getDbEntity().getName().equalsIgnoreCase(dbEntity.getName())) {
                objEntity = candiate;
                break;
            }
        }
        assertNotNull(objEntity);
       
        assertEquals(objEntity.getClassName(), map.getDefaultPackage() + "." + objEntity.getName());
        assertEquals(objEntity.getSuperClassName(), map.getDefaultSuperclass());
        assertEquals(objEntity.getClientClassName(),
                map.getDefaultClientPackage() + "." + objEntity.getName());
        assertEquals(objEntity.getClientSuperClassName(), map.getDefaultClientSuperclass());

        assertEquals(1, objEntity.getAttributes().size());
        assertEquals("java.lang.String", objEntity
                .getAttributes()
                .iterator()
                .next()
                .getType());

        DataContext ctxt = createDataContext();

        // clear up
        // fix psql case issue
        map.removeDbEntity(objEntity.getDbEntity().getName(), true);
        map.removeObjEntity(objEntity.getName(), true);
        map.removeDbEntity(dbEntity.getName(), true);
        ctxt.getEntityResolver().clearCache();
        assertNull(map.getObjEntity(objEntity.getName()));
        assertNull(map.getDbEntity(dbEntity.getName()));
        assertFalse(map.getDbEntities().contains(dbEntity));

        assertTokensAndExecute(node, map, 1, 0);
        assertTokensAndExecute(node, map, 0, 0);
View Full Code Here

    }

    public void testEvaluateOBJ_PATH_ObjEntity() throws Exception {
        ASTObjPath node = new ASTObjPath("paintingArray.paintingTitle");

        ObjEntity ae = getDomain().getEntityResolver().lookupObjEntity(Artist.class);

        Object target = node.evaluate(ae);
        assertTrue(target instanceof ObjAttribute);
    }
View Full Code Here

    }

    public void testEvaluateDB_PATH_DbEntity() throws Exception {
        Expression e = Expression.fromString("db:paintingArray.PAINTING_TITLE");

        ObjEntity ae = getDomain().getEntityResolver().lookupObjEntity(Artist.class);
        DbEntity ade = ae.getDbEntity();

        Object objTarget = e.evaluate(ae);
        assertTrue(objTarget instanceof DbAttribute);

        Object dbTarget = e.evaluate(ade);
View Full Code Here

            return "UntitledObjEntity";
        }

        @Override
        protected Object create(String name, Object namingContext) {
            return new ObjEntity(name);
        }
View Full Code Here

        DataDomain domain = new DataDomain("dom1");
        org.apache.cayenne.map.EntityResolver resolver = domain.getEntityResolver();
        assertNotNull(resolver);

        DataMap map = new DataMap("map");
        ObjEntity entity = new ObjEntity("TestEntity");
        map.addObjEntity(entity);

        domain.addDataMap(map);

        assertSame(entity, resolver.getObjEntity("TestEntity"));
View Full Code Here

TOP

Related Classes of org.apache.cayenne.map.ObjEntity

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.