Package org.chaidb.db.exception

Examples of org.chaidb.db.exception.ChaiDBException


        TransactionImpl child;
        switch (isTxnValid(TXN_ABORTING)) {
            case 0:
                break;
            case 1:
                throw new ChaiDBException(ErrorCode.IN_RECOVER_PROCESS);
            case 2:
                throw new ChaiDBException(ErrorCode.RECOMMITED_FAILURE);
            case 3:
                throw new ChaiDBException(ErrorCode.REABORTTED_FAILURE);
            case 4:
                break;
            case 5:
                break;
        }
View Full Code Here


        Transaction child, child1;
        switch (isTxnValid(TXN_COMMITING)) {
            case 0:
                break;
            case 1:
                throw new ChaiDBException(ErrorCode.IN_RECOVER_PROCESS);
            case 2:
                throw new ChaiDBException(ErrorCode.RECOMMITED_FAILURE);
            case 3:
                throw new ChaiDBException(ErrorCode.REABORTTED_FAILURE);
            case 4:
                break;
            case 5:
                break;
        }
        //Set status to committed
        status = TXN_COMMITING;

        /*
         * Commit any unresolved children.  If there's an error, abort any
         * unresolved children and the parent.
         */
        Enumeration childTxns = this.getChilds().elements();
        while (childTxns.hasMoreElements()) {
            child = (Transaction) childTxns.nextElement();
            try {
                child.commit();
            } catch (ChaiDBException txnAbortedEx) {  //If one child txn isn't committed successfully, all childs txns will be aborted.
                logger.error(txnAbortedEx);
                Enumeration childTxns1 = this.getChilds().elements();
                while (childTxns1.hasMoreElements()) {
                    child1 = (Transaction) childTxns1.nextElement();
                    try {
                        child1.abort();
                    } catch (ChaiDBException e) {
                        logger.error(e);
                        // preserving all the previous abort reports -ranjeet
                        ChaiDBException highLevel = new ChaiDBException(ErrorCode.ABORT_FAILURE, txnAbortedEx);
                        throw highLevel;
                    }
                }//end while
                try {
                    this.abort(); // Abort itself parent.
                } catch (ChaiDBException e) {
                    logger.error(e);
                    // preserving all the previous abort reports -ranjeet
                    ChaiDBException highLevel = new ChaiDBException(ErrorCode.ABORT_FAILURE, txnAbortedEx);
                    throw highLevel;
                }
                throw new ChaiDBException(ErrorCode.COMMIT_FAILURE, txnAbortedEx);
            }//end try
        }//end while
        try {
            //At first we precommit the memory log
            lnkTransactionManager.getMemLogManager().preCommit(txnId);

            /*
             * If there are any log records, write a log record and sync the log,
             * else do no log writes.  If the commit is for a child transaction,
             * we do not need to commit the child synchronously since it may still
             * abort (if its parent aborts), and otherwise its parent or ultimate
             * ancestor will write synchronously.
             *
             * I'd rather return a logging error than a flag-wrong error, so if
             * the log routines fail, set "ret" without regard to previous value.
             */
            if (!(lastLsn.getFileId() == 0)) {
                bpm.flushChangedDocRoot(kCtx);
                if (this.parent == null) {
                    int flag = 0;
                    if ((this.flags & Transaction.TXN_NOSYNC) != 0) {
                        flag = Transaction.TXN_NOSYNC;
                    } else if ((this.flags & Transaction.TXN_SYNC) != 0) {
                        flag = Transaction.TXN_SYNC;
                    }

                    //Comment it out. Maybe it is caused long txn.
                    //The commit log record has inserted into log file.
                    //But before it will be removed from active txn list, there
                    //are some activity need to done, include memlogMgr.commit(),
                    //release resources, put locks etc. Once one of activity
                    //throw exception, the txn will never be removed from active txn list.
                    //I will move it into endTxn.

                    //(new TxnRegopLogRecord(TXN_COMMIT,(new Date()).getTime(),this.txnId)).log(flag);
                } else { /* Log the commit in the parent! */

                    (new TxnChildLogRecord(txnId, lastLsn, this.parent.getTxnId())).log(); //pending ?!
                    parent.setFlags(TXN_CHILDCOMMIT);
                }

            } //end if (!(lastLsn.getFileId() == 0))
            lnkTransactionManager.getMemLogManager().commit(txnId);
        } catch (ChaiDBException ie) {
            logger.error(ie);
            throw ie;
        } catch (Exception excp) {
            logger.error(excp);
            throw new ChaiDBException(ErrorCode.TXN_ERROR_BASE, excp);
        } finally {
            status = Transaction.TXN_RUNNING;
        }

        endTxn(isCommit);
View Full Code Here

            logRecord = lnkTransactionManager.getLogManager().get(keyLsn);
            try {
                logRecord.recover(LogRecord.UNDO);
            } catch (ChaiDBException ie) {
                logger.error(ie);
                throw new ChaiDBException(ErrorCode.UNDO_FAILURE, ie);
            }

        }//End for
    }
View Full Code Here

                dir = dir.substring(0, dir.lastIndexOf(File.separator));
                new File(dir).mkdirs();
                this.file = new RandomAccessFile(file, "rws");
            } catch (Exception e) {
                String details = "Open for file " + file.getName() + " failed. " + e.toString() + ".";
                throw new ChaiDBException(0, details);
            }
        } catch (IOException ioe) {
            String details = "Open for file " + file.getName() + " failed. " + ioe.toString() + ".";
            throw new ChaiDBException(0, details);
        }
    }
View Full Code Here

    private void close() throws ChaiDBException {
        try {
            file.close();
        } catch (IOException ioe) {
            String details = "Close for the state file failed. " + ioe.toString() + ".";
            throw new ChaiDBException(0, details);
        }
    }
View Full Code Here

            open(DB_STATE_FILE, "r");
            file.seek((long) stateIndex);
            file.read(state);
        } catch (IOException e) {
            String details = "The read state operation failed. " + e.toString() + ".";
            throw new ChaiDBException(0, details);
        } finally {
            close();
        }
    }
View Full Code Here

            open(DB_STATE_FILE, "rws");
            file.seek((long) stateIndex);
            file.write(state);
        } catch (IOException ioe) {
            String details = "The write state operation failed. " + ioe.toString() + ".";
            throw new ChaiDBException(0, details);
        } finally {
            close();
        }
    }
View Full Code Here

     */
    public boolean getNeedLog() throws ChaiDBException {
        if (txn == null)     // transaction turn off
            return false;
        else if (txn.getTxnId() == TransactionManager.TXN_INVALID_ID)
            throw new ChaiDBException(ErrorCode.DB_SERVER_SHUTDOWN);
        else return true;
    }
View Full Code Here

     *
     * @param treeName The tree id which the lock should be associted with.
     * @param lock     The lock should be associated with special tree id.
     */
    public void addLock(String treeName, Lock lock) throws ChaiDBException {
        if (lock == null) throw new ChaiDBException(ErrorCode.LOCK_NULL, "The lock passed by parameter is null");
//        if (!treeid2lock.containsKey(treeId)) {
//            treeid2lock.put(treeId, lock);
//        } else { //permit to add multi-locks on same lock for same identity
//            Lock tmpLock = (Lock)treeid2lock.get(treeId);
//            if (tmpLock != lock)
View Full Code Here

    public Lock getLock(String treeName) throws ChaiDBException {
        LinkedList lock;
        if (treeid2lock.containsKey(treeName)) {
            lock = (LinkedList) treeid2lock.get(treeName);
            if (lock == null || lock.size() == 0)
                throw new ChaiDBException(ErrorCode.LOCK_NULL, "The lock is null in the entry which treeid is exist.");
            else {
                if (lock.size() == 1) {
                    removeLock(treeName);
                }
                return (Lock) lock.removeFirst();
View Full Code Here

TOP

Related Classes of org.chaidb.db.exception.ChaiDBException

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.