Search in sources :

Example 1 with FieldDesc

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

the class ConcurrencyCheckDirty method update.

public void update(UpdateQueryPlan plan) {
    boolean debug = logger.isLoggable();
    if (debug) {
        // NOI18N
        logger.fine("sqlstore.sql.concurrency.concurrencychkdirty", beforeImage);
    }
    if (beforeImage != null) {
        ArrayList fields = plan.getConfig().fields;
        BitSet verifyGroupMask = prepareVerifyGroupMask(plan);
        for (int i = 0; i < 2; i++) {
            if (i == 0) {
                fields = plan.getConfig().fields;
            } else if (i == 1) {
                fields = plan.getConfig().hiddenFields;
            }
            if (fields == null) {
                continue;
            }
            for (int j = 0; j < fields.size(); j++) {
                FieldDesc f = (FieldDesc) fields.get(j);
                if (f instanceof LocalFieldDesc) {
                    LocalFieldDesc lf = (LocalFieldDesc) f;
                    // RESOLVE: we need to fetch the fields that are not present.
                    if (((lf.sqlProperties & FieldDesc.PROP_IN_CONCURRENCY_CHECK) > 0) && ((lf.sqlProperties & FieldDesc.PROP_SECONDARY_TRACKED_FIELD) == 0) && beforeImage.getPresenceMaskBit(lf.absoluteID)) {
                        if (isFieldVerificationRequired(lf, verifyGroupMask)) {
                            Object val = null;
                            val = lf.getValue(this.beforeImage);
                            addConstraint(plan, lf, val);
                        }
                    }
                }
            }
        }
    }
    if (debug) {
        // NOI18N
        logger.fine("sqlstore.sql.concurrency.concurrencychkdirty.exit");
    }
}
Also used : LocalFieldDesc(com.sun.jdo.spi.persistence.support.sqlstore.model.LocalFieldDesc) ArrayList(java.util.ArrayList) BitSet(java.util.BitSet) FieldDesc(com.sun.jdo.spi.persistence.support.sqlstore.model.FieldDesc) LocalFieldDesc(com.sun.jdo.spi.persistence.support.sqlstore.model.LocalFieldDesc)

Example 2 with FieldDesc

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

the class ConcurrencyOptVerify method prepareVerifyGroupMask.

/**
 * Find all the local fields that have been updated
 * and use their concurrencyGroup to set the verifyGroupMask.
 */
protected BitSet prepareVerifyGroupMask(UpdateQueryPlan plan) {
    ArrayList fields;
    BitSet verifyGroupMask = new BitSet();
    int action = plan.getAction();
    for (int i = 0; i <= 1; i++) {
        if (i == 0) {
            fields = plan.getConfig().fields;
        } else {
            fields = plan.getConfig().hiddenFields;
        }
        if (fields == null) {
            continue;
        }
        for (int j = 0; j < fields.size(); j++) {
            FieldDesc f = (FieldDesc) fields.get(j);
            if ((f instanceof LocalFieldDesc) && (f.sqlProperties & FieldDesc.PROP_IN_CONCURRENCY_CHECK) > 0) {
                // the concurrency check.
                if (afterImage.getSetMaskBit(f.absoluteID) || ((action == QueryPlan.ACT_DELETE) && beforeImage.getPresenceMaskBit(f.absoluteID))) {
                    if (f.concurrencyGroup != -1) {
                        verifyGroupMask.set(f.concurrencyGroup);
                    }
                }
            }
        }
    }
    return verifyGroupMask;
}
Also used : LocalFieldDesc(com.sun.jdo.spi.persistence.support.sqlstore.model.LocalFieldDesc) ArrayList(java.util.ArrayList) BitSet(java.util.BitSet) FieldDesc(com.sun.jdo.spi.persistence.support.sqlstore.model.FieldDesc) LocalFieldDesc(com.sun.jdo.spi.persistence.support.sqlstore.model.LocalFieldDesc)

Example 3 with FieldDesc

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

the class ResultDesc method findOrCreateStateManager.

/**
 * Returns a StateManager which PC instance to be populated with the values.
 * If such instance exists in this PersistenceManager cache,
 * it is returned, otherwise a new instance is created.
 */
private StateManager findOrCreateStateManager(ResultSet resultData, PersistenceManager pm) {
    try {
        Class oidClass = config.getOidClass();
        Object oid = oidClass.newInstance();
        // Copy key field values
        Field[] keyFields = config.getKeyFields();
        String[] keyNames = config.getKeyFieldNames();
        for (int i = 0; i < keyFields.length; i++) {
            Field keyField = keyFields[i];
            String keyName = keyNames[i];
            FieldDesc fd = config.getField(keyName);
            int index = fieldNames.indexOf(keyName);
            ResultFieldDesc rfd = (ResultFieldDesc) fields.get(index);
            Object v = getConvertedObject(resultData, rfd.getColumnRef(), fd, null);
            if (debug) {
                // NOI18N
                logger.finest("sqlstore.resultdesc.marking_key_field", keyName);
            }
            if (v == null) {
                return null;
            }
            keyField.set(oid, v);
        }
        return pm.findOrCreateStateManager(oid, config.getPersistenceCapableClass());
    } catch (Exception e) {
        // RESOLVE...
        throw new JDOFatalInternalException(e.getMessage());
    }
}
Also used : Field(java.lang.reflect.Field) JDOFatalInternalException(com.sun.jdo.api.persistence.support.JDOFatalInternalException) SQLException(java.sql.SQLException) JDOFatalInternalException(com.sun.jdo.api.persistence.support.JDOFatalInternalException) LocalFieldDesc(com.sun.jdo.spi.persistence.support.sqlstore.model.LocalFieldDesc) ForeignFieldDesc(com.sun.jdo.spi.persistence.support.sqlstore.model.ForeignFieldDesc) FieldDesc(com.sun.jdo.spi.persistence.support.sqlstore.model.FieldDesc)

Example 4 with FieldDesc

use of com.sun.jdo.spi.persistence.support.sqlstore.model.FieldDesc 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)

Aggregations

FieldDesc (com.sun.jdo.spi.persistence.support.sqlstore.model.FieldDesc)4 LocalFieldDesc (com.sun.jdo.spi.persistence.support.sqlstore.model.LocalFieldDesc)4 ForeignFieldDesc (com.sun.jdo.spi.persistence.support.sqlstore.model.ForeignFieldDesc)2 ArrayList (java.util.ArrayList)2 BitSet (java.util.BitSet)2 JDOFatalInternalException (com.sun.jdo.api.persistence.support.JDOFatalInternalException)1 ClassDesc (com.sun.jdo.spi.persistence.support.sqlstore.model.ClassDesc)1 Field (java.lang.reflect.Field)1 SQLException (java.sql.SQLException)1