Package org.apache.cayenne.jpa.map

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


            addChildVisitor(JpaEntityListeners.class, listenersVisitor);
        }

        @Override
        Object createObject(ProjectPath path) {
            JpaEntity jpaEntity = (JpaEntity) path.getObject();
            ObjEntity cayenneEntity = new ObjEntity(jpaEntity.getName());
            cayenneEntity.setClassName(jpaEntity.getClassName());
            initCallbacks(jpaEntity, cayenneEntity);

            ((DataMap) targetPath.getObject()).addObjEntity(cayenneEntity);

            return cayenneEntity;
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());

            // TODO: db relationship should probably be created when the first join is
            // created...
            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);
            }

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

            addChildVisitor(JpaId.class, new IdVisitor());
        }

        @Override
        public boolean onStartNode(ProjectPath path) {
            JpaEntity entity = (JpaEntity) path.getObject();

            // * entity name
            if (entity.getClassName() == null) {
                return false;
            }

            if (entity.getName() == null) {

                // use unqualified class name
                String fqName = entity.getClassName();
                int split = fqName.lastIndexOf('.');
                entity.setName(split > 0 ? fqName.substring(split + 1) : fqName);
            }

            if (entity.getAttributes() == null) {
                entity.setAttributes(new JpaAttributes());
            }

            // * default persistent fields
            JpaClassDescriptor descriptor = entity.getClassDescriptor();

            AccessType access = entity.getAccess();
            if (access == null) {
                access = ((JpaEntityMap) path.getRoot()).getAccess();
                entity.setAccess(access);
            }

            if (access == AccessType.PROPERTY) {
                for (JpaPropertyDescriptor candidate : descriptor
                        .getPropertyDescriptors()) {
                    processProperty(entity, descriptor, candidate);
                }
            }
            // field is default...
            else {
                for (JpaPropertyDescriptor candidate : descriptor.getFieldDescriptors()) {
                    processProperty(entity, descriptor, candidate);
                }
            }

            // * default table (see @Table annotation defaults, JPA spec 9.1.1)
            if (entity.getTable() == null) {
                JpaTable table = new JpaTable(AnnotationPrototypes.getTable());

                // unclear whether we need to apply any other name transformations ... or
                // even if we need to upperclas the name. Per default examples looks like
                // we need.
                // table.setName(entity.getName().toUpperCase());
                table.setName(entity.getName());
                entity.setTable(table);
            }

            return true;
        }
View Full Code Here

                column.setName(jpaBasic.getName());
                column.setNullable(jpaBasic.isOptional());
                jpaBasic.setColumn(column);
            }

            JpaEntity entity = (JpaEntity) path.firstInstanceOf(JpaEntity.class);

            // process temporal type defaults
            if (jpaBasic.getTemporal() == null && jpaBasic.getEnumerated() == null) {
                JpaClassDescriptor descriptor = entity.getClassDescriptor();
                JpaPropertyDescriptor property = descriptor.getProperty(jpaBasic
                        .getName());

                // sanity check
                if (property == null) {
View Full Code Here

                column.setName(jpaBasic.getName());
                jpaBasic.setColumn(column);
            }

            if (jpaBasic.getTemporal() == null) {
                JpaEntity entity = (JpaEntity) path.firstInstanceOf(JpaEntity.class);
                JpaClassDescriptor descriptor = entity.getClassDescriptor();
                JpaPropertyDescriptor property = descriptor.getProperty(jpaBasic
                        .getName());

                if (Date.class.equals(property.getType())) {
                    jpaBasic.setTemporal(TemporalType.TIMESTAMP);
View Full Code Here

            if (column.getName() == null) {
                column.setName(parent.getName());
            }

            if (column.getTable() == null) {
                JpaEntity entity = (JpaEntity) path.firstInstanceOf(JpaEntity.class);
                column.setTable(entity.getTable().getName());
            }

            if (parent.getPropertyDescriptor().isStringType()) {
                if (column.getLength() < 0) {
                    column.setLength(255);
View Full Code Here

            if (id.getColumn() == null) {

                JpaColumn column = new JpaColumn(AnnotationPrototypes.getColumn());
                column.setName(id.getName());

                JpaEntity entity = (JpaEntity) path.firstInstanceOf(JpaEntity.class);
                column.setTable(entity.getTable().getName());
                id.setColumn(column);
            }

            return true;
        }
View Full Code Here

        public boolean onStartNode(ProjectPath path) {
            JpaRelationship relationship = (JpaRelationship) path.getObjectParent();
            JpaJoinColumn column = (JpaJoinColumn) path.getObject();

            if (column.getTable() == null) {
                JpaEntity entity = (JpaEntity) path.firstInstanceOf(JpaEntity.class);
                column.setTable(entity.getTable().getName());
            }

            // JPA Spec, 2.1.8.2 (same for all relationship owners):
            // The following mapping defaults apply: [...]
            // Table A contains a foreign key to table B. The foreign key column
            // name is formed as the concatenation of the following: the name of
            // the relationship property or field of entityA; "_" ; the name of
            // the primary key column in table B. The foreign key column has the
            // same type as the primary key of table B.

            JpaEntityMap map = (JpaEntityMap) path.firstInstanceOf(JpaEntityMap.class);
            JpaEntity target = map.entityForClass(relationship.getTargetEntityName());

            if (target == null) {
                context.recordConflict(new SimpleValidationFailure(
                        relationship,
                        "Invalid relationship target "
                                + relationship.getTargetEntityName()));
            }
            else if (target.getAttributes() == null
                    || target.getAttributes().getIds().isEmpty()) {
                context.recordConflict(new SimpleValidationFailure(
                        target,
                        "Relationship target has no PK defined: "
                                + relationship.getTargetEntityName()));
            }
            else if (target.getAttributes().getIds().size() > 1) {
                // TODO: andrus, 4/30/2006 implement this; note that instead of
                // checking for "attribute.getJoinColumns().isEmpty()" above,
                // we'll have to match individual columns
                context.recordConflict(new SimpleValidationFailure(
                        relationship,
                        "Defaults for compound FK are not implemented."));
            }
            else {
                JpaId id = target.getAttributes().getIds().iterator().next();

                String pkName = id.getColumn() != null ? id.getColumn().getName() : id
                        .getName();
                column.setName(relationship.getName() + '_' + pkName);
                column.setReferencedColumnName(id.getColumn() != null ? id
View Full Code Here

        public boolean onStartNode(ProjectPath path) {

            JpaRelationship relationship = (JpaRelationship) path.getObject();
            if (Util.isEmptyString(relationship.getTargetEntityName())) {

                JpaEntity entity = (JpaEntity) path.firstInstanceOf(JpaEntity.class);

                String name = relationship.getName();

                JpaClassDescriptor srcDescriptor = entity.getClassDescriptor();
                JpaPropertyDescriptor property = srcDescriptor.getProperty(name);

                Class targetEntityType = property.getTargetEntityType();

                if (targetEntityType == null) {
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.