本文整理匯總了Java中com.sleepycat.je.Database.openCursor方法的典型用法代碼示例。如果您正苦於以下問題:Java Database.openCursor方法的具體用法?Java Database.openCursor怎麽用?Java Database.openCursor使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.sleepycat.je.Database
的用法示例。
在下文中一共展示了Database.openCursor方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getTotalCount
import com.sleepycat.je.Database; //導入方法依賴的package包/類
/**
* 獲取總數
* @param dbName
* @return
* @throws Exception
*/
public int getTotalCount(String dbName) throws Exception {
int count = 0;
Cursor cursor = null;
try {
Database db = this.getDb(dbName);
cursor = db.openCursor(null, null);
DatabaseEntry foundKey = new DatabaseEntry();
DatabaseEntry foundData = new DatabaseEntry();
if (cursor.getLast(foundKey, foundData, LockMode.DEFAULT) == OperationStatus.SUCCESS) {
count = cursor.count();
}
} finally {
if (cursor != null) {
cursor.close();
}
}
return count;
}
示例2: testCursorDupAndCloseDb
import com.sleepycat.je.Database; //導入方法依賴的package包/類
public void testCursorDupAndCloseDb()
throws DatabaseException {
initEnv(false);
DatabaseConfig dbConfig = new DatabaseConfig();
dbConfig.setAllowCreate(true);
Database myDb = exampleEnv.openDatabase(null, "fooDb", dbConfig);
myDb.put(null, new StringDbt("blah"), new StringDbt("blort"));
Cursor cursor = myDb.openCursor(null, null);
OperationStatus status = cursor.getNext(new DatabaseEntry(),
new DatabaseEntry(),
LockMode.DEFAULT);
Cursor cursorDup = cursor.dup(true);
cursor.close();
cursorDup.close();
myDb.close();
}
示例3: initDbs
import com.sleepycat.je.Database; //導入方法依賴的package包/類
/**
* Set up the environment and db.
*/
private void initDbs(int nDumps, Hashtable[] dataMaps)
throws DatabaseException {
EnvironmentConfig envConfig = TestUtils.initEnvConfig();
envConfig.setConfigParam(EnvironmentParams.NODE_MAX.getName(), "6");
envConfig.setAllowCreate(true);
env = new Environment(envHome, envConfig);
/* Make a db and open it. */
for (int i = 0; i < nDumps; i += 1) {
DatabaseConfig dbConfig = new DatabaseConfig();
dbConfig.setAllowCreate(true);
dbConfig.setSortedDuplicates(true);
Database myDb = env.openDatabase(null, dbName + i, dbConfig);
Cursor cursor = myDb.openCursor(null, null);
doLargePut(dataMaps[i], cursor, N_KEYS);
cursor.close();
myDb.close();
}
}
示例4: dumpData
import com.sleepycat.je.Database; //導入方法依賴的package包/類
void dumpData(Database db)
throws DatabaseException {
Cursor cursor = db.openCursor(null, null);
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry data = new DatabaseEntry();
int i = 0;
try {
while (cursor.getNext(key, data, null) ==
OperationStatus.SUCCESS) {
TestData t = new TestData(key, data);
System.out.println(t);
i++;
}
}
finally {
cursor.close();
}
System.out.println("scanned=" + i);
}
示例5: get
import com.sleepycat.je.Database; //導入方法依賴的package包/類
/**
* 通過遊標查詢數據
* 當key為null或者""時,返回數據庫的所有記錄
* @param dbName
* @param key
* @return
* @throws Exception
*/
public List<BerkeleyBean> get(String dbName, String key) throws Exception {
List<BerkeleyBean> resultList = null;
Cursor cursor = null;
try {
// 每次取50條
int itemLimit = 50;
Database db = this.getDb(dbName);
cursor = db.openCursor(null, null);
resultList = new ArrayList<BerkeleyBean>(itemLimit);
byte keyData[] = null;
if (key != null && !"".equals(key.trim())) {
keyData = key.getBytes("utf-8");
}
DatabaseEntry foundKey = new DatabaseEntry(keyData);
DatabaseEntry foundData = new DatabaseEntry();
// 循環取得數據
BerkeleyBean bean = null;
String getKey = null;
byte data[] = null;
while (cursor.getNext(foundKey, foundData, LockMode.DEFAULT) == OperationStatus.SUCCESS) {
getKey = new String(foundKey.getData(), "utf-8");
data = foundData.getData();
bean = new BerkeleyBean();
bean.setKey(getKey);
bean.setValue(data);
resultList.add(bean);
if (itemLimit-- <= 0)
break;
}
} finally {
if (cursor != null) {
cursor.close();
}
}
return resultList;
}
示例6: getCursor
import com.sleepycat.je.Database; //導入方法依賴的package包/類
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));
}
示例7: getCursor
import com.sleepycat.je.Database; //導入方法依賴的package包/類
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));
}
示例8: delete
import com.sleepycat.je.Database; //導入方法依賴的package包/類
private void delete(Database db, String keyString, String dataString)
throws DatabaseException {
DatabaseEntry key = new DatabaseEntry(keyString.getBytes());
DatabaseEntry data = new DatabaseEntry(dataString.getBytes());
Cursor c = db.openCursor(null, null);
assertEquals(OperationStatus.SUCCESS,
c.getSearchBoth(key, data, null));
assertEquals(OperationStatus.SUCCESS, c.delete());
c.close();
}
示例9: getCursor
import com.sleepycat.je.Database; //導入方法依賴的package包/類
@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));
}
示例10: dumpData
import com.sleepycat.je.Database; //導入方法依賴的package包/類
/**
* Print the contents of the databases out for debugging
*/
protected void dumpData(int numDbs)
throws DatabaseException {
DatabaseConfig dbConfig = new DatabaseConfig();
if (btreeComparisonFunction != null) {
dbConfig.setBtreeComparator(btreeComparisonFunction.getClass());
}
dbConfig.setSortedDuplicates(true);
dbConfig.setTransactional(true);
for (int d = 0; d < numDbs; d++) {
Database checkDb = env.openDatabase(null, DB_NAME + d, dbConfig);
Cursor myCursor = checkDb.openCursor(null, null);
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry data = new DatabaseEntry();
OperationStatus status =
myCursor.getFirst(key, data, LockMode.DEFAULT);
while (status == OperationStatus.SUCCESS) {
System.out.println("Database " + d +
" seen = " +
/*
new String(key.getData()) +
"/" +
new String(data.getData()));
*/
TestUtils.dumpByteArray(key.getData()) +
"/" +
TestUtils.dumpByteArray(data.getData()));
status = myCursor.getNext(key, data, LockMode.DEFAULT);
}
myCursor.close();
}
}
示例11: copyDatabaseTo
import com.sleepycat.je.Database; //導入方法依賴的package包/類
/**
* Utility method to copy the contents from one database to another.
*
* @param from ???
* @param to ???
*
* @throws DatabaseException if ???
*/
private void copyDatabaseTo(Database from, Database to) throws DatabaseException {
try (Cursor cursor = from.openCursor(null, null)) {
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry value = new DatabaseEntry();
while (cursor.getNext(key, value, LockMode.DEFAULT) == OperationStatus.SUCCESS) {
to.put(null, key, value);
}
}
to.sync();
}
示例12: dumpData
import com.sleepycat.je.Database; //導入方法依賴的package包/類
/**
* Print the contents of the databases out for debugging
*/
protected void dumpData(int numDbs)
throws DatabaseException {
DatabaseConfig dbConfig = new DatabaseConfig();
if (btreeComparisonFunction != null) {
dbConfig.setBtreeComparator(btreeComparisonFunction.getClass());
}
dbConfig.setSortedDuplicates(true);
dbConfig.setTransactional(true);
for (int d = 0; d < numDbs; d++) {
Database checkDb = env.openDatabase(null, DB_NAME + d, dbConfig);
Cursor myCursor = checkDb.openCursor(null, null);
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry data = new DatabaseEntry();
OperationStatus status =
myCursor.getFirst(key, data, LockMode.DEFAULT);
while (status == OperationStatus.SUCCESS) {
System.out.println("Database " + d +
" seen = " +
/*
new String(key.getData()) +
"/" +
new String(data.getData()));
*/
TestUtils.dumpByteArray(key.getData()) +
"/" +
TestUtils.dumpByteArray(data.getData()));
status = myCursor.getNext(key, data, LockMode.DEFAULT);
}
myCursor.close();
}
}
示例13: setupBINSplitDuringDeletedDINReplay
import com.sleepycat.je.Database; //導入方法依賴的package包/類
/**
* Insert two dups, delete them, and compress to free the BIN entry;
* then fill the BIN with LNs and flush the BIN.
*/
private void setupBINSplitDuringDeletedDINReplay(Database db)
throws DatabaseException {
setStepwiseStart();
int max = 128;
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry data = new DatabaseEntry();
IntegerBinding.intToEntry(0, key);
IntegerBinding.intToEntry(0, data);
assertEquals(OperationStatus.SUCCESS,
db.putNoOverwrite(null, key, data));
IntegerBinding.intToEntry(1, data);
assertEquals(OperationStatus.SUCCESS,
db.putNoDupData(null, key, data));
assertEquals(OperationStatus.SUCCESS,
db.delete(null, key));
env.compress();
Cursor cursor = db.openCursor(null, null);
for (int i = 1; i <= max; i ++) {
IntegerBinding.intToEntry(i, key);
IntegerBinding.intToEntry(0, data);
assertEquals(OperationStatus.SUCCESS,
cursor.putNoOverwrite(key, data));
}
TestUtils.logBINAndIN(env, cursor);
cursor.close();
}
示例14: put
import com.sleepycat.je.Database; //導入方法依賴的package包/類
public void put(String key, String data)
throws RemoteException {
try {
Environment env = null;
Transaction txn = null;
Database db = null;
SecondaryDatabase secDb = null;
Cursor cursor = null;
JEConnection dc = null;
try {
dc = getConnection(JE_ENV);
env = dc.getEnvironment();
DatabaseConfig dbConfig = new DatabaseConfig();
SecondaryConfig secDbConfig = new SecondaryConfig();
dbConfig.setAllowCreate(true);
dbConfig.setTransactional(TRANSACTIONAL);
secDbConfig.setAllowCreate(true);
secDbConfig.setTransactional(TRANSACTIONAL);
secDbConfig.setKeyCreator(new MyKeyCreator());
/*
* Use JEConnection.openDatabase() to obtain a cached Database
* handle. Do not call close() on Database handles obtained
* using this method.
*/
db = dc.openDatabase("db", dbConfig);
secDb = dc.openSecondaryDatabase("secDb", db, secDbConfig);
cursor = db.openCursor(null, null);
cursor.put(new DatabaseEntry(key.getBytes("UTF-8")),
new DatabaseEntry(data.getBytes("UTF-8")));
} finally {
if (cursor != null) {
cursor.close();
}
if (dc != null) {
dc.close();
}
}
} catch (Exception e) {
System.err.println("Failure in put" + e);
}
}
示例15: get
import com.sleepycat.je.Database; //導入方法依賴的package包/類
public String get(String key)
throws RemoteException {
try {
Environment env = null;
Transaction txn = null;
Database db = null;
Cursor cursor = null;
JEConnection dc = null;
try {
dc = getConnection(JE_ENV);
env = dc.getEnvironment();
DatabaseConfig dbConfig = new DatabaseConfig();
dbConfig.setAllowCreate(true);
dbConfig.setTransactional(TRANSACTIONAL);
/*
* Use JEConnection.openDatabase() to obtain a cached Database
* handle. Do not call close() on Database handles obtained
* using this method.
*/
db = dc.openDatabase("db", dbConfig);
cursor = db.openCursor(null, null);
DatabaseEntry data = new DatabaseEntry();
cursor.getSearchKey(new DatabaseEntry(key.getBytes("UTF-8")),
data,
null);
return new String(data.getData(), "UTF-8");
} finally {
if (cursor != null) {
cursor.close();
}
if (dc != null) {
dc.close();
}
}
} catch (Exception e) {
System.err.println("Failure in get" + e);
e.printStackTrace();
}
return null;
}