updated to use parent pom; added query methods
This commit is contained in:
184
pom.xml
184
pom.xml
@@ -2,16 +2,74 @@
|
||||
<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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.springframework.datastore</groupId>
|
||||
<artifactId>datastore-document</artifactId>
|
||||
<groupId>org.springframework.data </groupId>
|
||||
<artifactId>spring-datastore-document</artifactId>
|
||||
<name>Spring Datastore Document</name>
|
||||
<description>Spring Support for Document Datastores</description>
|
||||
<url>http://www.springsource.org</url>
|
||||
<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>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<spring.version>3.0.0.RELEASE</spring.version>
|
||||
<slf4j.version>1.6.0</slf4j.version>
|
||||
<spring.version>3.0.4.RELEASE</spring.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
@@ -22,44 +80,35 @@
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>1.2.15</version>
|
||||
<!-- 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>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<version>1.1.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- Spring dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>jcl-over-slf4j</artifactId>
|
||||
<version>${slf4j.version}</version>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<version>${slf4j.version}</version>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-tx</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Document Store dependencies -->
|
||||
@@ -74,73 +123,6 @@
|
||||
<version>0.11.0-1</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 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>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<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>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-tx</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!--
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>data-commons</artifactId>
|
||||
<version>1.0.0.CI-SNAPSHOT</version>
|
||||
</dependency>
|
||||
-->
|
||||
|
||||
</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>
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<DB> {
|
||||
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) {
|
||||
return MongoDbUtils.translateMongoExceptionIfPossible(ex);
|
||||
}
|
||||
|
||||
22
template.mf
Normal file
22
template.mf
Normal file
@@ -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"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user