Package oracle.toplink.essentials.descriptors

Examples of oracle.toplink.essentials.descriptors.DescriptorQueryManager


            // For bug 2612185 specify the identity hashtable to be used in cloning so
            // it is not thrown away at the end of cloning.
            expression = expression.copiedVersionFrom(clonedExpressions);
        }

        DescriptorQueryManager queryManager = getDescriptor().getQueryManager();

       
        // Leaf inheritence and multiple table join.
        if (queryManager.getAdditionalJoinExpression() != null) {
            // CR#3701077, additional join not required for view, view does join.
            if (! (getDescriptor().hasInheritance() && (getDescriptor().getInheritancePolicy().hasView()))) {
                Expression additionalJoin = (Expression)queryManager.getAdditionalJoinExpression();
   
                // If there's an expression, then we know we'll have to rebuild anyway, so don't clone.
                if (expression == null) {
                    // Should never happen...
                    expression = (Expression)additionalJoin.clone();
View Full Code Here


     * Delete an object from the database.
     */
    public void deleteObjectForWrite() {
        WriteObjectQuery writeQuery = getWriteObjectQuery();
        Object object = writeQuery.getObject();
        DescriptorQueryManager queryManager = getDescriptor().getQueryManager();

        // check for user-defined query
        if ((!writeQuery.isUserDefined())// this is not a user-defined query
                 &&queryManager.hasDeleteQuery()// there is a user-defined query
                 &&isExpressionQueryMechanism()) {// this is not a hand-coded call (custom SQL etc.)
            performUserDefinedDelete();
            return;
        }

        CommitManager commitManager = getSession().getCommitManager();

        // This must be done after the custom query check, otherwise it will be done twice.
        commitManager.markPreModifyCommitInProgress(object);

        if (writeQuery.getObjectChangeSet() == null) {
            // PERF: Avoid events if no listeners.
            if (getDescriptor().getEventManager().hasAnyEventListeners()) {
                // only throw the events if there is no changeset otherwise the event will be thrown twice
                // once by the calculate changes code and here
                getDescriptor().getEventManager().executeEvent(new DescriptorEvent(DescriptorEventManager.PreDeleteEvent, writeQuery));
            }
        }

        // check whether deep shallow modify is turned on
        if (writeQuery.shouldCascadeParts()) {
            queryManager.preDelete(writeQuery);
        }

        // In a unit of work/writeObjects the preDelete may cause a shallow update of this object,
        // in this case the following second write must do the real delete.
        if (!commitManager.isShallowCommitted(object) && !writeQuery.shouldCascadeParts()) {
            updateForeignKeyFieldBeforeDelete();
        } else {
            // CR#2660080 missing aboutToDelete event.   
            // PERF: Avoid events if no listeners.
            if (getDescriptor().getEventManager().hasAnyEventListeners()) {
                DescriptorEvent event = new DescriptorEvent(DescriptorEventManager.AboutToDeleteEvent, writeQuery);
                event.setRecord(getModifyRow());
                getDescriptor().getEventManager().executeEvent(event);
            }

            int rowCount = deleteObject().intValue();
           
            if (rowCount < 1) {
                getSession().getEventManager().noRowsModified(writeQuery, object);
            }

            if (getDescriptor().usesOptimisticLocking()) {
                getDescriptor().getOptimisticLockingPolicy().validateDelete(rowCount, object, writeQuery);
            }
               
            // remember that the object was deleted
            addObjectDeletedDuringCommit();
        }

        commitManager.markPostModifyCommitInProgress(object);
       
        // Verify if deep shallow modify is turned on.
        if (writeQuery.shouldCascadeParts()) {
            queryManager.postDelete(writeQuery);
        }

        // PERF: Avoid events if no listeners.
        if (getDescriptor().getEventManager().hasAnyEventListeners()) {
            getDescriptor().getEventManager().executeEvent(new DescriptorEvent(DescriptorEventManager.PostDeleteEvent, writeQuery));
View Full Code Here

     * Insert an object in the database.
     */
    public void insertObjectForWrite() {
        WriteObjectQuery writeQuery = getWriteObjectQuery();
        Object object = writeQuery.getObject();
        DescriptorQueryManager queryManager = getDescriptor().getQueryManager();

        // check for user-defined query
        if ((!writeQuery.isUserDefined())// this is not a user-defined query
                 &&queryManager.hasInsertQuery()// there is a user-defined query
                 &&isExpressionQueryMechanism()) {// this is not a hand-coded call (custom SQL etc.)
            performUserDefinedInsert();
            return;
        }

        CommitManager commitManager = getSession().getCommitManager();

        // This must be done after the custom query check, otherwise it will be done twice.
        commitManager.markPreModifyCommitInProgress(object);

        if (writeQuery.getObjectChangeSet() == null) {
            // PERF: Avoid events if no listeners.
            if (getDescriptor().getEventManager().hasAnyEventListeners()) {
                // only throw the events if there is no changeset otherwise the event will be thrown twice
                // once by the calculate changes code and here
                getDescriptor().getEventManager().executeEvent(new DescriptorEvent(DescriptorEventManager.PreInsertEvent, writeQuery));
            }
        }

        // check whether deep shallow modify is turned on
        if (writeQuery.shouldCascadeParts()) {
            queryManager.preInsert(writeQuery);
        }

        // In a unit of work/writeObjects the preInsert may have caused a shallow insert of this object,
        // in this case this second write must do an update.
        if (commitManager.isShallowCommitted(object)) {
            updateForeignKeyFieldAfterInsert();
        } else {
            AbstractRecord modifyRow = writeQuery.getModifyRow();
            if (modifyRow == null) {// Maybe have been passed in as in aggregate collection.
                if (writeQuery.shouldCascadeParts()) {
                    writeQuery.setModifyRow(getDescriptor().getObjectBuilder().buildRow(object, getSession()));
                } else {
                    writeQuery.setModifyRow(getDescriptor().getObjectBuilder().buildRowForShallowInsert(object, getSession()));
                }
            } else {
                if (writeQuery.shouldCascadeParts()) {
                    writeQuery.setModifyRow(getDescriptor().getObjectBuilder().buildRow(modifyRow, object, getSession()));
                } else {
                    writeQuery.setModifyRow(getDescriptor().getObjectBuilder().buildRowForShallowInsert(modifyRow, object, getSession()));
                }
            }

            // the modify row and the translation row are the same for insert
            writeQuery.setTranslationRow(getModifyRow());
            if (!writeQuery.getDescriptor().isAggregateCollectionDescriptor()) {// Should/cannot be recomputed in aggregate collection.
                writeQuery.setPrimaryKey(getDescriptor().getObjectBuilder().extractPrimaryKeyFromObject(object, getSession()));
            }
            addWriteLockFieldForInsert();

            // CR#3237
            // Store the size of the modify row so we can determine if the user has added to the row in the insert.
            int modifyRowSize = getModifyRow().size();

            // PERF: Avoid events if no listeners.
            if (getDescriptor().getEventManager().hasAnyEventListeners()) {
                DescriptorEvent event = new DescriptorEvent(DescriptorEventManager.AboutToInsertEvent, writeQuery);
                event.setRecord(getModifyRow());
                getDescriptor().getEventManager().executeEvent(event);
            }

            // CR#3237
            // Call insert with a boolean that tells it to reprepare if the user has altered the modify row.
            insertObject(modifyRowSize != getModifyRow().size());

            // register the object before post insert to resolve possible cycles
            registerObjectInIdentityMap();
            if (writeQuery.getObjectChangeSet() != null) {
                //make sure that we put this new changeset in the changes list of the
                //uow changeset for serialization, or customer usage.
                ((UnitOfWorkChangeSet)writeQuery.getObjectChangeSet().getUOWChangeSet()).putNewObjectInChangesList(writeQuery.getObjectChangeSet(), getSession());
            }
        }

        commitManager.markPostModifyCommitInProgress(object);
        // Verify if deep shallow modify is turned on.
        if (writeQuery.shouldCascadeParts()) {
            queryManager.postInsert(writeQuery);
        }

        // PERF: Avoid events if no listeners.
        if (getDescriptor().getEventManager().hasAnyEventListeners()) {
            getDescriptor().getEventManager().executeEvent(new DescriptorEvent(DescriptorEventManager.PostInsertEvent, writeQuery));
View Full Code Here

     * Insert an object in the database.
     */
    public void insertObjectForWriteWithChangeSet() {
        WriteObjectQuery writeQuery = getWriteObjectQuery();
        ObjectChangeSet objectChangeSet = writeQuery.getObjectChangeSet();
        DescriptorQueryManager queryManager = getDescriptor().getQueryManager();
        CommitManager commitManager = getSession().getCommitManager();

        // check for user-defined query
        if ((!writeQuery.isUserDefined())// this is not a user-defined query
                 &&queryManager.hasInsertQuery()// there is a user-defined query
                 &&isExpressionQueryMechanism()) {// this is not a hand-coded call (custom SQL etc.)
            //must mark the changeSet here because the userDefined Insert will not use the changesets
            commitManager.markPreModifyCommitInProgress(objectChangeSet);
            performUserDefinedInsert();
            return;
        }

        // This must be done after the custom query check, otherwise it will be done twice.
        commitManager.markPreModifyCommitInProgress(objectChangeSet);
        commitManager.markPreModifyCommitInProgress(writeQuery.getObject());

        // check whether deep shallow modify is turned on
        if (writeQuery.shouldCascadeParts()) {
            queryManager.preInsert(writeQuery);
        }

        // In a unit of work/writeObjects the preInsert may have caused a shallow insert of this object,
        // in this case this second write must do an update.
        if (commitManager.isShallowCommitted(objectChangeSet)) {
            updateForeignKeyFieldAfterInsert();
        } else {
            AbstractRecord modifyRow = writeQuery.getModifyRow();
            if (modifyRow == null) {// Maybe have been passed in as in aggregate collection.
                if (writeQuery.shouldCascadeParts()) {
                    writeQuery.setModifyRow(getDescriptor().getObjectBuilder().buildRowWithChangeSet(objectChangeSet, getSession()));
                } else {
                    writeQuery.setModifyRow(getDescriptor().getObjectBuilder().buildRowForShallowInsertWithChangeSet(objectChangeSet, getSession()));
                }
            } else {
                if (writeQuery.shouldCascadeParts()) {
                    writeQuery.setModifyRow(getDescriptor().getObjectBuilder().buildRowWithChangeSet(modifyRow, objectChangeSet, getSession()));
                } else {
                    writeQuery.setModifyRow(getDescriptor().getObjectBuilder().buildRowForShallowInsertWithChangeSet(modifyRow, objectChangeSet, getSession()));
                }
            }

            // the modify row and the translation row are the same for insert
            writeQuery.setTranslationRow(getModifyRow());
            if (!writeQuery.getDescriptor().isAggregateCollectionDescriptor()) {// Should/cannot be recomputed in aggregate collection.
                writeQuery.setPrimaryKey(objectChangeSet.getPrimaryKeys());
            }
            addWriteLockFieldForInsert();

            // PERF: Avoid events if no listeners.
            if (getDescriptor().getEventManager().hasAnyEventListeners()) {
                DescriptorEvent event = new DescriptorEvent(DescriptorEventManager.AboutToInsertEvent, writeQuery);
                event.setRecord(getModifyRow());
                getDescriptor().getEventManager().executeEvent(event);
            }

            insertObject();

            // register the object before post insert to resolve possible cycles
            registerObjectInIdentityMap();
            // if we inserted through preInsert then make sure this code updates
            // the change tracker. Otherwise the changes will be detected on commit;
            if (getSession().isUnitOfWork()
                    && !((UnitOfWorkImpl) getSession())
                            .isAfterWriteChangesButBeforeCommit()) {

                ((UnitOfWorkImpl) getSession()).updateChangeTrackersIfRequired(
                        writeQuery.getObject(), writeQuery.getObjectChangeSet(),
                        (UnitOfWorkImpl) getSession(), getDescriptor());
            }
            if (objectChangeSet != null) {
                //make sure that we put this new changeset in the changes list of the
                //uow changeset for serialization, or customer usage.
                ((UnitOfWorkChangeSet)objectChangeSet.getUOWChangeSet()).putNewObjectInChangesList(objectChangeSet, getSession());
            }
        }

        commitManager.markPostModifyCommitInProgress(objectChangeSet);
        commitManager.markPostModifyCommitInProgress(writeQuery.getObject());
        // Verify if deep shallow modify is turned on.
        if (writeQuery.shouldCascadeParts()) {
            queryManager.postInsert(writeQuery);
        }

        // PERF: Avoid events if no listeners.
        if (getDescriptor().getEventManager().hasAnyEventListeners()) {
            getDescriptor().getEventManager().executeEvent(new DescriptorEvent(DescriptorEventManager.PostInsertEvent, writeQuery));
View Full Code Here

     * Update the object
     */
    public void updateObjectForWrite() {
        WriteObjectQuery writeQuery = getWriteObjectQuery();
        Object object = writeQuery.getObject();
        DescriptorQueryManager queryManager = getDescriptor().getQueryManager();

        // check for user-defined query
        if ((!writeQuery.isUserDefined())// this is not a user-defined query
                 &&queryManager.hasUpdateQuery()// there is a user-defined query
                 &&isExpressionQueryMechanism()) {// this is not a hand-coded call (custom SQL etc.)
            performUserDefinedUpdate();
            return;
        }

        // This must be done after the custom query check, otherwise it will be done twice.
        getSession().getCommitManager().markPreModifyCommitInProgress(object);

        if (writeQuery.getObjectChangeSet() == null) {
            // PERF: Avoid events if no listeners.
            if (getDescriptor().getEventManager().hasAnyEventListeners()) {
                // only throw the events if there is no changeset otherwise the event will be thrown twice
                // once by the calculate changes code and here
                getDescriptor().getEventManager().executeEvent(new DescriptorEvent(DescriptorEventManager.PreUpdateEvent, writeQuery));
            }
        }

        // Verify if deep shallow modify is turned on
        if (writeQuery.shouldCascadeParts()) {
            queryManager.preUpdate(writeQuery);
        }

        // The row must not be built until after preUpdate in case the object reference has changed.
        // For a user defined update in the uow to row must be built twice to check if any update is required.
        if ((writeQuery.isUserDefined() || writeQuery.isCallQuery()) && (!getSession().isUnitOfWork())) {
            writeQuery.setModifyRow(getDescriptor().getObjectBuilder().buildRow(object, getSession()));
        } else {
            writeQuery.setModifyRow(getDescriptor().getObjectBuilder().buildRowForUpdate(writeQuery));
        }

        if (!getModifyRow().isEmpty()) {
            // If user defined the entire row is required. Must not be built until change is known.
            if ((writeQuery.isUserDefined() || writeQuery.isCallQuery()) && getSession().isUnitOfWork()) {
                writeQuery.setModifyRow(getDescriptor().getObjectBuilder().buildRow(object, getSession()));
            }

            // Update the write lock field if required
            if (getDescriptor().usesOptimisticLocking()) {
                OptimisticLockingPolicy policy = getDescriptor().getOptimisticLockingPolicy();
                policy.addLockValuesToTranslationRow(writeQuery);

                // update the row with newer lock value   
                policy.updateRowAndObjectForUpdate(writeQuery, object);              
            }

            // PERF: Avoid events if no listeners.
            if (getDescriptor().getEventManager().hasAnyEventListeners()) {
                DescriptorEvent event = new DescriptorEvent(DescriptorEventManager.AboutToUpdateEvent, writeQuery);
                event.setRecord(getModifyRow());
                getDescriptor().getEventManager().executeEvent(event);
            }

            int rowCount = updateObject().intValue();

            if (rowCount < 1) {
                getSession().getEventManager().noRowsModified(writeQuery, object);
            }
            if (getDescriptor().usesOptimisticLocking()) {
                getDescriptor().getOptimisticLockingPolicy().validateUpdate(rowCount, object, writeQuery);
            }
        }

        getSession().getCommitManager().markPostModifyCommitInProgress(object);

        // Verify if deep shallow modify is turned on
        if (writeQuery.shouldCascadeParts()) {
            queryManager.postUpdate(writeQuery);
        }

        // PERF: Avoid events if no listeners.
        if (getDescriptor().getEventManager().hasAnyEventListeners()) {
            getDescriptor().getEventManager().executeEvent(new DescriptorEvent(DescriptorEventManager.PostUpdateEvent, writeQuery));
View Full Code Here

     * Update the object
     */
    public void updateObjectForWriteWithChangeSet() {
        WriteObjectQuery writeQuery = getWriteObjectQuery();
        Object object = writeQuery.getObject();
        DescriptorQueryManager queryManager = getDescriptor().getQueryManager();

        // check for user-defined query
        if ((!writeQuery.isUserDefined())// this is not a user-defined query
                 &&queryManager.hasUpdateQuery()// there is a user-defined query
                 &&isExpressionQueryMechanism()) {// this is not a hand-coded call (custom SQL etc.)
            // THis must be done here because the userdefined updatedoes not use a changeset so it will noe be set otherwise
            getSession().getCommitManager().markPreModifyCommitInProgress(writeQuery.getObjectChangeSet());
            performUserDefinedUpdate();
            return;
        }

        // This must be done after the custom query check, otherwise it will be done twice.
        getSession().getCommitManager().markPreModifyCommitInProgress(object);
        // This must be done after the custom query check, otherwise it will be done twice.
        getSession().getCommitManager().markPreModifyCommitInProgress(writeQuery.getObjectChangeSet());

        if (writeQuery.getObjectChangeSet().hasChanges()) {
            // PERF: Avoid events if no listeners.
            if (getDescriptor().getEventManager().hasAnyEventListeners()) {
                DescriptorEvent event = new DescriptorEvent(DescriptorEventManager.PreUpdateWithChangesEvent, writeQuery);
                getDescriptor().getEventManager().executeEvent(event);

                // PreUpdateWithChangesEvent listeners may have altered the object - should recalculate the change set.
                UnitOfWorkChangeSet uowChangeSet = (oracle.toplink.essentials.internal.sessions.UnitOfWorkChangeSet)((UnitOfWorkImpl)writeQuery.getSession()).getUnitOfWorkChangeSet();
                // writeQuery.getObjectChangeSet() is mapped to object in uowChangeSet.
                // It is first cleared then re-populated by calculateChanges method.
                writeQuery.getObjectChangeSet().clear();
                if(writeQuery.getDescriptor().getObjectChangePolicy().calculateChanges(object, ((UnitOfWorkImpl)event.getSession()).getBackupClone(object), uowChangeSet, writeQuery.getSession(), writeQuery.getDescriptor(), false) == null) {
                    // calculateChanges returns null in case the changeSet doesn't have changes.
                    // It should be removed from the list of ObjectChangeSets that have changes in uowChangeSet.
                    uowChangeSet.getAllChangeSets().remove(writeQuery.getObjectChangeSet());
                }
            }
        }
        
        // Verify if deep shallow modify is turned on
        if (writeQuery.shouldCascadeParts()) {
            queryManager.preUpdate(writeQuery);
        }

        // The row must not be built until after preUpdate in case the object reference has changed.
        // For a user defined update in the uow to row must be built twice to check if any update is required.
        writeQuery.setModifyRow(getDescriptor().getObjectBuilder().buildRowForUpdateWithChangeSet(writeQuery));
           
      Boolean shouldModifyVersionField = writeQuery.getObjectChangeSet().shouldModifyVersionField();

        if (!getModifyRow().isEmpty() || (shouldModifyVersionField != null) || writeQuery.getObjectChangeSet().hasCmpPolicyForcedUpdate()) {
            // If user defined the entire row is required. Must not be built until change is known.
            if (writeQuery.isUserDefined() || writeQuery.isCallQuery()) {
                writeQuery.setModifyRow(getDescriptor().getObjectBuilder().buildRow(object, getSession()));
            }

            // Update the write lock field if required
            if (getDescriptor().usesOptimisticLocking()) {
                OptimisticLockingPolicy policy = getDescriptor().getOptimisticLockingPolicy();
                policy.addLockValuesToTranslationRow(writeQuery);

                if (!getModifyRow().isEmpty() || (shouldModifyVersionField.booleanValue() && policy instanceof VersionLockingPolicy)) {
                    // update the row with newer lock value   
                    policy.updateRowAndObjectForUpdate(writeQuery, object);
                } else if (!shouldModifyVersionField.booleanValue() && policy instanceof VersionLockingPolicy) {
                    ((VersionLockingPolicy)policy).writeLockValueIntoRow(writeQuery, object);
                }
            }

            // PERF: Avoid events if no listeners.
            if (getDescriptor().getEventManager().hasAnyEventListeners()) {
                DescriptorEvent event = new DescriptorEvent(DescriptorEventManager.AboutToUpdateEvent, writeQuery);
                event.setRecord(getModifyRow());
                getDescriptor().getEventManager().executeEvent(event);
            }

            int rowCount = updateObject().intValue();

            if (rowCount < 1) {
                getSession().getEventManager().noRowsModified(writeQuery, object);
            }
            if (getDescriptor().usesOptimisticLocking()) {
                getDescriptor().getOptimisticLockingPolicy().validateUpdate(rowCount, object, writeQuery);
            }
        }

        getSession().getCommitManager().markPostModifyCommitInProgress(object);
        getSession().getCommitManager().markPostModifyCommitInProgress(writeQuery.getObjectChangeSet());

        // Verify if deep shallow modify is turned on
        if (writeQuery.shouldCascadeParts()) {
            queryManager.postUpdate(writeQuery);
        }

        // PERF: Avoid events if no listeners.
        if (getDescriptor().getEventManager().hasAnyEventListeners()) {
            getDescriptor().getEventManager().executeEvent(new DescriptorEvent(DescriptorEventManager.PostUpdateEvent, writeQuery));
View Full Code Here

        if (!isUserDefined()) {
            if (isCallQuery()) {
                // this is a hand-coded (custom SQL, SDK etc.) call
                return null;
            }
            DescriptorQueryManager descriptorQueryManager = getDescriptor().getQueryManager();

            // By default all descriptors have a custom ("static") read-object query.
            // This allows the read-object query and SQL to be prepare once.
            if (descriptorQueryManager.hasReadObjectQuery()) {
                // If the query require special SQL generation or execution do not use the static read object query.
                // PERF: the read-object query should always be static to ensure no regeneration of SQL.
                if (getJoinedAttributeManager().hasJoinedAttributeExpressions() || hasPartialAttributeExpressions() || hasAsOfClause() || hasNonDefaultFetchGroup() || (!wasDefaultLockMode()) || (!shouldIgnoreBindAllParameters())) {
                    return null;
                }

                if ((getSelectionKey() != null) || (getSelectionObject() != null)) {// Must be primary key.
                    return descriptorQueryManager.getReadObjectQuery();
                }

                if (getSelectionCriteria() != null) {
                    AbstractRecord primaryKeyRow = getDescriptor().getObjectBuilder().extractPrimaryKeyRowFromExpression(getSelectionCriteria(), translationRow, session);

                    // Only execute the query if the selection criteria has the primary key fields set
                    if (primaryKeyRow != null) {
                        return descriptorQueryManager.getReadObjectQuery();
                    }
                }
            }
        }
View Full Code Here

     */
    protected DatabaseQuery checkForCustomQuery(AbstractSession session, AbstractRecord translationRow) {
        checkDescriptor(session);

        // check if user defined a custom query
        DescriptorQueryManager queryManager = getDescriptor().getQueryManager();
        if ((!isCallQuery())// this is not a hand-coded (custom SQL, SDK etc.) call
                 &&(!isUserDefined())// and this is not a user-defined query (in the query manager)
                 &&queryManager.hasDeleteQuery()) {// and there is a user-defined query (in the query manager)
            return queryManager.getDeleteQuery();
        }

        return null;
    }
View Full Code Here

TOP

Related Classes of oracle.toplink.essentials.descriptors.DescriptorQueryManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.