Package com.sleepycat.db

Examples of com.sleepycat.db.Database


        }
        boolean exists;
        try {
            DatabaseConfig config = new DatabaseConfig();
            config.setReadOnly(true);
            Database db = DbCompat.openDatabase
                (env, null/*txn*/, fileName, dbName, config);
            db.close();
            exists = true;
        } catch (FileNotFoundException e) {
            exists = false;
        } catch (Exception e) {
            /* Any other exception means the DB does exist. */
 
View Full Code Here


        dbConfig.setType(DatabaseType.BTREE);

        // Create the Serial class catalog.  This holds the serialized class
        // format for all database records of serial format.
        //
        Database catalogDb = env.openDatabase(null, CLASS_CATALOG, null,
                                              dbConfig);
        javaCatalog = new StoredClassCatalog(catalogDb);

        // Open the Berkeley DB database for the part, supplier and shipment
        // stores.  The stores are opened with no duplicate keys allowed.
View Full Code Here

        throws DatabaseException, FileNotFoundException
    {
        TestOptions options = new TestOptions();
        options.db_config.setErrorPrefix("DatabaseTest::test6 ");

        Database db = new Database(TestUtils.getDBFileName(DATABASETEST_DBNAME), null, options.db_config);

        EnvironmentConfig envc = new EnvironmentConfig();
        envc.setAllowCreate(true);
        envc.setInitializeCache(true);
      Environment db_env = new Environment(TestUtils.BASETEST_DBFILE, envc);

      db.close();
      db_env.close();

      System.gc();
      System.runFinalization();
    }
View Full Code Here

    void rundb(int count, TestOptions options)
            throws DatabaseException, FileNotFoundException
    {
      String name;

        Database db;
        if(options.database == null)
        {
          if (options.db_env != null)
              name = DATABASETEST_DBNAME;
          else
              name = TestUtils.getDBFileName(DATABASETEST_DBNAME);

            if(count == 0)
                options.db_config.setAllowCreate(true);

            if(options.db_env == null)
                db = new Database(name, null, options.db_config);
            else
                db = options.db_env.openDatabase(null, name, null, options.db_config);
        } else {
            db = options.database;
        }

      // The bit map of keys we've seen
      long bitmap = 0;

      // The bit map of keys we expect to see
      long expected = (1 << (count+1)) - 1;

      byte outbuf[] = new byte[count+1];
      int i;
      for (i=0; i<count; i++) {
        outbuf[i] = (byte)('0' + i);
      }
      outbuf[i++] = (byte)'x';

      DatabaseEntry key = new DatabaseEntry(outbuf, 0, i);
      DatabaseEntry data = new DatabaseEntry(outbuf, 0, i);

      TestUtils.DEBUGOUT("Put: " + (char)outbuf[0] + ": " + new String(outbuf, 0, i));
      db.putNoOverwrite(null, key, data);

      // Acquire a cursor for the table.
      Cursor dbcp = db.openCursor(null, CursorConfig.DEFAULT);

      // Walk through the table, checking
      DatabaseEntry readkey = new DatabaseEntry();
      DatabaseEntry readdata = new DatabaseEntry();
      DatabaseEntry whoknows = new DatabaseEntry();

      /*
       * NOTE: Maybe want to change from user-buffer to DB buffer
       *       depending on the flag options.user_buffer (setReuseBuffer)
       * The old version set MALLOC/REALLOC here - not sure if it is the same.
       */

      TestUtils.DEBUGOUT("Dbc.get");
      while (dbcp.getNext(readkey, readdata, LockMode.DEFAULT) == OperationStatus.SUCCESS) {
        String key_string =
        new String(readkey.getData(), 0, readkey.getSize());
        String data_string =
        new String(readdata.getData(), 0, readkey.getSize());
        TestUtils.DEBUGOUT("Got: " + key_string + ": " + data_string);
        int len = key_string.length();
        if (len <= 0 || key_string.charAt(len-1) != 'x') {
          TestUtils.ERR("reread terminator is bad");
        }
        len--;
        long bit = (1 << len);
        if (len > count) {
          TestUtils.ERR("reread length is bad: expect " + count + " got "+ len + " (" + key_string + ")" );
        }
        else if (!data_string.equals(key_string)) {
          TestUtils.ERR("key/data don't match");
        }
        else if ((bitmap & bit) != 0) {
          TestUtils.ERR("key already seen");
        }
        else if ((expected & bit) == 0) {
          TestUtils.ERR("key was not expected");
        }
        else {
          bitmap |= bit;
          expected &= ~(bit);
          for (i=0; i<len; i++) {
            if (key_string.charAt(i) != ('0' + i)) {
              System.out.print(" got " + key_string
              + " (" + (int)key_string.charAt(i)
              + "), wanted " + i
              + " (" + (int)('0' + i)
              + ") at position " + i + "\n");
              TestUtils.ERR("key is corrupt");
            }
          }
        }
      }
      if (expected != 0) {
        System.out.print(" expected more keys, bitmap is: " + expected + "\n");
        TestUtils.ERR("missing keys in database");
      }

      dbcp.close();
      TestUtils.DEBUGOUT("options.save_db " + options.save_db + " options.database " + options.database);
      if(options.save_db == false)
          db.close(false);
      else if (options.database == null)
          options.database = db;
    }
View Full Code Here

        /* Create an empty database. */
        DatabaseConfig config = new DatabaseConfig();
        config.setAllowCreate(true);
        DbCompat.setTypeBtree(config);
        Database db =
            DbCompat.testOpenDatabase(env, null, file, null, config);
        db.close();

        /* Open the empty database read-only. */
        config.setAllowCreate(false);
        config.setReadOnly(true);
        db = DbCompat.testOpenDatabase(env, null, file, null, config);

        /* Expect exception when creating the catalog. */
        try {
            new StoredClassCatalog(db);
            fail();
        } catch (IllegalStateException e) { }
        db.close();
    }
View Full Code Here

TOP

Related Classes of com.sleepycat.db.Database

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.