private void processDatabases(
      Element root, DefaultDataSet dataset, BdbEnvironment envFormat, List<Database> dbs)
      throws Exception {

    for (Database db : dbs) {
      String dbName = db.getDatabaseName();
      BdbDatabase dbFormat = envFormat.getDatabase(dbName);
      String peerName = envFormat.getPeerName();
      String tagName = (peerName == null) ? dbName : envFormat.getPeerName() + "." + dbName;

      DefaultTable table = new DefaultTable(tagName);
      dataset.addTable(table);
      DatabaseEntry key = new DatabaseEntry();
      DatabaseEntry data = new DatabaseEntry();

      if (dbFormat != null) {
        Cursor c = db.openCursor(null, null);
        int rows = 0;
        try {
          while (c.getNext(key, data, LockMode.DEFAULT) == OperationStatus.SUCCESS) {
            rows++;
            byteBufferRead(root, tagName, key, data, dbFormat, schemaIDBinding);
          }
          if (rows == 0) {
            root.addElement(tagName);
          }
        } finally {
          c.close();
        }
      }
    }
  }
Example #2
0
 /** {@inheritDoc} */
 public void abort() {
   try {
     txn.abort();
   } catch (DatabaseException e) {
     throw BdbEnvironment.convertException(e, false);
   }
 }
Example #3
0
 /** {@inheritDoc} */
 public void prepare(byte[] gid) {
   try {
     txn.prepare(gid);
   } catch (DatabaseException e) {
     throw BdbEnvironment.convertException(e, false);
   }
 }
Example #4
0
 /**
  * Creates an instance of this class.
  *
  * @param env the Berkeley DB environment
  * @param timeout the number of milliseconds the transaction should be allowed to run
  * @throws IllegalArgumentException if timeout is less than {@code 1}
  * @throws DbDatabaseException if an unexpected database problem occurs
  */
 BdbTransaction(Environment env, long timeout) {
   if (timeout <= 0) {
     throw new IllegalArgumentException("Timeout must be greater than 0");
   }
   try {
     txn = env.beginTransaction(null, null);
     /* Avoid overflow -- BDB treats 0 as unlimited */
     long timeoutMicros = (timeout < (Long.MAX_VALUE / 1000)) ? 1000 * timeout : 0;
     txn.setTxnTimeout(timeoutMicros);
   } catch (DatabaseException e) {
     throw BdbEnvironment.convertException(e, false);
   }
 }