public void testDescendOne() {
    Query q = newQuery();

    q.constrain(STArrIntegerWTONTestCase.class);
    q.descend("intArr").constrain(new Integer(17));
    expect(q, new int[] {3, 4});
  }
示例#2
0
  // FIXME
  public void _testDescendOne() {
    Query q = newQuery();

    q.constrain(STVectorEU.class);
    q.descend("col").constrain(new Integer(17));
    expect(q, new int[] {0});
  }
 @SuppressWarnings("unchecked")
 private ObjectSet executeSODAQuery(final A a, Evaluation e) {
   Query q = db().query();
   q.constrain(e);
   ObjectSet set = q.execute();
   return set;
 }
示例#4
0
  public void handleRevisions(
      EClass eClass,
      CDOBranch branch,
      long timeStamp,
      boolean exactTime,
      CDORevisionHandler handler) {
    Query query = getObjectContainer().query();
    query.constrain(DB4ORevision.class);
    if (eClass != null) {
      query
          .descend(DB4ORevision.ATTRIBUTE_PACKAGE_NS_URI)
          .constrain(eClass.getEPackage().getNsURI());
      query.descend(DB4ORevision.ATTRIBUTE_CLASS_NAME).constrain(eClass.getName());
    }

    ObjectSet<?> revisions = query.execute();
    if (revisions.isEmpty()) {
      return;
    }

    for (Object revision : revisions.toArray()) {
      CDORevision cdoRevision = DB4ORevision.getCDORevision(getStore(), (DB4ORevision) revision);
      handler.handleRevision(cdoRevision);
    }
  }
 public void testDescendOne() {
   Query q = st.query();
   Object[] r = store();
   q.constrain(STOwnCollectionW.class);
   q.descend("col").constrain(new Integer(17));
   st.expect(q, new Object[] {r[3], r[4]});
 }
示例#6
0
 public void testGreater() {
   Query q = st.query();
   q.constrain(new STInteger(9));
   q.descend("i_int").constraints().greater();
   Object[] r = store();
   st.expect(q, new Object[] {r[2], r[3]});
 }
示例#7
0
 public void testNotLike() {
   Query q = st.query();
   q.constrain(new STInteger(1));
   q.descend("i_int").constraints().like().not();
   Object[] r = store();
   st.expect(q, new Object[] {r[0], r[2], r[3]});
 }
  public void testSmaller() {
    Query q = newQuery();
    q.constrain(new STDoubleTestCase(1));
    q.descend("i_double").constraints().smaller();

    expect(q, new int[] {0, 1});
  }
  public void testGreaterOrEqual() {
    Query q = newQuery();
    q.constrain(_array[2]);
    q.descend("i_double").constraints().greater().equal();

    expect(q, new int[] {2, 3, 4});
  }
 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();
 }
示例#11
0
  public void testGreater() {
    Query q = newQuery();
    q.constrain(new STDoubleTestCase(1));
    q.descend("i_double").constraints().greater();

    expect(q, new int[] {2, 3, 4});
  }
  public void testDescendOne() {
    Query q = newQuery();

    q.constrain(STHashSetUTestCase.class);
    q.descend("col").constrain(new Integer(17));
    expect(q, new int[] {3, 4});
  }
  public void testDescendToObject() {
    Query q = newQuery();

    q.constrain(new STHashSetUTestCase());
    q.descend("col").descend("foo1").constrain("bar");
    expect(q, new int[] {5, 6});
  }
 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;
 }
 public long size(ObjectContainer container) {
   Query query = container.query();
   query.constrain(PersistentCooldownQueueItem.class);
   query.descend("parent").constrain(this).identity();
   ObjectSet<PersistentCooldownQueueItem> results = query.execute();
   return results.size();
 }
示例#16
0
 public void testDescendOne() {
   Query q = st.query();
   Object[] r = store();
   q.constrain(STArrIntegerON.class);
   q.descend("intArr").constrain(new Integer(17));
   st.expect(q, new Object[] {r[3], r[4]});
 }
示例#17
0
 public void testNotEquals() {
   Query q = st.query();
   Object[] r = store();
   q.constrain(r[0]);
   q.descend("i_int").constrain(new Integer(0)).not();
   st.expect(q, new Object[] {r[1], r[2], r[3]});
 }
 public void testLastOrderWins() {
   Query query = newQuery(Data.class);
   query.descend("_id").orderDescending();
   query.descend("_id").orderAscending();
   query.descend("_id").constrain(new Integer(0)).greater();
   assertOrdered(query.execute());
 }
示例#19
0
 public void testNotContains() {
   Query q = st.query();
   q.constrain(new STInteger(0));
   q.descend("i_int").constrain(new Integer(0)).contains().not();
   Object[] r = store();
   st.expect(q, new Object[] {r[1], r[2]});
 }
  /**
   * Creates an {@link AttachedDevice} resource in the DataBase and validates the transaction
   *
   * @param resource - The {@link AttachedDevice} resource to create
   */
  public void create(AttachedDevice resource) {
    // Store the created resource
    DB.store(resource);
    // MgmtObjs
    MgmtObjs mgmtObjs = new MgmtObjs();
    mgmtObjs.setUri(resource.getMgmtObjsReference());
    mgmtObjs.setCreationTime(resource.getCreationTime());
    mgmtObjs.setLastModifiedTime(resource.getLastModifiedTime());
    mgmtObjs.setAccessRightID(resource.getAccessRightID());
    DAOFactory.getMgmtObjsDAO().create(mgmtObjs);
    // Subscriptions
    Subscriptions subscriptions = new Subscriptions();
    subscriptions.setUri(resource.getSubscriptionsReference());
    DAOFactory.getSubscriptionsDAO().create(subscriptions);
    // Create the query based on the uri constraint
    Query query = DB.query();
    query.constrain(AttachedDevices.class);
    query.descend("uri").constrain(resource.getUri().split("/" + resource.getId())[0]);
    // Store all the founded resources
    ObjectSet<AttachedDevices> result = query.execute();

    // Update the lastModifiedTime attribute of the parent
    AttachedDevices attachedDevices = result.get(0);
    // Update the lastModifiedTime attribute of the parent
    attachedDevices.setLastModifiedTime(
        DateConverter.toXMLGregorianCalendar(new Date()).toString());
    DB.store(attachedDevices);
    // Validate the current transaction
    commit();
  }
示例#21
0
  public void testQueryEvents() {

    EventRegistry registry = EventRegistryFactory.forObjectContainer(db());

    EventRecorder recorder = new EventRecorder(fileSession().lock());

    registry.queryStarted().addListener(recorder);
    registry.queryFinished().addListener(recorder);

    Assert.areEqual(0, recorder.size());

    Query q = db().query();
    q.execute();

    Assert.areEqual(2, recorder.size());
    EventRecord e1 = recorder.get(0);
    Assert.areSame(registry.queryStarted(), e1.e);
    Assert.areSame(q, ((QueryEventArgs) e1.args).query());

    EventRecord e2 = recorder.get(1);
    Assert.areSame(registry.queryFinished(), e2.e);
    Assert.areSame(q, ((QueryEventArgs) e2.args).query());

    recorder.clear();

    registry.queryStarted().removeListener(recorder);
    registry.queryFinished().removeListener(recorder);

    db().query().execute();

    Assert.areEqual(0, recorder.size());
  }
示例#22
0
 public void testDescendantDescendantStringPath() {
   Query q = st.query();
   Object[] r = store();
   q.constrain(new STRUH1());
   q.descend("h2").descend("h3").descend("foo3").constrain("str3");
   st.expect(q, new Object[] {r[4], r[5]});
 }
 private Item itemByName(String string) {
   Query q = db().query();
   q.constrain(Item.class);
   q.descend("_name").constrain(string);
   Object object = q.execute().next();
   return (Item) object;
 }
示例#24
0
 public void testStrNull() {
   Query q = st.query();
   q.constrain(new STRUH1());
   q.descend("foo1").constrain(null);
   Object[] r = store();
   st.expect(q, new Object[] {r[0], r[2], r[3], r[4], r[5]});
 }
示例#25
0
 public void testDescendToObject() {
   Query q = st.query();
   Object[] r = store();
   q.constrain(new STHashtableT());
   q.descend("col").descend("foo1").constrain("bar");
   st.expect(q, new Object[] {r[5], r[6]});
 }
示例#26
0
 public void testBothNull() {
   Query q = st.query();
   q.constrain(new STRUH1());
   q.descend("foo1").constrain(null);
   q.descend("h2").constrain(null);
   st.expectOne(q, store()[0]);
 }
  @SuppressWarnings("unchecked")
  private void garbageCollectIdentities() {
    final MessageManager messageManager = mFreetalk.getMessageManager();
    final PersistentTaskManager taskManager = mFreetalk.getTaskManager();

    synchronized (this) {
      if (mIdentityFetchInProgress
          || mOwnIdentityFetchInProgress
          || mLastIdentityFetchTime == 0
          || mLastOwnIdentityFetchTime == 0) return;

      /* Executing the thread loop once will always take longer than THREAD_PERIOD. Therefore, if we set the limit to 3*THREAD_PERIOD,
       * it will hit identities which were last received before more than 2*THREAD_LOOP, not exactly 3*THREAD_LOOP. */
      long lastAcceptTime =
          Math.min(mLastIdentityFetchTime, mLastOwnIdentityFetchTime) - GARBAGE_COLLECT_DELAY;
      lastAcceptTime =
          Math.max(
              lastAcceptTime,
              0); // This is not really needed but a time less than 0 does not make sense.;

      Query q = db.query();
      q.constrain(WoTIdentity.class);
      q.descend("mLastReceivedFromWoT").constrain(lastAcceptTime).smaller();
      ObjectSet<WoTIdentity> result = q.execute();

      for (WoTIdentity identity : result) {
        identity.initializeTransient(mFreetalk);
        Logger.debug(this, "Garbage collecting identity " + identity);
        deleteIdentity(identity, messageManager, taskManager);
      }

      if (mShortestUniqueNicknameCacheNeedsUpdate) updateShortestUniqueNicknameCache();
    }
  }
示例#28
0
 public void testDescendantDescendantNotNull() {
   Query q = st.query();
   Object[] r = store();
   q.constrain(new STRUH1());
   q.descend("h2").descend("h3").constrain(null).not();
   st.expect(q, new Object[] {r[4], r[5]});
 }
示例#29
0
 public void testDescendOne() {
   Query q = st.query();
   Object[] r = store();
   q.constrain(STVectorEU.class);
   q.descend("col").constrain(new Integer(17));
   st.expect(q, new Object[] {r[0]});
 }
示例#30
0
  /**
   * ATTENTION: This function is duplicated in the Web Of Trust plugin, please backport any changes.
   */
  private void databaseIntegrityTest() {
    Logger.normal(this, "Testing database integrity...");
    synchronized (mIdentityManager) {
      synchronized (mMessageManager) {
        synchronized (mTaskManager) {
          final Query q = db.query();
          q.constrain(Persistent.class);

          for (final Persistent p : new Persistent.InitializingObjectSet<Persistent>(this, q)) {
            try {
              p.databaseIntegrityTest();
            } catch (Exception e) {
              try {
                Logger.error(this, "Integrity test failed for " + p, e);
              } catch (Exception toStringException) {
                Logger.error(
                    this,
                    "Integrity test failed for object and toString also failed, toString-Exception below",
                    toStringException);
                Logger.error(this, "Original integrity test failure below", e);
              }
            }
          }
        }
      }
    }
    Logger.normal(this, "Database integrity test finished.");
  }