public interface PojoQueryBuilder<T>
the pojo facade is to simplify working with
custom pojos. PojoQueryBuilder keeps all the powerful queries available via
StructuredQueryBuilder while enabling queries across objects persisted using
PojoRepository.
For methods which accept a "pojoProperty" argument we are refering to properties appropriate for JavaBeans, including properties accessible via public getters and setters, or public fields.
Where StructuredQueryBuilder accepts StructuredQueryBuilder.TextIndex as a first argument
to
value(TextIndex, String...)
and
word(TextIndex, String...)
methods,
PojoQueryBuilder adds shortcut methods which accept as the first argument a String name of the
pojoProperty. Similarly, PojoQueryBuilder accepts String pojoProperty arguments wherever
StructuredQueryBuilder accepts StructuredQueryBuilder.Element,
StructuredQueryBuilder.Attribute, and StructuredQueryBuilder.PathIndex
as arguments to
geoAttributePair(Element, Attribute, Attribute),
geoElement(Element),
geoElement(Element, Element),
geoElementPair(Element, Element, Element),
geoPath(PathIndex)
Here are a couple examples. Without the pojo facade you might persist your products using
JacksonDatabindHandle and query the
json property thusly:
StructuredQueryBuilder sqb = new StructuredQueryBuilder();
QueryDefinition query = sqb.value(sqb.jsonProperty("productId"), 12345);
If you use PojoRepository to persist your products, you can query more simply:
PojoQueryBuilder pqb = pojoRepository.getQueryBuilder();
QueryDefinition query = pqb.value("productId", 12345);
Similarly, without the pojo facade you might persist your pojos using
JAXBHandle and if they
have a geoPosition property which is an object with latitude and longitude pojoProperty's
(which persist as elements) you might query them thusly:
StructuredQueryBuilder sqb = new StructuredQueryBuilder();
StructuredQueryBuilder.GeospatialIndex geoIdx = sqb.geoElementPair(
sqb.element("geoPosition"), sqb.element("latitude"), sqb.element("longitude"));
But if you use PojoRepository to persist your pojos with a latitude and longitude
pojoProperty's, you can query them more simply:
PojoQueryBuilder pqb = pojoRepository.getQueryBuilder();
StructuredQueryBuilder.GeospatialIndex geoIdx =
pqb.geoPair("latitude", "longitude");
As custom pojos may have nested pojos, PojoQueryBuilder also makes it easy to query those nested pojos. For example, if you had the following classes:
class City {
@Id int id;
Country country;
int getId();
void setId(int id);
Country getCountry();
void setCountry(Country country);
}
class Country {
String continent;
String getContinent();
void setContinent();
}
That is, you have a pojo class City with a property "country" of type Country, you could query properties on the nested country thusly:
PojoRepository<City, Integer> cities =
databaseClient.newPojoRepository(City.class, Integer.class);
PojoQueryBuilder citiesQb = cities.getQueryBuilder();
PojoQueryBuilder countriesQb = citiesQb.containerQueryBuilder("country");
QueryDefinition query = countriesQb.value("continent", "EU"); | Modifier and Type | Interface and Description |
|---|---|
static class |
PojoQueryBuilder.Operator
Copied directly from
StructuredQueryBuilder.Operator |
StructuredQueryDefinition containerQuery(String pojoProperty, StructuredQueryDefinition query)
<C> PojoQueryBuilder<C> containerQueryBuilder(String pojoProperty, Class<C> clazz)
pojoProperty - the name of a field or JavaBean property (accessed via getter or setter) on class T
that is a pojo of type clazzclazz - the class type of the nested pojoStructuredQueryBuilder.GeospatialIndex geoPair(String latitudePropertyName, String longitudePropertyName)
geospatial query, reference a pair of properties. These properties
should ideally have Geospatial Element Pair Indexes configured in the database. For help
creating these indexes, see GenerateIndexConfig, GeospatialLatitude, and
GeospatialLongitude.latitudePropertyName - the name of a field or JavaBean property (accessed via getter or setter)
ideally annotated with @GeospatialLatitudelongitudePropertyName - the name of a field or JavaBean property (accessed via getter or setter)
ideally annotated with @GeospatialLongitudeStructuredQueryBuilder.GeospatialIndex geoPath(String pojoProperty)
geospatial query, reference a geo property which has
a corresponding Geospatial Path Range Index configured in the database. For help
creating this index, see GenerateIndexConfig and GeospatialPathIndexProperty.pojoProperty - the name of a field or JavaBean property (accessed via getter or setter) on class T
ideally annotated with @GeospatialPathIndexPropertyStructuredQueryDefinition range(String pojoProperty, PojoQueryBuilder.Operator operator, Object... values)
datatype configured. For help
creating this index, see GenerateIndexConfig and PathIndexProperty.pojoProperty - the name of a field or JavaBean property (accessed via getter or setter) on class T
annotated with @PathIndexPropertyoperator - the operator used to compare property values with passed valuesvalues - the possible datatyped values for the comparison. Make sure the datatypes
match the datatype configured.StructuredQueryDefinition range(String pojoProperty, String[] options, PojoQueryBuilder.Operator operator, Object... values)
datatype configured. For help
creating this index, see GenerateIndexConfig and PathIndexProperty.pojoProperty - the name of a field or JavaBean property (accessed via getter or setter) on class T
annotated with @PathIndexPropertyoptions - options for fine tuning the queryoperator - the operator used to compare property values with passed valuesvalues - the possible datatyped values for the comparison. Make sure the datatypes
match the datatype configured.StructuredQueryDefinition value(String pojoProperty, String... values)
pojoProperty - the name of a field or JavaBean property (accessed via getter or setter) on class Tvalues - match a persisted pojo of type T if it has the property with any of the valuesStructuredQueryDefinition value(String pojoProperty, Boolean value)
pojoProperty - the name of a field or JavaBean property (accessed via getter or setter) on class Tvalue - match a persisted pojo of type T if it has the property with the boolean valueStructuredQueryDefinition value(String pojoProperty, Number... values)
pojoProperty - the name of a field or JavaBean property (accessed via getter or setter) on class Tvalues - match a persisted pojo of type T if it has the property with any of the numeric valuesStructuredQueryDefinition value(String pojoProperty, String[] options, double weight, String... values)
pojoProperty - the name of a field or JavaBean property (accessed via getter or setter) on class Toptions - options for fine tuning the queryweight - the multiplier for the match in the document rankingvalues - match a persisted pojo of type T if it has the property with any of the valuesStructuredQueryDefinition value(String pojoProperty, String[] options, double weight, Boolean value)
pojoProperty - the name of a field or JavaBean property (accessed via getter or setter) on class Toptions - options for fine tuning the queryweight - the multiplier for the match in the document rankingvalue - match a persisted pojo of type T if it has the property with the boolean valueStructuredQueryDefinition value(String pojoProperty, String[] options, double weight, Number... values)
pojoProperty - the name of a field or JavaBean property (accessed via getter or setter) on class Toptions - options for fine tuning the queryweight - the multiplier for the match in the document rankingvalues - match a persisted pojo of type T if it has the property with any of the numeric valuesStructuredQueryDefinition word(String pojoProperty, String... words)
pojoProperty - the name of a field or JavaBean property (accessed via getter or setter) on class Twords - match a persisted pojo of type T if it has the property with any of the words or phrasesStructuredQueryDefinition word(String pojoProperty, String[] options, double weight, String... words)
pojoProperty - the name of a field or JavaBean property (accessed via getter or setter) on class Toptions - options for fine tuning the queryweight - the multiplier for the match in the document rankingwords - match a persisted pojo of type T if it has the property with any of the words or phrasesStructuredQueryDefinition and(StructuredQueryDefinition... queries)
StructuredQuerybuilder.andStructuredQueryDefinition andNot(StructuredQueryDefinition positive, StructuredQueryDefinition negative)
StructuredQuerybuilder.andNotStructuredQueryDefinition boost(StructuredQueryDefinition matchingQuery, StructuredQueryDefinition boostingQuery)
StructuredQuerybuilder.boostStructuredQueryBuilder.Region box(double south, double west, double north, double east)
StructuredQuerybuilder.boxRawStructuredQueryDefinition build(StructuredQueryDefinition... queries)
StructuredQuerybuilder.buildStructuredQueryBuilder.Region circle(double latitude, double longitude, double radius)
StructuredQuerybuilder.circle(double, double, double)StructuredQueryBuilder.Region circle(StructuredQueryBuilder.Point center, double radius)
StructuredQuerybuilder.circle(StructuredQueryBuilder.Point, double)StructuredQueryDefinition collection(String... uris)
StructuredQuerybuilder.collection(String...)StructuredQueryDefinition geospatial(StructuredQueryBuilder.GeospatialIndex index, String[] options, StructuredQueryBuilder.Region... regions)
StructuredQuerybuilder.geospatial(StructuredQueryBuilder.GeospatialIndex, StructuredQueryBuilder.FragmentScope, String[], StructuredQueryBuilder.Region...) but without StructuredQueryBuilder.FragmentScopeStructuredQueryDefinition geospatial(StructuredQueryBuilder.GeospatialIndex index, StructuredQueryBuilder.Region... regions)
StructuredQueryDefinition near(int distance, double weight, StructuredQueryBuilder.Ordering order, StructuredQueryDefinition... queries)
StructuredQueryDefinition near(StructuredQueryDefinition... queries)
StructuredQuerybuilder.near(StructuredQueryDefinition...)StructuredQueryDefinition not(StructuredQueryDefinition query)
StructuredQuerybuilder.notStructuredQueryDefinition notIn(StructuredQueryDefinition positive, StructuredQueryDefinition negative)
StructuredQuerybuilder.andStructuredQueryDefinition or(StructuredQueryDefinition... queries)
StructuredQuerybuilder.andStructuredQueryBuilder.Region point(double latitude, double longitude)
StructuredQuerybuilder.pointStructuredQueryBuilder.Region polygon(StructuredQueryBuilder.Point... points)
StructuredQuerybuilder.polygonStructuredQueryDefinition term(double weight, String... terms)
StructuredQuerybuilder.term(double, String...)StructuredQueryDefinition term(String... terms)
StructuredQuerybuilder.term(String...)PojoQueryDefinition filteredQuery(StructuredQueryDefinition query)
Copyright © 2013-2015 MarkLogic Corporation.