Package com.sun.sgs.service.store.db

Examples of com.sun.sgs.service.store.db.DbCursor


    boolean txnDone = false;
    String nextName;
    boolean found;
    long oid;
    try {
        DbCursor cursor = namesDb.openCursor(txn);
        try {
      boolean hasNext = cursor.findNext(encodeString(name));
      nextName =
          hasNext ? decodeString(cursor.getKey()) : null;
      found = hasNext && name.equals(nextName);
      oid = hasNext ? decodeLong(cursor.getValue()) : -1;
        } finally {
      cursor.close();
        }
        txnDone = true;
        txn.commit();
    } finally {
        if (!txnDone) {
View Full Code Here


    boolean txnDone = false;
    String nextName;
    long oid;
    long nextOid;
    try {
        DbCursor cursor = namesDb.openCursor(txn);
        try {
      boolean hasNext = cursor.findNext(encodeString(name));
      nextName =
          hasNext ? decodeString(cursor.getKey()) : null;
      if (hasNext && name.equals(nextName)) {
          oid = decodeLong(cursor.getValue());
          /* Move to name after matching name */
          hasNext = cursor.findNext();
          nextName =
        hasNext ? decodeString(cursor.getKey()) : null;
      } else {
          oid = -1;
      }
      nextOid = hasNext ? decodeLong(cursor.getValue()) : -1;
        } finally {
      cursor.close();
        }
        txnDone = true;
        txn.commit();
    } finally {
        if (!txnDone) {
View Full Code Here

    DbTransaction txn = env.beginTransaction(txnTimeout);
    boolean txnDone = false;
    long oid;
    String nextName;
    try {
        DbCursor cursor = namesDb.openCursor(txn);
        try {
      boolean hasNext = (name == null) ? cursor.findFirst()
          : cursor.findNext(encodeString(name));
      nextName =
          hasNext ? decodeString(cursor.getKey()) : null;
      if ((name != null) && name.equals(nextName)) {
          hasNext = cursor.findNext();
          nextName = (hasNext)
        ? decodeString(cursor.getKey()) : null;
      }
      oid = hasNext ? decodeLong(cursor.getValue()) : -1;
        } finally {
      cursor.close();
        }
        txnDone = true;
        txn.commit();
    } finally {
        if (!txnDone) {
View Full Code Here

        oidsDb.delete(txn, encodeLong(oid));
    } else {
        oidsDb.put(txn, encodeLong(oid), oidValues[i]);
    }
      }
      DbCursor cursor = namesDb.openCursor(txn);
      try {
    for (int i = 0; i < names.length; i++) {
        String name = names[i];
        if (name == null) {
      throw new IllegalArgumentException(
          "The names must not be null");
        }
        long value = nameValues[i];
        if (value < -1) {
      throw new IllegalArgumentException(
          "The name values must not be less than -1");
        }
        String nextName = cursor.findNext(encodeString(name))
      ? decodeString(cursor.getKey()) : null;
        BindingKey nextKey = BindingKey.getAllowLast(nextName);
        if (value != -1) {
      /* Set -- next name must be write locked */
      checkLocked(nodeInfo, nextKey, true);
      if (!name.equals(nextName)) {
          lock(nodeInfo, BindingKey.get(name), true,
         "commit");
      }
      namesDb.put(
          txn, encodeString(name), encodeLong(value));
        } else if (!name.equals(nextName)) {
      /* Already removed -- next name must be read locked */
      checkLocked(nodeInfo, nextKey, false);
        } else {
      /* Remove -- name and next name must be write locked */
      checkLocked(nodeInfo, nextKey, true);
      checkLocked(nodeInfo,
            BindingKey.getAllowLast(
          cursor.findNext() ?
          decodeString(cursor.getKey()) : null),
            true);
      namesDb.delete(txn, encodeString(name));
      releaseLock(nodeInfo, nextKey, "commit");
        }
    }
      } finally {
    cursor.close();
      }
      txnDone = true;
      txn.commit();
  } finally {
      if (!txnDone) {
View Full Code Here

      infoDb.get(dbTxn, firstPlaceholderKey, true));
  if (placeholderOid < 0) {
      logger.log(Level.FINEST, "No allocation placeholders");
      return;
  }
  DbCursor cursor = oidsDb.openCursor(dbTxn);
  try {
      while (cursor.findNext(DataEncoding.encodeLong(placeholderOid))) {
    byte[] key = cursor.getKey();
    if (DataEncoding.decodeLong(key) != placeholderOid) {
        if (logger.isLoggable(Level.FINEST)) {
      logger.log(Level.FINEST,
           "Placeholder oid:{0,number,#} not found",
           placeholderOid);
        }
    } else if (isPlaceholderValue(cursor.getValue())) {
        boolean success = oidsDb.delete(dbTxn, key);
        assert success;
        if (logger.isLoggable(Level.FINEST)) {
      logger.log(Level.FINEST,
           "Removed placeholder at oid:{0,number,#}",
           placeholderOid);
        }
    } else {
        if (logger.isLoggable(Level.FINEST)) {
      logger.log(Level.FINEST,
           "Ignoring oid:{0,number,#} that does not" +
           " refer to a placeholder",
           placeholderOid);
        }
    }
    placeholderOid += ALLOCATION_BLOCK_SIZE;
      }
      infoDb.put(
    dbTxn, firstPlaceholderKey, DataEncoding.encodeLong(-1));
  } finally {
      cursor.close();
  }
    }
View Full Code Here

     * @param  oid the object ID or -1
     * @return  the next object ID or -1
     */
    long nextObjectIdRaw(Transaction txn, long oid) {
  TxnInfo txnInfo = checkTxn(txn);
  DbCursor cursor = oidsDb.openCursor(txnInfo.dbTxn);
  try {
      boolean found =  (oid < 0)
    ? cursor.findFirst()
    : cursor.findNext(DataEncoding.encodeLong(oid + 1));
      if (found) {
    return DataEncoding.decodeLong(cursor.getKey());
      } else {
    return -1;
      }
  } finally {
      cursor.close();
  }
    }
View Full Code Here

TOP

Related Classes of com.sun.sgs.service.store.db.DbCursor

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.