Package com.sleepycat.je.util

Examples of com.sleepycat.je.util.StringDbt


            DatabaseConfig dbConfig = new DatabaseConfig();
            dbConfig.setTransactional(true);
            dbConfig.setAllowCreate(true);
            db = env.openDatabase(null, "foo", dbConfig);

            StringDbt key = new StringDbt("key1");
            StringDbt data = new StringDbt("data1");
            txnA = env.beginTransaction(null, TransactionConfig.DEFAULT);
            OperationStatus status = db.put(txnA, key, data);
            assertEquals(OperationStatus.SUCCESS, status);

            /*
             * txnA should have a write lock on this record. Now try
             * to read-uncommitted it.
             */
            DatabaseEntry foundKey = new DatabaseEntry();
            DatabaseEntry foundData = new DatabaseEntry();

            /*
             * Make sure we get a deadlock exception without read-uncommitted.
             */
            try {
                db.get(null, key, foundData, LockMode.DEFAULT);
                fail("Should deadlock");
            } catch (DeadlockException e) {
            }

            /*
             * Specify read-uncommitted as a lock mode.
             */
            status = db.get(null, key, foundData, LockMode.READ_UNCOMMITTED);
            assertEquals(OperationStatus.SUCCESS, status);
            assertTrue(Arrays.equals(data.getData(), foundData.getData()));

            status = db.getSearchBoth
                (null, key, data, LockMode.READ_UNCOMMITTED);
            assertEquals(OperationStatus.SUCCESS, status);

            cursor = db.openCursor(null, CursorConfig.DEFAULT);
            status = cursor.getFirst(foundKey, foundData,
                                     LockMode.READ_UNCOMMITTED);
            assertEquals(OperationStatus.SUCCESS, status);
            assertTrue(Arrays.equals(key.getData(), foundKey.getData()));
            assertTrue(Arrays.equals(data.getData(), foundData.getData()));
            cursor.close();

            /*
             * Specify read-uncommitted through a read-uncommitted txn.
             */
            TransactionConfig txnConfig = new TransactionConfig();
            txnConfig.setReadUncommitted(true);
            Transaction readUncommittedTxn =
                env.beginTransaction(null, txnConfig);

            status = db.get
                (readUncommittedTxn, key, foundData, LockMode.DEFAULT);
            assertEquals(OperationStatus.SUCCESS, status);
            assertTrue(Arrays.equals(data.getData(), foundData.getData()));

            status = db.getSearchBoth
                (readUncommittedTxn, key, data,LockMode.DEFAULT);
            assertEquals(OperationStatus.SUCCESS, status);

            cursor = db.openCursor(readUncommittedTxn, CursorConfig.DEFAULT);
            status = cursor.getFirst(foundKey, foundData, LockMode.DEFAULT);
            assertEquals(OperationStatus.SUCCESS, status);
            assertTrue(Arrays.equals(key.getData(), foundKey.getData()));
            assertTrue(Arrays.equals(data.getData(), foundData.getData()));
            cursor.close();
            readUncommittedTxn.abort();

            /*
             * Specify read-uncommitted through a read-uncommitted cursor
             */
            CursorConfig cursorConfig = new CursorConfig();
            cursorConfig.setReadUncommitted(true);
            cursor = db.openCursor(null, cursorConfig);
            status = cursor.getFirst(foundKey, foundData, LockMode.DEFAULT);
            assertEquals(OperationStatus.SUCCESS, status);
            assertTrue(Arrays.equals(key.getData(), foundKey.getData()));
            assertTrue(Arrays.equals(data.getData(), foundData.getData()));

            /*
             * Open through the compatiblity method, should accept dirty
             * read (but ignores it)
             */
 
View Full Code Here


        // Set up sample data
        int nKeys = simpleKeyStrings.length;
        simpleKeys = new StringDbt[nKeys];
        simpleData = new StringDbt[nKeys];
        for (int i = 0; i < nKeys; i++) {
            simpleKeys[i] = new StringDbt(simpleKeyStrings[i]);
            simpleData[i] = new StringDbt(simpleDataStrings[i]);
        }

        // Set up an environment
        EnvironmentConfig envConfig = TestUtils.initEnvConfig();
        envConfig.setTxnNoSync(Boolean.getBoolean(TestUtils.NO_SYNC));
View Full Code Here

  for (int i = 0; i < nKeys; i++) {
      byte[] key = new byte[N_KEY_BYTES];
      TestUtils.generateRandomAlphaBytes(key);
      String keyString = new String(key);
      String dataString = Integer.toString(i);
      putAndVerifyCursor(cursor, new StringDbt(keyString),
                               new StringDbt(dataString), true);
      if (dataMap != null) {
    dataMap.put(keyString, dataString);
      }
  }
    }
View Full Code Here

      TestUtils.generateRandomAlphaBytes(key);
      String keyString = new String(key);
      byte[] dataBytes = new byte[120];
      TestUtils.generateRandomAlphaBytes(dataBytes);
      String dataString = new String(dataBytes);
      putAndVerifyCursor(cursor, new StringDbt(keyString),
                               new StringDbt(dataString), true);
  }
    }
View Full Code Here

      }
      for (int j = 1; j <= nDupesThisTime; j++) {
    byte[] data = new byte[N_KEY_BYTES];
    TestUtils.generateRandomAlphaBytes(data);
    OperationStatus status =
                    putAndVerifyCursor(cursor, new StringDbt(keyString),
                                       new StringDbt(data), putVariant);

    if (verifyCount) {
        assertTrue(cursor.count() == j);
    }
View Full Code Here

  } else {
      status = cursor.putNoOverwrite(key, data);
  }

  if (status == OperationStatus.SUCCESS) {
      StringDbt keyCheck = new StringDbt();
      StringDbt dataCheck = new StringDbt();

      assertEquals(OperationStatus.SUCCESS, cursor.getCurrent
       (keyCheck, dataCheck, LockMode.DEFAULT));
      assertEquals(key.getString(), keyCheck.getString());
      assertEquals(data.getString(), dataCheck.getString());
  }

  return status;
    }
View Full Code Here

  try {
      Transaction txn = env.beginTransaction(null, null);
      XidImpl xid = new XidImpl(1, "TwoPCTest1".getBytes(), null);
      env.setXATransaction(xid, txn);

      StringDbt key = new StringDbt("key");
      StringDbt data = new StringDbt("data");
      db.put(txn, key, data);

      env.prepare(xid);
      env.commit(xid, false);
  } catch (Exception E) {
View Full Code Here

        throws Throwable {

  Transaction txn = env.beginTransaction(null, null);
  XidImpl xid = new XidImpl(1, "TwoPCTest2".getBytes(), null);
  env.setXATransaction(xid, txn);
  StringDbt key = new StringDbt("key");
  StringDbt data = new StringDbt("data");
  db.put(txn, key, data);

  try {
      env.prepare(xid);
      env.prepare(xid);
View Full Code Here

     */
    public void testRollbackNonExistent()
        throws Throwable {

  Transaction txn = env.beginTransaction(null, null);
  StringDbt key = new StringDbt("key");
  StringDbt data = new StringDbt("data");
  db.put(txn, key, data);
  XidImpl xid = new XidImpl(1, "TwoPCTest2".getBytes(), null);

  try {
      env.rollback(xid);
View Full Code Here

     */
    public void testCommitNonExistent()
        throws Throwable {

  Transaction txn = env.beginTransaction(null, null);
  StringDbt key = new StringDbt("key");
  StringDbt data = new StringDbt("data");
  db.put(txn, key, data);
  XidImpl xid = new XidImpl(1, "TwoPCTest2".getBytes(), null);

  try {
      env.commit(xid, false);
View Full Code Here

TOP

Related Classes of com.sleepycat.je.util.StringDbt

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.