Skip to content

Commit 486e269

Browse files
committed
more tests and fixes of pojo facade
1 parent dc2e8b5 commit 486e269

File tree

7 files changed

+291
-209
lines changed

7 files changed

+291
-209
lines changed

src/main/java/com/marklogic/client/impl/PojoQueryBuilderImpl.java

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright 2012-2014 MarkLogic Corporation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package com.marklogic.client.impl;
217

318
import com.marklogic.client.pojo.PojoQueryBuilder;
@@ -24,6 +39,8 @@ public PojoQueryBuilderImpl(Class<T> clazz) {
2439
}
2540

2641
private StructuredQueryBuilder.PathIndex pojoFieldPath(String pojoField) {
42+
//System.out.println("DEBUG: [PojoQueryBuilderImpl] =[" + "*[local-name()=\"" + classWrapper + "\"]/" + pojoField + "]");
43+
//return pathIndex("*[local-name()=\"" + classWrapper + "\"]/" + pojoField);
2744
return pathIndex(classWrapper + "/" + pojoField);
2845
}
2946

@@ -88,19 +105,19 @@ public String getRangeIndexType(String fieldName) {
88105
if ( type == null ) {
89106
Class fieldClass = getType(fieldName);
90107
if ( String.class.isAssignableFrom(fieldClass) ) {
91-
type = "string";
92-
} else if ( Integer.class.isAssignableFrom(fieldClass) ) {
93-
type = "int";
94-
} else if ( Long.class.isAssignableFrom(fieldClass) ) {
95-
type = "long";
96-
} else if ( Float.class.isAssignableFrom(fieldClass) ) {
97-
type = "float";
98-
} else if ( Double.class.isAssignableFrom(fieldClass) ) {
99-
type = "double";
108+
type = "xs:string";
109+
} else if ( Integer.TYPE.equals(fieldClass) ) {
110+
type = "xs:int";
111+
} else if ( Long.TYPE.equals(fieldClass) ) {
112+
type = "xs:long";
113+
} else if ( Float.TYPE.equals(fieldClass) ) {
114+
type = "xs:float";
115+
} else if ( Double.TYPE.equals(fieldClass) ) {
116+
type = "xs:double";
100117
} else if ( Number.class.isAssignableFrom(fieldClass) ) {
101-
type = "decimal";
118+
type = "xs:decimal";
102119
} else if ( Date.class.isAssignableFrom(fieldClass) ) {
103-
type = "dateTime";
120+
type = "xs:dateTime";
104121
}
105122
if ( type == null ) {
106123
throw new IllegalArgumentException("Field " + fieldName + " is not a native Java type");
@@ -114,8 +131,8 @@ public Class getType(String fieldName) {
114131
Class fieldClass = types.get(fieldName);
115132
if ( fieldClass == null ) {
116133
// figure out the type of the java field
117-
String initCapPojoField = fieldName.substring(1,2).toUpperCase() +
118-
fieldName.substring(2);
134+
String initCapPojoField = fieldName.substring(0,1).toUpperCase() +
135+
fieldName.substring(1);
119136
try {
120137
fieldClass = clazz.getField(fieldName).getType();
121138
} catch(NoSuchFieldException e) {
@@ -162,5 +179,3 @@ public Class getType(String fieldName) {
162179
return fieldClass;
163180
}
164181
}
165-
166-

src/main/java/com/marklogic/client/impl/PojoRepositoryImpl.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,16 @@ public boolean exists(ID id) {
9393
}
9494

9595
public long count() {
96-
return count((String) null);
96+
return count((QueryDefinition) null);
9797
}
9898

9999
public long count(String... collections) {
100-
if ( collections == null ) return 0l;
101-
return count(wrapQuery(qb.collection(collections)));
100+
if ( collections != null && collections.length > 0 ) {
101+
if ( collections.length > 1 || collections[0] != null ) {
102+
return count(qb.collection(collections));
103+
}
104+
}
105+
return count((QueryDefinition) null);
102106
}
103107
public long count(QueryDefinition query) {
104108
long pageLength = getPageLength();

src/main/java/com/marklogic/client/query/StructuredQueryBuilder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1814,9 +1814,10 @@ void innerSerialize(XMLStreamWriter serializer) throws Exception {
18141814
serializer.writeEndElement();
18151815
}
18161816
}
1817-
class JSONPropertyImpl extends IndexImpl implements JSONProperty {
1817+
class JSONPropertyImpl extends ElementImpl implements JSONProperty {
18181818
String name;
18191819
JSONPropertyImpl(String name) {
1820+
super(name);
18201821
this.name = name;
18211822
}
18221823
@Override

src/test/java/com/marklogic/client/test/BulkReadWriteTest.java

Lines changed: 0 additions & 186 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
import javax.xml.bind.JAXBContext;
2828
import javax.xml.bind.JAXBException;
29-
import javax.xml.bind.annotation.XmlRootElement;
3029

3130
import static org.junit.Assert.assertEquals;
3231
import static org.junit.Assert.assertNotNull;
@@ -55,7 +54,6 @@
5554
import com.marklogic.client.query.DeleteQueryDefinition;
5655
import com.marklogic.client.query.QueryManager;
5756
import com.marklogic.client.query.StructuredQueryBuilder;
58-
import com.marklogic.client.pojo.annotation.Id;
5957

6058
/** Loads data from cities15000.txt which contains every city above 15000 people, and adds
6159
* data from countryInfo.txt.
@@ -82,190 +80,6 @@ public static void afterClass() {
8280
Common.release();
8381
}
8482

85-
static public class Country {
86-
private String name, continent, currencyCode, currencyName, isoCode;
87-
88-
public String getIsoCode() {
89-
return isoCode;
90-
}
91-
92-
public Country setIsoCode(String isoCode) {
93-
this.isoCode = isoCode;
94-
return this;
95-
}
96-
97-
public String getName() {
98-
return name;
99-
}
100-
101-
public Country setName(String name) {
102-
this.name = name;
103-
return this;
104-
}
105-
106-
public String getContinent() {
107-
return continent;
108-
}
109-
110-
public Country setContinent(String continent) {
111-
this.continent = continent;
112-
return this;
113-
}
114-
115-
public String getCurrencyCode() {
116-
return currencyCode;
117-
}
118-
119-
public Country setCurrencyCode(String currencyCode) {
120-
this.currencyCode = currencyCode;
121-
return this;
122-
}
123-
124-
public String getCurrencyName() {
125-
return currencyName;
126-
}
127-
128-
public Country setCurrencyName(String currencyName) {
129-
this.currencyName = currencyName;
130-
return this;
131-
}
132-
}
133-
134-
@XmlRootElement
135-
static public class City {
136-
private int geoNameId;
137-
private String name;
138-
private String asciiName;
139-
private String[] alternateNames;
140-
private double latitude;
141-
private double longitude;
142-
private String countryIsoCode;
143-
private String countryName;
144-
private String continent;
145-
private String currencyCode;
146-
private String currencyName;
147-
private long population;
148-
private int elevation;
149-
150-
@Id
151-
public int getGeoNameId() {
152-
return geoNameId;
153-
}
154-
155-
public City setGeoNameId(int geoNameId) {
156-
this.geoNameId = geoNameId;
157-
return this;
158-
}
159-
160-
public String getName() {
161-
return name;
162-
}
163-
164-
public City setName(String name) {
165-
this.name = name;
166-
return this;
167-
}
168-
169-
public String getAsciiName() {
170-
return asciiName;
171-
}
172-
173-
public City setAsciiName(String asciiName) {
174-
this.asciiName = asciiName;
175-
return this;
176-
}
177-
178-
public String[] getAlternateNames() {
179-
return alternateNames;
180-
}
181-
182-
public City setAlternateNames(String[] alternateNames) {
183-
this.alternateNames = alternateNames;
184-
return this;
185-
}
186-
187-
public double getLatitude() {
188-
return latitude;
189-
}
190-
191-
public City setLatitude(double latitude) {
192-
this.latitude = latitude;
193-
return this;
194-
}
195-
196-
public double getLongitude() {
197-
return longitude;
198-
}
199-
200-
public City setLongitude(double longitude) {
201-
this.longitude = longitude;
202-
return this;
203-
}
204-
205-
public String getCountryIsoCode() {
206-
return countryIsoCode;
207-
}
208-
209-
public City setCountryIsoCode(String countryIsoCode) {
210-
this.countryIsoCode = countryIsoCode;
211-
return this;
212-
}
213-
214-
public String getCountryName() {
215-
return countryName;
216-
}
217-
218-
public City setCountryName(String countryName) {
219-
this.countryName = countryName;
220-
return this;
221-
}
222-
223-
public String getContinent() {
224-
return continent;
225-
}
226-
227-
public City setContinent(String continent) {
228-
this.continent = continent;
229-
return this;
230-
}
231-
232-
public String getCurrencyCode() {
233-
return currencyCode;
234-
}
235-
236-
public City setCurrencyCode(String currencyCode) {
237-
this.currencyCode = currencyCode;
238-
return this;
239-
}
240-
241-
public String getCurrencyName() {
242-
return currencyName;
243-
}
244-
245-
public City setCurrencyName(String currencyName) {
246-
this.currencyName = currencyName;
247-
return this;
248-
}
249-
250-
public long getPopulation() {
251-
return population;
252-
}
253-
254-
public City setPopulation(long population) {
255-
this.population = population;
256-
return this;
257-
}
258-
259-
public int getElevation() {
260-
return elevation;
261-
}
262-
263-
public City setElevation(int elevation) {
264-
this.elevation = elevation;
265-
return this;
266-
}
267-
}
268-
26983
interface CityWriter {
27084
public void addCity(City city);
27185
public void finishBatch();

0 commit comments

Comments
 (0)