| | |
| | | dbCloseLock.readLock().lock(); |
| | | try |
| | | { |
| | | // If the DB has been closed then return immediately. |
| | | if (isDBClosed()) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | txn = dbenv.beginTransaction(); |
| | | db.put(txn, key, data); |
| | | txn.commit(Durability.COMMIT_WRITE_NO_SYNC); |
| | |
| | | try |
| | | { |
| | | db.close(); |
| | | db = null; |
| | | } |
| | | finally |
| | | { |
| | |
| | | Cursor cursor = null; |
| | | try |
| | | { |
| | | // If the DB has been closed then return immediately. |
| | | if (isDBClosed()) |
| | | { |
| | | return 0; |
| | | } |
| | | |
| | | cursor = db.openCursor(null, null); |
| | | DatabaseEntry key = new DatabaseEntry(); |
| | | DatabaseEntry entry = new DatabaseEntry(); |
| | |
| | | */ |
| | | public long count() |
| | | { |
| | | dbCloseLock.readLock().lock(); |
| | | try |
| | | { |
| | | // If the DB has been closed then return immediately. |
| | | if (isDBClosed()) |
| | | { |
| | | return 0L; |
| | | } |
| | | |
| | | return db.count(); |
| | | } |
| | | catch(Exception e) |
| | | catch (Exception e) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | finally |
| | | { |
| | | dbCloseLock.readLock().unlock(); |
| | | } |
| | | return 0L; |
| | | } |
| | | |
| | |
| | | Cursor cursor = null; |
| | | try |
| | | { |
| | | // If the DB has been closed then return immediately. |
| | | if (isDBClosed()) |
| | | { |
| | | return 0; |
| | | } |
| | | |
| | | cursor = db.openCursor(null, null); |
| | | DatabaseEntry key = new DatabaseEntry(); |
| | | DatabaseEntry entry = new DatabaseEntry(); |
| | |
| | | |
| | | try |
| | | { |
| | | // If the DB has been closed then create empty cursor. |
| | | if (isDBClosed()) |
| | | { |
| | | isClosed = true; |
| | | txn = null; |
| | | cursor = null; |
| | | return; |
| | | } |
| | | |
| | | localCursor = db.openCursor(localTxn, null); |
| | | if (startingDraftCN >= 0) |
| | | { |
| | |
| | | dbCloseLock.readLock().lock(); |
| | | try |
| | | { |
| | | // If the DB has been closed then create empty cursor. |
| | | if (isDBClosed()) |
| | | { |
| | | isClosed = true; |
| | | txn = null; |
| | | cursor = null; |
| | | return; |
| | | } |
| | | |
| | | // Create the transaction that will protect whatever done with this |
| | | // write cursor. |
| | | localTxn = dbenv.beginTransaction(); |
| | |
| | | */ |
| | | public String currentValue() |
| | | { |
| | | if (isClosed) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | try |
| | | { |
| | | if (seqnumData != null) |
| | |
| | | */ |
| | | public String currentServiceID() |
| | | { |
| | | if (isClosed) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | try |
| | | { |
| | | if (seqnumData != null) |
| | |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | return null; |
| | | } |
| | | |
| | |
| | | */ |
| | | public int currentKey() |
| | | { |
| | | try |
| | | if (isClosed) |
| | | { |
| | | return -1; |
| | | } |
| | | |
| | | try |
| | | { |
| | | String str = decodeUTF8(key.getData()); |
| | | int draftCN = new Integer(str); |
| | | return draftCN; |
| | | } |
| | | catch(Exception e) |
| | | catch (Exception e) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | return -1; |
| | | } |
| | | |
| | |
| | | */ |
| | | public ChangeNumber currentChangeNumber() |
| | | { |
| | | if (isClosed) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | try |
| | | { |
| | | if (seqnumData != null) |
| | |
| | | */ |
| | | public boolean next() throws DatabaseException |
| | | { |
| | | if (isClosed) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | OperationStatus status = cursor.getNext(key, entry, LockMode.DEFAULT); |
| | | if (status != OperationStatus.SUCCESS) |
| | | { |
| | |
| | | */ |
| | | public void delete() throws DatabaseException |
| | | { |
| | | if (isClosed) |
| | | { |
| | | throw new IllegalStateException("DraftCNDB already closed"); |
| | | } |
| | | |
| | | cursor.delete(); |
| | | } |
| | | |
| | |
| | | */ |
| | | public DatabaseEntry getKey() |
| | | { |
| | | if (isClosed) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | return key; |
| | | } |
| | | } |
| | |
| | | dbCloseLock.writeLock().lock(); |
| | | try |
| | | { |
| | | // If the DB has been closed then return immediately. |
| | | if (isDBClosed()) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | String dbName = db.getDatabaseName(); |
| | | |
| | | // Closing is requested by the Berkeley DB before truncate |
| | | db.close(); |
| | | db = null; // In case there's a failure between here and recreation. |
| | | |
| | | // Clears the changes |
| | | dbenv.clearDb(dbName); |
| | |
| | | dbCloseLock.writeLock().unlock(); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | //Returns {@code true} if the DB is closed. This method assumes that either |
| | | // the db read/write lock has been taken. |
| | | private boolean isDBClosed() |
| | | { |
| | | return db == null; |
| | | } |
| | | } |