Search in sources :

Example 1 with ForeignFieldDesc

use of com.sun.jdo.spi.persistence.support.sqlstore.model.ForeignFieldDesc in project Payara by payara.

the class ResultDesc method setFields.

/**
 * Bind the columns from this ResultSet row to the persistent object described
 * by this ResultDesc. External queries always return only one type of objects
 * and don't have nested ResultDescs. Internal queries can have nested ResultDescs.
 * Run through all the fields of the field list and bind the values in
 * that order. Nested ResultDescs are processed by recursive calls.
 *
 * @param pm The PersistenceManager responsible for instantiating objects.
 * @param resultData JDBC ResultSet containing the data to be materialized.
 * @return
 *   Persistent object corresponding to values from ResultSet row, can be null.
 */
private Object setFields(PersistenceManager pm, ResultSet resultData) {
    Object pcObj = null;
    // Get the Statemanager corresponding to the current row
    SQLStateManager sm = (SQLStateManager) findOrCreateStateManager(resultData, pm);
    if (sm != null) {
        pcObj = sm.getPersistent();
        sm.getLock();
        try {
            // from streams corresponding to LONG columns on Oracle.
            for (int i = 0; i < fields.size(); i++) {
                Object temp = fields.get(i);
                if (temp instanceof ResultFieldDesc) {
                    ResultFieldDesc rfd = (ResultFieldDesc) temp;
                    LocalFieldDesc f = rfd.getFieldDesc();
                    if (!sm.getPresenceMaskBit(f.absoluteID)) {
                        Object value = getConvertedObject(resultData, rfd.getColumnRef(), f, sm);
                        if (debug) {
                            // NOI18N
                            logger.finest("sqlstore.resultdesc.marking_field", f.getName());
                        }
                        // Set the field value and presence mask bit.
                        setFieldValue(sm, f, value);
                    }
                } else {
                    ResultDesc frd = (ResultDesc) temp;
                    ForeignFieldDesc parentField = frd.parentField;
                    // it with the value from database might corrupt consistency of data.
                    if (!sm.getPresenceMaskBit(parentField.absoluteID) || parentField.cardinalityUPB > 1) {
                        Object fobj = frd.setFields(pm, resultData);
                        if (parentField.cardinalityUPB > 1) {
                            // parentField is a collection.
                            // Add the value and set the presence mask bit if necessary
                            addCollectionValue(sm, parentField, fobj);
                        } else {
                            // parentField is an object.
                            // Set the field value and presence mask bit.
                            setFieldValue(sm, parentField, fobj);
                        }
                    }
                    if (debug) {
                        // NOI18N
                        logger.finest(// NOI18N
                        "sqlstore.resultdesc.marking_foreign_field", parentField.getName());
                    }
                }
            }
            sm.initialize(true);
        } finally {
            // Always release the lock.
            sm.releaseLock();
        }
    } else {
    // sm can be null if we can not find or create a statemanager from the result data.
    // This is possible if we are projecting on a foreignfield and there is no
    // result returned.
    }
    return pcObj;
}
Also used : LocalFieldDesc(com.sun.jdo.spi.persistence.support.sqlstore.model.LocalFieldDesc) ForeignFieldDesc(com.sun.jdo.spi.persistence.support.sqlstore.model.ForeignFieldDesc)

Example 2 with ForeignFieldDesc

use of com.sun.jdo.spi.persistence.support.sqlstore.model.ForeignFieldDesc in project Payara by payara.

the class ResultDesc method applyDeferredUpdatesToPrefetchedCollections.

/**
 * Process deferred updates for the prefetched collection fields.
 * @param pc Instance from the query result.
 */
private void applyDeferredUpdatesToPrefetchedCollections(PersistenceCapable pc) {
    if (prefetchedCollectionFields != null) {
        StateManager sm = pc.jdoGetStateManager();
        Iterator prefetchedCollectionFieldsIter = prefetchedCollectionFields.keySet().iterator();
        while (prefetchedCollectionFieldsIter.hasNext()) {
            ForeignFieldDesc prefetchedCollectionField = (ForeignFieldDesc) prefetchedCollectionFieldsIter.next();
            ResultDesc prefetchedResultDesc = (ResultDesc) prefetchedCollectionFields.get(prefetchedCollectionField);
            // process deferred updates for prefetched collection relationships
            if (prefetchedCollectionField.cardinalityUPB > 1) {
                Collection relationshipValue = (Collection) prefetchedCollectionField.getValue(sm);
                if (relationshipValue instanceof SCOCollection && ((SCOCollection) relationshipValue).isDeferred()) {
                    ((SCOCollection) relationshipValue).applyDeferredUpdates(null);
                }
                // recursion into the next level
                for (Iterator iter = relationshipValue.iterator(); iter.hasNext(); ) {
                    PersistenceCapable persistenceCapable = (PersistenceCapable) iter.next();
                    prefetchedResultDesc.applyDeferredUpdatesToPrefetchedCollections(persistenceCapable);
                }
            }
        }
    }
}
Also used : ForeignFieldDesc(com.sun.jdo.spi.persistence.support.sqlstore.model.ForeignFieldDesc)

Aggregations

ForeignFieldDesc (com.sun.jdo.spi.persistence.support.sqlstore.model.ForeignFieldDesc)2 LocalFieldDesc (com.sun.jdo.spi.persistence.support.sqlstore.model.LocalFieldDesc)1