use of org.eclipse.persistence.sessions.DatabaseRecord in project eclipselink by eclipse-ee4j.
the class AdapterWithReturnObjectControl method getObjectForInsert.
@Override
public Object getObjectForInsert(Session session, Object objectToInsert) {
ClassDescriptor desc = session.getClassDescriptor(objectToInsert);
DataRecord rowToInsert = desc.getObjectBuilder().buildRow(objectToInsert, (AbstractSession) session, WriteType.INSERT);
DataRecord rowReturn = getRowForInsert(rowToInsert);
if (rowReturn != null && !rowReturn.isEmpty()) {
DataRecord row = new DatabaseRecord(rowToInsert.size());
row.putAll(rowToInsert);
row.putAll(rowReturn);
return readObjectFromRow(session, desc, row);
} else {
return objectToInsert;
}
}
use of org.eclipse.persistence.sessions.DatabaseRecord in project eclipselink by eclipse-ee4j.
the class TargetInvocationWhileInstantiatingMethodBasedProxyTest method setup.
@Override
protected void setup() throws NoSuchMethodException {
descriptor = new RelationalDescriptor();
descriptor.setJavaClass(TargetInvocationWhileInstantiatingMethodBasedProxyTest.class);
descriptor.addTableName("Dummy_Table");
row = new DatabaseRecord();
Class<?>[] parmClasses = { DatabaseRecord.class };
theMethod = TargetInvocationWhileInstantiatingMethodBasedProxyTest.class.getDeclaredMethod("invalidMethod", parmClasses);
theTransformer = new MethodBasedAttributeTransformer();
theTransformer.setAttributeTransformationMethod(theMethod);
theReceiver = new TargetInvocationWhileInstantiatingMethodBasedProxyTest();
valueHolder = new TransformerBasedValueHolder(theTransformer, theReceiver, row, (AbstractSession) getSession());
expectedException = DescriptorException.targetInvocationWhileInstantiatingMethodBasedProxy(new Exception());
}
use of org.eclipse.persistence.sessions.DatabaseRecord in project eclipselink by eclipse-ee4j.
the class TargetInvocationWhileInvokingAttributeMethodTest method setup.
@Override
protected void setup() {
descriptor = new RelationalDescriptor();
descriptor.setJavaClass(TargetInvocationWhileInvokingAttributeMethodTest.class);
descriptor.addTableName("EMPLOYEE");
mapping = new TransformationMapping();
mapping.setAttributeName("normalHours");
mapping.setAttributeTransformation("invalidMethod");
descriptor.addMapping(mapping);
mapping.initialize((AbstractSession) getSession());
row = new DatabaseRecord();
expectedException = DescriptorException.targetInvocationWhileInvokingAttributeMethod(mapping, new Exception());
}
use of org.eclipse.persistence.sessions.DatabaseRecord in project eclipselink by eclipse-ee4j.
the class TargetInvocationWhileInvokingRowExtractionMethodTest method setup.
@Override
protected void setup() throws NoSuchMethodException {
descriptor = new RelationalDescriptor();
descriptor.setJavaClass(TargetInvocationWhileInvokingRowExtractionMethodTest.class);
descriptor.addTableName("PROJECT");
descriptor.getInheritancePolicy().setParentClass(null);
descriptor.getInheritancePolicy().dontReadSubclassesOnQueries();
descriptor.getInheritancePolicy().setClassIndicatorFieldName("PROJECT.PROJ_TYPE");
descriptor.getInheritancePolicy().setShouldUseClassNameAsIndicator(true);
policy = descriptor.getInheritancePolicy();
policy.setClassExtractionMethodName("invalidMethod");
policy.preInitialize((AbstractSession) getSession());
row = new DatabaseRecord();
Class<?>[] parmClasses = { DataRecord.class };
expectedException = DescriptorException.targetInvocationWhileInvokingRowExtractionMethod(row, TargetInvocationWhileInvokingRowExtractionMethodTest.class.getDeclaredMethod("invalidMethod", parmClasses), descriptor, new Exception());
}
use of org.eclipse.persistence.sessions.DatabaseRecord in project eclipselink by eclipse-ee4j.
the class AggregateObjectMapping method readFromReturnRowIntoObject.
/**
* INTERNAL:
* Build an aggregate object from the specified return row and put it
* in the specified target object.
* Return row is merged into object after execution of insert or update call
* according to ReturningPolicy.
* If not null changeSet must correspond to targetObject. changeSet is updated with all of the field values in the row.
*/
public Object readFromReturnRowIntoObject(AbstractRecord row, Object targetObject, ReadObjectQuery query, Collection handledMappings, ObjectChangeSet changeSet) throws DatabaseException {
Object aggregate = getAttributeValueFromObject(targetObject);
ObjectChangeSet aggregateChangeSet = null;
if (aggregate == null) {
aggregate = readFromRowIntoObject(row, null, targetObject, null, query, query.getSession(), true);
} else {
if (changeSet != null && (!changeSet.isNew() || (query.getDescriptor() != null && query.getDescriptor().shouldUseFullChangeSetsForNewObjects()))) {
aggregateChangeSet = getReferenceDescriptor(aggregate, query.getSession()).getObjectBuilder().createObjectChangeSet(aggregate, (UnitOfWorkChangeSet) ((UnitOfWorkImpl) query.getSession()).getUnitOfWorkChangeSet(), true, query.getSession());
}
AbstractRecord aggregateRow = new DatabaseRecord();
int size = row.size();
List<DatabaseField> fields = row.getFields();
List values = row.getValues();
List<DatabaseField> aggregateFields = getReferenceFields();
for (int i = 0; i < size; i++) {
DatabaseField field = fields.get(i);
if (aggregateFields.contains(field)) {
aggregateRow.add(field, values.get(i));
}
}
getObjectBuilder(aggregate, query.getSession()).assignReturnRow(aggregate, query.getSession(), aggregateRow, aggregateChangeSet);
}
if (aggregate != null && isNullAllowed()) {
boolean allAttributesNull = true;
int nAggregateFields = this.fields.size();
for (int i = 0; (i < nAggregateFields) && allAttributesNull; i++) {
DatabaseField field = this.fields.elementAt(i);
if (row.containsKey(field)) {
allAttributesNull = row.get(field) == null;
} else {
Object fieldValue = valueFromObject(targetObject, field, query.getSession());
if (fieldValue == null) {
Object baseValue = getDescriptor().getObjectBuilder().getBaseValueForField(field, targetObject);
if (baseValue != null) {
DatabaseMapping baseMapping = getDescriptor().getObjectBuilder().getBaseMappingForField(field);
if (baseMapping.isForeignReferenceMapping()) {
ForeignReferenceMapping refMapping = (ForeignReferenceMapping) baseMapping;
if (refMapping.usesIndirection()) {
allAttributesNull = refMapping.getIndirectionPolicy().objectIsInstantiated(baseValue);
}
} else if (baseMapping.isTransformationMapping()) {
AbstractTransformationMapping transMapping = (AbstractTransformationMapping) baseMapping;
if (transMapping.usesIndirection()) {
allAttributesNull = transMapping.getIndirectionPolicy().objectIsInstantiated(baseValue);
}
}
}
} else {
allAttributesNull = false;
}
}
}
if (allAttributesNull) {
aggregate = null;
setAttributeValueInObject(targetObject, aggregate);
}
}
if (changeSet != null && (!changeSet.isNew() || (query.getDescriptor() != null && query.getDescriptor().shouldUseFullChangeSetsForNewObjects()))) {
AggregateChangeRecord record = (AggregateChangeRecord) changeSet.getChangesForAttributeNamed(getAttributeName());
if (aggregate == null) {
if (record != null) {
record.setChangedObject(null);
}
} else {
if (record == null) {
record = new AggregateChangeRecord(changeSet);
record.setAttribute(getAttributeName());
record.setMapping(this);
changeSet.addChange(record);
}
if (aggregateChangeSet == null) {
// the old aggregate value was null
aggregateChangeSet = getReferenceDescriptor(aggregate, query.getSession()).getObjectBuilder().createObjectChangeSet(aggregate, (UnitOfWorkChangeSet) ((UnitOfWorkImpl) query.getSession()).getUnitOfWorkChangeSet(), true, query.getSession());
}
record.setChangedObject(aggregateChangeSet);
}
}
if (handledMappings != null) {
handledMappings.add(this);
}
return aggregate;
}
Aggregations