Browse Source

Merge remote branch 'origin/master'

pull/1/head
Mark Pollack 15 years ago
parent
commit
81c0b4fbde
  1. 40
      spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/query/BasicQuery.java
  2. 161
      spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/query/Criteria.java
  3. 24
      spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/query/CriteriaSpec.java
  4. 29
      spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/query/FieldSpecification.java
  5. 46
      spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/query/OrCriteria.java
  6. 25
      spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/query/Query.java
  7. 68
      spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/query/QueryBuilder.java
  8. 25
      spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/query/SliceSpecification.java
  9. 29
      spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/query/SortSpecification.java

40
spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/query/BasicQuery.java

@ -1,40 +0,0 @@ @@ -1,40 +0,0 @@
/*
* Copyright 2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.document.mongodb.query;
import com.mongodb.DBObject;
import com.mongodb.util.JSON;
public class BasicQuery implements Query {
private DBObject dbo = null;
public BasicQuery(String query) {
super();
this.dbo = (DBObject) JSON.parse(query);
}
public BasicQuery(DBObject dbo) {
super();
this.dbo = dbo;
}
public DBObject getQueryObject() {
return dbo;
}
}

161
spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/query/Criteria.java

@ -1,161 +0,0 @@ @@ -1,161 +0,0 @@
/*
* Copyright 2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.document.mongodb.query;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import org.springframework.data.document.InvalidDocumentStoreApiUageException;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
public class Criteria implements CriteriaSpec {
private QueryBuilder qb = null;
private LinkedHashMap<String, Object> criteria = new LinkedHashMap<String, Object>();
private Object isValue = null;
public Criteria(QueryBuilder qb) {
super();
this.qb = qb;
}
public Criteria and(String key) {
return qb.find(key);
}
public Criteria is(Object o) {
if (isValue != null) {
throw new InvalidDocumentStoreApiUageException("Multiple 'is' values declared.");
}
this.isValue = o;
return this;
}
public Criteria lt(Object o) {
criteria.put("$lt", o);
return this;
}
public Criteria lte(Object o) {
criteria.put("$lte", o);
return this;
}
public Criteria gt(Object o) {
criteria.put("$gt", o);
return this;
}
public Criteria gte(Object o) {
criteria.put("$gte", o);
return this;
}
public Criteria in(Object... o) {
criteria.put("$in", o);
return this;
}
public Criteria nin(Object... o) {
criteria.put("$min", o);
return this;
}
public Criteria mod(Number value, Number remainder) {
List<Object> l = new ArrayList<Object>();
l.add(value);
l.add(remainder);
criteria.put("$mod", l);
return this;
}
public Criteria all(Object o) {
criteria.put("$is", o);
return this;
}
public Criteria size(Object o) {
criteria.put("$is", o);
return this;
}
public Criteria exists(boolean b) {
return this;
}
public Criteria type(int t) {
return this;
}
public Criteria not() {
criteria.put("$not", null);
return this;
}
public Criteria regExp(String re) {
return this;
}
public void or(List<Query> queries) {
criteria.put("$or", queries);
}
public Query build() {
return qb.build();
}
/* (non-Javadoc)
* @see org.springframework.datastore.document.mongodb.query.Criteria#getCriteriaObject(java.lang.String)
*/
public DBObject getCriteriaObject(String key) {
DBObject dbo = new BasicDBObject();
boolean not = false;
for (String k : criteria.keySet()) {
if (not) {
DBObject notDbo = new BasicDBObject();
notDbo.put(k, criteria.get(k));
dbo.put("$not", notDbo);
not = false;
}
else {
if ("$not".equals(k)) {
not = true;
}
else {
dbo.put(k, criteria.get(k));
}
}
}
DBObject queryCriteria = new BasicDBObject();
if (isValue != null) {
queryCriteria.put(key, isValue);
queryCriteria.putAll(dbo);
}
else {
queryCriteria.put(key, dbo);
}
return queryCriteria;
}
}

24
spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/query/CriteriaSpec.java

@ -1,24 +0,0 @@ @@ -1,24 +0,0 @@
/*
* Copyright 2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.document.mongodb.query;
import com.mongodb.DBObject;
public interface CriteriaSpec {
DBObject getCriteriaObject(String key);
}

29
spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/query/FieldSpecification.java

@ -1,29 +0,0 @@ @@ -1,29 +0,0 @@
/*
* Copyright 2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.document.mongodb.query;
public class FieldSpecification {
public FieldSpecification include(String key) {
return this;
}
public FieldSpecification exclude(String key) {
return this;
}
}

46
spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/query/OrCriteria.java

@ -1,46 +0,0 @@ @@ -1,46 +0,0 @@
/*
* Copyright 2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.document.mongodb.query;
import org.bson.types.BasicBSONList;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
public class OrCriteria implements CriteriaSpec {
Query[] queries = null;
public OrCriteria(Query[] queries) {
super();
this.queries = queries;
}
/* (non-Javadoc)
* @see org.springframework.datastore.document.mongodb.query.Criteria#getCriteriaObject(java.lang.String)
*/
public DBObject getCriteriaObject(String key) {
DBObject dbo = new BasicDBObject();
BasicBSONList l = new BasicBSONList();
for (Query q : queries) {
l.add(q.getQueryObject());
}
dbo.put(key, l);
return dbo;
}
}

25
spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/query/Query.java

@ -1,25 +0,0 @@ @@ -1,25 +0,0 @@
/*
* Copyright 2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.document.mongodb.query;
import com.mongodb.DBObject;
public interface Query {
DBObject getQueryObject();
}

68
spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/query/QueryBuilder.java

@ -1,68 +0,0 @@ @@ -1,68 +0,0 @@
/*
* Copyright 2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.document.mongodb.query;
import java.util.LinkedHashMap;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
public class QueryBuilder implements Query {
private LinkedHashMap<String, CriteriaSpec> criteria = new LinkedHashMap<String, CriteriaSpec>();
public Criteria find(String key) {
Criteria c = new Criteria(this);
this.criteria.put(key, c);
return c;
}
public QueryBuilder or(Query... queries) {
this.criteria.put("$or", new OrCriteria(queries));
return this;
}
public FieldSpecification fields() {
return new FieldSpecification();
}
public SliceSpecification slice() {
return new SliceSpecification();
}
public SortSpecification sort() {
return new SortSpecification();
}
public QueryBuilder limit(int limit) {
return this;
}
public Query build() {
return this;
}
public DBObject getQueryObject() {
DBObject dbo = new BasicDBObject();
for (String k : criteria.keySet()) {
CriteriaSpec c = criteria.get(k);
DBObject cl = c.getCriteriaObject(k);
dbo.putAll(cl);
}
return dbo;
}
}

25
spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/query/SliceSpecification.java

@ -1,25 +0,0 @@ @@ -1,25 +0,0 @@
/*
* Copyright 2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.document.mongodb.query;
public class SliceSpecification {
public SliceSpecification on(String key, int size) {
return this;
}
}

29
spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/query/SortSpecification.java

@ -1,29 +0,0 @@ @@ -1,29 +0,0 @@
/*
* Copyright 2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.document.mongodb.query;
public class SortSpecification {
public enum SortOrder {
ASCENDING, DESCENDING
}
public SortSpecification on(String key, SortOrder order) {
return this;
}
}
Loading…
Cancel
Save