Search in sources :

Example 26 with ObjectTypeConverter

use of org.eclipse.persistence.mappings.converters.ObjectTypeConverter in project eclipselink by eclipse-ee4j.

the class ObjectPersistenceRuntimeXMLProject method buildOneToOneMappingDescriptor.

protected ClassDescriptor buildOneToOneMappingDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(OneToOneMapping.class);
    descriptor.getInheritancePolicy().setParentClass(ObjectReferenceMapping.class);
    XMLCompositeCollectionMapping sourceToTargetKeyFieldAssociationsMapping = new XMLCompositeCollectionMapping();
    sourceToTargetKeyFieldAssociationsMapping.setReferenceClass(Association.class);
    // Handle translation of foreign key associations to hashtables.
    sourceToTargetKeyFieldAssociationsMapping.setAttributeAccessor(new AttributeAccessor() {

        @Override
        public Object getAttributeValueFromObject(Object object) {
            Map<DatabaseField, DatabaseField> sourceToTargetKeyFields = ((OneToOneMapping) object).getSourceToTargetKeyFields();
            List<Association> associations = new ArrayList<>(sourceToTargetKeyFields.size());
            Iterator<Map.Entry<DatabaseField, DatabaseField>> iterator = sourceToTargetKeyFields.entrySet().iterator();
            while (iterator.hasNext()) {
                Map.Entry<DatabaseField, DatabaseField> entry = iterator.next();
                associations.add(new Association(entry.getKey(), entry.getValue()));
            }
            return associations;
        }

        @Override
        public void setAttributeValueInObject(Object object, Object value) {
            OneToOneMapping mapping = (OneToOneMapping) object;
            @SuppressWarnings({ "unchecked" }) List<Association> associations = (List<Association>) value;
            mapping.setSourceToTargetKeyFields(new HashMap<>(associations.size() + 1));
            mapping.setTargetToSourceKeyFields(new HashMap<>(associations.size() + 1));
            Iterator<Association> iterator = associations.iterator();
            while (iterator.hasNext()) {
                Association association = iterator.next();
                mapping.getSourceToTargetKeyFields().put((DatabaseField) association.getKey(), (DatabaseField) association.getValue());
                mapping.getTargetToSourceKeyFields().put((DatabaseField) association.getValue(), (DatabaseField) association.getKey());
            }
        }
    });
    sourceToTargetKeyFieldAssociationsMapping.setAttributeName("sourceToTargetKeyFieldAssociations");
    sourceToTargetKeyFieldAssociationsMapping.setXPath(getSecondaryNamespaceXPath() + "foreign-key/" + getSecondaryNamespaceXPath() + "field-reference");
    descriptor.addMapping(sourceToTargetKeyFieldAssociationsMapping);
    XMLCompositeCollectionMapping foreignKeyFieldNamesMapping = new XMLCompositeCollectionMapping();
    foreignKeyFieldNamesMapping.useCollectionClass(NonSynchronizedVector.class);
    foreignKeyFieldNamesMapping.setAttributeName("foreignKeyFields");
    foreignKeyFieldNamesMapping.setGetMethodName("getForeignKeyFields");
    foreignKeyFieldNamesMapping.setSetMethodName("setForeignKeyFields");
    foreignKeyFieldNamesMapping.setXPath(getSecondaryNamespaceXPath() + "foreign-key-fields/" + getSecondaryNamespaceXPath() + "field");
    foreignKeyFieldNamesMapping.setReferenceClass(DatabaseField.class);
    ((XMLField) foreignKeyFieldNamesMapping.getField()).setLeafElementType(fieldQname);
    descriptor.addMapping(foreignKeyFieldNamesMapping);
    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);
    XMLDirectMapping joinFetchMapping = new XMLDirectMapping();
    joinFetchMapping.setAttributeName("joinFetch");
    joinFetchMapping.setXPath(getPrimaryNamespaceXPath() + "join-fetch/text()");
    ObjectTypeConverter joinFetchConverter = new ObjectTypeConverter();
    joinFetchConverter.addConversionValue("true", ForeignReferenceMapping.INNER_JOIN);
    joinFetchConverter.addConversionValue("false", ForeignReferenceMapping.NONE);
    joinFetchMapping.setConverter(joinFetchConverter);
    joinFetchMapping.setNullValue(ForeignReferenceMapping.NONE);
    descriptor.addMapping(joinFetchMapping);
    XMLCompositeObjectMapping indirectionPolicyMapping = new XMLCompositeObjectMapping();
    indirectionPolicyMapping.setReferenceClass(IndirectionPolicy.class);
    // Handle translation of NoIndirectionPolicy -> null.
    indirectionPolicyMapping.setAttributeAccessor(new AttributeAccessor() {

        @Override
        public Object getAttributeValueFromObject(Object object) {
            IndirectionPolicy policy = ((ForeignReferenceMapping) object).getIndirectionPolicy();
            if (policy instanceof NoIndirectionPolicy) {
                return null;
            }
            return policy;
        }

        @Override
        public void setAttributeValueInObject(Object object, Object value) {
            IndirectionPolicy policy = (IndirectionPolicy) value;
            if (value == null) {
                policy = new NoIndirectionPolicy();
            }
            ((ForeignReferenceMapping) object).setIndirectionPolicy(policy);
        }
    });
    indirectionPolicyMapping.setAttributeName("indirectionPolicy");
    indirectionPolicyMapping.setXPath(getPrimaryNamespaceXPath() + "indirection");
    descriptor.addMapping(indirectionPolicyMapping);
    XMLCompositeObjectMapping selectionQueryMapping = new XMLCompositeObjectMapping();
    selectionQueryMapping.setAttributeName("selectionQuery");
    selectionQueryMapping.setGetMethodName("getSelectionQuery");
    selectionQueryMapping.setSetMethodName("setSelectionQuery");
    selectionQueryMapping.setReferenceClass(ReadQuery.class);
    selectionQueryMapping.setXPath(getPrimaryNamespaceXPath() + "selection-query");
    descriptor.addMapping(selectionQueryMapping);
    return descriptor;
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) HashMap(java.util.HashMap) ProxyIndirectionPolicy(org.eclipse.persistence.internal.indirection.ProxyIndirectionPolicy) IndirectionPolicy(org.eclipse.persistence.internal.indirection.IndirectionPolicy) BasicIndirectionPolicy(org.eclipse.persistence.internal.indirection.BasicIndirectionPolicy) ContainerIndirectionPolicy(org.eclipse.persistence.internal.indirection.ContainerIndirectionPolicy) NoIndirectionPolicy(org.eclipse.persistence.internal.indirection.NoIndirectionPolicy) TransparentIndirectionPolicy(org.eclipse.persistence.internal.indirection.TransparentIndirectionPolicy) InMemoryQueryIndirectionPolicy(org.eclipse.persistence.queries.InMemoryQueryIndirectionPolicy) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) Association(org.eclipse.persistence.mappings.Association) PropertyAssociation(org.eclipse.persistence.mappings.PropertyAssociation) TypedAssociation(org.eclipse.persistence.mappings.TypedAssociation) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) XMLCompositeCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping) Iterator(java.util.Iterator) ObjectTypeConverter(org.eclipse.persistence.mappings.converters.ObjectTypeConverter) ArrayList(java.util.ArrayList) List(java.util.List) NoIndirectionPolicy(org.eclipse.persistence.internal.indirection.NoIndirectionPolicy) AttributeAccessor(org.eclipse.persistence.mappings.AttributeAccessor) Map(java.util.Map) HardCacheWeakIdentityMap(org.eclipse.persistence.internal.identitymaps.HardCacheWeakIdentityMap) CacheIdentityMap(org.eclipse.persistence.internal.identitymaps.CacheIdentityMap) NoIdentityMap(org.eclipse.persistence.internal.identitymaps.NoIdentityMap) WeakIdentityMap(org.eclipse.persistence.internal.identitymaps.WeakIdentityMap) FullIdentityMap(org.eclipse.persistence.internal.identitymaps.FullIdentityMap) SoftCacheWeakIdentityMap(org.eclipse.persistence.internal.identitymaps.SoftCacheWeakIdentityMap) HashMap(java.util.HashMap) EISOneToOneMapping(org.eclipse.persistence.eis.mappings.EISOneToOneMapping) OneToOneMapping(org.eclipse.persistence.mappings.OneToOneMapping) VariableOneToOneMapping(org.eclipse.persistence.mappings.VariableOneToOneMapping) XMLCompositeObjectMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping)

Example 27 with ObjectTypeConverter

use of org.eclipse.persistence.mappings.converters.ObjectTypeConverter in project eclipselink by eclipse-ee4j.

the class ObjectPersistenceRuntimeXMLProject_11_1_1 method buildAggregateCollectionMappingDescriptor.

@Override
protected ClassDescriptor buildAggregateCollectionMappingDescriptor() {
    XMLDescriptor descriptor = (XMLDescriptor) super.buildAggregateCollectionMappingDescriptor();
    XMLDirectMapping joinFetchMapping = new XMLDirectMapping();
    joinFetchMapping.setAttributeName("joinFetch");
    joinFetchMapping.setXPath(getPrimaryNamespaceXPath() + "join-fetch/text()");
    ObjectTypeConverter joinFetchConverter = new ObjectTypeConverter();
    joinFetchConverter.addConversionValue("inner-join", ForeignReferenceMapping.INNER_JOIN);
    joinFetchConverter.addConversionValue("outer-join", ForeignReferenceMapping.OUTER_JOIN);
    joinFetchConverter.addConversionValue("none", ForeignReferenceMapping.NONE);
    joinFetchMapping.setConverter(joinFetchConverter);
    joinFetchMapping.setNullValue(ForeignReferenceMapping.NONE);
    descriptor.addMapping(joinFetchMapping);
    return descriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) ObjectTypeConverter(org.eclipse.persistence.mappings.converters.ObjectTypeConverter)

Example 28 with ObjectTypeConverter

use of org.eclipse.persistence.mappings.converters.ObjectTypeConverter in project eclipselink by eclipse-ee4j.

the class ObjectPersistenceRuntimeXMLProject_11_1_1 method buildClassDescriptorDescriptor.

@Override
protected ClassDescriptor buildClassDescriptorDescriptor() {
    ClassDescriptor descriptor = super.buildClassDescriptorDescriptor();
    XMLDirectMapping identityMapClassMapping = (XMLDirectMapping) descriptor.getMappingForAttributeName("identityMapClass");
    ObjectTypeConverter identityMapClassConverter = (ObjectTypeConverter) identityMapClassMapping.getConverter();
    identityMapClassConverter.addConversionValue("soft-reference", SoftIdentityMap.class);
    XMLDirectMapping remoteIdentityMapClassMapping = (XMLDirectMapping) descriptor.getMappingForAttributeName("remoteIdentityMapClass");
    ObjectTypeConverter remoteIdentityMapClassConverter = (ObjectTypeConverter) remoteIdentityMapClassMapping.getConverter();
    remoteIdentityMapClassConverter.addConversionValue("soft-reference", SoftIdentityMap.class);
    XMLDirectMapping unitOfWorkCacheIsolationLevelMapping = (XMLDirectMapping) descriptor.getMappingForAttributeName("unitOfWorkCacheIsolationLevel");
    ObjectTypeConverter unitOfWorkCacheIsolationLevelConverter = (ObjectTypeConverter) unitOfWorkCacheIsolationLevelMapping.getConverter();
    unitOfWorkCacheIsolationLevelConverter.addConversionValue("default", ClassDescriptor.UNDEFINED_ISOLATATION);
    unitOfWorkCacheIsolationLevelMapping.setNullValue(ClassDescriptor.UNDEFINED_ISOLATATION);
    return descriptor;
}
Also used : ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) ObjectTypeConverter(org.eclipse.persistence.mappings.converters.ObjectTypeConverter)

Example 29 with ObjectTypeConverter

use of org.eclipse.persistence.mappings.converters.ObjectTypeConverter in project eclipselink by eclipse-ee4j.

the class ObjectPersistenceRuntimeXMLProject_11_1_1 method buildOneToManyMappingMappingDescriptor.

@Override
protected ClassDescriptor buildOneToManyMappingMappingDescriptor() {
    XMLDescriptor descriptor = (XMLDescriptor) super.buildOneToManyMappingMappingDescriptor();
    XMLDirectMapping joinFetchMapping = new XMLDirectMapping();
    joinFetchMapping.setAttributeName("joinFetch");
    joinFetchMapping.setXPath(getPrimaryNamespaceXPath() + "join-fetch/text()");
    ObjectTypeConverter joinFetchConverter = new ObjectTypeConverter();
    joinFetchConverter.addConversionValue("inner-join", ForeignReferenceMapping.INNER_JOIN);
    joinFetchConverter.addConversionValue("outer-join", ForeignReferenceMapping.OUTER_JOIN);
    joinFetchConverter.addConversionValue("none", ForeignReferenceMapping.NONE);
    joinFetchMapping.setConverter(joinFetchConverter);
    joinFetchMapping.setNullValue(ForeignReferenceMapping.NONE);
    descriptor.addMapping(joinFetchMapping);
    return descriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) ObjectTypeConverter(org.eclipse.persistence.mappings.converters.ObjectTypeConverter)

Example 30 with ObjectTypeConverter

use of org.eclipse.persistence.mappings.converters.ObjectTypeConverter in project eclipselink by eclipse-ee4j.

the class ObjectPersistenceRuntimeXMLProject method buildReportQueryDescriptor.

protected ClassDescriptor buildReportQueryDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(ReportQuery.class);
    descriptor.getInheritancePolicy().setParentClass(ReadAllQuery.class);
    XMLDirectMapping returnChoiceMapping = new XMLDirectMapping();
    returnChoiceMapping.setAttributeName("returnChoice");
    returnChoiceMapping.setXPath(getPrimaryNamespaceXPath() + "return-choice/text()");
    ObjectTypeConverter returnChoiceConverter = new ObjectTypeConverter();
    returnChoiceConverter.addConversionValue("return-single-result", ReportQuery.ShouldReturnSingleResult);
    returnChoiceConverter.addConversionValue("return-single-value", ReportQuery.ShouldReturnSingleValue);
    returnChoiceConverter.addConversionValue("return-single-attribute", ReportQuery.ShouldReturnSingleAttribute);
    returnChoiceMapping.setConverter(returnChoiceConverter);
    returnChoiceMapping.setNullValue(0);
    descriptor.addMapping(returnChoiceMapping);
    XMLDirectMapping retrievePrimaryKeysMapping = new XMLDirectMapping();
    retrievePrimaryKeysMapping.setAttributeName("shouldRetrievePrimaryKeys");
    retrievePrimaryKeysMapping.setXPath(getPrimaryNamespaceXPath() + "retrieve-primary-keys/text()");
    ObjectTypeConverter retrievePrimaryKeysConverter = new ObjectTypeConverter();
    retrievePrimaryKeysConverter.addConversionValue("full-primary-key", ReportQuery.FULL_PRIMARY_KEY);
    retrievePrimaryKeysConverter.addConversionValue("first-primary-key", ReportQuery.FIRST_PRIMARY_KEY);
    retrievePrimaryKeysConverter.addConversionValue("no-primary-key", ReportQuery.NO_PRIMARY_KEY);
    retrievePrimaryKeysMapping.setConverter(retrievePrimaryKeysConverter);
    returnChoiceMapping.setNullValue(ReportQuery.NO_PRIMARY_KEY);
    descriptor.addMapping(retrievePrimaryKeysMapping);
    XMLCompositeCollectionMapping reportItemsMapping = new XMLCompositeCollectionMapping();
    reportItemsMapping.useCollectionClass(NonSynchronizedVector.class);
    reportItemsMapping.setAttributeName("items");
    reportItemsMapping.setReferenceClass(ReportItem.class);
    reportItemsMapping.setXPath(getPrimaryNamespaceXPath() + "report-items/" + getPrimaryNamespaceXPath() + "item");
    descriptor.addMapping(reportItemsMapping);
    XMLCompositeCollectionMapping groupByMapping = new XMLCompositeCollectionMapping();
    groupByMapping.useCollectionClass(NonSynchronizedVector.class);
    groupByMapping.setAttributeName("groupByExpressions");
    groupByMapping.setReferenceClass(Expression.class);
    groupByMapping.setXPath(getPrimaryNamespaceXPath() + "group-by-expressions/" + getPrimaryNamespaceXPath() + "expression");
    descriptor.addMapping(groupByMapping);
    return descriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) ObjectTypeConverter(org.eclipse.persistence.mappings.converters.ObjectTypeConverter) XMLCompositeCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping)

Aggregations

ObjectTypeConverter (org.eclipse.persistence.mappings.converters.ObjectTypeConverter)35 XMLDirectMapping (org.eclipse.persistence.oxm.mappings.XMLDirectMapping)26 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)25 XMLCompositeObjectMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping)10 DirectToFieldMapping (org.eclipse.persistence.mappings.DirectToFieldMapping)8 RelationalDescriptor (org.eclipse.persistence.descriptors.RelationalDescriptor)6 XMLField (org.eclipse.persistence.oxm.XMLField)5 XMLCompositeCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping)5 ArrayList (java.util.ArrayList)4 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)4 AttributeAccessor (org.eclipse.persistence.mappings.AttributeAccessor)4 OneToOneMapping (org.eclipse.persistence.mappings.OneToOneMapping)4 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 List (java.util.List)2 Map (java.util.Map)2 Vector (java.util.Vector)2 VersionLockingPolicy (org.eclipse.persistence.descriptors.VersionLockingPolicy)2 CacheIdentityMap (org.eclipse.persistence.internal.identitymaps.CacheIdentityMap)2 FullIdentityMap (org.eclipse.persistence.internal.identitymaps.FullIdentityMap)2