Search in sources :

Example 1 with InsertObjectQuery

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();
}
Also used : Employee(org.eclipse.persistence.testing.models.employee.domain.Employee) InsertObjectQuery(org.eclipse.persistence.queries.InsertObjectQuery)

Example 2 with InsertObjectQuery

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);
}
Also used : InsertObjectQuery(org.eclipse.persistence.queries.InsertObjectQuery)

Example 3 with InsertObjectQuery

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);
            }
        }
    }
}
Also used : ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) CommitOrderType(org.eclipse.persistence.sessions.UnitOfWork.CommitOrderType) ArrayList(java.util.ArrayList) UpdateObjectQuery(org.eclipse.persistence.queries.UpdateObjectQuery) WriteObjectQuery(org.eclipse.persistence.queries.WriteObjectQuery) InsertObjectQuery(org.eclipse.persistence.queries.InsertObjectQuery)

Example 4 with InsertObjectQuery

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());
}
Also used : InsertObjectQuery(org.eclipse.persistence.queries.InsertObjectQuery)

Example 5 with InsertObjectQuery

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);
    }
}
Also used : ContainerPolicy(org.eclipse.persistence.internal.queries.ContainerPolicy) InsertObjectQuery(org.eclipse.persistence.queries.InsertObjectQuery)

Aggregations

InsertObjectQuery (org.eclipse.persistence.queries.InsertObjectQuery)27 ContainerPolicy (org.eclipse.persistence.internal.queries.ContainerPolicy)7 WriteObjectQuery (org.eclipse.persistence.queries.WriteObjectQuery)7 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)5 AbstractSession (org.eclipse.persistence.internal.sessions.AbstractSession)4 UnitOfWorkChangeSet (org.eclipse.persistence.internal.sessions.UnitOfWorkChangeSet)4 ArrayList (java.util.ArrayList)3 AbstractRecord (org.eclipse.persistence.internal.sessions.AbstractRecord)3 ObjectChangeSet (org.eclipse.persistence.internal.sessions.ObjectChangeSet)3 DatabaseRecord (org.eclipse.persistence.sessions.DatabaseRecord)3 Employee (org.eclipse.persistence.testing.models.employee.domain.Employee)3 EISDescriptor (org.eclipse.persistence.eis.EISDescriptor)2 XMLInteraction (org.eclipse.persistence.eis.interactions.XMLInteraction)2 XQueryInteraction (org.eclipse.persistence.eis.interactions.XQueryInteraction)2 EISDirectMapping (org.eclipse.persistence.eis.mappings.EISDirectMapping)2 EISOneToOneMapping (org.eclipse.persistence.eis.mappings.EISOneToOneMapping)2 UnitOfWorkImpl (org.eclipse.persistence.internal.sessions.UnitOfWorkImpl)2 Address (org.eclipse.persistence.testing.models.order.Address)2 LineItem (org.eclipse.persistence.testing.models.order.LineItem)2 Order (org.eclipse.persistence.testing.models.order.Order)2