Package oracle.toplink.essentials.mappings

Examples of oracle.toplink.essentials.mappings.DatabaseMapping


    private void refreshFetchGroupIntoClones(Object cachedObject, Object workingClone, Object backupClone, FetchGroup fetchGroupInObject, FetchGroup fetchGroupInClone, UnitOfWorkImpl uow) {
        Vector mappings = descriptor.getMappings();
        boolean isObjectPartial = (fetchGroupInObject != null);
        Set fetchedAttributes = isObjectPartial ? fetchGroupInObject.getAttributes() : null;
        for (int index = 0; index < mappings.size(); index++) {
            DatabaseMapping mapping = (DatabaseMapping)mappings.get(index);
            if ((!isObjectPartial) || ((fetchedAttributes != null) && fetchedAttributes.contains(mapping.getAttributeName()))) {
                //only fill in the unfetched attributes into clones
                mapping.buildClone(cachedObject, workingClone, uow);
                    mapping.buildClone(workingClone, backupClone, uow);
            }
        }
    }
View Full Code Here


        Vector mappings = descriptor.getMappings();

        //fetched attributes list in working clone
        Set fetchedAttributesClone = fetchGroupInClone.getAttributes();
        for (int index = 0; index < mappings.size(); index++) {
            DatabaseMapping mapping = (DatabaseMapping)mappings.get(index);

            //only revert the attribute which is fetched by the cached object, but not fecthed by the clones.
            if (isAttributeFetched(cachedObject, mapping.getAttributeName()) && (!fetchedAttributesClone.contains(mapping.getAttributeName()))) {
                //only fill in the unfetched attributes into clones
                mapping.buildClone(cachedObject, workingClone, uow);
                    mapping.buildClone(workingClone, backupClone, uow);
            }
        }
    }
View Full Code Here

        //First add all primary key attributes into the fetch group
        Iterator pkMappingIter = builder.getPrimaryKeyMappings().iterator();

        while (pkMappingIter.hasNext()) {
            DatabaseMapping pkMapping = (DatabaseMapping)pkMappingIter.next();
            DatabaseField pkField = pkMapping.getField();

            // Add pk attribute to the fetch group attributes list
            attributes.add(pkMapping.getAttributeName());
        }

        //second, add version/optimistic locking object attributes into the fetch group if applied.
        OptimisticLockingPolicy lockingPolicy = getDescriptor().getOptimisticLockingPolicy();
        if (query.shouldMaintainCache() && (lockingPolicy != null)) {
            lockingPolicy.prepareFetchGroupForReadQuery(query.getFetchGroup(), query);
        }

        //thrid, prepare all fetch group attributes
        Iterator attrIter = attributes.iterator();
        while (attrIter.hasNext()) {
            String attrName = (String)attrIter.next();
            DatabaseMapping mapping = builder.getMappingForAttributeName(attrName);
            if (mapping == null) {
                //the attribute name defined in the fetch group is not mapped
                throw QueryException.fetchGroupAttributeNotMapped(attrName);
            }

            //partially fetch each fetch group attribute
            if (mapping.isCollectionMapping()) {
                query.getFetchGroup().addFetchGroupAttribute(query.getExpressionBuilder().anyOf(attrName));
            } else {
                query.getFetchGroup().addFetchGroupAttribute(query.getExpressionBuilder().get(attrName));
            }
        }
View Full Code Here

                Class classValue = descriptor.getInheritancePolicy().classFromRow(entityRecord, query.getSession());
                descriptor = query.getSession().getDescriptor(classValue);
            }
        }
        for (Iterator mappings = descriptor.getMappings().iterator(); mappings.hasNext();){
            DatabaseMapping mapping = (DatabaseMapping)mappings.next();
            FieldResult fieldResult = (FieldResult)this.getFieldResults().get(mapping.getAttributeName());
            if (fieldResult != null){
                if (mapping.getFields().size() == 1 ){
                    entityRecord.put(mapping.getFields().firstElement(), record.get(fieldResult.getColumnName()));
                }else if (mapping.getFields().size() >1){
                    getValueFromRecordForMapping(entityRecord,mapping,fieldResult,record);
                }
            }else{
                for (Iterator fields = mapping.getFields().iterator(); fields.hasNext();){
                    DatabaseField field = (DatabaseField)fields.next();
                    entityRecord.put(field, record.get(field));
                }
            }
        }
View Full Code Here

    /**
     * INTERNAL:
     *   This method is for processing a single FieldResult, returning the DatabaseField it refers to.
     */
    public DatabaseField processValueFromRecordForMapping(ClassDescriptor descriptor, String[] attributeNames, int currentLoc){
        DatabaseMapping mapping = descriptor.getMappingForAttributeName(attributeNames[currentLoc]);
        if (mapping==null){throw QueryException.mappingForFieldResultNotFound(attributeNames,currentLoc);}
        currentLoc++;
        if (attributeNames.length!=currentLoc){
            ClassDescriptor currentDescriptor = mapping.getReferenceDescriptor();
            DatabaseField df= processValueFromRecordForMapping(currentDescriptor, attributeNames, currentLoc);
            if (mapping.isOneToOneMapping()){
                return (DatabaseField)(((OneToOneMapping)mapping).getTargetToSourceKeyFields().get(df));
            }
            return df;
        }else{
            //this is it.. return this mapping's field
            return (DatabaseField) mapping.getFields().firstElement();
        }
    }
View Full Code Here

        if ( (size==0) || (clone==null) ){
            return;
        }
        ClassDescriptor descriptor = unitOfWork.getDescriptor(clone);
        for (int index = 0; index < size; index++) {
            DatabaseMapping mapping = descriptor.getMappingForAttributeName((String)joinManager.getJoinedAttributes().get(index));
            if (mapping !=null){
                Object attributeValue = mapping.getRealAttributeValueFromObject(clone, unitOfWork);
                if (attributeValue != null){
                    if ( mapping.isForeignReferenceMapping() && (((ForeignReferenceMapping)mapping).getIndirectionPolicy().usesTransparentIndirection()) ) {
                        ((IndirectContainer)attributeValue).getValueHolder().getValue()
                    }
                    //recurse through the mapping if the expression's base isn't the base expressionBuilder
                    QueryKeyExpression queryKeyExpression = (QueryKeyExpression)joinExpressions.get(index);
                    if (!queryKeyExpression.getBaseExpression().isExpressionBuilder()){
                        ObjectLevelReadQuery nestedQuery =null;
                        //if (joinManager.getJoinedMappingQueryClones()==null){
                            if (joinManager.getJoinedMappingQueries_()!=null){
                                nestedQuery = (ObjectLevelReadQuery)joinManager.getJoinedMappingQueries_().get(mapping);
                            }
                        /*}else{
                            nestedQuery = joinManager.getJoinedMappingQueryClones().get(mapping);
                        }*/

                        if ( (nestedQuery!=null) && (nestedQuery.getJoinedAttributeManager()!=null)){
                            if (!mapping.isCollectionMapping()){
                                triggerJoinExpressions(unitOfWork, nestedQuery.getJoinedAttributeManager(), attributeValue);
                            }else {
                                ContainerPolicy cp = ((CollectionMapping)mapping).getContainerPolicy();
                                Object iterator = cp.iteratorFor(attributeValue);
                                while (cp.hasNext(iterator)){
View Full Code Here

        // then no elaborate conversion is required.
        // If key is compound, add each value to the vector.
        KeyElementAccessor[] pkElementArray = this.getKeyClassFields(key.getClass());
        Vector pkVector = new Vector(pkElementArray.length);
        for (int index = 0; index < pkElementArray.length; index++) {
            DatabaseMapping mapping = this.getDescriptor().getObjectBuilder().getMappingForAttributeName(pkElementArray[index].getAttributeName());
            if (mapping == null) {
                mapping = this.getDescriptor().getObjectBuilder().getMappingForField(pkElementArray[index].getDatabaseField());
            }
            while (mapping.isAggregateObjectMapping()) {
                mapping = mapping.getReferenceDescriptor().getObjectBuilder().getMappingForAttributeName(pkElementArray[index].getAttributeName());
                if (mapping == null) {// must be aggregate
                    mapping = this.getDescriptor().getObjectBuilder().getMappingForField(pkElementArray[index].getDatabaseField());
                }
            }
            Object fieldValue = null;
            if (mapping.isDirectToFieldMapping()) {
                fieldValue = ((AbstractDirectMapping)mapping).getFieldValue(pkElementArray[index].getValue(key), (oracle.toplink.essentials.internal.sessions.AbstractSession)session);
            } else {
                fieldValue = pkElementArray[index].getValue(key);
            }
            pkVector.add(fieldValue);
View Full Code Here

        ObjectBuilder builder = getDescriptor().getObjectBuilder();
        KeyElementAccessor[] pkElementArray = this.getKeyClassFields(getPKClass());
               
        for (int index = 0; index < pkElementArray.length; index++) {
            KeyElementAccessor accessor = pkElementArray[index];
            DatabaseMapping mapping = builder.getMappingForAttributeName(accessor.getAttributeName());
            // With session validation, the mapping shouldn't be null at this
            // point, don't bother checking.
           
            while (mapping.isAggregateObjectMapping()) {
                mapping = mapping.getReferenceDescriptor().getObjectBuilder().getMappingForAttributeName(pkElementArray[index].getAttributeName());
           
                if (mapping == null) { // must be aggregate
                    mapping = builder.getMappingForField(accessor.getDatabaseField());
                }
            }
           
            Object fieldValue = mapping.getRealAttributeValueFromObject(key, (oracle.toplink.essentials.internal.sessions.AbstractSession) session);
            accessor.setValue(keyInstance, fieldValue);
        }
       
        return keyInstance;
    }
View Full Code Here

            KeyElementAccessor[] keyElements = this.getKeyClassFields(key.getClass());
            for (int index = 0; index < keyElements.length; ++index) {
                Object toWriteInto = bean;
                Object keyFieldValue = keyElements[index].getValue(key);
                DatabaseField field = keyElements[index].getDatabaseField();
                DatabaseMapping mapping = this.getDescriptor().getObjectBuilder().getMappingForAttributeName(keyElements[index].getAttributeName());
                if (mapping == null) {// must be aggregate
                    mapping = this.getDescriptor().getObjectBuilder().getMappingForField(field);
                }
                while (mapping.isAggregateObjectMapping()) {
                    Object aggregate = mapping.getRealAttributeValueFromObject(toWriteInto, session);
                    if (aggregate == null) {
                        aggregate = mapping.getReferenceDescriptor().getJavaClass().newInstance();
                        mapping.setRealAttributeValueInObject(toWriteInto, aggregate);
                    }
                    mapping = mapping.getReferenceDescriptor().getObjectBuilder().getMappingForAttributeName(keyElements[index].getAttributeName());
                    if (mapping == null) {// must be aggregate
                        mapping = this.getDescriptor().getObjectBuilder().getMappingForField(field);
                    }

                    //change the object to write into to the aggregate for the next stage of the
                    // loop or for when we exit the loop.
                    toWriteInto = aggregate;
                }
                mapping.setRealAttributeValueInObject(toWriteInto, keyFieldValue);
            }
            return bean;
        } catch (Exception e) {
            throw DescriptorException.errorUsingPrimaryKey(key, this.getDescriptor(), e);
        }
View Full Code Here

            }
            allMappings.add(descriptor.getObjectBuilder().getMappingForField(field));
           
            Exception elementIsFound = null; // use exception existence to detemine if element was found, so we can throw exception later
            for (int index = (allMappings.size() - 1); index >= 0; --index) { // start with the writable first
                DatabaseMapping mapping = (DatabaseMapping) allMappings.get(index);
               
                if (mapping.isForeignReferenceMapping()) {
                    // In EJB3 this should be a direct to field mapping (either
                    // on the entity directly or on an embeddable (aggregate).
                    continue;
                } else if (mapping.isAggregateMapping()) { // in the case of aggregates drill down.
                    ObjectBuilder builder = mapping.getReferenceDescriptor().getObjectBuilder();
                   
                    Vector aggregateMappings = builder.getReadOnlyMappingsForField(field);
                    if ((aggregateMappings != null) && (!aggregateMappings.isEmpty())) {
                        // Add all the mappings from the aggregate to be
                        // processed.
                        allMappings.addAll(aggregateMappings);
                    }
                                       
                    DatabaseMapping writableMapping = builder.getMappingForField(field);
                   
                    if (writableMapping != null) {
                        // Since it may be another aggregate mapping, add it to
                        // the allMappings list so we can drill down on it as
                        // well.
View Full Code Here

TOP

Related Classes of oracle.toplink.essentials.mappings.DatabaseMapping

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.