Examples of OneToOneMapping


Examples of org.eclipse.persistence.mappings.OneToOneMapping

                        overrideField.setTable(getReferenceDatabaseTable());
                    }
                   
                    addFieldNameTranslation(embeddableMapping, overrideName, overrideField, mappingAccessor);
                } else if (mapping.isOneToOneMapping()) {
                    OneToOneMapping oneToOneMapping = (OneToOneMapping) mapping;
                   
                    if (oneToOneMapping.isForeignKeyRelationship()) {
                        AssociationOverrideMetadata associationOverride = associationOverrides.get(overrideName);
                       
                        if (associationOverride == null) {
                            for (DatabaseField fkField : oneToOneMapping.getForeignKeyFields()) {
                                DatabaseField collectionTableField = fkField.clone();
                                collectionTableField.setTable(getReferenceDatabaseTable());
                                embeddableMapping.addFieldTranslation(collectionTableField, fkField.getName());
                            }
                        } else {
View Full Code Here

Examples of org.eclipse.persistence.mappings.OneToOneMapping

     * INTERNAL:
     */
    protected void prepareOneToOneSelectionQuery(OneToOneMapping sourceMapping, AbstractSession session) {
        // Clone the mapping because in reality that is what we have, that
        // is, a 1-1 mapping to each class of the hierarchy.
        OneToOneMapping oneToOne = (OneToOneMapping) sourceMapping.clone();
           
        // Update the target keys to have an empty table (descriptor will figure it out)
        for (DatabaseField targetField : oneToOne.getTargetToSourceKeyFields().keySet()) {
            targetField.setTable(new DatabaseTable());
        }
       
        addSelectionQuery(oneToOne, sourceMapping, session);
    }
View Full Code Here

Examples of org.eclipse.persistence.mappings.OneToOneMapping

                }
                return associations;
            }

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

Examples of org.eclipse.persistence.mappings.OneToOneMapping

                }
                return associations;
            }

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

Examples of org.eclipse.persistence.mappings.OneToOneMapping

     */
    protected void processOneToManyMapping() {
       // Non-owning side, process the foreign keys from the owner.
       DatabaseMapping owningMapping = getOwningMapping();
       if (owningMapping.isOneToOneMapping()){
           OneToOneMapping ownerMapping = (OneToOneMapping) owningMapping;
          
           // If the owner uses a relation table mechanism we must map a M-M.
           if (ownerMapping.hasRelationTableMechanism()) {
              ManyToManyMapping mapping = new ManyToManyMapping();
              // Process the common collection mapping.
              process(mapping);
              // Process the mapped by relation table metadata.
              processMappedByRelationTable(ownerMapping.getRelationTableMechanism(), mapping.getRelationTableMechanism());
              // Set the mapping to read only
              mapping.setIsReadOnly(true);
           } else {
               // Create a 1-M mapping and process common collection mapping
               // metadata first followed by specific metadata.
              OneToManyMapping mapping = new OneToManyMapping();
              process(mapping);
             
               Map<DatabaseField, DatabaseField> keys = ownerMapping.getSourceToTargetKeyFields();
               for (DatabaseField fkField : keys.keySet()) {
                   DatabaseField pkField = keys.get(fkField);
                   
                   // If we are within a table per class strategy we have to update
                   // the primary key field to point to our own database table.
View Full Code Here

Examples of org.eclipse.persistence.mappings.OneToOneMapping

    public OneToOneMapping addOneToOneMapping(String name, DynamicType refType, String... fkFieldNames) {
        if (fkFieldNames == null || refType.getDescriptor().getPrimaryKeyFields().size() != fkFieldNames.length) {
            throw new IllegalArgumentException("Invalid FK field names: " + fkFieldNames + " for target: " + refType);
        }

        OneToOneMapping mapping = new OneToOneMapping();
        mapping.setAttributeName(name);
        mapping.setReferenceClass(refType.getJavaClass());

        for (int index = 0; index < fkFieldNames.length; index++) {
            String targetField = refType.getDescriptor().getPrimaryKeyFields().get(index).getName();
            mapping.addForeignKeyFieldName(fkFieldNames[index], targetField);
        }

        return (OneToOneMapping) addMapping(mapping);
    }
View Full Code Here

Examples of org.eclipse.persistence.mappings.OneToOneMapping

                    fieldValue = ((AbstractDirectMapping)mapping).getFieldValue(pkElementArray[index].getValue(key, session), session);
                }
            } else {
                fieldValue = pkElementArray[index].getValue(key, session);
                if ( (fieldValue !=null) && (pkClass != null) && (mapping.isOneToOneMapping()) ){
                    OneToOneMapping refmapping = (OneToOneMapping)mapping;
                    DatabaseField targetKey = refmapping.getSourceToTargetKeyFields().get(pkElementArray[index].getDatabaseField());
                    CMPPolicy refPolicy = refmapping.getReferenceDescriptor().getCMPPolicy();
                    if (refPolicy.isCMP3Policy()){
                        Class aPKClass = refPolicy.getPKClass();
                        if ((aPKClass != null) && (aPKClass != fieldValue.getClass()) && (!aPKClass.isAssignableFrom(fieldValue.getClass()))) {
                            throw new IllegalArgumentException(ExceptionLocalization.buildMessage("invalid_pk_class", new Object[] { aPKClass, fieldValue.getClass() }));
                        }
View Full Code Here

Examples of org.eclipse.persistence.mappings.OneToOneMapping

                            // ensure the referenced descriptor was initialized
                            refDescriptor.initialize(session);
                            CMPPolicy refPolicy = refDescriptor.getCMPPolicy();
                            if ((refPolicy!=null) && refPolicy.isCMP3Policy() && (refPolicy.getPKClass() == currentKeyClass)){
                                //Since the ref pk class is our pk class, get the accessor we need to pull the value out of the PK class for our field
                                OneToOneMapping refmapping = (OneToOneMapping)mapping;
                                DatabaseField targetKey = refmapping.getSourceToTargetKeyFields().get(field);
                                pkAttributes[i] = ((CMP3Policy)refPolicy).fieldToAccessorMap.get(targetKey);
                                //associate their accessor to our field so we can look it up when we need it
                                this.fieldToAccessorMap.put(field, pkAttributes[i]);
                                noSuchElementException = null;
                                break;
View Full Code Here

Examples of org.eclipse.persistence.mappings.OneToOneMapping

        if (mapping.isDirectToFieldMapping()) {
            fieldValue = ((AbstractDirectMapping)mapping).getFieldValue(accessor.getValue(key, session), session);
        } else {
            fieldValue = accessor.getValue(key, session);
            if (mapping.isOneToOneMapping()){
                OneToOneMapping refmapping = (OneToOneMapping)mapping;
                DatabaseField targetKey = refmapping.getSourceToTargetKeyFields().get(accessor.getDatabaseField());
                CMPPolicy refPolicy = refmapping.getReferenceDescriptor().getCMPPolicy();
                if (refPolicy.isCMP3Policy()){
                    Class pkClass = refPolicy.getPKClass();
                    if ((pkClass != null) && (pkClass != fieldValue.getClass()) && (!pkClass.isAssignableFrom(fieldValue.getClass()))) {
                        throw new IllegalArgumentException(ExceptionLocalization.buildMessage("invalid_pk_class", new Object[] { refPolicy.getPKClass(), fieldValue.getClass() }));
                    }
View Full Code Here

Examples of org.eclipse.persistence.mappings.OneToOneMapping

                }
                return associations;
            }

            public void setAttributeValueInObject(Object object, Object value) {
                OneToOneMapping mapping = (OneToOneMapping)object;
                List associations = (List)value;
                mapping.setSourceToTargetKeyFields(new HashMap(associations.size() + 1));
                mapping.setTargetToSourceKeyFields(new HashMap(associations.size() + 1));
                Iterator iterator = associations.iterator();
                while (iterator.hasNext()) {
                    Association 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");
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.