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");
}
}
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);
}
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));
}
}
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;
}
}
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);
}
}
}
}
Aggregations