public void test() {
   ObjectContainer oc = Test.objectContainer();
   ObjectSet objectSet = oc.queryByExample(new CallbackCanDelete("p1", null));
   CallbackCanDelete ccd = (CallbackCanDelete) objectSet.next();
   oc.deactivate(ccd, Integer.MAX_VALUE);
   oc.delete(ccd);
 }
 /**
  * Verifica se o objeto está armazenado no banco de dados e, caso não esteja (isso é, não seja
  * idêntico), o armazena.
  *
  * @param objeto objeto que será verificado e armazenado no banco de dados @
  */
 public void armazenarVerificar(Object objeto) {
   ObjectSet<Object> resultado = bd.queryByExample(objeto);
   if (resultado == null || resultado.size() == 0) {
     bd.store(objeto);
   } else {
     throw new RuntimeException("[armazenar] Objeto existente no banco de dados.");
   }
 }
 public Boolean verificar(Object objeto) {
   ObjectSet<Object> resultado = bd.queryByExample(objeto);
   if (resultado == null || resultado.size() == 0) {
     return true;
   } else {
     return false;
   }
 }
 public void deleteTemplates() {
   openTemplateDb();
   ObjectSet<Request> objectList = dbTemplateContainer.queryByExample(null);
   while (objectList.hasNext()) {
     Request r = (Request) objectList.next();
     dbTemplateContainer.delete(r);
   }
   closeTemplateDb();
 }
 public void deleteRequests() {
   openRequestDb();
   Request req = new Request();
   ObjectSet<Request> objectList = dbRequestContainer.queryByExample(req);
   while (objectList.hasNext()) {
     Request r = (Request) objectList.next();
     dbRequestContainer.delete(r);
   }
   closeRequestDb();
 }
 public SimpleRequestTemplate getTemplate() {
   openTemplateDb();
   SimpleRequestTemplate result = null;
   ObjectSet<SimpleRequestTemplate> objectList = dbTemplateContainer.queryByExample(null);
   if (objectList != null) {
     result = (SimpleRequestTemplate) objectList.next();
   }
   closeTemplateDb();
   return result;
 }
 public ArrayList<Request> getRequests() {
   openRequestDb();
   ArrayList<Request> result = new ArrayList<Request>();
   Request req = new Request();
   ObjectSet<Request> objectList = dbRequestContainer.queryByExample(req);
   while (objectList.hasNext()) {
     result.add(objectList.next());
   }
   closeRequestDb();
   return result;
 }
 /**
  * Apaga um objeto armazenado no banco de dados, após verificar que ele realmente está armazenado
  * (os atributos devem ter valores idênticos).
  *
  * @param objeto objeto que será apagado do banco de dados @
  */
 public void apagar(Object objeto) {
   if (objeto != null) {
     List resultado = bd.queryByExample(objeto);
     if (resultado.size() > 0) {
       bd.delete(objeto);
     } else {
       throw new RuntimeException("[apagar] Objeto não encontrado no banco de dados.");
     }
   } else {
     System.out.println("[apagar] Erro: objeto nulo.");
   }
 }
Example #9
0
 public ArrayList<Jogo> buscarJogos() {
   ObjectContainer bd = Db4o.openFile("BD/DADOS.yep");
   ArrayList<Jogo> jogoList = new ArrayList<Jogo>();
   try {
     ObjectSet result = bd.queryByExample(new Jogo());
     for (int i = 0; i < result.size(); i++) jogoList.add((Jogo) result.next());
   } catch (Exception e) {
     JOptionPane.showMessageDialog(null, "Error ao buscar Times!!!");
   } finally {
     bd.close();
   }
   return jogoList;
 }
Example #10
0
 public void specific(ObjectContainer con, int step) {
   super.specific(con, step);
   TEntry entry = new TEntry().lastElement();
   Stack stack = new Stack();
   if (step > 0) {
     stack.addElement(entry.key);
     ObjectSet set = con.queryByExample(stack);
     if (set.size() != step) {
       Regression.addError("Stack member query not found");
     } else {
       Stack res = (Stack) set.next();
       if (!(stack.pop().equals(new TEntry().lastElement().key))) {
         Regression.addError("Stack order changed.");
       }
     }
   }
 }
 public void armazenarSeNaoExiste(Object objeto) {
   ObjectSet<Object> resultado = bd.queryByExample(objeto);
   if (resultado == null || resultado.size() == 0) {
     bd.store(objeto);
   }
 }
  public static ObjectSet<RegisterContextRequest> getAllRegistrations() {

    ObjectSet<RegisterContextRequest> result = db.queryByExample(RegisterContextRequest.class);
    // listResult(result);
    return result;
  }
    /** @sharpen.remove */
    public void test() throws IOException {

      boolean cached = USE_CACHE.value().booleanValue();
      boolean useLogFile = USE_LOGFILE.value().booleanValue();
      boolean writeTrash = WRITE_TRASH.value().booleanValue();

      if (cached && writeTrash) {
        System.err.println(
            "DISABLED CrashSimulatingTestCase: combination of write trash and cache");
        // The cache may touch more bytes than the ones we modified.
        // We should be safe even if we don't get this test to pass.
        return;
      }

      if (useLogFile && writeTrash) {
        System.err.println(
            "DISABLED CrashSimulatingTestCase: combination of write trash and use log file");

        // The log file is not a public API yet anyway.
        // It's only needed for the PointerBasedIdSystem
        // With the new BTreeIdSystem it's not likely to become important
        // so we can safely ignore the failing write trash case.
        return;
      }

      if (Platform4.needsLockFileThread()) {
        System.out.println(
            "CrashSimulatingTestCase is ignored on platforms with lock file thread.");
        return;
      }

      String path = Path4.combine(Path4.getTempPath(), "crashSimulate");
      String fileName = Path4.combine(path, "cs");

      File4.delete(fileName);
      File4.mkdirs(path);

      createFile(baseConfig(useLogFile), fileName);

      CrashSimulatingStorage crashSimulatingStorage =
          new CrashSimulatingStorage(new FileStorage(), fileName);
      Storage storage =
          cached ? (Storage) new CachingStorage(crashSimulatingStorage) : crashSimulatingStorage;

      Configuration recordConfig = baseConfig(useLogFile);
      recordConfig.storage(storage);

      ObjectContainer oc = Db4o.openFile(recordConfig, fileName);

      ObjectSet objectSet = oc.queryByExample(new CrashData(null, "three"));
      oc.delete(objectSet.next());

      oc.store(new CrashData(null, "four"));
      oc.store(new CrashData(null, "five"));
      oc.store(new CrashData(null, "six"));
      oc.store(new CrashData(null, "seven"));
      oc.store(new CrashData(null, "eight"));
      oc.store(new CrashData(null, "nine"));
      oc.store(new CrashData(null, "10"));
      oc.store(new CrashData(null, "11"));
      oc.store(new CrashData(null, "12"));
      oc.store(new CrashData(null, "13"));
      oc.store(new CrashData(null, "14"));

      oc.commit();

      Query q = oc.query();
      q.constrain(CrashData.class);
      objectSet = q.execute();
      while (objectSet.hasNext()) {
        CrashData cData = (CrashData) objectSet.next();
        if (!(cData._name.equals("10") || cData._name.equals("13"))) {
          oc.delete(cData);
        }
      }

      oc.commit();

      oc.close();

      int count = crashSimulatingStorage._batch.writeVersions(fileName, writeTrash);

      checkFiles(useLogFile, fileName, "R", crashSimulatingStorage._batch.numSyncs());
      checkFiles(useLogFile, fileName, "W", count);
      if (VERBOSE) {
        System.out.println("Total versions: " + count);
      }
    }