Package org.eclipse.persistence.mappings

Examples of org.eclipse.persistence.mappings.OneToOneMapping


    /**
     * INTERNAL:
     * Initialize a OneToOneMapping.
     */
    protected OneToOneMapping initOneToOneMapping() {
        OneToOneMapping mapping = new OneToOneMapping();
        mapping.setIsReadOnly(false);
        mapping.setIsPrivateOwned(isPrivateOwned());
        mapping.setJoinFetch(getMappingJoinFetchType(getJoinFetch()));
        mapping.setIsOptional(isOptional());
        mapping.setAttributeName(getAttributeName());
        mapping.setReferenceClassName(getReferenceClassName());
       
        // Process the indirection.
        processIndirection(mapping);
       
        // Set the getter and setter methods if access is PROPERTY.
View Full Code Here


     * INTERNAL:
     * Process a one to one setting into an EclipseLink OneToOneMapping.
     */
    public void process() {
        // Initialize our mapping now with what we found.
        OneToOneMapping mapping = initOneToOneMapping();
       
        if (m_mappedBy == null || m_mappedBy.equals("")) {
            // Owning side, look for JoinColumns or PrimaryKeyJoinColumns.
            processOwningMappingKeys(mapping);
        } else {   
            // Non-owning side, process the foreign keys from the owner.
            OneToOneMapping ownerMapping = null;
            if (getOwningMapping(m_mappedBy).isOneToOneMapping()){
                ownerMapping = (OneToOneMapping)getOwningMapping(m_mappedBy);
            } else {
                // If improper mapping encountered, throw an exception.
                throw ValidationException.invalidMapping(getJavaClass(), getReferenceClass());
            }

            mapping.setSourceToTargetKeyFields(ownerMapping.getTargetToSourceKeyFields());
            mapping.setTargetToSourceKeyFields(ownerMapping.getSourceToTargetKeyFields());
        }
       
        // Process properties
        processProperties(mapping);

View Full Code Here

    /**
     * INTERNAL:
     * Initialize a OneToOneMapping.
     */
    protected OneToOneMapping initOneToOneMapping() {
        OneToOneMapping mapping = new OneToOneMapping();
        mapping.setIsOneToOneRelationship(true);
        mapping.setIsReadOnly(false);
        mapping.setIsOptional(isOptional());
        mapping.setAttributeName(getAttributeName());
        mapping.setReferenceClassName(getReferenceClassName());
        mapping.setDerivesId(derivesId());
       
        // Process join fetch type.
        processJoinFetch(getJoinFetch(), mapping);
       
        // Process the batch fetch if specified.
View Full Code Here

            // metadata.
            OneToManyMapping mapping = new OneToManyMapping();
            process(mapping);
           
            // Non-owning side, process the foreign keys from the owner.
            OneToOneMapping ownerMapping = null;
            if (getOwningMapping(getMappedBy()).isOneToOneMapping()){
                ownerMapping = (OneToOneMapping) getOwningMapping(getMappedBy());
            } else {
                // If improper mapping encountered, throw an exception.
                throw ValidationException.invalidMapping(getJavaClass(), getReferenceClass());
            }
               
            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

    /**
     * INTERNAL:
     * Initialize a OneToOneMapping.
     */
    protected OneToOneMapping initOneToOneMapping() {
        OneToOneMapping mapping = new OneToOneMapping();
        mapping.setIsReadOnly(false);
        mapping.setIsPrivateOwned(isPrivateOwned());
        mapping.setJoinFetch(getMappingJoinFetchType(getJoinFetch()));
        mapping.setIsOptional(isOptional());
        mapping.setAttributeName(getAttributeName());
        mapping.setReferenceClassName(getReferenceClassName());
       
        // Process the indirection.
        processIndirection(mapping);
       
        // Set the getter and setter methods if access is PROPERTY.
View Full Code Here

     * INTERNAL:
     * Process a many to one setting into an EclipseLink OneToOneMapping.
     */
    public void process() {
        // Initialize our mapping now with what we found.
        OneToOneMapping mapping = initOneToOneMapping();

        // Now process the JoinColumns (if there are any) for this mapping.
        processOwningMappingKeys(mapping);
       
        // process properties
View Full Code Here

     * INTERNAL:
     * Process a one to one setting into an EclipseLink OneToOneMapping.
     */
    public void process() {
        // Initialize our mapping now with what we found.
        OneToOneMapping mapping = initOneToOneMapping();
       
        if (m_mappedBy == null || m_mappedBy.equals("")) {
            // Owning side, look for JoinColumns or PrimaryKeyJoinColumns.
            processOwningMappingKeys(mapping);
        } else {   
            // Non-owning side, process the foreign keys from the owner.
            OneToOneMapping ownerMapping = null;
            if (getOwningMapping(m_mappedBy).isOneToOneMapping()){
                ownerMapping = (OneToOneMapping)getOwningMapping(m_mappedBy);
            } else {
                // If improper mapping encountered, throw an exception.
                throw ValidationException.invalidMapping(getJavaClass(), getReferenceClass());
            }

            Map<DatabaseField, DatabaseField> targetToSourceKeyFields;
            Map<DatabaseField, DatabaseField> sourceToTargetKeyFields;
           
            // If we are within a table per class strategy we have to update
            // the primary key field to point to our own database table.
            if (getDescriptor().usesTablePerClassInheritanceStrategy()) {
                targetToSourceKeyFields = new HashMap<DatabaseField, DatabaseField>();
                sourceToTargetKeyFields = new HashMap<DatabaseField, DatabaseField>();
               
                for (DatabaseField fkField : ownerMapping.getSourceToTargetKeyFields().keySet()) {
                    // We need to update the pk field to be to our table.
                    DatabaseField pkField = (DatabaseField) ownerMapping.getSourceToTargetKeyFields().get(fkField).clone();
                    pkField.setTable(getDescriptor().getPrimaryTable());
                    sourceToTargetKeyFields.put(fkField, pkField);
                    targetToSourceKeyFields.put(pkField, fkField);
                }
            } else {
                targetToSourceKeyFields = ownerMapping.getTargetToSourceKeyFields();
                sourceToTargetKeyFields = ownerMapping.getSourceToTargetKeyFields();
            }
           
            mapping.setSourceToTargetKeyFields(targetToSourceKeyFields);
            mapping.setTargetToSourceKeyFields(sourceToTargetKeyFields);
        }
View Full Code Here

    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

    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

     * 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

TOP

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

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.