public void testQuery() {
   createData();
   EmbeddedObjectContainer database = Db4oEmbedded.openFile(aliasConfig(), tempFile());
   database.query(B.class);
   database.query(A.class);
   database.close();
   querydb(Db4oEmbedded.newConfiguration(), new int[] {1, 0}, A.class, B.class);
 }
 public Pilot deletePilot(Pilot pilot) throws Exception {
   if (objCont != null) {
     objCont = getObjCont();
   }
   try {
     objCont.delete(pilot);
     objCont.commit();
   } catch (Exception e) {
     throw e;
   }
   return pilot;
 }
 public Flight saveFlight(Flight flight) throws Exception {
   if (objCont != null) {
     objCont = getObjCont();
   }
   try {
     objCont.store(flight);
     objCont.commit();
   } catch (Exception e) {
     throw e;
   }
   return flight;
 }
 public List<Flight> getFlights(Flight flight) throws Exception {
   List<Flight> flightList;
   if (objCont != null) {
     objCont = getObjCont();
   }
   try {
     flightList = objCont.queryByExample(flight);
     objCont.commit();
   } catch (Exception e) {
     throw e;
   }
   return flightList;
 }
 public List<Pilot> getPilots(Pilot pilot) throws Exception {
   List<Pilot> pilotList;
   if (objCont != null) {
     objCont = getObjCont();
   }
   try {
     pilotList = objCont.queryByExample(pilot);
     objCont.commit();
   } catch (Exception e) {
     throw e;
   }
   return pilotList;
 }
Esempio n. 6
0
  /**
   * Creates a new cache element.
   *
   * @param element The cache element to create (or update).
   */
  public void createCacheElement(CacheElement element) {
    dbLock.writeLock().lock();
    try {
      deleteCacheElement(element);
      db.store(element);

      if (writeCount++ == BATCH_SIZE) {
        db.commit();
        writeCount = 0;
      }

    } finally {
      dbLock.writeLock().unlock();
    }
  }
Esempio n. 7
0
 /** Deletes the cache element with the given type and key. */
 private void deleteCacheElement(CacheElement element) {
   // Retrieve it from the database first.
   element = getCacheElement(element.getType(), element.getKey());
   if (element != null) {
     db.delete(element);
   }
 }
 public Boolean closeObjCont() throws Exception {
   Boolean closed = Boolean.FALSE;
   if (objCont != null) {
     objCont.close();
     closed = Boolean.TRUE;
   } else {
     closed = Boolean.TRUE;
   }
   return closed;
 }
Esempio n. 9
0
 /** Recreates the database. */
 public void clearDatabase() {
   dbLock.writeLock().lock();
   try {
     db.close();
     dbFile.delete();
     openDatabase(dbFile);
   } finally {
     dbLock.writeLock().unlock();
   }
 }
  public <T, T1> void querydb(
      EmbeddedConfiguration config, int[] count, Class<T> class1, Class<T1> class2) {
    EmbeddedObjectContainer database = Db4oEmbedded.openFile(config, tempFile());
    try {
      List<T> list = database.query(class1);
      Assert.areEqual(
          count[0], list.size(), "Unexpected result querying for " + class1.getSimpleName());
      if (count[0] > 0) {
        // System.out.println("Querying for " + class1.getSimpleName() + " getting " +
        // list.get(0).getClass().getSimpleName());
      }

      List<T1> list1 = database.query(class2);
      Assert.areEqual(
          count[1], list1.size(), "Unexpected result querying for " + class2.getSimpleName());
      if (count[1] > 0) {
        // System.out.println("Querying for " + class2.getSimpleName() + " getting " +
        // list1.get(0).getClass().getSimpleName());
      }

    } finally {
      database.close();
    }
  }
Esempio n. 11
0
  public CacheElement getCacheElement(int type, String key) {
    dbLock.readLock().lock();
    try {

      ObjectSet<CacheElement> result = db.query(new CacheElementPredicate(type, key));
      if (result.size() > 1) {
        LOG.error(
            "Programming error. Got "
                + result.size()
                + " cache elements of type "
                + type
                + " and key "
                + key);
      }
      return result.isEmpty() ? null : result.get(0);

    } finally {
      dbLock.readLock().unlock();
    }
  }
 public void CloseDB() {
   _db.close();
 }
 private void assertName(EmbeddedConfiguration config, String expected) {
   EmbeddedObjectContainer db = Db4oEmbedded.openFile(config, FILE_NAME);
   Assert.areEqual(expected, db.toString());
   db.close();
 }
 private void createData() {
   EmbeddedObjectContainer database = Db4oEmbedded.openFile(tempFile());
   database.store(new A("Item1"));
   database.commit();
   database.close();
 }