Examples of JpaClassDescriptor


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

        Annotation[] classAnnotations = managedClass.getAnnotations();

        // per 'getAnnotations' docs, array is returned by copy, so we can modify it...
        Arrays.sort(classAnnotations, typeAnnotationsSorter);

        JpaClassDescriptor descriptor = new JpaClassDescriptor(managedClass);

        // initially set access to the map level access - may be overridden below
        descriptor.setAccess(context.getEntityMap().getAccess());

        AnnotationContext stack = new AnnotationContext(descriptor);
        stack.push(context.getEntityMap());

        // === push class-level stuff
        for (int i = 0; i < classAnnotations.length; i++) {
            AnnotationProcessor processor = classProcessorFactory
                    .getProcessor(classAnnotations[i]);
            if (processor != null) {
                processor.onStartElement(managedClass, stack);
            }
        }

        // if class is not properly annotated, bail early
        if (stack.depth() == 1) {
            return;
        }

        // apply entity callbacks ...
        if (stack.peek() instanceof JpaAbstractEntity) {
            for (Method callback : getEntityCallbacks(managedClass)) {
                applyEntityCallbackAnnotations(callback, stack);
            }
        }

        // per JPA spec, 2.1.1, regarding access type:

        // When annotations are used, the placement of the mapping annotations on either
        // the persistent fields or persistent properties of the entity class specifies
        // the access type as being either field- or property-based access respectively.

        // Question (andrus) - if no annotations are placed at the field or method level,
        // we still must determine the access type to apply default mappping rules. How?
        // (using FIELD access for now).

        boolean fieldAccess = false;

        for (JpaPropertyDescriptor property : descriptor.getFieldDescriptors()) {
            stack.setPropertyDescriptor(property);
            if (applyMemberAnnotations(property, stack)) {
                fieldAccess = true;
            }
        }

        boolean propertyAccess = false;

        for (JpaPropertyDescriptor property : descriptor.getPropertyDescriptors()) {
            stack.setPropertyDescriptor(property);
            if (applyMemberAnnotations(property, stack)) {
                propertyAccess = true;
            }
        }

        if (stack.peek() instanceof JpaManagedClass) {
            JpaManagedClass entity = (JpaManagedClass) stack.peek();
            // sanity check
            if (fieldAccess && propertyAccess) {
                throw new JpaProviderException("Entity '"
                        + entity.getClassName()
                        + "' has both property and field annotations.");
            }

            // TODO: andrus - 11/29/2006 - clean this redundancy - access field should be
            // stored either in the entity or the descriptor.
            if (fieldAccess) {
                descriptor.setAccess(AccessType.FIELD);
                entity.setAccess(AccessType.FIELD);
            }
            else if (propertyAccess) {
                descriptor.setAccess(AccessType.PROPERTY);
                entity.setAccess(AccessType.PROPERTY);
            }
        }

        // === pop class-level stuff
View Full Code Here

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

                JpaManagedClass relationshipOwner = (JpaManagedClass) path
                        .firstInstanceOf(JpaManagedClass.class);

                String name = relationship.getName();

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

                Class<?> targetEntityType = property.getTargetEntityType();

                if (targetEntityType == null) {
                    context.recordConflict(new SimpleValidationFailure(property
View Full Code Here

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

            JpaAbstractEntity entity = (JpaAbstractEntity) path
                    .firstInstanceOf(JpaAbstractEntity.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) {
                    throw new IllegalStateException("No class property found for name: "
View Full Code Here

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

                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

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

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

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

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

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

            return true;
View Full Code Here

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

        Annotation[] classAnnotations = managedClass.getAnnotations();

        // per 'getAnnotations' docs, array is returned by copy, so we can modify it...
        Arrays.sort(classAnnotations, typeAnnotationsSorter);

        JpaClassDescriptor descriptor = new JpaClassDescriptor(managedClass);

        // initially set access to the map level access - may be overridden below
        descriptor.setAccess(context.getEntityMap().getAccess());

        AnnotationContext stack = new AnnotationContext(descriptor);
        stack.push(context.getEntityMap());

        // === push class-level stuff
        for (int i = 0; i < classAnnotations.length; i++) {
            AnnotationProcessor processor = classProcessorFactory
                    .getProcessor(classAnnotations[i]);
            if (processor != null) {
                processor.onStartElement(managedClass, stack);
            }
        }

        // if class is not properly annotated, bail early
        if (stack.depth() == 1) {
            return;
        }

        // apply entity callbacks ...
        if (stack.peek() instanceof JpaAbstractEntity) {
            for (Method callback : getEntityCallbacks(managedClass)) {
                applyEntityCallbackAnnotations(callback, stack);
            }
        }

        // per JPA spec, 2.1.1, regarding access type:

        // When annotations are used, the placement of the mapping annotations on either
        // the persistent fields or persistent properties of the entity class specifies
        // the access type as being either field- or property-based access respectively.

        // Question (andrus) - if no annotations are placed at the field or method level,
        // we still must determine the access type to apply default mappping rules. How?
        // (using FIELD access for now).

        boolean fieldAccess = false;

        for (JpaPropertyDescriptor property : descriptor.getFieldDescriptors()) {
            stack.setPropertyDescriptor(property);
            if (applyMemberAnnotations(property, stack)) {
                fieldAccess = true;
            }
        }

        boolean propertyAccess = false;

        for (JpaPropertyDescriptor property : descriptor.getPropertyDescriptors()) {
            stack.setPropertyDescriptor(property);
            if (applyMemberAnnotations(property, stack)) {
                propertyAccess = true;
            }
        }

        if (stack.peek() instanceof JpaManagedClass) {
            JpaManagedClass entity = (JpaManagedClass) stack.peek();
            // sanity check
            if (fieldAccess && propertyAccess) {
                throw new JpaProviderException("Entity '"
                        + entity.getClassName()
                        + "' has both property and field annotations.");
            }

            // TODO: andrus - 11/29/2006 - clean this redundancy - access field should be
            // stored either in the entity or the descriptor.
            if (fieldAccess) {
                descriptor.setAccess(AccessType.FIELD);
                entity.setAccess(AccessType.FIELD);
            }
            else if (propertyAccess) {
                descriptor.setAccess(AccessType.PROPERTY);
                entity.setAccess(AccessType.PROPERTY);
            }
        }

        // === pop class-level stuff
View Full Code Here

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

                JpaManagedClass relationshipOwner = (JpaManagedClass) path
                        .firstInstanceOf(JpaManagedClass.class);

                String name = relationship.getName();

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

                Class<?> targetEntityType = property.getTargetEntityType();

                if (targetEntityType == null) {
                    context.recordConflict(new SimpleValidationFailure(property
View Full Code Here

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

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

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

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

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

            return true;
View Full Code Here

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

            JpaAbstractEntity entity = (JpaAbstractEntity) path
                    .firstInstanceOf(JpaAbstractEntity.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) {
                    throw new IllegalStateException("No class property found for name: "
View Full Code Here

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

                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
TOP
Copyright © 2018 www.massapi.com. 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.