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)
pojoProperty
- the property container to match againstquery
- the query to match within the container<C> PojoQueryBuilder<C> containerQueryBuilder(String pojoProperty, Class<C> clazz)
C
- the type of the class contained by pojoPropertypojoProperty
- 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 @GeospatialLatitude
longitudePropertyName
- the name of a field or JavaBean property (accessed via getter or setter)
ideally annotated with @GeospatialLongitude
StructuredQueryBuilder.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 @GeospatialPathIndexProperty
StructuredQueryDefinition 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 @PathIndexProperty
operator
- 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 @PathIndexProperty
options
- 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.and
.
Defines an AND query over the list of query definitions.queries
- the query definitionsStructuredQueryDefinition andNot(StructuredQueryDefinition positive, StructuredQueryDefinition negative)
StructuredQuerybuilder.andNot
.
Defines an AND NOT query combining a positive and negative
query. You can use an AND or OR query over a list of query
definitions as the positive or negative query.positive
- the positive query definitionnegative
- the negative query definitionStructuredQueryDefinition boost(StructuredQueryDefinition matchingQuery, StructuredQueryDefinition boostingQuery)
StructuredQuerybuilder.boost
.
Defines a boost query for the matching and boosting query definitions. The matching
or boosting query definitions can each be an AND or OR query definition for complex
combinations of criteria.matchingQuery
- the query definition that filters documentsboostingQuery
- the query definition that increases the rank for some filtered documentsStructuredQueryBuilder.Region box(double south, double west, double north, double east)
StructuredQuerybuilder.box
.
Specifies a geospatial region as a box, supplying
the coordinates for the perimeter.south
- the latitude of the south coordinatewest
- the longitude of the west coordinatenorth
- the latitude of the north coordinateeast
- the longitude of the east coordinateRawStructuredQueryDefinition build(StructuredQueryDefinition... queries)
StructuredQuerybuilder.build
.
Builds a structured query in XML from the list of query definitions.
The structured query can be passed to the search() method of QueryManager.queries
- the query definitionsStructuredQueryBuilder.Region circle(double latitude, double longitude, double radius)
StructuredQuerybuilder.circle(double, double, double)
.
Specifies a geospatial region as a circle,
supplying coordinates for the center.latitude
- the latitude coordinate of the centerlongitude
- the longitude coordinate of the centerradius
- the radius of the circleStructuredQueryBuilder.Region circle(StructuredQueryBuilder.Point center, double radius)
StructuredQuerybuilder.circle(StructuredQueryBuilder.Point, double)
.
Specifies a geospatial region as a circle,
supplying a point for the center.center
- the point defining the centerradius
- the radius of the circleStructuredQueryDefinition collection(String... uris)
StructuredQuerybuilder.collection(String...)
.
Matches documents belonging to at least one
of the criteria collections.uris
- the identifiers for the criteria collectionsStructuredQueryDefinition geospatial(StructuredQueryBuilder.GeospatialIndex index, String[] options, StructuredQueryBuilder.Region... regions)
StructuredQuerybuilder.geospatial(StructuredQueryBuilder.GeospatialIndex, StructuredQueryBuilder.FragmentScope, String[], StructuredQueryBuilder.Region...)
but without StructuredQueryBuilder.FragmentScope.
Matches an element, element pair, element attribute, pair, or path
specifying a geospatial point that appears within one of the criteria regions.index
- the container for the coordinates of the geospatial pointoptions
- options for fine tuning the queryregions
- the possible regions containing the pointStructuredQueryDefinition geospatial(StructuredQueryBuilder.GeospatialIndex index, StructuredQueryBuilder.Region... regions)
StructuredQuerybuilder.geospatial(StructuredQueryBuilder.GeospatialIndex, StructuredQueryBuilder.Region...)
.
Matches an element, element pair, element attribute, pair, or path
specifying a geospatial point that appears within one of the criteria regions.index
- the container for the coordinates of the geospatial pointregions
- the possible regions containing the pointStructuredQueryDefinition near(int distance, double weight, StructuredQueryBuilder.Ordering order, StructuredQueryDefinition... queries)
StructuredQuerybuilder.near(int, double, StructuredQueryBuilder.Ordering, StructuredQueryDefinition...)
.
Defines a NEAR query over the list of query definitions
with specified parameters.distance
- the proximity for the query termsweight
- the weight for the queryorder
- the ordering for the query termsqueries
- the query definitionsStructuredQueryDefinition near(StructuredQueryDefinition... queries)
StructuredQuerybuilder.near(StructuredQueryDefinition...)
.
Defines a NEAR query over the list of query definitions
with default parameters.queries
- the query definitionsStructuredQueryDefinition not(StructuredQueryDefinition query)
StructuredQuerybuilder.not
.
Defines a NOT query for a query definition. To negate
a list of query definitions, define an AND or
OR query over the list and define the NOT query over
the AND or OR query.query
- the query definitionStructuredQueryDefinition notIn(StructuredQueryDefinition positive, StructuredQueryDefinition negative)
StructuredQuerybuilder.and
.
Defines a not-in query for the positive and negative query definitions. These query definitions
can each be an AND or OR query definition for complex combinations of criteria.positive
- the query definition that includes documentsnegative
- the query definition that excludes documentsStructuredQueryDefinition or(StructuredQueryDefinition... queries)
StructuredQuerybuilder.and
.
Defines an OR query over the list of query definitions.queries
- the query definitionsStructuredQueryBuilder.Region point(double latitude, double longitude)
StructuredQuerybuilder.point
.
Specifies a geospatial point.latitude
- the latitude coordinatelongitude
- the longitude coordinateStructuredQueryBuilder.Region polygon(StructuredQueryBuilder.Point... points)
StructuredQuerybuilder.polygon
.
Specifies a geospatial region as an arbitrary polygon.points
- the list of points defining the perimeter of the regionStructuredQueryDefinition term(double weight, String... terms)
StructuredQuerybuilder.term(double, String...)
.
Matches documents containing the specified terms, modifying
the contribution of the match to the score with the weight.weight
- the multiplier for the match in the document rankingterms
- the possible terms to matchStructuredQueryDefinition term(String... terms)
StructuredQuerybuilder.term(String...)
.
Matches documents containing the specified terms.terms
- the possible terms to matchPojoQueryDefinition filteredQuery(StructuredQueryDefinition query)
query
- the query to mark as filteredCopyright © 2013-2016 MarkLogic Corporation.