Skip to content

Commit 90aa66b

Browse files
committed
add javadocs
1 parent 83a0671 commit 90aa66b

File tree

3 files changed

+118
-0
lines changed

3 files changed

+118
-0
lines changed

src/main/java/com/marklogic/client/pojo/PojoPage.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@
1717

1818
import com.marklogic.client.Page;
1919

20+
/** Enables pagination over objects retrieved from the server and deserialized by
21+
* PojoRepository read and search methods.
22+
*/
2023
public interface PojoPage<T> extends Page<T> {}

src/main/java/com/marklogic/client/pojo/PojoQueryBuilder.java

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,104 @@
2222
import com.marklogic.client.query.StructuredQueryDefinition;
2323
import com.marklogic.client.util.IterableNamespaceContext;
2424

25+
/** Extends StructuredQueryBuilder with convenience methods specific to working with pojos.
26+
* The goal of {@link com.marklogic.client.pojo the pojo facade} is to simplify working with
27+
* custom pojos. PojoQueryBuilder keeps all the powerful queries available via
28+
* StructuredQueryBuilder while enabling queries across objects persisted using
29+
* {@link PojoRepository}.
30+
*
31+
* <p>For methods which accept a "pojoField" argument and for {@link #geoField geoField}, we are refering to
32+
* fields (or properties) appropriate for
33+
* <a href="http://docs.oracle.com/javase/tutorial/javabeans/">JavaBeans</a>,
34+
* including fields accessible via public getters and setters, or public fields.</p>
35+
*
36+
*
37+
* <p>Where StructuredQueryBuilder accepts StructuredQueryBuilder.TextIndex as a first argument
38+
* to
39+
* {@link #value(StructuredQueryBuilder.TextIndex, String...) value(TextIndex, String...)}
40+
* and
41+
* {@link #word(StructuredQueryBuilder.TextIndex, String...) word(TextIndex, String...)}
42+
* methods,
43+
* PojoQueryBuilder adds shortcut methods which accept as the first argument a String name of the
44+
* pojoField. Similarly, PojoQueryBuilder accepts String pojoField arguments wherever
45+
* StructuredQueryBuilder accepts StructuredQueryBuilder.Element,
46+
* StructuredQueryBuilder.Attribute, and StructuredQueryBuilder.PathIndex
47+
* as arguments to
48+
* {@link #geoAttributePair(StructuredQueryBuilder.Element, StructuredQueryBuilder.Attribute,
49+
* StructuredQueryBuilder.Attribute)
50+
* geoAttributePair(Element, Attribute, Attribute)},
51+
* {@link #geoElement(StructuredQueryBuilder.Element)
52+
* geoElement(Element)},
53+
* {@link #geoElement(StructuredQueryBuilder.Element, StructuredQueryBuilder.Element)
54+
* geoElement(Element, Element)},
55+
* {@link #geoElementPair(StructuredQueryBuilder.Element, StructuredQueryBuilder.Element,
56+
* StructuredQueryBuilder.Element)
57+
* geoElementPair(Element, Element, Element)},
58+
* {@link #geoPath(StructuredQueryBuilder.PathIndex)
59+
* geoPath(PathIndex)}
60+
* </p>
61+
*
62+
* <p>Here are a couple examples. Without the pojo facade you might persist your products using
63+
* {@link com.marklogic.client.io.JacksonDatabindHandle JacksonDatabindHandle} and query the
64+
* json property thusly:</p>
65+
* <pre>{@code StructuredQueryBuilder sqb = new StructuredQueryBuilder();
66+
* QueryDefinition query = sqb.value(sqb.jsonProperty("productId"), 12345);}</pre>
67+
*
68+
* <p>If you use {@link PojoRepository} to persist your products, you can query more simply:</p>
69+
* <pre>{@code PojoQueryBuilder pqb = pojoRepository.getQueryBuilder();
70+
* QueryDefinition query = pqb.value("productId", 12345);}</pre>
71+
*
72+
* <p>Similarly, without the pojo facade you might persist your pojos using
73+
* {@link com.marklogic.client.io.JAXBHandle JAXBHandle} and if they
74+
* have a geoPosition field which is an object with latitude and longitude pojoFields
75+
* (which persist as elements) you might query them thusly:</p>
76+
* <pre>{@code StructuredQueryBuilder sqb = new StructuredQueryBuilder();
77+
* StructuredQueryBuilder.GeospatialIndex geoIdx = sqb.geoElementPair(
78+
* sqb.element("geoPosition"), sqb.element("latitude"), sqb.element("longitude"));}</pre>
79+
*
80+
* <p>But if you use {@link PojoRepository} to persist your pojos with a latitude and longitude
81+
* pojoFields, you can query them more simply:</p>
82+
* <pre>{@code PojoQueryBuilder pqb = pojoRepository.getQueryBuilder();
83+
* StructuredQueryBuilder.GeospatialIndex geoIdx =
84+
* pqb.geoPair("latitude", "longitude");}</pre>
85+
*
86+
* <p>As custom pojos may have nested pojos, PojoQueryBuilder also makes it easy to query
87+
* those nested pojos. For example, if you had the following classes:</p>
88+
* <pre> class City {
89+
* {@literal @}Id int id;
90+
* Country country;
91+
* int getId();
92+
* void setId(int id);
93+
* Country getCountry();
94+
* void setCountry(Country country);
95+
* }
96+
* class Country {
97+
* String continent;
98+
* String getContinent();
99+
* void setContinent();
100+
* }</pre>
101+
*
102+
* <p>That is, you have a pojo class City with a field "country" of type
103+
* Country, you could query fields on the nested country thusly:</p>
104+
* <pre>{@code PojoRepository<City, Integer> cities =
105+
* databaseClient.newPojoRepository(City.class, Integer.class);
106+
* PojoQueryBuilder citiesQb = cities.getQueryBuilder();
107+
* PojoQueryBuilder countriesQb = citiesQb.containerQuery("country");
108+
* QueryDefinition query = countriesQb.value("continent", "EU"); }</pre>
109+
*/
25110
public interface PojoQueryBuilder<T> {
26111
public StructuredQueryDefinition containerQuery(String pojoField,
27112
StructuredQueryDefinition query);
28113
public StructuredQueryDefinition containerQuery(StructuredQueryDefinition query);
29114
public PojoQueryBuilder<T> containerQuery(String pojoField);
30115
public StructuredQueryBuilder.GeospatialIndex
31116
geoPair(String latitudeFieldName, String longitudeFieldName);
117+
/**
118+
* NOTE: Since the pojo facade abstracts away the persistence details, "field" here refers
119+
* to a pojoField like all other convenience methods in PojoQueryBuilder,not
120+
* a MarkLogic field specified on the server.
121+
* @param pojoField the name of a field (or getter or setter) on class T
122+
*/
32123
public StructuredQueryBuilder.GeospatialIndex
33124
geoField(String pojoField);
34125
public StructuredQueryBuilder.GeospatialIndex
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* The goal of this package (sometimes referred to as "the pojo facade" is to simplify working
3+
* with custom Plain Old Java Objects (pojos) without hassling with persistence details.
4+
* {@link com.marklogic.client.pojo.PojoRepository} simplifies create, read, update, and delete
5+
* (CRUD) operations on custom pojos. {@link com.marklogic.client.pojo.PojoQueryBuilder} keeps
6+
* all the powerful queries available via StructuredQueryBuilder while enabling queries across
7+
* objects persisted using PojoRepository.
8+
*/
9+
/*
10+
* Copyright 2012-2014 MarkLogic Corporation
11+
*
12+
* Licensed under the Apache License, Version 2.0 (the "License");
13+
* you may not use this file except in compliance with the License.
14+
* You may obtain a copy of the License at
15+
*
16+
* http://www.apache.org/licenses/LICENSE-2.0
17+
*
18+
* Unless required by applicable law or agreed to in writing, software
19+
* distributed under the License is distributed on an "AS IS" BASIS,
20+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21+
* See the License for the specific language governing permissions and
22+
* limitations under the License.
23+
*/
24+
package com.marklogic.client.pojo;

0 commit comments

Comments
 (0)