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

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


      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


      int result;
      byte[] hashValue = classesDb.get(dbTxn, hashKey, false);
      if (hashValue != null) {
    result = DataEncoding.decodeInt(hashValue);
      } else {
    DbCursor cursor = classesDb.openCursor(dbTxn);
    try {
        result = cursor.findLast()
      ? getClassIdFromKey(cursor.getKey()) + 1 : 1;
        byte[] idKey = getKeyFromClassId(result);
        boolean success =
      cursor.putNoOverwrite(idKey, classInfo);
        if (!success) {
      throw new DataStoreException(
          "Class ID key already present");
        }
    } finally {
        cursor.close();
    }
    boolean success = classesDb.putNoOverwrite(
        dbTxn, hashKey, DataEncoding.encodeInt(result));
    if (!success) {
        throw new DataStoreException(
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

      int result;
      byte[] hashValue = classesDb.get(dbTxn, hashKey, false);
      if (hashValue != null) {
    result = DataEncoding.decodeInt(hashValue);
      } else {
    DbCursor cursor = classesDb.openCursor(dbTxn);
    try {
        result = cursor.findLast()
      ? getClassIdFromKey(cursor.getKey()) + 1 : 1;
        byte[] idKey = getKeyFromClassId(result);
        boolean success =
      cursor.putNoOverwrite(idKey, classInfo);
        if (!success) {
      throw new DataStoreException(
          "Class ID key already present");
        }
    } finally {
        cursor.close();
    }
    boolean success = classesDb.putNoOverwrite(
        dbTxn, hashKey, DataEncoding.encodeInt(result));
    if (!success) {
        throw new DataStoreException(
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

      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

      }
      DbTransaction txn = env.beginTransaction(txnTimeout);
      boolean txnDone = false;
      NextObjectResults result;
      try {
    DbCursor cursor = oidsDb.openCursor(txn);
    try {
        boolean found = (oid == -1) ? cursor.findFirst()
      : cursor.findNext(encodeLong(oid));
        long nextOid = !found ? -1 : decodeLong(cursor.getKey());
        if (oid != -1 && oid == nextOid) {
      found = cursor.findNext();
      nextOid = !found ? -1 : decodeLong(cursor.getKey());
        }
        result = !found ? null
      : new NextObjectResults(
          nextOid, cursor.getValue(),
          getWaiting(oid) == GetWaitingResult.WRITERS);
    } finally {
        cursor.close();
    }
    txnDone = true;
    txn.commit();
      } finally {
    if (!txnDone) {
View Full Code Here

    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

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.