Search in sources :

Example 56 with Query

use of org.skife.jdbi.v2.Query in project packages-jpl by SWI-Prolog.

the class AddWithThreads method testThreadedAdds.

public void testThreadedAdds() {
    latch = new CountDownLatch(4);
    final AddWithThreads[] addTasks = { new AddWithThreads("a", latch), new AddWithThreads("b", latch), new AddWithThreads("c", latch), new AddWithThreads("d", latch) };
    // System.out.println("Starting threads...");
    for (int i = 0; i < addTasks.length; i++) {
        addTasks[i].start();
    }
    try {
        // System.out.println("Latch is waiting");
        assertTrue("Timed out waiting for action to execute", latch.await(20, TimeUnit.SECONDS));
    // System.out.println("Latch has been flipped");
    } catch (final InterruptedException e) {
        fail("Waiting thread was interrupted: " + e);
    }
    for (int i = 0; i < AddWithThreads.REPS; i++) {
        for (int j = 0; j < addTasks.length; j++) {
            Query query = new Query(addTasks[j].getNamespace() + "(test('" + i + "'))");
            // System.out.println("query: " + query);
            // boolean ret = query.hasMoreElements();
            query.close();
        }
    }
}
Also used : Query(org.jpl7.Query) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 57 with Query

use of org.skife.jdbi.v2.Query in project packages-jpl by SWI-Prolog.

the class Family method run.

public void run() {
    Map<String, Term> solution;
    Variable X = new Variable("X");
    // --------------------------------------------------
    Query q2 = new Query("child_of", new Term[] { new Atom("joe"), new Atom("ralf") });
    System.err.println("child_of(joe,ralf) is " + (q2.hasSolution() ? "provable" : "not provable"));
    new Query("sleep", new Term[] { new org.jpl7.Integer(delay) }).hasSolution();
    // --------------------------------------------------
    Query q3 = new Query("descendent_of", new Term[] { new Atom("steve"), new Atom("ralf") });
    System.err.println("descendent_of(steve,ralf) is " + (q3.hasSolution() ? "provable" : "not provable"));
    new Query("sleep", new Term[] { new org.jpl7.Integer(delay) }).hasSolution();
    // --------------------------------------------------
    Query q4 = new Query("descendent_of", new Term[] { X, new Atom("ralf") });
    solution = q4.oneSolution();
    System.err.println("first solution of descendent_of(X, ralf)");
    System.err.println("X = " + solution.get(X.name));
    new Query("sleep", new Term[] { new org.jpl7.Integer(delay) }).hasSolution();
    // --------------------------------------------------
    Map<String, Term>[] solutions = q4.allSolutions();
    System.err.println("all solutions of descendent_of(X, ralf)");
    for (int i = 0; i < solutions.length; i++) {
        System.err.println("X = " + solutions[i].get(X.name));
    }
    new Query("sleep", new Term[] { new org.jpl7.Integer(delay) }).hasSolution();
    // --------------------------------------------------
    System.err.println("each solution of descendent_of(X, ralf)");
    while (q4.hasMoreSolutions()) {
        solution = q4.nextSolution();
        System.err.println("X = " + solution.get(X.name));
    }
    new Query("sleep", new Term[] { new org.jpl7.Integer(delay) }).hasSolution();
    // --------------------------------------------------
    Variable Y = new Variable("Y");
    Query q5 = new Query("descendent_of", new Term[] { X, Y });
    System.err.println(id + ": each solution of descendent_of(X, Y)");
    while (q5.hasMoreSolutions()) {
        solution = q5.nextSolution();
        System.err.println(id + ": X = " + solution.get(X.name) + ", Y = " + solution.get(Y.name));
        new Query("sleep", new Term[] { new org.jpl7.Integer(delay) }).hasSolution();
    }
}
Also used : Variable(org.jpl7.Variable) Query(org.jpl7.Query) Term(org.jpl7.Term) Map(java.util.Map) Atom(org.jpl7.Atom)

Example 58 with Query

use of org.skife.jdbi.v2.Query in project packages-jpl by SWI-Prolog.

the class TestJUnit method testGetSolution1.

public void testGetSolution1() {
    Query q = new Query("fail");
    q.open();
    q.getSolution();
    assertTrue("an opened query on which getSolution has failed once is closed", !q.isOpen());
}
Also used : Query(org.jpl7.Query)

Example 59 with Query

use of org.skife.jdbi.v2.Query in project packages-jpl by SWI-Prolog.

the class TestJUnit method testDontTellMeMode1.

public void testDontTellMeMode1() {
    final Query q = new Query("setof(_M,current_module(_M),_Ms),length(_Ms,N)");
    JPL.setDTMMode(true);
    assertTrue("in dont-tell-me mode, setof(_M,current_module(_M),_Ms),length(_Ms,N) returns binding for just one variable", q.oneSolution().keySet().size() == 1);
}
Also used : Query(org.jpl7.Query)

Example 60 with Query

use of org.skife.jdbi.v2.Query in project packages-jpl by SWI-Prolog.

the class TestJUnit method testJRef2.

public void testJRef2() {
    int i = 76543;
    Integer I = new Integer(i);
    Query q = new Query("jpl_call(?,intValue,[],I2)", JPL.newJRef(I));
    Term I2 = q.oneSolution().get("I2");
    assertTrue(I2.isInteger() && I2.intValue() == i);
}
Also used : Integer(org.jpl7.Integer) BigInteger(java.math.BigInteger) Query(org.jpl7.Query) Term(org.jpl7.Term)

Aggregations

Query (org.jpl7.Query)56 Term (org.jpl7.Term)33 Variable (org.jpl7.Variable)23 Map (java.util.Map)18 Atom (org.jpl7.Atom)16 Compound (org.jpl7.Compound)16 Query (com.google.datastore.v1.Query)12 Handle (org.skife.jdbi.v2.Handle)12 Test (org.junit.Test)10 GqlQuery (com.google.datastore.v1.GqlQuery)7 Integer (org.jpl7.Integer)6 SQLException (java.sql.SQLException)5 ArrayList (java.util.ArrayList)5 Datastore (com.google.datastore.v1.client.Datastore)4 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 List (java.util.List)4 SplitQueryFn (org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.Read.SplitQueryFn)4 RunQueryRequest (com.google.datastore.v1.RunQueryRequest)3 Nullable (javax.annotation.Nullable)3