beginning of the MongoDB support

This commit is contained in:
trisberg
2010-07-15 16:40:43 -04:00
commit eca4edc1af
8 changed files with 283 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
/*
* 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;
/**
* Class used to map a Document to a business object.
*
* @author Thomas Risberg
* @since 1.0
*/
public interface DocumentMapper<D, T> {
T mapDocument(D document);
}

View File

@@ -0,0 +1,29 @@
/*
* 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;
/**
* Class used to map a business object to an object providing the source data for a Document.
*
* @author Thomas Risberg
* @since 1.0
*/
public interface DocumentSource<D, T> {
D getDocument(T source);
}

View File

@@ -0,0 +1,75 @@
/*
* 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.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import com.mongodb.DB;
import com.mongodb.Mongo;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Convenient factory for configuring MongoDB.
*
* @author Thomas Risberg
* @since 1.0
*/
public class MongoDbFactoryBean implements FactoryBean<DB>, InitializingBean {
/**
* Logger, available to subclasses.
*/
protected final Log logger = LogFactory.getLog(getClass());
private Mongo mongo;
private String databaseName;
public void setMongo(Mongo mongo) {
this.mongo = mongo;
}
public void setDatabaseName(String databaseName) {
this.databaseName = databaseName;
}
public DB getObject() throws Exception {
return mongo.getDB(databaseName);
}
public Class<? extends DB> getObjectType() {
return DB.class;
}
public boolean isSingleton() {
return false;
}
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();
}
}
}