private static void closeEnv() {
    System.out.println("Closing env and databases");
    if (myDb != null) {
      try {
        myDb.close();
      } catch (DatabaseException e) {
        System.err.println("closeEnv: myDb: " + e.toString());
        e.printStackTrace();
      }
    }

    if (myClassDb != null) {
      try {
        myClassDb.close();
      } catch (DatabaseException e) {
        System.err.println("closeEnv: myClassDb: " + e.toString());
        e.printStackTrace();
      }
    }

    if (myEnv != null) {
      try {
        myEnv.close();
      } catch (DatabaseException e) {
        System.err.println("closeEnv: " + e.toString());
        e.printStackTrace();
      }
    }
  }
Beispiel #2
0
  public static void main(String[] args) {
    Environment env = null;
    Database db = null;
    EnvironmentConfig envconfig = new EnvironmentConfig();
    envconfig.setAllowCreate(true);
    try {
      env = new Environment(new File("D://bdb"), envconfig);
      DatabaseConfig dbconfig = new DatabaseConfig();
      dbconfig.setAllowCreate(true);
      db = env.openDatabase(null, "dbac.db", dbconfig);
      String key = "mykey";
      DatabaseEntry thekey = new DatabaseEntry();
      thekey.setData(key.getBytes("utf-8"));

      Long value = new Long(123456);
      DatabaseEntry thevalue = new DatabaseEntry();
      EntryBinding myBinging = TupleBinding.getPrimitiveBinding(Long.class);
      myBinging.objectToEntry(value, thevalue);
      // LongBinding myLongBinging=(LongBinding)TupleBinding.getPrimitiveBinding(Long.class);
      // myLongBinging.objectToEntry(value, thevalue);
      db.put(null, thekey, thevalue);
      DatabaseEntry valueEntry = new DatabaseEntry();
      OperationStatus status = db.get(null, thekey, valueEntry, LockMode.DEFAULT);
      if (status == OperationStatus.SUCCESS) {
        // Long number=myLongBinging.entryToObject(valueEntry);
        Long number = (Long) myBinging.entryToObject(valueEntry);
        System.out.println(env.getDatabaseNames());
        System.out.println(number);
      }
    } catch (EnvironmentLockedException e) {
      e.printStackTrace();
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      if (db != null) {
        try {
          db.close();
        } catch (DatabaseException e) {
          e.printStackTrace();
        }
      }
      if (env != null) {
        try {
          env.cleanLog();
          env.close();
        } catch (DatabaseException e) {
          e.printStackTrace();
        }
      }
    }
  }
Beispiel #3
0
 public void getNextURLs(int max, List<WebURL> result) {
   while (true) {
     synchronized (mutex) {
       if (isFinished) {
         return;
       }
       try {
         List<WebURL> curResults = workQueues.get(max);
         workQueues.delete(curResults.size());
         if (inProcessPages != null) {
           for (WebURL curPage : curResults) {
             inProcessPages.put(curPage);
           }
         }
         result.addAll(curResults);
       } catch (DatabaseException e) {
         logger.error("Error while getting next urls: " + e.getMessage());
         e.printStackTrace();
       }
       if (result.size() > 0) {
         return;
       }
     }
     try {
       synchronized (waitingList) {
         waitingList.wait();
       }
     } catch (InterruptedException ignored) {
       // Do nothing
     }
     if (isFinished) {
       return;
     }
   }
 }
Beispiel #4
0
 public void close() {
   try {
     urlsDB.close();
   } catch (DatabaseException e) {
     e.printStackTrace();
   }
 }
Beispiel #5
0
 public void remove(String csName) {
   try {
     m_env.removeDatabase(null, csName);
   } catch (DatabaseException e) {
     e.printStackTrace();
   }
   m_env = null;
 }
 /* (non-Javadoc)
  * @see de.tudarmstadt.ukp.dkpro.ir.util.berkeleydb.BerkeleyDbEnvironmentResource#close()
  */
 public void close() {
   if (environment != null) {
     try {
       environment.close();
     } catch (DatabaseException e) {
       // TODO use logger instead of out
       e.printStackTrace();
     }
   }
 }
Beispiel #7
0
 protected void deleteItem(final WorkQueueFrontier frontier, final CrawlURI peekItem)
     throws IOException {
   try {
     final BdbMultipleWorkQueues queues = ((BdbFrontier) frontier).getWorkQueues();
     queues.delete(peekItem);
   } catch (DatabaseException e) {
     e.printStackTrace();
     throw IoUtils.wrapAsIOException(e);
   }
 }
 /**
  * Method used by BdbFrontier during checkpointing.
  *
  * <p>The backing bdbje database has been marked deferred write so we save on writes to disk.
  * Means no guarantees disk will have whats in memory unless a sync is called (Calling sync on the
  * bdbje Environment is not sufficent).
  *
  * <p>Package access only because only Frontiers of this package would ever need access.
  *
  * @see <a href="http://www.sleepycat.com/jedocs/GettingStartedGuide/DB.html">Deferred Write
  *     Databases</a>
  */
 void sync() {
   if (this.pendingUrisDB == null) {
     return;
   }
   try {
     this.pendingUrisDB.sync();
   } catch (DatabaseException e) {
     e.printStackTrace();
   }
 }
Beispiel #9
0
 public BtreeFile createBtreeFile(String csName) // , boolean bCanSortMultiThreads)
     {
   // Now open, or create and open, the database
   try {
     Database bdb = m_env.openDatabase(null, csName, m_DbConfig);
     BtreeFile btreeFile = new BtreeFile(bdb); // , bCanSortMultiThreads);
     return btreeFile;
   } catch (DatabaseException e) {
     e.printStackTrace();
     return null;
   }
 }
 public static void main(String args[]) {
   ExampleInventoryRead eir = new ExampleInventoryRead();
   try {
     eir.run(args);
   } catch (DatabaseException dbe) {
     System.err.println("ExampleInventoryRead: " + dbe.toString());
     dbe.printStackTrace();
   } finally {
     myDbEnv.close();
   }
   System.out.println("All done.");
 }
Beispiel #11
0
 public void sync() {
   if (resumable) {
     return;
   }
   if (urlsDB == null) {
     return;
   }
   try {
     urlsDB.sync();
   } catch (DatabaseException e) {
     e.printStackTrace();
   }
 }
  public Groundhog getGroundhog(String groundhogName) {

    Groundhog groundhog = null;
    File file = new File(baseDirectoryPath + groundhogName);
    if (file.isDirectory()) {

      try {
        groundhog = new Groundhog(file, defaultCacheSize);
        return groundhog;
      } catch (DatabaseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
    return groundhog;
  }
  /** Main */
  public static void main(String argv[]) {

    if (argv.length < 2) {
      usage();
      return;
    }
    File envHomeDirectory = new File(argv[0]);

    boolean doInsertArg = false;
    if (argv[1].equalsIgnoreCase("insert")) {
      doInsertArg = true;
    } else if (argv[1].equalsIgnoreCase("retrieve")) {
      doInsertArg = false;
    } else {
      usage();
    }

    int startOffset = 0;
    int numRecordsVal = 0;

    if (doInsertArg) {

      if (argv.length > 2) {
        numRecordsVal = Integer.parseInt(argv[2]);
      } else {
        usage();
        return;
      }

      if (argv.length > 3) {
        startOffset = Integer.parseInt(argv[3]);
      }
    }

    try {
      BindingExample app =
          new BindingExample(numRecordsVal, doInsertArg, envHomeDirectory, startOffset);
      app.run();
    } catch (DatabaseException e) {
      e.printStackTrace();
      System.exit(EXIT_FAILURE);
    }
    System.exit(EXIT_SUCCESS);
  }