Format, organize imports, remove eclipse artifacts
This commit is contained in:
@@ -1,9 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry including="**/*.aj|**/*.java" kind="src" output="target/classes" path="src/main/java"/>
|
||||
<classpathentry including="**/*.aj|**/*.java" kind="src" output="target/test-classes" path="src/test/java"/>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/resources"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
|
||||
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
||||
@@ -1,24 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>spring-data-mongodb-cross-store</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.ajdt.core.ajbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.maven.ide.eclipse.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.ajdt.ui.ajnature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.maven.ide.eclipse.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -1,9 +0,0 @@
|
||||
#Tue Mar 01 09:48:37 EST 2011
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
|
||||
org.eclipse.jdt.core.compiler.compliance=1.6
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.source=1.6
|
||||
@@ -1,8 +0,0 @@
|
||||
#Mon Feb 28 16:25:59 EST 2011
|
||||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
fullBuildGoals=process-test-resources
|
||||
resolveWorkspaceProjects=true
|
||||
resourceFilterGoals=process-resources resources\:testResources
|
||||
skipCompilerPlugin=true
|
||||
version=1
|
||||
@@ -115,72 +115,72 @@
|
||||
<version>1.0.0.Final</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>jboss-repository</id>
|
||||
<name>JBoss Public Repository</name>
|
||||
<url>http://repository.jboss.org/nexus/content/groups/public-jboss</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>spring-maven-snapshot</id>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
<name>Springframework Maven SNAPSHOT Repository</name>
|
||||
<url>http://maven.springframework.org/snapshot</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>spring-maven-milestones</id>
|
||||
<name>Springframework Maven Milestone Repository</name>
|
||||
<url>http://maven.springframework.org/milestone</url>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>aspectj-maven-plugin</artifactId>
|
||||
<version>1.2</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjrt</artifactId>
|
||||
<version>${aspectj.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjtools</artifactId>
|
||||
<version>${aspectj.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
<goal>test-compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<outxml>true</outxml>
|
||||
<aspectLibraries>
|
||||
<aspectLibrary>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-aspects</artifactId>
|
||||
</aspectLibrary>
|
||||
<aspectLibrary>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-commons-aspects</artifactId>
|
||||
</aspectLibrary>
|
||||
</aspectLibraries>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</dependencies>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>jboss-repository</id>
|
||||
<name>JBoss Public Repository</name>
|
||||
<url>http://repository.jboss.org/nexus/content/groups/public-jboss</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>spring-maven-snapshot</id>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
<name>Springframework Maven SNAPSHOT Repository</name>
|
||||
<url>http://maven.springframework.org/snapshot</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>spring-maven-milestones</id>
|
||||
<name>Springframework Maven Milestone Repository</name>
|
||||
<url>http://maven.springframework.org/milestone</url>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>aspectj-maven-plugin</artifactId>
|
||||
<version>1.2</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjrt</artifactId>
|
||||
<version>${aspectj.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjtools</artifactId>
|
||||
<version>${aspectj.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
<goal>test-compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<outxml>true</outxml>
|
||||
<aspectLibraries>
|
||||
<aspectLibrary>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-aspects</artifactId>
|
||||
</aspectLibrary>
|
||||
<aspectLibrary>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-commons-aspects</artifactId>
|
||||
</aspectLibrary>
|
||||
</aspectLibraries>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -8,7 +8,7 @@ import java.lang.annotation.Target;
|
||||
/**
|
||||
* Annotation to denote an object that should be transparently persisted
|
||||
* using MongoDB
|
||||
*
|
||||
*
|
||||
* @author Thomas Risberg
|
||||
*/
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package org.springframework.persistence.document;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.mongodb.BasicDBObject;
|
||||
import com.mongodb.DBCollection;
|
||||
import com.mongodb.DBObject;
|
||||
import com.mongodb.MongoException;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -14,111 +16,104 @@ import org.springframework.persistence.support.ChangeSetBacked;
|
||||
import org.springframework.persistence.support.ChangeSetPersister;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
import com.mongodb.BasicDBObject;
|
||||
import com.mongodb.DB;
|
||||
import com.mongodb.DBCollection;
|
||||
import com.mongodb.DBObject;
|
||||
import com.mongodb.Mongo;
|
||||
import com.mongodb.MongoException;
|
||||
|
||||
//import edu.emory.mathcs.backport.java.util.Arrays;
|
||||
|
||||
public class MongoChangeSetPersister implements ChangeSetPersister<Object> {
|
||||
|
||||
protected final Log log = LogFactory.getLog(getClass());
|
||||
protected final Log log = LogFactory.getLog(getClass());
|
||||
|
||||
@Autowired
|
||||
private MongoTemplate mongoTemplate;
|
||||
|
||||
@Autowired
|
||||
private ConversionService conversionService;
|
||||
|
||||
@Override
|
||||
public void getPersistentState(Class<? extends ChangeSetBacked> entityClass, Object id, ChangeSet changeSet)
|
||||
throws DataAccessException, NotFoundException {
|
||||
String collection = ClassUtils.getShortName(entityClass).toLowerCase();
|
||||
DBObject q = new BasicDBObject();
|
||||
q.put("_id", id);
|
||||
try {
|
||||
DBObject dbo = mongoTemplate.getCollection(collection).findOne(q);
|
||||
log.debug("Found DBObject: " + dbo);
|
||||
if (dbo == null) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
String classShortName = ClassUtils.getShortName(entityClass);
|
||||
for (Object property : dbo.toMap().keySet()) {
|
||||
String propertyKey = (String) property;
|
||||
String propertyName = propertyKey.startsWith(classShortName) ? propertyKey.substring(propertyKey.indexOf(classShortName)
|
||||
+ classShortName.length() + 1) : propertyKey;
|
||||
// System.err.println("Mongo persisted property [" + propertyName + "] :: " + propertyKey + " = " + dbo.get(propertyKey));
|
||||
if (propertyKey.startsWith("_")) {
|
||||
// Id or class
|
||||
changeSet.set(propertyKey, dbo.get(propertyKey));
|
||||
} else {
|
||||
//throw new IllegalStateException("Unknown property [" + propertyName + "] found in MongoDB store");
|
||||
changeSet.set(propertyKey, dbo.get(propertyKey));
|
||||
}
|
||||
}
|
||||
} catch (MongoException ex) {
|
||||
throw new DataAccessResourceFailureException("Can't read from Mongo", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPersistentId(Class<? extends ChangeSetBacked> entityClass,
|
||||
ChangeSet cs) throws DataAccessException {
|
||||
log.debug("getPersistentId called on " + entityClass);
|
||||
if (cs == null) {
|
||||
return null;
|
||||
}
|
||||
if (cs.getValues().get(ChangeSetPersister.ID_KEY) == null) {
|
||||
// Not yet persistent
|
||||
return null;
|
||||
}
|
||||
Object o = cs.getValues().get(ChangeSetPersister.ID_KEY);
|
||||
return o;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object persistState(Class<? extends ChangeSetBacked> entityClass, ChangeSet cs) throws DataAccessException {
|
||||
log.info("PERSIST::"+cs);
|
||||
cs.set(CLASS_KEY, entityClass.getName());
|
||||
String idstr = cs.get(ID_KEY, String.class, this.conversionService);
|
||||
Object id = null;
|
||||
if (idstr != null) {
|
||||
id = idstr;
|
||||
}
|
||||
if (id == null) {
|
||||
log.info("Flush: entity make persistent; data store will assign id");
|
||||
cs.set("_class", entityClass.getName());
|
||||
String collection = entityClass.getSimpleName().toLowerCase();
|
||||
DBCollection dbc = mongoTemplate.getCollection(collection);
|
||||
DBObject dbo = mapChangeSetToDbObject(cs);
|
||||
if (dbc == null) {
|
||||
dbc = mongoTemplate.createCollection(collection);
|
||||
}
|
||||
dbc.save(dbo);
|
||||
id = dbo.get(ID_KEY);
|
||||
log.info("Data store assigned id: " + id);
|
||||
} else {
|
||||
log.info("Flush: entity already persistent with id=" + id);
|
||||
String collection = entityClass.getName();
|
||||
DBCollection dbc = mongoTemplate.getCollection(collection);
|
||||
DBObject dbo = mapChangeSetToDbObject(cs);
|
||||
if (dbc == null) {
|
||||
throw new DataAccessResourceFailureException("Expected to find a collection named '" + collection +"'. It was not found, so ChangeSet can't be persisted.");
|
||||
}
|
||||
dbc.save(dbo);
|
||||
}
|
||||
@Autowired
|
||||
private MongoTemplate mongoTemplate;
|
||||
|
||||
return 0L;
|
||||
}
|
||||
@Autowired
|
||||
private ConversionService conversionService;
|
||||
|
||||
private DBObject mapChangeSetToDbObject(ChangeSet cs) {
|
||||
BasicDBObject dbo = new BasicDBObject();
|
||||
for (String property : cs.getValues().keySet()) {
|
||||
dbo.put(property, cs.getValues().get(property));
|
||||
}
|
||||
return dbo;
|
||||
}
|
||||
@Override
|
||||
public void getPersistentState(Class<? extends ChangeSetBacked> entityClass, Object id, ChangeSet changeSet)
|
||||
throws DataAccessException, NotFoundException {
|
||||
String collection = ClassUtils.getShortName(entityClass).toLowerCase();
|
||||
DBObject q = new BasicDBObject();
|
||||
q.put("_id", id);
|
||||
try {
|
||||
DBObject dbo = mongoTemplate.getCollection(collection).findOne(q);
|
||||
log.debug("Found DBObject: " + dbo);
|
||||
if (dbo == null) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
String classShortName = ClassUtils.getShortName(entityClass);
|
||||
for (Object property : dbo.toMap().keySet()) {
|
||||
String propertyKey = (String) property;
|
||||
String propertyName = propertyKey.startsWith(classShortName) ? propertyKey.substring(propertyKey.indexOf(classShortName)
|
||||
+ classShortName.length() + 1) : propertyKey;
|
||||
// System.err.println("Mongo persisted property [" + propertyName + "] :: " + propertyKey + " = " + dbo.get(propertyKey));
|
||||
if (propertyKey.startsWith("_")) {
|
||||
// Id or class
|
||||
changeSet.set(propertyKey, dbo.get(propertyKey));
|
||||
} else {
|
||||
//throw new IllegalStateException("Unknown property [" + propertyName + "] found in MongoDB store");
|
||||
changeSet.set(propertyKey, dbo.get(propertyKey));
|
||||
}
|
||||
}
|
||||
} catch (MongoException ex) {
|
||||
throw new DataAccessResourceFailureException("Can't read from Mongo", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPersistentId(Class<? extends ChangeSetBacked> entityClass,
|
||||
ChangeSet cs) throws DataAccessException {
|
||||
log.debug("getPersistentId called on " + entityClass);
|
||||
if (cs == null) {
|
||||
return null;
|
||||
}
|
||||
if (cs.getValues().get(ChangeSetPersister.ID_KEY) == null) {
|
||||
// Not yet persistent
|
||||
return null;
|
||||
}
|
||||
Object o = cs.getValues().get(ChangeSetPersister.ID_KEY);
|
||||
return o;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object persistState(Class<? extends ChangeSetBacked> entityClass, ChangeSet cs) throws DataAccessException {
|
||||
log.info("PERSIST::" + cs);
|
||||
cs.set(CLASS_KEY, entityClass.getName());
|
||||
String idstr = cs.get(ID_KEY, String.class, this.conversionService);
|
||||
Object id = null;
|
||||
if (idstr != null) {
|
||||
id = idstr;
|
||||
}
|
||||
if (id == null) {
|
||||
log.info("Flush: entity make persistent; data store will assign id");
|
||||
cs.set("_class", entityClass.getName());
|
||||
String collection = entityClass.getSimpleName().toLowerCase();
|
||||
DBCollection dbc = mongoTemplate.getCollection(collection);
|
||||
DBObject dbo = mapChangeSetToDbObject(cs);
|
||||
if (dbc == null) {
|
||||
dbc = mongoTemplate.createCollection(collection);
|
||||
}
|
||||
dbc.save(dbo);
|
||||
id = dbo.get(ID_KEY);
|
||||
log.info("Data store assigned id: " + id);
|
||||
} else {
|
||||
log.info("Flush: entity already persistent with id=" + id);
|
||||
String collection = entityClass.getName();
|
||||
DBCollection dbc = mongoTemplate.getCollection(collection);
|
||||
DBObject dbo = mapChangeSetToDbObject(cs);
|
||||
if (dbc == null) {
|
||||
throw new DataAccessResourceFailureException("Expected to find a collection named '" + collection + "'. It was not found, so ChangeSet can't be persisted.");
|
||||
}
|
||||
dbc.save(dbo);
|
||||
}
|
||||
|
||||
return 0L;
|
||||
}
|
||||
|
||||
private DBObject mapChangeSetToDbObject(ChangeSet cs) {
|
||||
BasicDBObject dbo = new BasicDBObject();
|
||||
for (String property : cs.getValues().keySet()) {
|
||||
dbo.put(property, cs.getValues().get(property));
|
||||
}
|
||||
return dbo;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import org.springframework.persistence.support.AbstractDeferredUpdateMixinFields
|
||||
|
||||
/**
|
||||
* Aspect to turn an object annotated with DocumentEntity into a document entity using Mongo.
|
||||
*
|
||||
*
|
||||
* @author Thomas Risberg
|
||||
*/
|
||||
public aspect MongoDocumentBacking extends AbstractDeferredUpdateMixinFields<DocumentEntity> {
|
||||
|
||||
@@ -13,69 +13,66 @@ import org.springframework.persistence.support.ChangeSetPersister.NotFoundExcept
|
||||
import org.springframework.persistence.support.EntityInstantiator;
|
||||
import org.springframework.persistence.support.HashMapChangeSet;
|
||||
|
||||
import com.mongodb.DB;
|
||||
|
||||
public class MongoEntityOperations extends OrderedEntityOperations<Object, ChangeSetBacked> {
|
||||
|
||||
@Autowired
|
||||
private MongoTemplate mongoTemplate;
|
||||
|
||||
private EntityInstantiator<ChangeSetBacked, ChangeSet> entityInstantiator;
|
||||
|
||||
private MongoChangeSetPersister changeSetPersister;
|
||||
@Autowired
|
||||
private MongoTemplate mongoTemplate;
|
||||
|
||||
public void setEntityInstantiator(EntityInstantiator<ChangeSetBacked, ChangeSet> entityInstantiator) {
|
||||
this.entityInstantiator = entityInstantiator;
|
||||
}
|
||||
private EntityInstantiator<ChangeSetBacked, ChangeSet> entityInstantiator;
|
||||
|
||||
@Autowired
|
||||
public void setChangeSetPersister(MongoChangeSetPersister changeSetPersister) {
|
||||
this.changeSetPersister = changeSetPersister;
|
||||
}
|
||||
private MongoChangeSetPersister changeSetPersister;
|
||||
|
||||
public void setEntityInstantiator(EntityInstantiator<ChangeSetBacked, ChangeSet> entityInstantiator) {
|
||||
this.entityInstantiator = entityInstantiator;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setChangeSetPersister(MongoChangeSetPersister changeSetPersister) {
|
||||
this.changeSetPersister = changeSetPersister;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean cacheInEntity() {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean cacheInEntity() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChangeSetBacked findEntity(Class<ChangeSetBacked> entityClass, Object key) throws DataAccessException {
|
||||
try {
|
||||
ChangeSet cs = new HashMapChangeSet();
|
||||
changeSetPersister.getPersistentState(entityClass, key, cs);
|
||||
return entityInstantiator.createEntityFromState(cs, entityClass);
|
||||
}
|
||||
catch (NotFoundException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public ChangeSetBacked findEntity(Class<ChangeSetBacked> entityClass, Object key) throws DataAccessException {
|
||||
try {
|
||||
ChangeSet cs = new HashMapChangeSet();
|
||||
changeSetPersister.getPersistentState(entityClass, key, cs);
|
||||
return entityInstantiator.createEntityFromState(cs, entityClass);
|
||||
} catch (NotFoundException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object findUniqueKey(ChangeSetBacked entity) throws DataAccessException {
|
||||
return entity.getId();
|
||||
}
|
||||
@Override
|
||||
public Object findUniqueKey(ChangeSetBacked entity) throws DataAccessException {
|
||||
return entity.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTransactional() {
|
||||
// TODO
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean isTransactional() {
|
||||
// TODO
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTransient(ChangeSetBacked entity) throws DataAccessException {
|
||||
return entity.getId() == null;
|
||||
}
|
||||
@Override
|
||||
public boolean isTransient(ChangeSetBacked entity) throws DataAccessException {
|
||||
return entity.getId() == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object makePersistent(Object owner, ChangeSetBacked entity, Field f, RelatedEntity fs) throws DataAccessException {
|
||||
changeSetPersister.persistState(entity.getClass(), entity.getChangeSet());
|
||||
return entity.getId();
|
||||
}
|
||||
@Override
|
||||
public Object makePersistent(Object owner, ChangeSetBacked entity, Field f, RelatedEntity fs) throws DataAccessException {
|
||||
changeSetPersister.persistState(entity.getClass(), entity.getChangeSet());
|
||||
return entity.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supports(Class<?> entityClass, RelatedEntity fs) {
|
||||
return entityClass.isAnnotationPresent(DocumentEntity.class);
|
||||
}
|
||||
@Override
|
||||
public boolean supports(Class<?> entityClass, RelatedEntity fs) {
|
||||
return entityClass.isAnnotationPresent(DocumentEntity.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.springframework.data.document.persistence;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
|
||||
import com.mongodb.*;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -17,122 +18,116 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.mongodb.DBCollection;
|
||||
import com.mongodb.DBCursor;
|
||||
import com.mongodb.DBObject;
|
||||
import com.mongodb.Mongo;
|
||||
import com.mongodb.MongoException;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = "classpath:/META-INF/spring/applicationContext.xml")
|
||||
public class CrossStoreMongoTests {
|
||||
|
||||
@Autowired
|
||||
private Mongo mongo;
|
||||
@Autowired
|
||||
private Mongo mongo;
|
||||
|
||||
@Autowired
|
||||
private MongoTemplate mongoTemplate;
|
||||
|
||||
private EntityManager entityManager;
|
||||
|
||||
private String colName = MongoPerson.class.getSimpleName().toLowerCase();
|
||||
@Autowired
|
||||
private MongoTemplate mongoTemplate;
|
||||
|
||||
|
||||
@PersistenceContext
|
||||
public void setEntityManager(EntityManager entityManager) {
|
||||
this.entityManager = entityManager;
|
||||
private EntityManager entityManager;
|
||||
|
||||
private String colName = MongoPerson.class.getSimpleName().toLowerCase();
|
||||
|
||||
|
||||
@PersistenceContext
|
||||
public void setEntityManager(EntityManager entityManager) {
|
||||
this.entityManager = entityManager;
|
||||
}
|
||||
|
||||
private void clearData(String collectionName) {
|
||||
DBCollection col = this.mongoTemplate.getCollection(collectionName);
|
||||
if (col != null) {
|
||||
this.mongoTemplate.dropCollection(collectionName);
|
||||
}
|
||||
}
|
||||
|
||||
private void clearData(String collectionName) {
|
||||
DBCollection col = this.mongoTemplate.getCollection(collectionName);
|
||||
if (col != null) {
|
||||
this.mongoTemplate.dropCollection(collectionName);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
@Rollback(false)
|
||||
public void testUserConstructor() {
|
||||
clearData(colName);
|
||||
int age = 33;
|
||||
MongoPerson p = new MongoPerson("Thomas", age);
|
||||
Assert.assertEquals(age, p.getAge());
|
||||
p.birthday();
|
||||
Assert.assertEquals(1 + age, p.getAge());
|
||||
}
|
||||
@Test
|
||||
@Transactional
|
||||
@Rollback(false)
|
||||
public void testUserConstructor() {
|
||||
clearData(colName);
|
||||
int age = 33;
|
||||
MongoPerson p = new MongoPerson("Thomas", age);
|
||||
Assert.assertEquals(age, p.getAge());
|
||||
p.birthday();
|
||||
Assert.assertEquals(1 + age, p.getAge());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
public void testInstantiatedFinder() throws MongoException {
|
||||
DBCollection col = this.mongoTemplate.getCollection(colName);
|
||||
DBObject dbo = col.findOne();
|
||||
Object _id = dbo.get("_id");
|
||||
MongoPerson found = MongoPerson.findPerson(_id);
|
||||
Assert.assertNotNull(found);
|
||||
Assert.assertEquals(_id, found.getId());
|
||||
System.out.println("Loaded MongoPerson data: " + found);
|
||||
}
|
||||
@Test
|
||||
@Transactional
|
||||
public void testInstantiatedFinder() throws MongoException {
|
||||
DBCollection col = this.mongoTemplate.getCollection(colName);
|
||||
DBObject dbo = col.findOne();
|
||||
Object _id = dbo.get("_id");
|
||||
MongoPerson found = MongoPerson.findPerson(_id);
|
||||
Assert.assertNotNull(found);
|
||||
Assert.assertEquals(_id, found.getId());
|
||||
System.out.println("Loaded MongoPerson data: " + found);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
@Rollback(false)
|
||||
public void testCreateMongoToJpaEntityRelationship() {
|
||||
clearData(colName);
|
||||
Account a = new Account();
|
||||
a.setName("My Account");
|
||||
a.setFriendlyName("My Test Acct.");
|
||||
a.setBalance(123.45F);
|
||||
a.setId(2L);
|
||||
MongoPerson p = new MongoPerson("Jack", 22);
|
||||
entityManager.persist(a);
|
||||
p.setAccount(a);
|
||||
}
|
||||
@Test
|
||||
@Transactional
|
||||
@Rollback(false)
|
||||
public void testCreateMongoToJpaEntityRelationship() {
|
||||
clearData(colName);
|
||||
Account a = new Account();
|
||||
a.setName("My Account");
|
||||
a.setFriendlyName("My Test Acct.");
|
||||
a.setBalance(123.45F);
|
||||
a.setId(2L);
|
||||
MongoPerson p = new MongoPerson("Jack", 22);
|
||||
entityManager.persist(a);
|
||||
p.setAccount(a);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
public void testReadMongoToJpaEntityRelationship() {
|
||||
DBCollection col = this.mongoTemplate.getCollection(colName);
|
||||
DBCursor dbc = col.find();
|
||||
Object _id = null;
|
||||
for (DBObject dbo : dbc) {
|
||||
System.out.println(dbo);
|
||||
if ("Jack".equals(dbo.get("name"))) {
|
||||
_id = dbo.get("_id");
|
||||
break;
|
||||
}
|
||||
}
|
||||
System.out.println(_id);
|
||||
MongoPerson found = MongoPerson.findPerson(_id);
|
||||
System.out.println(found);
|
||||
if (found != null)
|
||||
System.out.println(found.getAccount());
|
||||
}
|
||||
@Test
|
||||
@Transactional
|
||||
public void testReadMongoToJpaEntityRelationship() {
|
||||
DBCollection col = this.mongoTemplate.getCollection(colName);
|
||||
DBCursor dbc = col.find();
|
||||
Object _id = null;
|
||||
for (DBObject dbo : dbc) {
|
||||
System.out.println(dbo);
|
||||
if ("Jack".equals(dbo.get("name"))) {
|
||||
_id = dbo.get("_id");
|
||||
break;
|
||||
}
|
||||
}
|
||||
System.out.println(_id);
|
||||
MongoPerson found = MongoPerson.findPerson(_id);
|
||||
System.out.println(found);
|
||||
if (found != null)
|
||||
System.out.println(found.getAccount());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
@Rollback(false)
|
||||
public void testCreateJpaToMongoEntityRelationship() {
|
||||
clearData("resume");
|
||||
Person p = new Person("Thomas", 20);
|
||||
Resume r = new Resume();
|
||||
r.addEducation("Skanstulls High School, 1975");
|
||||
r.addEducation("Univ. of Stockholm, 1980");
|
||||
r.addJob("DiMark, DBA, 1990-2000");
|
||||
r.addJob("VMware, Developer, 2007-");
|
||||
p.setResume(r);
|
||||
p.setId(1L);
|
||||
entityManager.persist(p);
|
||||
}
|
||||
@Test
|
||||
@Transactional
|
||||
@Rollback(false)
|
||||
public void testCreateJpaToMongoEntityRelationship() {
|
||||
clearData("resume");
|
||||
Person p = new Person("Thomas", 20);
|
||||
Resume r = new Resume();
|
||||
r.addEducation("Skanstulls High School, 1975");
|
||||
r.addEducation("Univ. of Stockholm, 1980");
|
||||
r.addJob("DiMark, DBA, 1990-2000");
|
||||
r.addJob("VMware, Developer, 2007-");
|
||||
p.setResume(r);
|
||||
p.setId(1L);
|
||||
entityManager.persist(p);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
public void testReadJpaToMongoEntityRelationship() {
|
||||
Person found = entityManager.find(Person.class, 1L);
|
||||
System.out.println(found);
|
||||
@Test
|
||||
@Transactional
|
||||
public void testReadJpaToMongoEntityRelationship() {
|
||||
Person found = entityManager.find(Person.class, 1L);
|
||||
System.out.println(found);
|
||||
// TODO: This part isn't working yet - there is no reference to the Momgo _id stored in the db
|
||||
// if (found != null)
|
||||
// System.out.println(found.getResume());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,61 +5,62 @@ import javax.persistence.Id;
|
||||
|
||||
@Entity
|
||||
public class Account {
|
||||
|
||||
@Id private Long id;
|
||||
|
||||
private String name;
|
||||
@Id
|
||||
private Long id;
|
||||
|
||||
private float balance;
|
||||
private String name;
|
||||
|
||||
private String friendlyName;
|
||||
private float balance;
|
||||
|
||||
private String whatever;
|
||||
private String friendlyName;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
private String whatever;
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public float getBalance() {
|
||||
return balance;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setBalance(float balance) {
|
||||
this.balance = balance;
|
||||
}
|
||||
public float getBalance() {
|
||||
return balance;
|
||||
}
|
||||
|
||||
public String getFriendlyName() {
|
||||
return friendlyName;
|
||||
}
|
||||
public void setBalance(float balance) {
|
||||
this.balance = balance;
|
||||
}
|
||||
|
||||
public void setFriendlyName(String friendlyName) {
|
||||
this.friendlyName = friendlyName;
|
||||
}
|
||||
public String getFriendlyName() {
|
||||
return friendlyName;
|
||||
}
|
||||
|
||||
public String getWhatever() {
|
||||
return whatever;
|
||||
}
|
||||
public void setFriendlyName(String friendlyName) {
|
||||
this.friendlyName = friendlyName;
|
||||
}
|
||||
|
||||
public void setWhatever(String whatever) {
|
||||
this.whatever = whatever;
|
||||
}
|
||||
public String getWhatever() {
|
||||
return whatever;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Account [id=" + id + ", name=" + name + ", balance=" + balance
|
||||
+ ", friendlyName=" + friendlyName + "]";
|
||||
}
|
||||
public void setWhatever(String whatever) {
|
||||
this.whatever = whatever;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Account [id=" + id + ", name=" + name + ", balance=" + balance
|
||||
+ ", friendlyName=" + friendlyName + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,62 +2,62 @@ package org.springframework.persistence.document.test;
|
||||
|
||||
import org.springframework.persistence.RelatedEntity;
|
||||
import org.springframework.persistence.document.DocumentEntity;
|
||||
|
||||
|
||||
@DocumentEntity
|
||||
public class MongoPerson {
|
||||
|
||||
// TODO only public because of AspectJ bug
|
||||
public String name;
|
||||
|
||||
public int age;
|
||||
|
||||
public java.util.Date birthDate;
|
||||
|
||||
// TODO only public to check weaving bug--
|
||||
// seems to work whereas private didn't
|
||||
@RelatedEntity
|
||||
public Account account;
|
||||
// TODO only public because of AspectJ bug
|
||||
public String name;
|
||||
|
||||
public MongoPerson(String name, int age) {
|
||||
this.name = name;
|
||||
this.age = age;
|
||||
this.birthDate = new java.util.Date();
|
||||
}
|
||||
public int age;
|
||||
|
||||
public void birthday() {
|
||||
++age;
|
||||
}
|
||||
public java.util.Date birthDate;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
// TODO only public to check weaving bug--
|
||||
// seems to work whereas private didn't
|
||||
@RelatedEntity
|
||||
public Account account;
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public MongoPerson(String name, int age) {
|
||||
this.name = name;
|
||||
this.age = age;
|
||||
this.birthDate = new java.util.Date();
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
public void birthday() {
|
||||
++age;
|
||||
}
|
||||
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public java.util.Date getBirthDate() {
|
||||
return birthDate;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setBirthDate(java.util.Date birthDate) {
|
||||
this.birthDate = birthDate;
|
||||
}
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public Account getAccount() {
|
||||
return account;
|
||||
}
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public void setAccount(Account account) {
|
||||
this.account = account;
|
||||
}
|
||||
public java.util.Date getBirthDate() {
|
||||
return birthDate;
|
||||
}
|
||||
|
||||
public void setBirthDate(java.util.Date birthDate) {
|
||||
this.birthDate = birthDate;
|
||||
}
|
||||
|
||||
public Account getAccount() {
|
||||
return account;
|
||||
}
|
||||
|
||||
public void setAccount(Account account) {
|
||||
this.account = account;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,58 +3,52 @@ package org.springframework.persistence.document.test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Configurable;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.persistence.support.ChangeSet;
|
||||
import org.springframework.persistence.support.ChangeSetBacked;
|
||||
import org.springframework.persistence.support.ChangeSetConfiguration;
|
||||
import org.springframework.persistence.support.ChangeSetPersister;
|
||||
import org.springframework.persistence.support.ChangeSetSynchronizer;
|
||||
import org.springframework.persistence.support.HashMapChangeSet;
|
||||
import org.springframework.persistence.support.*;
|
||||
import org.springframework.persistence.support.ChangeSetPersister.NotFoundException;
|
||||
|
||||
/**
|
||||
* EXAMPLE OF CODE THAT SHOULD BE GENERATED BY ROO BESIDES EACH MONGOENTITY CLASS
|
||||
*
|
||||
*
|
||||
* Note: Combines X_Roo_Entity with X_Roo_Finder, as
|
||||
* we need only a single aspect for entities.
|
||||
*
|
||||
*
|
||||
* @author Thomas Risberg
|
||||
*
|
||||
*/
|
||||
privileged aspect MongoPerson_Roo_Mongo_Entity {
|
||||
|
||||
private static ChangeSetPersister<Object> changeSetPersister() {
|
||||
return new MongoConfigurationHolder().changeSetConfig.getChangeSetPersister();
|
||||
}
|
||||
|
||||
private static ChangeSetSynchronizer<ChangeSetBacked> changeSetManager() {
|
||||
return new MongoConfigurationHolder().changeSetConfig.getChangeSetManager();
|
||||
}
|
||||
|
||||
@Configurable
|
||||
public static class MongoConfigurationHolder {
|
||||
@Autowired
|
||||
@Qualifier("mongoChangeSetConfiguration")
|
||||
public ChangeSetConfiguration<Object> changeSetConfig;
|
||||
}
|
||||
private static ChangeSetPersister<Object> changeSetPersister() {
|
||||
return new MongoConfigurationHolder().changeSetConfig.getChangeSetPersister();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add constructor that takes ChangeSet.
|
||||
* @param ChangeSet
|
||||
*/
|
||||
public MongoPerson.new(ChangeSet cs) {
|
||||
super();
|
||||
setChangeSet(cs);
|
||||
}
|
||||
private static ChangeSetSynchronizer<ChangeSetBacked> changeSetManager() {
|
||||
return new MongoConfigurationHolder().changeSetConfig.getChangeSetManager();
|
||||
}
|
||||
|
||||
public static MongoPerson MongoPerson.findPerson(Object id) {
|
||||
ChangeSet rv = new HashMapChangeSet();
|
||||
try {
|
||||
changeSetPersister().getPersistentState(MongoPerson.class, id, rv);
|
||||
return new MongoPerson(rv);
|
||||
}
|
||||
catch (NotFoundException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@Configurable
|
||||
public static class MongoConfigurationHolder {
|
||||
@Autowired
|
||||
@Qualifier("mongoChangeSetConfiguration")
|
||||
public ChangeSetConfiguration<Object> changeSetConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add constructor that takes ChangeSet.
|
||||
* @param ChangeSet
|
||||
*/
|
||||
public MongoPerson.new(ChangeSet cs) {
|
||||
super();
|
||||
setChangeSet(cs);
|
||||
}
|
||||
|
||||
public static MongoPerson MongoPerson.findPerson(Object id) {
|
||||
ChangeSet rv = new HashMapChangeSet();
|
||||
try {
|
||||
changeSetPersister().getPersistentState(MongoPerson.class, id, rv);
|
||||
return new MongoPerson(rv);
|
||||
} catch (NotFoundException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,73 +4,74 @@ import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
|
||||
import org.springframework.persistence.RelatedEntity;
|
||||
|
||||
|
||||
@Entity
|
||||
public class Person {
|
||||
|
||||
@Id Long id;
|
||||
|
||||
private String name;
|
||||
|
||||
private int age;
|
||||
|
||||
private java.util.Date birthDate;
|
||||
|
||||
// @Document // need to decide what the annotation here should be
|
||||
@RelatedEntity
|
||||
public Resume resume;
|
||||
@Id
|
||||
Long id;
|
||||
|
||||
public Person() {
|
||||
}
|
||||
private String name;
|
||||
|
||||
public Person(String name, int age) {
|
||||
this.name = name;
|
||||
this.age = age;
|
||||
this.birthDate = new java.util.Date();
|
||||
}
|
||||
private int age;
|
||||
|
||||
public void birthday() {
|
||||
++age;
|
||||
}
|
||||
private java.util.Date birthDate;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
// @Document // need to decide what the annotation here should be
|
||||
@RelatedEntity
|
||||
public Resume resume;
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
public Person() {
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public Person(String name, int age) {
|
||||
this.name = name;
|
||||
this.age = age;
|
||||
this.birthDate = new java.util.Date();
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public void birthday() {
|
||||
++age;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public java.util.Date getBirthDate() {
|
||||
return birthDate;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setBirthDate(java.util.Date birthDate) {
|
||||
this.birthDate = birthDate;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Resume getResume() {
|
||||
return resume;
|
||||
}
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public void setResume(Resume resume) {
|
||||
this.resume = resume;
|
||||
}
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public java.util.Date getBirthDate() {
|
||||
return birthDate;
|
||||
}
|
||||
|
||||
public void setBirthDate(java.util.Date birthDate) {
|
||||
this.birthDate = birthDate;
|
||||
}
|
||||
|
||||
public Resume getResume() {
|
||||
return resume;
|
||||
}
|
||||
|
||||
public void setResume(Resume resume) {
|
||||
this.resume = resume;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,29 +5,29 @@ import org.springframework.persistence.document.DocumentEntity;
|
||||
@DocumentEntity
|
||||
public class Resume {
|
||||
|
||||
private String education = "";
|
||||
|
||||
private String jobs = "";
|
||||
private String education = "";
|
||||
|
||||
public String getEducation() {
|
||||
return education;
|
||||
}
|
||||
private String jobs = "";
|
||||
|
||||
public void addEducation(String education) {
|
||||
this.education = this.education + (this.education.length() > 0 ? "; " : "") + education;
|
||||
}
|
||||
public String getEducation() {
|
||||
return education;
|
||||
}
|
||||
|
||||
public String getJobs() {
|
||||
return jobs;
|
||||
}
|
||||
public void addEducation(String education) {
|
||||
this.education = this.education + (this.education.length() > 0 ? "; " : "") + education;
|
||||
}
|
||||
|
||||
public void addJob(String job) {
|
||||
this.jobs = this.jobs + (this.jobs.length() > 0 ? "; " : "") + job;
|
||||
}
|
||||
public String getJobs() {
|
||||
return jobs;
|
||||
}
|
||||
|
||||
public void addJob(String job) {
|
||||
this.jobs = this.jobs + (this.jobs.length() > 0 ? "; " : "") + job;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Resume [education=" + education + ", jobs=" + jobs + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Resume [education=" + education + ", jobs=" + jobs + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
|
||||
<persistence-unit name="test" transaction-type="RESOURCE_LOCAL">
|
||||
<provider>org.hibernate.ejb.HibernatePersistence</provider>
|
||||
<class>org.springframework.persistence.document.test.Account</class>
|
||||
<properties>
|
||||
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
|
||||
<!--value='create' to build a new database on each run; value='update' to modify an existing database; value='create-drop' means the same as 'create' but also drops tables when Hibernate closes; value='validate' makes no changes to the database-->
|
||||
<property name="hibernate.hbm2ddl.auto" value="update"/>
|
||||
<property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.ImprovedNamingStrategy"/>
|
||||
</properties>
|
||||
</persistence-unit>
|
||||
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
version="2.0"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
|
||||
<persistence-unit name="test" transaction-type="RESOURCE_LOCAL">
|
||||
<provider>org.hibernate.ejb.HibernatePersistence</provider>
|
||||
<class>org.springframework.persistence.document.test.Account</class>
|
||||
<properties>
|
||||
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
|
||||
<!--value='create' to build a new database on each run; value='update' to modify an existing database; value='create-drop' means the same as 'create' but also drops tables when Hibernate closes; value='validate' makes no changes to the database-->
|
||||
<property name="hibernate.hbm2ddl.auto" value="update"/>
|
||||
<property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.ImprovedNamingStrategy"/>
|
||||
</properties>
|
||||
</persistence-unit>
|
||||
</persistence>
|
||||
|
||||
@@ -1,98 +1,99 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:tx="http://www.springframework.org/schema/tx"
|
||||
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:tx="http://www.springframework.org/schema/tx"
|
||||
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
|
||||
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
|
||||
|
||||
<context:spring-configured/>
|
||||
<context:spring-configured/>
|
||||
|
||||
<context:component-scan base-package="org.springframework.persistence.test">
|
||||
<context:exclude-filter expression=".*_Roo_.*" type="regex"/>
|
||||
<context:exclude-filter expression="org.springframework.stereotype.Controller" type="annotation"/>
|
||||
</context:component-scan>
|
||||
<context:component-scan base-package="org.springframework.persistence.test">
|
||||
<context:exclude-filter expression=".*_Roo_.*" type="regex"/>
|
||||
<context:exclude-filter expression="org.springframework.stereotype.Controller" type="annotation"/>
|
||||
</context:component-scan>
|
||||
|
||||
<!-- Store spanning config -->
|
||||
|
||||
<bean class="org.springframework.persistence.StoreSpanning"
|
||||
factory-method="aspectOf" >
|
||||
<property name="mappingValidator">
|
||||
<bean class="org.springframework.persistence.support.SimpleMappingValidator" />
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="entityOperationsLocator" class="org.springframework.persistence.ChainingEntityOperationsLocator" />
|
||||
|
||||
<bean class="org.springframework.persistence.ChainingForeignStoreKeyManagerLocator" />
|
||||
|
||||
<bean class="org.springframework.persistence.PresentKeyForeignStoreKeyManager" autowire="constructor" />
|
||||
|
||||
<bean class="org.springframework.persistence.GeneratedFieldForeignStoreKeyManager" />
|
||||
<!-- Store spanning config -->
|
||||
|
||||
<bean class="org.springframework.persistence.document.MongoEntityOperations" >
|
||||
<property name="order" value="5" />
|
||||
<property name="entityInstantiator">
|
||||
<bean class="org.springframework.persistence.support.ChangeSetConstructorEntityInstantiator" />
|
||||
</property>
|
||||
<property name="changeSetPersister" ref="mongoChangeSetPersister" />
|
||||
</bean>
|
||||
<bean class="org.springframework.persistence.StoreSpanning"
|
||||
factory-method="aspectOf">
|
||||
<property name="mappingValidator">
|
||||
<bean class="org.springframework.persistence.support.SimpleMappingValidator"/>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean class="org.springframework.persistence.EntityManagerJpaEntityOperations" />
|
||||
<bean id="entityOperationsLocator" class="org.springframework.persistence.ChainingEntityOperationsLocator"/>
|
||||
|
||||
<bean class="org.springframework.persistence.support.ChangeSetForeignStoreKeyManager">
|
||||
<property name="fieldDelimiter" value="#"/>
|
||||
</bean>
|
||||
<bean class="org.springframework.persistence.ChainingForeignStoreKeyManagerLocator"/>
|
||||
|
||||
<!-- Mongo config -->
|
||||
<bean id="mongo" class="org.springframework.data.document.mongodb.MongoFactoryBean">
|
||||
<property name="host" value="localhost" />
|
||||
<property name="port" value="27017" />
|
||||
</bean>
|
||||
<bean class="org.springframework.persistence.PresentKeyForeignStoreKeyManager" autowire="constructor"/>
|
||||
|
||||
<bean id="mongoTemplate" class="org.springframework.data.document.mongodb.MongoTemplate">
|
||||
<constructor-arg name="mongo" ref="mongo" />
|
||||
<constructor-arg name="databaseName" value="test" />
|
||||
</bean>
|
||||
|
||||
<bean class="org.springframework.data.document.mongodb.MongoExceptionTranslator" />
|
||||
<bean class="org.springframework.persistence.GeneratedFieldForeignStoreKeyManager"/>
|
||||
|
||||
<!-- Mongo aspect config -->
|
||||
<bean class="org.springframework.persistence.document.MongoDocumentBacking"
|
||||
factory-method="aspectOf">
|
||||
<property name="changeSetConfiguration" ref="mongoChangeSetConfiguration"/>
|
||||
</bean>
|
||||
<bean id ="mongoChangeSetPersister" class="org.springframework.persistence.document.MongoChangeSetPersister" />
|
||||
<bean id="mongoChangeSetSynchronizer" class="org.springframework.persistence.support.SimpleReflectiveChangeSetSynchronizer" />
|
||||
<bean id="mongoChangeSetConfiguration" class="org.springframework.persistence.support.ChangeSetConfiguration">
|
||||
<property name="changeSetPersister" ref="mongoChangeSetPersister"/>
|
||||
<property name="changeSetManager" ref="mongoChangeSetSynchronizer"/>
|
||||
</bean>
|
||||
<!-- Needed for ChangeSet persistence -->
|
||||
<bean id="conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean" />
|
||||
<bean class="org.springframework.persistence.document.MongoEntityOperations">
|
||||
<property name="order" value="5"/>
|
||||
<property name="entityInstantiator">
|
||||
<bean class="org.springframework.persistence.support.ChangeSetConstructorEntityInstantiator"/>
|
||||
</property>
|
||||
<property name="changeSetPersister" ref="mongoChangeSetPersister"/>
|
||||
</bean>
|
||||
|
||||
<jdbc:embedded-database id="dataSource" type="HSQL">
|
||||
</jdbc:embedded-database>
|
||||
|
||||
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager" >
|
||||
<property name="entityManagerFactory" ref="entityManagerFactory"/>
|
||||
</bean>
|
||||
<bean class="org.springframework.persistence.EntityManagerJpaEntityOperations"/>
|
||||
|
||||
<tx:annotation-driven mode="aspectj" transaction-manager="transactionManager"/>
|
||||
|
||||
<bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="entityManagerFactory">
|
||||
<property name="persistenceUnitName" value="test"/>
|
||||
<property name="dataSource" ref="dataSource"/>
|
||||
<property name="jpaVendorAdapter">
|
||||
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
|
||||
<property name="showSql" value="true"/>
|
||||
<property name="generateDdl" value="true"/>
|
||||
<property name="databasePlatform" value="org.hibernate.dialect.HSQLDialect"/>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
<bean class="org.springframework.persistence.support.ChangeSetForeignStoreKeyManager">
|
||||
<property name="fieldDelimiter" value="#"/>
|
||||
</bean>
|
||||
|
||||
<!-- Mongo config -->
|
||||
<bean id="mongo" class="org.springframework.data.document.mongodb.MongoFactoryBean">
|
||||
<property name="host" value="localhost"/>
|
||||
<property name="port" value="27017"/>
|
||||
</bean>
|
||||
|
||||
<bean id="mongoTemplate" class="org.springframework.data.document.mongodb.MongoTemplate">
|
||||
<constructor-arg name="mongo" ref="mongo"/>
|
||||
<constructor-arg name="databaseName" value="test"/>
|
||||
</bean>
|
||||
|
||||
<bean class="org.springframework.data.document.mongodb.MongoExceptionTranslator"/>
|
||||
|
||||
<!-- Mongo aspect config -->
|
||||
<bean class="org.springframework.persistence.document.MongoDocumentBacking"
|
||||
factory-method="aspectOf">
|
||||
<property name="changeSetConfiguration" ref="mongoChangeSetConfiguration"/>
|
||||
</bean>
|
||||
<bean id="mongoChangeSetPersister" class="org.springframework.persistence.document.MongoChangeSetPersister"/>
|
||||
<bean id="mongoChangeSetSynchronizer"
|
||||
class="org.springframework.persistence.support.SimpleReflectiveChangeSetSynchronizer"/>
|
||||
<bean id="mongoChangeSetConfiguration" class="org.springframework.persistence.support.ChangeSetConfiguration">
|
||||
<property name="changeSetPersister" ref="mongoChangeSetPersister"/>
|
||||
<property name="changeSetManager" ref="mongoChangeSetSynchronizer"/>
|
||||
</bean>
|
||||
<!-- Needed for ChangeSet persistence -->
|
||||
<bean id="conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean"/>
|
||||
|
||||
<jdbc:embedded-database id="dataSource" type="HSQL">
|
||||
</jdbc:embedded-database>
|
||||
|
||||
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
|
||||
<property name="entityManagerFactory" ref="entityManagerFactory"/>
|
||||
</bean>
|
||||
|
||||
<tx:annotation-driven mode="aspectj" transaction-manager="transactionManager"/>
|
||||
|
||||
<bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="entityManagerFactory">
|
||||
<property name="persistenceUnitName" value="test"/>
|
||||
<property name="dataSource" ref="dataSource"/>
|
||||
<property name="jpaVendorAdapter">
|
||||
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
|
||||
<property name="showSql" value="true"/>
|
||||
<property name="generateDdl" value="true"/>
|
||||
<property name="databasePlatform" value="org.hibernate.dialect.HSQLDialect"/>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
|
||||
Reference in New Issue
Block a user