Browse Source

DATADOC-271 - Added license headers to cross-store files.

pull/1/head
Oliver Gierke 14 years ago
parent
commit
105e1da82b
  1. 15
      spring-data-mongodb-cross-store/src/main/java/org/springframework/data/mongodb/crossstore/DocumentBacked.java
  2. 15
      spring-data-mongodb-cross-store/src/main/java/org/springframework/data/mongodb/crossstore/MongoChangeSetPersister.java
  3. 15
      spring-data-mongodb-cross-store/src/main/java/org/springframework/data/mongodb/crossstore/MongoDocumentBacking.aj
  4. 5
      spring-data-mongodb-cross-store/src/main/java/org/springframework/data/mongodb/crossstore/RelatedDocument.java
  5. 243
      spring-data-mongodb-cross-store/src/test/java/org/springframework/data/mongodb/crossstore/CrossStoreMongoTests.java
  6. 15
      spring-data-mongodb-cross-store/src/test/java/org/springframework/data/mongodb/crossstore/test/Address.java
  7. 125
      spring-data-mongodb-cross-store/src/test/java/org/springframework/data/mongodb/crossstore/test/Person.java
  8. 67
      spring-data-mongodb-cross-store/src/test/java/org/springframework/data/mongodb/crossstore/test/Resume.java

15
spring-data-mongodb-cross-store/src/main/java/org/springframework/data/mongodb/crossstore/DocumentBacked.java

@ -1,3 +1,18 @@
/*
* Copyright 2011 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.data.mongodb.crossstore; package org.springframework.data.mongodb.crossstore;
import org.springframework.data.persistence.ChangeSetBacked; import org.springframework.data.persistence.ChangeSetBacked;

15
spring-data-mongodb-cross-store/src/main/java/org/springframework/data/mongodb/crossstore/MongoChangeSetPersister.java

@ -1,3 +1,18 @@
/*
* Copyright 2011 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.data.mongodb.crossstore; package org.springframework.data.mongodb.crossstore;
import javax.persistence.EntityManagerFactory; import javax.persistence.EntityManagerFactory;

15
spring-data-mongodb-cross-store/src/main/java/org/springframework/data/mongodb/crossstore/MongoDocumentBacking.aj

@ -1,3 +1,18 @@
/*
* Copyright 2011 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.data.mongodb.crossstore; package org.springframework.data.mongodb.crossstore;
import java.lang.reflect.Field; import java.lang.reflect.Field;

5
spring-data-mongodb-cross-store/src/main/java/org/springframework/data/mongodb/crossstore/RelatedDocument.java

@ -1,11 +1,11 @@
/* /*
* Copyright (c) 2011 by the original author(s). * Copyright 2011 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.data.mongodb.crossstore; package org.springframework.data.mongodb.crossstore;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;

243
spring-data-mongodb-cross-store/src/test/java/org/springframework/data/mongodb/crossstore/CrossStoreMongoTests.java

@ -1,3 +1,18 @@
/*
* Copyright 2011 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.data.mongodb.crossstore; package org.springframework.data.mongodb.crossstore;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
@ -27,128 +42,128 @@ import com.mongodb.DBObject;
@ContextConfiguration(locations = "classpath:/META-INF/spring/applicationContext.xml") @ContextConfiguration(locations = "classpath:/META-INF/spring/applicationContext.xml")
public class CrossStoreMongoTests { public class CrossStoreMongoTests {
@Autowired @Autowired
private MongoTemplate mongoTemplate; private MongoTemplate mongoTemplate;
private EntityManager entityManager; private EntityManager entityManager;
@Autowired @Autowired
private PlatformTransactionManager transactionManager; private PlatformTransactionManager transactionManager;
@PersistenceContext @PersistenceContext
public void setEntityManager(EntityManager entityManager) { public void setEntityManager(EntityManager entityManager) {
this.entityManager = entityManager; this.entityManager = entityManager;
} }
private void clearData(String collectionName) { private void clearData(String collectionName) {
DBCollection col = this.mongoTemplate.getCollection(collectionName); DBCollection col = this.mongoTemplate.getCollection(collectionName);
if (col != null) { if (col != null) {
this.mongoTemplate.dropCollection(collectionName); this.mongoTemplate.dropCollection(collectionName);
} }
} }
@Test @Test
@Transactional @Transactional
@Rollback(false) @Rollback(false)
public void testCreateJpaToMongoEntityRelationship() { public void testCreateJpaToMongoEntityRelationship() {
clearData(Person.class.getName()); clearData(Person.class.getName());
Person p = new Person("Thomas", 20); Person p = new Person("Thomas", 20);
Address a = new Address(12, "MAin St.", "Boston", "MA", "02101"); Address a = new Address(12, "MAin St.", "Boston", "MA", "02101");
p.setAddress(a); p.setAddress(a);
Resume r = new Resume(); Resume r = new Resume();
r.addEducation("Skanstulls High School, 1975"); r.addEducation("Skanstulls High School, 1975");
r.addEducation("Univ. of Stockholm, 1980"); r.addEducation("Univ. of Stockholm, 1980");
r.addJob("DiMark, DBA, 1990-2000"); r.addJob("DiMark, DBA, 1990-2000");
r.addJob("VMware, Developer, 2007-"); r.addJob("VMware, Developer, 2007-");
p.setResume(r); p.setResume(r);
p.setId(1L); p.setId(1L);
entityManager.persist(p); entityManager.persist(p);
} }
@Test @Test
@Transactional @Transactional
@Rollback(false) @Rollback(false)
public void testReadJpaToMongoEntityRelationship() { public void testReadJpaToMongoEntityRelationship() {
Person found = entityManager.find(Person.class, 1L); Person found = entityManager.find(Person.class, 1L);
Assert.assertNotNull(found); Assert.assertNotNull(found);
Assert.assertEquals(Long.valueOf(1), found.getId()); Assert.assertEquals(Long.valueOf(1), found.getId());
Assert.assertNotNull(found); Assert.assertNotNull(found);
Assert.assertEquals(Long.valueOf(1), found.getId()); Assert.assertEquals(Long.valueOf(1), found.getId());
Assert.assertNotNull(found.getResume()); Assert.assertNotNull(found.getResume());
Assert.assertEquals("DiMark, DBA, 1990-2000" + "; " Assert.assertEquals("DiMark, DBA, 1990-2000" + "; "
+ "VMware, Developer, 2007-", found.getResume().getJobs()); + "VMware, Developer, 2007-", found.getResume().getJobs());
found.getResume().addJob("SpringDeveloper.com, Consultant, 2005-2006"); found.getResume().addJob("SpringDeveloper.com, Consultant, 2005-2006");
found.setAge(44); found.setAge(44);
} }
@Test @Test
@Transactional @Transactional
@Rollback(false) @Rollback(false)
public void testUpdatedJpaToMongoEntityRelationship() { public void testUpdatedJpaToMongoEntityRelationship() {
Person found = entityManager.find(Person.class, 1L); Person found = entityManager.find(Person.class, 1L);
Assert.assertNotNull(found); Assert.assertNotNull(found);
Assert.assertEquals(Long.valueOf(1), found.getId()); Assert.assertEquals(Long.valueOf(1), found.getId());
Assert.assertNotNull(found); Assert.assertNotNull(found);
Assert.assertEquals(Long.valueOf(1), found.getId()); Assert.assertEquals(Long.valueOf(1), found.getId());
Assert.assertNotNull(found.getResume()); Assert.assertNotNull(found.getResume());
Assert.assertEquals("DiMark, DBA, 1990-2000" + "; " Assert.assertEquals("DiMark, DBA, 1990-2000" + "; "
+ "VMware, Developer, 2007-" + "; " + "VMware, Developer, 2007-" + "; "
+ "SpringDeveloper.com, Consultant, 2005-2006", found.getResume().getJobs()); + "SpringDeveloper.com, Consultant, 2005-2006", found.getResume().getJobs());
} }
@Test @Test
public void testMergeJpaEntityWithMongoDocument() { public void testMergeJpaEntityWithMongoDocument() {
TransactionTemplate txTemplate = new TransactionTemplate(transactionManager); TransactionTemplate txTemplate = new TransactionTemplate(transactionManager);
final Person detached = entityManager.find(Person.class, 1L); final Person detached = entityManager.find(Person.class, 1L);
detached.getResume().addJob("TargetRx, Developer, 2000-2005"); detached.getResume().addJob("TargetRx, Developer, 2000-2005");
Person merged = txTemplate.execute(new TransactionCallback<Person>() { Person merged = txTemplate.execute(new TransactionCallback<Person>() {
public Person doInTransaction(TransactionStatus status) { public Person doInTransaction(TransactionStatus status) {
return entityManager.merge(detached); return entityManager.merge(detached);
} }
}); });
Assert.assertTrue(detached.getResume().getJobs().contains("TargetRx, Developer, 2000-2005")); Assert.assertTrue(detached.getResume().getJobs().contains("TargetRx, Developer, 2000-2005"));
Assert.assertTrue(merged.getResume().getJobs().contains("TargetRx, Developer, 2000-2005")); Assert.assertTrue(merged.getResume().getJobs().contains("TargetRx, Developer, 2000-2005"));
final Person updated = entityManager.find(Person.class, 1L); final Person updated = entityManager.find(Person.class, 1L);
Assert.assertTrue(updated.getResume().getJobs().contains("TargetRx, Developer, 2000-2005")); Assert.assertTrue(updated.getResume().getJobs().contains("TargetRx, Developer, 2000-2005"));
} }
@Test @Test
public void testRemoveJpaEntityWithMongoDocument() { public void testRemoveJpaEntityWithMongoDocument() {
TransactionTemplate txTemplate = new TransactionTemplate(transactionManager); TransactionTemplate txTemplate = new TransactionTemplate(transactionManager);
txTemplate.execute(new TransactionCallback<Person>() { txTemplate.execute(new TransactionCallback<Person>() {
public Person doInTransaction(TransactionStatus status) { public Person doInTransaction(TransactionStatus status) {
Person p2 = new Person("Thomas", 20); Person p2 = new Person("Thomas", 20);
Resume r2 = new Resume(); Resume r2 = new Resume();
r2.addEducation("Skanstulls High School, 1975"); r2.addEducation("Skanstulls High School, 1975");
r2.addJob("DiMark, DBA, 1990-2000"); r2.addJob("DiMark, DBA, 1990-2000");
p2.setResume(r2); p2.setResume(r2);
p2.setId(2L); p2.setId(2L);
entityManager.persist(p2); entityManager.persist(p2);
Person p3 = new Person("Thomas", 20); Person p3 = new Person("Thomas", 20);
Resume r3 = new Resume(); Resume r3 = new Resume();
r3.addEducation("Univ. of Stockholm, 1980"); r3.addEducation("Univ. of Stockholm, 1980");
r3.addJob("VMware, Developer, 2007-"); r3.addJob("VMware, Developer, 2007-");
p3.setResume(r3); p3.setResume(r3);
p3.setId(3L); p3.setId(3L);
entityManager.persist(p3); entityManager.persist(p3);
return null; return null;
} }
}); });
txTemplate.execute(new TransactionCallback<Person>() { txTemplate.execute(new TransactionCallback<Person>() {
public Person doInTransaction(TransactionStatus status) { public Person doInTransaction(TransactionStatus status) {
final Person found2 = entityManager.find(Person.class, 2L); final Person found2 = entityManager.find(Person.class, 2L);
entityManager.remove(found2); entityManager.remove(found2);
return null; return null;
} }
}); });
boolean weFound3 = false; boolean weFound3 = false;
for (DBObject dbo : this.mongoTemplate.getCollection(Person.class.getName()).find()) { for (DBObject dbo : this.mongoTemplate.getCollection(Person.class.getName()).find()) {
Assert.assertTrue(!dbo.get("_entity_id").equals(2L)); Assert.assertTrue(!dbo.get("_entity_id").equals(2L));
if (dbo.get("_entity_id").equals(3L)) { if (dbo.get("_entity_id").equals(3L)) {
weFound3 = true; weFound3 = true;
} }
} }
Assert.assertTrue(weFound3); Assert.assertTrue(weFound3);
} }
} }

15
spring-data-mongodb-cross-store/src/test/java/org/springframework/data/mongodb/crossstore/test/Address.java

@ -1,3 +1,18 @@
/*
* Copyright 2011 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.data.mongodb.crossstore.test; package org.springframework.data.mongodb.crossstore.test;
public class Address { public class Address {

125
spring-data-mongodb-cross-store/src/test/java/org/springframework/data/mongodb/crossstore/test/Person.java

@ -1,3 +1,18 @@
/*
* Copyright 2011 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.data.mongodb.crossstore.test; package org.springframework.data.mongodb.crossstore.test;
import javax.persistence.Entity; import javax.persistence.Entity;
@ -8,80 +23,80 @@ import org.springframework.data.mongodb.crossstore.RelatedDocument;
@Entity @Entity
public class Person { public class Person {
@Id @Id
Long id; Long id;
private String name; private String name;
private int age; private int age;
private java.util.Date birthDate; private java.util.Date birthDate;
@RelatedDocument @RelatedDocument
private Address address; private Address address;
@RelatedDocument @RelatedDocument
private Resume resume; private Resume resume;
public Person() { public Person() {
} }
public Person(String name, int age) { public Person(String name, int age) {
this.name = name; this.name = name;
this.age = age; this.age = age;
this.birthDate = new java.util.Date(); this.birthDate = new java.util.Date();
} }
public void birthday() { public void birthday() {
++age; ++age;
} }
public Long getId() { public Long getId() {
return id; return id;
} }
public void setId(Long id) { public void setId(Long id) {
this.id = id; this.id = id;
} }
public String getName() { public String getName() {
return name; return name;
} }
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
public int getAge() { public int getAge() {
return age; return age;
} }
public void setAge(int age) { public void setAge(int age) {
this.age = age; this.age = age;
} }
public java.util.Date getBirthDate() { public java.util.Date getBirthDate() {
return birthDate; return birthDate;
} }
public void setBirthDate(java.util.Date birthDate) { public void setBirthDate(java.util.Date birthDate) {
this.birthDate = birthDate; this.birthDate = birthDate;
} }
public Resume getResume() { public Resume getResume() {
return resume; return resume;
} }
public void setResume(Resume resume) { public void setResume(Resume resume) {
this.resume = resume; this.resume = resume;
} }
public Address getAddress() { public Address getAddress() {
return address; return address;
} }
public void setAddress(Address address) { public void setAddress(Address address) {
this.address = address; this.address = address;
} }
} }

67
spring-data-mongodb-cross-store/src/test/java/org/springframework/data/mongodb/crossstore/test/Resume.java

@ -1,3 +1,18 @@
/*
* Copyright 2011 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.data.mongodb.crossstore.test; package org.springframework.data.mongodb.crossstore.test;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@ -9,40 +24,40 @@ import org.springframework.data.mongodb.core.mapping.Document;
@Document @Document
public class Resume { public class Resume {
private static final Log LOGGER = LogFactory.getLog(Resume.class); private static final Log LOGGER = LogFactory.getLog(Resume.class);
@Id @Id
private ObjectId id; private ObjectId id;
private String education = ""; private String education = "";
private String jobs = ""; private String jobs = "";
public String getId() { public String getId() {
return id.toString(); return id.toString();
} }
public String getEducation() { public String getEducation() {
return education; return education;
} }
public void addEducation(String education) { public void addEducation(String education) {
LOGGER.debug("Adding education " + education); LOGGER.debug("Adding education " + education);
this.education = this.education + (this.education.length() > 0 ? "; " : "") + education; this.education = this.education + (this.education.length() > 0 ? "; " : "") + education;
} }
public String getJobs() { public String getJobs() {
return jobs; return jobs;
} }
public void addJob(String job) { public void addJob(String job) {
LOGGER.debug("Adding job " + job); LOGGER.debug("Adding job " + job);
this.jobs = this.jobs + (this.jobs.length() > 0 ? "; " : "") + job; this.jobs = this.jobs + (this.jobs.length() > 0 ? "; " : "") + job;
} }
@Override @Override
public String toString() { public String toString() {
return "Resume [education=" + education + ", jobs=" + jobs + "]"; return "Resume [education=" + education + ", jobs=" + jobs + "]";
} }
} }

Loading…
Cancel
Save