Package org.eclipse.persistence.mappings

Examples of org.eclipse.persistence.mappings.AttributeAccessor


    else if (mapping.isCollectionMapping()) {
      return mapping.getContainerPolicy().getContainerClass();
    }

    // Property mapping
    AttributeAccessor accessor = mapping.getAttributeAccessor();

    // Attribute
    if (accessor.isInstanceVariableAttributeAccessor()) {
      InstanceVariableAttributeAccessor attributeAccessor = (InstanceVariableAttributeAccessor) accessor;
      Field field = attributeAccessor.getAttributeField();

      if (field == null) {
        try {
          field = mapping.getDescriptor().getJavaClass().getDeclaredField(attributeAccessor.getAttributeName());
        }
        catch (Exception e) {}
      }

      return field.getType();
    }

    // Property
    if (accessor.isMethodAttributeAccessor()) {
      MethodAttributeAccessor methodAccessor = (MethodAttributeAccessor) accessor;
      Method method = methodAccessor.getGetMethod();

      if (method == null) {
        try {
          method = mapping.getDescriptor().getJavaClass().getDeclaredMethod(methodAccessor.getGetMethodName());
        }
        catch (Exception e) {}
      }

      return method.getReturnType();
    }

    // Anything else
    return accessor.getAttributeClass();
  }
View Full Code Here


                Iterator<DatabaseMapping> ormMappings = ormDescriptor.getMappings().iterator();
                while(ormMappings.hasNext()) {
                    DatabaseMapping ormMapping = ormMappings.next();
                    DatabaseMapping oxmMapping = oxmDescriptor.getMappingForAttributeName(ormMapping.getAttributeName());
                    if(oxmMapping != null) {
                        AttributeAccessor oxmAccessor = oxmMapping.getAttributeAccessor();
                        OrmAttributeAccessor newAccessor = new OrmAttributeAccessor(ormMapping.getAttributeAccessor(), oxmAccessor);
                        if(ormMapping.isOneToOneMapping() && ((OneToOneMapping)ormMapping).usesIndirection()) {
                            newAccessor.setValueHolderProperty(true);
                        }
                        newAccessor.setChangeTracking(ormDescriptor.getObjectChangePolicy().isAttributeChangeTrackingPolicy());
                        oxmMapping.setAttributeAccessor(newAccessor);
                       
                        //check to see if we need to deal with containerAccessor
                        AttributeAccessor containerAccessor = null;
                        Class containerClass = null;
                        if(oxmMapping instanceof XMLCompositeObjectMapping) {
                            containerAccessor = ((XMLCompositeObjectMapping)oxmMapping).getContainerAccessor();
                            containerClass = ((XMLCompositeObjectMapping)oxmMapping).getReferenceClass();
                        } else if(oxmMapping instanceof XMLCompositeCollectionMapping) {
                            containerAccessor = ((XMLCompositeCollectionMapping)oxmMapping).getContainerAccessor();
                            containerClass = ((XMLCompositeCollectionMapping)oxmMapping).getReferenceClass();
                        }
                        if(containerAccessor != null) {
                            ClassDescriptor containerDescriptor = ormSession.getDescriptor(containerClass);
                            if(containerDescriptor != null) {
                                DatabaseMapping ormContainerMapping = containerDescriptor.getMappingForAttributeName(containerAccessor.getAttributeName());
                                if(ormContainerMapping != null) {
                                    //Check for indirection on the container mapping
                                    OrmAttributeAccessor ormAccessor = new OrmAttributeAccessor(ormContainerMapping.getAttributeAccessor(), containerAccessor);
                                    ormAccessor.setChangeTracking(containerDescriptor.getObjectChangePolicy().isAttributeChangeTrackingPolicy());
                                    ormAccessor.setValueHolderProperty(ormContainerMapping instanceof OneToOneMapping && ((OneToOneMapping)ormContainerMapping).usesIndirection());
View Full Code Here

        sessionFile.setXPath("sessions-file/text()");
        descriptor.addMapping(sessionFile);

        XMLChoiceCollectionMapping operationsMapping = new XMLChoiceCollectionMapping();
        operationsMapping.setAttributeName("operations");
        operationsMapping.setAttributeAccessor(new AttributeAccessor() {
            public Object getAttributeValueFromObject(Object object) {
                return ((XRServiceModel)object).getOperationsList();
            }
            @SuppressWarnings("unchecked")
            public void setAttributeValueInObject(Object object, Object value) {
View Full Code Here

        sxf.setXPath("simple-xml-format");
        sxf.setReferenceClass(SimpleXMLFormat.class);
        descriptor.addMapping(sxf);

        XMLDirectMapping isCollection = new XMLDirectMapping();
        isCollection.setAttributeAccessor(new AttributeAccessor() {
            @Override
            public String getAttributeName() {
                return "isCollection";
            }
            @Override
View Full Code Here

        descriptor.getInheritancePolicy().setParentClass(CollectionMapping.class);

        XMLCompositeCollectionMapping sourceToTargetKeyFieldAssociationsMapping = new XMLCompositeCollectionMapping();
        sourceToTargetKeyFieldAssociationsMapping.setReferenceClass(Association.class);
        // Handle translation of foreign key associations to hashtables.
        sourceToTargetKeyFieldAssociationsMapping.setAttributeAccessor(new AttributeAccessor() {
            public Object getAttributeValueFromObject(Object object) {
                AggregateCollectionMapping mapping = (AggregateCollectionMapping)object;
                List sourceFields = mapping.getSourceKeyFields();
                List targetFields = mapping.getTargetForeignKeyFields();
                List associations = new ArrayList(sourceFields.size());
                for (int index = 0; index < sourceFields.size(); index++) {
                    associations.add(new Association(targetFields.get(index), sourceFields.get(index)));
                }
                return associations;
            }

            public void setAttributeValueInObject(Object object, Object value) {
                AggregateCollectionMapping mapping = (AggregateCollectionMapping)object;
                List associations = (List)value;
                mapping.setSourceKeyFields(NonSynchronizedVector.newInstance(associations.size()));
                mapping.setTargetForeignKeyFields(NonSynchronizedVector.newInstance(associations.size()));
                Iterator iterator = associations.iterator();
                while (iterator.hasNext()) {
                    Association association = (Association)iterator.next();
                    mapping.getSourceKeyFields().add((DatabaseField)association.getValue());
                    mapping.getTargetForeignKeyFields().add((DatabaseField)association.getKey());
                }
            }
        });
        sourceToTargetKeyFieldAssociationsMapping.setAttributeName("sourceToTargetKeyFieldAssociations");
        sourceToTargetKeyFieldAssociationsMapping.setXPath(getPrimaryNamespaceXPath() + "target-foreign-key/" + getSecondaryNamespaceXPath() + "field-reference");
        descriptor.addMapping(sourceToTargetKeyFieldAssociationsMapping);

        XMLDirectMapping relationshipPartnerAttributeNameMapping = new XMLDirectMapping();
        relationshipPartnerAttributeNameMapping.setAttributeName("relationshipPartnerAttributeName");
        relationshipPartnerAttributeNameMapping.setGetMethodName("getRelationshipPartnerAttributeName");
        relationshipPartnerAttributeNameMapping.setSetMethodName("setRelationshipPartnerAttributeName");
        relationshipPartnerAttributeNameMapping.setXPath(getPrimaryNamespaceXPath() + "bidirectional-target-attribute/text()");
        descriptor.addMapping(relationshipPartnerAttributeNameMapping);

        XMLDirectMapping usesBatchReadingMapping = new XMLDirectMapping();
        usesBatchReadingMapping.setAttributeName("usesBatchReading");
        usesBatchReadingMapping.setGetMethodName("shouldUseBatchReading");
        usesBatchReadingMapping.setSetMethodName("setUsesBatchReading");
        usesBatchReadingMapping.setXPath(getPrimaryNamespaceXPath() + "batch-reading/text()");
        usesBatchReadingMapping.setNullValue(Boolean.FALSE);
        descriptor.addMapping(usesBatchReadingMapping);

        XMLCompositeObjectMapping containerPolicyMapping = new XMLCompositeObjectMapping();
        containerPolicyMapping.setAttributeName("collectionPolicy");
        containerPolicyMapping.setGetMethodName("getContainerPolicy");
        containerPolicyMapping.setSetMethodName("setContainerPolicy");
        containerPolicyMapping.setReferenceClass(ContainerPolicy.class);
        containerPolicyMapping.setXPath(getPrimaryNamespaceXPath() + "container");
        descriptor.addMapping(containerPolicyMapping);

        XMLCompositeObjectMapping indirectionPolicyMapping = new XMLCompositeObjectMapping();
        indirectionPolicyMapping.setReferenceClass(IndirectionPolicy.class);
        // Handle translation of NoIndirectionPolicy -> null.
        indirectionPolicyMapping.setAttributeAccessor(new AttributeAccessor() {
            public Object getAttributeValueFromObject(Object object) {
                IndirectionPolicy policy = ((ForeignReferenceMapping)object).getIndirectionPolicy();
                if (policy instanceof NoIndirectionPolicy) {
                    return null;
                }
View Full Code Here

        descriptor.addMapping(isNullAllowedMapping);

        XMLCompositeCollectionMapping aggregateToSourceFieldNameAssociationsMapping = new XMLCompositeCollectionMapping();
        aggregateToSourceFieldNameAssociationsMapping.setReferenceClass(FieldTranslation.class);
        // Handle translation of fields associations string to field.
        aggregateToSourceFieldNameAssociationsMapping.setAttributeAccessor(new AttributeAccessor() {
            public Object getAttributeValueFromObject(Object object) {
                AggregateObjectMapping mapping = (AggregateObjectMapping)object;
                Vector associations = mapping.getAggregateToSourceFieldNameAssociations();
                Vector translations = new Vector(associations.size());
                for (int index = 0; index < associations.size(); index++) {
View Full Code Here

        XMLCompositeObjectMapping expressionMapping = new XMLCompositeObjectMapping();
        expressionMapping.setAttributeName("selectionCriteria");
        expressionMapping.setGetMethodName("getSelectionCriteria");
        expressionMapping.setSetMethodName("setSelectionCriteria");
        expressionMapping.setAttributeAccessor(new AttributeAccessor() {
            public Object getAttributeValueFromObject(Object object) {
                return ((DatabaseQuery)object).getSelectionCriteria();
            }

            public void setAttributeValueInObject(Object object, Object value) {
                if (!(object instanceof ObjectLevelReadQuery)) {
                    return;
                }
                ObjectLevelReadQuery query = (ObjectLevelReadQuery)object;
                Expression expression = (Expression)value;
                if (expression != null) {
                    expression = expression.rebuildOn(query.getExpressionBuilder());
                }
                query.setSelectionCriteria(expression);
            }
        });
        expressionMapping.setReferenceClass(Expression.class);
        expressionMapping.setXPath(getSecondaryNamespaceXPath() + "criteria");
        descriptor.addMapping(expressionMapping);

        XMLCompositeCollectionMapping argumentsMapping = new XMLCompositeCollectionMapping();

        // Handle translation of argument lists to query-arguments.
        argumentsMapping.setAttributeAccessor(new AttributeAccessor() {
            public Object getAttributeValueFromObject(Object object) {
                DatabaseQuery query = (DatabaseQuery)object;
                Vector arguments = query.getArguments();
                Vector types = query.getArgumentTypeNames();
                Vector values = query.getArgumentValues();
View Full Code Here

        XMLCompositeObjectMapping inMemoryQueryIndirectionPolicyMapping = new XMLCompositeObjectMapping();
        inMemoryQueryIndirectionPolicyMapping.setAttributeName("inMemoryQueryIndirectionPolicy");
        inMemoryQueryIndirectionPolicyMapping.setReferenceClass(InMemoryQueryIndirectionPolicy.class);
        // Handle translation of default to null.
        inMemoryQueryIndirectionPolicyMapping.setAttributeAccessor(new AttributeAccessor() {
            public Object getAttributeValueFromObject(Object object) {
                InMemoryQueryIndirectionPolicy policy = ((ObjectLevelReadQuery)object).getInMemoryQueryIndirectionPolicy();
                if (policy.shouldThrowIndirectionException()) {
                    return null;
                }
View Full Code Here

        descriptor.addMapping(XMLDirectMapping4);

        XMLCompositeCollectionMapping propertiesMapping = new XMLCompositeCollectionMapping();
        propertiesMapping.setAttributeName("properties");
        propertiesMapping.setReferenceClass(PropertyAssociation.class);
        propertiesMapping.setAttributeAccessor(new AttributeAccessor() {
            public Object getAttributeValueFromObject(Object object) {
                DatabaseMapping mapping = (DatabaseMapping)object;
                Vector propertyAssociations = new NonSynchronizedVector();
                for (Iterator i = mapping.getProperties().entrySet().iterator(); i.hasNext();) {
                    Map.Entry me = (Map.Entry)i.next();
View Full Code Here

        descriptor.addMapping(changePolicyMapping);

        XMLCompositeCollectionMapping propertiesMapping = new XMLCompositeCollectionMapping();
        propertiesMapping.setAttributeName("properties");
        propertiesMapping.setReferenceClass(PropertyAssociation.class);
        propertiesMapping.setAttributeAccessor(new AttributeAccessor() {
            public Object getAttributeValueFromObject(Object object) {
                ClassDescriptor desc = (ClassDescriptor)object;
                Vector propertyAssociations = new NonSynchronizedVector();
                for (Iterator i = desc.getProperties().entrySet().iterator(); i.hasNext();) {
                    Map.Entry me = (Map.Entry)i.next();
View Full Code Here

TOP

Related Classes of org.eclipse.persistence.mappings.AttributeAccessor

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.