Query Parameters
Typed Query Parameters

RQL provides comprehensive type-safe support for setting query parameter values at runtime.

  • Methods for setting a single value using a parameter.
  • Methods to set a list of values using a parameter.
  • Value ranges are supported by a specific type-generic interface (IGenValue) designed to be used in value lists.
  • Conditions within a single query can include multiple parameters.
  • Parameters are denoted by Pn, where n is an integer.

Methods for Setting Type-Safe Query Parameters

public Query setString(int pn, String value)
public Query setInteger(int pn, int value)
public Query setLong(int pn, long value)
public Query setDouble(int pn, double value)
public Query setBoolean(int pn, boolean value)
public Query setDate(int pn, Date value)
public Query setEmpty(int pn)
public Query setNull(int pn)
public Query setStringList(int pn, List<String> valueList)
public Query setIntegerList(int pn, List<IGenValue<Integer>> valueList)
public Query setLongList(int pn, List<IGenValue<Long>> valueList)
public Query setDoubleList(int pn, List<IGenValue<Double>> valueList)
public Query setDateList(int pn, List<IGenValue<Date>> valueList)
public Query setObjectList(int pn, List objectList)

Examples

Object Model

public class Person {
    public Long id;
    public String name;
    public String address1;
    public String address2;
    public String hobby;
    public Integer age;
    public Integer number;
    public Boolean bool;
    public Date birthDate;
    public Organization organization;
    public List<Person> friends;
    public List<Car> cars;

    public Person() {
    }
}

Note that in all the examples below, the first parameter is an integer representing the number n in the parameter Pn.

setString

RootStore r1 = rdb.getRootStore("fi.rootrql.example1.Person");
Query query =  Query.createQuery()
					//.addQ1Query(r1, "(name = 'boss2')")
					.addQ1Query(r1, "(name = P1)");
query.setString(1, "boss2");
List<Person> list = query.queryQ1Objects();

setInteger

RootStore r1 = rdb.getRootStore("fi.rootrql.example1.Person");
Query query =  Query.createQuery()
					//.addQ1Query(r1, "(age = 42)")
					.addQ1Query(r1, "(age = P1)");
query.setInteger(1, 42);
List<Person> list = query.queryQ1Objects();

setLong

RootStore r1 = rdb.getRootStore("fi.rootrql.example1.Person");
Query query =  Query.createQuery()
					//.addQ1Query(r1, "(id = 10L)");
					.addQ1Query(r1, "(id = P1)");
query.setLong(1, 10L);
List<Person> list = query.queryQ1Objects();

setDouble

RootStore r1 = rdb.getRootStore("fi.rootrql.example1.Person");
Query query =  Query.createQuery()
					//.addQ1Query(r1, "(cars.power = 460.0)");
					.addQ1Query(r1, "(cars.power = P1)");
query.setDouble(1, 460.0);
List<Person> list = query.queryQ1Objects();

setBoolean

RootStore r1 = rdb.getRootStore("fi.rootrql.example1.Person");
Query query =  Query.createQuery()
					//.addQ1Query(r1, "(bool = true)");
					.addQ1Query(r1, "(bool = P1)");
query.setBoolean(1, true);
List<Person> list = query.queryQ1Objects();

setDate

RootStore r1 = rdb.getRootStore("fi.rootrql.example1.Person");
Query query =  Query.createQuery()
					//.addQ1Query(r1, "(birthDate = 1991-04-19)");
					.addQ1Query(r1, "(birthDate = P1)");
query.setDate(1, Date.valueOf("1991-04-19"));
List<Person> list = query.queryQ1Objects();

Empty means that the list exists, but it contains no elements.

setEmpty

RootStore r1 = rdb.getRootStore("fi.rootrql.example1.Person");
Query query =  Query.createQuery()
					//.addQ1Query(r1, "(cars = EMPTY)");
					.addQ1Query(r1, "(cars = P1)");
query.setEmpty(1);
List<Person> list = query.queryQ1Objects();

Null means that the reference value is null, whether it points to a list or a single object.

setNull

RootStore r1 = rdb.getRootStore("fi.rootrql.example1.Person");
Query query =  Query.createQuery()
					//.addQ1Query(r1, "(cars = null)");
					.addQ1Query(r1, "(cars = P1)");
query.setNull(1);
List<Person> list = query.queryQ1Objects();

The generic IGenValue interface is designed for lists, providing the ability to use both single values and ranges of values as list items.

setStringList

RootStore r1 = rdb.getRootStore("fi.rootrql.example1.Person");
Query query =  Query.createQuery()
				//.addQ1Query(r1, "(name IN ('boss1','boss2','boss3'))");
					.addQ1Query(r1, "(name IN (P1))");
List<String> valueList = new ArrayList<>();
valueList.add("boss1");
valueList.add("boss2");
valueList.add("boss3");
query.setStringList(1, valueList);
List<Person> list = query.queryQ1Objects();

An interval can have either an inclusive or exclusive qualifier for its start and end values, similar to the concepts of inclusivity and exclusivity in mathematics.

setIntegerList

RootStore r1 = rdb.getRootStore("fi.rootrql.example1.Person");
Query query =  Query.createQuery()
				//.addQ1Query(r1, "(age IN (42, [19,28), 53, [70,100)))");
					.addQ1Query(r1, "(age IN (P1))");
List<IGenValue<Integer>> valueList = new ArrayList<IGenValue<Integer>>();
valueList.add(new IntegerValue(42));
valueList.add(new IntegerRange(19, Query.RANGE_INCLUSIVE, 28, Query.RANGE_EXCLUSIVE));
valueList.add(new IntegerValue(53));
valueList.add(new IntegerRange(70, Query.RANGE_INCLUSIVE, 100, Query.RANGE_EXCLUSIVE));
query.setIntegerList(1, valueList);
List<Person> list = query.queryQ1Objects();

setLongList

RootStore r1 = rdb.getRootStore("fi.rootrql.example1.Person");
Query query =  Query.createQuery()
				//.addQ1Query(r1, "(id IN (2, [8,10], 20))");
					.addQ1Query(r1, "(id IN (P1))");
List<IGenValue<Long>> valueList = new ArrayList<IGenValue<Long>>();
valueList.add(new LongValue(2L));
valueList.add(new LongRange(8L, Query.RANGE_INCLUSIVE, 10L, Query.RANGE_INCLUSIVE));
valueList.add(new LongValue(20L));
query.setLongList(1, valueList);
List<Person> list = query.queryQ1Objects();

setDoubleList

RootStore r1 = rdb.getRootStore("fi.rootrql.example1.Person");
Query query =  Query.createQuery()
		//.addQ1Query(r1, "(cars.power IN (100.0, [200.0,500.0), 750.0))");
					.addQ1Query(r1, "(cars.power IN (P1))");
List<IGenValue<Double>> valueList = new ArrayList<IGenValue<Double>>();
valueList.add(new DoubleValue(100.0));
valueList.add(new DoubleRange(200.0, Query.RANGE_INCLUSIVE, 500.0, Query.RANGE_EXCLUSIVE));
valueList.add(new DoubleValue(750.0));
query.setDoubleList(1, valueList);
List<Person> list = query.queryQ1Objects();

Note that date intervals, or ranges of dates, are also supported by the generic IGenValue interface.

setDateList

RootStore r1 = rdb.getRootStore("fi.rootrql.example1.Person");
Query query =  Query.createQuery()
//.addQ1Query(r1, "(birthDate IN (1971-09-21, 1981-03-10,
//                                [2004-04-24, 2008-08-12)))");
					.addQ1Query(r1, "(birthDate IN (P1))");
List<IGenValue<Date>> valueList = new ArrayList<IGenValue<Date>>();
valueList.add(new DateValue(Date.valueOf("1971-09-21")));
valueList.add(new DateValue(Date.valueOf("1981-03-10")));
valueList.add(new DateRange( Date.valueOf("2004-04-24"), Query.RANGE_INCLUSIVE, Date.valueOf("2008-08-12"), Query.RANGE_EXCLUSIVE));
query.setDateList(1, valueList);
List<Person> list = query.queryQ1Objects();

setObjectList

RootStore r1 = rdb.getRootStore("fi.rootrql.example1.Person");
Query query =  Query.createQuery()
.addQ1Query(r1, "(hobby = 'golf')");
List<Person> list = query.queryQ1Objects(); query = Query.createQuery()
.addQ1Query(r1, "(friends IN (P1))");
query.setObjectList(1, list);
list = query.queryQ1Objects();

Object lists as parameters may be needed, for example, when the results of a query (or multiple queries) are used in another query condition.

Multipele parameters

RootStore r1 = rdb.getRootStore("fi.rootrql.example1.Person");
Query query =  Query.createQuery()
					.addQ1Query(r1, "(hobby = 'golf')");
List<Person> list = query.queryQ1Objects();
query = Query.createQuery()
.addQ1Query(r1, "(birthDate IN (P1), friends IN (P2), cars.power IN (P3))");
List<IGenValue<Date>> valueList = new ArrayList<IGenValue<Date>>(); valueList.add(new DateValue(Date.valueOf("1971-09-21"))); valueList.add(new DateValue(Date.valueOf("1981-03-10"))); valueList.add(new DateRange( Date.valueOf("2004-04-24"), Query.RANGE_INCLUSIVE, Date.valueOf("2008-08-12"), Query.RANGE_EXCLUSIVE));
query.setDateList(1, valueList);
//Set Person objects from the search result Q1 to the value of parameter P2.
query.setObjectList(2, list);
List<IGenValue<Double>> valueList2 = new ArrayList<IGenValue<Double>>(); valueList2.add(new DoubleValue(100.0)); valueList2.add(new DoubleRange( 200.0, Query.RANGE_INCLUSIVE, 500.0, Query.RANGE_EXCLUSIVE)); valueList2.add(new DoubleValue(750.0));
query.setDoubleList(3, valueList2);
list = query.queryQ1Objects();

The object oriented RQL query language, with support for multiple parameters and value lists, including single value items and ranges, offers excellent flexibility for programming advanced query conditions.

Links to other pages on this site.


Page content © 2024 

company name

Contact us:

mail address