use of org.eclipse.persistence.mappings.Association in project eclipselink by eclipse-ee4j.
the class MapEntryDirectEntity1MReportQueryTest method removeFromResult.
@Override
protected void removeFromResult(ReportQueryResult result, Vector expected) {
for (Enumeration e = expected.elements(); e.hasMoreElements(); ) {
ReportQueryResult expectedResult = (ReportQueryResult) e.nextElement();
Association expectedAssocication = (Association) expectedResult.getByIndex(0);
Association resultAssocication = (Association) result.getByIndex(0);
if (expectedAssocication.getKey().equals(resultAssocication.getKey()) && expectedAssocication.getValue().equals(resultAssocication.getValue())) {
expected.removeElement(expectedResult);
return;
}
}
getSession().logMessage("missing element: " + result);
}
use of org.eclipse.persistence.mappings.Association 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.mappings.Association in project eclipselink by eclipse-ee4j.
the class ObjectPersistenceRuntimeXMLProject_11_1_1 method buildRelationalDescriptorDescriptor.
/*
* this overridden method does <b>not</b> do super buildRelationalDescriptorDescriptor()
* on purpose 'cause the way the fields are mapped/named changed from 10.3.x to 11.1.x
*/
@Override
protected ClassDescriptor buildRelationalDescriptorDescriptor() {
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClass(RelationalDescriptor.class);
descriptor.getInheritancePolicy().setParentClass(ClassDescriptor.class);
XMLCompositeCollectionMapping tablesMapping = new XMLCompositeCollectionMapping();
tablesMapping.useCollectionClass(NonSynchronizedVector.class);
tablesMapping.setAttributeName("tables/table");
tablesMapping.setGetMethodName("getTables");
tablesMapping.setSetMethodName("setTables");
tablesMapping.setXPath(getPrimaryNamespaceXPath() + "tables/" + getPrimaryNamespaceXPath() + "table");
tablesMapping.setReferenceClass(DatabaseTable.class);
descriptor.addMapping(tablesMapping);
XMLCompositeCollectionMapping foreignKeyForMultipleTables = new XMLCompositeCollectionMapping();
foreignKeyForMultipleTables.setReferenceClass(Association.class);
foreignKeyForMultipleTables.setAttributeName("foreignKeysForMultipleTables");
foreignKeyForMultipleTables.setXPath(getPrimaryNamespaceXPath() + "foreign-keys-for-multiple-table/" + getSecondaryNamespaceXPath() + "field-reference");
foreignKeyForMultipleTables.setAttributeAccessor(new AttributeAccessor() {
@Override
public Object getAttributeValueFromObject(Object object) {
ClassDescriptor descriptor = (ClassDescriptor) object;
List<Association> associations = descriptor.getMultipleTableForeignKeyAssociations();
for (int index = 0; index < associations.size(); index++) {
Association association = associations.get(index);
String targetPrimaryKeyFieldName = (String) association.getKey();
association.setKey(new DatabaseField((String) association.getValue()));
association.setValue(new DatabaseField(targetPrimaryKeyFieldName));
}
return associations;
}
@Override
public void setAttributeValueInObject(Object object, Object value) {
ClassDescriptor descriptor = (ClassDescriptor) object;
List<Association> associations = (List<Association>) value;
for (int index = 0; index < associations.size(); index++) {
Association association = associations.get(index);
association.setKey(((DatabaseField) association.getKey()).getQualifiedName());
association.setValue(((DatabaseField) association.getValue()).getQualifiedName());
}
descriptor.setForeignKeyFieldNamesForMultipleTable(associations);
}
});
descriptor.addMapping(foreignKeyForMultipleTables);
return descriptor;
}
use of org.eclipse.persistence.mappings.Association in project eclipselink by eclipse-ee4j.
the class ObjectPersistenceRuntimeXMLProject method buildRelationalDescriptorDescriptor.
protected ClassDescriptor buildRelationalDescriptorDescriptor() {
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClass(RelationalDescriptor.class);
descriptor.getInheritancePolicy().setParentClass(ClassDescriptor.class);
XMLCompositeCollectionMapping tablesMapping = new XMLCompositeCollectionMapping();
tablesMapping.useCollectionClass(NonSynchronizedVector.class);
tablesMapping.setAttributeName("tables/table");
tablesMapping.setGetMethodName("getTables");
tablesMapping.setSetMethodName("setTables");
tablesMapping.setXPath(getPrimaryNamespaceXPath() + "tables/" + getPrimaryNamespaceXPath() + "table");
tablesMapping.setReferenceClass(DatabaseTable.class);
descriptor.addMapping(tablesMapping);
XMLCompositeCollectionMapping multipleTablesPrimaryKey = new XMLCompositeCollectionMapping();
multipleTablesPrimaryKey.setAttributeAccessor(new AttributeAccessor() {
@Override
public Object getAttributeValueFromObject(Object object) {
ClassDescriptor mapping = (ClassDescriptor) object;
List<Association> associations = mapping.getMultipleTablePrimaryKeyAssociations();
for (int index = 0; index < associations.size(); index++) {
Association association = associations.get(index);
association.setKey(new DatabaseField((String) association.getKey()));
association.setValue(new DatabaseField((String) association.getValue()));
}
return associations;
}
@Override
public void setAttributeValueInObject(Object object, Object value) {
ClassDescriptor mapping = (ClassDescriptor) object;
@SuppressWarnings({ "unchecked" }) List<Association> associations = (List<Association>) value;
for (int index = 0; index < associations.size(); index++) {
Association association = associations.get(index);
association.setKey(((DatabaseField) association.getKey()).getQualifiedName());
association.setValue(((DatabaseField) association.getValue()).getQualifiedName());
}
mapping.setForeignKeyFieldNamesForMultipleTable(associations);
}
});
multipleTablesPrimaryKey.setAttributeName("multipleTablesPrimaryKeys");
multipleTablesPrimaryKey.setReferenceClass(Association.class);
multipleTablesPrimaryKey.setXPath(getPrimaryNamespaceXPath() + "multiple-table-primary-keys/" + getSecondaryNamespaceXPath() + "field-reference");
descriptor.addMapping(multipleTablesPrimaryKey);
XMLCompositeCollectionMapping multipleTables = new XMLCompositeCollectionMapping();
multipleTables.setReferenceClass(Association.class);
multipleTables.setXPath(getPrimaryNamespaceXPath() + "multiple-table-foreign-keys/" + getSecondaryNamespaceXPath() + "field-reference");
multipleTables.setAttributeAccessor(new AttributeAccessor() {
@Override
public Object getAttributeValueFromObject(Object object) {
ClassDescriptor mapping = (ClassDescriptor) object;
List<Association> associations = mapping.getMultipleTableForeignKeyAssociations();
for (int index = 0; index < associations.size(); index++) {
Association association = associations.get(index);
association.setKey(new DatabaseField((String) association.getKey()));
association.setValue(new DatabaseField((String) association.getValue()));
}
return associations;
}
@Override
public void setAttributeValueInObject(Object object, Object value) {
ClassDescriptor mapping = (ClassDescriptor) object;
@SuppressWarnings({ "unchecked" }) List<Association> associations = (List<Association>) value;
for (int index = 0; index < associations.size(); index++) {
Association association = associations.get(index);
association.setKey(((DatabaseField) association.getKey()).getQualifiedName());
association.setValue(((DatabaseField) association.getValue()).getQualifiedName());
}
mapping.setForeignKeyFieldNamesForMultipleTable(associations);
}
});
multipleTables.setAttributeName("multipleTablesForeignKeys");
descriptor.addMapping(multipleTables);
return descriptor;
}
use of org.eclipse.persistence.mappings.Association in project eclipselink by eclipse-ee4j.
the class ObjectTypeConverter method setFieldToAttributeValueAssociations.
/**
* INTERNAL:
* Set a collection of the field to attribute value associations.
*/
public void setFieldToAttributeValueAssociations(Vector fieldToAttributeValueAssociations) {
setFieldToAttributeValues(new HashMap(fieldToAttributeValueAssociations.size() + 1));
setAttributeToFieldValues(new HashMap(fieldToAttributeValueAssociations.size() + 1));
for (Enumeration associationsEnum = fieldToAttributeValueAssociations.elements(); associationsEnum.hasMoreElements(); ) {
Association association = (Association) associationsEnum.nextElement();
addConversionValue(association.getKey(), association.getValue());
}
}
Aggregations