Interface PojoQueryBuilder<T>


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");