Package org.eclipse.persistence.internal.jpa.metadata.accessors.mappings

Examples of org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.MappingAccessor


        if (hasAttributeName()) {
            // If the mapping is an aggregate object mapping, validate the
            // attribute name existing on the embeddable and update the reference class.
            if (mapping.isAggregateObjectMapping()) {
                ClassAccessor embeddableAccessor = getProject().getEmbeddableAccessor(referenceClass);
                MappingAccessor mappingAccessor = embeddableAccessor.getDescriptor().getMappingAccessor(getAttributeName());
                   
                if (mappingAccessor == null) {
                    throw ValidationException.embeddableAttributeNameForConvertNotFound(accessor.getJavaClassName(), mapping.getAttributeName(), embeddableAccessor.getJavaClassName(), getAttributeName());
                }

                referenceClass = mappingAccessor.getReferenceClass();
            } else {
                throw ValidationException.invalidMappingForConvertWithAttributeName(accessor.getJavaClassName(), mapping.getAttributeName());
            }
        } else {
            // In an aggregate object case, the attribute name must be specified.
View Full Code Here


     * again. If still no accessor is found and this descriptor represents an
     * inheritance subclass, then traverse up the chain to look for that
     * accessor. Null is returned otherwise.
     */
    public MappingAccessor getAccessorFor(String fieldOrPropertyName) {
        MappingAccessor accessor = m_accessors.get(fieldOrPropertyName);
       
        if (accessor == null) {
            // Perhaps we have a property name ...
            accessor = m_accessors.get(Helper.getAttributeNameFromMethodName(fieldOrPropertyName));
          
View Full Code Here

     * references. If the referencingAccessor is null, no check will be made.
     */
    public DatabaseMapping getMappingForAttributeName(String attributeName, MetadataAccessor referencingAccessor) {
        // Get accessor will traverse the parent descriptors of an inheritance
        // hierarchy.
        MappingAccessor accessor = getAccessorFor(attributeName);
       
        if (accessor != null) {
            // If the accessor is a relationship accessor than it may or may
            // not have been processed yet. Fast track its processing if it
            // needs to be. The process call will do nothing if it has already
            // been processed.
            if (accessor.isRelationship()) {
                RelationshipAccessor relationshipAccessor = (RelationshipAccessor) accessor;
               
                // Check that we don't have circular mappedBy values which
                // will cause an infinite loop.
                if (referencingAccessor != null && (relationshipAccessor.isOneToOne() || relationshipAccessor.isCollectionAccessor())) {
                    String mappedBy = null;
                   
                    if (relationshipAccessor.isOneToOne()) {
                        mappedBy = ((OneToOneAccessor) relationshipAccessor).getMappedBy();
                    } else {
                        mappedBy = ((CollectionAccessor) relationshipAccessor).getMappedBy();
                    }
                   
                    if (mappedBy != null && mappedBy.equals(referencingAccessor.getAttributeName())) {
                        throw ValidationException.circularMappedByReferences(referencingAccessor.getJavaClass(), referencingAccessor.getAttributeName(), getJavaClass(), attributeName);
                    }
                }
               
                relationshipAccessor.processRelationship();
            }
           
            // Return the mapping stored on the accessor.
            return accessor.getMapping();
        }
       
        // Found nothing ... return null.
        return null;
    }
View Full Code Here

               
                // If the mapping is an aggregate object mapping, validate the
                // attribute name existing on the embeddable.
                if (mappingToApplyConvert.isAggregateObjectMapping()) {
                    ClassAccessor embeddableAccessor = getProject().getEmbeddableAccessor(referenceClass);
                    MappingAccessor mappingAccessor = embeddableAccessor.getDescriptor().getMappingAccessor(attributeName);
                   
                    if (mappingAccessor == null) {
                        throw ValidationException.embeddableAttributeNameForConvertNotFound(accessor.getJavaClassName(), mapping.getAttributeName(), embeddableAccessor.getJavaClassName(), attributeName);
                    }
                }
View Full Code Here

            return;
        }
       
        // Log a warning message if we are overriding a mapping accessor.
        if (m_mappingAccessors.containsKey(accessor.getAttributeName())) {
            MappingAccessor existingAccessor = m_mappingAccessors.get(accessor.getAttributeName());
            String existingAccessType = existingAccessor.usesPropertyAccess() ? JPA_ACCESS_PROPERTY : JPA_ACCESS_FIELD;
            String accessType = accessor.usesPropertyAccess() ? JPA_ACCESS_PROPERTY : JPA_ACCESS_FIELD;
            getLogger().logWarningMessage(getLogger().INVERSE_ACCESS_TYPE_MAPPING_OVERRIDE, accessor.getJavaClass().getName(), existingAccessor.getAnnotatedElementName(), existingAccessType, accessor.getAnnotatedElementName(), accessType);
        }
       
        m_mappingAccessors.put(accessor.getAttributeName(), accessor);
       
        // Store IdAccessors in a separate map for use by hasIdAccessor()
View Full Code Here

     * accessor is found and this descriptor represents an inheritance subclass,
     * then traverse up the chain to look for that accessor. Null is returned
     * otherwise.
     */
    protected MappingAccessor getMappingAccessor(String fieldOrPropertyName, boolean checkForMethodName) {
        MappingAccessor accessor = m_mappingAccessors.get(fieldOrPropertyName);
       
        if (accessor == null) {
            // Perhaps we have a method name. This is value add, and maybe we
            // really shouldn't do this but it covers the following case:
            // <order-by>age, getGender DESC</order-by>, where the user
            // specifies a method name.
            if (checkForMethodName) {
                accessor = m_mappingAccessors.get(Helper.getAttributeNameFromMethodName(fieldOrPropertyName));
            }
          
            // If still no accessor and we are an inheritance subclass, check
            // our parent descriptor. Unless we are within a table per class
            // strategy in which case, if the mapping doesn't exist within our
            // accessor list, we don't want to deal with it.
            if (accessor == null && isInheritanceSubclass() && ! usesTablePerClassInheritanceStrategy()) {
                accessor = getInheritanceParentDescriptor().getMappingAccessor(fieldOrPropertyName, checkForMethodName);
            }
        }
       
        if (accessor == null) {
            // Traverse any dot notation (nested embeddables) if specified.
            if (fieldOrPropertyName.contains(".")) {
                String attributeName = fieldOrPropertyName.substring(0, fieldOrPropertyName.indexOf("."));
                String subAttributeName = fieldOrPropertyName.substring(fieldOrPropertyName.indexOf(".") + 1);
           
                MappingAccessor embeddedAccessor = m_mappingAccessors.get(attributeName);
           
                if (embeddedAccessor != null) {
                    accessor = embeddedAccessor.getReferenceDescriptor().getMappingAccessor(subAttributeName, checkForMethodName);
                }
            }

            // If we are still null, maybe the user has not used a dot notation
            // that is, has not been fully specific. At this point this is value
View Full Code Here

            return;
        }
       
        // Log a warning message if we are overriding a mapping accessor.
        if (m_mappingAccessors.containsKey(accessor.getAttributeName())) {
            MappingAccessor existingAccessor = m_mappingAccessors.get(accessor.getAttributeName());
            String existingAccessType = existingAccessor.usesPropertyAccess() ? AccessType.PROPERTY.name() : AccessType.FIELD.name();
            String accessType = accessor.usesPropertyAccess() ? AccessType.PROPERTY.name() : AccessType.FIELD.name();
            getLogger().logWarningMessage(getLogger().INVERSE_ACCESS_TYPE_MAPPING_OVERRIDE, accessor.getJavaClass().getName(), existingAccessor.getAnnotatedElementName(), existingAccessType, accessor.getAnnotatedElementName(), accessType);
        }
       
        m_mappingAccessors.put(accessor.getAttributeName(), accessor);
       
        // Store IdAccessors in a separate map for use by hasIdAccessor()
View Full Code Here

     * accessor is found and this descriptor represents an inheritance subclass,
     * then traverse up the chain to look for that accessor. Null is returned
     * otherwise.
     */
    protected MappingAccessor getMappingAccessor(String fieldOrPropertyName, boolean checkForMethodName) {
        MappingAccessor accessor = m_mappingAccessors.get(fieldOrPropertyName);
       
        if (accessor == null) {
            // Perhaps we have a method name. This is value add, and maybe we
            // really shouldn't do this but it covers the following case:
            // <order-by>age, getGender DESC</order-by>, where the user
            // specifies a method name.
            if (checkForMethodName) {
                accessor = m_mappingAccessors.get(Helper.getAttributeNameFromMethodName(fieldOrPropertyName));
            }
          
            // If still no accessor and we are an inheritance subclass, check
            // our parent descriptor. Unless we are within a table per class
            // strategy in which case, if the mapping doesn't exist within our
            // accessor list, we don't want to deal with it.
            if (accessor == null && isInheritanceSubclass() && ! usesTablePerClassInheritanceStrategy()) {
                accessor = getInheritanceParentDescriptor().getMappingAccessor(fieldOrPropertyName, checkForMethodName);
            }
        }
       
        if (accessor == null) {
            // Traverse any dot notation (nested embeddables) if specified.
            if (fieldOrPropertyName.contains(".")) {
                String attributeName = fieldOrPropertyName.substring(0, fieldOrPropertyName.indexOf("."));
                String subAttributeName = fieldOrPropertyName.substring(fieldOrPropertyName.indexOf(".") + 1);
           
                MappingAccessor embeddedAccessor = m_mappingAccessors.get(attributeName);
           
                if (embeddedAccessor != null) {
                    accessor = embeddedAccessor.getReferenceDescriptor().getMappingAccessor(subAttributeName, checkForMethodName);
                }
            }

            // If we are still null, maybe the user has not used a dot notation
            // that is, has not been fully specific. At this point this is value
View Full Code Here

                                    // Grab the map key class from the generic.
                                    mapKeyType = annotatedElement.getGenericType().get(1);
                                } else {
                                    if (mappingAccessor.getReferenceDescriptor().hasIdAccessor()) {
                                        // Grab the id type from the reference descriptor, now there's a handle!
                                        MappingAccessor idAccessor = mappingAccessor.getReferenceDescriptor().getIdAccessors().values().iterator().next();
                                        mapKeyType = idAccessor.getReferenceClassName();
                                    } else {
                                        // We don't know at this point so just use the catch all default.
                                        mapKeyType = TypeVisitor.GENERIC_TYPE;
                                    }                                   
                                }
View Full Code Here

            StringTokenizer commaTokenizer = new StringTokenizer(m_value, ",");
       
            while (commaTokenizer.hasMoreTokens()) {
                StringTokenizer spaceTokenizer = new StringTokenizer(commaTokenizer.nextToken());
                String propertyOrFieldName = spaceTokenizer.nextToken();
                MappingAccessor referenceAccessor = referenceDescriptor.getMappingAccessor(propertyOrFieldName);
           
                if (referenceAccessor == null) {
                    throw ValidationException.invalidOrderByValue(propertyOrFieldName, referenceDescriptor.getJavaClass(), getAccessibleObjectName(), javaClass);
                }

                String attributeName = referenceAccessor.getAttributeName();
                String ordering = (spaceTokenizer.hasMoreTokens()) ? spaceTokenizer.nextToken() : ASCENDING;

                if (referenceAccessor.isEmbedded()) {
                    for (String orderByAttributeName : referenceDescriptor.getOrderByAttributeNames()) {
                        mapping.addAggregateOrderBy(m_value, orderByAttributeName, ordering.equals(DESCENDING));
                    }
                } else if (referenceAccessor.getClassAccessor().isEmbeddableAccessor()) {
                    // We have a specific order by from an embeddable, we need to rip off
                    // the last bit of a dot notation if specified and pass in the chained
                    // string names of the nested embeddables only.
                    String embeddableChain = m_value;
                    if (embeddableChain.contains(".")) {
View Full Code Here

TOP

Related Classes of org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.MappingAccessor

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.