Package org.apache.cayenne.jpa.map

Examples of org.apache.cayenne.jpa.map.JpaEntity


        }

        @Override
        public void onFinishNode(ProjectPath path) {

            JpaEntity entity = path.firstInstanceOf(JpaEntity.class);
            DataMap dataMap = targetPath.firstInstanceOf(DataMap.class);
            ObjEntity cayenneEntity = targetPath.firstInstanceOf(ObjEntity.class);

            // as superentity may not be loaded yet, must lookup DbEntity via JPA
            // mapping...
            DbEntity cayennePrimaryTable = dataMap.getDbEntity(entity
                    .lookupTable()
                    .getName());

            for (JpaSecondaryTable secondaryTable : entity.getSecondaryTables()) {

                // create a relationship between master DbEntity and a secondary
                // DbEntity...

                DbEntity cayenneSecondaryTable = dataMap.getDbEntity(secondaryTable
                        .getName());

                JpaDbRelationship dbRelationship = new JpaDbRelationship(
                        getSecondaryTableDbRelationshipName(secondaryTable.getName()));
                dbRelationship.setTargetEntityName(secondaryTable.getName());
                cayennePrimaryTable.addRelationship(dbRelationship);

                for (JpaPrimaryKeyJoinColumn column : secondaryTable
                        .getPrimaryKeyJoinColumns()) {
                    DbAttribute pkAttribute = (DbAttribute) cayennePrimaryTable
                            .getAttribute(column.getReferencedColumnName());
                    if (pkAttribute == null) {
                        recordConflict(path, "Invalid referenced column name: "
                                + column.getReferencedColumnName());
                        continue;
                    }

                    DbAttribute attribute = new DbAttribute(column.getName());
                    attribute.setPrimaryKey(true);
                    attribute.setMandatory(true);
                    attribute.setAttributePrecision(pkAttribute.getAttributePrecision());
                    attribute.setType(pkAttribute.getType());
                    attribute.setMaxLength(pkAttribute.getMaxLength());
                    attribute.setAttributePrecision(pkAttribute.getAttributePrecision());
                    cayenneSecondaryTable.addAttribute(attribute);

                    DbJoin join = new DbJoin(dbRelationship, column
                            .getReferencedColumnName(), column.getName());
                    dbRelationship.addJoin(join);
                }

                dbRelationship.setToDependentPK(true);
                dbRelationship.setToMany(false);
            }

            // init discriminator column
            JpaDiscriminatorColumn discriminator = entity.lookupDiscriminatorColumn();
            if (discriminator != null) {

                if (cayennePrimaryTable.getAttribute(discriminator.getName()) == null) {
                    DbAttribute dbAttribute = new DbAttribute(discriminator.getName());

                    switch (discriminator.getDiscriminatorType()) {
                        case CHAR:
                            dbAttribute.setType(Types.CHAR);
                            dbAttribute.setMaxLength(1);
                            break;
                        case STRING:
                            dbAttribute.setType(Types.VARCHAR);
                            dbAttribute.setMaxLength(discriminator.getLength());
                            break;
                        case INTEGER:
                            dbAttribute.setType(Types.INTEGER);
                            break;
                    }

                    dbAttribute.setMandatory(false);
                    cayennePrimaryTable.addAttribute(dbAttribute);
                }

                String valueString = entity.getDiscriminatorValue();
                if (valueString != null && valueString.length() > 0) {

                    Object value = null;
                    switch (discriminator.getDiscriminatorType()) {
                        case CHAR:
View Full Code Here


            ObjRelationship cayenneRelationship = new ObjRelationship(relationship
                    .getName());

            cayenneSrcEntity.addRelationship(cayenneRelationship);

            JpaEntity jpaTargetEntity = ((JpaEntityMap) path.getRoot())
                    .entityForClass(relationship.getTargetEntityName());

            if (jpaTargetEntity == null) {
                recordConflict(path, "Unknown target entity '"
                        + relationship.getTargetEntityName());
                return null;
            }

            cayenneRelationship.setTargetEntityName(jpaTargetEntity.getName());

            DbEntity cayenneSrcDbEntity = cayenneSrcEntity.getDbEntity();
            DbEntity cayenneTargetDbEntity = cayenneSrcEntity.getDataMap().getDbEntity(
                    jpaTargetEntity.getTable().getName());
            if (cayenneTargetDbEntity == null) {
                cayenneTargetDbEntity = new DbEntity(jpaTargetEntity.getTable().getName());
                cayenneSrcEntity.getDataMap().addDbEntity(cayenneTargetDbEntity);
            }

            JpaDbRelationship dbRelationship = new JpaDbRelationship(cayenneRelationship
                    .getName());
View Full Code Here

        JpaEntityMap jpaMap = context.getEntityMap();

        JpaTable table = new JpaTable();
        table.setName("ET1");
       
        JpaEntity jpaEntity = new JpaEntity();
        jpaEntity.setName("E1");
        jpaEntity.setClassName("abc.C2");
        jpaEntity.setTable(table);
        jpaEntity.setPostLoad(new JpaLifecycleCallback("xpl2"));
        jpaEntity.setPreRemove(new JpaLifecycleCallback("xpr2"));
        jpaMap.getEntities().add(jpaEntity);

        DataMap cayenneMap = new DataMapConverter().toDataMap("n1", context);

        ObjEntity entity = cayenneMap.getObjEntity("E1");
View Full Code Here

        JpaEntityMap jpaMap = context.getEntityMap();

        JpaTable table = new JpaTable();
        table.setName("ET1");
       
        JpaEntity jpaEntity = new JpaEntity();
        jpaEntity.setName("E1");
        jpaEntity.setClassName("abc.C2");
        jpaEntity.setTable(table);
        jpaEntity.setPostLoad(new JpaLifecycleCallback("xpl2"));
        jpaEntity.setPreRemove(new JpaLifecycleCallback("xpr2"));
        jpaMap.getEntities().add(jpaEntity);

        JpaEntityListeners listeners = new JpaEntityListeners();
        jpaEntity.setEntityListeners(listeners);

        JpaEntityListener l1 = new JpaEntityListener();
        l1.setClassName("abc.C1");
        l1.setPostLoad(new JpaLifecycleCallback("xpl1"));
        l1.setPreRemove(new JpaLifecycleCallback("xpr1"));
View Full Code Here

                new MockPersistenceUnitInfo());
        EntityMapAnnotationLoader loader = new EntityMapAnnotationLoader(context);
        loader.loadClassMapping(MockAnnotatedBeanOrdering.class);

        JpaEntityMap map = context.getEntityMap();
        JpaEntity entity = map.getEntities().iterator().next();

        // regardless of the ordering of annotations, we should get the same result for
        // both attributes
        assertEquals(3, entity.getAttributes().getBasicAttributes().size());
        JpaBasic a1 = entity.getAttributes().getBasicAttribute("attribute1");
        assertTrue(a1.isLob());

        JpaBasic a2 = entity.getAttributes().getBasicAttribute("attribute2");
        assertTrue(a2.isLob());

        JpaBasic a3 = entity.getAttributes().getBasicAttribute("attribute3");
        assertTrue(a3.isLob());
    }
View Full Code Here

        EntityMapAnnotationLoader loader = new EntityMapAnnotationLoader(context);
        loader.loadClassMapping(MockAnnotatedBean2.class);

        JpaEntityMap map = context.getEntityMap();
        assertEquals(1, map.getEntities().size());
        JpaEntity entity = map.getEntities().iterator().next();
        assertEquals(1, entity.getAttributeOverrides().size());
        JpaAttributeOverride entityOverride = entity
                .getAttributeOverrides()
                .iterator()
                .next();
        assertEquals("entityAttribute", entityOverride.getName());
    }
View Full Code Here

        assertNull(entity.getAttributes().getBasicAttribute("attribute2"));
    }

    public void testSkipCayennePersistentProperties() throws Exception {

        JpaEntity e5 = context.getEntityMap().entityForClass(MockAnnotatedBean5.class);
        assertNotNull(e5);

        assertNotNull(e5.getAttributes().getBasicAttribute("attribute1"));
        assertNull(e5.getAttributes().getBasicAttribute("objectId"));
    }
View Full Code Here

                ProjectPath path,
                JpaManagedClass managedClass,
                JpaColumn column) {

            if (managedClass instanceof JpaEntity) {
                JpaEntity entity = (JpaEntity) managedClass;

                if (column.getTable().equals(entity.lookupTable().getName())) {
                    return column.getName();
                }

                JpaSecondaryTable table = entity.getSecondaryTable(column.getTable());
                if (table == null) {
                    recordConflict(path, "Unrecognized secondary table: '"
                            + column.getTable()
                            + "'");
                    return column.getName();
View Full Code Here

        @Override
        public boolean onStartNode(ProjectPath path) {

            JpaJoinColumn jpaJoin = (JpaJoinColumn) path.getObject();
            JpaRelationship jpaRelationship = (JpaRelationship) path.getObjectParent();
            JpaEntity targetEntity = context.getEntityMap().entityForClass(
                    jpaRelationship.getTargetEntityName());
            JpaId jpaTargetId = targetEntity.getAttributes().getIdForColumnName(
                    jpaJoin.getReferencedColumnName());

            if (jpaTargetId == null) {
                throw new IllegalArgumentException("Null id "
                        + targetEntity.getName()
                        + "."
                        + jpaJoin.getReferencedColumnName());
            }

            DbRelationship dbRelationship = (DbRelationship) targetPath.getObject();
View Full Code Here

        @Override
        public boolean onStartNode(ProjectPath path) {

            JpaJoinColumn jpaJoin = (JpaJoinColumn) path.getObject();
            JpaRelationship jpaRelationship = (JpaRelationship) path.getObjectParent();
            JpaEntity targetEntity = context.getEntityMap().entityForClass(
                    jpaRelationship.getTargetEntityName());
            JpaId jpaTargetId = targetEntity.getAttributes().getId(
                    jpaJoin.getReferencedColumnName());

            ObjRelationship objRelationship = (ObjRelationship) targetPath.getObject();
            DataMap dataMap = objRelationship.getSourceEntity().getDataMap();
View Full Code Here

TOP

Related Classes of org.apache.cayenne.jpa.map.JpaEntity

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.