added new cross-store module
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
package org.springframework.persistence.document;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Annotation to denote an object that should be transparently persisted
|
||||
* using MongoDB
|
||||
*
|
||||
* @author Thomas Risberg
|
||||
*/
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
public @interface DocumentEntity {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package org.springframework.data.document.persistence;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
|
||||
@Entity
|
||||
public class Account {
|
||||
|
||||
private String name;
|
||||
|
||||
private float balance;
|
||||
|
||||
private String friendlyName;
|
||||
|
||||
private String whatever;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public float getBalance() {
|
||||
return balance;
|
||||
}
|
||||
|
||||
public void setBalance(float balance) {
|
||||
this.balance = balance;
|
||||
}
|
||||
|
||||
public String getFriendlyName() {
|
||||
return friendlyName;
|
||||
}
|
||||
|
||||
public void setFriendlyName(String friendlyName) {
|
||||
this.friendlyName = friendlyName;
|
||||
}
|
||||
|
||||
public String getWhatever() {
|
||||
return whatever;
|
||||
}
|
||||
|
||||
public void setWhatever(String whatever) {
|
||||
this.whatever = whatever;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package org.springframework.data.document.persistence;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.annotation.Rollback;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.mongodb.Mongo;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = "classpath:/META-INF/spring/applicationContext.xml")
|
||||
public class CrossStoreMongoTests {
|
||||
|
||||
@Autowired
|
||||
private Mongo mongo;
|
||||
|
||||
@Test
|
||||
// @Transactional
|
||||
// @Rollback(false)
|
||||
public void testUserConstructor() {
|
||||
int age = 33;
|
||||
MongoPerson p = new MongoPerson("Thomas", age);
|
||||
//Assert.assertEquals(p.getRedisValue().getString("RedisPerson.name"), p.getName());
|
||||
Assert.assertEquals(age, p.getAge());
|
||||
p.birthday();
|
||||
Assert.assertEquals(1 + age, p.getAge());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package org.springframework.data.document.persistence;
|
||||
|
||||
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;
|
||||
|
||||
public MongoPerson(String name, int age) {
|
||||
this.name = name;
|
||||
this.age = age;
|
||||
this.birthDate = new java.util.Date();
|
||||
}
|
||||
|
||||
public void birthday() {
|
||||
++age;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
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 Account getAccount() {
|
||||
return account;
|
||||
}
|
||||
|
||||
public void setAccount(Account account) {
|
||||
this.account = account;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
|
||||
|
||||
<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 ref="mongo" />
|
||||
<constructor-arg value="database" />
|
||||
<property name="defaultCollectionName" value="springdata" />
|
||||
</bean>
|
||||
|
||||
<bean class="org.springframework.data.document.mongodb.MongoExceptionTranslator" />
|
||||
|
||||
</beans>
|
||||
Reference in New Issue
Block a user