Search in sources :

Example 6 with LocalFieldDesc

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

the class UpdateStatement method getInputValue.

/**
 * Gets input value corrsponding to given columnRef from given updateDesc
 * @param updateDesc updateDesc pointing to the input values
 * @param columnRef The columnRef. It always contains
 * the <code>LocalFieldDesc</code> for the field.
 * @param getBeforeValue If true, value returned is fetched from beforeImage
 * if false, the value returned is fetched from afterImage.
 * @return input value corrsponding to given columnRef from given updateDesc.
 */
private static Object getInputValue(UpdateObjectDescImpl updateDesc, ColumnRef columnRef, boolean getBeforeValue) {
    Object value;
    LocalFieldDesc field = (LocalFieldDesc) columnRef.getValue();
    if (field.isVersion()) {
        // Bind the value from the after image for version fields,
        // as they're incremented internally after each flush.
        // Version fields must not be modified from "outside".
        value = updateDesc.getAfterValue(field);
    } else {
        value = getBeforeValue ? updateDesc.getBeforeValue(field) : updateDesc.getAfterValue(field);
    }
    return value;
}
Also used : LocalFieldDesc(com.sun.jdo.spi.persistence.support.sqlstore.model.LocalFieldDesc)

Example 7 with LocalFieldDesc

use of com.sun.jdo.spi.persistence.support.sqlstore.model.LocalFieldDesc 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 8 with LocalFieldDesc

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

the class RetrieveDescImpl method addParameterConstraints.

/**
 * Add Constraints corresponding to given <code>fields</code>.
 * The constraints are added as Parameter Constraints.
 * index of the parameter starts at given <code>startIndex</code>
 * @param fields fields for which constraints are to be added.
 * @param startIndex starting Index for the parameter.
 */
public void addParameterConstraints(LocalFieldDesc[] fields, int startIndex) {
    for (int i = 0; i < fields.length; i++) {
        LocalFieldDesc field = fields[i];
        addParameterConstraint(field, i + startIndex);
    }
}
Also used : LocalFieldDesc(com.sun.jdo.spi.persistence.support.sqlstore.model.LocalFieldDesc) Constraint(com.sun.jdo.spi.persistence.support.sqlstore.sql.constraint.Constraint)

Example 9 with LocalFieldDesc

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

the class UpdateObjectDescImpl method setObjectInfo.

/**
 * We send the AfterImage for updates and inserts
 * but for updates it will only hold values for updated attributes (unless
 * the class is configured to send the whole AfterImage, also we'll let the
 * concurrency interface affect the sent AfterImage (and the sent
 * BeforeImage)).  For deletes the AfterImage will be NIL, for inserts the
 * BeforeImage will be NIL.  For deletes the BeforeImage will contain values
 * for all key attributes.  Also for deletes and updates we'll send the
 * HiddenValues array from the paladin (although we can set to NIL any
 * values in the array not needed by this particular update).
 *
 * UpdatedAttributes will contain indexes into the PersistentDesc.Attributes
 * array for new or updated values.
 *
 * Initially we'll probably just send the whole BeforeImage and AfterImage
 * (except that we won't have an AfterImage for Deletes and we won't have
 * a BeforeImage for updates).
 */
public void setObjectInfo(StateManager biStateManager, StateManager aiStateManager, int action) {
    this.beforeImage = (SQLStateManager) biStateManager;
    this.afterImage = (SQLStateManager) aiStateManager;
    ClassDesc config = (ClassDesc) afterImage.getPersistenceConfig();
    updateAction = action;
    this.afterHiddenValues = afterImage.hiddenValues;
    if (beforeImage != null) {
        this.beforeHiddenValues = beforeImage.hiddenValues;
    }
    // This pass through attributes we are only going to look at local attributes.
    // These are attributes that are stored in this object and are not references
    // to other persistent objects.
    boolean debug = logger.isLoggable(Logger.FINER);
    for (int i = 0; i < config.fields.size(); i++) {
        FieldDesc f = (FieldDesc) config.fields.get(i);
        LocalFieldDesc lf = null;
        boolean updated = false;
        if (f instanceof LocalFieldDesc) {
            lf = (LocalFieldDesc) f;
        } else {
            continue;
        }
        if ((updateAction == LOG_DESTROY) || ((lf.sqlProperties & FieldDesc.PROP_RECORD_ON_UPDATE) > 0)) {
            continue;
        } else if (lf.absoluteID < 0) {
            if ((beforeImage == null) || (beforeImage.getHiddenValue(lf.absoluteID) != afterImage.getHiddenValue(lf.absoluteID))) {
                updated = true;
            }
        } else if (lf.getType().isPrimitive() || String.class == lf.getType() || java.util.Date.class == lf.getType()) {
            Object afterVal = lf.getValue(afterImage);
            Object beforeVal = null;
            if (beforeImage != null) {
                beforeVal = lf.getValue(beforeImage);
            }
            if ((beforeVal != null) && (afterVal != null)) {
                if (!beforeVal.equals(afterVal)) {
                    updated = true;
                }
            } else {
                updated = true;
            }
        } else {
        // What else??
        }
        if (updated) {
            if (debug) {
                // NOI18N
                logger.finer("sqlstore.sql.updateobjdescimpl.updated", f.getName());
            }
            updatedFields.add(lf);
        }
    }
    if (concurrency != null) {
        concurrency.commit(this, beforeImage, afterImage, updateAction);
    }
}
Also used : LocalFieldDesc(com.sun.jdo.spi.persistence.support.sqlstore.model.LocalFieldDesc) ClassDesc(com.sun.jdo.spi.persistence.support.sqlstore.model.ClassDesc) FieldDesc(com.sun.jdo.spi.persistence.support.sqlstore.model.FieldDesc) LocalFieldDesc(com.sun.jdo.spi.persistence.support.sqlstore.model.LocalFieldDesc) ForeignFieldDesc(com.sun.jdo.spi.persistence.support.sqlstore.model.ForeignFieldDesc)

Example 10 with LocalFieldDesc

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

the class CorrelatedExistSelectPlan method processFields.

/**
 * There are no real fields to be selected for an (NOT)EXIST query.
 * This method just adds the table for the nested select.
 * The statement for nested select is created as a side effect.
 */
protected void processFields() {
    for (int i = 0; i < parentField.foreignFields.size(); i++) {
        LocalFieldDesc field = (LocalFieldDesc) parentField.foreignFields.get(i);
        addTable(field);
    }
}
Also used : LocalFieldDesc(com.sun.jdo.spi.persistence.support.sqlstore.model.LocalFieldDesc)

Aggregations

LocalFieldDesc (com.sun.jdo.spi.persistence.support.sqlstore.model.LocalFieldDesc)14 FieldDesc (com.sun.jdo.spi.persistence.support.sqlstore.model.FieldDesc)3 ArrayList (java.util.ArrayList)3 ColumnElement (org.netbeans.modules.dbschema.ColumnElement)3 JDOFatalInternalException (com.sun.jdo.api.persistence.support.JDOFatalInternalException)2 ForeignFieldDesc (com.sun.jdo.spi.persistence.support.sqlstore.model.ForeignFieldDesc)2 BitSet (java.util.BitSet)2 ClassDesc (com.sun.jdo.spi.persistence.support.sqlstore.model.ClassDesc)1 Constraint (com.sun.jdo.spi.persistence.support.sqlstore.sql.constraint.Constraint)1 ConstraintFieldDesc (com.sun.jdo.spi.persistence.support.sqlstore.sql.constraint.ConstraintFieldDesc)1