Search in sources :

Example 56 with SqlQuery

use of org.apache.ignite.cache.query.SqlQuery in project ignite by apache.

the class IgniteSqlQueryPutBenchmark method executeQuery.

/**
     * @param minSalary Min salary.
     * @param maxSalary Max salary.
     * @return Query result.
     * @throws Exception If failed.
     */
private Collection<Cache.Entry<Integer, Object>> executeQuery(double minSalary, double maxSalary) throws Exception {
    SqlQuery qry = new SqlQuery(Person.class, "salary >= ? and salary <= ?");
    qry.setArgs(minSalary, maxSalary);
    return cache.query(qry).getAll();
}
Also used : SqlQuery(org.apache.ignite.cache.query.SqlQuery)

Example 57 with SqlQuery

use of org.apache.ignite.cache.query.SqlQuery in project ignite by apache.

the class IgniteRepositoryQuery method prepareQuery.

/**
     * @param prmtrs Prmtrs.
     * @return prepared query for execution
     */
@NotNull
private Query prepareQuery(Object[] prmtrs) {
    Object[] parameters = prmtrs;
    String sql = qry.sql();
    Query query;
    switch(qry.options()) {
        case SORTING:
            sql = IgniteQueryGenerator.addSorting(new StringBuilder(sql), (Sort) parameters[parameters.length - 1]).toString();
            parameters = Arrays.copyOfRange(parameters, 0, parameters.length - 1);
            break;
        case PAGINATION:
            sql = IgniteQueryGenerator.addPaging(new StringBuilder(sql), (Pageable) parameters[parameters.length - 1]).toString();
            parameters = Arrays.copyOfRange(parameters, 0, parameters.length - 1);
            break;
    }
    if (qry.isFieldQuery()) {
        SqlFieldsQuery sqlFieldsQry = new SqlFieldsQuery(sql);
        sqlFieldsQry.setArgs(parameters);
        query = sqlFieldsQry;
    } else {
        SqlQuery sqlQry = new SqlQuery(type, sql);
        sqlQry.setArgs(parameters);
        query = sqlQry;
    }
    return query;
}
Also used : SqlQuery(org.apache.ignite.cache.query.SqlQuery) Query(org.apache.ignite.cache.query.Query) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) SqlQuery(org.apache.ignite.cache.query.SqlQuery) RepositoryQuery(org.springframework.data.repository.query.RepositoryQuery) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

SqlQuery (org.apache.ignite.cache.query.SqlQuery)57 Cache (javax.cache.Cache)20 IgniteCache (org.apache.ignite.IgniteCache)20 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)18 Ignite (org.apache.ignite.Ignite)17 List (java.util.List)13 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)13 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)10 CAX (org.apache.ignite.internal.util.typedef.CAX)9 ArrayList (java.util.ArrayList)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 BinaryObject (org.apache.ignite.binary.BinaryObject)7 CacheException (javax.cache.CacheException)6 Collection (java.util.Collection)4 Random (java.util.Random)4 QueryCursor (org.apache.ignite.cache.query.QueryCursor)4 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)4 IOException (java.io.IOException)3 HashSet (java.util.HashSet)3 UUID (java.util.UUID)3