private void restoreMembers(Data data) {
   Query q = newQuery(Data.class);
   ObjectSet objectSet = q.execute();
   Data rdata = (Data) objectSet.next();
   data.i_map = rdata.i_map;
   data.i_helper = rdata.i_helper;
 }
 private Item storedItem(String id) {
   Query query = newQuery(Item.class);
   query.descend("_id").constrain(id);
   ObjectSet<Item> result = query.execute();
   Assert.isTrue(result.hasNext());
   return result.next();
 }
 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);
 }
  public Object sample(int n) {
    if ((n < 0) || (n >= size)) {
      throw new IllegalArgumentException(
          "Can't get element " + n + " from set " + this + " of size " + size);
    }

    if (n < individuals.size()) {
      return individuals.get(n);
    }

    int indexSoFar = individuals.size();
    for (Iterator iter = popAppSatisfiers.entrySet().iterator(); iter.hasNext(); ) {
      Map.Entry entry = (Map.Entry) iter.next();
      NumberVar popApp = (NumberVar) entry.getKey();
      ObjectSet satisfiers = (ObjectSet) entry.getValue();
      Set exceptions = (Set) popAppExceptions.get(popApp);

      int numInSet = satisfiers.size() - exceptions.size();
      if (n < indexSoFar + numInSet) {
        return sampleFromPOPApp(satisfiers, exceptions, n - indexSoFar);
      }
      indexSoFar += numInSet;
    }

    return null; // shouldn't get here
  }
 public void test() {
   SubClass subClass = retrieveOnlyInstance(SubClass.class);
   db().delete(subClass);
   db().commit();
   ObjectSet objectSet = db().query(Member.class);
   Assert.areEqual(0, objectSet.size());
 }
Beispiel #6
0
 public void _test() throws Exception {
   Query query = newQuery();
   query.constrain(new TestEvaluation());
   query.constrain(Item.class);
   query.descend("name").orderDescending();
   ObjectSet set = query.execute();
   Assert.areEqual(3, set.size());
 }
 public void testAllThere() throws Exception {
   for (int i = 0; i < FOOS.length; i++) {
     Query q = createQuery(FOOS[i]);
     ObjectSet objectSet = q.execute();
     Assert.areEqual(1, objectSet.size());
     FieldIndexItem fii = (FieldIndexItem) objectSet.next();
     Assert.areEqual(FOOS[i], fii.foo);
   }
 }
 private void assertQueryForTimestamp(Item expected, long timestamp) {
   Query query = db().query();
   query.constrain(Item.class);
   query.descend(VirtualField.COMMIT_TIMESTAMP).constrain(timestamp);
   ObjectSet<Object> objectSet = query.execute();
   Assert.areEqual(1, objectSet.size());
   Item actual = (Item) objectSet.next();
   Assert.areSame(expected, actual);
 }
 private void assertOrdered(ObjectSet result) {
   Assert.areEqual(IDS.length, result.size());
   int previousId = 0;
   while (result.hasNext()) {
     Data data = (Data) result.next();
     Assert.isTrue(previousId < data._id);
     previousId = data._id;
   }
 }
 public void checkUpdateSameObject(ExtObjectContainer oc) throws Exception {
   Query query = oc.query();
   query.descend("_s").constrain(testString + COUNT / 2);
   ObjectSet result = query.execute();
   Assert.areEqual(1, result.size());
   SimpleObject o = (SimpleObject) result.next();
   int i = o.getI();
   Assert.isTrue(COUNT <= i && i < COUNT + threadCount());
 }
 @SuppressWarnings("unchecked")
 public void testCircularEvaluation() throws Exception {
   populate();
   CircularEvaluator.D one = new CircularEvaluator.D(null, _a);
   CircularEvaluator.D two = new CircularEvaluator.D(one, _a);
   one._d = two;
   ObjectSet set = executeSODAQuery(_a, new CircularEvaluator(one));
   Assert.areEqual(1, set.size());
 }
 public void concUpdateSameObject(ExtObjectContainer oc, int seq) throws Exception {
   Query query = oc.query();
   query.descend("_s").constrain(testString + COUNT / 2);
   ObjectSet result = query.execute();
   Assert.areEqual(1, result.size());
   SimpleObject o = (SimpleObject) result.next();
   o.setI(COUNT + seq);
   oc.store(o);
 }
Beispiel #13
0
  // assumes o is in satisfiers \ exceptions
  private int getIndexInPOPApp(ObjectSet satisfiers, Set exceptions, Object o) {
    SortedSet exceptionIndices = new TreeSet();
    for (Iterator iter = exceptions.iterator(); iter.hasNext(); ) {
      Object exception = iter.next();
      exceptionIndices.add(new Integer(satisfiers.indexOf(exception)));
    }

    int origIndex = satisfiers.indexOf(o);
    int numExceptionsBefore = exceptionIndices.headSet(new Integer(origIndex)).size();
    return (origIndex - numExceptionsBefore);
  }
  // It will fail for C/S because the reference system in the
  // server is not in sync.
  @SuppressWarnings("unchecked")
  public void _testChangingSODA() throws Exception {
    populate();
    _b.a = new A();

    ObjectSet set = executeSODAQuery(_a, new Evaluator(_a));
    Assert.areEqual(0, set.size());

    set = executeSODAQuery(_b.a, new Evaluator(_b.a));
    Assert.areEqual(1, set.size());
  }
 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();
 }
Beispiel #16
0
 public void testIdentity() {
   Query q = st.query();
   q.constrain(new STInteger(1));
   ObjectSet set = q.execute();
   STInteger identityConstraint = (STInteger) set.next();
   identityConstraint.i_int = 9999;
   q = st.query();
   q.constrain(identityConstraint).identity();
   identityConstraint.i_int = 1;
   st.expectOne(q, store()[1]);
 }
 public void concUpdate(ExtObjectContainer oc, int seq) throws Exception {
   Query q = oc.query();
   q.constrain(IndexedByIdentityTestCase.class);
   ObjectSet os = q.execute();
   Assert.areEqual(COUNT, os.size());
   while (os.hasNext()) {
     IndexedByIdentityTestCase idi = (IndexedByIdentityTestCase) os.next();
     idi.atom.name = "updated" + seq;
     oc.store(idi);
     Thread.sleep(100);
   }
 }
 public void testUpdate() {
   ExtObjectContainer oc = fixture().db();
   initGenericObjects();
   // Db4oUtil.dump(oc);
   ReflectClass rc = getReflectClass(oc, PERSON_CLASSNAME);
   Assert.isNotNull(rc);
   Query q = oc.query();
   q.constrain(rc);
   ObjectSet results = q.execute();
   // Db4oUtil.dumpResults(oc, results);
   Assert.isTrue(results.size() == 1);
 }
 public void testQuery() {
   ExtObjectContainer oc = fixture().db();
   initGenericObjects();
   ReflectClass rc = getReflectClass(oc, PERSON_CLASSNAME);
   Assert.isNotNull(rc);
   // now query to make sure there are none left
   Query q = oc.query();
   q.constrain(rc);
   q.descend("surname").constrain("John");
   ObjectSet results = q.execute();
   Assert.isTrue(results.size() == 1);
 }
 public void concUpdateDifferentObject(ExtObjectContainer oc, int seq) throws Exception {
   Query query = oc.query();
   query
       .descend("_s")
       .constrain(testString + seq)
       .and(query.descend("_i").constrain(new Integer(seq)));
   ObjectSet result = query.execute();
   Assert.areEqual(1, result.size());
   SimpleObject o = (SimpleObject) result.next();
   o.setI(seq + COUNT);
   oc.store(o);
 }
 public void test() {
   Query q = st.query();
   Object[] r = store();
   q.constrain(new Helper("aaa"));
   ObjectSet os = q.execute();
   Helper helperA = (Helper) os.next();
   q = st.query();
   q.constrain(STIdentityEvaluation.class);
   q.descend("helper").constrain(helperA).identity();
   q.constrain(new IncludeAllEvaluation());
   st.expect(q, new Object[] {r[1], r[2], r[3]});
 }
Beispiel #22
0
 public void testQuery() {
   Query q = Test.query();
   ObjectSet objectSet = q.execute();
   Test.ensure(objectSet.size() >= 2);
   int i = 0;
   while (objectSet.hasNext()) {
     Object obj = objectSet.next();
     Test.ensure(obj != null);
     i++;
   }
   Test.ensure(i >= 2);
 }
Beispiel #23
0
 public void testNotIdentity() {
   Query q = st.query();
   q.constrain(new STInteger(1));
   ObjectSet set = q.execute();
   STInteger identityConstraint = (STInteger) set.next();
   identityConstraint.i_int = 9080;
   q = st.query();
   q.constrain(identityConstraint).identity().not();
   identityConstraint.i_int = 1;
   Object[] r = store();
   st.expect(q, new Object[] {r[0], r[2], r[3]});
 }
Beispiel #24
0
  /**
   * Update local information from the scene. It's important that this method is synchronized
   * because we get ConcurrentModificationException's during rendering otherwise.
   *
   * <p>This method is called from sceneChanged().
   */
  protected synchronized void updateCharges(Scene theScene) {
    // Clear cached infos.
    cachedBounds = null;
    cachedWire = null;
    charges.clear();

    setPositive = null;
    setNegative = null;

    // Get all selection sets.
    Object layersObj = theScene.getMetadata("selectionsPlugin.selectionSets");

    if (layersObj == null) return;

    if (!(layersObj instanceof ArrayList)) return;

    ArrayList<ObjectSet> layers = (ArrayList<ObjectSet>) layersObj;

    // Try to find those which are of interest for us.
    for (ObjectSet set : layers) {
      if (set.getName().equals(setNamePositive)) {
        setPositive = set;
      } else if (set.getName().equals(setNameNegative)) {
        setNegative = set;
      }
    }

    // Create charges.
    if (setPositive != null) {
      for (ObjectInfo oi : setPositive.getObjects(theScene)) {
        if (oi.getObject() instanceof Sphere) {
          Sphere s = (Sphere) oi.getObject();
          double q = s.getRadii().x;
          Vec3 pos = oi.getCoords().getOrigin();

          charges.add(new SphereCharge(pos, q));
        }
      }
    }

    if (setNegative != null) {
      for (ObjectInfo oi : setNegative.getObjects(theScene)) {
        if (oi.getObject() instanceof Sphere) {
          Sphere s = (Sphere) oi.getObject();
          double q = -s.getRadii().x;
          Vec3 pos = oi.getCoords().getOrigin();

          charges.add(new SphereCharge(pos, q));
        }
      }
    }
  }
  public void checkUpdateDifferentObject(ExtObjectContainer oc) throws Exception {

    ObjectSet result = oc.query(SimpleObject.class);
    Assert.areEqual(COUNT, result.size());
    while (result.hasNext()) {
      SimpleObject o = (SimpleObject) result.next();
      int i = o.getI();
      if (i >= COUNT) {
        i -= COUNT;
      }
      Assert.areEqual(testString + i, o.getS());
    }
  }
 private void tUpdateB(ExtObjectContainer oc) {
   ObjectSet res = query(oc, "b");
   CreateIndexFor ci = (CreateIndexFor) res.next();
   ci.i_name = "j";
   oc.store(ci);
   res = query(oc, "b");
   Assert.areEqual(0, res.size());
   res = query(oc, "j");
   Assert.areEqual(1, res.size());
   ci.i_name = "b";
   oc.store(ci);
   tQueryB(oc);
 }
  public void testQueryForVersionNumber() {
    store(new Item(NEWER));
    db().commit();

    Item newer = itemByName(NEWER);

    long version = version(newer);

    Query query = db().query();
    query.descend(VirtualField.COMMIT_TIMESTAMP).constrain(new Long(version)).smaller().not();
    ObjectSet<Item> set = query.execute();
    Assert.areEqual(1, set.size());
    Assert.areSame(newer, set.next());
  }
  public void testCreate() throws Exception {

    initGenericObjects();
    // fixture().reopen();
    ExtObjectContainer oc = fixture().db();
    // now check to see if person was saved
    ReflectClass rc = getReflectClass(oc, PERSON_CLASSNAME);
    Assert.isNotNull(rc);
    Query q = oc.query();
    q.constrain(rc);
    ObjectSet results = q.execute();
    Assert.isTrue(results.size() == 1);
    // Db4oUtil.dumpResults(fixture().db(), results);

  }
  public void test() {
    final ItemDates item1 = new ItemDates(new Date(0), new Date());
    final ItemDates item2 =
        new ItemDates(new Date(10000), new Date(System.currentTimeMillis() - 10000));

    a().provider().storeNew(item1);
    a().provider().storeNew(item2);
    a().provider().commit();

    replicateAll(a().provider(), b().provider());

    final ObjectSet found = b().provider().getStoredObjects(ItemDates.class);
    Iterator4Assert.sameContent(
        new Object[] {item2, item1}, ReplicationTestPlatform.adapt(found.iterator()));
  }
Beispiel #30
0
  /**
   * Adds the given POP application satisfier set as a subset of this set, with the given
   * exceptions. The exceptions set must be a subset of the given satisfier set. If the given POP
   * application was already a subset of this set, then the new exceptions set is the intersection
   * of the given exceptions set with the old one. Otherwise, the exceptions set is the given one
   * minus any individual elements of this set that satisfy the given POP application.
   */
  public void addSatisfiers(NumberVar popApp, ObjectSet satisfiers, Set newExceptions) {
    if (popAppSatisfiers.containsKey(popApp)) {
      // already in set; assume satisfiers the same
      Set curExceptions = (Set) popAppExceptions.get(popApp);
      int oldNumExceptions = curExceptions.size();
      curExceptions.retainAll(newExceptions);
      size += (oldNumExceptions - curExceptions.size());
    } else {
      popAppSatisfiers.put(popApp, satisfiers);
      Set oldIndivs = (Set) popAppIndivs.remove(popApp);
      for (Iterator iter = oldIndivs.iterator(); iter.hasNext(); ) {
        individuals.remove(iter.next());
      }

      Set curExceptions = new HashSet(newExceptions);
      curExceptions.removeAll(oldIndivs);
      popAppExceptions.put(popApp, curExceptions);

      size +=
          (satisfiers.size()
              - oldIndivs.size() // because they were already
              // here
              - curExceptions.size()); // because they weren't added
    }
  }