DATACOUCH-677 - Revert "Datacouch 550 autoindex not working in spring boot app (#295)"
This reverts commit 8ebb81b62d.
This commit is contained in:
@@ -166,10 +166,6 @@ public class CouchbaseTemplate implements CouchbaseOperations, ApplicationContex
|
||||
|
||||
if (context instanceof ConfigurableApplicationContext && indexCreator != null) {
|
||||
((ConfigurableApplicationContext) context).addApplicationListener(indexCreator);
|
||||
if (mappingContext instanceof CouchbaseMappingContext) {
|
||||
CouchbaseMappingContext cmc = (CouchbaseMappingContext) mappingContext;
|
||||
cmc.setIndexCreator(indexCreator);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,7 +121,4 @@ public class CouchbasePersistentEntityIndexCreator implements ApplicationListene
|
||||
return this.mappingContext.equals(context);
|
||||
}
|
||||
|
||||
public boolean hasSeen(CouchbasePersistentEntity<?> entity) {
|
||||
return classesSeen.containsKey(entity.getType());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,15 +16,10 @@
|
||||
|
||||
package org.springframework.data.couchbase.core.mapping;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.data.couchbase.core.index.CouchbasePersistentEntityIndexCreator;
|
||||
import org.springframework.data.mapping.context.AbstractMappingContext;
|
||||
import org.springframework.data.mapping.context.MappingContextEvent;
|
||||
import org.springframework.data.mapping.model.FieldNamingStrategy;
|
||||
import org.springframework.data.mapping.model.Property;
|
||||
import org.springframework.data.mapping.model.PropertyNameFieldNamingStrategy;
|
||||
@@ -36,7 +31,6 @@ import org.springframework.data.util.TypeInformation;
|
||||
* {@link BasicCouchbasePersistentEntity} and {@link BasicCouchbasePersistentProperty} as primary abstractions.
|
||||
*
|
||||
* @author Michael Nitschinger
|
||||
* @author Michael Reiche
|
||||
*/
|
||||
public class CouchbaseMappingContext
|
||||
extends AbstractMappingContext<BasicCouchbasePersistentEntity<?>, CouchbasePersistentProperty>
|
||||
@@ -56,8 +50,6 @@ public class CouchbaseMappingContext
|
||||
private FieldNamingStrategy fieldNamingStrategy = DEFAULT_NAMING_STRATEGY;
|
||||
|
||||
private boolean autoIndexCreation = true;
|
||||
private ApplicationEventPublisher eventPublisher;
|
||||
private CouchbasePersistentEntityIndexCreator indexCreator = null;
|
||||
|
||||
/**
|
||||
* Configures the {@link FieldNamingStrategy} to be used to determine the field name if no manual mapping is applied.
|
||||
@@ -109,15 +101,6 @@ public class CouchbaseMappingContext
|
||||
@Override
|
||||
public void setApplicationContext(final ApplicationContext applicationContext) throws BeansException {
|
||||
context = applicationContext;
|
||||
super.setApplicationContext(applicationContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
|
||||
eventPublisher = applicationEventPublisher;
|
||||
if (this.eventPublisher == null) {
|
||||
this.eventPublisher = context;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isAutoIndexCreation() {
|
||||
@@ -128,45 +111,4 @@ public class CouchbaseMappingContext
|
||||
this.autoIndexCreation = autoCreateIndexes;
|
||||
}
|
||||
|
||||
/**
|
||||
* override method from AbstractMappingContext as that method will not publishEvent() if it finds the entity has
|
||||
* already been cached
|
||||
*
|
||||
* @param typeInformation - entity type
|
||||
*/
|
||||
@Override
|
||||
protected Optional<BasicCouchbasePersistentEntity<?>> addPersistentEntity(TypeInformation<?> typeInformation) {
|
||||
Optional<BasicCouchbasePersistentEntity<?>> entity = super.addPersistentEntity(typeInformation);
|
||||
|
||||
if (this.eventPublisher != null && entity.isPresent()) {
|
||||
if (this.indexCreator != null) {
|
||||
if (!indexCreator.hasSeen(entity.get())) {
|
||||
this.eventPublisher.publishEvent(new MappingContextEvent(this, entity.get()));
|
||||
}
|
||||
}
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* override method from AbstractMappingContext as that method will not publishEvent() if it finds the entity has
|
||||
* already been cached. Instead, user our own addPersistEntity that will.
|
||||
*
|
||||
* @param typeInformation - entity type
|
||||
*/
|
||||
@Override
|
||||
public BasicCouchbasePersistentEntity<?> getPersistentEntity(TypeInformation<?> typeInformation) {
|
||||
Optional<BasicCouchbasePersistentEntity<?>> entity = addPersistentEntity(typeInformation);
|
||||
return entity.isPresent() ? entity.get() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* capture the indexCreator when it has been added as a listener. only publishEvent() if the indexCreator hasn't
|
||||
* already seen the class.
|
||||
*
|
||||
* @param indexCreator
|
||||
*/
|
||||
public void setIndexCreator(CouchbasePersistentEntityIndexCreator indexCreator) {
|
||||
this.indexCreator = indexCreator;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user