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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations