示例#1
0
  public void execute(DocumentMap dm) {
    documentMap = dm;
    candidates = new HashSet<String>();
    if ((query1 == null) || (query2 == null)) {
      throw new RuntimeException("Invalid query");
    }
    /* this seems to be faster than using executor.invokeAll (see Or query)
    Future t1 = documentMap.executor.submit(new ConcurrentQuery(query1,documentMap));
    Future t2 = documentMap.executor.submit(new ConcurrentQuery(query2,documentMap));
    while (true) {
        if (t1.isDone() && t2.isDone()) {
            break;
        }
    }
    */

    query1.execute(documentMap);
    query2.execute(documentMap);
    if ((query1.candidates == null) || query1.candidates.isEmpty()) {
      return;
    }
    if ((query2.candidates == null) || query2.candidates.isEmpty()) {
      return;
    }
    for (String cand : query1.candidates) {
      if (query2.candidates.contains(cand)) {
        candidates.add(cand);
      }
    }
    candidateIt = candidates.iterator();
  }
示例#2
0
  @Test
  public void testExecuteOnDBConnection() throws IOException {
    Query<Organisation> query = new Query<Organisation>(Organisation.class);
    query.clear();
    query.add(Organisation.FLD_NAME1, "=", "orgname2");

    // create a new DBConnection
    DBConnection connection = new DBConnection();
    connection.setDBConnectString("jdbc:h2:mem:test_query_mem");
    connection.setDBUser("sa");
    connection.setDBPassword("");
    assertTrue(connection.connect());
    initElexisDatabase(connection);

    List<Organisation> result = query.execute(connection);
    assertEquals(0, result.size());

    DBConnection initialConnection = PersistentObject.getDefaultConnection();

    // change default connection of PersistenObject and create an Organization
    PersistentObject.connect(connection);
    new Organisation("orgname2", "orgzusatz1");

    result = query.execute(connection);
    assertEquals(1, result.size());

    // cleanup new connection and reset to initial connection
    PersistentObject.disconnect();
    PersistentObject.connect(initialConnection);
  }
  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());
  }
  public void testUntyped() throws QueryException {
    // one untyped iterator is now resolved fine
    Query q = this.qs.newQuery("SELECT DISTINCT * " + "FROM /pos " + "WHERE ID = 3 ");
    q.execute();

    // if there are two untyped iterators, then it's a problem, see bug 32251 and BugTest
    q = this.qs.newQuery("SELECT DISTINCT * FROM /pos, positions WHERE ID = 3");
    try {
      q.execute();
      fail("Expected a TypeMismatchException");
    } catch (TypeMismatchException e) {
      // pass
    }
  }
 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 void conc(ExtObjectContainer oc) {
   oc.queryByExample((new QueryNonExistantTestCase(true)));
   assertOccurrences(oc, QueryNonExistantTestCase.class, 0);
   Query q = oc.query();
   q.constrain(new QueryNonExistantTestCase(true));
   Assert.areEqual(0, q.execute().size());
 }
示例#7
0
  /**
   * Runs a query and checks the updating flag.
   *
   * @throws IOException I/O exception
   */
  @Test
  public void queryUpdating() throws IOException {
    // test non-updating query
    Query query = session.query("12345678");
    assertFalse(query.updating());
    assertEqual("12345678", query.execute());
    assertFalse(query.updating());
    query.close();

    // test updating query
    query = session.query("insert node <a/> into <b/>");
    assertTrue(query.updating());
    assertEqual("", query.execute());
    assertTrue(query.updating());
    query.close();
  }
示例#8
0
 /**
  * Execute a script that is part of the call
  *
  * @param call e.g. scriptname(a="foo",b="bar")
  * @param objects some Objects to cinvert in the script
  * @return the result of the interpreter
  * @throws ElexisException if no such scruiopt was found or an error occurred
  */
 public static Object executeScript(String call, PersistentObject... objects)
     throws ElexisException {
   call = call.trim();
   String name = call;
   String params = null;
   int x = name.indexOf('(');
   if (x != -1) {
     name = call.substring(0, x);
     params = call.substring(x + 1, call.length() - 1);
   }
   Query<Script> qbe = new Query<Script>(Script.class);
   qbe.add("ID", Query.EQUALS, PREFIX + name);
   List<Script> found = qbe.execute();
   if (found.size() == 0) {
     throw new ElexisException(
         Script.class,
         "A Script with this name was not found " + name,
         ElexisException.EE_NOT_FOUND);
   }
   Script script = found.get(0);
   try {
     return script.execute(params, objects);
   } catch (Exception e) {
     ExHandler.handle(e);
     throw new ElexisException(
         Script.class,
         "Error while executing " + name + ": " + e.getMessage(),
         ElexisException.EE_UNEXPECTED_RESPONSE);
   }
 }
 @SuppressWarnings("unchecked")
 private ObjectSet executeSODAQuery(final A a, Evaluation e) {
   Query q = db().query();
   q.constrain(e);
   ObjectSet set = q.execute();
   return set;
 }
示例#10
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());
  }
 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;
 }
 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());
 }
 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();
 }
示例#14
0
 /**
  * Runs a query with an external variable declaration.
  *
  * @throws IOException I/O exception
  */
 @Test
 public void queryBindDynamic() throws IOException {
   final Query query = session.query("declare variable $a as xs:integer external; $a");
   query.bind("a", "1");
   assertEqual("1", query.execute());
   query.close();
 }
示例#15
0
 @Test
 public void testExecute() {
   Query<Organisation> query = new Query<Organisation>(Organisation.class);
   query.clear();
   query.add(Organisation.FLD_NAME1, "=", "orgname");
   List<Organisation> result = query.execute();
   assertEquals(1, result.size());
 }
示例#16
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 concRead(ExtObjectContainer oc) {
   for (int i = 0; i < COUNT; i++) {
     Query q = oc.query();
     q.constrain(Atom.class);
     q.descend("name").constrain("ibi" + i);
     ObjectSet objectSet = q.execute();
     Assert.areEqual(1, objectSet.size());
     Atom child = (Atom) objectSet.next();
     q = oc.query();
     q.constrain(IndexedByIdentityTestCase.class);
     q.descend("atom").constrain(child).identity();
     objectSet = q.execute();
     Assert.areEqual(1, objectSet.size());
     IndexedByIdentityTestCase ibi = (IndexedByIdentityTestCase) objectSet.next();
     Assert.areSame(child, ibi.atom);
   }
 }
 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());
 }
 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);
 }
示例#20
0
 /**
  * Runs a query and checks the serialization parameters.
  *
  * @throws IOException I/O exception
  */
 @Test
 public void queryOptions() throws IOException {
   final Query query = session.query("declare option output:encoding 'US-ASCII';()");
   query.execute();
   final SerializerOptions sp = new SerializerOptions();
   sp.parse(query.options());
   assertEquals("US-ASCII", sp.get(SerializerOptions.ENCODING));
   query.close();
 }
 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);
 }
 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);
   }
 }
  public void testTyped() throws QueryException {
    Query q =
        this.qs.newQuery( // must quote "query" because it is a reserved word
            "IMPORT com.gemstone.gemfire.cache.\"query\".data.Portfolio;\n"
                + "SELECT DISTINCT *\n"
                + "FROM /pos TYPE Portfolio\n"
                + "WHERE ID = 3  ");
    Object r = q.execute();
    CacheUtils.getLogger().fine(Utils.printResult(r));

    q =
        this.qs.newQuery( // must quote "query" because it is a reserved word
            "IMPORT com.gemstone.gemfire.cache.\"query\".data.Portfolio;\n"
                + "SELECT DISTINCT *\n"
                + "FROM /pos ptfo TYPE Portfolio\n"
                + "WHERE ID = 3  ");
    r = q.execute();
    CacheUtils.getLogger().fine(Utils.printResult(r));
  }
示例#24
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]);
 }
示例#25
0
 /**
  * Runs a query with an external variable declaration.
  *
  * @throws IOException I/O exception
  */
 @Test
 public void queryBind() throws IOException {
   final Query query = session.query("declare variable $a external; $a");
   query.bind("$a", "4");
   assertEqual("4", query.execute());
   query.bind("$a", "5");
   assertEqual("5", query.next());
   query.bind("$a", "6");
   assertEqual("6", query.next());
   query.close();
 }
示例#26
0
 @Test
 public void testQueryExpression() {
   PreparedStatement ps =
       link.prepareStatement(
           "SELECT " + Organisation.FLD_NAME1 + " FROM " + Organisation.TABLENAME);
   Query<Organisation> query = new Query<Organisation>(Organisation.class);
   ArrayList<String> result = query.execute(ps, new String[0]);
   int nrOrgs = result.size();
   System.out.println("Before creating new organistaion found " + nrOrgs + " Organisation");
   for (String s : result) {
     System.out.println("Organisation: found " + s);
   }
   new Organisation("NeueOrganistation", "Zusatznamen2");
   result = query.execute(ps, new String[0]);
   System.out.println("After creating new organistaion found " + result.size() + " Organisation");
   for (String s : result) {
     System.out.println("Organisation: found " + s);
   }
   assertEquals(nrOrgs + 1, result.size());
 }
 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);
 }
示例#28
0
 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);
 }
示例#29
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]});
 }
示例#30
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);
 }