Package com.mobixess.jodb.core.transaction

Examples of com.mobixess.jodb.core.transaction.TransactionContainer


        }
        return thisKey.remaining() - that.remaining();*/
    }
   
    private synchronized void insertChunk(int index, JODBOperationContext context){
        TransactionContainer transactionContainer = context!=null ? context.getTransactionContainer() : null;
       
        _offsetArrays = JODBIndexingRootAgent.ensurePersistentArrayCapacity(_offsetArrays, _totalChunks+1, transactionContainer, CHUNK_HOLDER_DEFAULT_CAPACITY);
        if(index!=_totalChunks){
            System.arraycopy(_offsetArrays, index, _offsetArrays, index+1, _totalChunks-index);
            System.arraycopy(_totalIndexesWithinChunks, index, _totalIndexesWithinChunks, index+1, _totalChunks-index);
        }
        _offsetArrays[index] = new long[CHUNK_CAPACITY];
        if(transactionContainer != null){//make sure the new array is registered in transaction container
            try {
                transactionContainer.set(_offsetArrays, Integer.MAX_VALUE);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        _totalIndexesWithinChunks[index] = 0;
        if(_dataArrays!=null){
            _dataArrays = JODBIndexingRootAgent.ensurePersistentArrayCapacity(_dataArrays, _totalChunks+1, transactionContainer, CHUNK_HOLDER_DEFAULT_CAPACITY);
            if(index!=_totalChunks){
                System.arraycopy(_dataArrays, index, _dataArrays, index+1, _totalChunks-index);
            }
            _dataArrays[index] = new byte[CHUNK_CAPACITY*_dataElementSize];
            if(transactionContainer != null){//make sure the new array is registered in transaction container
                try {
                    transactionContainer.set(_dataArrays, Integer.MAX_VALUE);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
View Full Code Here


    public long getVersion() {
        return _version;
    }
   
    public synchronized JODBIndexingAgent enableIndex(Field field, JODBOperationContext context) throws IOException{
        TransactionContainer transactionContainer = context.getTransactionContainer();
        transactionContainer.enableAgentMode();
        try{
            JODBIndexingAgent agent = addAgent(field, context);
            IOBase base = context.getBase();
            int classId = base.getOrSetClassTypeSubstitutionID(field.getDeclaringClass());
            int fieldId = base.getOrSetFieldSubstitutionID(field);
            long[] allOffsets = base.getForAllObjects(context.getIoTicket());
            DataContainersCache dataContainersCache = TransactionUtils.getObjectDataContainerCache();
            ObjectDataContainer dataContainer = dataContainersCache.pullObjectDataContainer();
            try{
                for (int i = 0; i < allOffsets.length; i++) {
                    processIndexForObjectId(allOffsets[i], classId, fieldId, field.getType(), dataContainer, agent, context);
                    dataContainer.reset();
                }
                try {
                    transactionContainer.set(agent, Integer.MAX_VALUE);
                } catch (IllegalClassTypeException e) {
                    e.printStackTrace();
                }
            }finally{
                dataContainersCache.pushObjectDataContainer(dataContainer);
            }
           
            return agent;
        }finally{
            transactionContainer.disableAgentMode();
        }
    }
View Full Code Here

            }
        }
    }
   
    private synchronized JODBIndexingAgent addAgent(Field field, JODBOperationContext context) throws IOException{
        TransactionContainer transactionContainer = context.getTransactionContainer();
        transactionContainer.enableAgentMode();
        try{
            int fieldId = context.getBase().getOrSetFieldSubstitutionID(field);
            for (int i = 0; i < _totalAgents; i++) {
                if(_agents[i].getFieldId() == fieldId){
                    return _agents[i];
                }
            }
            _totalAgents++;
            _agents = ensurePersistentArrayCapacity(_agents, _totalAgents, transactionContainer, _capacityIncrement);
            _agents[_totalAgents-1] = new JODBIndexingAgent(field,context);
            try {
                transactionContainer.set(this, Integer.MAX_VALUE);
            } catch (IllegalClassTypeException e) {
                // TODO log
                e.printStackTrace();
            }
            return _agents[_totalAgents-1];
        }finally{
            transactionContainer.disableAgentMode();
        }
    }
View Full Code Here

   
    public synchronized void removeAgent(Field field, JODBOperationContext context){
        int fieldId = context.getBase().getOrSetFieldSubstitutionID(field);
        for (int i = 0; i < _totalAgents; i++) {
            if(_agents[i].getFieldId() == fieldId){
                TransactionContainer transactionContainer = context.getTransactionContainer();
                try {
                    transactionContainer.delete(_agents[i], Integer.MAX_VALUE);
                } catch (IllegalClassTypeException e) {
                    // TODO log
                    e.printStackTrace();
                }
                if(i < _totalAgents-1){
                    System.arraycopy(_agents, i+1, _agents, i, _totalAgents - i);
                    _agents[_totalAgents-1] = null;
                }
                _totalAgents--;
                try {
                    transactionContainer.enableAgentMode();
                    transactionContainer.set(_agents, 1);
                } catch (IllegalClassTypeException e) {
                    // TODO log
                    e.printStackTrace();
                } finally{
                    transactionContainer.disableAgentMode();
                }
                break;
            }
        }
    }
View Full Code Here

        }
    }
   
    private void applyTransaction0( JODBOperationContext context, IOTicket writeTicket, boolean writeLocked ) throws IOException, IllegalClassTypeException{
        //local transaction only
        TransactionContainer transactionContainer = context.getTransactionContainer();
        IOTicket readTicket = context.getIoTicket();
        if(JODBConfig.DEBUG){
            _logger.info(" *******************  Transaction start for container="+System.identityHashCode(transactionContainer));
        }
        //JODBSession session, IOTicket readTicket, IOTicket writeTicket
        //JODBOperationContext context = new JODBOperationContext(session,readTicket,null,transactionContainer);
        long transactionOffset = getTransactionOffset();
        context.setTransactionOffset(transactionOffset);
        try{
            readTicket.lock(false, 0);//for transaction assembling we need only read lock
            TransactionAssembler.assembleTransactionData(context, transactionContainer);
        }finally{
            readTicket.unlock();
        }
        //transaction lock engaged earlier so no one will ask for write lock concurently
        ////////////////////// WRITE LOCK PHASE ////////////////////
        if(!writeLocked){
            writeTicket.lock(true, 0);
        }
       
       
        transactionContainer.processTranslatedObjectsIndex(context, transactionOffset);
        transactionContainer.resetTransactionBufferToEnd();
        try {
            transactionContainer.enableAgentMode();
            TransactionAssembler.assembleTransactionData(context, transactionContainer);
        } finally {
            transactionContainer.disableAgentMode();
        }
       
        applyTransaction0(context.getSession(), transactionContainer, transactionOffset, writeTicket);
    }
View Full Code Here

    }
   
    /*package*/void init(File file) throws IOException {
        initIoBase(file);
        _session = new JODBSession(_base);
        _transactionContainer = new TransactionContainer(_session, null);
        if(_base.isNewDatabase()){
            JODBIndexingRootAgent agent = new JODBIndexingRootAgent();
            try {
                _transactionContainer.enableAgentMode();
                _transactionContainer.set(agent, Integer.MAX_VALUE);
View Full Code Here

    /*package*/ JodbSessionContainerSE(URI serverURI, ITransactionResolver transactionResolver, boolean readOnly) throws IOException {
        _base = new JODBIOBaseProxy(serverURI);
        _session = new JODBSession(_base);
        if(!readOnly){
            _transactionContainer = new TransactionContainer(_session, transactionResolver);
        }
    }
View Full Code Here

TOP

Related Classes of com.mobixess.jodb.core.transaction.TransactionContainer

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.