Search in sources :

Example 1 with QueryCompiler

use of com.bluenimble.platform.db.query.QueryCompiler in project serverless by bluenimble.

the class TestWithBindingsQueryCompiler method main.

public static void main(String[] args) throws Exception {
    Map<String, Object> bindings = new HashMap<String, Object>();
    bindings.put("alpha", "alpha-val");
    bindings.put("beta", new Date());
    Query query = new JsonQuery(Json.load(new File("tests/queries/with-bindings.json")), bindings);
    System.out.println("Select==>");
    QueryCompiler sc = new SqlQueryCompiler(Query.Construct.select);
    CompiledQuery cq = sc.compile(query);
    System.out.println("   query: " + cq.query());
    System.out.println();
    System.out.println("bindings: " + cq.bindings());
    System.out.println("Delete==>");
    QueryCompiler dc = new SqlQueryCompiler(Query.Construct.delete);
    cq = dc.compile(query);
    System.out.println("   query: " + cq.query());
    System.out.println();
    System.out.println("bindings: " + cq.bindings());
}
Also used : CompiledQuery(com.bluenimble.platform.db.query.CompiledQuery) Query(com.bluenimble.platform.db.query.Query) JsonQuery(com.bluenimble.platform.db.query.impls.JsonQuery) JsonQuery(com.bluenimble.platform.db.query.impls.JsonQuery) HashMap(java.util.HashMap) SqlQueryCompiler(com.bluenimble.platform.db.query.impls.SqlQueryCompiler) SqlQueryCompiler(com.bluenimble.platform.db.query.impls.SqlQueryCompiler) QueryCompiler(com.bluenimble.platform.db.query.QueryCompiler) File(java.io.File) Date(java.util.Date) CompiledQuery(com.bluenimble.platform.db.query.CompiledQuery)

Example 2 with QueryCompiler

use of com.bluenimble.platform.db.query.QueryCompiler in project serverless by bluenimble.

the class TestQueryCompilerWithOperators method main.

public static void main(String[] args) throws Exception {
    Query query = new JsonQuery(Json.load(new File("tests/queries/with-operators.json")));
    System.out.println("Select==>");
    QueryCompiler sc = new SqlQueryCompiler(Query.Construct.select);
    CompiledQuery cq = sc.compile(query);
    System.out.println("   query: " + cq.query());
    System.out.println();
    System.out.println("bindings: " + cq.bindings());
    System.out.println("Delete==>");
    QueryCompiler dc = new SqlQueryCompiler(Query.Construct.delete);
    cq = dc.compile(query);
    System.out.println("   query: " + cq.query());
    System.out.println();
    System.out.println("bindings: " + cq.bindings());
}
Also used : CompiledQuery(com.bluenimble.platform.db.query.CompiledQuery) Query(com.bluenimble.platform.db.query.Query) JsonQuery(com.bluenimble.platform.db.query.impls.JsonQuery) JsonQuery(com.bluenimble.platform.db.query.impls.JsonQuery) SqlQueryCompiler(com.bluenimble.platform.db.query.impls.SqlQueryCompiler) SqlQueryCompiler(com.bluenimble.platform.db.query.impls.SqlQueryCompiler) QueryCompiler(com.bluenimble.platform.db.query.QueryCompiler) File(java.io.File) CompiledQuery(com.bluenimble.platform.db.query.CompiledQuery)

Example 3 with QueryCompiler

use of com.bluenimble.platform.db.query.QueryCompiler in project serverless by bluenimble.

the class OrientDatabase method compile.

private CompiledQuery compile(String entity, Query.Construct construct, final Query query, final boolean returnBefore) throws DatabaseException {
    final String fEntity = entity;
    QueryCompiler compiler = new SqlQueryCompiler(construct) {

        private static final long serialVersionUID = -1248971549807669897L;

        @Override
        protected void onQuery(Timing timing, Query query) throws DatabaseException {
            super.onQuery(timing, query);
            if (Timing.start.equals(timing)) {
                return;
            }
            if (query.start() > 0) {
                buff.append(Lang.SPACE).append(Sql.Skip).append(Lang.SPACE).append(query.start());
            }
            if (query.count() > 0) {
                buff.append(Lang.SPACE).append(Sql.Limit).append(Lang.SPACE).append(query.count());
            }
        }

        @Override
        protected void onSelect(Timing timing, Select select) throws DatabaseException {
            super.onSelect(timing, select);
            if (Timing.end.equals(timing) && returnBefore) {
                buff.append(Lang.SPACE).append(Sql.ReturnBefore);
            }
        }

        @Override
        protected String operatorFor(Operator operator) {
            if (Operator.ftq.equals(operator)) {
                return Lucene;
            } else if (Operator.regex.equals(operator)) {
                return Maches;
            }
            return super.operatorFor(operator);
        }

        @Override
        protected void entity() {
            buff.append(fEntity);
        }
    };
    return compiler.compile(query);
}
Also used : Operator(com.bluenimble.platform.db.query.Query.Operator) Query(com.bluenimble.platform.db.query.Query) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) CompiledQuery(com.bluenimble.platform.db.query.CompiledQuery) SqlQueryCompiler(com.bluenimble.platform.db.query.impls.SqlQueryCompiler) Select(com.bluenimble.platform.db.query.Select) SqlQueryCompiler(com.bluenimble.platform.db.query.impls.SqlQueryCompiler) QueryCompiler(com.bluenimble.platform.db.query.QueryCompiler)

Example 4 with QueryCompiler

use of com.bluenimble.platform.db.query.QueryCompiler in project serverless by bluenimble.

the class TestStartPageQueryCompiler method main.

public static void main(String[] args) throws Exception {
    Query query = new JsonQuery(Json.load(new File("tests/queries/complete.json")));
    System.out.println("Select==>");
    QueryCompiler sc = new SqlQueryCompiler(Query.Construct.select) {

        private static final long serialVersionUID = -1248971549807669897L;

        @Override
        protected void onQuery(Timing timing, Query query) throws DatabaseException {
            super.onQuery(timing, query);
            if (Timing.start.equals(timing)) {
                return;
            }
            if (query.start() > 0) {
                buff.append(Lang.SPACE).append("skip").append(Lang.SPACE).append(query.start());
            }
            if (query.count() > 0) {
                buff.append(Lang.SPACE).append("limit").append(Lang.SPACE).append(query.count());
            }
        }
    };
    CompiledQuery cq = sc.compile(query);
    System.out.println("   query: " + cq.query());
    System.out.println();
    System.out.println("bindings: " + cq.bindings());
    System.out.println("Delete==>");
    QueryCompiler dc = new SqlQueryCompiler(Query.Construct.delete);
    cq = dc.compile(query);
    System.out.println("   query: " + cq.query());
    System.out.println();
    System.out.println("bindings: " + cq.bindings());
}
Also used : CompiledQuery(com.bluenimble.platform.db.query.CompiledQuery) Query(com.bluenimble.platform.db.query.Query) JsonQuery(com.bluenimble.platform.db.query.impls.JsonQuery) JsonQuery(com.bluenimble.platform.db.query.impls.JsonQuery) SqlQueryCompiler(com.bluenimble.platform.db.query.impls.SqlQueryCompiler) SqlQueryCompiler(com.bluenimble.platform.db.query.impls.SqlQueryCompiler) QueryCompiler(com.bluenimble.platform.db.query.QueryCompiler) File(java.io.File) CompiledQuery(com.bluenimble.platform.db.query.CompiledQuery)

Example 5 with QueryCompiler

use of com.bluenimble.platform.db.query.QueryCompiler in project serverless by bluenimble.

the class TestQueryCompiler method main.

public static void main(String[] args) throws Exception {
    Query query = new JsonQuery(Json.load(new File("tests/queries/simple.json")));
    System.out.println("Select==>");
    QueryCompiler sc = new SqlQueryCompiler(Query.Construct.select);
    CompiledQuery cq = sc.compile(query);
    System.out.println("   query: " + cq.query());
    System.out.println();
    System.out.println("bindings: " + cq.bindings());
    System.out.println("Delete==>");
    QueryCompiler dc = new SqlQueryCompiler(Query.Construct.delete);
    cq = dc.compile(query);
    System.out.println("   query: " + cq.query());
    System.out.println();
    System.out.println("bindings: " + cq.bindings());
}
Also used : CompiledQuery(com.bluenimble.platform.db.query.CompiledQuery) Query(com.bluenimble.platform.db.query.Query) JsonQuery(com.bluenimble.platform.db.query.impls.JsonQuery) JsonQuery(com.bluenimble.platform.db.query.impls.JsonQuery) SqlQueryCompiler(com.bluenimble.platform.db.query.impls.SqlQueryCompiler) SqlQueryCompiler(com.bluenimble.platform.db.query.impls.SqlQueryCompiler) QueryCompiler(com.bluenimble.platform.db.query.QueryCompiler) File(java.io.File) CompiledQuery(com.bluenimble.platform.db.query.CompiledQuery)

Aggregations

CompiledQuery (com.bluenimble.platform.db.query.CompiledQuery)5 Query (com.bluenimble.platform.db.query.Query)5 QueryCompiler (com.bluenimble.platform.db.query.QueryCompiler)5 SqlQueryCompiler (com.bluenimble.platform.db.query.impls.SqlQueryCompiler)5 JsonQuery (com.bluenimble.platform.db.query.impls.JsonQuery)4 File (java.io.File)4 Operator (com.bluenimble.platform.db.query.Query.Operator)1 Select (com.bluenimble.platform.db.query.Select)1 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1