public interface PojoQueryBuilder<T>
Specific to pojos yet similar to StructuredQueryBuilder, this class generates structured queries. It adds convenience methods specific to working with pojos and does not replicate StructuredQueryBuilder methods that don’t make sense for pojos. The goal of 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<City> citiesQb = cities.getQueryBuilder();
PojoQueryBuilder<Country> countriesQb = citiesQb.containerQueryBuilder("country", Country.class);
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)
Use this method to provide a query builder that can query a nested object within your pojo. All other PojoQueryBuilder methods create queries for direct children of T which are native types. If a child of T is a pojo, and you need to query one of its children, this method provides you a query builder that is specific to that child object. To query further levels of nested objects you may use this method on the each returned PojoQueryBuilder which represents one level deeper.
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)
For use in a 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)
For use in a 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)
Query a Path Range Index configured in the database for a pojo property. Make sure the datatype for your values parameter match the 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)
Query a Path Range Index configured in the database for a pojo property. Make sure the datatype for your values parameter match the 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)
Filter search results by properties matching specified 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)
Filter search results by properties matching specified 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)
Filter search results by properties matching specified 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)
Filter search results by properties matching specified 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)
Filter search results by properties matching specified 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 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)
Filter search results by properties matching specified 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)
Filter search results by properties with at least one of the specified words or phrases.
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)
Filter search results by properties with at least one of the specified words or phrases.
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)
Copied directly from StructuredQuerybuilder.and. Defines an AND query over the list of query definitions.
queries - the query definitionsStructuredQueryDefinition andNot(StructuredQueryDefinition positive, StructuredQueryDefinition negative)
Copied directly from 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)
Copied directly from 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)
Copied directly from 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)
Copied directly from 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)
Copied directly from 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)
Copied directly from 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)
Copied directly from 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)
Copied from 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)
Copied directly from 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)
Copied directly from 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)
Copied directly from StructuredQuerybuilder.near(StructuredQueryDefinition...). Defines a NEAR query over the list of query definitions with default parameters.
queries - the query definitionsStructuredQueryDefinition not(StructuredQueryDefinition query)
Copied directly from 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)
Copied directly from 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)
Copied directly from StructuredQuerybuilder.and. Defines an OR query over the list of query definitions.
queries - the query definitionsStructuredQueryBuilder.Region point(double latitude, double longitude)
Copied directly from StructuredQuerybuilder.point. Specifies a geospatial point.
latitude - the latitude coordinatelongitude - the longitude coordinateStructuredQueryBuilder.Region polygon(StructuredQueryBuilder.Point... points)
Copied directly from 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)
Copied directly from 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)
Copied directly from StructuredQuerybuilder.term(String...). Matches documents containing the specified terms.
terms - the possible terms to matchPojoQueryDefinition filteredQuery(StructuredQueryDefinition query)
Wraps the structured query into a combined query with options containing <search-option>filtered</search-option> so results are accurate though slower.
query - the query to mark as filteredCopyright © 2013-2017 MarkLogic Corporation.