Search in sources :

Example 86 with DatabaseRecord

use of org.eclipse.persistence.sessions.DatabaseRecord in project eclipselink by eclipse-ee4j.

the class CacheInvalidator method invalidateObject.

// invalidates in tjhe cache the object corresponding to the massage
public void invalidateObject(Session session, javax.jms.Message msg) throws javax.jms.JMSException {
    String tableName = msg.getStringProperty("TABLE");
    if (tableName == null) {
        return;
    }
    Class<?> baseClass = (Class) tableNameToClass.get(tableName);
    if (baseClass == null) {
        return;
    }
    Vector pkFieldNames = (Vector) tableNameToPkFieldNames.get(tableName);
    if (pkFieldNames == null) {
        return;
    }
    // create DatabaseRecord corresponding to the message
    DatabaseRecord row = new DatabaseRecord(pkFieldNames.size());
    for (int i = 0; i < pkFieldNames.size(); i++) {
        String fieldName = (String) pkFieldNames.elementAt(i);
        Object value = msg.getObjectProperty(fieldName);
        row.put(fieldName, value);
    }
    // invalidate in TopLink cache the object corresponding to the row and the baseClass
    session.getIdentityMapAccessor().invalidateObject(row, baseClass);
}
Also used : DatabaseRecord(org.eclipse.persistence.sessions.DatabaseRecord)

Example 87 with DatabaseRecord

use of org.eclipse.persistence.sessions.DatabaseRecord in project eclipselink by eclipse-ee4j.

the class CascadeLockingPolicy method getMappedTranslationRow.

/**
 * INTERNAL:
 */
protected AbstractRecord getMappedTranslationRow(Object changedObj, UnitOfWorkImpl uow) {
    AbstractRecord translationRow = new DatabaseRecord();
    Iterator<Map.Entry<DatabaseField, DatabaseField>> it = m_mappedQueryKeyFields.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry<DatabaseField, DatabaseField> entry = it.next();
        Object value = m_descriptor.getObjectBuilder().extractValueFromObjectForField(changedObj, entry.getValue(), uow);
        translationRow.add(entry.getKey(), value);
    }
    return translationRow;
}
Also used : DatabaseRecord(org.eclipse.persistence.sessions.DatabaseRecord) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) AbstractRecord(org.eclipse.persistence.internal.sessions.AbstractRecord) HashMap(java.util.HashMap) Map(java.util.Map)

Example 88 with DatabaseRecord

use of org.eclipse.persistence.sessions.DatabaseRecord in project eclipselink by eclipse-ee4j.

the class CascadeLockingPolicy method getUnmappedTranslationRow.

/**
 * INTERNAL:
 */
protected AbstractRecord getUnmappedTranslationRow(Object changedObj, UnitOfWorkImpl uow) {
    AbstractRecord unmappedFieldsQueryTranslationRow = new DatabaseRecord();
    Iterator<DatabaseField> itPrimaryKey = m_descriptor.getPrimaryKeyFields().iterator();
    while (itPrimaryKey.hasNext()) {
        DatabaseField primaryKey = itPrimaryKey.next();
        Object value = m_descriptor.getObjectBuilder().extractValueFromObjectForField(changedObj, primaryKey, uow);
        unmappedFieldsQueryTranslationRow.add(primaryKey, value);
    }
    List result = (List) uow.executeQuery(m_unmappedFieldsQuery, unmappedFieldsQueryTranslationRow);
    if (result == null || result.isEmpty()) {
        // the object is not in the db
        return null;
    }
    AbstractRecord unmappedValues = (AbstractRecord) result.get(0);
    AbstractRecord translationRow = new DatabaseRecord();
    Iterator<Map.Entry<DatabaseField, DatabaseField>> it = m_unmappedQueryKeyFields.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry<DatabaseField, DatabaseField> entry = it.next();
        Object value = unmappedValues.get(entry.getValue());
        translationRow.add(entry.getKey(), value);
    }
    return translationRow;
}
Also used : DatabaseRecord(org.eclipse.persistence.sessions.DatabaseRecord) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) AbstractRecord(org.eclipse.persistence.internal.sessions.AbstractRecord) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 89 with DatabaseRecord

use of org.eclipse.persistence.sessions.DatabaseRecord in project eclipselink by eclipse-ee4j.

the class OneToOneMapping method buildShallowOriginalFromRow.

/**
 * INTERNAL:
 * Builds a shallow original object.  Only direct attributes and primary
 * keys are populated.  In this way the minimum original required for
 * instantiating a working copy clone can be built without placing it in
 * the shared cache (no concern over cycles).
 */
@Override
public void buildShallowOriginalFromRow(AbstractRecord databaseRow, Object original, JoinedAttributeManager joinManager, ObjectBuildingQuery query, AbstractSession executionSession) {
    // Now we are only building this original so we can extract the primary
    // key out of it.  If the primary key is stored across a 1-1 a value
    // holder needs to be built/triggered to get at it.
    // In this case recursively build the shallow original across the 1-1.
    // We only need the primary key for that object, and we know
    // what that primary key is: it is the foreign key in our row.
    ClassDescriptor descriptor = getReferenceDescriptor();
    AbstractRecord targetRow = new DatabaseRecord();
    for (Iterator<DatabaseField> keys = getSourceToTargetKeyFields().keySet().iterator(); keys.hasNext(); ) {
        DatabaseField foreignKey = keys.next();
        DatabaseField targetKey = getSourceToTargetKeyFields().get(foreignKey);
        targetRow.put(targetKey, databaseRow.get(foreignKey));
    }
    Object targetObject = descriptor.getObjectBuilder().buildNewInstance();
    descriptor.getObjectBuilder().buildAttributesIntoShallowObject(targetObject, targetRow, query);
    targetObject = getIndirectionPolicy().valueFromRow(targetObject);
    setAttributeValueInObject(original, targetObject);
}
Also used : ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) DatabaseRecord(org.eclipse.persistence.sessions.DatabaseRecord)

Example 90 with DatabaseRecord

use of org.eclipse.persistence.sessions.DatabaseRecord in project eclipselink by eclipse-ee4j.

the class AbstractTransformationMapping method buildPhantomRowFrom.

/**
 * INTERNAL
 * Build a phantom row that contains only the fields
 * for the mapping, populated with the values generated by
 * invoking the field methods on the specified object.
 */
protected AbstractRecord buildPhantomRowFrom(Object domainObject, AbstractSession session) {
    AbstractRecord row = new DatabaseRecord(this.fieldToTransformers.size());
    for (Object[] pair : this.fieldToTransformers) {
        DatabaseField field = (DatabaseField) pair[0];
        FieldTransformer transformer = (FieldTransformer) pair[1];
        Object fieldValue = this.invokeFieldTransformer(field, transformer, domainObject, session);
        row.put(field, fieldValue);
    }
    return row;
}
Also used : DatabaseRecord(org.eclipse.persistence.sessions.DatabaseRecord) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) MethodBasedFieldTransformer(org.eclipse.persistence.mappings.transformers.MethodBasedFieldTransformer) FieldTransformer(org.eclipse.persistence.mappings.transformers.FieldTransformer) AbstractRecord(org.eclipse.persistence.internal.sessions.AbstractRecord)

Aggregations

DatabaseRecord (org.eclipse.persistence.sessions.DatabaseRecord)110 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)44 AbstractRecord (org.eclipse.persistence.internal.sessions.AbstractRecord)43 Vector (java.util.Vector)31 ArrayList (java.util.ArrayList)17 NonSynchronizedVector (org.eclipse.persistence.internal.helper.NonSynchronizedVector)17 BigDecimal (java.math.BigDecimal)14 List (java.util.List)14 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)14 DatabaseSession (org.eclipse.persistence.sessions.DatabaseSession)14 Test (org.junit.Test)14 Expression (org.eclipse.persistence.expressions.Expression)12 AbstractSession (org.eclipse.persistence.internal.sessions.AbstractSession)12 HashMap (java.util.HashMap)11 Map (java.util.Map)10 EclipseLinkException (org.eclipse.persistence.exceptions.EclipseLinkException)7 ExpressionBuilder (org.eclipse.persistence.expressions.ExpressionBuilder)7 RelationalDescriptor (org.eclipse.persistence.descriptors.RelationalDescriptor)6 DescriptorException (org.eclipse.persistence.exceptions.DescriptorException)6 SQLUpdateStatement (org.eclipse.persistence.internal.expressions.SQLUpdateStatement)6