diff --git a/pom.xml b/pom.xml index 06bd88aab..84ad02131 100644 --- a/pom.xml +++ b/pom.xml @@ -2,17 +2,75 @@ 4.0.0 - org.springframework.datastore - datastore-document + org.springframework.data + spring-datastore-document Spring Datastore Document + Spring Support for Document Datastores + http://www.springsource.org jar - 1.0.0.CI-SNAPSHOT + 1.0.0.M1-SNAPSHOT + + + org.springframework.data + spring-data-parent + 1.0.0.M1-SNAPSHOT + + + + Issue Tracker + http://jira.springframework.org/browse/DATASQL + + + http://git.springsource.org/spring-data/datastore-sql + + + SpringSource, a division of VMware + http://www.SpringSource.org + + 2010 + + + + trisberg + Thomas Risberg + trisberg at vmware.com + SpringSource + http://www.SpringSource.com + + Project Admin + Developer + + -5 + + + + + + Apache License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.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. + + + UTF-8 - 3.0.0.RELEASE - 1.6.0 - + 3.0.4.RELEASE + @@ -23,95 +81,29 @@ - log4j - log4j - 1.2.15 - - - - javax.mail - mail - - - javax.jms - jms - - - com.sun.jdmk - jmxtools - - - com.sun.jmx - jmxri - - - - - org.slf4j - slf4j-api - ${slf4j.version} - - - org.slf4j - jcl-over-slf4j - ${slf4j.version} - - - org.slf4j - slf4j-log4j12 - ${slf4j.version} + junit + junit + test - - - org.mongodb - mongo-java-driver - 2.1 + log4j + log4j - com.google.code.jcouchdb - jcouchdb - 0.11.0-1 + commons-logging + commons-logging + 1.1.1 + provided - - - org.springframework - spring-core - ${spring.version} - - - commons-logging - commons-logging - - - org.springframework spring-test - ${spring.version} test - - - commons-logging - commons-logging - - org.springframework spring-context - ${spring.version} - - - org.springframework - spring-aop - ${spring.version} - - - org.springframework - spring-aspects - ${spring.version} org.springframework @@ -119,28 +111,18 @@ ${spring.version} - + + org.mongodb + mongo-java-driver + 2.1 + - org.springframework.data - data-commons - 1.0.0.CI-SNAPSHOT + com.google.code.jcouchdb + jcouchdb + 0.11.0-1 - --> - - - - org.apache.maven.plugins - maven-compiler-plugin - 2.0.2 - - 1.5 - 1.5 - - - - - \ No newline at end of file diff --git a/src/main/java/org/springframework/datastore/document/InvalidDocumentStoreApiUageException.java b/src/main/java/org/springframework/datastore/document/InvalidDocumentStoreApiUageException.java new file mode 100644 index 000000000..f3379734a --- /dev/null +++ b/src/main/java/org/springframework/datastore/document/InvalidDocumentStoreApiUageException.java @@ -0,0 +1,31 @@ +/* + * 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.datastore.document; + +import org.springframework.dao.InvalidDataAccessApiUsageException; + +public class InvalidDocumentStoreApiUageException extends InvalidDataAccessApiUsageException { + + public InvalidDocumentStoreApiUageException(String msg) { + super(msg); + } + + public InvalidDocumentStoreApiUageException(String msg, Throwable cause) { + super(msg, cause); + } + +} diff --git a/src/main/java/org/springframework/datastore/document/mongodb/MongoTemplate.java b/src/main/java/org/springframework/datastore/document/mongodb/MongoTemplate.java index 7e379822a..ab688458e 100644 --- a/src/main/java/org/springframework/datastore/document/mongodb/MongoTemplate.java +++ b/src/main/java/org/springframework/datastore/document/mongodb/MongoTemplate.java @@ -25,7 +25,10 @@ import org.springframework.dao.InvalidDataAccessApiUsageException; import org.springframework.datastore.document.AbstractDocumentStoreTemplate; import org.springframework.datastore.document.DocumentMapper; import org.springframework.datastore.document.DocumentSource; +import org.springframework.datastore.document.InvalidDocumentStoreApiUageException; +import org.springframework.util.Assert; +import com.mongodb.BasicDBObject; import com.mongodb.CommandResult; import com.mongodb.DB; import com.mongodb.DBCollection; @@ -106,6 +109,30 @@ public class MongoTemplate extends AbstractDocumentStoreTemplate { return results; } + public List queryForList(String collectionName, String fieldName, String[] operands, Object[] values, Class targetClass) { + DocumentMapper mapper = MongoBeanPropertyDocumentMapper.newInstance(targetClass); + return queryForList(collectionName, fieldName, operands, values, mapper); + } + + public List queryForList(String collectionName, String fieldName, String[] operands, Object[] values, DocumentMapper mapper) { + if (operands.length != values.length) { + throw new InvalidDocumentStoreApiUageException("The number of operands and values must match"); + } + List results = new ArrayList(); + DBObject query = new BasicDBObject(); + DBObject condition = new BasicDBObject(); + for (int i = 0; i < operands.length; i++) { + condition.put(operands[i], values[i]); + } + query.put(fieldName, condition); + System.out.println("--> " + query); + DBCollection collection = getConnection().getCollection(collectionName); + for (DBObject dbo : collection.find(query)) { + results.add(mapper.mapDocument(dbo)); + } + return results; + } + public RuntimeException translateIfNecessary(RuntimeException ex) { return MongoDbUtils.translateMongoExceptionIfPossible(ex); } diff --git a/template.mf b/template.mf new file mode 100644 index 000000000..83d97a4f5 --- /dev/null +++ b/template.mf @@ -0,0 +1,22 @@ +Bundle-SymbolicName: org.springframework.datastore.document +Bundle-Name: Spring Datastore Document +Bundle-Vendor: SpringSource +Bundle-ManifestVersion: 2 +Import-Package: + sun.reflect;version="0";resolution:=optional +Import-Template: + org.springframework.beans.*;version="[3.0.0, 4.0.0)", + org.springframework.core.*;version="[3.0.0, 4.0.0)", + org.springframework.dao.*;version="[3.0.0, 4.0.0)", + org.springframework.util.*;version="[3.0.0, 4.0.0)", + org.springframework.data.core.*;version="[1.0.0, 2.0.0)", + org.springframework.datastore.core.*;version="[1.0.0, 2.0.0)", + org.springframework.datastore.persistence.*;version="[1.0.0, 2.0.0)", + com.mongodb.*;version="0", + org.jcouchdb.*;version="0", + org.bson.*;version="0", + org.aopalliance.*;version="[1.0.0, 2.0.0)";resolution:=optional, + org.apache.commons.logging.*;version="[1.1.1, 2.0.0)", + org.w3c.dom.*;version="0" + +