Java Code Examples for com.sleepycat.je.Database#openCursor()
The following examples show how to use
com.sleepycat.je.Database#openCursor() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UpgradeFrom7To8.java From qpid-broker-j with Apache License 2.0 | 6 votes |
private int getConfigVersion(Database configVersionDb) { Cursor cursor = null; try { cursor = configVersionDb.openCursor(null, null); DatabaseEntry key = new DatabaseEntry(); DatabaseEntry value = new DatabaseEntry(); while (cursor.getNext(key, value, LockMode.RMW) == OperationStatus.SUCCESS) { return IntegerBinding.entryToInt(value); } return -1; } finally { if (cursor != null) { cursor.close(); } } }
Example 2
Source File: BerkeleyDBManager.java From WebCollector with GNU General Public License v3.0 | 6 votes |
public void list() throws Exception { if (env == null) { open(); } Cursor cursor = null; Database crawldbDatabase = env.openDatabase(null, "crawldb", BerkeleyDBUtils.defaultDBConfig); cursor = crawldbDatabase.openCursor(null, CursorConfig.DEFAULT); DatabaseEntry key = new DatabaseEntry(); DatabaseEntry value = new DatabaseEntry(); while (cursor.getNext(key, value, LockMode.DEFAULT) == OperationStatus.SUCCESS) { CrawlDatum datum = BerkeleyDBUtils.createCrawlDatum(key, value); System.out.println(CrawlDatumFormater.datumToString(datum)); // try { // CrawlDatum datum = BerkeleyDBUtils.createCrawlDatum(key, value); // System.out.println(CrawlDatumFormater.datumToString(datum)); // } catch (Exception ex) { // LOG.info("Exception when generating", ex); // continue; // } } }
Example 3
Source File: Upgrader.java From qpid-broker-j with Apache License 2.0 | 5 votes |
int getSourceVersion(Database versionDb) { int version = -1; Cursor cursor = null; try { cursor = versionDb.openCursor(null, null); DatabaseEntry key = new DatabaseEntry(); DatabaseEntry value = new DatabaseEntry(); while(cursor.getNext(key, value, null) == OperationStatus.SUCCESS) { int ver = IntegerBinding.entryToInt(key); if(ver > version) { version = ver; } } } finally { if(cursor != null) { cursor.close(); } } return version; }
Example 4
Source File: UpgradeFrom7To8.java From qpid-broker-j with Apache License 2.0 | 5 votes |
private long getMaximumMessageId(Database messageMetaDataDb) { Cursor cursor = null; long maximumMessageId = 0; // Our hand-rolled sequences value always began at zero try { cursor = messageMetaDataDb.openCursor(null, null); DatabaseEntry key = new DatabaseEntry(); DatabaseEntry value = new DatabaseEntry(); MessageMetaDataBinding valueBinding = MessageMetaDataBinding.getInstance(); while (cursor.getNext(key, value, LockMode.RMW) == OperationStatus.SUCCESS) { long messageId = LongBinding.entryToLong(key); maximumMessageId = Math.max(messageId, maximumMessageId); } } finally { if (cursor != null) { cursor.close(); } } return maximumMessageId; }
Example 5
Source File: JE_Table.java From tddl5 with Apache License 2.0 | 5 votes |
public ISchematicCursor getCursor(ITransaction txn, IndexMeta indexMeta, String isolation, String actualTableName) throws TddlException { Database db = getDatabase(actualTableName); if (db == null) { throw new IllegalArgumentException("table don't contains indexName:" + actualTableName); } CursorConfig cc = CursorConfig.DEFAULT; LockMode lm = LockMode.DEFAULT; if (txn != null) { com.sleepycat.je.TransactionConfig _config = ((JE_Transaction) txn).config; if (_config.getReadUncommitted()) { cc = CursorConfig.READ_UNCOMMITTED; lm = LockMode.READ_UNCOMMITTED; } else if (_config.getReadCommitted()) { cc = CursorConfig.READ_COMMITTED; // lm = LockMode.READ_COMMITTED; } } else { if (Isolation.READ_COMMITTED.equals(isolation)) { cc = CursorConfig.READ_COMMITTED; // lm = LockMode.READ_COMMITTED;//not support } else if (Isolation.READ_UNCOMMITTED.equals(isolation)) { cc = CursorConfig.READ_UNCOMMITTED; lm = LockMode.READ_UNCOMMITTED; } else if (Isolation.REPEATABLE_READ.equals(isolation)) { // default } else if (Isolation.SERIALIZABLE.equals(isolation)) { // txn_config } } JE_Cursor je_cursor = new JE_Cursor(indexMeta, db.openCursor(txn == null ? null : ((JE_Transaction) txn).txn, cc), lm); if (txn != null) { ((JE_Transaction) txn).addCursor(je_cursor); } return new SchematicCursor(je_cursor, je_cursor.getiCursorMeta(), ExecUtils.getOrderBy(indexMeta)); }
Example 6
Source File: JE_Table.java From tddl5 with Apache License 2.0 | 5 votes |
@Override public ISchematicCursor getCursor(ExecutionContext executionContext, IndexMeta indexMeta, String actualTableName) throws TddlException { Database db = getDatabase(actualTableName); if (db == null) { throw new IllegalArgumentException("table don't contains indexName:" + actualTableName); } ITransaction txn = executionContext.getTransaction(); CursorConfig cc = CursorConfig.DEFAULT; LockMode lm = LockMode.DEFAULT; if (txn != null) { com.sleepycat.je.TransactionConfig _config = ((JE_Transaction) txn).config; if (_config.getReadUncommitted()) { cc = CursorConfig.READ_UNCOMMITTED; lm = LockMode.READ_UNCOMMITTED; } else if (_config.getReadCommitted()) { cc = CursorConfig.READ_COMMITTED; // lm = LockMode.READ_COMMITTED; } } else { cc = CursorConfig.READ_COMMITTED; } JE_Cursor je_cursor = new JE_Cursor(indexMeta, db.openCursor(txn == null ? null : ((JE_Transaction) txn).txn, cc), lm); if (txn != null) { ((JE_Transaction) txn).addCursor(je_cursor); } return new SchematicCursor(je_cursor, je_cursor.getiCursorMeta(), ExecUtils.getOrderBy(indexMeta)); }
Example 7
Source File: JE_Table.java From tddl with Apache License 2.0 | 5 votes |
public ISchematicCursor getCursor(ITransaction txn, IndexMeta indexMeta, String isolation, String actualTableName) throws TddlException { Database db = getDatabase(actualTableName); if (db == null) { throw new TddlException("table don't contains indexName:" + actualTableName); } CursorConfig cc = CursorConfig.DEFAULT; LockMode lm = LockMode.DEFAULT; if (txn != null) { com.sleepycat.je.TransactionConfig _config = ((JE_Transaction) txn).config; if (_config.getReadUncommitted()) { cc = CursorConfig.READ_UNCOMMITTED; lm = LockMode.READ_UNCOMMITTED; } else if (_config.getReadCommitted()) { cc = CursorConfig.READ_COMMITTED; // lm = LockMode.READ_COMMITTED; } } else { if (Isolation.READ_COMMITTED.equals(isolation)) { cc = CursorConfig.READ_COMMITTED; // lm = LockMode.READ_COMMITTED;//not support } else if (Isolation.READ_UNCOMMITTED.equals(isolation)) { cc = CursorConfig.READ_UNCOMMITTED; lm = LockMode.READ_UNCOMMITTED; } else if (Isolation.REPEATABLE_READ.equals(isolation)) { // default } else if (Isolation.SERIALIZABLE.equals(isolation)) { // txn_config } } JE_Cursor je_cursor = new JE_Cursor(indexMeta, db.openCursor(txn == null ? null : ((JE_Transaction) txn).txn, cc), lm); if (txn != null) { ((JE_Transaction) txn).addCursor(je_cursor); } return new SchematicCursor(je_cursor, je_cursor.getiCursorMeta(), ExecUtils.getOrderBy(indexMeta)); }
Example 8
Source File: JE_Table.java From tddl with Apache License 2.0 | 5 votes |
@Override public ISchematicCursor getCursor(ExecutionContext executionContext, IndexMeta indexMeta, String actualTableName) throws TddlException { Database db = getDatabase(actualTableName); if (db == null) { throw new TddlException("table don't contains indexName:" + actualTableName); } ITransaction txn = executionContext.getTransaction(); CursorConfig cc = CursorConfig.DEFAULT; LockMode lm = LockMode.DEFAULT; if (txn != null) { com.sleepycat.je.TransactionConfig _config = ((JE_Transaction) txn).config; if (_config.getReadUncommitted()) { cc = CursorConfig.READ_UNCOMMITTED; lm = LockMode.READ_UNCOMMITTED; } else if (_config.getReadCommitted()) { cc = CursorConfig.READ_COMMITTED; // lm = LockMode.READ_COMMITTED; } } else { cc = CursorConfig.READ_COMMITTED; } JE_Cursor je_cursor = new JE_Cursor(indexMeta, db.openCursor(txn == null ? null : ((JE_Transaction) txn).txn, cc), lm); if (txn != null) { ((JE_Transaction) txn).addCursor(je_cursor); } return new SchematicCursor(je_cursor, je_cursor.getiCursorMeta(), ExecUtils.getOrderBy(indexMeta)); }
Example 9
Source File: BerkeleyDBManager.java From WebCollector with GNU General Public License v3.0 | 5 votes |
@Override public void merge() throws Exception { LOG.info("start merge"); Database crawldbDatabase = env.openDatabase(null, "crawldb", BerkeleyDBUtils.defaultDBConfig); /*合并fetch库*/ LOG.info("merge fetch database"); Database fetchDatabase = env.openDatabase(null, "fetch", BerkeleyDBUtils.defaultDBConfig); Cursor fetchCursor = fetchDatabase.openCursor(null, null); DatabaseEntry key = new DatabaseEntry(); DatabaseEntry value = new DatabaseEntry(); while (fetchCursor.getNext(key, value, LockMode.DEFAULT) == OperationStatus.SUCCESS) { crawldbDatabase.put(null, key, value); } fetchCursor.close(); fetchDatabase.close(); /*合并link库*/ LOG.info("merge link database"); Database linkDatabase = env.openDatabase(null, "link", BerkeleyDBUtils.defaultDBConfig); Cursor linkCursor = linkDatabase.openCursor(null, null); while (linkCursor.getNext(key, value, LockMode.DEFAULT) == OperationStatus.SUCCESS) { if (!(crawldbDatabase.get(null, key, value, LockMode.DEFAULT) == OperationStatus.SUCCESS)) { crawldbDatabase.put(null, key, value); } } linkCursor.close(); linkDatabase.close(); LOG.info("end merge"); crawldbDatabase.close(); env.removeDatabase(null, "fetch"); LOG.debug("remove fetch database"); env.removeDatabase(null, "link"); LOG.debug("remove link database"); }
Example 10
Source File: UpgradeFrom5To6.java From qpid-broker-j with Apache License 2.0 | 4 votes |
/** * @return a (sorted) map of offset -> data for the given message id */ private SortedMap<Integer, byte[]> getMessageData(final long messageId, final Database oldDatabase) { TreeMap<Integer, byte[]> data = new TreeMap<Integer, byte[]>(); Cursor cursor = oldDatabase.openCursor(null, CursorConfig.READ_COMMITTED); try { DatabaseEntry contentKeyEntry = new DatabaseEntry(); DatabaseEntry value = new DatabaseEntry(); CompoundKeyBinding binding = new CompoundKeyBinding(); binding.objectToEntry(new CompoundKey(messageId, 0), contentKeyEntry); OperationStatus status = cursor.getSearchKeyRange(contentKeyEntry, value, LockMode.DEFAULT); OldDataBinding dataBinding = new OldDataBinding(); while (status == OperationStatus.SUCCESS) { CompoundKey compoundKey = binding.entryToObject(contentKeyEntry); long id = compoundKey.getMessageId(); if (id != messageId) { // we have exhausted all chunks for this message id, break break; } int offsetInMessage = compoundKey.getOffset(); OldDataValue dataValue = dataBinding.entryToObject(value); data.put(offsetInMessage, dataValue.getData()); status = cursor.getNext(contentKeyEntry, value, LockMode.DEFAULT); } } finally { cursor.close(); } return data; }
Example 11
Source File: TestKDTreeSplit.java From bboxdb with Apache License 2.0 | 4 votes |
/** * Split the region * @param sampleSize * @param numberOfElements * @return */ private void splitRegion(final Hyperrectangle boundingBoxToSplit) { final int parentBoxDimension = boxDimension.get(boundingBoxToSplit) % dataDimension; final double splitPosition = getSplitPosition(boundingBoxToSplit, parentBoxDimension); final Hyperrectangle leftBBox = boundingBoxToSplit.splitAndGetLeft(splitPosition, parentBoxDimension, true); final Hyperrectangle rightBBox = boundingBoxToSplit.splitAndGetRight(splitPosition, parentBoxDimension, false); // Write the box dimension boxDimension.put(leftBBox, parentBoxDimension + 1); boxDimension.put(rightBBox, parentBoxDimension + 1); // Insert new boxes and remove old one elements.put(leftBBox, buildNewDatabase()); elements.put(rightBBox, buildNewDatabase()); final Database database = elements.remove(boundingBoxToSplit); // Data to redistribute final Cursor cursor = database.openCursor(null, null); final DatabaseEntry foundKey = new DatabaseEntry(); final DatabaseEntry foundData = new DatabaseEntry(); while(cursor.getNext(foundKey, foundData, LockMode.DEFAULT) == OperationStatus.SUCCESS) { final Hyperrectangle box = Hyperrectangle.fromByteArray(foundData.getData()); boolean redistributed = false; if(leftBBox.intersects(box)) { elements.get(leftBBox).put(null, foundKey, foundData); elementCounter.computeIfAbsent(leftBBox, l -> new AtomicLong(0)).incrementAndGet(); redistributed = true; } if(rightBBox.intersects(box)) { elements.get(rightBBox).put(null, foundKey, foundData); elementCounter.computeIfAbsent(rightBBox, l -> new AtomicLong(0)).incrementAndGet(); redistributed = true; } if(! redistributed) { System.err.println("Unable to redistribute: " + box + " left / right " + leftBBox + " " + rightBBox); } } cursor.close(); // Name needs to be fetched before database is closed final String databaseName = database.getDatabaseName(); database.close(); dbEnv.removeDatabase(null, databaseName); }