use of org.eclipse.persistence.queries.InsertObjectQuery in project eclipselink by eclipse-ee4j.
the class InsertWeakIdentityMapTest method test.
@Override
public void test() {
for (int index = 0; index < (identityMapSize * 2); index++) {
Employee obj = new Employee();
InsertObjectQuery query = new InsertObjectQuery(obj);
getAbstractSession().beginTransaction();
getSession().executeQuery(query);
getAbstractSession().rollbackTransaction();
System.gc();
}
System.gc();
}
use of org.eclipse.persistence.queries.InsertObjectQuery in project eclipselink by eclipse-ee4j.
the class AbstractSession method insertObject.
/**
* PUBLIC:
* Insert the object and all of its privately owned parts into the database.
* Insert should only be used if the application knows that the object is new,
* otherwise writeObject should be used.
* The insert operation can be customized through using an insert query.
*
* @exception DatabaseException if an error occurs on the database,
* these include constraint violations, security violations and general database errors.
*
* @see InsertObjectQuery
* @see #writeObject(Object)
*/
public Object insertObject(Object domainObject) throws DatabaseException {
InsertObjectQuery query = new InsertObjectQuery();
query.setObject(domainObject);
query.setIsExecutionClone(true);
return executeQuery(query);
}
use of org.eclipse.persistence.queries.InsertObjectQuery in project eclipselink by eclipse-ee4j.
the class CommitManager method commitChangedObjectsForClassWithChangeSet.
/**
* Commit changed of the objects of the class type in the change set.
* This allows for the order of the classes to be processed optimally.
*/
protected void commitChangedObjectsForClassWithChangeSet(UnitOfWorkChangeSet uowChangeSet, Class<?> theClass) {
Map<ObjectChangeSet, ObjectChangeSet> objectChangesList = uowChangeSet.getObjectChanges().get(theClass);
if (objectChangesList != null) {
// may be no changes for that class type.
ClassDescriptor descriptor = null;
AbstractSession session = getSession();
Collection<ObjectChangeSet> changes = objectChangesList.values();
CommitOrderType order = ((UnitOfWorkImpl) session).getCommitOrder();
if (order != CommitOrderType.NONE) {
changes = new ArrayList(objectChangesList.values());
if (order == CommitOrderType.CHANGES) {
Collections.sort((List) changes, new ObjectChangeSet.ObjectChangeSetComparator());
} else {
Collections.sort((List) changes);
}
}
for (ObjectChangeSet changeSetToWrite : changes) {
Object objectToWrite = changeSetToWrite.getUnitOfWorkClone();
if (descriptor == null) {
descriptor = session.getDescriptor(objectToWrite);
}
if (!isProcessedCommit(objectToWrite)) {
// Commit and resume on failure can cause a new change set to be in existing, so need to check here.
WriteObjectQuery commitQuery = null;
if (changeSetToWrite.isNew()) {
commitQuery = new InsertObjectQuery();
} else {
commitQuery = new UpdateObjectQuery();
}
commitQuery.setIsExecutionClone(true);
commitQuery.setDescriptor(descriptor);
commitQuery.setObjectChangeSet(changeSetToWrite);
commitQuery.setObject(objectToWrite);
commitQuery.cascadeOnlyDependentParts();
// removed checking session type to set cascade level
// will always be a unitOfWork so we need to cascade dependent parts
session.executeQuery(commitQuery);
}
}
}
}
use of org.eclipse.persistence.queries.InsertObjectQuery in project eclipselink by eclipse-ee4j.
the class AggregateCollectionMapping method objectAddedDuringUpdate.
/**
* INTERNAL:
* An object was added to the collection during an update, insert it if private.
*/
@Override
protected void objectAddedDuringUpdate(ObjectLevelModifyQuery query, Object objectAdded, ObjectChangeSet changeSet, Map extraData) throws DatabaseException, OptimisticLockException {
// Insert must not be done for uow or cascaded queries and we must cascade to cascade policy.
InsertObjectQuery insertQuery = getAndPrepareModifyQueryForInsert(query, objectAdded);
ContainerPolicy.copyMapDataToRow(extraData, insertQuery.getModifyRow());
if (this.listOrderField != null && extraData != null) {
insertQuery.getModifyRow().put(this.listOrderField, extraData.get(this.listOrderField));
}
query.getSession().executeQuery(insertQuery, insertQuery.getTranslationRow());
}
use of org.eclipse.persistence.queries.InsertObjectQuery in project eclipselink by eclipse-ee4j.
the class AggregateCollectionMapping method postInsert.
/**
* INTERNAL:
* Insert privately owned parts
*/
@Override
public void postInsert(WriteObjectQuery query) throws DatabaseException, OptimisticLockException {
if (isReadOnly()) {
return;
}
Object objects = getRealCollectionAttributeValueFromObject(query.getObject(), query.getSession());
int index = 0;
// insert each object one by one
ContainerPolicy cp = getContainerPolicy();
for (Object iter = cp.iteratorFor(objects); cp.hasNext(iter); ) {
Object wrappedObject = cp.nextEntry(iter, query.getSession());
Object object = cp.unwrapIteratorResult(wrappedObject);
InsertObjectQuery insertQuery = getAndPrepareModifyQueryForInsert(query, object);
ContainerPolicy.copyMapDataToRow(cp.getKeyMappingDataForWriteQuery(wrappedObject, query.getSession()), insertQuery.getModifyRow());
if (this.listOrderField != null) {
insertQuery.getModifyRow().add(this.listOrderField, index++);
}
query.getSession().executeQuery(insertQuery, insertQuery.getTranslationRow());
cp.propogatePostInsert(query, wrappedObject);
}
}
Aggregations