Search in sources :

Example 61 with DatabaseRecord

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

the class StoredProcedureObjectRelationalParameters method verify.

@Override
public void verify() {
    if ((results2.size() != 1) && (results3.size() != 1)) {
        throw new TestErrorException("Collections returned did not contain expected number of results");
    }
    Address addressRead = ((Address) ((DatabaseRecord) results2.get(0)).get("address"));
    if (!originalAddress.getStreet().equals(addressRead.getStreet())) {
        throw new TestErrorException("Address in did not equal the address returned out by SProc_Read_PHolders");
    }
    Address addressRemoved = ((Address) ((DatabaseRecord) results3.get(0)).get("address"));
    if (!originalAddress.getStreet().equals(addressRemoved.getStreet())) {
        throw new TestErrorException("Address in did not equal the address returned out by SProc_Delete_PHolders");
    }
}
Also used : Address(org.eclipse.persistence.testing.models.insurance.Address) DatabaseRecord(org.eclipse.persistence.sessions.DatabaseRecord)

Example 62 with DatabaseRecord

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

the class VariableOneToOneMappingIsNotDefinedProperlyTest method setup.

@Override
protected void setup() {
    descriptor = getSession().getDescriptor(Actor.class);
    mapping = (VariableOneToOneMapping) descriptor.getMappingForAttributeName("program");
    sourceField = new DatabaseField("ACTOR.PROGRAM_ID");
    targetQueryKeyName = (String) mapping.getSourceToTargetQueryKeyNames().get(sourceField);
    mapping.addForeignQueryKeyName("ACTOR.PROGRAM_ID", "name2");
    mapping.getForeignKeyFields().removeElement(sourceField);
    actor = Actor.example4();
    databaseRow = new DatabaseRecord();
    if (testMode == 0) {
    // nothing extra needed
    } else if (testMode == 1) {
        ObjectChangeSet changeSet = new ObjectChangeSet(new Vector(), descriptor, actor, new UnitOfWorkChangeSet(), true);
        changeRecord = new ObjectReferenceChangeRecord(changeSet);
        changeRecord.setNewValue(changeSet);
    } else if (testMode == 2) {
        deleteObjectQuery = new DeleteObjectQuery(actor);
        deleteObjectQuery.setSession((AbstractSession) getSession());
    }
    expectedException = DescriptorException.variableOneToOneMappingIsNotDefinedProperly(mapping, descriptor, targetQueryKeyName);
}
Also used : ObjectReferenceChangeRecord(org.eclipse.persistence.internal.sessions.ObjectReferenceChangeRecord) DatabaseRecord(org.eclipse.persistence.sessions.DatabaseRecord) Actor(org.eclipse.persistence.testing.models.interfaces.Actor) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) UnitOfWorkChangeSet(org.eclipse.persistence.internal.sessions.UnitOfWorkChangeSet) ObjectChangeSet(org.eclipse.persistence.internal.sessions.ObjectChangeSet) DeleteObjectQuery(org.eclipse.persistence.queries.DeleteObjectQuery) Vector(java.util.Vector)

Example 63 with DatabaseRecord

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

the class ClassDescriptor method initialize.

/**
 * INTERNAL:
 * Initialize the query manager specific to the descriptor type.
 */
public void initialize(DescriptorQueryManager queryManager, AbstractSession session) {
    // PERF: set read-object query to cache generated SQL.
    if (!queryManager.hasReadObjectQuery()) {
        // Prepare static read object query always.
        ReadObjectQuery readObjectQuery = new ReadObjectQuery();
        readObjectQuery.setSelectionCriteria(getObjectBuilder().getPrimaryKeyExpression());
        queryManager.setReadObjectQuery(readObjectQuery);
    }
    queryManager.getReadObjectQuery().setName("read" + getJavaClass().getSimpleName());
    if (!queryManager.hasInsertQuery()) {
        // Prepare insert query always.
        queryManager.setInsertQuery(new InsertObjectQuery());
    }
    queryManager.getInsertQuery().setModifyRow(getObjectBuilder().buildTemplateInsertRow(session));
    if (!usesFieldLocking()) {
        // do not reset the query if we are using field locking
        if (!queryManager.hasDeleteQuery()) {
            // Prepare delete query always.
            queryManager.setDeleteQuery(new DeleteObjectQuery());
        }
        queryManager.getDeleteQuery().setModifyRow(new DatabaseRecord());
    }
    if (queryManager.hasUpdateQuery()) {
        // Do not prepare to update by default to allow minimal update.
        queryManager.getUpdateQuery().setModifyRow(getObjectBuilder().buildTemplateUpdateRow(session));
    }
}
Also used : ReadObjectQuery(org.eclipse.persistence.queries.ReadObjectQuery) DatabaseRecord(org.eclipse.persistence.sessions.DatabaseRecord) DeleteObjectQuery(org.eclipse.persistence.queries.DeleteObjectQuery) InsertObjectQuery(org.eclipse.persistence.queries.InsertObjectQuery)

Example 64 with DatabaseRecord

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

the class AdapterWithReturnObjectControl method getObjectForUpdate.

@Override
public Object getObjectForUpdate(Session session, Object objectToUpdateBeforeChange, Object objectToUpdateAfterChange, boolean useUOW) {
    ClassDescriptor desc = session.getClassDescriptor(objectToUpdateBeforeChange);
    DataRecord rowBeforeChange = desc.getObjectBuilder().buildRow(objectToUpdateBeforeChange, (AbstractSession) session, WriteType.UPDATE);
    DataRecord rowAfterChange = desc.getObjectBuilder().buildRow(objectToUpdateAfterChange, (AbstractSession) session, WriteType.UPDATE);
    DataRecord rowChange = new DatabaseRecord();
    getChange(rowChange, session, objectToUpdateBeforeChange, objectToUpdateAfterChange, desc, useUOW, WriteType.UPDATE);
    DataRecord rowReturn = getRowForUpdate(rowChange);
    if (rowReturn != null && !rowReturn.isEmpty()) {
        DataRecord row = new DatabaseRecord(rowAfterChange.size());
        row.putAll(rowAfterChange);
        row.putAll(rowReturn);
        return readObjectFromRow(session, desc, row);
    } else {
        return objectToUpdateAfterChange;
    }
}
Also used : ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) DatabaseRecord(org.eclipse.persistence.sessions.DatabaseRecord)

Example 65 with DatabaseRecord

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

the class AdapterWithReturnObjectControl method getChange.

public void getChange(DataRecord row, DatabaseMapping mapping, Session session, Object object1, Object object2, boolean useUOW, WriteType writeType) {
    if (mapping.isAggregateObjectMapping()) {
        Object aggregate1 = mapping.getAttributeValueFromObject(object1);
        Object aggregate2 = mapping.getAttributeValueFromObject(object2);
        if (aggregate1 == null && aggregate2 == null) {
            if (!useUOW) {
                mapping.writeFromObjectIntoRow(object2, (DatabaseRecord) row, (AbstractSession) session, writeType);
            }
        } else if (aggregate1 != null && aggregate2 != null && aggregate1.getClass().equals(aggregate2.getClass())) {
            ClassDescriptor desc = mapping.getReferenceDescriptor();
            getChange(row, session, aggregate1, aggregate2, desc, useUOW, writeType);
        } else {
            mapping.writeFromObjectIntoRow(object2, (DatabaseRecord) row, (AbstractSession) session, writeType);
        }
    } else {
        DatabaseRecord row1 = new DatabaseRecord();
        DatabaseRecord row2 = new DatabaseRecord();
        mapping.writeFromObjectIntoRow(object1, row1, (AbstractSession) session, writeType);
        mapping.writeFromObjectIntoRow(object2, row2, (AbstractSession) session, writeType);
        for (int i = 0; i < row1.size(); i++) {
            DatabaseField field = row1.getFields().elementAt(i);
            Object valueBefore = row1.getValues().elementAt(i);
            Object valueAfter = row2.get(field);
            boolean changed;
            if (valueAfter == null) {
                changed = valueBefore != null;
            } else {
                changed = !valueAfter.equals(valueBefore);
            }
            if (changed) {
                row.put(field, valueAfter);
            }
        }
    }
}
Also used : ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) DatabaseRecord(org.eclipse.persistence.sessions.DatabaseRecord) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) AbstractSession(org.eclipse.persistence.internal.sessions.AbstractSession)

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