use of org.eclipse.persistence.oxm.mappings.XMLDirectMapping in project eclipselink by eclipse-ee4j.
the class ObjectPersistenceRuntimeXMLProject method buildManyToManyMappingMappingDescriptor.
protected ClassDescriptor buildManyToManyMappingMappingDescriptor() {
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClass(ManyToManyMapping.class);
descriptor.getInheritancePolicy().setParentClass(CollectionMapping.class);
XMLDirectMapping relationTableMapping = new XMLDirectMapping();
relationTableMapping.setAttributeName("relationTableName");
// CR#2407 Call getRelationTableQualifiedName that includes table qualifier.
relationTableMapping.setGetMethodName("getRelationTableQualifiedName");
relationTableMapping.setSetMethodName("setRelationTableName");
relationTableMapping.setXPath(getSecondaryNamespaceXPath() + "relation-table/text()");
descriptor.addMapping(relationTableMapping);
XMLCompositeCollectionMapping sourceToRelationKeyFieldAssociationsMapping = new XMLCompositeCollectionMapping();
sourceToRelationKeyFieldAssociationsMapping.setReferenceClass(Association.class);
// Handle translation of foreign key associations to hashtables.
sourceToRelationKeyFieldAssociationsMapping.setAttributeAccessor(new AttributeAccessor() {
@Override
public Object getAttributeValueFromObject(Object object) {
List<DatabaseField> sourceFields = ((ManyToManyMapping) object).getSourceKeyFields();
List<DatabaseField> relationFields = ((ManyToManyMapping) object).getSourceRelationKeyFields();
List<Association> associations = new ArrayList<>(sourceFields.size());
for (int index = 0; index < sourceFields.size(); index++) {
associations.add(new Association(relationFields.get(index), sourceFields.get(index)));
}
return associations;
}
@Override
public void setAttributeValueInObject(Object object, Object value) {
ManyToManyMapping mapping = (ManyToManyMapping) object;
@SuppressWarnings({ "unchecked" }) List<Association> associations = (List<Association>) value;
mapping.setSourceKeyFields(NonSynchronizedVector.newInstance(associations.size()));
mapping.setSourceRelationKeyFields(NonSynchronizedVector.newInstance(associations.size()));
Iterator<Association> iterator = associations.iterator();
while (iterator.hasNext()) {
Association association = iterator.next();
mapping.getSourceKeyFields().add((DatabaseField) association.getValue());
mapping.getSourceRelationKeyFields().add((DatabaseField) association.getKey());
}
}
});
sourceToRelationKeyFieldAssociationsMapping.setAttributeName("sourceToRelationKeyFieldAssociationsMapping");
sourceToRelationKeyFieldAssociationsMapping.setXPath(getSecondaryNamespaceXPath() + "source-relation-foreign-key/" + getSecondaryNamespaceXPath() + "field-reference");
descriptor.addMapping(sourceToRelationKeyFieldAssociationsMapping);
XMLCompositeCollectionMapping targetToRelationKeyFieldAssociationsMapping = new XMLCompositeCollectionMapping();
targetToRelationKeyFieldAssociationsMapping.setReferenceClass(Association.class);
// Handle translation of foreign key associations to hashtables.
targetToRelationKeyFieldAssociationsMapping.setAttributeAccessor(new AttributeAccessor() {
@Override
public Object getAttributeValueFromObject(Object object) {
List<DatabaseField> targetFields = ((ManyToManyMapping) object).getTargetKeyFields();
List<DatabaseField> relationFields = ((ManyToManyMapping) object).getTargetRelationKeyFields();
List<Association> associations = new ArrayList<>(targetFields.size());
for (int index = 0; index < targetFields.size(); index++) {
associations.add(new Association(relationFields.get(index), targetFields.get(index)));
}
return associations;
}
@Override
public void setAttributeValueInObject(Object object, Object value) {
ManyToManyMapping mapping = (ManyToManyMapping) object;
@SuppressWarnings({ "unchecked" }) List<Association> associations = (List<Association>) value;
mapping.setTargetKeyFields(NonSynchronizedVector.newInstance(associations.size()));
mapping.setTargetRelationKeyFields(NonSynchronizedVector.newInstance(associations.size()));
Iterator<Association> iterator = associations.iterator();
while (iterator.hasNext()) {
Association association = iterator.next();
mapping.getTargetKeyFields().add((DatabaseField) association.getValue());
mapping.getTargetRelationKeyFields().add((DatabaseField) association.getKey());
}
}
});
targetToRelationKeyFieldAssociationsMapping.setAttributeName("targetToRelationKeyFieldAssociations");
targetToRelationKeyFieldAssociationsMapping.setXPath(getSecondaryNamespaceXPath() + "target-relation-foreign-key/" + getSecondaryNamespaceXPath() + "field-reference");
descriptor.addMapping(targetToRelationKeyFieldAssociationsMapping);
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() {
@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);
XMLCompositeObjectMapping insertQueryMapping = new XMLCompositeObjectMapping();
insertQueryMapping.setAttributeName("insertQuery");
insertQueryMapping.setGetMethodName("getInsertQuery");
insertQueryMapping.setSetMethodName("setInsertQuery");
insertQueryMapping.setReferenceClass(DataModifyQuery.class);
insertQueryMapping.setXPath(getPrimaryNamespaceXPath() + "insert-query");
descriptor.addMapping(insertQueryMapping);
XMLCompositeObjectMapping deleteQueryMapping = new XMLCompositeObjectMapping();
deleteQueryMapping.setAttributeName("deleteQuery");
deleteQueryMapping.setGetMethodName("getDeleteQuery");
deleteQueryMapping.setSetMethodName("setDeleteQuery");
deleteQueryMapping.setReferenceClass(DataModifyQuery.class);
deleteQueryMapping.setXPath(getPrimaryNamespaceXPath() + "delete-query");
descriptor.addMapping(deleteQueryMapping);
XMLCompositeObjectMapping deleteAllQueryMapping = new XMLCompositeObjectMapping();
deleteAllQueryMapping.setAttributeName("deleteAllQuery");
deleteAllQueryMapping.setGetMethodName("getDeleteAllQuery");
deleteAllQueryMapping.setSetMethodName("setDeleteAllQuery");
deleteAllQueryMapping.setReferenceClass(DataModifyQuery.class);
deleteAllQueryMapping.setXPath(getPrimaryNamespaceXPath() + "delete-all-query");
descriptor.addMapping(deleteAllQueryMapping);
XMLCompositeObjectMapping historyPolicyMapping = new XMLCompositeObjectMapping();
historyPolicyMapping.setAttributeName("historyPolicy");
historyPolicyMapping.setGetMethodName("getHistoryPolicy");
historyPolicyMapping.setSetMethodName("setHistoryPolicy");
historyPolicyMapping.setReferenceClass(HistoryPolicy.class);
historyPolicyMapping.setXPath(getPrimaryNamespaceXPath() + "history-policy");
descriptor.addMapping(historyPolicyMapping);
return descriptor;
}
use of org.eclipse.persistence.oxm.mappings.XMLDirectMapping in project eclipselink by eclipse-ee4j.
the class ObjectPersistenceRuntimeXMLProject method buildAggregateMappingDescriptor.
protected ClassDescriptor buildAggregateMappingDescriptor() {
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClass(AggregateMapping.class);
descriptor.getInheritancePolicy().setParentClass(DatabaseMapping.class);
XMLDirectMapping referenceClassMapping = new XMLDirectMapping();
referenceClassMapping.setAttributeName("referenceClass");
referenceClassMapping.setGetMethodName("getReferenceClass");
referenceClassMapping.setSetMethodName("setReferenceClass");
referenceClassMapping.setXPath(getPrimaryNamespaceXPath() + "reference-class/text()");
descriptor.addMapping(referenceClassMapping);
return descriptor;
}
use of org.eclipse.persistence.oxm.mappings.XMLDirectMapping in project eclipselink by eclipse-ee4j.
the class ObjectPersistenceRuntimeXMLProject method buildTypedAssociationDescriptor.
protected ClassDescriptor buildTypedAssociationDescriptor() {
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClass(TypedAssociation.class);
descriptor.setDefaultRootElement("class-indicator-mapping");
descriptor.getEventManager().setPostBuildSelector("postBuild");
XMLDirectMapping keyMapping = new XMLDirectMapping();
keyMapping.setAttributeClassification(Class.class);
keyMapping.setAttributeName("key");
keyMapping.setGetMethodName("getKey");
keyMapping.setSetMethodName("setKey");
keyMapping.setXPath(getPrimaryNamespaceXPath() + "class/text()");
descriptor.addMapping(keyMapping);
XMLDirectMapping valueMapping = new XMLDirectMapping();
valueMapping.setAttributeName("value");
valueMapping.setGetMethodName("getValue");
valueMapping.setSetMethodName("setValue");
valueMapping.setField(buildTypedField(getPrimaryNamespaceXPath() + "class-indicator/text()"));
descriptor.addMapping(valueMapping);
return descriptor;
}
use of org.eclipse.persistence.oxm.mappings.XMLDirectMapping in project eclipselink by eclipse-ee4j.
the class ObjectPersistenceRuntimeXMLProject method buildInterfacePolicyDescriptor.
protected ClassDescriptor buildInterfacePolicyDescriptor() {
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClass(InterfacePolicy.class);
descriptor.setDefaultRootElement("interfaces");
XMLCompositeDirectCollectionMapping parentInterfacesMapping = new XMLCompositeDirectCollectionMapping();
parentInterfacesMapping.setAttributeElementClass(Class.class);
parentInterfacesMapping.setAttributeName("parentInterfaces");
parentInterfacesMapping.setGetMethodName("getParentInterfaces");
parentInterfacesMapping.setSetMethodName("setParentInterfaces");
parentInterfacesMapping.setXPath(getPrimaryNamespaceXPath() + "interface/text()");
descriptor.addMapping(parentInterfacesMapping);
XMLDirectMapping implementorDescriptorMapping = new XMLDirectMapping();
implementorDescriptorMapping.setAttributeName("implementorDescriptor");
implementorDescriptorMapping.setGetMethodName("getImplementorDescriptor");
implementorDescriptorMapping.setSetMethodName("setImplementorDescriptor");
implementorDescriptorMapping.setXPath(getPrimaryNamespaceXPath() + "implementor-descriptor/text()");
descriptor.addMapping(implementorDescriptorMapping);
return descriptor;
}
use of org.eclipse.persistence.oxm.mappings.XMLDirectMapping in project eclipselink by eclipse-ee4j.
the class ObjectPersistenceRuntimeXMLProject method buildDailyCacheInvalidationPolicyDescriptor.
protected ClassDescriptor buildDailyCacheInvalidationPolicyDescriptor() {
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClass(DailyCacheInvalidationPolicy.class);
descriptor.getInheritancePolicy().setParentClass(CacheInvalidationPolicy.class);
XMLDirectMapping expiryMinuteMapping = new XMLDirectMapping();
expiryMinuteMapping.setAttributeName("expiryTime");
expiryMinuteMapping.setGetMethodName("getExpiryTime");
expiryMinuteMapping.setSetMethodName("setExpiryTime");
XMLField expiryTimeField = new XMLField(getPrimaryNamespaceXPath() + "expiry-time/text()");
expiryTimeField.setIsTypedTextField(true);
expiryMinuteMapping.setField(expiryTimeField);
descriptor.addMapping(expiryMinuteMapping);
return descriptor;
}
Aggregations