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

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


   * Use an absolute path to avoid problems on Windows.
   * -tjb@sun.com (02/16/2007)
   */
  directory = new File(specifiedDirectory).getAbsolutePath();
  txnInfoTable = getTxnInfoTable(TxnInfo.class);
  DbTransaction dbTxn = null;
  boolean done = false;
  try {
      File directoryFile = new File(specifiedDirectory).getAbsoluteFile();
            if (!directoryFile.exists()) {
                logger.log(Level.INFO, "Creating database directory : " +
                           directoryFile.getAbsolutePath());
                if (!directoryFile.mkdirs()) {
                    throw new DataStoreException("Unable to create database " +
                                                 "directory : " +
                                                 directoryFile.getName());
                }
      }
            env = wrappedProps.getClassInstanceProperty(
                    ENVIRONMENT_CLASS_PROPERTY,
                    DEFAULT_ENVIRONMENT_CLASS,
                    DbEnvironment.class,
                    new Class<?>[]{
                        String.class, Properties.class, Scheduler.class
                    },
                    directory, properties, scheduler);
      dbTxn = env.beginTransaction(Long.MAX_VALUE);
      Databases dbs = getDatabases(dbTxn);
      infoDb = dbs.info;
      classesDb = dbs.classes;
      oidsDb = dbs.oids;
      namesDb = dbs.names;
      useAllocationBlockPlaceholders =
    env.useAllocationBlockPlaceholders();
      freeObjectIds = new FreeObjectIds(useAllocationBlockPlaceholders);
      removeUnusedAllocationPlaceholders(dbTxn);
      done = true;
      dbTxn.commit();
  } catch (RuntimeException e) {
      throw handleException(
    null, Level.SEVERE, e, "DataStore initialization");
  } catch (Error e) {
      logger.logThrow(
    Level.SEVERE, e, "DataStore initialization failed");
      throw e;
  } finally {
      if (dbTxn != null && !done) {
    try {
        dbTxn.abort();
    } catch (RuntimeException e) {
        logger.logThrow(Level.FINE, e, "Exception during abort");
    }
      }
  }
View Full Code Here


  ObjectIdInfo objectIdInfo = txnInfo.getObjectIdInfo();
  if (objectIdInfo == null) {
      logger.log(Level.FINE, "Allocate more object IDs");
      long newNextObjectId;
      long newLastObjectId;
      DbTransaction dbTxn = env.beginTransaction(txn.getTimeout());
      boolean done = false;
      try {
    newNextObjectId = DataStoreHeader.getNextId(
        NEXT_OBJ_ID_KEY, infoDb, dbTxn, ALLOCATION_BLOCK_SIZE);
    newLastObjectId =
        newNextObjectId + ALLOCATION_BLOCK_SIZE - 1;
    maybeUpdateAllocationBlockPlaceholders(
        dbTxn, newLastObjectId);
    done = true;
    dbTxn.commit();
      } finally {
    if (!done) {
        dbTxn.abort();
    }
      }
      objectIdInfo = txnInfo.createObjectIdInfo(
    newNextObjectId, newLastObjectId);
  }
View Full Code Here

   * improve concurrency.  -tjb@sun.com (05/23/2007)
   *
   * Use full transaction isolation to insure consistency when
   * concurrently allocating new class IDs.  -tjb@sun.com (03/17/2009)
   */
  DbTransaction dbTxn = env.beginTransaction(txn.getTimeout(), true);
  try {
      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(
      "Class hash already present");
    }
      }
      done = true;
      dbTxn.commit();
      return result;
  } finally {
      if (!done) {
    dbTxn.abort();
      }
  }
    }
View Full Code Here

    {
  checkTxn(txn);
  byte[] key = getKeyFromClassId(classId);
  byte[] result;
  boolean done = false;
  DbTransaction dbTxn = env.beginTransaction(txn.getTimeout());
  try {
      result = classesDb.get(dbTxn, key, false);
      done = true;
      dbTxn.commit();
  } finally {
      if (!done) {
    dbTxn.abort();
      }
  }
  if (result != null) {
      return result;
  } else {
View Full Code Here

     * Returns the next available ID stored under the specified key, and
     * increments the stored value by the specified amount.  Uses the specified
     * timeout when creating a DB transaction.
     */
    private long getNextId(long key, int blockSize, long timeout) {
  DbTransaction dbTxn = env.beginTransaction(timeout);
  boolean done = false;
  try {
      long id = DataStoreHeader.getNextId(
    key, infoDb, dbTxn, blockSize);
      done = true;
      dbTxn.commit();
      return id;
  } finally {
      if (!done) {
    dbTxn.abort();
      }
  }
    }
View Full Code Here

   * improve concurrency.  -tjb@sun.com (05/23/2007)
   *
   * Use full transaction isolation to insure consistency when
   * concurrently allocating new class IDs.  -tjb@sun.com (03/17/2009)
   */
  DbTransaction dbTxn = env.beginTransaction(timeout, true);
  try {
      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(
      "Class hash already present");
    }
      }
      done = true;
      dbTxn.commit();
      return result;
  } finally {
      if (!done) {
    dbTxn.abort();
      }
  }
    }
View Full Code Here

   * Use an absolute path to avoid problems on Windows.
   * -tjb@sun.com (02/16/2007)
   */
  directory = new File(specifiedDirectory).getAbsolutePath();
  txnInfoTable = getTxnInfoTable(TxnInfo.class);
  DbTransaction dbTxn = null;
  boolean done = false;
  try {
      File directoryFile = new File(specifiedDirectory).getAbsoluteFile();
            if (!directoryFile.exists()) {
                logger.log(Level.INFO, "Creating database directory : " +
                           directoryFile.getAbsolutePath());
                if (!directoryFile.mkdirs()) {
                    throw new DataStoreException("Unable to create database " +
                                                 "directory : " +
                                                 directoryFile.getName());
                }
      }
            env = wrappedProps.getClassInstanceProperty(
                    ENVIRONMENT_CLASS_PROPERTY,
                    DEFAULT_ENVIRONMENT_CLASS,
                    DbEnvironment.class,
                    new Class<?>[]{
                        String.class, Properties.class,
      ComponentRegistry.class, TransactionProxy.class
                    },
                    directory, properties, systemRegistry, txnProxy);
      dbTxn = env.beginTransaction(Long.MAX_VALUE);
      Databases dbs = DbUtilities.getDatabases(env, dbTxn, logger);
      infoDb = dbs.info();
      classesDb = dbs.classes();
      oidsDb = dbs.oids();
      namesDb = dbs.names();
      nodeId = DataStoreHeader.getNextId(
    DataStoreHeader.NEXT_NODE_ID_KEY, infoDb, dbTxn, 1);
      useAllocationBlockPlaceholders =
    env.useAllocationBlockPlaceholders();
      freeObjectIds = new FreeObjectIds(useAllocationBlockPlaceholders);
      removeUnusedAllocationPlaceholders(dbTxn);
      done = true;
      dbTxn.commit();

            logger.log(Level.CONFIG,
                       "Created DataStoreImpl with properties:" +
                       "\n  " + DIRECTORY_PROPERTY + "=" + specifiedDirectory +
                       "\n  " + ENVIRONMENT_CLASS_PROPERTY + "=" +
                       env.getClass().getName());
           
  } catch (RuntimeException e) {
      throw handleException(
    null, Level.SEVERE, e, "DataStore initialization");
  } catch (Error e) {
      logger.logThrow(
    Level.SEVERE, e, "DataStore initialization failed");
      throw e;
  } finally {
      if (dbTxn != null && !done) {
    try {
        dbTxn.abort();
    } catch (RuntimeException e) {
        logger.logThrow(Level.FINE, e, "Exception during abort");
    }
      }
  }
View Full Code Here

  ObjectIdInfo objectIdInfo = txnInfo.getObjectIdInfo();
  if (objectIdInfo == null) {
      logger.log(Level.FINE, "Allocate more object IDs");
      long newNextObjectId;
      long newLastObjectId;
      DbTransaction dbTxn = env.beginTransaction(txn.getTimeout());
      boolean done = false;
      try {
    newNextObjectId = DbUtilities.getNextObjectId(
        infoDb, dbTxn, ALLOCATION_BLOCK_SIZE);
    newLastObjectId =
        newNextObjectId + ALLOCATION_BLOCK_SIZE - 1;
    maybeUpdateAllocationBlockPlaceholders(
        dbTxn, newLastObjectId);
    done = true;
    dbTxn.commit();
      } finally {
    if (!done) {
        dbTxn.abort();
    }
      }
      objectIdInfo = txnInfo.createObjectIdInfo(
    newNextObjectId, newLastObjectId);
  }
View Full Code Here

     * Returns the next available ID stored under the specified key, and
     * increments the stored value by the specified amount.  Uses the specified
     * timeout when creating a DB transaction.
     */
    private long getNextId(long key, int blockSize, long timeout) {
  DbTransaction dbTxn = env.beginTransaction(timeout);
  boolean done = false;
  try {
      long id = DataStoreHeader.getNextId(
    key, infoDb, dbTxn, blockSize);
      done = true;
      dbTxn.commit();
      return id;
  } finally {
      if (!done) {
    dbTxn.abort();
      }
  }
    }
View Full Code Here

      throw new IllegalArgumentException(
    "The class ID must be greater than 0");
  }
  byte[] key = getKeyFromClassId(classId);
  boolean done = false;
  DbTransaction dbTxn = env.beginTransaction(timeout);
  try {
      byte[] result = classesDb.get(dbTxn, key, false);
      done = true;
      dbTxn.commit();
      return result;
  } finally {
      if (!done) {
    dbTxn.abort();
      }
  }
    }
View Full Code Here

TOP

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

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.