⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 currenttransaction.java

📁 这是个爬虫和lucece相结合最好了
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        Trans trans = (Trans) localTrans.get();        if (trans != null && trans.txn != null) {            Transaction parent = closeTxn(trans);            trans.txn.commit();            return parent;        } else {            throw new IllegalStateException("No transaction is active");        }    }    /**     * Aborts the transaction that is active for the current thread for this     * environment and makes the parent transaction (if any) the current     * transaction.     *     * @return the parent transaction or null if the aborted transaction was     * not nested.     *     * @throws DatabaseException if an error occurs aborting the transaction.     * The transaction will still be closed and the parent transaction will     * become the current transaction.     *     * @throws IllegalStateException if no transaction is active for the     * current thread for this environment.     */    public final Transaction abortTransaction()        throws DatabaseException, IllegalStateException {        Trans trans = (Trans) localTrans.get();        if (trans != null && trans.txn != null) {            Transaction parent = closeTxn(trans);            trans.txn.abort();            return parent;        } else {            throw new IllegalStateException("No transaction is active");        }    }    /**     * Returns whether the current transaction is a readUncommitted     * transaction.     */    final boolean isReadUncommitted() {        Trans trans = (Trans) localTrans.get();        if (trans != null && trans.config != null) {            return trans.config.getReadUncommitted();        } else {            return false;        }    }    private Transaction closeTxn(Trans trans) {        localTrans.set(trans.parent);        return (trans.parent != null) ? trans.parent.txn : null;    }    private static class Trans {        private Trans parent;        private Transaction txn;        private TransactionConfig config;        private Trans(Trans parent, TransactionConfig config) {            this.parent = parent;            this.config = config;        }    }    /**     * Opens a cursor for a given database, dup'ing an existing CDB cursor if     * one is open for the current thread.     */    Cursor openCursor(Database db, CursorConfig cursorConfig,                      boolean writeCursor, Transaction txn)        throws DatabaseException {        if (cdbMode) {            CdbCursors cdbCursors = null;            WeakHashMap cdbCursorsMap = (WeakHashMap) localCdbCursors.get();            if (cdbCursorsMap == null) {                cdbCursorsMap = new WeakHashMap();                localCdbCursors.set(cdbCursorsMap);            } else {                cdbCursors = (CdbCursors) cdbCursorsMap.get(db);            }            if (cdbCursors == null) {                cdbCursors = new CdbCursors();                cdbCursorsMap.put(db, cdbCursors);            }            /*             * In CDB mode the cursorConfig specified by the user is ignored             * and only the writeCursor parameter is honored.  This is the only             * meaningful cursor attribute for CDB, and here we count on             * writeCursor flag being set correctly by the caller.             */            List cursors;            CursorConfig cdbConfig;            if (writeCursor) {                if (cdbCursors.readCursors.size() > 0) {                                        /*                     * Although CDB allows opening a write cursor when a read                     * cursor is open, a self-deadlock will occur if a write is                     * attempted for a record that is read-locked; we should                     * avoid self-deadlocks at all costs                     */                    throw new IllegalStateException(                      "cannot open CDB write cursor when read cursor is open");                }                cursors = cdbCursors.writeCursors;                cdbConfig = new CursorConfig();                DbCompat.setWriteCursor(cdbConfig, true);            } else {                cursors = cdbCursors.readCursors;                cdbConfig = null;            }            Cursor cursor;            if (cursors.size() > 0) {                Cursor other = ((Cursor) cursors.get(0));                cursor = other.dup(false);            } else {                cursor = db.openCursor(null, cdbConfig);            }            cursors.add(cursor);            return cursor;        } else {            return db.openCursor(txn, cursorConfig);        }    }    /**     * Duplicates a cursor for a given database.     *     * @param writeCursor true to open a write cursor in a CDB environment, and     * ignored for other environments.     *     * @param samePosition is passed through to Cursor.dup().     *     * @return the open cursor.     *     * @throws DatabaseException if a database problem occurs.     */    Cursor dupCursor(Cursor cursor, boolean writeCursor, boolean samePosition)        throws DatabaseException {        if (cdbMode) {            WeakHashMap cdbCursorsMap = (WeakHashMap) localCdbCursors.get();            if (cdbCursorsMap != null) {                Database db = cursor.getDatabase();                CdbCursors cdbCursors = (CdbCursors) cdbCursorsMap.get(db);                if (cdbCursors != null) {                    List cursors = writeCursor ? cdbCursors.writeCursors                                               : cdbCursors.readCursors;                    if (cursors.contains(cursor)) {                        Cursor newCursor = cursor.dup(samePosition);                        cursors.add(newCursor);                        return newCursor;                    }                }            }            throw new IllegalStateException("cursor to dup not tracked");        } else {            return cursor.dup(samePosition);        }    }    /**     * Closes a cursor.     *     * @param cursor the cursor to close.     *     * @throws DatabaseException if a database problem occurs.     */    void closeCursor(Cursor cursor)        throws DatabaseException {        if (cursor == null) {            return;        }        if (cdbMode) {            WeakHashMap cdbCursorsMap = (WeakHashMap) localCdbCursors.get();            if (cdbCursorsMap != null) {                Database db = cursor.getDatabase();                CdbCursors cdbCursors = (CdbCursors) cdbCursorsMap.get(db);                if (cdbCursors != null) {                    if (cdbCursors.readCursors.remove(cursor) ||                        cdbCursors.writeCursors.remove(cursor)) {                        cursor.close();                        return;                    }                }            }            throw new IllegalStateException(              "closing CDB cursor that was not known to be open");        } else {            cursor.close();        }    }    /**     * Returns true if a CDB cursor is open and therefore a Database write     * operation should not be attempted since a self-deadlock may result.     */    boolean isCDBCursorOpen(Database db)        throws DatabaseException {        if (cdbMode) {            WeakHashMap cdbCursorsMap = (WeakHashMap) localCdbCursors.get();            if (cdbCursorsMap != null) {                CdbCursors cdbCursors = (CdbCursors) cdbCursorsMap.get(db);                if (cdbCursors != null &&                    (cdbCursors.readCursors.size() > 0 ||                     cdbCursors.writeCursors.size() > 0)) {                    return true;                }            }        }        return false;    }    static final class CdbCursors {        List writeCursors = new ArrayList();        List readCursors = new ArrayList();    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -