From 38d8529b8192a692e75298913132aecb67035ae3 Mon Sep 17 00:00:00 2001 From: Oliver Drotbohm Date: Thu, 4 Apr 2019 13:49:38 +0200 Subject: [PATCH] DATAMONGO-2248 - Removed cross-store module. Related tickets: DATAMONGO-1705. --- pom.xml | 2 - spring-data-mongodb-cross-store/aop.xml | 7 - spring-data-mongodb-cross-store/pom.xml | 148 ---------- .../mongodb/crossstore/DocumentBacked.java | 28 -- .../crossstore/MongoChangeSetPersister.java | 214 -------------- .../crossstore/MongoDocumentBacking.aj | 272 ------------------ .../mongodb/crossstore/RelatedDocument.java | 31 -- .../data/mongodb/crossstore/package-info.java | 5 - .../crossstore/CrossStoreMongoTests.java | 195 ------------- .../data/mongodb/crossstore/test/Address.java | 75 ----- .../data/mongodb/crossstore/test/Person.java | 102 ------- .../data/mongodb/crossstore/test/Resume.java | 63 ---- .../test/resources/META-INF/persistence.xml | 15 - .../META-INF/spring/applicationContext.xml | 72 ----- .../src/test/resources/logback.xml | 18 -- 15 files changed, 1247 deletions(-) delete mode 100644 spring-data-mongodb-cross-store/aop.xml delete mode 100644 spring-data-mongodb-cross-store/pom.xml delete mode 100644 spring-data-mongodb-cross-store/src/main/java/org/springframework/data/mongodb/crossstore/DocumentBacked.java delete mode 100644 spring-data-mongodb-cross-store/src/main/java/org/springframework/data/mongodb/crossstore/MongoChangeSetPersister.java delete mode 100644 spring-data-mongodb-cross-store/src/main/java/org/springframework/data/mongodb/crossstore/MongoDocumentBacking.aj delete mode 100644 spring-data-mongodb-cross-store/src/main/java/org/springframework/data/mongodb/crossstore/RelatedDocument.java delete mode 100644 spring-data-mongodb-cross-store/src/main/java/org/springframework/data/mongodb/crossstore/package-info.java delete mode 100644 spring-data-mongodb-cross-store/src/test/java/org/springframework/data/mongodb/crossstore/CrossStoreMongoTests.java delete mode 100644 spring-data-mongodb-cross-store/src/test/java/org/springframework/data/mongodb/crossstore/test/Address.java delete mode 100644 spring-data-mongodb-cross-store/src/test/java/org/springframework/data/mongodb/crossstore/test/Person.java delete mode 100644 spring-data-mongodb-cross-store/src/test/java/org/springframework/data/mongodb/crossstore/test/Resume.java delete mode 100644 spring-data-mongodb-cross-store/src/test/resources/META-INF/persistence.xml delete mode 100644 spring-data-mongodb-cross-store/src/test/resources/META-INF/spring/applicationContext.xml delete mode 100644 spring-data-mongodb-cross-store/src/test/resources/logback.xml diff --git a/pom.xml b/pom.xml index d00702b73..4e8ef5da1 100644 --- a/pom.xml +++ b/pom.xml @@ -20,7 +20,6 @@ spring-data-mongodb - spring-data-mongodb-cross-store spring-data-mongodb-distribution @@ -132,7 +131,6 @@ benchmarks spring-data-mongodb - spring-data-mongodb-cross-store spring-data-mongodb-distribution spring-data-mongodb-benchmarks diff --git a/spring-data-mongodb-cross-store/aop.xml b/spring-data-mongodb-cross-store/aop.xml deleted file mode 100644 index d11b1549e..000000000 --- a/spring-data-mongodb-cross-store/aop.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/spring-data-mongodb-cross-store/pom.xml b/spring-data-mongodb-cross-store/pom.xml deleted file mode 100644 index d3b7593d3..000000000 --- a/spring-data-mongodb-cross-store/pom.xml +++ /dev/null @@ -1,148 +0,0 @@ - - - - 4.0.0 - - - org.springframework.data - spring-data-mongodb-parent - 2.2.0.BUILD-SNAPSHOT - ../pom.xml - - - spring-data-mongodb-cross-store - Spring Data MongoDB - Cross-Store Support - - - 2.1.1 - 5.2.1.Final - spring.data.mongodb.cross.store - ${basedir}/.. - - - - - - - org.springframework - spring-beans - - - commons-logging - commons-logging - - - - - org.springframework - spring-tx - - - org.springframework - spring-aspects - - - org.springframework - spring-orm - - - - - org.springframework.data - spring-data-mongodb - 2.2.0.BUILD-SNAPSHOT - - - - - io.projectreactor - reactor-core - true - - - - org.aspectj - aspectjrt - ${aspectj} - - - - - org.eclipse.persistence - javax.persistence - ${jpa} - true - - - - - org.hibernate - hibernate-entitymanager - ${hibernate} - test - - - hsqldb - hsqldb - 1.8.0.10 - test - - - javax.validation - validation-api - ${validation} - test - - - org.hibernate - hibernate-validator - 5.2.4.Final - test - - - - - - - - org.codehaus.mojo - aspectj-maven-plugin - 1.6 - - - org.aspectj - aspectjrt - ${aspectj} - - - org.aspectj - aspectjtools - ${aspectj} - - - - - - compile - test-compile - - - - - true - - - org.springframework - spring-aspects - - - ${source.level} - ${source.level} - ${source.level} - aop.xml - - - - - - diff --git a/spring-data-mongodb-cross-store/src/main/java/org/springframework/data/mongodb/crossstore/DocumentBacked.java b/spring-data-mongodb-cross-store/src/main/java/org/springframework/data/mongodb/crossstore/DocumentBacked.java deleted file mode 100644 index d2d305e18..000000000 --- a/spring-data-mongodb-cross-store/src/main/java/org/springframework/data/mongodb/crossstore/DocumentBacked.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2011-2019 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 - * - * https://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; - -import org.springframework.data.crossstore.ChangeSetBacked; - -/** - * @author Thomas Risberg - * @author Oliver Gierke - * @deprecated will be removed without replacement. - */ -@Deprecated -public interface DocumentBacked extends ChangeSetBacked { - -} diff --git a/spring-data-mongodb-cross-store/src/main/java/org/springframework/data/mongodb/crossstore/MongoChangeSetPersister.java b/spring-data-mongodb-cross-store/src/main/java/org/springframework/data/mongodb/crossstore/MongoChangeSetPersister.java deleted file mode 100644 index 1376c94ef..000000000 --- a/spring-data-mongodb-cross-store/src/main/java/org/springframework/data/mongodb/crossstore/MongoChangeSetPersister.java +++ /dev/null @@ -1,214 +0,0 @@ -/* - * Copyright 2011-2019 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 - * - * https://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; - -import javax.persistence.EntityManagerFactory; - -import org.bson.Document; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.dao.DataAccessException; -import org.springframework.dao.DataAccessResourceFailureException; -import org.springframework.dao.DataIntegrityViolationException; -import org.springframework.data.crossstore.ChangeSet; -import org.springframework.data.crossstore.ChangeSetBacked; -import org.springframework.data.crossstore.ChangeSetPersister; -import org.springframework.data.mongodb.core.CollectionCallback; -import org.springframework.data.mongodb.core.MongoTemplate; -import org.springframework.util.ClassUtils; - -import com.mongodb.MongoException; -import com.mongodb.client.MongoCollection; -import com.mongodb.client.model.Filters; -import com.mongodb.client.result.DeleteResult; - -/** - * @author Thomas Risberg - * @author Oliver Gierke - * @author Alex Vengrovsk - * @author Mark Paluch - * @deprecated will be removed without replacement. - */ -@Deprecated -public class MongoChangeSetPersister implements ChangeSetPersister { - - private static final String ENTITY_CLASS = "_entity_class"; - private static final String ENTITY_ID = "_entity_id"; - private static final String ENTITY_FIELD_NAME = "_entity_field_name"; - private static final String ENTITY_FIELD_CLASS = "_entity_field_class"; - - private final Logger log = LoggerFactory.getLogger(getClass()); - - private MongoTemplate mongoTemplate; - private EntityManagerFactory entityManagerFactory; - - public void setMongoTemplate(MongoTemplate mongoTemplate) { - this.mongoTemplate = mongoTemplate; - } - - public void setEntityManagerFactory(EntityManagerFactory entityManagerFactory) { - this.entityManagerFactory = entityManagerFactory; - } - - /* - * (non-Javadoc) - * @see org.springframework.data.crossstore.ChangeSetPersister#getPersistentState(java.lang.Class, java.lang.Object, org.springframework.data.crossstore.ChangeSet) - */ - public void getPersistentState(Class entityClass, Object id, final ChangeSet changeSet) - throws DataAccessException, NotFoundException { - - if (id == null) { - log.debug("Unable to load MongoDB data for null id"); - return; - } - - String collName = getCollectionNameForEntity(entityClass); - - final Document dbk = new Document(); - dbk.put(ENTITY_ID, id); - dbk.put(ENTITY_CLASS, entityClass.getName()); - if (log.isDebugEnabled()) { - log.debug("Loading MongoDB data for {}", dbk); - } - mongoTemplate.execute(collName, new CollectionCallback() { - public Object doInCollection(MongoCollection collection) throws MongoException, DataAccessException { - for (Document dbo : collection.find(dbk)) { - String key = (String) dbo.get(ENTITY_FIELD_NAME); - if (log.isDebugEnabled()) { - log.debug("Processing key: {}", key); - } - if (!changeSet.getValues().containsKey(key)) { - String className = (String) dbo.get(ENTITY_FIELD_CLASS); - if (className == null) { - throw new DataIntegrityViolationException( - "Unble to convert property " + key + ": Invalid metadata, " + ENTITY_FIELD_CLASS + " not available"); - } - Class clazz = ClassUtils.resolveClassName(className, ClassUtils.getDefaultClassLoader()); - Object value = mongoTemplate.getConverter().read(clazz, dbo); - if (log.isDebugEnabled()) { - log.debug("Adding to ChangeSet: {}", key); - } - changeSet.set(key, value); - } - } - return null; - } - }); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.crossstore.ChangeSetPersister#getPersistentId(org.springframework.data.crossstore.ChangeSetBacked, org.springframework.data.crossstore.ChangeSet) - */ - public Object getPersistentId(ChangeSetBacked entity, ChangeSet cs) throws DataAccessException { - if (log.isDebugEnabled()) { - log.debug("getPersistentId called on {}", entity); - } - if (entityManagerFactory == null) { - throw new DataAccessResourceFailureException("EntityManagerFactory cannot be null"); - } - - return entityManagerFactory.getPersistenceUnitUtil().getIdentifier(entity); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.crossstore.ChangeSetPersister#persistState(org.springframework.data.crossstore.ChangeSetBacked, org.springframework.data.crossstore.ChangeSet) - */ - public Object persistState(ChangeSetBacked entity, ChangeSet cs) throws DataAccessException { - if (cs == null) { - log.debug("Flush: changeset was null, nothing to flush."); - return 0L; - } - - if (log.isDebugEnabled()) { - log.debug("Flush: changeset: {}", cs.getValues()); - } - - String collName = getCollectionNameForEntity(entity.getClass()); - if (mongoTemplate.getCollection(collName) == null) { - mongoTemplate.createCollection(collName); - } - - for (String key : cs.getValues().keySet()) { - if (key != null && !key.startsWith("_") && !key.equals(ChangeSetPersister.ID_KEY)) { - Object value = cs.getValues().get(key); - final Document dbQuery = new Document(); - dbQuery.put(ENTITY_ID, getPersistentId(entity, cs)); - dbQuery.put(ENTITY_CLASS, entity.getClass().getName()); - dbQuery.put(ENTITY_FIELD_NAME, key); - final Document dbId = mongoTemplate.execute(collName, new CollectionCallback() { - public Document doInCollection(MongoCollection collection) - throws MongoException, DataAccessException { - Document id = collection.find(dbQuery).first(); - return id; - } - }); - - if (value == null) { - if (log.isDebugEnabled()) { - log.debug("Flush: removing: {}", dbQuery); - } - mongoTemplate.execute(collName, new CollectionCallback() { - public Object doInCollection(MongoCollection collection) - throws MongoException, DataAccessException { - DeleteResult dr = collection.deleteMany(dbQuery); - return null; - } - }); - } else { - final Document dbDoc = new Document(); - dbDoc.putAll(dbQuery); - if (log.isDebugEnabled()) { - log.debug("Flush: saving: {}", dbQuery); - } - mongoTemplate.getConverter().write(value, dbDoc); - dbDoc.put(ENTITY_FIELD_CLASS, value.getClass().getName()); - if (dbId != null) { - dbDoc.put("_id", dbId.get("_id")); - } - mongoTemplate.execute(collName, new CollectionCallback() { - public Object doInCollection(MongoCollection collection) - throws MongoException, DataAccessException { - - if (dbId != null) { - collection.replaceOne(Filters.eq("_id", dbId.get("_id")), dbDoc); - } else { - - if (dbDoc.containsKey("_id") && dbDoc.get("_id") == null) { - dbDoc.remove("_id"); - } - collection.insertOne(dbDoc); - } - return null; - } - }); - } - } - } - return 0L; - } - - /** - * Returns the collection the given entity type shall be persisted to. - * - * @param entityClass must not be {@literal null}. - * @return - */ - private String getCollectionNameForEntity(Class entityClass) { - return mongoTemplate.getCollectionName(entityClass); - } -} diff --git a/spring-data-mongodb-cross-store/src/main/java/org/springframework/data/mongodb/crossstore/MongoDocumentBacking.aj b/spring-data-mongodb-cross-store/src/main/java/org/springframework/data/mongodb/crossstore/MongoDocumentBacking.aj deleted file mode 100644 index 2769d9693..000000000 --- a/spring-data-mongodb-cross-store/src/main/java/org/springframework/data/mongodb/crossstore/MongoDocumentBacking.aj +++ /dev/null @@ -1,272 +0,0 @@ -/* - * Copyright 2011-2019 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 - * - * https://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; - -import java.lang.reflect.Field; - -import javax.persistence.EntityManager; -import javax.persistence.Transient; -import javax.persistence.Entity; - -import org.aspectj.lang.JoinPoint; -import org.aspectj.lang.reflect.FieldSignature; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.dao.DataAccessException; -import org.springframework.data.mongodb.crossstore.RelatedDocument; -import org.springframework.data.mongodb.crossstore.DocumentBacked; -import org.springframework.data.crossstore.ChangeSetBackedTransactionSynchronization; -import org.springframework.data.crossstore.ChangeSet; -import org.springframework.data.crossstore.ChangeSetPersister; -import org.springframework.data.crossstore.ChangeSetPersister.NotFoundException; -import org.springframework.data.crossstore.HashMapChangeSet; -import org.springframework.transaction.support.TransactionSynchronizationManager; - -/** - * Aspect to turn an object annotated with @Document into a persistent document using Mongo. - * - * @author Thomas Risberg - * @deprecated will be removed without replacement. - */ -@Deprecated -public aspect MongoDocumentBacking { - - private static final Logger LOGGER = LoggerFactory.getLogger(MongoDocumentBacking.class); - - // Aspect shared config - private ChangeSetPersister changeSetPersister; - - public void setChangeSetPersister(ChangeSetPersister changeSetPersister) { - this.changeSetPersister = changeSetPersister; - } - - // ITD to introduce N state to Annotated objects - declare parents : (@Entity *) implements DocumentBacked; - - // The annotated fields that will be persisted in MongoDB rather than with JPA - declare @field: @RelatedDocument * (@Entity+ *).*:@Transient; - - // ------------------------------------------------------------------------- - // Advise user-defined constructors of ChangeSetBacked objects to create a new - // backing ChangeSet - // ------------------------------------------------------------------------- - pointcut arbitraryUserConstructorOfChangeSetBackedObject(DocumentBacked entity) : - execution((DocumentBacked+).new(..)) && - !execution((DocumentBacked+).new(ChangeSet)) && - this(entity); - - pointcut finderConstructorOfChangeSetBackedObject(DocumentBacked entity, ChangeSet cs) : - execution((DocumentBacked+).new(ChangeSet)) && - this(entity) && - args(cs); - - protected pointcut entityFieldGet(DocumentBacked entity) : - get(@RelatedDocument * DocumentBacked+.*) && - this(entity) && - !get(* DocumentBacked.*); - - protected pointcut entityFieldSet(DocumentBacked entity, Object newVal) : - set(@RelatedDocument * DocumentBacked+.*) && - this(entity) && - args(newVal) && - !set(* DocumentBacked.*); - - // intercept EntityManager.merge calls - public pointcut entityManagerMerge(EntityManager em, Object entity) : - call(* EntityManager.merge(Object)) && - target(em) && - args(entity); - - // intercept EntityManager.remove calls - // public pointcut entityManagerRemove(EntityManager em, Object entity) : - // call(* EntityManager.remove(Object)) && - // target(em) && - // args(entity); - - // move changeSet from detached entity to the newly merged persistent object - Object around(EntityManager em, Object entity) : entityManagerMerge(em, entity) { - Object mergedEntity = proceed(em, entity); - if (entity instanceof DocumentBacked && mergedEntity instanceof DocumentBacked) { - ((DocumentBacked) mergedEntity).changeSet = ((DocumentBacked) entity).getChangeSet(); - } - return mergedEntity; - } - - // clear changeSet from removed entity - // Object around(EntityManager em, Object entity) : entityManagerRemove(em, entity) { - // if (entity instanceof DocumentBacked) { - // removeChangeSetValues((DocumentBacked)entity); - // } - // return proceed(em, entity); - // } - - private static void removeChangeSetValues(DocumentBacked entity) { - LOGGER.debug("Removing all change-set values for " + entity); - ChangeSet nulledCs = new HashMapChangeSet(); - DocumentBacked documentEntity = (DocumentBacked) entity; - @SuppressWarnings("unchecked") - ChangeSetPersister changeSetPersister = (ChangeSetPersister) documentEntity.itdChangeSetPersister; - try { - changeSetPersister.getPersistentState(documentEntity.getClass(), documentEntity.get_persistent_id(), - documentEntity.getChangeSet()); - } catch (DataAccessException e) { - } catch (NotFoundException e) { - } - for (String key : entity.getChangeSet().getValues().keySet()) { - nulledCs.set(key, null); - } - entity.setChangeSet(nulledCs); - } - - before(DocumentBacked entity) : arbitraryUserConstructorOfChangeSetBackedObject(entity) { - LOGGER.debug("User-defined constructor called on DocumentBacked object of class " + entity.getClass()); - // Populate all ITD fields - entity.setChangeSet(new HashMapChangeSet()); - entity.itdChangeSetPersister = changeSetPersister; - entity.itdTransactionSynchronization = new ChangeSetBackedTransactionSynchronization(changeSetPersister, entity); - // registerTransactionSynchronization(entity); - } - - private static void registerTransactionSynchronization(DocumentBacked entity) { - if (TransactionSynchronizationManager.isSynchronizationActive()) { - if (!TransactionSynchronizationManager.getSynchronizations().contains(entity.itdTransactionSynchronization)) { - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Adding transaction synchronization for " + entity); - } - TransactionSynchronizationManager.registerSynchronization(entity.itdTransactionSynchronization); - } else { - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Transaction synchronization already active for " + entity); - } - } - } else { - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Transaction synchronization is not active for " + entity); - } - } - } - - // ------------------------------------------------------------------------- - // ChangeSet-related mixins - // ------------------------------------------------------------------------- - // Introduced field - @Transient - private ChangeSet DocumentBacked.changeSet; - - @Transient - private ChangeSetPersister DocumentBacked.itdChangeSetPersister; - - @Transient - private ChangeSetBackedTransactionSynchronization DocumentBacked.itdTransactionSynchronization; - - public void DocumentBacked.setChangeSet(ChangeSet cs) { - this.changeSet = cs; - } - - public ChangeSet DocumentBacked.getChangeSet() { - return changeSet; - } - - // Flush the entity state to the persistent store - public void DocumentBacked.flush() { - Object id = itdChangeSetPersister.getPersistentId(this, this.changeSet); - itdChangeSetPersister.persistState(this, this.changeSet); - } - - public Object DocumentBacked.get_persistent_id() { - return itdChangeSetPersister.getPersistentId(this, this.changeSet); - } - - // lifecycle methods - @javax.persistence.PostPersist - public void DocumentBacked.itdPostPersist() { - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("JPA lifecycle event PrePersist: " + this.getClass().getName()); - } - registerTransactionSynchronization(this); - } - - @javax.persistence.PreUpdate - public void DocumentBacked.itdPreUpdate() { - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("JPA lifecycle event PreUpdate: " + this.getClass().getName() + " :: " + this); - } - registerTransactionSynchronization(this); - } - - @javax.persistence.PostUpdate - public void DocumentBacked.itdPostUpdate() { - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("JPA lifecycle event PostUpdate: " + this.getClass().getName() + " :: " + this); - } - registerTransactionSynchronization(this); - } - - @javax.persistence.PostRemove - public void DocumentBacked.itdPostRemove() { - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("JPA lifecycle event PostRemove: " + this.getClass().getName() + " :: " + this); - } - registerTransactionSynchronization(this); - removeChangeSetValues(this); - } - - @javax.persistence.PostLoad - public void DocumentBacked.itdPostLoad() { - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("JPA lifecycle event PostLoad: " + this.getClass().getName() + " :: " + this); - } - registerTransactionSynchronization(this); - } - - /** - * delegates field reads to the state accessors instance - */ - Object around(DocumentBacked entity): entityFieldGet(entity) { - Field f = field(thisJoinPoint); - String propName = f.getName(); - LOGGER.trace("GET " + f + " -> ChangeSet value property [" + propName + "] using: " + entity.getChangeSet()); - if (entity.getChangeSet().getValues().get(propName) == null) { - try { - this.changeSetPersister - .getPersistentState(entity.getClass(), entity.get_persistent_id(), entity.getChangeSet()); - } catch (NotFoundException e) { - } - } - Object fValue = entity.getChangeSet().getValues().get(propName); - if (fValue != null) { - return fValue; - } - return proceed(entity); - } - - /** - * delegates field writes to the state accessors instance - */ - Object around(DocumentBacked entity, Object newVal) : entityFieldSet(entity, newVal) { - Field f = field(thisJoinPoint); - String propName = f.getName(); - LOGGER.trace("SET " + f + " -> ChangeSet number value property [" + propName + "] with value=[" + newVal + "]"); - entity.getChangeSet().set(propName, newVal); - return proceed(entity, newVal); - } - - Field field(JoinPoint joinPoint) { - FieldSignature fieldSignature = (FieldSignature) joinPoint.getSignature(); - return fieldSignature.getField(); - } -} diff --git a/spring-data-mongodb-cross-store/src/main/java/org/springframework/data/mongodb/crossstore/RelatedDocument.java b/spring-data-mongodb-cross-store/src/main/java/org/springframework/data/mongodb/crossstore/RelatedDocument.java deleted file mode 100644 index bd529cacb..000000000 --- a/spring-data-mongodb-cross-store/src/main/java/org/springframework/data/mongodb/crossstore/RelatedDocument.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2011-2019 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 - * - * https://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; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * @author Thomas Risberg - * @deprecated will be removed without replacement. - */ -@Deprecated -@Retention(RetentionPolicy.RUNTIME) -@Target({ ElementType.FIELD }) -public @interface RelatedDocument { -} diff --git a/spring-data-mongodb-cross-store/src/main/java/org/springframework/data/mongodb/crossstore/package-info.java b/spring-data-mongodb-cross-store/src/main/java/org/springframework/data/mongodb/crossstore/package-info.java deleted file mode 100644 index 720909133..000000000 --- a/spring-data-mongodb-cross-store/src/main/java/org/springframework/data/mongodb/crossstore/package-info.java +++ /dev/null @@ -1,5 +0,0 @@ -/** - * Infrastructure for Spring Data's MongoDB cross store support. - */ -package org.springframework.data.mongodb.crossstore; - diff --git a/spring-data-mongodb-cross-store/src/test/java/org/springframework/data/mongodb/crossstore/CrossStoreMongoTests.java b/spring-data-mongodb-cross-store/src/test/java/org/springframework/data/mongodb/crossstore/CrossStoreMongoTests.java deleted file mode 100644 index c850fce4f..000000000 --- a/spring-data-mongodb-cross-store/src/test/java/org/springframework/data/mongodb/crossstore/CrossStoreMongoTests.java +++ /dev/null @@ -1,195 +0,0 @@ -/* - * Copyright 2011-2019 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 - * - * https://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; - -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; - -import org.bson.Document; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.mongodb.core.MongoTemplate; -import org.springframework.data.mongodb.crossstore.test.Address; -import org.springframework.data.mongodb.crossstore.test.Person; -import org.springframework.data.mongodb.crossstore.test.Resume; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.transaction.PlatformTransactionManager; -import org.springframework.transaction.TransactionStatus; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.transaction.support.TransactionCallback; -import org.springframework.transaction.support.TransactionTemplate; - -/** - * Integration tests for MongoDB cross-store persistence (mainly {@link MongoChangeSetPersister}). - * - * @author Thomas Risberg - * @author Oliver Gierke - */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration("classpath:/META-INF/spring/applicationContext.xml") -public class CrossStoreMongoTests { - - @Autowired MongoTemplate mongoTemplate; - - @PersistenceContext EntityManager entityManager; - - @Autowired PlatformTransactionManager transactionManager; - TransactionTemplate txTemplate; - - @Before - public void setUp() { - - txTemplate = new TransactionTemplate(transactionManager); - - clearData(Person.class); - - Address address = new Address(12, "MAin St.", "Boston", "MA", "02101"); - - Resume resume = new Resume(); - resume.addEducation("Skanstulls High School, 1975"); - resume.addEducation("Univ. of Stockholm, 1980"); - resume.addJob("DiMark, DBA, 1990-2000"); - resume.addJob("VMware, Developer, 2007-"); - - final Person person = new Person("Thomas", 20); - person.setAddress(address); - person.setResume(resume); - person.setId(1L); - - txTemplate.execute(new TransactionCallback() { - public Void doInTransaction(TransactionStatus status) { - entityManager.persist(person); - return null; - } - }); - } - - @After - public void tearDown() { - txTemplate.execute(new TransactionCallback() { - public Void doInTransaction(TransactionStatus status) { - entityManager.remove(entityManager.find(Person.class, 1L)); - return null; - } - }); - } - - private void clearData(Class domainType) { - - String collectionName = mongoTemplate.getCollectionName(domainType); - mongoTemplate.dropCollection(collectionName); - } - - @Test - @Transactional - public void testReadJpaToMongoEntityRelationship() { - - Person found = entityManager.find(Person.class, 1L); - Assert.assertNotNull(found); - Assert.assertEquals(Long.valueOf(1), found.getId()); - Assert.assertNotNull(found); - Assert.assertEquals(Long.valueOf(1), found.getId()); - Assert.assertNotNull(found.getResume()); - Assert.assertEquals("DiMark, DBA, 1990-2000" + "; " + "VMware, Developer, 2007-", found.getResume().getJobs()); - } - - @Test - @Transactional - public void testUpdatedJpaToMongoEntityRelationship() { - - Person found = entityManager.find(Person.class, 1L); - found.setAge(44); - found.getResume().addJob("SpringDeveloper.com, Consultant, 2005-2006"); - - entityManager.merge(found); - - Assert.assertNotNull(found); - Assert.assertEquals(Long.valueOf(1), found.getId()); - Assert.assertNotNull(found); - Assert.assertEquals(Long.valueOf(1), found.getId()); - Assert.assertNotNull(found.getResume()); - Assert.assertEquals("DiMark, DBA, 1990-2000" + "; " + "VMware, Developer, 2007-" + "; " - + "SpringDeveloper.com, Consultant, 2005-2006", found.getResume().getJobs()); - } - - @Test - public void testMergeJpaEntityWithMongoDocument() { - - final Person detached = entityManager.find(Person.class, 1L); - entityManager.detach(detached); - detached.getResume().addJob("TargetRx, Developer, 2000-2005"); - - Person merged = txTemplate.execute(new TransactionCallback() { - public Person doInTransaction(TransactionStatus status) { - Person result = entityManager.merge(detached); - entityManager.flush(); - return result; - } - }); - - Assert.assertTrue(detached.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); - Assert.assertTrue(updated.getResume().getJobs().contains("TargetRx, Developer, 2000-2005")); - } - - @Test - public void testRemoveJpaEntityWithMongoDocument() { - - txTemplate.execute(new TransactionCallback() { - public Person doInTransaction(TransactionStatus status) { - Person p2 = new Person("Thomas", 20); - Resume r2 = new Resume(); - r2.addEducation("Skanstulls High School, 1975"); - r2.addJob("DiMark, DBA, 1990-2000"); - p2.setResume(r2); - p2.setId(2L); - entityManager.persist(p2); - Person p3 = new Person("Thomas", 20); - Resume r3 = new Resume(); - r3.addEducation("Univ. of Stockholm, 1980"); - r3.addJob("VMware, Developer, 2007-"); - p3.setResume(r3); - p3.setId(3L); - entityManager.persist(p3); - return null; - } - }); - txTemplate.execute(new TransactionCallback() { - public Person doInTransaction(TransactionStatus status) { - final Person found2 = entityManager.find(Person.class, 2L); - entityManager.remove(found2); - return null; - } - }); - - boolean weFound3 = false; - - for (Document dbo : this.mongoTemplate.getCollection(mongoTemplate.getCollectionName(Person.class)).find()) { - Assert.assertTrue(!dbo.get("_entity_id").equals(2L)); - if (dbo.get("_entity_id").equals(3L)) { - weFound3 = true; - } - } - Assert.assertTrue(weFound3); - } - -} diff --git a/spring-data-mongodb-cross-store/src/test/java/org/springframework/data/mongodb/crossstore/test/Address.java b/spring-data-mongodb-cross-store/src/test/java/org/springframework/data/mongodb/crossstore/test/Address.java deleted file mode 100644 index 41928e784..000000000 --- a/spring-data-mongodb-cross-store/src/test/java/org/springframework/data/mongodb/crossstore/test/Address.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2011-2019 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 - * - * https://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; - -public class Address { - - private Integer streetNumber; - private String streetName; - private String city; - private String state; - private String zip; - - public Address(Integer streetNumber, String streetName, String city, String state, String zip) { - super(); - this.streetNumber = streetNumber; - this.streetName = streetName; - this.city = city; - this.state = state; - this.zip = zip; - } - - public Integer getStreetNumber() { - return streetNumber; - } - - public void setStreetNumber(Integer streetNumber) { - this.streetNumber = streetNumber; - } - - public String getStreetName() { - return streetName; - } - - public void setStreetName(String streetName) { - this.streetName = streetName; - } - - public String getCity() { - return city; - } - - public void setCity(String city) { - this.city = city; - } - - public String getState() { - return state; - } - - public void setState(String state) { - this.state = state; - } - - public String getZip() { - return zip; - } - - public void setZip(String zip) { - this.zip = zip; - } - -} diff --git a/spring-data-mongodb-cross-store/src/test/java/org/springframework/data/mongodb/crossstore/test/Person.java b/spring-data-mongodb-cross-store/src/test/java/org/springframework/data/mongodb/crossstore/test/Person.java deleted file mode 100644 index e33a3c1d8..000000000 --- a/spring-data-mongodb-cross-store/src/test/java/org/springframework/data/mongodb/crossstore/test/Person.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright 2011-2019 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 - * - * https://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; - -import javax.persistence.Entity; -import javax.persistence.Id; - -import org.springframework.data.mongodb.crossstore.RelatedDocument; - -@Entity -public class Person { - - @Id - Long id; - - private String name; - - private int age; - - private java.util.Date birthDate; - - @RelatedDocument - private Address address; - - @RelatedDocument - private Resume resume; - - public Person() { - } - - public Person(String name, int age) { - this.name = name; - this.age = age; - this.birthDate = new java.util.Date(); - } - - public void birthday() { - ++age; - } - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - 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 Resume getResume() { - return resume; - } - - public void setResume(Resume resume) { - this.resume = resume; - } - - public Address getAddress() { - return address; - } - - public void setAddress(Address address) { - this.address = address; - } - -} diff --git a/spring-data-mongodb-cross-store/src/test/java/org/springframework/data/mongodb/crossstore/test/Resume.java b/spring-data-mongodb-cross-store/src/test/java/org/springframework/data/mongodb/crossstore/test/Resume.java deleted file mode 100644 index e836ef4bd..000000000 --- a/spring-data-mongodb-cross-store/src/test/java/org/springframework/data/mongodb/crossstore/test/Resume.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2011-2019 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 - * - * https://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; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.bson.types.ObjectId; -import org.springframework.data.annotation.Id; -import org.springframework.data.mongodb.core.mapping.Document; - -@Document -public class Resume { - - private static final Log LOGGER = LogFactory.getLog(Resume.class); - - @Id - private ObjectId id; - - private String education = ""; - - private String jobs = ""; - - public String getId() { - return id.toString(); - } - - public String getEducation() { - return education; - } - - public void addEducation(String education) { - LOGGER.debug("Adding education " + education); - this.education = this.education + (this.education.length() > 0 ? "; " : "") + education; - } - - public String getJobs() { - return jobs; - } - - public void addJob(String job) { - LOGGER.debug("Adding job " + job); - this.jobs = this.jobs + (this.jobs.length() > 0 ? "; " : "") + job; - } - - @Override - public String toString() { - return "Resume [education=" + education + ", jobs=" + jobs + "]"; - } - -} diff --git a/spring-data-mongodb-cross-store/src/test/resources/META-INF/persistence.xml b/spring-data-mongodb-cross-store/src/test/resources/META-INF/persistence.xml deleted file mode 100644 index a03bc925e..000000000 --- a/spring-data-mongodb-cross-store/src/test/resources/META-INF/persistence.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - org.hibernate.ejb.HibernatePersistence - org.springframework.data.mongodb.crossstore.test.Person - - - - - - - - diff --git a/spring-data-mongodb-cross-store/src/test/resources/META-INF/spring/applicationContext.xml b/spring-data-mongodb-cross-store/src/test/resources/META-INF/spring/applicationContext.xml deleted file mode 100644 index d8ea5b0c2..000000000 --- a/spring-data-mongodb-cross-store/src/test/resources/META-INF/spring/applicationContext.xml +++ /dev/null @@ -1,72 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/spring-data-mongodb-cross-store/src/test/resources/logback.xml b/spring-data-mongodb-cross-store/src/test/resources/logback.xml deleted file mode 100644 index 5ecc71909..000000000 --- a/spring-data-mongodb-cross-store/src/test/resources/logback.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - %d %5p %40.40c:%4L - %m%n - - - - - - - - - - \ No newline at end of file