Examples of ObjectLevelReadQuery


Examples of org.eclipse.persistence.queries.ObjectLevelReadQuery

        // Now initialize the mapping
        cloneMapping.initialize(session);
           
        // The selection query should be initialized with all the right
        // goodies now, cache it for quick retrieval.
        ObjectLevelReadQuery selectionQuery = (ObjectLevelReadQuery) cloneMapping.getSelectionQuery();
        selectionQuery.getExpressionBuilder().setQueryClassAndDescriptor(descriptor.getJavaClass(), descriptor);

        // By default its source mapping will be the cloned mapping, we
        // need to set the actual source mapping so that we can look it
        // back up correctly.
        selectionQuery.setSourceMapping(sourceMapping);
           
        // Cache the selection query for this source mapping.
        selectionQueriesForAllObjects.put(sourceMapping, selectionQuery);
    }
View Full Code Here

Examples of org.eclipse.persistence.queries.ObjectLevelReadQuery

            //assert !getCommitManager().isActive();
            // This will either throw an exception or do a logic only operation
            // (i.e. mark for later deletion if a deleteObjet query).
            boolean objectLevelRead = (query.isObjectLevelReadQuery() && !query.isReportQuery() && query.shouldMaintainCache());
            if (objectLevelRead) {
                ObjectLevelReadQuery readQuery = (ObjectLevelReadQuery)query;
                if (isAfterWriteChangesButBeforeCommit()) {
                    throw ValidationException.illegalOperationForUnitOfWorkLifecycle(getLifecycle(), "executeQuery(ObjectLevelReadQuery)");
                }
                Object result = readQuery.checkEarlyReturn(this, Record);

                if (result != null) {
                    if (result == InvalidObject.instance) {
                        return null;
                    }
                    return result;
                }

                // Must use the uow connection in these cases.
                // can be certain that commit manager not active as on client.
                if (readQuery.isLockQuery(this) && !wasTransactionBegunPrematurely()) {
                    beginEarlyTransaction();
                }
            } else if (query.isObjectLevelModifyQuery()) {
                return query.executeInUnitOfWork(this, Record);
            }
View Full Code Here

Examples of org.eclipse.persistence.queries.ObjectLevelReadQuery

     * {@inheritDoc}
     */
    @Override
    public void visit(SelectStatement expression) {

      ObjectLevelReadQuery query = queryContext.getDatabaseQuery();

      // Create and prepare the query
      if (query == null) {
        query = buildReadAllQuery(expression);
        queryContext.setDatabasQuery(query);
        query.setJPQLString(jpqlQuery);
        ((JPQLCallQueryMechanism) query.getQueryMechanism()).getJPQLCall().setIsParsed(true);
      }

      // Now populate it
      expression.accept(buildVisitor(query));
    }
View Full Code Here

Examples of org.eclipse.persistence.queries.ObjectLevelReadQuery

      if (queryExpression == null) {
        queryExpression = queryContext.buildExpression(expression);
        queryContext.addQueryExpression(variableName, queryExpression);
      }

      ObjectLevelReadQuery query = (ObjectLevelReadQuery) queryContext.getDatabaseQuery();

      if (query.getExpressionBuilder() != queryExpression) {
        query.addNonFetchJoinedAttribute(queryExpression);
      }

      return queryExpression;
    }
View Full Code Here

Examples of org.eclipse.persistence.queries.ObjectLevelReadQuery

     * INTERNAL:
     * Used for joining.  Add any queries necessary for joining to the join manager
     */
    @Override
    public void addNestedJoinsQueriesForMapKey(JoinedAttributeManager joinManager, ObjectLevelReadQuery query, AbstractSession session){
        ObjectLevelReadQuery nestedQuery = keyMapping.getNestedJoinQuery(joinManager, query, session);
        if (nestedQuery != null){
            joinManager.getJoinedMappingQueries_().put((DatabaseMapping)keyMapping, nestedQuery);
        }
    }
View Full Code Here

Examples of org.eclipse.persistence.queries.ObjectLevelReadQuery

            //assert !getCommitManager().isActive();
            // This will either throw an exception or do a logic only operation
            // (i.e. mark for later deletion if a deleteObjet query).
            boolean objectLevelRead = (query.isObjectLevelReadQuery() && !query.isReportQuery() && query.shouldMaintainCache());
            if (objectLevelRead) {
                ObjectLevelReadQuery readQuery = (ObjectLevelReadQuery)query;
                if (isAfterWriteChangesButBeforeCommit()) {
                    throw ValidationException.illegalOperationForUnitOfWorkLifecycle(getLifecycle(), "executeQuery(ObjectLevelReadQuery)");
                }
                Object result = readQuery.checkEarlyReturn(this, Record);

                if (result != null) {
                    if (result == InvalidObject.instance) {
                        return null;
                    }
                    return result;
                }

                // Must use the uow connection in these cases.
                // can be certain that commit manager not active as on client.
                if (readQuery.isLockQuery(this) && !wasTransactionBegunPrematurely()) {
                    beginEarlyTransaction();
                }
            } else if (query.isObjectLevelModifyQuery()) {
                return query.executeInUnitOfWork(this, Record);
            }
View Full Code Here

Examples of org.eclipse.persistence.queries.ObjectLevelReadQuery

     */
    public DatabaseQuery translate(){
        //TODO fetch joins
        //find and translate subqueries.
       
        ObjectLevelReadQuery query = null;
        if (this.queryResult.equals(ResultType.ENTITY)){
            query = new ReadAllQuery(this.queryType);
        }else if (this.queryResult.equals(ResultType.PARTIAL)){
            ReadAllQuery raq = new ReadAllQuery(this.queryType);
            for (Selection selection: this.selection.getCompoundSelectionItems()){
                raq.addPartialAttribute(((SelectionImpl)selection).currentNode);
            }
            query = raq;
        }else{
            if (this.roots == null || this.roots.isEmpty()) throw new IllegalStateException(ExceptionLocalization.buildMessage("CRITERIA_NO_ROOT_FOR_COMPOUND_QUERY"));
            ReportQuery reportQuery = null;
            if (this.queryResult.equals(ResultType.CONSTRUCTOR)){
                reportQuery = new ReportQuery();
                reportQuery.addConstructorReportItem(((ConstructorSelectionImpl)this.selection).translate());
                reportQuery.setShouldReturnSingleAttribute(true);
            }else {
                if (this.queryResult.equals(ResultType.TUPLE)){
                    reportQuery = new TupleQuery(this.selection==null?new ArrayList():this.selection.getCompoundSelectionItems());
                }else{
                    reportQuery = new ReportQuery();
                    reportQuery.setShouldReturnWithoutReportQueryResult(true);
                }
                if (this.selection != null){
                    if (this.selection.isCompoundSelection()){
                        for (Selection nested: this.selection.getCompoundSelectionItems()){
                            if (((SelectionImpl)nested).isCompoundSelection()){
                                reportQuery.addConstructorReportItem(((ConstructorSelectionImpl)nested).translate());
                            }else{
                                reportQuery.addItem(nested.getAlias(), ((SelectionImpl)nested).getCurrentNode());
                            }
                        }
                    }else{
                        reportQuery.addAttribute(this.selection.getAlias(), ((SelectionImpl)this.selection).getCurrentNode(), ((SelectionImpl)this.selection).getJavaType());
                    }
                }
            }
            if (this.where != null && ((InternalSelection)this.where).getCurrentNode() != null){
                reportQuery.setReferenceClass(((InternalSelection)this.where).getCurrentNode().getBuilder().getQueryClass());
                reportQuery.setExpressionBuilder(((InternalSelection)this.where).getCurrentNode().getBuilder());
            }else{
                Root root = this.getRoots().iterator().next();
                reportQuery.setReferenceClass(root.getJavaType());
                reportQuery.setExpressionBuilder(((RootImpl)root).getCurrentNode().getBuilder());
            }
            query = reportQuery;
        }
        if (this.where != null){
            query.setSelectionCriteria(((InternalSelection)this.where).getCurrentNode());
        }
        if (this.distinct){
            query.setDistinctState(ObjectLevelReadQuery.USE_DISTINCT);
        }
        else{
            query.setDistinctState(ObjectLevelReadQuery.DONT_USE_DISTINCT);

        }
        if (this.orderBy!= null && !this.orderBy.isEmpty()){
            for (Order order: this.orderBy){
                OrderImpl orderImpl = (OrderImpl)order;
                org.eclipse.persistence.expressions.Expression orderExp = ((ExpressionImpl)orderImpl.getExpression()).getCurrentNode();
                if (orderImpl.isAscending()){
                    orderExp = orderExp.ascending();
                } else{
                    orderExp = orderExp.descending();
                }
                query.addOrdering(orderExp);
            }
        }
       
        return query;
    }
View Full Code Here

Examples of org.eclipse.persistence.queries.ObjectLevelReadQuery

    /**
     * INTERNAL:
     * Used for joining.  Add any queries necessary for joining to the join manager
     */
    public void addNestedJoinsQueriesForMapKey(JoinedAttributeManager joinManager, ObjectLevelReadQuery query, AbstractSession session){
        ObjectLevelReadQuery nestedQuery = keyMapping.getNestedJoinQuery(joinManager, query, session);
        if (nestedQuery != null){
            joinManager.getJoinedMappingQueries_().put((DatabaseMapping)keyMapping, nestedQuery);
        }
    }
View Full Code Here

Examples of org.eclipse.persistence.queries.ObjectLevelReadQuery

            super(QueryHints.FETCH, "");
        }
   
        DatabaseQuery applyToDatabaseQuery(Object valueToApply, DatabaseQuery query, ClassLoader loader) {
            if (query.isObjectLevelReadQuery() && !query.isReportQuery()) {
                ObjectLevelReadQuery olrq = (ObjectLevelReadQuery)query;
                StringTokenizer tokenizer = new StringTokenizer((String)valueToApply, ".");
                if (tokenizer.countTokens() < 2){
                    throw QueryException.queryHintDidNotContainEnoughTokens(query, QueryHints.FETCH, valueToApply);
                }
                // ignore the first token since we are assuming read all query
                // e.g. In e.phoneNumbers we will assume "e" refers to the base of the query
                String previousToken = tokenizer.nextToken();
                ClassDescriptor descriptor = olrq.getDescriptor();
                Expression expression = olrq.getExpressionBuilder();
                while (tokenizer.hasMoreTokens()){
                    String token = tokenizer.nextToken();
                    ForeignReferenceMapping frMapping = null;
                    DatabaseMapping mapping = descriptor.getObjectBuilder().getMappingForAttributeName(token);
                    if (mapping == null){
                        throw QueryException.queryHintNavigatedNonExistantRelationship(query, QueryHints.FETCH, valueToApply, previousToken + "." + token);
                    } else if (!mapping.isForeignReferenceMapping()){
                        throw QueryException.queryHintNavigatedIllegalRelationship(query, QueryHints.FETCH, valueToApply, previousToken + "." + token);
                    } else {
                        frMapping = (ForeignReferenceMapping)mapping;
                    }
                    descriptor = frMapping.getReferenceDescriptor();
                    if (frMapping.isCollectionMapping()){
                        expression = expression.anyOf(token);
                    } else {
                        expression = expression.get(token);
                    }
                    previousToken = token;
                }
                olrq.addJoinedAttribute(expression);
            } else {
                throw new IllegalArgumentException(ExceptionLocalization.buildMessage("ejb30-wrong-type-for-query-hint",new Object[]{getQueryId(query), name, getPrintValue(valueToApply)}));
            }
            return query;
        }
View Full Code Here

Examples of org.eclipse.persistence.queries.ObjectLevelReadQuery

            super(QueryHints.LEFT_FETCH, "");
        }
   
        DatabaseQuery applyToDatabaseQuery(Object valueToApply, DatabaseQuery query, ClassLoader loader) {
            if (query.isObjectLevelReadQuery() && !query.isReportQuery()) {
                ObjectLevelReadQuery olrq = (ObjectLevelReadQuery)query;
                StringTokenizer tokenizer = new StringTokenizer((String)valueToApply, ".");
                if (tokenizer.countTokens() < 2){
                    throw QueryException.queryHintDidNotContainEnoughTokens(query, QueryHints.LEFT_FETCH, valueToApply);
                }
                // ignore the first token since we are assuming read all query
                // e.g. In e.phoneNumbers we will assume "e" refers to the base of the query
                String previousToken = tokenizer.nextToken();
                ClassDescriptor descriptor = olrq.getDescriptor();
                Expression expression = olrq.getExpressionBuilder();
                while (tokenizer.hasMoreTokens()){
                    String token = tokenizer.nextToken();
                    ForeignReferenceMapping frMapping = null;
                    DatabaseMapping mapping = descriptor.getObjectBuilder().getMappingForAttributeName(token);
                    if (mapping == null){
                        throw QueryException.queryHintNavigatedNonExistantRelationship(query, QueryHints.LEFT_FETCH, valueToApply, previousToken + "." + token);
                    } else if (!mapping.isForeignReferenceMapping()){
                        throw QueryException.queryHintNavigatedIllegalRelationship(query, QueryHints.LEFT_FETCH, valueToApply, previousToken + "." + token);
                    } else {
                        frMapping = (ForeignReferenceMapping)mapping;
                    }
                    descriptor = frMapping.getReferenceDescriptor();
                    if (frMapping.isCollectionMapping()){
                        expression = expression.anyOfAllowingNone(token);
                    } else {
                        expression = expression.getAllowingNull(token);
                    }
                    previousToken = token;
                }
                olrq.addJoinedAttribute(expression);
            } else {
                throw new IllegalArgumentException(ExceptionLocalization.buildMessage("ejb30-wrong-type-for-query-hint",new Object[]{getQueryId(query), name, getPrintValue(valueToApply)}));
            }
            return query;
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.