use of org.eclipse.persistence.sessions.DatabaseRecord in project eclipselink by eclipse-ee4j.
the class UnitOfWorkImpl method commitToDatabase.
/**
* INTERNAL:
* CommitChanges To The Database from a calculated changeSet
* @param commitTransaction false if called by writeChanges as intent is
* not to finalize the transaction.
*/
protected void commitToDatabase(boolean commitTransaction) {
try {
// CR4202 - ported from 3.6.4
if (wasTransactionBegunPrematurely()) {
// beginTransaction() has been already called
setWasTransactionBegunPrematurely(false);
} else {
beginTransaction();
}
if (commitTransaction) {
setWasNonObjectLevelModifyQueryExecuted(false);
}
this.preDeleteComplete = false;
// PERF: Avoid deletion if nothing to delete.
List deletedObjects = null;
if (hasDeletedObjects()) {
deletedObjects = new ArrayList(this.deletedObjects.size());
for (Object objectToDelete : this.deletedObjects.keySet()) {
ClassDescriptor descriptor = getDescriptor(objectToDelete);
if (descriptor.hasPreDeleteMappings()) {
for (DatabaseMapping mapping : descriptor.getPreDeleteMappings()) {
DeleteObjectQuery deleteQuery = descriptor.getQueryManager().getDeleteQuery();
if (deleteQuery == null) {
deleteQuery = new DeleteObjectQuery();
deleteQuery.setDescriptor(descriptor);
} else {
// Ensure original query has been prepared.
deleteQuery.checkPrepare(this, deleteQuery.getTranslationRow());
deleteQuery = (DeleteObjectQuery) deleteQuery.clone();
}
deleteQuery.setIsExecutionClone(true);
deleteQuery.setTranslationRow(new DatabaseRecord());
deleteQuery.setObject(objectToDelete);
deleteQuery.setSession(this);
mapping.earlyPreDelete(deleteQuery, objectToDelete);
}
}
deletedObjects.add(objectToDelete);
}
this.preDeleteComplete = true;
}
if (this.shouldPerformDeletesFirst) {
if (deletedObjects != null) {
// This must go to the commit manager because uow overrides to do normal deletion.
getCommitManager().deleteAllObjects(deletedObjects);
// Clear change sets of the deleted object to avoid redundant updates.
for (Iterator objects = getObjectsDeletedDuringCommit().keySet().iterator(); objects.hasNext(); ) {
org.eclipse.persistence.internal.sessions.ObjectChangeSet objectChangeSet = (org.eclipse.persistence.internal.sessions.ObjectChangeSet) this.unitOfWorkChangeSet.getObjectChangeSetForClone(objects.next());
if (objectChangeSet != null) {
objectChangeSet.clear(true);
}
}
}
// Let the commit manager figure out how to write the objects
super.writeAllObjectsWithChangeSet(this.unitOfWorkChangeSet);
// Issue all the SQL for the ModifyAllQuery's, don't touch the cache though
issueModifyAllQueryList();
} else {
// Let the commit manager figure out how to write the objects
super.writeAllObjectsWithChangeSet(this.unitOfWorkChangeSet);
if (deletedObjects != null) {
// This must go to the commit manager because uow overrides to do normal deletion.
getCommitManager().deleteAllObjects(deletedObjects);
}
// Issue all the SQL for the ModifyAllQuery's, don't touch the cache though
issueModifyAllQueryList();
}
// Issue prepare event.
if (this.eventManager != null) {
this.eventManager.prepareUnitOfWork();
}
// do not lock objects unless we are at the commit stage
if (commitTransaction) {
try {
acquireWriteLocks();
commitTransaction();
} catch (RuntimeException throwable) {
releaseWriteLocks();
throw throwable;
} catch (Error throwable) {
releaseWriteLocks();
throw throwable;
}
} else {
setWasTransactionBegunPrematurely(true);
// must let the UnitOfWork know that the transaction was begun
// before the commit process.
}
} catch (RuntimeException exception) {
// The number of SQL statements been prepared need be stored into UOW
// before any exception being thrown.
copyStatementsCountIntoProperties();
try {
rollbackTransaction(commitTransaction);
} catch (RuntimeException ignore) {
// Ignore
}
if (hasExceptionHandler()) {
getExceptionHandler().handleException(exception);
} else {
throw exception;
}
}
}
use of org.eclipse.persistence.sessions.DatabaseRecord in project eclipselink by eclipse-ee4j.
the class IllegalArgumentWhileInvokingAttributeMethodTest method setup.
@Override
protected void setup() {
descriptor = new RelationalDescriptor();
descriptor.setJavaClass(IllegalArgumentWhileInvokingAttributeMethodTest.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.illegalArgumentWhileInvokingAttributeMethod(mapping, new Exception());
}
use of org.eclipse.persistence.sessions.DatabaseRecord in project eclipselink by eclipse-ee4j.
the class IndirectSetTest method setUp.
/**
* set up the test fixture:
*/
@Before
public void setUp() {
list = setUpList();
Object temp = new HashSet<>(list);
ValueHolderInterface vh = new QueryBasedValueHolder(new ReadAllQuery(), new DatabaseRecord(), new TestSession(temp));
if (cls == null) {
testList = IndirectCollectionsFactory.createIndirectSet();
} else {
try {
testList = cls.getConstructor().newInstance();
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}
}
testList.setValueHolder(vh);
if (useListener) {
testListLsn = new Listener();
testList._persistence_setPropertyChangeListener(testListLsn);
}
}
use of org.eclipse.persistence.sessions.DatabaseRecord in project eclipselink by eclipse-ee4j.
the class IndexedInteraction method buildRow.
/**
* Build a database row from the record returned from the interaction.
* Also handles MappedRecords for case of input being indexed but mapped ouput.
*/
@Override
public AbstractRecord buildRow(jakarta.resource.cci.Record record, EISAccessor accessor) {
AbstractRecord row = null;
if (record instanceof IndexedRecord) {
IndexedRecord indexedRecord = (IndexedRecord) record;
row = new DatabaseRecord(indexedRecord.size());
for (int index = 0; index < indexedRecord.size(); index++) {
DatabaseField field = getOutputArguments().get(index);
row.put(field, indexedRecord.get(index));
}
} else if (record instanceof MappedRecord) {
MappedRecord mappedRecord = (MappedRecord) record;
// Handle the case of a single output argument of the entire row contained within the return record.
if (getOutputArgumentNames().size() == 1) {
mappedRecord = (MappedRecord) mappedRecord.get(getOutputArgumentNames().get(0));
// Handle the case were the output row is mapped into a database row of values.
} else if (getOutputArgumentNames().size() > 1) {
row = new DatabaseRecord(getOutputArgumentNames().size());
for (int index = 0; index < getOutputArgumentNames().size(); index++) {
DatabaseField field = getOutputArguments().get(index);
row.put(field, mappedRecord.get(getOutputArgumentNames().get(index)));
}
return row;
}
// Wrapped the record in a database to avoid loosing any information in conversion to database row,
// also gets around problem of some adatpers not supporting keySet or entrySet.
row = new EISMappedRecord(mappedRecord, accessor);
} else {
row = new DatabaseRecord(1);
row.put(getOutputResultPath(), record);
}
return row;
}
use of org.eclipse.persistence.sessions.DatabaseRecord in project eclipselink by eclipse-ee4j.
the class StoredProcedureVARRAYParametersTest 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");
}
// check that a Struct was returned for address
Object addressOut = ((DatabaseRecord) results2.get(0)).get("address");
if ((addressOut == null) || (!(addressOut instanceof Struct))) {
throw new TestErrorException("Address returned by SProc_Read_PHolders was null or not a Struct :" + addressOut);
}
// This is an Address instance instead of struct since it picks up the address class from the value passed in.
Address addressInOut = ((Address) ((DatabaseRecord) results3.get(0)).get("address"));
if ((addressInOut == null) || !originalAddress.getStreet().equals(addressInOut.getStreet())) {
throw new TestErrorException("Address in did not equal the address returned out by SProc_Delete_PHolders " + addressInOut);
}
Vector childrenRead = ((Vector) ((DatabaseRecord) results2.get(0)).get("childrenNames"));
if ((childrenNames.size() != childrenRead.size()) && (!childrenNames.get(0).equals(childrenRead.get(0)))) {
throw new TestErrorException("First Child's Name did not match what was returned out by SProc_Read_PHolders");
}
childrenRead = ((Vector) ((DatabaseRecord) results3.get(0)).get("childrenNames"));
if ((childrenNames.size() != childrenRead.size()) && (!childrenNames.get(0).equals(childrenRead.get(0)))) {
throw new TestErrorException("First Child's Name did not match what was returned out by SProc_Delete_PHolders");
}
Vector phonesRead = ((Vector) ((DatabaseRecord) results2.get(0)).get("phones"));
if ((phoneNumbers.size() != phonesRead.size()) && (!phoneNumbers.get(0).equals(childrenRead.get(0)))) {
throw new TestErrorException("First phone did not match what was returned out by SProc_Read_PHolders");
}
phonesRead = ((Vector) ((DatabaseRecord) results3.get(0)).get("phones"));
if ((phoneNumbers.size() != phonesRead.size()) && (!phoneNumbers.get(0).equals(phonesRead.get(0)))) {
throw new TestErrorException("First phone did not match what was returned out by SProc_Delete_PHolders");
}
}
Aggregations