use of org.eclipse.persistence.mappings.Association 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.Association in project eclipselink by eclipse-ee4j.
the class ObjectPersistenceRuntimeXMLProject_11_1_1 method buildXMLObjectReferenceMappingDescriptor.
protected ClassDescriptor buildXMLObjectReferenceMappingDescriptor() {
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClass(XMLObjectReferenceMapping.class);
descriptor.getInheritancePolicy().setParentClass(AggregateMapping.class);
XMLCompositeCollectionMapping sourceToTargetKeyFieldAssociationsMapping = new XMLCompositeCollectionMapping();
sourceToTargetKeyFieldAssociationsMapping.setReferenceClass(Association.class);
// Handle translation of foreign key associations to hashmaps.
sourceToTargetKeyFieldAssociationsMapping.setAttributeAccessor(new AttributeAccessor() {
@Override
public Object getAttributeValueFromObject(Object object) {
Map<XMLField, XMLField> sourceToTargetKeyFields = ((XMLObjectReferenceMapping) object).getSourceToTargetKeyFieldAssociations();
List<Association> associations = new ArrayList<>(sourceToTargetKeyFields.size());
Iterator<Map.Entry<XMLField, XMLField>> iterator = sourceToTargetKeyFields.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<XMLField, XMLField> entry = iterator.next();
associations.add(new Association(entry.getKey(), entry.getValue()));
}
return associations;
}
@Override
public void setAttributeValueInObject(Object object, Object value) {
XMLObjectReferenceMapping mapping = (XMLObjectReferenceMapping) object;
List<Association> associations = (List<Association>) value;
mapping.setSourceToTargetKeyFieldAssociations(new HashMap<>(associations.size() + 1));
Iterator<Association> iterator = associations.iterator();
while (iterator.hasNext()) {
Association association = iterator.next();
mapping.getSourceToTargetKeyFieldAssociations().put(association.getKey(), association.getValue());
}
}
});
sourceToTargetKeyFieldAssociationsMapping.setAttributeName("sourceToTargetKeyFieldAssociations");
sourceToTargetKeyFieldAssociationsMapping.setXPath(getPrimaryNamespaceXPath() + "source-to-target-key-field-association/" + getSecondaryNamespaceXPath() + "field-reference");
descriptor.addMapping(sourceToTargetKeyFieldAssociationsMapping);
XMLCompositeCollectionMapping sourceToTargetKeysMapping = new XMLCompositeCollectionMapping();
sourceToTargetKeysMapping.setReferenceClass(DatabaseField.class);
sourceToTargetKeysMapping.setAttributeName("sourceToTargetKeys");
sourceToTargetKeysMapping.setXPath(getPrimaryNamespaceXPath() + "source-to-target-key-fields/" + getPrimaryNamespaceXPath() + "field");
((XMLField) sourceToTargetKeysMapping.getField()).setLeafElementType(fieldQname);
descriptor.addMapping(sourceToTargetKeysMapping);
return descriptor;
}
use of org.eclipse.persistence.mappings.Association in project eclipselink by eclipse-ee4j.
the class AbstractTransformationMapping method getFieldNameToMethodNameAssociations.
/**
* INTERNAL:
* Needed for backwards compatibility
*/
public Vector getFieldNameToMethodNameAssociations() {
Vector associations = new Vector();
for (Iterator<FieldTransformation> source = getFieldTransformations().iterator(); source.hasNext(); ) {
FieldTransformation tf = source.next();
if (tf instanceof MethodBasedFieldTransformation) {
Association ass = new Association();
ass.setKey(tf.getField().getQualifiedName());
ass.setValue(((MethodBasedFieldTransformation) tf).getMethodName());
associations.addElement(ass);
}
}
return associations;
}
use of org.eclipse.persistence.mappings.Association in project eclipselink by eclipse-ee4j.
the class AbstractTransformationMapping method setFieldNameToMethodNameAssociations.
/**
* INTERNAL:
* needed for backwards compatibility
*/
public void setFieldNameToMethodNameAssociations(Vector associations) {
setFieldTransformations(org.eclipse.persistence.internal.helper.NonSynchronizedVector.newInstance(associations.size()));
for (Iterator source = associations.iterator(); source.hasNext(); ) {
Association ass = (Association) source.next();
MethodBasedFieldTransformation tf = new MethodBasedFieldTransformation();
tf.setField(new DatabaseField((String) ass.getKey()));
tf.setMethodName((String) ass.getValue());
getFieldTransformations().add(tf);
}
}
use of org.eclipse.persistence.mappings.Association in project eclipselink by eclipse-ee4j.
the class DBWSBuilderModelProject method buildDBWSBuilderModelDescriptor.
protected ClassDescriptor buildDBWSBuilderModelDescriptor() {
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClass(DBWSBuilderModel.class);
descriptor.setDefaultRootElement("dbws-builder");
XMLCompositeCollectionMapping propertiesMapping = new XMLCompositeCollectionMapping();
propertiesMapping.setReferenceClass(Association.class);
propertiesMapping.setAttributeAccessor(new AttributeAccessor() {
@Override
public String getAttributeName() {
return "properties";
}
@Override
public Object getAttributeValueFromObject(Object object) throws DescriptorException {
DBWSBuilderModel model = (DBWSBuilderModel) object;
Vector<Association> associations = new Vector<Association>();
for (Map.Entry<String, String> me : model.properties.entrySet()) {
associations.add(new Association(me.getKey(), me.getValue()));
}
return associations;
}
@Override
public void setAttributeValueInObject(Object object, Object value) throws DescriptorException {
DBWSBuilderModel model = (DBWSBuilderModel) object;
Vector<Association> associations = (Vector<Association>) value;
for (Association a : associations) {
model.properties.put((String) a.getKey(), (String) a.getValue());
}
}
});
propertiesMapping.setXPath("properties/property");
descriptor.addMapping(propertiesMapping);
XMLChoiceCollectionMapping operationsMapping = new XMLChoiceCollectionMapping();
operationsMapping.setAttributeName("operations");
operationsMapping.setContainerPolicy(new ListContainerPolicy(ArrayList.class));
operationsMapping.addChoiceElement("table", TableOperationModel.class);
operationsMapping.addChoiceElement("procedure", ProcedureOperationModel.class);
operationsMapping.addChoiceElement("plsql-procedure", PLSQLProcedureOperationModel.class);
operationsMapping.addChoiceElement("sql", SQLOperationModel.class);
operationsMapping.addChoiceElement("batch-sql", BatchSQLOperationModel.class);
descriptor.addMapping(operationsMapping);
return descriptor;
}
Aggregations