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());
 }
示例#2
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);
    }
  }
示例#3
0
 public void testEqualsNull() {
   Query q = st.query();
   q.constrain(new STOrU(1000, null));
   q.descend("orInt").constraints().or(q.descend("orString").constrain(null));
   Object[] r = store();
   st.expect(q, new Object[] {r[1], r[2], r[4]});
 }
示例#4
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]);
 }
示例#5
0
 public void testTwoLevelOr() {
   Query q = st.query();
   Object[] r = store();
   q.constrain(new STRUH1("str1"));
   q.descend("foo1")
       .constraints()
       .or(q.descend("h2").descend("h3").descend("foo3").constrain("str3"));
   st.expect(q, new Object[] {r[1], r[4], r[5]});
 }
示例#6
0
 public void testLike() {
   Query q = st.query();
   q.constrain(new STInteger(90));
   q.descend("i_int").constraints().like();
   st.expectOne(q, new STInteger(909));
   q = st.query();
   q.constrain(new STInteger(10));
   q.descend("i_int").constraints().like();
   st.expectNone(q);
 }
示例#7
0
 public void testOrAndOr() {
   Query q = st.query();
   q.constrain(new STOrU(0, null));
   (q.descend("orInt").constrain(new Integer(5)).or(q.descend("orString").constrain(null)))
       .and(
           q.descend("orInt")
               .constrain(new Integer(Integer.MAX_VALUE - 1))
               .or(q.descend("orString").constrain("joho")));
   st.expectOne(q, store()[4]);
 }
示例#8
0
 public void testNotOrOrAnd() {
   Query q = st.query();
   q.constrain(new STOrU(0, null));
   (q.descend("orInt")
           .constrain(new Integer(Integer.MAX_VALUE - 1))
           .or(q.descend("orString").constrain("joho")))
       .or(q.descend("orInt").constrain(new Integer(5)).and(q.descend("orString").constrain(null)))
       .not();
   Object[] r = store();
   st.expect(q, new Object[] {r[0], r[3]});
 }
  public void conc(ExtObjectContainer oc) {
    Query q = oc.query();
    q.constrain(QueryForUnknownFieldTestCase.class);
    q.descend("_name").constrain("name");
    Assert.areEqual(1, q.execute().size());

    q = oc.query();
    q.constrain(QueryForUnknownFieldTestCase.class);
    q.descend("name").constrain("name");
    Assert.areEqual(0, q.execute().size());
  }
示例#10
0
 public void testAndOrAnd() {
   Query q = st.query();
   q.constrain(new STOrU(0, null));
   (q.descend("orInt").constrain(new Integer(5)).and(q.descend("orString").constrain(null)))
       .or(
           q.descend("orInt")
               .constrain(new Integer(1000))
               .and(q.descend("orString").constrain("joho")));
   Object[] r = store();
   st.expect(q, new Object[] {r[1], r[2]});
 }
示例#11
0
 public void testSequentialAddition() {
   Query q = st.query();
   store();
   q.constrain(new STRUH1());
   Query cur = q.descend("h2");
   cur.constrain(new STRUH2());
   cur.descend("foo2").constrain("str2");
   cur = cur.descend("h3");
   cur.constrain(new STRUH3());
   cur.descend("foo3").constrain("str3");
   st.expectOne(q, store()[5]);
 }
 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);
 }
示例#13
0
  public List filtrar(Class classe, Evaluation filtro, String campoOrdem, int ordem) {
    Query query = bd.query();
    query.constrain(classe);
    query.constrain(filtro);

    if (ORDENACAO_CRESCENTE == ordem) {
      query.descend(campoOrdem).orderAscending();
    } else {
      query.descend(campoOrdem).orderDescending();
    }

    return query.execute();
  }
示例#14
0
 /**
  * Configura a ordenação do resultado de uma pesquisa, antes de executá-la.
  *
  * @param query a pesquisa que terá sua ordenação configurada
  * @param nomeAtributo o nome do atributo pelo qual a pesquisa será ordenada
  * @param tipoOrdenacao o tipo de ordenação desejada ('1 - crescente' e '2 - decrescente') @
  */
 private void configurarOrdenacao(Query query, String nomeAtributo, int tipoOrdenacao) {
   if (nomeAtributo != null) {
     if (tipoOrdenacao == ORDENACAO_DECRESCENTE || tipoOrdenacao == ORDENACAO_CRESCENTE) {
       if (tipoOrdenacao == ORDENACAO_DECRESCENTE) {
         query.descend(nomeAtributo).orderDescending();
       } else if (tipoOrdenacao == ORDENACAO_CRESCENTE) {
         query.descend(nomeAtributo).orderAscending();
       }
     } else {
       throw new RuntimeException(
           "[pesquisar] Os tipos validos de ordenacao são '1 - crescente' e '2 - decrescente'.");
     }
   }
 }
示例#15
0
  // FIXME
  public void _testDescendOne() {
    Query q = newQuery();

    q.constrain(STVectorEU.class);
    q.descend("col").constrain(new Integer(17));
    expect(q, new int[] {0});
  }
示例#16
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]});
 }
示例#17
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]});
 }
 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]});
 }
 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;
 }
  /**
   * 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 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]});
 }
示例#22
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]});
 }
示例#23
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]});
 }
示例#24
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 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();
 }
示例#26
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]});
 }
  @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 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]});
 }
示例#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
 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]});
 }