adding beginnings of some Mongo abstractions
This commit is contained in:
22
.classpath
22
.classpath
@@ -2,10 +2,12 @@
|
||||
<classpathentry kind="src" path="src/main/java"/>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="var" path="M2_REPO/aopalliance/aopalliance/1.0/aopalliance-1.0.jar" sourcepath="M2_REPO/aopalliance/aopalliance/1.0/aopalliance-1.0-sources.jar"/>
|
||||
<classpathentry kind="var" path="M2_REPO/org/aopalliance/com.springsource.org.aopalliance/1.0.0/com.springsource.org.aopalliance-1.0.0.jar" sourcepath="M2_REPO/org/aopalliance/com.springsource.org.aopalliance/1.0.0/com.springsource.org.aopalliance-1.0.0-sources.jar"/>
|
||||
<classpathentry kind="var" path="M2_REPO/org/slf4j/jcl-over-slf4j/1.6.0/jcl-over-slf4j-1.6.0.jar"/>
|
||||
<classpathentry kind="var" path="M2_REPO/junit/junit/4.8.1/junit-4.8.1.jar"/>
|
||||
<classpathentry kind="var" path="M2_REPO/log4j/log4j/1.2.15/log4j-1.2.15.jar"/>
|
||||
<classpathentry kind="var" path="M2_REPO/org/springframework/data/data-commons/1.0.0.CI-SNAPSHOT/data-commons-1.0.0.CI-SNAPSHOT.jar"/>
|
||||
<classpathentry kind="var" path="M2_REPO/org/slf4j/jcl-over-slf4j/1.6.0/jcl-over-slf4j-1.6.0.jar" sourcepath="M2_REPO/org/slf4j/jcl-over-slf4j/1.6.0/jcl-over-slf4j-1.6.0-sources.jar"/>
|
||||
<classpathentry kind="var" path="M2_REPO/junit/junit/4.8.1/junit-4.8.1.jar" sourcepath="M2_REPO/junit/junit/4.8.1/junit-4.8.1-sources.jar"/>
|
||||
<classpathentry kind="var" path="M2_REPO/log4j/log4j/1.2.15/log4j-1.2.15.jar" sourcepath="M2_REPO/log4j/log4j/1.2.15/log4j-1.2.15-sources.jar"/>
|
||||
<classpathentry kind="var" path="M2_REPO/org/mongodb/mongo-java-driver/1.4/mongo-java-driver-1.4.jar"/>
|
||||
<classpathentry kind="var" path="M2_REPO/org/springframework/org.springframework.aop/3.0.0.RELEASE/org.springframework.aop-3.0.0.RELEASE.jar" sourcepath="M2_REPO/org/springframework/org.springframework.aop/3.0.0.RELEASE/org.springframework.aop-3.0.0.RELEASE-sources.jar"/>
|
||||
<classpathentry kind="var" path="M2_REPO/org/springframework/org.springframework.asm/3.0.0.RELEASE/org.springframework.asm-3.0.0.RELEASE.jar" sourcepath="M2_REPO/org/springframework/org.springframework.asm/3.0.0.RELEASE/org.springframework.asm-3.0.0.RELEASE-sources.jar"/>
|
||||
@@ -15,6 +17,16 @@
|
||||
<classpathentry kind="var" path="M2_REPO/org/springframework/org.springframework.expression/3.0.0.RELEASE/org.springframework.expression-3.0.0.RELEASE.jar" sourcepath="M2_REPO/org/springframework/org.springframework.expression/3.0.0.RELEASE/org.springframework.expression-3.0.0.RELEASE-sources.jar"/>
|
||||
<classpathentry kind="var" path="M2_REPO/org/springframework/org.springframework.test/3.0.0.RELEASE/org.springframework.test-3.0.0.RELEASE.jar" sourcepath="M2_REPO/org/springframework/org.springframework.test/3.0.0.RELEASE/org.springframework.test-3.0.0.RELEASE-sources.jar"/>
|
||||
<classpathentry kind="var" path="M2_REPO/org/springframework/org.springframework.transaction/3.0.0.RELEASE/org.springframework.transaction-3.0.0.RELEASE.jar" sourcepath="M2_REPO/org/springframework/org.springframework.transaction/3.0.0.RELEASE/org.springframework.transaction-3.0.0.RELEASE-sources.jar"/>
|
||||
<classpathentry kind="var" path="M2_REPO/org/slf4j/slf4j-api/1.6.0/slf4j-api-1.6.0.jar"/>
|
||||
<classpathentry kind="var" path="M2_REPO/org/slf4j/slf4j-log4j12/1.6.0/slf4j-log4j12-1.6.0.jar"/>
|
||||
<classpathentry kind="var" path="M2_REPO/org/slf4j/slf4j-api/1.6.0/slf4j-api-1.6.0.jar" sourcepath="M2_REPO/org/slf4j/slf4j-api/1.6.0/slf4j-api-1.6.0-sources.jar"/>
|
||||
<classpathentry kind="var" path="M2_REPO/org/slf4j/slf4j-log4j12/1.6.0/slf4j-log4j12-1.6.0.jar" sourcepath="M2_REPO/org/slf4j/slf4j-log4j12/1.6.0/slf4j-log4j12-1.6.0-sources.jar"/>
|
||||
<classpathentry kind="var" path="M2_REPO/org/springframework/spring-aop/3.0.2.RELEASE/spring-aop-3.0.2.RELEASE.jar" sourcepath="M2_REPO/org/springframework/spring-aop/3.0.2.RELEASE/spring-aop-3.0.2.RELEASE-sources.jar"/>
|
||||
<classpathentry kind="var" path="M2_REPO/org/springframework/spring-asm/3.0.2.RELEASE/spring-asm-3.0.2.RELEASE.jar" sourcepath="M2_REPO/org/springframework/spring-asm/3.0.2.RELEASE/spring-asm-3.0.2.RELEASE-sources.jar"/>
|
||||
<classpathentry kind="var" path="M2_REPO/org/springframework/spring-aspects/3.0.2.RELEASE/spring-aspects-3.0.2.RELEASE.jar" sourcepath="M2_REPO/org/springframework/spring-aspects/3.0.2.RELEASE/spring-aspects-3.0.2.RELEASE-sources.jar"/>
|
||||
<classpathentry kind="var" path="M2_REPO/org/springframework/spring-beans/3.0.2.RELEASE/spring-beans-3.0.2.RELEASE.jar" sourcepath="M2_REPO/org/springframework/spring-beans/3.0.2.RELEASE/spring-beans-3.0.2.RELEASE-sources.jar"/>
|
||||
<classpathentry kind="var" path="M2_REPO/org/springframework/spring-context/3.0.2.RELEASE/spring-context-3.0.2.RELEASE.jar" sourcepath="M2_REPO/org/springframework/spring-context/3.0.2.RELEASE/spring-context-3.0.2.RELEASE-sources.jar"/>
|
||||
<classpathentry kind="var" path="M2_REPO/org/springframework/spring-context-support/3.0.2.RELEASE/spring-context-support-3.0.2.RELEASE.jar" sourcepath="M2_REPO/org/springframework/spring-context-support/3.0.2.RELEASE/spring-context-support-3.0.2.RELEASE-sources.jar"/>
|
||||
<classpathentry kind="var" path="M2_REPO/org/springframework/spring-core/3.0.2.RELEASE/spring-core-3.0.2.RELEASE.jar" sourcepath="M2_REPO/org/springframework/spring-core/3.0.2.RELEASE/spring-core-3.0.2.RELEASE-sources.jar"/>
|
||||
<classpathentry kind="var" path="M2_REPO/org/springframework/spring-expression/3.0.2.RELEASE/spring-expression-3.0.2.RELEASE.jar" sourcepath="M2_REPO/org/springframework/spring-expression/3.0.2.RELEASE/spring-expression-3.0.2.RELEASE-sources.jar"/>
|
||||
<classpathentry kind="var" path="M2_REPO/org/springframework/spring-test/3.0.2.RELEASE/spring-test-3.0.2.RELEASE.jar" sourcepath="M2_REPO/org/springframework/spring-test/3.0.2.RELEASE/spring-test-3.0.2.RELEASE-sources.jar"/>
|
||||
<classpathentry kind="var" path="M2_REPO/org/springframework/spring-tx/3.0.2.RELEASE/spring-tx-3.0.2.RELEASE.jar" sourcepath="M2_REPO/org/springframework/spring-tx/3.0.2.RELEASE/spring-tx-3.0.2.RELEASE-sources.jar"/>
|
||||
</classpath>
|
||||
10
pom.xml
10
pom.xml
@@ -2,11 +2,11 @@
|
||||
<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.document</groupId>
|
||||
<groupId>org.springframework.datastore</groupId>
|
||||
<artifactId>datastore-document</artifactId>
|
||||
<name>Spring Datastore Document</name>
|
||||
<packaging>jar</packaging>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<version>1.0.0.CI-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
@@ -92,6 +92,12 @@
|
||||
<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>
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* 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.mongodb;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.datastore.core.DatastoreConnectionFactory;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.mongodb.DB;
|
||||
import com.mongodb.Mongo;
|
||||
|
||||
/**
|
||||
* Convenient factory for configuring MongoDB.
|
||||
*
|
||||
* @author Thomas Risberg
|
||||
* @since 1.0
|
||||
*/
|
||||
public class MongoConnectionFactory implements DatastoreConnectionFactory<DB>, InitializingBean {
|
||||
|
||||
/**
|
||||
* Logger, available to subclasses.
|
||||
*/
|
||||
protected final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
private Mongo mongo;
|
||||
private String databaseName;
|
||||
|
||||
public MongoConnectionFactory() {
|
||||
super();
|
||||
}
|
||||
|
||||
public MongoConnectionFactory(String databaseName) {
|
||||
super();
|
||||
this.databaseName = databaseName;
|
||||
}
|
||||
|
||||
public MongoConnectionFactory(Mongo mongo, String databaseName) {
|
||||
super();
|
||||
this.mongo = mongo;
|
||||
this.databaseName = databaseName;
|
||||
}
|
||||
|
||||
public void setMongo(Mongo mongo) {
|
||||
this.mongo = mongo;
|
||||
}
|
||||
|
||||
public void setDatabaseName(String databaseName) {
|
||||
this.databaseName = databaseName;
|
||||
}
|
||||
|
||||
public boolean isSingleton() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
// apply defaults - convenient when used to configure for tests
|
||||
// in an application context
|
||||
if (databaseName == null) {
|
||||
logger.warn("Property databaseName not specified. Using default name 'test'");
|
||||
databaseName = "test";
|
||||
}
|
||||
if (mongo == null) {
|
||||
logger.warn("Property mongo not specified. Using default configuration");
|
||||
mongo = new Mongo();
|
||||
}
|
||||
}
|
||||
|
||||
public DB getConnection() {
|
||||
Assert.notNull(mongo, "Mongo must not be null");
|
||||
Assert.hasText(databaseName, "Database name must not be empty");
|
||||
return mongo.getDB(databaseName);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package org.springframework.datastore.document.mongodb;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.core.DataMapper;
|
||||
import org.springframework.data.core.QueryDefinition;
|
||||
import org.springframework.datastore.core.AbstractDatastoreTemplate;
|
||||
|
||||
import com.mongodb.DB;
|
||||
import com.mongodb.Mongo;
|
||||
|
||||
public class MongoDatastoreTemplate extends AbstractDatastoreTemplate<DB> {
|
||||
|
||||
private Mongo mongo;
|
||||
|
||||
|
||||
public MongoDatastoreTemplate() {
|
||||
super();
|
||||
}
|
||||
|
||||
public MongoDatastoreTemplate(Mongo mongo, String databaseName) {
|
||||
super();
|
||||
this.mongo = mongo;
|
||||
setDatastoreConnectionFactory(new MongoConnectionFactory(mongo, databaseName));
|
||||
}
|
||||
|
||||
|
||||
public Mongo getMongo() {
|
||||
return mongo;
|
||||
}
|
||||
|
||||
public void setMongo(Mongo mongo) {
|
||||
this.mongo = mongo;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public <S, T> List<T> query(QueryDefinition arg0, DataMapper<S, T> arg1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -38,19 +38,18 @@ public class MongoDbFactoryBean implements FactoryBean<DB>, InitializingBean {
|
||||
*/
|
||||
protected final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
private Mongo mongo;
|
||||
private String databaseName;
|
||||
private MongoConnectionFactory mcf = new MongoConnectionFactory();
|
||||
|
||||
public void setMongo(Mongo mongo) {
|
||||
this.mongo = mongo;
|
||||
this.mcf.setMongo(mongo);
|
||||
}
|
||||
|
||||
public void setDatabaseName(String databaseName) {
|
||||
this.databaseName = databaseName;
|
||||
this.mcf.setDatabaseName(databaseName);
|
||||
}
|
||||
|
||||
public DB getObject() throws Exception {
|
||||
return mongo.getDB(databaseName);
|
||||
return mcf.getConnection();
|
||||
}
|
||||
|
||||
public Class<? extends DB> getObjectType() {
|
||||
@@ -62,14 +61,7 @@ public class MongoDbFactoryBean implements FactoryBean<DB>, InitializingBean {
|
||||
}
|
||||
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
if (databaseName == null) {
|
||||
logger.warn("Property databaseName not specified. Using default name 'test'");
|
||||
databaseName = "test";
|
||||
}
|
||||
if (mongo == null) {
|
||||
logger.warn("Property mongo not specified. Using default configuration");
|
||||
mongo = new Mongo();
|
||||
}
|
||||
this.mcf.afterPropertiesSet();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user