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);
 }
示例#2
0
 //	Constructors and Operations:
 public static void main(String[] arg) {
   ObjectContainer db = Db4oEmbedded.openFile(Db4oEmbedded.newConfiguration(), DB.TAXI);
   System.out.println("Datenbank " + DB.TAXI + " wurde geöffnet.");
   try {
     //	Hier tun wir etwas mit der Datenbank.
   } finally {
     db.close();
   }
 }
 private void createFile(Configuration config, String fileName) throws IOException {
   ObjectContainer oc = Db4o.openFile(config, fileName);
   try {
     populate(oc);
   } finally {
     oc.close();
   }
   File4.copy(fileName, fileName + "0");
 }
 /** @deprecated using deprecated api */
 public void test() throws Exception {
   int originalActivationDepth = ((Config4Impl) Db4o.configure()).activationDepth();
   Db4o.configure().activationDepth(0);
   ObjectServer server = Db4oClientServer.openServer(tempFile(), -1);
   try {
     server.grantAccess("db4o", "db4o");
     ObjectContainer oc =
         Db4oClientServer.openClient("localhost", server.ext().port(), "db4o", "db4o");
     oc.close();
   } finally {
     Db4o.configure().activationDepth(originalActivationDepth);
     server.close();
   }
 }
示例#5
0
  protected static void showAgglomerationsInfoFromDeparment(ObjectContainer bd, String depId) {

    ObjectSet<Departement> oc =
        bd.query(
            new Predicate<Departement>() {
              public boolean match(Departement d) {
                return true;
              }
            });
    for (Departement d : oc) {
      if (d.getNom() == depId) {
        for (Agglomeration ag : d.agglomerations) {
          System.out.println(
              "codePostal: "
                  + ag.codePostal
                  + " nom: "
                  + ag.nom
                  + " descritpion: "
                  + ag.description
                  + " nbHabit: "
                  + ag.description
                  + " surface: "
                  + d.surface);
        }
      }
    }
  }
 private void checkFiles(boolean useLogFile, String fileName, String infix, int count) {
   for (int i = 1; i <= count; i++) {
     String versionedFileName = fileName + infix + i;
     if (VERBOSE) {
       System.out.println("Checking " + versionedFileName);
     }
     ObjectContainer oc = Db4o.openFile(baseConfig(useLogFile), versionedFileName);
     try {
       if (!stateBeforeCommit(oc)) {
         if (!stateAfterFirstCommit(oc)) {
           Assert.isTrue(stateAfterSecondCommit(oc));
         }
       }
     } finally {
       oc.close();
     }
   }
 }
  public void test() {

    final Collection4 expected =
        new Collection4(new Object[] {"PING", Boolean.TRUE, new Integer(42)});
    final MessageCollector recipient = new MessageCollector();
    final ObjectServer server = openServerWith(recipient);
    try {
      final ObjectContainer client = openClient("client", server);
      try {
        final MessageSender sender = messageSender(client);
        sendAll(expected, sender);
      } finally {
        client.close();
      }
    } finally {
      server.close();
    }

    Assert.areEqual(expected.toString(), recipient.messages.toString());
  }
 private boolean expect(ObjectContainer container, String[] names) {
   Collection4 expected = new Collection4(names);
   ObjectSet actual = container.query(CrashData.class);
   while (actual.hasNext()) {
     CrashData current = (CrashData) actual.next();
     if (!expected.remove(current._name)) {
       return false;
     }
   }
   return expected.isEmpty();
 }
  public void test() {

    Test.store(new Parent1(new Child1()));

    ObjectContainer container = Test.reOpen();
    container
        .ext()
        .configure()
        .addAlias(new TypeAlias("com.db4o.test.aliases.Parent1", "com.db4o.test.aliases.Parent2"));
    container
        .ext()
        .configure()
        .addAlias(new TypeAlias("com.db4o.test.aliases.Child1", "com.db4o.test.aliases.Child2"));

    ObjectSet os = container.query(Parent2.class);

    Test.ensure(os.size() > 0);

    Parent2 p2 = (Parent2) os.next();

    Test.ensure(p2.child != null);
  }
示例#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.");
       }
     }
   }
 }
  private void predictCollisions(Ball sourceBall) {
    double dt = CollisionUtils.calcTimeToHitWall(sourceBall, WallType.HORIZONTAL);
    if (CollisionUtils.isCollisionConsistency(dt)) {
      queue.add(new WallCollisionEvent(timer.getTimestamp(dt), sourceBall, WallType.HORIZONTAL));
    }

    dt = CollisionUtils.calcTimeToHitWall(sourceBall, WallType.VERTICAL);
    if (CollisionUtils.isCollisionConsistency(dt)) {
      queue.add(new WallCollisionEvent(timer.getTimestamp(dt), sourceBall, WallType.VERTICAL));
    }

    for (Ball targetBall : objectContainer.getBalls()) {
      dt = CollisionUtils.calcTimeToHitBall(sourceBall, targetBall);
      if (CollisionUtils.isCollisionConsistency(dt)) {
        queue.add(new BallCollisionEvent(timer.getTimestamp(dt), sourceBall, targetBall));
      }
    }
  }
 private void populate(ObjectContainer container) {
   for (int i = 0; i < 10; i++) {
     container.store(new Item("delme"));
   }
   CrashData one = new CrashData(null, "one");
   CrashData two = new CrashData(one, "two");
   CrashData three = new CrashData(one, "three");
   container.store(one);
   container.store(two);
   container.store(three);
   container.commit();
   ObjectSet objectSet = container.query(Item.class);
   while (objectSet.hasNext()) {
     container.delete(objectSet.next());
   }
 }
示例#13
0
 private void start() {
   ObjectContainer oc =
       com.db4o.cs.Db4oClientServer.openClient(
           Db4oNetworking.HOST, _port, Db4oNetworking.USERNAME, Db4oNetworking.PASSWORD);
   oc.store(new Item(0));
   oc.commit();
   print("[0]");
   print(CLIENT_STARTED_OK);
   for (int i = 1; i < ITEM_COUNT; i++) {
     oc.store(new Item(i));
     oc.commit();
     print("[" + i + "]");
   }
   oc.close();
   print(CLIENT_COMPLETED_OK);
 }
示例#14
0
  public static void main(String[] args) {
    new File(FILE).delete();
    ObjectContainer oc = Db4o.openFile(FILE);
    for (int i = 0; i < COUNT; i++) {
      oc.store(new AddJustOneObject());
    }
    oc.close();

    oc = Db4o.openFile(FILE);
    long start = System.currentTimeMillis();
    oc.store(new AddJustOneObject());
    oc.commit();
    long stop = System.currentTimeMillis();
    oc.close();

    long duration = stop - start;

    System.out.println("Add one to " + COUNT + " and commit: " + duration + "ms");
  }
示例#15
0
 public void objectOnDeactivate(ObjectContainer container) {
   container.deactivate(parent, 3);
 }
示例#16
0
 /**
  * Method for getting the index of a given Panel
  *
  * @param object The object to get the index of
  * @return The index of the given object
  */
 public int getIndex(GPropertiesPanel object) {
   return objects.getIndex(object);
 }
示例#17
0
 /**
  * Method gets the size of this container.
  *
  * @return The size.
  */
 public int getPanelsSize() {
   return objects.getSize();
 }
示例#18
0
 /**
  * Method for getting a Panel by index reference
  *
  * @param index The index of the object
  * @return The object with the given index
  */
 public GPropertiesPanel getPanel(int index) {
   return (GPropertiesPanel) objects.get(index);
 }
示例#19
0
 /** Method for removing all current Panels */
 public void removeAllPanels() {
   pane.removeAll();
   objects.removeAll();
 }
示例#20
0
 /**
  * Method for removing a Panel by object reference
  *
  * @param object The object to remove
  */
 public void removePanel(GPropertiesPanel object) {
   pane.remove(object);
   objects.remove(object);
 }
示例#21
0
 /**
  * Method for removing a Panel by index reference
  *
  * @param index The index of the object to remove
  */
 public void removePanel(int index) {
   pane.remove((GPropertiesPanel) objects.get(index));
   objects.remove(index);
 }
示例#22
0
 /**
  * Method for adding a new Panel
  *
  * @param object The new Panel
  */
 public void addPanel(GPropertiesPanel object, String title) {
   pane.add(object, title);
   objects.add(object);
 }
示例#23
0
 public void sodaQuery(ObjectContainer oc) {
   Query q = oc.query();
   q.constrain(Cat.class);
   constrain(q);
   q.execute();
 }
 private void moveBalls(double dt) {
   for (Ball ball : objectContainer.getBalls()) {
     ball.move(dt);
   }
 }
 public static long[] allActivatableElementIds(ObjectContainer db) {
   Query q = db.query();
   q.constrain(ActivatableElement.class);
   ObjectSet<Object> objectSet = q.execute();
   return objectSet.ext().getIDs();
 }
    /** @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);
      }
    }
示例#27
0
 public void objectOnActivate(ObjectContainer container) {
   CallbacksTestCase.called[CallbacksTestCase.ACTIVATE] = true;
   container.activate(parent, 3);
 }
示例#28
0
 public boolean objectCanDelete(ObjectContainer container) {
   container.activate(this, Integer.MAX_VALUE);
   Test.ensure(_name.equals("p1"));
   Test.ensure(_next != null);
   return true;
 }
示例#29
0
 public void objectOnDelete(ObjectContainer container) {
   container.delete(parent);
 }
示例#30
0
  public void test() {

    ObjectContainer con = Test.objectContainer();
    Test.deleteAllInstances(this);

    IsStored isStored = new IsStored();
    isStored.myString = "isStored";
    con.store(isStored);
    Test.ensure(con.ext().isStored(isStored));
    Test.ensure(Test.occurrences(this) == 1);
    con.delete(isStored);
    Test.ensure(!con.ext().isStored(isStored));
    Test.ensure(Test.occurrences(this) == 0);
    con.commit();
    if (con.ext().isStored(isStored)) {

      // this will fail in CS due to locally cached references
      if (!Test.clientServer) {
        Test.error();
      }
    }
    Test.ensure(Test.occurrences(this) == 0);
    con.store(isStored);
    Test.ensure(con.ext().isStored(isStored));
    Test.ensure(Test.occurrences(this) == 1);
    con.commit();
    Test.ensure(con.ext().isStored(isStored));
    Test.ensure(Test.occurrences(this) == 1);
    con.delete(isStored);
    Test.ensure(!con.ext().isStored(isStored));
    Test.ensure(Test.occurrences(this) == 0);
    con.commit();
    if (con.ext().isStored(isStored)) {

      // this will fail in CS due to locally cached references
      if (!Test.clientServer) {
        Test.error();
      }
    }
    Test.ensure(Test.occurrences(this) == 0);
  }