Browse Source

updated to use parent pom; added query methods

pull/1/head
Thomas Risberg 15 years ago
parent
commit
9c8c442b3d
  1. 182
      pom.xml
  2. 31
      src/main/java/org/springframework/datastore/document/InvalidDocumentStoreApiUageException.java
  3. 27
      src/main/java/org/springframework/datastore/document/mongodb/MongoTemplate.java
  4. 22
      template.mf

182
pom.xml

@ -2,17 +2,75 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.datastore</groupId> <groupId>org.springframework.data </groupId>
<artifactId>datastore-document</artifactId> <artifactId>spring-datastore-document</artifactId>
<name>Spring Datastore Document</name> <name>Spring Datastore Document</name>
<description>Spring Support for Document Datastores</description>
<url>http://www.springsource.org</url>
<packaging>jar</packaging> <packaging>jar</packaging>
<version>1.0.0.CI-SNAPSHOT</version> <version>1.0.0.M1-SNAPSHOT</version>
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-parent</artifactId>
<version>1.0.0.M1-SNAPSHOT</version>
</parent>
<issueManagement>
<system>Issue Tracker</system>
<url>http://jira.springframework.org/browse/DATASQL</url>
</issueManagement>
<scm>
<url>http://git.springsource.org/spring-data/datastore-sql</url>
</scm>
<organization>
<name>SpringSource, a division of VMware</name>
<url>http://www.SpringSource.org</url>
</organization>
<inceptionYear>2010</inceptionYear>
<developers>
<developer>
<id>trisberg</id>
<name>Thomas Risberg</name>
<email>trisberg at vmware.com</email>
<organization>SpringSource</organization>
<organizationUrl>http://www.SpringSource.com</organizationUrl>
<roles>
<role>Project Admin</role>
<role>Developer</role>
</roles>
<timezone>-5</timezone>
</developer>
</developers>
<licenses>
<license>
<name>Apache License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0</url>
<comments>
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.
</comments>
</license>
</licenses>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring.version>3.0.0.RELEASE</spring.version> <spring.version>3.0.4.RELEASE</spring.version>
<slf4j.version>1.6.0</slf4j.version> </properties>
</properties>
<dependencies> <dependencies>
<dependency> <dependency>
@ -23,95 +81,29 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>log4j</groupId> <groupId>junit</groupId>
<artifactId>log4j</artifactId> <artifactId>junit</artifactId>
<version>1.2.15</version> <scope>test</scope>
<!-- Exclusions only required for version 1.2.15 of log4j -->
<exclusions>
<exclusion>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
</exclusion>
<exclusion>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jdmk</groupId>
<artifactId>jmxtools</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jmx</groupId>
<artifactId>jmxri</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${slf4j.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>log4j</groupId>
<artifactId>slf4j-log4j12</artifactId> <artifactId>log4j</artifactId>
<version>${slf4j.version}</version>
</dependency> </dependency>
<!-- Document Store dependencies -->
<dependency> <dependency>
<groupId>org.mongodb</groupId> <groupId>commons-logging</groupId>
<artifactId>mongo-java-driver</artifactId> <artifactId>commons-logging</artifactId>
<version>2.1</version> <version>1.1.1</version>
<scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>com.google.code.jcouchdb</groupId>
<artifactId>jcouchdb</artifactId>
<version>0.11.0-1</version>
</dependency>
<!-- Spring dependencies --> <!-- Spring dependencies -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency> <dependency>
<groupId>org.springframework</groupId> <groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId> <artifactId>spring-test</artifactId>
<version>${spring.version}</version>
<scope>test</scope> <scope>test</scope>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework</groupId> <groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId> <artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>${spring.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework</groupId> <groupId>org.springframework</groupId>
@ -119,28 +111,18 @@
<version>${spring.version}</version> <version>${spring.version}</version>
</dependency> </dependency>
<!-- <!-- Document Store dependencies -->
<dependency> <dependency>
<groupId>org.springframework.data</groupId> <groupId>org.mongodb</groupId>
<artifactId>data-commons</artifactId> <artifactId>mongo-java-driver</artifactId>
<version>1.0.0.CI-SNAPSHOT</version> <version>2.1</version>
</dependency>
<dependency>
<groupId>com.google.code.jcouchdb</groupId>
<artifactId>jcouchdb</artifactId>
<version>0.11.0-1</version>
</dependency> </dependency>
-->
</dependencies> </dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
</project> </project>

31
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);
}
}

27
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.AbstractDocumentStoreTemplate;
import org.springframework.datastore.document.DocumentMapper; import org.springframework.datastore.document.DocumentMapper;
import org.springframework.datastore.document.DocumentSource; 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.CommandResult;
import com.mongodb.DB; import com.mongodb.DB;
import com.mongodb.DBCollection; import com.mongodb.DBCollection;
@ -106,6 +109,30 @@ public class MongoTemplate extends AbstractDocumentStoreTemplate<DB> {
return results; return results;
} }
public <T> List<T> queryForList(String collectionName, String fieldName, String[] operands, Object[] values, Class<T> targetClass) {
DocumentMapper<DBObject, T> mapper = MongoBeanPropertyDocumentMapper.newInstance(targetClass);
return queryForList(collectionName, fieldName, operands, values, mapper);
}
public <T> List<T> queryForList(String collectionName, String fieldName, String[] operands, Object[] values, DocumentMapper<DBObject, T> mapper) {
if (operands.length != values.length) {
throw new InvalidDocumentStoreApiUageException("The number of operands and values must match");
}
List<T> results = new ArrayList<T>();
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) { public RuntimeException translateIfNecessary(RuntimeException ex) {
return MongoDbUtils.translateMongoExceptionIfPossible(ex); return MongoDbUtils.translateMongoExceptionIfPossible(ex);
} }

22
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"
Loading…
Cancel
Save