Package com.mobixess.jodb.core

Examples of com.mobixess.jodb.core.JodbIOException


        return result;
    }

    public void applyTransaction(TransactionContainer transactionContainer, JODBSession session, IOTicket writeTicket, JODBIndexingRootAgent indexingRootAgent, JODBSessionContainer sessionContainer ) throws IOException{
        if(isClosed()){
            throw new JodbIOException("Container closed");
        }
        if(transactionContainer.isEmpty()){
            return;
        }
        IOTicket readTicket = getIOTicket(true, false);
        boolean writeLocked = true;
        if(writeTicket == null){
            writeTicket = getIOTicket(true, true);
            writeLocked = false;
        }
        transactionContainer.lockTransaction();
        JODBOperationContext context = new JODBOperationContext(session,readTicket,null,transactionContainer, indexingRootAgent);
        try {
            applyTransaction0(context, writeTicket, writeLocked);
        } catch (IOException e) {
            handleTransactionInterrupt(writeTicket.getRandomAccessBuffer());
            throw e;
        } catch (IllegalClassTypeException e) {
            //should never happen as exception would occur much earlier when object is set to container
            throw new JodbIOException(e);
        } finally{
            writeTicket.unlock();//write ticket may remain locked due to exception
            transactionContainer.reset();
            writeTicket.close();
            readTicket.close();
View Full Code Here


    }
   
    private void applyTransaction0(JODBSession session, ITranslatedDataSorce translatedDataSorce , long transactionOffset, IOTicket writeTicket ) throws IOException{
   
        if(!_transactionLock.isWriteLockedByCurrentThread()){
            throw new JodbIOException("Transaction without holding write lock");
        }
       
        IRandomAccessDataBuffer mainDataBuffer = writeTicket.getRandomAccessBuffer();

        IRandomAccessDataBuffer newDataBuffer = translatedDataSorce.getTransactionNewDataFile();
        IRandomAccessDataBuffer replacementsDataBuffer = translatedDataSorce.getTransactionReplacementsDataFile();
        IRandomAccessDataBuffer rollbackDataBuffer = translatedDataSorce.getRollbackDataFile();
       
        long dataBlockIncrease = newDataBuffer.length();

        _substitutions.backupPendingSubstitutions();
        DataEntry entry = _entries.lastElement();
       
       
        if(_substitutions.hasPendingSubstitutionTables()){
            translatedDataSorce.resetTransactionBufferToEnd();
            //writing substitution table
            replacementsDataBuffer.resetToEnd();
            SubstTable substTable = entry.getLiteralSubstTable();
            replacementsDataBuffer.write(TransactionAssembler.TRANSACTION_REPLACEMENT_ENTRY_TYPE_STATIC);
            replacementsDataBuffer.writeLong(substTable._tableOffset);//offset of table in main file
            long lengthEntryOffset = replacementsDataBuffer.getCursorOffset();
            replacementsDataBuffer.writeLong(0);//reserved space for length
            substTable.writePendingRecords(mainDataBuffer, replacementsDataBuffer);
            //replacement length
            long substTableLen = replacementsDataBuffer.getCursorOffset() - lengthEntryOffset - 8;//8 bytes for len of entry
            replacementsDataBuffer.seek(lengthEntryOffset);
            replacementsDataBuffer.writeLong(substTableLen);
        }
       
        DataEntry pendingDataEntry = null;
        if(_substitutions.hasPendingSubstitutionTables()){//last entry didn't accept all substitutions, seel current entry and create new one
            replacementsDataBuffer.resetToEnd();                   
            pendingDataEntry = new DataEntry();
            newDataBuffer.resetToEnd();
            pendingDataEntry.writeWithAllSubstitutionRecords(newDataBuffer, null, 0, transactionOffset);
        }
       
        if (dataBlockIncrease>0) {
            //write replacement for data entry length
            replacementsDataBuffer.resetToEnd();
            replacementsDataBuffer.writeByte(TransactionAssembler.TRANSACTION_REPLACEMENT_ENTRY_TYPE_STATIC);
            replacementsDataBuffer.writeLong(entry._tableOffset);
            long lengthEntryOffset = replacementsDataBuffer.getCursorOffset();
            replacementsDataBuffer.writeLong(0);//reserved space for length
            entry.write(replacementsDataBuffer, entry._dataBlockLength + dataBlockIncrease, pendingDataEntry != null);//write as sealed if pending data entry exists
            long len = replacementsDataBuffer.getCursorOffset() - lengthEntryOffset - 8;//8 bytes for len of entry
            //replacement length
            replacementsDataBuffer.seek(lengthEntryOffset);
            replacementsDataBuffer.writeLong(len);
            //..
        }               
        translatedDataSorce.resetTransactionBufferToStart();
        if(JODBConfig.DEBUG){
            _logger.info("File size prior transaction="+mainDataBuffer.length());
            _logger.info("Transaction state offset="+transactionOffset+" new data len="+newDataBuffer.length()+" replacement data="+replacementsDataBuffer.length()+" rollback data"+rollbackDataBuffer.length());
        }
        long transactionDataEnd = transactionOffset+newDataBuffer.length();
        _header.setDataTransactionState(mainDataBuffer, transactionOffset, transactionDataEnd);
        mainDataBuffer.seek(transactionOffset);
        long toTransfer = newDataBuffer.length();
        long transfered = mainDataBuffer.transferFrom(newDataBuffer.getChannel(), transactionOffset, toTransfer);
        if(toTransfer!=transfered){
            throw new JodbIOException("unable to transfer transaction data "+transfered+"<>"+toTransfer);
        }
       
        mainDataBuffer.seek(mainDataBuffer.getCursorOffset()+transfered);
       
        long rollbackTransactionStartOffset = mainDataBuffer.getCursorOffset();
       
        long backupEnd = backup(mainDataBuffer, rollbackTransactionStartOffset, replacementsDataBuffer);
       
        _header.setRollbackTransactionState(mainDataBuffer, rollbackTransactionStartOffset, backupEnd);
       
       
        _header.setTransactionInProgressState(mainDataBuffer);
       
        translatedDataSorce.resetTransactionBufferToStart();
       
        while(replacementsDataBuffer.getCursorOffset()<replacementsDataBuffer.length()){
            byte replacementType = replacementsDataBuffer.readByte();
            long targetOffset = replacementsDataBuffer.readLong();
            switch (replacementType) {
            case TransactionAssembler.TRANSACTION_REPLACEMENT_ENTRY_TYPE_STATIC:
                long dataLength = replacementsDataBuffer.readLong();
                transfered = mainDataBuffer.transferFrom(replacementsDataBuffer.getChannel(), targetOffset, dataLength);
                if(transfered!=dataLength){
                    throw new JodbIOException("unable to transfer rollback data "+transfered+"<>"+toTransfer);
                }
                break;
            case TransactionAssembler.TRANSACTION_REPLACEMENT_ENTRY_TYPE_REDIRECTOR:
                mainDataBuffer.seek(targetOffset);
                short id = mainDataBuffer.readShort();
View Full Code Here

                dataLength = mainBuffer.getCursorOffset() - startOffset + bytesRepresentingLength + 8;//8 bytes for redirection offset entry
                mainBuffer.seek(targetOffset);
                replacementsDataBuffer.skip(8);//skip relative address
                break;
            default:
                throw new JodbIOException("illegal replacement type "+replacementType);
            }
            mainBuffer.seek(mainBufferBackupPosition);
            mainBuffer.writeLong(targetOffset);//rollback entry target offset
            mainBuffer.writeLong(dataLength);
            mainBufferBackupPosition = mainBuffer.getCursorOffset();
View Full Code Here

        return address|(1L<<63);
    }
   
    private final void verifyAddress(long address) throws IOException{
        if( (address & ~(0xFFL << 56)) != address ){//what is the purpose of this check
            throw new JodbIOException("address verification failed");
        }
    }
View Full Code Here

        return getIOTicket(read, write, false);
    }
   
    public IOTicketImpl getIOTicket(boolean read, boolean write, boolean remote) throws IOException{
        if(isClosed()){
            throw new JodbIOException("Container closed");
        }
        IOTicketImpl result = new IOTicketImpl(_targetDBFile,read,write);
        _ioBuffersCache.put(result, new IOTicketWRHolder(result));
        return result;
    }
View Full Code Here

            if(field!=null && activeObject!=null){
                try {
                    activeObject = field.get(activeObject);
                } catch (Exception e) {
                    e.printStackTrace();
                    throw new JodbIOException(e);
                }
            }
            if(activeObject!=null){
                if(originClass != activeObject.getClass()){
                    processCompareResult(COMPARE_RESULT.UNKNOWN);
View Full Code Here

                    return CONSTRAINT_EVALUATION_STATUS.ACCEPTED;
                }else{
                    return CONSTRAINT_EVALUATION_STATUS.REJECTED;
                }
            default:
                throw new JodbIOException();
            }
        }
View Full Code Here

                Class persistentObjectClass;
                try {
                    persistentObjectClass = context.getSession().resolveClassForID(dataContainer.getOriginalClassType());
                } catch (ClassNotFoundException e) {
                    //TODO debug output???
                    throw new JodbIOException(e);
                }
                if(originClass!=persistentObjectClass){
                    processCompareResult(COMPARE_RESULT.UNKNOWN);
                    return;
                }
View Full Code Here

            return _closed;
        }
       
        public void lock(boolean write, long offset) throws IOException {
            if(_lock.isHeldByCurrentThread()){
                throw new JodbIOException("recursive lock requests are not allowed");
            }
            try {
                if(write){
                    _ioLock.writeLock().tryLock(JODBConfig.getMaxWriteWait(), TimeUnit.MILLISECONDS);
                    _holdsGlobalWriteLock = true;
                }else{
                    _ioLock.readLock().tryLock(JODBConfig.getMaxReadWait(), TimeUnit.MILLISECONDS);
                    _holdsGlobalReadLock = true;
                }
                _lock.tryLock(write ? JODBConfig.getMaxWriteWait() : JODBConfig.getMaxReadWait() , TimeUnit.MILLISECONDS);
                _randomAccessBuffer.seek(offset);
            } catch (InterruptedException e) {
                unlock();
                e.printStackTrace();
                throw new JodbIOException(e);
            }
        }
View Full Code Here

                if(!isInstanceOf && activeObject!=null){
                    try {
                        activeObject = field.get(activeObject);
                    } catch (Exception e) {
                        e.printStackTrace();
                        throw new JodbIOException(e);
                    }
                }
            }
            if(!isInstanceOf){
                if( activeObject!=null){
View Full Code Here

TOP

Related Classes of com.mobixess.jodb.core.JodbIOException

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.