Package org.eclipse.persistence.mappings

Examples of org.eclipse.persistence.mappings.Association


    public Vector getFieldNameToMethodNameAssociations() {
        Vector associations = new Vector();
        for (Iterator source = getFieldTransformations().iterator(); source.hasNext();) {
            FieldTransformation tf = (FieldTransformation)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;
    }
View Full Code Here


     * 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().addElement(tf);
        }
    }
View Full Code Here

                AggregateCollectionMapping mapping = (AggregateCollectionMapping)object;
                List sourceFields = mapping.getSourceKeyFields();
                List targetFields = mapping.getTargetForeignKeyFields();
                List associations = new ArrayList(sourceFields.size());
                for (int index = 0; index < sourceFields.size(); index++) {
                    associations.add(new Association(targetFields.get(index), sourceFields.get(index)));
                }
                return associations;
            }

            public void setAttributeValueInObject(Object object, Object value) {
                AggregateCollectionMapping mapping = (AggregateCollectionMapping)object;
                List associations = (List)value;
                mapping.setSourceKeyFields(NonSynchronizedVector.newInstance(associations.size()));
                mapping.setTargetForeignKeyFields(NonSynchronizedVector.newInstance(associations.size()));
                Iterator iterator = associations.iterator();
                while (iterator.hasNext()) {
                    Association association = (Association)iterator.next();
                    mapping.getSourceKeyFields().add((DatabaseField)association.getValue());
                    mapping.getTargetForeignKeyFields().add((DatabaseField)association.getKey());
                }
            }
        });
        sourceToTargetKeyFieldAssociationsMapping.setAttributeName("sourceToTargetKeyFieldAssociations");
        sourceToTargetKeyFieldAssociationsMapping.setXPath(getPrimaryNamespaceXPath() + "target-foreign-key/" + getSecondaryNamespaceXPath() + "field-reference");
View Full Code Here

            public Object getAttributeValueFromObject(Object object) {
                AggregateObjectMapping mapping = (AggregateObjectMapping)object;
                Vector associations = mapping.getAggregateToSourceFieldNameAssociations();
                Vector translations = new Vector(associations.size());
                for (int index = 0; index < associations.size(); index++) {
                    Association association = (Association)associations.get(index);
                    FieldTranslation translation = new FieldTranslation();
                    translation.setKey(new DatabaseField((String)association.getKey()));
                    translation.setValue(new DatabaseField((String)association.getValue()));
                    translations.add(translation);
                }
                return translations;
            }

            public void setAttributeValueInObject(Object object, Object value) {
                AggregateObjectMapping mapping = (AggregateObjectMapping)object;
                Vector associations = (Vector)value;
                for (int index = 0; index < associations.size(); index++) {
                    Association association = (Association)associations.get(index);
                    association.setKey(((DatabaseField)association.getKey()).getQualifiedName());
                    association.setValue(((DatabaseField)association.getValue()).getQualifiedName());
                }
                mapping.setAggregateToSourceFieldNameAssociations(associations);
            }
        });
        aggregateToSourceFieldNameAssociationsMapping.setAttributeName("aggregateToSourceFieldNameAssociationsMapping");
View Full Code Here

        multipleTablesPrimaryKey.setAttributeAccessor(new AttributeAccessor() {
            public Object getAttributeValueFromObject(Object object) {
                ClassDescriptor mapping = (ClassDescriptor)object;
                Vector associations = mapping.getMultipleTablePrimaryKeyAssociations();
                for (int index = 0; index < associations.size(); index++) {
                    Association association = (Association)associations.get(index);
                    association.setKey(new DatabaseField((String)association.getKey()));
                    association.setValue(new DatabaseField((String)association.getValue()));
                }
                return associations;
            }

            public void setAttributeValueInObject(Object object, Object value) {
                ClassDescriptor mapping = (ClassDescriptor)object;
                Vector associations = (Vector)value;
                for (int index = 0; index < associations.size(); index++) {
                    Association 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() {
            public Object getAttributeValueFromObject(Object object) {
                ClassDescriptor mapping = (ClassDescriptor)object;
                Vector associations = mapping.getMultipleTableForeignKeyAssociations();
                for (int index = 0; index < associations.size(); index++) {
                    Association association = (Association)associations.get(index);
                    association.setKey(new DatabaseField((String)association.getKey()));
                    association.setValue(new DatabaseField((String)association.getValue()));
                }
                return associations;
            }

            public void setAttributeValueInObject(Object object, Object value) {
                ClassDescriptor mapping = (ClassDescriptor)object;
                Vector associations = (Vector)value;
                for (int index = 0; index < associations.size(); index++) {
                    Association association = (Association)associations.get(index);
                    association.setKey(((DatabaseField)association.getKey()).getQualifiedName());
                    association.setValue(((DatabaseField)association.getValue()).getQualifiedName());
                }
                mapping.setForeignKeyFieldNamesForMultipleTable(associations);
            }
        });
        multipleTables.setAttributeName("multipleTablesForeignKeys");
View Full Code Here

        foreignKeyForMultipleTables.setAttributeAccessor(new AttributeAccessor() {
                public Object getAttributeValueFromObject(Object object) {
                    ClassDescriptor descriptor = (ClassDescriptor) object;
                    Vector associations = descriptor.getMultipleTableForeignKeyAssociations();
                    for (int index = 0; index < associations.size(); index++) {
                        Association association = (Association) associations.get(index);
                        String targetPrimaryKeyFieldName = (String) association.getKey();
                        association.setKey(new DatabaseField((String) association.getValue()));
                        association.setValue(new DatabaseField(targetPrimaryKeyFieldName));
                    }
                    return associations;
                }
                public void setAttributeValueInObject(Object object, Object value) {
                    ClassDescriptor descriptor = (ClassDescriptor) object;
                    Vector associations = (Vector) value;
                    for (int index = 0; index < associations.size(); index++) {
                        Association association = (Association) associations.get(index);
                        association.setKey(((DatabaseField) association.getKey()).getQualifiedName());
                        association.setValue(((DatabaseField) association.getValue()).getQualifiedName());
                    }
                    descriptor.setForeignKeyFieldNamesForMultipleTable(associations);
                }
            });
        descriptor.addMapping(foreignKeyForMultipleTables);
View Full Code Here

                    Map sourceToTargetKeyFields = ((XMLObjectReferenceMapping) object).getSourceToTargetKeyFieldAssociations();
                    List associations = new ArrayList(sourceToTargetKeyFields.size());
                    Iterator iterator = sourceToTargetKeyFields.entrySet().iterator();
                    while (iterator.hasNext()) {
                        Map.Entry entry = (Map.Entry)iterator.next();
                        associations.add(new Association(entry.getKey(), entry.getValue()));
                    }
                    return associations;
                }

                public void setAttributeValueInObject(Object object, Object value) {
                    XMLObjectReferenceMapping mapping = (XMLObjectReferenceMapping) object;
                    List associations = (List)value;
                    mapping.setSourceToTargetKeyFieldAssociations(new HashMap(associations.size() + 1));
                    Iterator iterator = associations.iterator();
                    while (iterator.hasNext()) {
                        Association 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");
View Full Code Here

            public Object getAttributeValueFromObject(Object object) {
                List sourceFields = ((DirectCollectionMapping)object).getSourceKeyFields();
                List referenceFields = ((DirectCollectionMapping)object).getReferenceKeyFields();
                List associations = new ArrayList(sourceFields.size());
                for (int index = 0; index < sourceFields.size(); index++) {
                    associations.add(new Association(referenceFields.get(index), sourceFields.get(index)));
                }
                return associations;
            }

            public void setAttributeValueInObject(Object object, Object value) {
                DirectCollectionMapping mapping = (DirectCollectionMapping)object;
                List associations = (List)value;
                mapping.setSourceKeyFields(NonSynchronizedVector.newInstance(associations.size()));
                mapping.setReferenceKeyFields(NonSynchronizedVector.newInstance(associations.size()));
                Iterator iterator = associations.iterator();
                while (iterator.hasNext()) {
                    Association association = (Association)iterator.next();
                    mapping.getSourceKeyFields().add((DatabaseField)association.getValue());
                    mapping.getReferenceKeyFields().add((DatabaseField)association.getKey());
                }
            }
        });
        sourceToReferenceKeyFieldAssociationsMapping.setAttributeName("sourceToReferenceKeyFieldAssociations");
        sourceToReferenceKeyFieldAssociationsMapping.setXPath(getPrimaryNamespaceXPath() + "reference-foreign-key/" + getSecondaryNamespaceXPath() + "field-reference");
View Full Code Here

            public Object getAttributeValueFromObject(Object object) {
                List sourceFields = ((ManyToManyMapping)object).getSourceKeyFields();
                List relationFields = ((ManyToManyMapping)object).getSourceRelationKeyFields();
                List 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;
            }

            public void setAttributeValueInObject(Object object, Object value) {
                ManyToManyMapping mapping = (ManyToManyMapping)object;
                List associations = (List)value;
                mapping.setSourceKeyFields(NonSynchronizedVector.newInstance(associations.size()));
                mapping.setSourceRelationKeyFields(NonSynchronizedVector.newInstance(associations.size()));
                Iterator iterator = associations.iterator();
                while (iterator.hasNext()) {
                    Association 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() {
            public Object getAttributeValueFromObject(Object object) {
                List targetFields = ((ManyToManyMapping)object).getTargetKeyFields();
                List relationFields = ((ManyToManyMapping)object).getTargetRelationKeyFields();
                List 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;
            }

            public void setAttributeValueInObject(Object object, Object value) {
                ManyToManyMapping mapping = (ManyToManyMapping)object;
                List associations = (List)value;
                mapping.setTargetKeyFields(NonSynchronizedVector.newInstance(associations.size()));
                mapping.setTargetRelationKeyFields(NonSynchronizedVector.newInstance(associations.size()));
                Iterator iterator = associations.iterator();
                while (iterator.hasNext()) {
                    Association 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");
View Full Code Here

            public Object getAttributeValueFromObject(Object object) {
                List sourceFields = ((OneToManyMapping)object).getSourceKeyFields();
                List targetFields = ((OneToManyMapping)object).getTargetForeignKeyFields();
                List associations = new ArrayList(sourceFields.size());
                for (int index = 0; index < sourceFields.size(); index++) {
                    associations.add(new Association(targetFields.get(index), sourceFields.get(index)));
                }
                return associations;
            }

            public void setAttributeValueInObject(Object object, Object value) {
                OneToManyMapping mapping = (OneToManyMapping)object;
                List associations = (List)value;
                mapping.setSourceKeyFields(NonSynchronizedVector.newInstance(associations.size()));
                mapping.setTargetForeignKeyFields(NonSynchronizedVector.newInstance(associations.size()));
                Iterator iterator = associations.iterator();
                while (iterator.hasNext()) {
                    Association association = (Association)iterator.next();
                    mapping.getSourceKeyFields().add((DatabaseField)association.getValue());
                    mapping.getTargetForeignKeyFields().add((DatabaseField)association.getKey());
                }
            }
        });
        sourceToTargetKeyFieldAssociationsMapping.setAttributeName("sourceToTargetKeyFieldAssociations");
        sourceToTargetKeyFieldAssociationsMapping.setXPath(getSecondaryNamespaceXPath() + "target-foreign-key/" + getSecondaryNamespaceXPath() + "field-reference");
View Full Code Here

TOP

Related Classes of org.eclipse.persistence.mappings.Association

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.