Package com.mobixess.jodb.core.io

Examples of com.mobixess.jodb.core.io.JODBOperationContext


            sortDataCache.setValuesAccumulationMode();
        }else{
            sortDataCache.clearAll();
            sortDataCache = null;
        }
        JODBOperationContext context = new JODBOperationContext(_session,ticket,sortDataCache,null,null,excludedObjects,true);
        IndexDataIterator indexIterator = null;
        boolean skipConventionalSorting = false;

        FieldRecord indexDataIteratorFieldRecord = null;//used for iteraion through indexed data
        QueryNode indexedNode = null;
        TypeConstraint typeConstraint = null;
        try{
           
            Vector<ConstraintBase> vectorOfConstraints = _constraints._constraints;
            for (int i = 0; i < vectorOfConstraints.size(); i++) {
                ConstraintBase nextCandidate = vectorOfConstraints.elementAt(i);
                if(nextCandidate instanceof TypeConstraint){
                    if(typeConstraint == null){
                        typeConstraint = (TypeConstraint) nextCandidate;
                    }else{
                        typeConstraint = null;//multiple type constraints
                        break;
                    }
                }
            }
           
            if(typeConstraint != null){
                //boolean useIndexDataFromIterator = false;
                JODBIndexingRootAgent indexingRootAgent = _session.getIndexingRootAgent();
                ClassDescriptor classDescriptor = _session.getDescriptorForClass((Class)typeConstraint.getObject());
                JODBIndexingAgent indexingAgent = null;
                if(sortDataCache!=null){
                    //lookup indexing data to optimize query
                    SortNodeRecord[] sortRecords = sortDataCache.getSortNodes();
                    int fieldId = classDescriptor.getFieldIDForName(sortRecords[0]._fullPath);
                    if(fieldId!=-1){
                        indexingAgent = indexingRootAgent.getIndexingAgent(fieldId, base);
                        if(indexingAgent!=null){
                            indexIterator = indexingAgent.getIndexIterator(sortRecords[0]._orderAscending);
                            indexedNode = _descendants.get(sortRecords[0]._fullPath);
                            skipConventionalSorting = sortRecords.length == 1;
                        }
                    }
                }
                if(indexIterator == null){
                    //search first index
                    Iterator<String> descendants = _descendants.keySet().iterator();
                    while (descendants.hasNext() && indexIterator == null) {
                        String next = descendants.next();
                        Field field = classDescriptor.getFieldForName(next);
                        if(field==null){
                            continue;
                        }
                        indexingAgent = indexingRootAgent.getIndexingAgent(field, base);
                        if(indexingAgent!=null){
                            indexIterator = indexingAgent.getIndexIterator(true);
                            indexedNode = _descendants.get(next);
                        }
                    }
                }
                if(indexingAgent!=null && indexedNode != null){
                    Field field = classDescriptor.getFieldForID(indexingAgent.getFieldId(), null);
                    Class fieldType = field.getType();                       
                    if(fieldType.isPrimitive()){
                        indexDataIteratorFieldRecord = new FieldRecord();
                        indexDataIteratorFieldRecord._fieldID = indexingAgent.getFieldId();
                        indexDataIteratorFieldRecord._category = FIELD_CATEGORIES.PRIMITIVE;
                        indexDataIteratorFieldRecord._fieldTypeID = base.getClassTypeSubstitutionID(fieldType.getName());
                    }
                }
            }
            if(indexIterator==null){
                indexIterator = new LArrayIndexIterator(base.getForAllObjects(ticket));
            }

            LArrayChunkedBuffer acceptedIds = new LArrayChunkedBuffer();

            while (indexIterator.hasNext()) {
                resetStateOfConstraints();
                CONSTRAINT_EVALUATION_STATUS status = CONSTRAINT_EVALUATION_STATUS.UNKNOWN;
                long nextObjectId;
                if(indexDataIteratorFieldRecord!=null){
                    indexDataIteratorFieldRecord._primitiveRawDataBuffer.clear();
                    nextObjectId = indexIterator.next(indexDataIteratorFieldRecord._primitiveRawDataBuffer);
                    if(excludedObjects!=null && excludedObjects.binarySearch(nextObjectId)>=0){
                        continue;
                    }
                    if(_session.getObjectFromCache(nextObjectId) == null){
                        //do not analize active objects
                        indexDataIteratorFieldRecord._primitiveRawDataBuffer.flip();
                        if(sortDataCache!=null){
                            sortDataCache.setCandidateID(nextObjectId);
                        }
                        indexedNode.analize(-1, indexDataIteratorFieldRecord, context);
                        typeConstraint.setStatus(CONSTRAINT_EVALUATION_STATUS.ACCEPTED);
                        _constraints.markExistanceConstrantAsAccepted();
                        indexedNode._constraints.markExistanceConstrantAsAccepted();
                        status = getCumulativeStatus();
                    }
                }else{
                    nextObjectId = indexIterator.next();
                    if(excludedObjects!=null && excludedObjects.binarySearch(nextObjectId)>=0){
                        continue;
                    }
                }
                if(status == CONSTRAINT_EVALUATION_STATUS.UNKNOWN){
                    if(sortDataCache!=null){
                        sortDataCache.setCandidateID(nextObjectId);
                    }
                    status = analize(nextObjectId,context);
                }
                if(status == CONSTRAINT_EVALUATION_STATUS.EXCLUDED){
                    if( !context.isExcludedObjectId(nextObjectId) ){
                        dynamicLongArray.addElement(nextObjectId);
                    }
                    continue;
                }
                if(status == CONSTRAINT_EVALUATION_STATUS.ACCEPTED){
View Full Code Here


            return;
        }
       
        IOTicket writeTicket = _base.getIOTicket(true, true);
        try{
            JODBOperationContext context = new JODBOperationContext(_session, writeTicket, null, _transactionContainer, indexingRootAgent);
            writeTicket.lock(true);
           
            if(!enable){
                indexingRootAgent.removeAgent(field, context);
                return;
View Full Code Here

        //Constructor<>
    }
   
    @SuppressWarnings("unchecked")
    public boolean isOptimizedQuery(JODBSession session, Predicate predicate, Comparator comparator) throws IOException{
        JODBOperationContext context = new JODBOperationContext(session, null, null, null,null);
        INqLoader loader = getLoader(context, predicate, comparator);
        return loader.isPredicateOptimized() && loader.isComparatorOptimized();
    }
View Full Code Here

   
    public QueryBytecode getTransformationForQuery(JODBSession session, Predicate predicate, Comparator comparator) throws IOException{
        if(!isOptimizedQuery(session, predicate, comparator)){
            return null;
        }
        JODBOperationContext context = new JODBOperationContext(session, null, null, null,null);
        INqLoader loader = getLoader(context, predicate, comparator);
        return loader.getTransformedQueryBytecode();
    }
View Full Code Here

    public ObjectSet execute(JODBSession session, Predicate predicate, Comparator comparator) throws IOException
    {
        IOBase base = session.getBase();
        IOTicket ticket = base.getIOTicket(true, false);
        try {
            JODBOperationContext context = new JODBOperationContext(session, ticket, null, null,null);
            INqLoader loader = getLoader(context, predicate, comparator);
            if(!loader.isPredicateOptimized() || !loader.isComparatorOptimized()){
                return executeUnoptimized(session, predicate, comparator, loader);
            }
            Class predicateSubjectClass = loader.getPredicateSubjectClass();
View Full Code Here

   
    private void applyTransaction(TransactionContainer transactionContainer,IOTicket ticket,
            JODBSession session, long transactionOffset,JODBIndexingRootAgent indexingRootAgent) throws Exception
    {

        JODBOperationContext context = new JODBOperationContext(session,ticket,null,transactionContainer, indexingRootAgent);
        context.setTransactionOffset(transactionOffset);

        TransactionAssembler.assembleTransactionData(context, transactionContainer);

        transactionContainer.processTranslatedObjectsIndex(context, transactionOffset);
        transactionContainer.resetTransactionBufferToEnd();
View Full Code Here

TOP

Related Classes of com.mobixess.jodb.core.io.JODBOperationContext

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.