Package com.sleepycat.je

Examples of com.sleepycat.je.SecondaryCursor


{ return fetchSecArray(key, rangeFlag, 10); }

public DatabaseEntry[] fetchSecArray (String key, boolean rangeFlag, int RANGE)
{
  ArrayList<DatabaseEntry> al = new ArrayList<DatabaseEntry>();
  SecondaryCursor secCursor = null;
  DatabaseEntry[] dbData = null;
  try
 
   DatabaseEntry dbKey = new DatabaseEntry( key.getBytes("UTF-8") );
   DatabaseEntry dbe = new DatabaseEntry();
   secCursor = getSecDB().openSecondaryCursor(null, null);
   OperationStatus ostat = (rangeFlag) ? secCursor.getSearchKeyRange(dbKey, dbe, LockMode.DEFAULT):
    secCursor.getSearchKey(dbKey, dbe, LockMode.DEFAULT);

   int numRecords = 0;
   if (secCursor.count() >= 1)
   { while ( (ostat == OperationStatus.SUCCESS) && (numRecords < RANGE) )
   { al.add(dbe); dbe = new DatabaseEntry();
   ostat = (rangeFlag) ? secCursor.getNext(dbKey, dbe, LockMode.DEFAULT):
    secCursor.getNextDup(dbKey, dbe, LockMode.DEFAULT);
   numRecords++;
   }
   }
   else { al.add(dbe);
  }
  catch (RuntimeException re)
  { logger.error("Runtime error: Could not fetch documents with sec. key " + key + " " + re.getMessage())}
  catch (UnsupportedEncodingException ue)
  { logger.error("Unsupported encoding: Could not fetch documents with sec. key " + key + " " + ue.getMessage())}
  catch (DatabaseException de)
  { logger.error("Database error: Could not fetch documents with sec. key " + key + " " + de.getMessage())}
  finally
  { try { if (secCursor != null) secCursor.close(); } catch (DatabaseException dbe) { } }

  if (al.size() >= 1)
  { dbData = new DatabaseEntry[al.size()];
  for (int i = 0; i < al.size(); i++) dbData[i] = (DatabaseEntry) al.get(i);
  }
View Full Code Here


        CursorConfig cursorConfig = null;
        if (concurrentDB) {
            cursorConfig = new CursorConfig();
            DbCompat.setWriteCursor(cursorConfig, true);
        }
        SecondaryCursor cursor = db.openSecondaryCursor(txn, cursorConfig);
        try {
            status = cursor.getSearchBoth
                (keyEntry, pkeyEntry, dataEntry,
                 locking ? LockMode.RMW : null);
            if (status == OperationStatus.SUCCESS) {
                status = cursor.delete();
            }
            failed = false;
        } finally {
            cursor.close();
            if (autoCommit) {
                if (failed) {
                    txn.abort();
                } else {
                    txn.commit();
View Full Code Here

      Transaction tran = env.beginTransaction(null, null);
      DatabaseEntry key = new DatabaseEntry();
      DatabaseEntry pKey = new DatabaseEntry();
      DatabaseEntry data = new DatabaseEntry();
      try {
        SecondaryCursor cursor = db.openSecondaryCursor(tran, null);
        try {
          while (cursor.getNext(key, pKey, data, null) == OperationStatus.SUCCESS) {
            cursor.delete();
            dataBinding.entryToObject(data).remove();
          }
        } finally {
          cursor.close();
        }
        tran.commit();
      } catch (Exception e) {
        tran.abort();
        throw e;
View Full Code Here

          IMetaData o = keys[i];
          SecondaryDatabase db = dbKeys.get(o.getName());
          if (db == null) {
            return;
          }
          SecondaryCursor cursor = db.openSecondaryCursor(null, null);
          key.setData(o.getBytes());
          cursor.getSearchKey(key, data, null);
          cursors[i] = cursor;
        }
        JoinCursor joinCursor = dbMain.join(cursors, null);
        try {
          while (joinCursor.getNext(key, null) == OperationStatus.SUCCESS) {
            entries.add(key);
            key = new DatabaseEntry();
          }
        } finally {
          joinCursor.close();
        }
      } finally {
        for (SecondaryCursor cursor : cursors) {
          if (cursor == null) {
            break;
          }
          cursor.close();
        }
      }
      Transaction tran = env.beginTransaction(null, null);
      try {
        Cursor cursor = dbMain.openCursor(tran, null);
        try {
          for (DatabaseEntry entry : entries) {
            cursor.getSearchKey(entry, data, null);
            cursor.delete();
            dataBinding.entryToObject(data).remove();
          }
        } finally {
          cursor.close();
        }
        tran.commit();
      } catch (Exception e) {
        tran.abort();
        throw e;
View Full Code Here

      Transaction tran = env.beginTransaction(null, null);
      DatabaseEntry key = new DatabaseEntry(data.getBytes());
      DatabaseEntry pKey = new DatabaseEntry();
      DatabaseEntry pData = new DatabaseEntry();
      try {
        SecondaryCursor cursor = db.openSecondaryCursor(tran, null);
        try {
          OperationStatus ret = cursor.getSearchKey(key, pKey, pData, null);
          while (ret == OperationStatus.SUCCESS) {
            cursor.delete();
            dataBinding.entryToObject(pData).remove();
            ret = cursor.getNextDup(pKey, pData, null);
          }
        } finally {
          cursor.close();
        }
        tran.commit();
      } catch (Exception e) {
        tran.abort();
        throw e;
View Full Code Here

        /* Cursor operations. */

        txnCommit(txn);
        txn = txnBeginCursor();

        SecondaryCursor cursor = null;
        try {
            cursor = secDb.openSecondaryCursor(txn, null);

            try {
                cursor.getSearchBoth(key, data, LockMode.DEFAULT);
                fail();
            } catch (UnsupportedOperationException expected) { }

            try {
                cursor.getSearchBothRange(key, data, LockMode.DEFAULT);
                fail();
            } catch (UnsupportedOperationException expected) { }

            try {
                cursor.putCurrent(data);
                fail();
            } catch (UnsupportedOperationException expected) { }

            try {
                cursor.put(key, data);
                fail();
            } catch (UnsupportedOperationException expected) { }

            try {
                cursor.putNoOverwrite(key, data);
                fail();
            } catch (UnsupportedOperationException expected) { }

            try {
                cursor.putNoDupData(key, data);
                fail();
            } catch (UnsupportedOperationException expected) { }
        } finally {
            if (cursor != null) {
                cursor.close();
            }
        }

        txnCommit(txn);
        secDb.close();
View Full Code Here

        /* Cursor operations. */

        txnCommit(txn);
        txn = txnBeginCursor();
        Cursor cursor = priDb.openCursor(txn, null);
        SecondaryCursor secCursor = secDb.openSecondaryCursor(txn, null);

        assertEquals(OperationStatus.SUCCESS,
                     cursor.getSearchKey(key, found, null));
        assertEquals(OperationStatus.SUCCESS,
                     cursor.getSearchBoth(key, data, null));
        assertEquals(OperationStatus.SUCCESS,
                     cursor.getSearchKeyRange(key, found, null));
        assertEquals(OperationStatus.SUCCESS,
                     cursor.getSearchBothRange(key, data, null));
        assertEquals(OperationStatus.SUCCESS,
                     cursor.getFirst(found, found2, null));
        assertEquals(OperationStatus.SUCCESS,
                     cursor.getNext(found, found2, null));
        assertEquals(OperationStatus.SUCCESS,
                     cursor.getPrev(found, found2, null));
        assertEquals(OperationStatus.NOTFOUND,
                     cursor.getNextDup(found, found2, null));
        assertEquals(OperationStatus.NOTFOUND,
                     cursor.getPrevDup(found, found2, null));
        assertEquals(OperationStatus.SUCCESS,
                     cursor.getNextNoDup(found, found2, null));
        assertEquals(OperationStatus.SUCCESS,
                     cursor.getPrevNoDup(found, found2, null));
        assertEquals(OperationStatus.SUCCESS,
                     cursor.getLast(found, found2, null));

        assertEquals(OperationStatus.SUCCESS,
                     secCursor.getSearchKey(secKey, found, null));
        assertEquals(OperationStatus.SUCCESS,
                     secCursor.getSearchKeyRange(secKey, found, null));
        assertEquals(OperationStatus.SUCCESS,
                     secCursor.getFirst(found, found2, null));
        assertEquals(OperationStatus.SUCCESS,
                     secCursor.getNext(found, found2, null));
        assertEquals(OperationStatus.SUCCESS,
                     secCursor.getPrev(found, found2, null));
        assertEquals(OperationStatus.SUCCESS,
                     secCursor.getNextDup(found, found2, null));
        assertEquals(OperationStatus.SUCCESS,
                     secCursor.getPrevDup(found, found2, null));
        assertEquals(OperationStatus.SUCCESS,
                     secCursor.getNextNoDup(found, found2, null));
        assertEquals(OperationStatus.SUCCESS,
                     secCursor.getPrevNoDup(found, found2, null));
        assertEquals(OperationStatus.SUCCESS,
                     secCursor.getLast(found, found2, null));

        assertEquals(OperationStatus.SUCCESS,
                     secCursor.getSearchKey(secKey, found, found2, null));
        assertEquals(OperationStatus.SUCCESS,
                     secCursor.getSearchBoth(secKey, data, found, null));
        assertEquals(OperationStatus.SUCCESS,
                     secCursor.getSearchKeyRange(secKey, found, found2, null));
        assertEquals(OperationStatus.SUCCESS,
                     secCursor.getSearchBothRange(secKey, data, found, null));
        assertEquals(OperationStatus.SUCCESS,
                     secCursor.getFirst(found, found2, found3, null));
        assertEquals(OperationStatus.SUCCESS,
                     secCursor.getNext(found, found2, found3, null));
        assertEquals(OperationStatus.SUCCESS,
                     secCursor.getPrev(found, found2, found3, null));
        assertEquals(OperationStatus.SUCCESS,
                     secCursor.getNextDup(found, found2, found3, null));
        assertEquals(OperationStatus.SUCCESS,
                     secCursor.getPrevDup(found, found2, found3, null));
        assertEquals(OperationStatus.SUCCESS,
                     secCursor.getNextNoDup(found, found2, found3, null));
        assertEquals(OperationStatus.SUCCESS,
                     secCursor.getPrevNoDup(found, found2, found3, null));
        assertEquals(OperationStatus.SUCCESS,
                     secCursor.getLast(found, found2, found3, null));

        secCursor.close();
        cursor.close();
        txnCommit(txn);
        secDb.close();
        priDb.close();
        env.close();
View Full Code Here

                     priDb.put(txn, key, data));

        txnCommit(txn);
        txn = txnBeginCursor();
        Cursor cursor = priDb.openCursor(txn, null);
        SecondaryCursor secCursor = secDb.openSecondaryCursor(txn, null);

        /* Check the uninitialized state for certain operations. */

        try {
            cursor.count();
            fail();
        } catch (DatabaseException expected) {}
        try {
            cursor.delete();
            fail();
        } catch (DatabaseException expected) {}
        try {
            cursor.putCurrent(data);
            fail();
        } catch (DatabaseException expected) {}
        try {
            cursor.getCurrent(key, data, null);
            fail();
        } catch (DatabaseException expected) {}
        try {
            cursor.getNextDup(found, found2, null);
            fail();
        } catch (DatabaseException expected) {}
        try {
            cursor.getPrevDup(found, found2, null);
            fail();
        } catch (DatabaseException expected) {}

        try {
            secCursor.count();
            fail();
        } catch (DatabaseException expected) {}
        try {
            secCursor.delete();
            fail();
        } catch (DatabaseException expected) {}
        try {
            secCursor.getCurrent(key, data, null);
            fail();
        } catch (DatabaseException expected) {}
        try {
            secCursor.getNextDup(found, found2, null);
            fail();
        } catch (DatabaseException expected) {}
        try {
            secCursor.getPrevDup(found, found2, null);
            fail();
        } catch (DatabaseException expected) {}

        /* Initialize, then close, then check all operations. */

        assertEquals(OperationStatus.SUCCESS,
                     cursor.getSearchKey(key, found, null));
        assertEquals(OperationStatus.SUCCESS,
                     secCursor.getSearchKey(secKey, found, null));
        secCursor.close();
        cursor.close();

        try {
            cursor.close();
            fail();
        } catch (DatabaseException expected) {}
        try {
            cursor.count();
            fail();
        } catch (DatabaseException expected) {}
        try {
            cursor.delete();
            fail();
        } catch (DatabaseException expected) {}
        try {
            cursor.put(key, data);
            fail();
        } catch (DatabaseException expected) {}
        try {
            cursor.putNoOverwrite(key, data);
            fail();
        } catch (DatabaseException expected) {}
        try {
            cursor.putNoDupData(key, data);
            fail();
        } catch (DatabaseException expected) {}
        try {
            cursor.putCurrent(data);
            fail();
        } catch (DatabaseException expected) {}
        try {
            cursor.getCurrent(key, data, null);
            fail();
        } catch (DatabaseException expected) {}
        try {
            cursor.getSearchKey(key, found, null);
            fail();
        } catch (DatabaseException expected) {}
        try {
            cursor.getSearchBoth(key, data, null);
            fail();
        } catch (DatabaseException expected) {}
        try {
            cursor.getSearchKeyRange(key, found, null);
            fail();
        } catch (DatabaseException expected) {}
        try {
            cursor.getSearchBothRange(key, data, null);
            fail();
        } catch (DatabaseException expected) {}
        try {
            cursor.getFirst(found, found2, null);
            fail();
        } catch (DatabaseException expected) {}
        try {
            cursor.getNext(found, found2, null);
            fail();
        } catch (DatabaseException expected) {}
        try {
            cursor.getPrev(found, found2, null);
            fail();
        } catch (DatabaseException expected) {}
        try {
            cursor.getNextDup(found, found2, null);
            fail();
        } catch (DatabaseException expected) {}
        try {
            cursor.getPrevDup(found, found2, null);
            fail();
        } catch (DatabaseException expected) {}
        try {
            cursor.getNextNoDup(found, found2, null);
            fail();
        } catch (DatabaseException expected) {}
        try {
            cursor.getPrevNoDup(found, found2, null);
            fail();
        } catch (DatabaseException expected) {}
        try {
            cursor.getLast(found, found2, null);
            fail();
        } catch (DatabaseException expected) {}

        try {
            secCursor.close();
            fail();
        } catch (DatabaseException expected) {}
        try {
            secCursor.count();
            fail();
        } catch (DatabaseException expected) {}
        try {
            secCursor.delete();
            fail();
        } catch (DatabaseException expected) {}
        try {
            secCursor.getCurrent(key, data, null);
            fail();
        } catch (DatabaseException expected) {}
        try {
            secCursor.getSearchKey(secKey, found, null);
            fail();
        } catch (DatabaseException expected) {}
        try {
            secCursor.getSearchKeyRange(secKey, found, null);
            fail();
        } catch (DatabaseException expected) {}
        try {
            secCursor.getFirst(found, found2, null);
            fail();
        } catch (DatabaseException expected) {}
        try {
            secCursor.getNext(found, found2, null);
            fail();
        } catch (DatabaseException expected) {}
        try {
            secCursor.getPrev(found, found2, null);
            fail();
        } catch (DatabaseException expected) {}
        try {
            secCursor.getNextDup(found, found2, null);
            fail();
        } catch (DatabaseException expected) {}
        try {
            secCursor.getPrevDup(found, found2, null);
            fail();
        } catch (DatabaseException expected) {}
        try {
            secCursor.getNextNoDup(found, found2, null);
            fail();
        } catch (DatabaseException expected) {}
        try {
            secCursor.getPrevNoDup(found, found2, null);
            fail();
        } catch (DatabaseException expected) {}
        try {
            secCursor.getLast(found, found2, null);
            fail();
        } catch (DatabaseException expected) {}

        txnCommit(txn);
        secDb.close();
View Full Code Here

        }

        txnCommit(txn);
        txn = txnBeginCursor();

        SecondaryCursor c0 = secDb0.openSecondaryCursor(txn, null);
        SecondaryCursor c1 = secDb1.openSecondaryCursor(txn, null);
        SecondaryCursor c2 = secDb2.openSecondaryCursor(txn, null);
        SecondaryCursor[] cursors = {c0, c1, c2};

        for (int i = 0; i < joinSet.length; i += 2) {
            int[] indexKeys = joinSet[i];
            int[] priKeys = joinSet[i + 1];
            String prefix = name + " row=" + i;
            for (int k = 0; k < 3; k += 1) {
                String msg = prefix + " k=" + k + " ikey=" + indexKeys[k];
                setKey(key, indexKeys[k]);
                status = cursors[k].getSearchKey(key, data,
                                                 LockMode.DEFAULT);
                assertEquals(msg, OperationStatus.SUCCESS, status);
            }
            for (int j = 0; j < 2; j += 1) {
                boolean withData = (j == 0);
                JoinConfig config = (j == 0) ? null : joinConfigNoSort;
                JoinCursor jc = priDb.join(cursors, config);
                assertSame(priDb, jc.getDatabase());
                for (int k = 0; k < priKeys.length; k += 1) {
                    String msg = prefix + " k=" + k + " pkey=" + priKeys[k];
                    if (withData) {
                        status = jc.getNext(key, data, LockMode.DEFAULT);
                    } else {
                        status = jc.getNext(key, LockMode.DEFAULT);
                    }
                    assertEquals(msg, OperationStatus.SUCCESS, status);
                    assertEquals(msg, priKeys[k], (int) key.getData()[0]);
                    if (withData) {
                        boolean dataFound = false;
                        for (int m = 0; m < dataSet.length; m += 2) {
                            int[] vals = dataSet[m];
                            int priKey = dataSet[m + 1][0];
                            if (priKey == priKeys[k]) {
                                for (int n = 0; n < 3; n += 1) {
                                    assertEquals(msg, vals[n],
                                                 (int) data.getData()[n]);
                                    dataFound = true;;
                                }
                            }
                        }
                        assertTrue(msg, dataFound);
                    }
                }
                String msg = prefix + " no more expected";
                if (withData) {
                    status = jc.getNext(key, data, LockMode.DEFAULT);
                } else {
                    status = jc.getNext(key, LockMode.DEFAULT);
                }
                assertEquals(msg, OperationStatus.NOTFOUND, status);

                Cursor[] sorted = DbInternal.getSortedCursors(jc);
                assertEquals(CURSOR_ORDER.length, sorted.length);
                if (config == joinConfigNoSort) {
                    Database db0 = sorted[0].getDatabase();
                    Database db1 = sorted[1].getDatabase();
                    Database db2 = sorted[2].getDatabase();
                    assertSame(db0, secDb0);
                    assertSame(db1, secDb1);
                    assertSame(db2, secDb2);
                } else if (setNum == CURSOR_ORDER_SET) {
                    Database db0 = sorted[CURSOR_ORDER[0]].getDatabase();
                    Database db1 = sorted[CURSOR_ORDER[1]].getDatabase();
                    Database db2 = sorted[CURSOR_ORDER[2]].getDatabase();
                    assertSame(db0, secDb0);
                    assertSame(db1, secDb1);
                    assertSame(db2, secDb2);
                }
                jc.close();
            }
        }

        c0.close();
        c1.close();
        c2.close();
        txnCommit(txn);

        secDb0.close();
        secDb1.close();
        secDb2.close();
View Full Code Here

        throws DatabaseException {

        DatabaseEntry key = new DatabaseEntry();
        DatabaseEntry pKey = new DatabaseEntry();
        DatabaseEntry data = new DatabaseEntry();
        SecondaryCursor cursor = secDb.openSecondaryCursor(null, null);
        while (nextKey < MAX_KEY - 1) {
            OperationStatus status = cursor.getNext(key, pKey, data,
                                                    lockMode);
            assertEquals("nextKey=" + nextKey,
                         OperationStatus.SUCCESS, status);
            int keyFound = TestUtils.getTestVal(key.getData());
            assertEquals(keyFound, TestUtils.getTestVal(pKey.getData()));
            assertEquals(keyFound, TestUtils.getTestVal(data.getData()));
            /* Let the delete/update thread catch up. */
            nextKey = keyFound;
            if (nextKey < MAX_KEY - 1) {
                while (status != OperationStatus.KEYEMPTY) {
                    assertEquals(OperationStatus.SUCCESS, status);
                    status = cursor.getCurrent(key, pKey, data,
                                               lockMode);
                }
                nextKey = keyFound + 1;
            }
        }
        cursor.close();
    }
View Full Code Here

TOP

Related Classes of com.sleepycat.je.SecondaryCursor

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.