diff --git a/src/main/java/org/springframework/data/couchbase/core/CouchbaseTemplate.java b/src/main/java/org/springframework/data/couchbase/core/CouchbaseTemplate.java index d94739c9..d1f482a6 100644 --- a/src/main/java/org/springframework/data/couchbase/core/CouchbaseTemplate.java +++ b/src/main/java/org/springframework/data/couchbase/core/CouchbaseTemplate.java @@ -17,7 +17,9 @@ package org.springframework.data.couchbase.core; import org.springframework.beans.BeansException; -import org.springframework.context.*; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.context.ConfigurableApplicationContext; import org.springframework.dao.DataAccessException; import org.springframework.dao.support.PersistenceExceptionTranslator; import org.springframework.data.couchbase.CouchbaseClientFactory; @@ -32,8 +34,7 @@ import org.springframework.lang.Nullable; import com.couchbase.client.java.Collection; /** - * Implements Couchbase operations - * findBy, insertBy, upsertBy, replaceBy, removeBy, existsBy + * Implements Couchbase operations findBy, insertBy, upsertBy, replaceBy, removeBy, existsBy * * @author Michael Nitschinger * @author Michael Reiche diff --git a/src/main/java/org/springframework/data/couchbase/core/CouchbaseTemplateSupport.java b/src/main/java/org/springframework/data/couchbase/core/CouchbaseTemplateSupport.java index 1de8508f..0419125c 100644 --- a/src/main/java/org/springframework/data/couchbase/core/CouchbaseTemplateSupport.java +++ b/src/main/java/org/springframework/data/couchbase/core/CouchbaseTemplateSupport.java @@ -27,7 +27,11 @@ import org.springframework.data.couchbase.core.convert.translation.TranslationSe import org.springframework.data.couchbase.core.mapping.CouchbaseDocument; import org.springframework.data.couchbase.core.mapping.CouchbasePersistentEntity; import org.springframework.data.couchbase.core.mapping.CouchbasePersistentProperty; -import org.springframework.data.couchbase.core.mapping.event.*; +import org.springframework.data.couchbase.core.mapping.event.AfterConvertCallback; +import org.springframework.data.couchbase.core.mapping.event.BeforeConvertCallback; +import org.springframework.data.couchbase.core.mapping.event.BeforeConvertEvent; +import org.springframework.data.couchbase.core.mapping.event.BeforeSaveEvent; +import org.springframework.data.couchbase.core.mapping.event.CouchbaseMappingEvent; import org.springframework.data.couchbase.repository.support.MappingCouchbaseEntityInformation; import org.springframework.data.mapping.PersistentPropertyAccessor; import org.springframework.data.mapping.callback.EntityCallbacks; @@ -49,8 +53,8 @@ public class CouchbaseTemplateSupport implements ApplicationContextAware { private final MappingContext, CouchbasePersistentProperty> mappingContext; // TODO: this should be replaced I think private final TranslationService translationService; - private ApplicationContext applicationContext; EntityCallbacks entityCallbacks; + private ApplicationContext applicationContext; public CouchbaseTemplateSupport(final CouchbaseConverter converter) { this.converter = converter; @@ -74,8 +78,7 @@ public class CouchbaseTemplateSupport implements ApplicationContextAware { T readEntity = converter.read(entityClass, (CouchbaseDocument) translationService.decode(source, converted)); final ConvertingPropertyAccessor accessor = getPropertyAccessor(readEntity); - CouchbasePersistentEntity persistentEntity = mappingContext.getRequiredPersistentEntity( - readEntity.getClass()); + CouchbasePersistentEntity persistentEntity = mappingContext.getRequiredPersistentEntity(readEntity.getClass()); if (persistentEntity.getVersionProperty() != null) { accessor.setProperty(persistentEntity.getVersionProperty(), cas); @@ -85,8 +88,7 @@ public class CouchbaseTemplateSupport implements ApplicationContextAware { public void applyUpdatedCas(final Object entity, final long cas) { final ConvertingPropertyAccessor accessor = getPropertyAccessor(entity); - final CouchbasePersistentEntity persistentEntity = mappingContext.getRequiredPersistentEntity( - entity.getClass()); + final CouchbasePersistentEntity persistentEntity = mappingContext.getRequiredPersistentEntity(entity.getClass()); final CouchbasePersistentProperty versionProperty = persistentEntity.getVersionProperty(); if (versionProperty != null) { diff --git a/src/main/java/org/springframework/data/couchbase/core/ReactiveCouchbaseTemplate.java b/src/main/java/org/springframework/data/couchbase/core/ReactiveCouchbaseTemplate.java index cd8d275b..d7bf8398 100644 --- a/src/main/java/org/springframework/data/couchbase/core/ReactiveCouchbaseTemplate.java +++ b/src/main/java/org/springframework/data/couchbase/core/ReactiveCouchbaseTemplate.java @@ -19,7 +19,6 @@ package org.springframework.data.couchbase.core; import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; -import org.springframework.context.ApplicationEventPublisher; import org.springframework.dao.DataAccessException; import org.springframework.dao.support.PersistenceExceptionTranslator; import org.springframework.data.couchbase.CouchbaseClientFactory; diff --git a/src/main/java/org/springframework/data/couchbase/core/convert/MappingCouchbaseConverter.java b/src/main/java/org/springframework/data/couchbase/core/convert/MappingCouchbaseConverter.java index 2b36c344..3448d386 100644 --- a/src/main/java/org/springframework/data/couchbase/core/convert/MappingCouchbaseConverter.java +++ b/src/main/java/org/springframework/data/couchbase/core/convert/MappingCouchbaseConverter.java @@ -33,8 +33,6 @@ import org.springframework.context.ApplicationContextAware; import org.springframework.core.CollectionFactory; import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.support.DefaultConversionService; -import org.springframework.data.annotation.CreatedDate; -import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.convert.EntityInstantiator; import org.springframework.data.couchbase.core.mapping.CouchbaseDocument; import org.springframework.data.couchbase.core.mapping.CouchbaseList; @@ -64,9 +62,9 @@ import org.springframework.data.mapping.model.SpELExpressionEvaluator; import org.springframework.data.mapping.model.SpELExpressionParameterValueProvider; import org.springframework.data.util.ClassTypeInformation; import org.springframework.data.util.TypeInformation; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; -import org.springframework.lang.Nullable; /** * A mapping converter for Couchbase. The converter is responsible for reading from and writing to entities and @@ -112,8 +110,7 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter implem /** * Callbacks for Audit Mechanism */ - private @Nullable - EntityCallbacks entityCallbacks; + private @Nullable EntityCallbacks entityCallbacks; public MappingCouchbaseConverter() { super(new DefaultConversionService()); @@ -138,7 +135,7 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter implem * attribute. * * @param mappingContext the mapping context to use. - * @param typeKey the attribute name to use to store complex types class name. + * @param typeKey the attribute name to use to store complex types class name. */ public MappingCouchbaseConverter( final MappingContext, CouchbasePersistentProperty> mappingContext, @@ -167,7 +164,7 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter implem /** * Check if one class is a subtype of the other. * - * @param left the first class. + * @param left the first class. * @param right the second class. * @return true if it is a subtype, false otherwise. */ @@ -193,9 +190,9 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter implem /** * Read an incoming {@link CouchbaseDocument} into the target entity. * - * @param type the type information of the target entity. + * @param type the type information of the target entity. * @param source the document to convert. - * @param the entity type. + * @param the entity type. * @return the converted entity. */ protected R read(final TypeInformation type, final CouchbaseDocument source) { @@ -205,10 +202,10 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter implem /** * Read an incoming {@link CouchbaseDocument} into the target entity. * - * @param type the type information of the target entity. + * @param type the type information of the target entity. * @param source the document to convert. * @param parent an optional parent object. - * @param the entity type. + * @param the entity type. * @return the converted entity. */ @SuppressWarnings("unchecked") @@ -228,8 +225,8 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter implem return (R) readMap(typeToUse, source, parent); } - CouchbasePersistentEntity entity = (CouchbasePersistentEntity) mappingContext.getRequiredPersistentEntity( - typeToUse); + CouchbasePersistentEntity entity = (CouchbasePersistentEntity) mappingContext + .getRequiredPersistentEntity(typeToUse); return read(entity, source, parent); } @@ -243,11 +240,10 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter implem * @param entity the target entity. * @param source the document to convert. * @param parent an optional parent object. - * @param the entity type. + * @param the entity type. * @return the converted entity. */ - protected R read(final CouchbasePersistentEntity entity, final CouchbaseDocument source, - final Object parent) { + protected R read(final CouchbasePersistentEntity entity, final CouchbaseDocument source, final Object parent) { final DefaultSpELExpressionEvaluator evaluator = new DefaultSpELExpressionEvaluator(source, spELContext); ParameterValueProvider provider = getParameterProvider(entity, source, evaluator, parent); @@ -259,8 +255,8 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter implem entity.doWithProperties(new PropertyHandler() { @Override public void doWithPersistentProperty(final CouchbasePersistentProperty prop) { - if (!doesPropertyExistInSource(prop) || entity.isConstructorArgument(prop) || isIdConstructionProperty( - prop) || prop.isAnnotationPresent(N1qlJoin.class)) { + if (!doesPropertyExistInSource(prop) || entity.isConstructorArgument(prop) || isIdConstructionProperty(prop) + || prop.isAnnotationPresent(N1qlJoin.class)) { return; } Object obj = prop.isIdProperty() ? source.getId() : getValueInternal(prop, source, instance); @@ -289,8 +285,8 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter implem * Loads the property value through the value provider. * * @param property the source property. - * @param source the source document. - * @param parent the optional parent. + * @param source the source document. + * @param parent the optional parent. * @return the actual property value. */ protected Object getValueInternal(final CouchbasePersistentProperty property, final CouchbaseDocument source, @@ -301,10 +297,10 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter implem /** * Creates a new parameter provider. * - * @param entity the persistent entity. - * @param source the source document. + * @param entity the persistent entity. + * @param source the source document. * @param evaluator the SPEL expression evaluator. - * @param parent the optional parent. + * @param parent the optional parent. * @return a new parameter value provider. */ private ParameterValueProvider getParameterProvider( @@ -321,7 +317,7 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter implem /** * Recursively parses the a map from the source document. * - * @param type the type information for the document. + * @param type the type information for the document. * @param source the source document. * @param parent the optional parent. * @return the recursively parsed map. @@ -362,7 +358,7 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter implem /** * Potentially convert simple values like ENUMs. * - * @param value the value to convert. + * @param value the value to convert. * @param target the target object. * @return the potentially converted object. */ @@ -406,16 +402,15 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter implem writeInternal(source, target, type); if (target.getId() == null) { - throw new MappingException( - "An ID property is needed, but not found/could not be generated on this entity."); + throw new MappingException("An ID property is needed, but not found/could not be generated on this entity."); } } /** * Convert a source object into a {@link CouchbaseDocument} target. * - * @param source the source object. - * @param target the target document. + * @param source the source object. + * @param target the target document. * @param typeHint the type information for the source. */ @SuppressWarnings("unchecked") @@ -565,7 +560,7 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter implem * * @param source the source object. * @param target the target document. - * @param prop the property information. + * @param prop the property information. */ @SuppressWarnings("unchecked") private void writePropertyInternal(final Object source, final CouchbaseDocument target, @@ -615,9 +610,9 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter implem CouchbaseDocument propertyDoc = new CouchbaseDocument(); addCustomTypeKeyIfNecessary(type, source, propertyDoc); - CouchbasePersistentEntity entity = isSubtype(prop.getType(), source.getClass()) ? - mappingContext.getRequiredPersistentEntity(source.getClass()) : - mappingContext.getRequiredPersistentEntity(type); + CouchbasePersistentEntity entity = isSubtype(prop.getType(), source.getClass()) + ? mappingContext.getRequiredPersistentEntity(source.getClass()) + : mappingContext.getRequiredPersistentEntity(type); writeInternal(source, propertyDoc, entity); target.put(name, propertyDoc); } @@ -625,7 +620,7 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter implem /** * Wrapper method to create the underlying map. * - * @param map the source map. + * @param map the source map. * @param prop the persistent property. * @return the written couchbase document. */ @@ -641,7 +636,7 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter implem * * @param source the source object. * @param target the target document. - * @param type the type information for the document. + * @param type the type information for the document. * @return the written couchbase document. */ private CouchbaseDocument writeMapInternal(final Map source, final CouchbaseDocument target, @@ -660,9 +655,7 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter implem new CouchbaseList(conversions.getSimpleTypeHolder()), type.getMapValueType())); } else { CouchbaseDocument embeddedDoc = new CouchbaseDocument(); - TypeInformation valueTypeInfo = type.isMap() ? - type.getMapValueType() : - ClassTypeInformation.OBJECT; + TypeInformation valueTypeInfo = type.isMap() ? type.getMapValueType() : ClassTypeInformation.OBJECT; writeInternal(val, embeddedDoc, valueTypeInfo); target.put(simpleKey, embeddedDoc); } @@ -678,7 +671,7 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter implem * Helper method to create the underlying collection/list. * * @param collection the collection to write. - * @param prop the property information. + * @param prop the property information. * @return the created couchbase list. */ private CouchbaseList createCollection(final Collection collection, final CouchbasePersistentProperty prop) { @@ -691,7 +684,7 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter implem * * @param source the source object. * @param target the target document. - * @param type the type information for the document. + * @param type the type information for the document. * @return the created couchbase list. */ private CouchbaseList writeCollectionInternal(final Collection source, final CouchbaseList target, @@ -704,8 +697,8 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter implem if (elementType == null || conversions.isSimpleType(elementType)) { target.put(getPotentiallyConvertedSimpleWrite(element)); } else if (element instanceof Collection || elementType.isArray()) { - target.put(writeCollectionInternal(asCollection(element), - new CouchbaseList(conversions.getSimpleTypeHolder()), componentType)); + target.put(writeCollectionInternal(asCollection(element), new CouchbaseList(conversions.getSimpleTypeHolder()), + componentType)); } else { CouchbaseDocument embeddedDoc = new CouchbaseDocument(); @@ -722,13 +715,12 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter implem * Read a collection from the source object. * * @param targetType the target type. - * @param source the list as source. - * @param parent the optional parent. + * @param source the list as source. + * @param parent the optional parent. * @return the instantiated collection. */ @SuppressWarnings("unchecked") - private Object readCollection(final TypeInformation targetType, final CouchbaseList source, - final Object parent) { + private Object readCollection(final TypeInformation targetType, final CouchbaseList source, final Object parent) { Assert.notNull(targetType, "Target type must not be null!"); Class collectionType = targetType.getType(); @@ -737,9 +729,8 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter implem } collectionType = Collection.class.isAssignableFrom(collectionType) ? collectionType : List.class; - Collection items = targetType.getType().isArray() ? - new ArrayList() : - CollectionFactory.createCollection(collectionType, source.size(false)); + Collection items = targetType.getType().isArray() ? new ArrayList() + : CollectionFactory.createCollection(collectionType, source.size(false)); TypeInformation componentType = targetType.getComponentType(); Class rawComponentType = componentType == null ? null : componentType.getType(); @@ -764,7 +755,7 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter implem * * @param source the source object. * @param target the target document. - * @param key the key of the object. + * @param key the key of the object. */ private void writeSimpleInternal(final Object source, final CouchbaseDocument target, final String key) { target.put(key, getPotentiallyConvertedSimpleWrite(source)); @@ -777,14 +768,14 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter implem Optional> customTarget = conversions.getCustomWriteTarget(value.getClass()); - return customTarget.map(it -> (Object) conversionService.convert(value, it)).orElseGet( - () -> Enum.class.isAssignableFrom(value.getClass()) ? ((Enum) value).name() : value); + return customTarget.map(it -> (Object) conversionService.convert(value, it)) + .orElseGet(() -> Enum.class.isAssignableFrom(value.getClass()) ? ((Enum) value).name() : value); } /** * Add a custom type key if needed. * - * @param type the type information. + * @param type the type information. * @param source th the source object. * @param target the target document. */ @@ -807,8 +798,7 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter implem } /** - * COPIED - * Set the {@link EntityCallbacks} instance to use when invoking + * COPIED Set the {@link EntityCallbacks} instance to use when invoking * {@link org.springframework.data.mapping.callback.EntityCallback callbacks} like the {@link AfterConvertCallback}. *

* Overrides potentially existing {@link EntityCallbacks}. @@ -825,10 +815,10 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter implem /** * Helper method to read the value based on the value type. * - * @param value the value to convert. - * @param type the type information. + * @param value the value to convert. + * @param type the type information. * @param parent the optional parent. - * @param the target type. + * @param the target type. * @return the converted object. */ @SuppressWarnings("unchecked") @@ -961,8 +951,8 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter implem private final Object parent; public ConverterAwareSpELExpressionParameterValueProvider(final SpELExpressionEvaluator evaluator, - final ConversionService conversionService, - final ParameterValueProvider delegate, final Object parent) { + final ConversionService conversionService, final ParameterValueProvider delegate, + final Object parent) { super(evaluator, conversionService, delegate); this.parent = parent; } diff --git a/src/main/java/org/springframework/data/couchbase/core/mapping/event/AfterConvertCallback.java b/src/main/java/org/springframework/data/couchbase/core/mapping/event/AfterConvertCallback.java index 588d89b4..8c8976ae 100644 --- a/src/main/java/org/springframework/data/couchbase/core/mapping/event/AfterConvertCallback.java +++ b/src/main/java/org/springframework/data/couchbase/core/mapping/event/AfterConvertCallback.java @@ -34,8 +34,8 @@ public interface AfterConvertCallback extends EntityCallback { * Entity callback method invoked after a domain object is materialized from a {@link Document}. Can return either the * same or a modified instance of the domain object. * - * @param entity the domain object (the result of the conversion). - * @param document must not be {@literal null}. + * @param entity the domain object (the result of the conversion). + * @param document must not be {@literal null}. * @param collection name of the collection. * @return the domain object that is the result of reading it from the {@link Document}. */ diff --git a/src/main/java/org/springframework/data/couchbase/core/mapping/event/BeforeConvertCallback.java b/src/main/java/org/springframework/data/couchbase/core/mapping/event/BeforeConvertCallback.java index 307692f2..f9ae092d 100644 --- a/src/main/java/org/springframework/data/couchbase/core/mapping/event/BeforeConvertCallback.java +++ b/src/main/java/org/springframework/data/couchbase/core/mapping/event/BeforeConvertCallback.java @@ -32,7 +32,7 @@ public interface BeforeConvertCallback extends EntityCallback { * Entity callback method invoked before a domain object is converted to be persisted. Can return either the same or a * modified instance of the domain object. * - * @param entity the domain object to save. + * @param entity the domain object to save. * @param collection name of the collection. * @return the domain object to be persisted. */ diff --git a/src/main/java/org/springframework/data/couchbase/repository/auditing/CouchbaseAuditingRegistrar.java b/src/main/java/org/springframework/data/couchbase/repository/auditing/CouchbaseAuditingRegistrar.java index 127a53c0..2a154ffe 100644 --- a/src/main/java/org/springframework/data/couchbase/repository/auditing/CouchbaseAuditingRegistrar.java +++ b/src/main/java/org/springframework/data/couchbase/repository/auditing/CouchbaseAuditingRegistrar.java @@ -34,8 +34,8 @@ import org.springframework.data.couchbase.core.mapping.event.AuditingEventListen import org.springframework.util.Assert; /** - * A support registrar that allows to set up auditing for Couchbase (including {@link AuditingHandler} - * and { IsNewStrategyFactory} set up). See {@link EnableCouchbaseAuditing} for the associated annotation. + * A support registrar that allows to set up auditing for Couchbase (including {@link AuditingHandler} and { + * IsNewStrategyFactory} set up). See {@link EnableCouchbaseAuditing} for the associated annotation. * * @author Thomas Darimont * @author Oliver Gierke @@ -44,56 +44,56 @@ import org.springframework.util.Assert; */ public class CouchbaseAuditingRegistrar extends AuditingBeanDefinitionRegistrarSupport { - @Override - protected Class getAnnotation() { - return EnableCouchbaseAuditing.class; - } + @Override + protected Class getAnnotation() { + return EnableCouchbaseAuditing.class; + } - @Override - protected String getAuditingHandlerBeanName() { - return BeanNames.COUCHBASE_AUDITING_HANDLER; - } + @Override + protected String getAuditingHandlerBeanName() { + return BeanNames.COUCHBASE_AUDITING_HANDLER; + } - @Override - public void registerBeanDefinitions(AnnotationMetadata annotationMetadata, BeanDefinitionRegistry registry) { - Assert.notNull(annotationMetadata, "AnnotationMetadata must not be null!"); - Assert.notNull(registry, "BeanDefinitionRegistry must not be null!"); + @Override + public void registerBeanDefinitions(AnnotationMetadata annotationMetadata, BeanDefinitionRegistry registry) { + Assert.notNull(annotationMetadata, "AnnotationMetadata must not be null!"); + Assert.notNull(registry, "BeanDefinitionRegistry must not be null!"); - ensureMappingContext(registry, annotationMetadata); - super.registerBeanDefinitions(annotationMetadata, registry); - } + ensureMappingContext(registry, annotationMetadata); + super.registerBeanDefinitions(annotationMetadata, registry); + } - @Override - protected BeanDefinitionBuilder getAuditHandlerBeanDefinitionBuilder(AuditingConfiguration configuration) { - Assert.notNull(configuration, "AuditingConfiguration must not be null!"); + @Override + protected BeanDefinitionBuilder getAuditHandlerBeanDefinitionBuilder(AuditingConfiguration configuration) { + Assert.notNull(configuration, "AuditingConfiguration must not be null!"); - BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(IsNewAwareAuditingHandler.class); - builder.addConstructorArgReference(BeanNames.COUCHBASE_MAPPING_CONTEXT); - return configureDefaultAuditHandlerAttributes(configuration, builder); - } + BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(IsNewAwareAuditingHandler.class); + builder.addConstructorArgReference(BeanNames.COUCHBASE_MAPPING_CONTEXT); + return configureDefaultAuditHandlerAttributes(configuration, builder); + } - @Override - protected void registerAuditListenerBeanDefinition(BeanDefinition auditingHandlerDefinition, - BeanDefinitionRegistry registry) { - Assert.notNull(auditingHandlerDefinition, "BeanDefinition must not be null!"); - Assert.notNull(registry, "BeanDefinitionRegistry must not be null!"); + @Override + protected void registerAuditListenerBeanDefinition(BeanDefinition auditingHandlerDefinition, + BeanDefinitionRegistry registry) { + Assert.notNull(auditingHandlerDefinition, "BeanDefinition must not be null!"); + Assert.notNull(registry, "BeanDefinitionRegistry must not be null!"); - BeanDefinitionBuilder listenerBeanDefinitionBuilder = BeanDefinitionBuilder - .rootBeanDefinition(AuditingEventListener.class); - listenerBeanDefinitionBuilder.addConstructorArgValue(ParsingUtils.getObjectFactoryBeanDefinition( - getAuditingHandlerBeanName(), registry)); + BeanDefinitionBuilder listenerBeanDefinitionBuilder = BeanDefinitionBuilder + .rootBeanDefinition(AuditingEventListener.class); + listenerBeanDefinitionBuilder + .addConstructorArgValue(ParsingUtils.getObjectFactoryBeanDefinition(getAuditingHandlerBeanName(), registry)); - registerInfrastructureBeanWithId(listenerBeanDefinitionBuilder.getBeanDefinition(), - AuditingEventListener.class.getName(), registry); - } + registerInfrastructureBeanWithId(listenerBeanDefinitionBuilder.getBeanDefinition(), + AuditingEventListener.class.getName(), registry); + } - private void ensureMappingContext(BeanDefinitionRegistry registry, Object source) { - if (!registry.containsBeanDefinition(BeanNames.COUCHBASE_MAPPING_CONTEXT)) { - RootBeanDefinition definition = new RootBeanDefinition(CouchbaseMappingContext.class); - definition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); - definition.setSource(source); + private void ensureMappingContext(BeanDefinitionRegistry registry, Object source) { + if (!registry.containsBeanDefinition(BeanNames.COUCHBASE_MAPPING_CONTEXT)) { + RootBeanDefinition definition = new RootBeanDefinition(CouchbaseMappingContext.class); + definition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); + definition.setSource(source); - registry.registerBeanDefinition(BeanNames.COUCHBASE_MAPPING_CONTEXT, definition); - } - } + registry.registerBeanDefinition(BeanNames.COUCHBASE_MAPPING_CONTEXT, definition); + } + } } diff --git a/src/main/java/org/springframework/data/couchbase/repository/auditing/EnableCouchbaseAuditing.java b/src/main/java/org/springframework/data/couchbase/repository/auditing/EnableCouchbaseAuditing.java index f522b0d8..3dde0e68 100644 --- a/src/main/java/org/springframework/data/couchbase/repository/auditing/EnableCouchbaseAuditing.java +++ b/src/main/java/org/springframework/data/couchbase/repository/auditing/EnableCouchbaseAuditing.java @@ -41,24 +41,24 @@ import org.springframework.data.domain.AuditorAware; @Retention(RetentionPolicy.RUNTIME) @Import(CouchbaseAuditingRegistrar.class) public @interface EnableCouchbaseAuditing { - /** - * Configures the {@link AuditorAware} bean to be used to lookup the current principal. - */ - String auditorAwareRef() default "auditorAwareRef"; + /** + * Configures the {@link AuditorAware} bean to be used to lookup the current principal. + */ + String auditorAwareRef() default "auditorAwareRef"; - /** - * Configures whether the creation and modification dates are set. Defaults to {@literal true}. - */ - boolean setDates() default true; + /** + * Configures whether the creation and modification dates are set. Defaults to {@literal true}. + */ + boolean setDates() default true; - /** - * Configures whether the entity shall be marked as modified on creation. Defaults to {@literal true}. - */ - boolean modifyOnCreate() default true; + /** + * Configures whether the entity shall be marked as modified on creation. Defaults to {@literal true}. + */ + boolean modifyOnCreate() default true; - /** - * Configures a {@link DateTimeProvider} bean name that allows customizing the {@link org.joda.time.DateTime} to be - * used for setting creation and modification dates. - */ - String dateTimeProviderRef() default "dateTimeProviderRef"; + /** + * Configures a {@link DateTimeProvider} bean name that allows customizing the {@link org.joda.time.DateTime} to be + * used for setting creation and modification dates. + */ + String dateTimeProviderRef() default "dateTimeProviderRef"; } diff --git a/src/test/java/org/springframework/data/couchbase/core/CouchbaseTemplateKeyValueIntegrationTests.java b/src/test/java/org/springframework/data/couchbase/core/CouchbaseTemplateKeyValueIntegrationTests.java index 77659b2c..f6351bed 100644 --- a/src/test/java/org/springframework/data/couchbase/core/CouchbaseTemplateKeyValueIntegrationTests.java +++ b/src/test/java/org/springframework/data/couchbase/core/CouchbaseTemplateKeyValueIntegrationTests.java @@ -17,7 +17,7 @@ package org.springframework.data.couchbase.core; import static org.junit.jupiter.api.Assertions.*; -import static org.springframework.data.couchbase.config.BeanNames.COUCHBASE_TEMPLATE; +import static org.springframework.data.couchbase.config.BeanNames.*; import java.io.IOException; import java.time.Duration; @@ -33,19 +33,14 @@ import org.springframework.dao.DataRetrievalFailureException; import org.springframework.dao.DuplicateKeyException; import org.springframework.data.couchbase.CouchbaseClientFactory; import org.springframework.data.couchbase.SimpleCouchbaseClientFactory; -import org.springframework.data.couchbase.core.convert.CouchbaseConverter; -import org.springframework.data.couchbase.core.convert.MappingCouchbaseConverter; import org.springframework.data.couchbase.domain.Config; import org.springframework.data.couchbase.domain.User; -import org.springframework.data.couchbase.util.Capabilities; import org.springframework.data.couchbase.util.ClusterAwareIntegrationTests; import org.springframework.data.couchbase.util.ClusterType; import org.springframework.data.couchbase.util.IgnoreWhen; /** - * KV tests - * - * Theses tests rely on a cb server running. + * KV tests Theses tests rely on a cb server running. * * @author Michael Nitschinger * @author Michael Reiche @@ -70,7 +65,7 @@ class CouchbaseTemplateKeyValueIntegrationTests extends ClusterAwareIntegrationT @BeforeEach void beforeEach() { ApplicationContext ac = new AnnotationConfigApplicationContext(Config.class); - couchbaseTemplate = (CouchbaseTemplate)ac.getBean(COUCHBASE_TEMPLATE); + couchbaseTemplate = (CouchbaseTemplate) ac.getBean(COUCHBASE_TEMPLATE); } @Test @@ -118,8 +113,7 @@ class CouchbaseTemplateKeyValueIntegrationTests extends ClusterAwareIntegrationT assertTrue(removeResult.getCas() != 0); assertTrue(removeResult.getMutationToken().isPresent()); - assertThrows(DataRetrievalFailureException.class, - () -> couchbaseTemplate.findById(User.class).one(user.getId())); + assertThrows(DataRetrievalFailureException.class, () -> couchbaseTemplate.findById(User.class).one(user.getId())); } @Test diff --git a/src/test/java/org/springframework/data/couchbase/core/CouchbaseTemplateQueryIntegrationTests.java b/src/test/java/org/springframework/data/couchbase/core/CouchbaseTemplateQueryIntegrationTests.java index 475f3559..7bf82884 100644 --- a/src/test/java/org/springframework/data/couchbase/core/CouchbaseTemplateQueryIntegrationTests.java +++ b/src/test/java/org/springframework/data/couchbase/core/CouchbaseTemplateQueryIntegrationTests.java @@ -17,17 +17,15 @@ package org.springframework.data.couchbase.core; import static org.junit.jupiter.api.Assertions.*; -import static org.springframework.data.couchbase.config.BeanNames.COUCHBASE_TEMPLATE; +import static org.springframework.data.couchbase.config.BeanNames.*; import java.io.IOException; import java.time.Instant; import java.time.temporal.TemporalAccessor; import java.util.Arrays; import java.util.List; -import java.util.Optional; import java.util.UUID; -import org.springframework.data.couchbase.domain.Config; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; @@ -37,6 +35,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext import org.springframework.dao.DataRetrievalFailureException; import org.springframework.data.couchbase.CouchbaseClientFactory; import org.springframework.data.couchbase.SimpleCouchbaseClientFactory; +import org.springframework.data.couchbase.domain.Config; import org.springframework.data.couchbase.domain.NaiveAuditorAware; import org.springframework.data.couchbase.domain.User; import org.springframework.data.couchbase.domain.time.AuditingDateTimeProvider; @@ -44,15 +43,12 @@ import org.springframework.data.couchbase.util.Capabilities; import org.springframework.data.couchbase.util.ClusterAwareIntegrationTests; import org.springframework.data.couchbase.util.ClusterType; import org.springframework.data.couchbase.util.IgnoreWhen; -import org.springframework.test.context.TestContext; import com.couchbase.client.core.error.IndexExistsException; import com.couchbase.client.java.query.QueryScanConsistency; /** - * Query tests - * - * Theses tests rely on a cb server running + * Query tests Theses tests rely on a cb server running * * @author Michael Nitschinger * @author Michael Reiche @@ -93,8 +89,8 @@ class CouchbaseTemplateQueryIntegrationTests extends ClusterAwareIntegrationTest couchbaseTemplate.upsertById(User.class).all(Arrays.asList(user1, user2)); - final List foundUsers = couchbaseTemplate.findByQuery(User.class).consistentWith( - QueryScanConsistency.REQUEST_PLUS).all(); + final List foundUsers = couchbaseTemplate.findByQuery(User.class) + .consistentWith(QueryScanConsistency.REQUEST_PLUS).all(); for (User u : foundUsers) { System.out.println(u); @@ -119,6 +115,7 @@ class CouchbaseTemplateQueryIntegrationTests extends ClusterAwareIntegrationTest couchbaseTemplate.removeByQuery(User.class).all(); } } + @Test void removeByQuery() { User user1 = new User(UUID.randomUUID().toString(), "user1", "user1"); @@ -131,10 +128,8 @@ class CouchbaseTemplateQueryIntegrationTests extends ClusterAwareIntegrationTest couchbaseTemplate.removeByQuery(User.class).consistentWith(QueryScanConsistency.REQUEST_PLUS).all(); - assertThrows(DataRetrievalFailureException.class, - () -> couchbaseTemplate.findById(User.class).one(user1.getId())); - assertThrows(DataRetrievalFailureException.class, - () -> couchbaseTemplate.findById(User.class).one(user2.getId())); + assertThrows(DataRetrievalFailureException.class, () -> couchbaseTemplate.findById(User.class).one(user1.getId())); + assertThrows(DataRetrievalFailureException.class, () -> couchbaseTemplate.findById(User.class).one(user2.getId())); } } diff --git a/src/test/java/org/springframework/data/couchbase/core/query/QueryCriteriaTests.java b/src/test/java/org/springframework/data/couchbase/core/query/QueryCriteriaTests.java index 37b152ac..fbfee507 100644 --- a/src/test/java/org/springframework/data/couchbase/core/query/QueryCriteriaTests.java +++ b/src/test/java/org/springframework/data/couchbase/core/query/QueryCriteriaTests.java @@ -16,11 +16,11 @@ package org.springframework.data.couchbase.core.query; -import org.junit.jupiter.api.Test; - import static org.junit.jupiter.api.Assertions.*; import static org.springframework.data.couchbase.core.query.QueryCriteria.*; +import org.junit.jupiter.api.Test; + class QueryCriteriaTests { @Test @@ -65,19 +65,14 @@ class QueryCriteriaTests { assertEquals("`name` = \"Bubba\" or (`age` > 12 or `country` = \"Austria\")", c.export()); } - @Test void testNestedNotIn() { - QueryCriteria c = - where("name").is("Bubba").or( - where("age").gt(12).or("country").is("Austria")).and( - where("state").notIn(new String[]{"Alabama", "Florida"})); - assertEquals("`name` = \"Bubba\" or (`age` > 12 or `country` = \"Austria\") and " + - "(not( (`state` in ( [ \"Alabama\", \"Florida\" ] )) ))", - c.export()); + QueryCriteria c = where("name").is("Bubba").or(where("age").gt(12).or("country").is("Austria")) + .and(where("state").notIn(new String[] { "Alabama", "Florida" })); + assertEquals("`name` = \"Bubba\" or (`age` > 12 or `country` = \"Austria\") and " + + "(not( (`state` in ( [ \"Alabama\", \"Florida\" ] )) ))", c.export()); } - @Test void testLt() { QueryCriteria c = where("name").lt("Couch"); @@ -156,7 +151,6 @@ class QueryCriteriaTests { assertEquals("not( (`name` like \"%Elvis%\") )", c.export()); } - @Test void testIsNull() { QueryCriteria c = where("name").isNull(); @@ -201,13 +195,13 @@ class QueryCriteriaTests { @Test void testIn() { - QueryCriteria c = where("name").in(new String[]{"gump", "davis"}); + QueryCriteria c = where("name").in(new String[] { "gump", "davis" }); assertEquals("`name` in ( [ \"gump\", \"davis\" ] )", c.export()); } @Test void testNotIn() { - QueryCriteria c = where("name").notIn(new String[]{"gump", "davis"}); + QueryCriteria c = where("name").notIn(new String[] { "gump", "davis" }); assertEquals("not( (`name` in ( [ \"gump\", \"davis\" ] )) )", c.export()); } @@ -222,4 +216,4 @@ class QueryCriteriaTests { QueryCriteria c = where("name").FALSE(); assertEquals("not( (`name`) )", c.export()); } -} \ No newline at end of file +} diff --git a/src/test/java/org/springframework/data/couchbase/domain/AbstractEntity.java b/src/test/java/org/springframework/data/couchbase/domain/AbstractEntity.java index e604563e..71d2dbf0 100644 --- a/src/test/java/org/springframework/data/couchbase/domain/AbstractEntity.java +++ b/src/test/java/org/springframework/data/couchbase/domain/AbstractEntity.java @@ -1,64 +1,62 @@ package org.springframework.data.couchbase.domain; +import java.util.UUID; + import org.springframework.data.annotation.Id; import org.springframework.data.couchbase.core.mapping.Document; import org.springframework.data.couchbase.core.mapping.id.GeneratedValue; import org.springframework.data.couchbase.core.mapping.id.GenerationStrategy; -import java.util.UUID; - /** * @author Oliver Gierke */ @Document public class AbstractEntity { - @Id - @GeneratedValue(strategy = GenerationStrategy.UNIQUE) - private UUID id; + @Id @GeneratedValue(strategy = GenerationStrategy.UNIQUE) private UUID id; - public AbstractEntity(){ } + public AbstractEntity() {} - /** - * set the id - */ - public void setId(UUID id) { - this.id=id; - } - /** - * @return the id - */ - public UUID getId() { - return id; - } + /** + * @return the id + */ + public UUID getId() { + return id; + } - /* - * (non-Javadoc) - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public boolean equals(Object obj) { + /** + * set the id + */ + public void setId(UUID id) { + this.id = id; + } - if (this == obj) { - return true; - } + /* + * (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { - if (this.id == null || obj == null || !(this.getClass().equals(obj.getClass()))) { - return false; - } + if (this == obj) { + return true; + } - AbstractEntity that = (AbstractEntity) obj; + if (this.id == null || obj == null || !(this.getClass().equals(obj.getClass()))) { + return false; + } - return this.id.equals(that.getId()); - } + AbstractEntity that = (AbstractEntity) obj; - /* - * (non-Javadoc) - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() { - return id == null ? 0 : id.hashCode(); - } + return this.id.equals(that.getId()); + } + + /* + * (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + return id == null ? 0 : id.hashCode(); + } } - diff --git a/src/test/java/org/springframework/data/couchbase/domain/Airline.java b/src/test/java/org/springframework/data/couchbase/domain/Airline.java index 04817ee7..a1544c1c 100644 --- a/src/test/java/org/springframework/data/couchbase/domain/Airline.java +++ b/src/test/java/org/springframework/data/couchbase/domain/Airline.java @@ -7,13 +7,11 @@ import org.springframework.data.couchbase.core.index.QueryIndexed; import org.springframework.data.couchbase.core.mapping.Document; @Document -@CompositeQueryIndex(fields = {"id", "name desc"}) +@CompositeQueryIndex(fields = { "id", "name desc" }) public class Airline { - @Id - String id; + @Id String id; - @QueryIndexed - String name; + @QueryIndexed String name; @PersistenceConstructor public Airline(String id, String name) { diff --git a/src/test/java/org/springframework/data/couchbase/domain/AirportRepository.java b/src/test/java/org/springframework/data/couchbase/domain/AirportRepository.java index 61289143..d643e685 100644 --- a/src/test/java/org/springframework/data/couchbase/domain/AirportRepository.java +++ b/src/test/java/org/springframework/data/couchbase/domain/AirportRepository.java @@ -16,14 +16,14 @@ package org.springframework.data.couchbase.domain; +import java.util.List; + import org.springframework.data.couchbase.repository.ScanConsistency; import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.stereotype.Repository; import com.couchbase.client.java.query.QueryScanConsistency; -import java.util.List; - @Repository public interface AirportRepository extends PagingAndSortingRepository { diff --git a/src/test/java/org/springframework/data/couchbase/domain/Config.java b/src/test/java/org/springframework/data/couchbase/domain/Config.java index 32ad566d..747fa83c 100644 --- a/src/test/java/org/springframework/data/couchbase/domain/Config.java +++ b/src/test/java/org/springframework/data/couchbase/domain/Config.java @@ -1,16 +1,16 @@ package org.springframework.data.couchbase.domain; -import org.springframework.data.couchbase.domain.time.AuditingDateTimeProvider; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.auditing.DateTimeProvider; import org.springframework.data.couchbase.config.AbstractCouchbaseConfiguration; +import org.springframework.data.couchbase.domain.time.AuditingDateTimeProvider; import org.springframework.data.couchbase.repository.auditing.EnableCouchbaseAuditing; import org.springframework.data.couchbase.repository.config.EnableCouchbaseRepositories; @Configuration @EnableCouchbaseRepositories -@EnableCouchbaseAuditing //this activates auditing +@EnableCouchbaseAuditing // this activates auditing public class Config extends AbstractCouchbaseConfiguration { String bucketname = "travel-sample"; String username = "Administrator"; @@ -46,4 +46,4 @@ public class Config extends AbstractCouchbaseConfiguration { public DateTimeProvider testDateTimeProvider() { return new AuditingDateTimeProvider(); } -} \ No newline at end of file +} diff --git a/src/test/java/org/springframework/data/couchbase/domain/NaiveAuditorAware.java b/src/test/java/org/springframework/data/couchbase/domain/NaiveAuditorAware.java index f28932cb..f38d7d51 100644 --- a/src/test/java/org/springframework/data/couchbase/domain/NaiveAuditorAware.java +++ b/src/test/java/org/springframework/data/couchbase/domain/NaiveAuditorAware.java @@ -1,9 +1,9 @@ package org.springframework.data.couchbase.domain; -import org.springframework.data.domain.AuditorAware; - import java.util.Optional; +import org.springframework.data.domain.AuditorAware; + // These are the classes that would be used for a real getCurrentAuditor() implementation //import org.springframework.security.core.Authentication; //import org.springframework.security.core.context.SecurityContextHolder; @@ -27,4 +27,4 @@ public class NaiveAuditorAware implements AuditorAware { public void setAuditor(String auditor) { this.auditor = Optional.of(auditor); } -} \ No newline at end of file +} diff --git a/src/test/java/org/springframework/data/couchbase/domain/Person.java b/src/test/java/org/springframework/data/couchbase/domain/Person.java index a9c05330..308624fe 100644 --- a/src/test/java/org/springframework/data/couchbase/domain/Person.java +++ b/src/test/java/org/springframework/data/couchbase/domain/Person.java @@ -1,90 +1,92 @@ package org.springframework.data.couchbase.domain; -import org.springframework.data.annotation.*; -import org.springframework.data.couchbase.core.mapping.Document; -import org.springframework.data.couchbase.core.mapping.event.AuditingEventListener; -import org.springframework.data.couchbase.repository.auditing.EnableCouchbaseAuditing; - -import java.time.ZonedDateTime; -import java.util.Date; import java.util.Optional; import java.util.UUID; +import org.springframework.data.annotation.CreatedBy; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.LastModifiedBy; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.annotation.Version; +import org.springframework.data.couchbase.core.mapping.Document; + @Document public class Person extends AbstractEntity { - Optional firstname; - Optional lastname; + Optional firstname; + Optional lastname; - @CreatedBy - private String creator; + @CreatedBy private String creator; - @LastModifiedBy - private String lastModifiedBy; + @LastModifiedBy private String lastModifiedBy; - @LastModifiedDate - private long lastModification; + @LastModifiedDate private long lastModification; - @CreatedDate - private long creationDate; // =System.currentTimeMillis(); + @CreatedDate private long creationDate; // =System.currentTimeMillis(); - @Version - private long version; + @Version private long version; - public Person(){ - } + public Person() {} - public Person(String firstname, String lastname){ - this(); - setFirstname(firstname); - setLastname(lastname); - } + public Person(String firstname, String lastname) { + this(); + setFirstname(firstname); + setLastname(lastname); + } - public Person(int id,String firstname, String lastname){ - this(firstname,lastname); - setId(new UUID(id, id)); - } + public Person(int id, String firstname, String lastname) { + this(firstname, lastname); + setId(new UUID(id, id)); + } - public Optional getFirstname(){ - return firstname; - } - public void setFirstname(String firstname) { - this.firstname = firstname == null ? null : ( Optional.ofNullable(firstname.equals("")?null:firstname) ); - } - public void setFirstname(Optional firstname) { - this.firstname = firstname; - } + static String optional(String name, Optional obj) { + if (obj != null) + if (obj.isPresent()) + return (" " + name + ": '" + obj.get() + "'\n"); + else + return " " + name + ": null\n"; + return ""; + } - public Optional getLastname(){ - return lastname; - } - public void setLastname(String lastname) { - this.lastname = lastname == null ? null : ( Optional.ofNullable(lastname.equals("")?null:lastname) ); - } - public void setLastname(Optional lastname) { - this.lastname = lastname; - } + public Optional getFirstname() { + return firstname; + } - public String toString(){ - StringBuilder sb=new StringBuilder(); - sb.append("Person : {\n"); - sb.append(" id : "+getId()); - sb.append(optional(", firstname",firstname)); - sb.append(optional( ", lastname", lastname)); - sb.append(", version : "+version); - if(creator != null) sb.append(", creator : "+creator); - if(creationDate != 0) sb.append(", creationDate : "+creationDate); - if(lastModifiedBy != null) sb.append(", lastModifiedBy : "+lastModifiedBy); - if(lastModification != 0) sb.append(", lastModification : "+lastModification); - sb.append("}"); - return sb.toString(); - } + public void setFirstname(String firstname) { + this.firstname = firstname == null ? null : (Optional.ofNullable(firstname.equals("") ? null : firstname)); + } - static String optional(String name, Optional obj){ - if(obj != null) - if(obj.isPresent()) - return(" "+name+ ": '"+obj.get()+"'\n"); - else - return" "+name+": null\n" ; - return ""; - } + public void setFirstname(Optional firstname) { + this.firstname = firstname; + } + + public Optional getLastname() { + return lastname; + } + + public void setLastname(String lastname) { + this.lastname = lastname == null ? null : (Optional.ofNullable(lastname.equals("") ? null : lastname)); + } + + public void setLastname(Optional lastname) { + this.lastname = lastname; + } + + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("Person : {\n"); + sb.append(" id : " + getId()); + sb.append(optional(", firstname", firstname)); + sb.append(optional(", lastname", lastname)); + sb.append(", version : " + version); + if (creator != null) + sb.append(", creator : " + creator); + if (creationDate != 0) + sb.append(", creationDate : " + creationDate); + if (lastModifiedBy != null) + sb.append(", lastModifiedBy : " + lastModifiedBy); + if (lastModification != 0) + sb.append(", lastModification : " + lastModification); + sb.append("}"); + return sb.toString(); + } } diff --git a/src/test/java/org/springframework/data/couchbase/domain/ReactiveAirportRepository.java b/src/test/java/org/springframework/data/couchbase/domain/ReactiveAirportRepository.java index 624d0a1e..16008071 100644 --- a/src/test/java/org/springframework/data/couchbase/domain/ReactiveAirportRepository.java +++ b/src/test/java/org/springframework/data/couchbase/domain/ReactiveAirportRepository.java @@ -16,12 +16,13 @@ package org.springframework.data.couchbase.domain; +import reactor.core.publisher.Flux; + import org.springframework.data.couchbase.repository.ScanConsistency; import org.springframework.data.repository.reactive.ReactiveSortingRepository; import org.springframework.stereotype.Repository; import com.couchbase.client.java.query.QueryScanConsistency; -import reactor.core.publisher.Flux; @Repository public interface ReactiveAirportRepository extends ReactiveSortingRepository { diff --git a/src/test/java/org/springframework/data/couchbase/domain/ReactiveUserRepository.java b/src/test/java/org/springframework/data/couchbase/domain/ReactiveUserRepository.java index 0b378cb0..41a6d4a8 100644 --- a/src/test/java/org/springframework/data/couchbase/domain/ReactiveUserRepository.java +++ b/src/test/java/org/springframework/data/couchbase/domain/ReactiveUserRepository.java @@ -16,9 +16,10 @@ package org.springframework.data.couchbase.domain; +import reactor.core.publisher.Flux; + import org.springframework.data.repository.reactive.ReactiveSortingRepository; import org.springframework.stereotype.Repository; -import reactor.core.publisher.Flux; @Repository public interface ReactiveUserRepository extends ReactiveSortingRepository { diff --git a/src/test/java/org/springframework/data/couchbase/domain/User.java b/src/test/java/org/springframework/data/couchbase/domain/User.java index 73449c68..5641742f 100644 --- a/src/test/java/org/springframework/data/couchbase/domain/User.java +++ b/src/test/java/org/springframework/data/couchbase/domain/User.java @@ -18,7 +18,13 @@ package org.springframework.data.couchbase.domain; import java.util.Objects; -import org.springframework.data.annotation.*; +import org.springframework.data.annotation.CreatedBy; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.Id; +import org.springframework.data.annotation.LastModifiedBy; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.annotation.PersistenceConstructor; +import org.springframework.data.annotation.Version; import org.springframework.data.couchbase.core.mapping.Document; /** @@ -31,20 +37,14 @@ import org.springframework.data.couchbase.core.mapping.Document; @Document public class User { - @Id - private String id; + @Version long version; + @Id private String id; private String firstname; private String lastname; - @CreatedBy - private String createdBy; - @CreatedDate - private long createdDate; - @LastModifiedBy - private String lastModifiedBy; - @LastModifiedDate - private long lastModifiedDate; - @Version - long version; + @CreatedBy private String createdBy; + @CreatedDate private long createdDate; + @LastModifiedBy private String lastModifiedBy; + @LastModifiedDate private long lastModifiedDate; @PersistenceConstructor public User(final String id, final String firstname, final String lastname) { @@ -92,8 +92,8 @@ public class User { if (o == null || getClass() != o.getClass()) return false; User user = (User) o; - return Objects.equals(id, user.id) && Objects.equals(firstname, user.firstname) && Objects.equals(lastname, - user.lastname); + return Objects.equals(id, user.id) && Objects.equals(firstname, user.firstname) + && Objects.equals(lastname, user.lastname); } @Override diff --git a/src/test/java/org/springframework/data/couchbase/domain/UserRepository.java b/src/test/java/org/springframework/data/couchbase/domain/UserRepository.java index 01a41099..e8888f0c 100644 --- a/src/test/java/org/springframework/data/couchbase/domain/UserRepository.java +++ b/src/test/java/org/springframework/data/couchbase/domain/UserRepository.java @@ -16,14 +16,14 @@ package org.springframework.data.couchbase.domain; +import java.util.List; + import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.stereotype.Repository; -import java.util.List; -import java.util.UUID; - /** * User Repository for tests + * * @author Michael Nitschinger * @author Michael Reiche */ @@ -34,5 +34,4 @@ public interface UserRepository extends PagingAndSortingRepository List findByFirstnameAndLastname(String firstname, String lastname); - } diff --git a/src/test/java/org/springframework/data/couchbase/domain/time/AuditingDateTimeProvider.java b/src/test/java/org/springframework/data/couchbase/domain/time/AuditingDateTimeProvider.java index 4782e457..689290c4 100644 --- a/src/test/java/org/springframework/data/couchbase/domain/time/AuditingDateTimeProvider.java +++ b/src/test/java/org/springframework/data/couchbase/domain/time/AuditingDateTimeProvider.java @@ -1,17 +1,16 @@ package org.springframework.data.couchbase.domain.time; -import org.springframework.data.auditing.DateTimeProvider; - import java.time.Instant; import java.time.temporal.TemporalAccessor; import java.util.Optional; +import org.springframework.data.auditing.DateTimeProvider; + public class AuditingDateTimeProvider implements DateTimeProvider { private DateTimeService dateTimeService = new FixedDateTimeService(); - public AuditingDateTimeProvider() { - } + public AuditingDateTimeProvider() {} public AuditingDateTimeProvider(DateTimeService dateTimeService) { this.dateTimeService = dateTimeService; @@ -21,4 +20,4 @@ public class AuditingDateTimeProvider implements DateTimeProvider { public Optional getNow() { return Optional.of(Instant.ofEpochSecond(dateTimeService.getCurrentDateAndTime().toEpochSecond())); } -} \ No newline at end of file +} diff --git a/src/test/java/org/springframework/data/couchbase/domain/time/DateTimeService.java b/src/test/java/org/springframework/data/couchbase/domain/time/DateTimeService.java index 49674167..6916987f 100644 --- a/src/test/java/org/springframework/data/couchbase/domain/time/DateTimeService.java +++ b/src/test/java/org/springframework/data/couchbase/domain/time/DateTimeService.java @@ -4,4 +4,4 @@ import java.time.ZonedDateTime; public interface DateTimeService { ZonedDateTime getCurrentDateAndTime(); -} \ No newline at end of file +} diff --git a/src/test/java/org/springframework/data/couchbase/domain/time/FixedDateTimeService.java b/src/test/java/org/springframework/data/couchbase/domain/time/FixedDateTimeService.java index 0d234a99..00fac45b 100644 --- a/src/test/java/org/springframework/data/couchbase/domain/time/FixedDateTimeService.java +++ b/src/test/java/org/springframework/data/couchbase/domain/time/FixedDateTimeService.java @@ -4,12 +4,12 @@ import java.time.ZoneId; import java.time.ZonedDateTime; public class FixedDateTimeService implements DateTimeService { + public static void main(String[] args) { + System.out.println((new FixedDateTimeService()).getCurrentDateAndTime()); + } + @Override public ZonedDateTime getCurrentDateAndTime() { return ZonedDateTime.of(2020, 1, 1, 0, 0, 0, 0, ZoneId.of("GMT-8")); } - - public static void main(String[] args) { - System.out.println((new FixedDateTimeService()).getCurrentDateAndTime()); - } } diff --git a/src/test/java/org/springframework/data/couchbase/repository/CouchbaseRepositoryAutoQueryIndexIntegrationTests.java b/src/test/java/org/springframework/data/couchbase/repository/CouchbaseRepositoryAutoQueryIndexIntegrationTests.java index cfddd87e..42bcd73b 100644 --- a/src/test/java/org/springframework/data/couchbase/repository/CouchbaseRepositoryAutoQueryIndexIntegrationTests.java +++ b/src/test/java/org/springframework/data/couchbase/repository/CouchbaseRepositoryAutoQueryIndexIntegrationTests.java @@ -16,8 +16,10 @@ package org.springframework.data.couchbase.repository; -import com.couchbase.client.java.Cluster; -import com.couchbase.client.java.manager.query.QueryIndex; +import static org.junit.jupiter.api.Assertions.*; + +import java.util.Optional; + import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; @@ -29,29 +31,23 @@ import org.springframework.data.couchbase.util.ClusterType; import org.springframework.data.couchbase.util.IgnoreWhen; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; -import java.util.Optional; - -import static org.junit.jupiter.api.Assertions.*; +import com.couchbase.client.java.Cluster; +import com.couchbase.client.java.manager.query.QueryIndex; @SpringJUnitConfig(CouchbaseRepositoryAutoQueryIndexIntegrationTests.Config.class) @IgnoreWhen(missesCapabilities = Capabilities.QUERY, clusterTypes = ClusterType.MOCKED) public class CouchbaseRepositoryAutoQueryIndexIntegrationTests extends ClusterAwareIntegrationTests { - @Autowired - private Cluster cluster; + @Autowired private Cluster cluster; /** - * Since the index creation happens at startup, the only way to properly check is by querying the - * index list and making sure it is present. + * Since the index creation happens at startup, the only way to properly check is by querying the index list and + * making sure it is present. */ @Test void createsSingleFieldIndex() { - Optional foundIndex = cluster - .queryIndexes() - .getAllIndexes(bucketName()) - .stream() - .filter(i -> i.name().equals("idx_airline_name")) - .findFirst(); + Optional foundIndex = cluster.queryIndexes().getAllIndexes(bucketName()).stream() + .filter(i -> i.name().equals("idx_airline_name")).findFirst(); assertTrue(foundIndex.isPresent()); assertTrue(foundIndex.get().condition().get().contains("_class")); @@ -59,12 +55,8 @@ public class CouchbaseRepositoryAutoQueryIndexIntegrationTests extends ClusterAw @Test void createsCompositeIndex() { - Optional foundIndex = cluster - .queryIndexes() - .getAllIndexes(bucketName()) - .stream() - .filter(i -> i.name().equals("idx_airline_id_name")) - .findFirst(); + Optional foundIndex = cluster.queryIndexes().getAllIndexes(bucketName()).stream() + .filter(i -> i.name().equals("idx_airline_id_name")).findFirst(); assertTrue(foundIndex.isPresent()); assertTrue(foundIndex.get().condition().get().contains("_class")); diff --git a/src/test/java/org/springframework/data/couchbase/repository/CouchbaseRepositoryKeyValueIntegrationTests.java b/src/test/java/org/springframework/data/couchbase/repository/CouchbaseRepositoryKeyValueIntegrationTests.java index 9ccd2433..15cab50d 100644 --- a/src/test/java/org/springframework/data/couchbase/repository/CouchbaseRepositoryKeyValueIntegrationTests.java +++ b/src/test/java/org/springframework/data/couchbase/repository/CouchbaseRepositoryKeyValueIntegrationTests.java @@ -28,7 +28,6 @@ import org.springframework.data.couchbase.config.AbstractCouchbaseConfiguration; import org.springframework.data.couchbase.domain.User; import org.springframework.data.couchbase.domain.UserRepository; import org.springframework.data.couchbase.repository.config.EnableCouchbaseRepositories; -import org.springframework.data.couchbase.util.Capabilities; import org.springframework.data.couchbase.util.ClusterAwareIntegrationTests; import org.springframework.data.couchbase.util.ClusterType; import org.springframework.data.couchbase.util.IgnoreWhen; @@ -44,8 +43,7 @@ import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; @IgnoreWhen(clusterTypes = ClusterType.MOCKED) public class CouchbaseRepositoryKeyValueIntegrationTests extends ClusterAwareIntegrationTests { - @Autowired - UserRepository userRepository; + @Autowired UserRepository userRepository; @Test @IgnoreWhen(clusterTypes = ClusterType.MOCKED) diff --git a/src/test/java/org/springframework/data/couchbase/repository/ReactiveCouchbaseRepositoryKeyValueIntegrationTests.java b/src/test/java/org/springframework/data/couchbase/repository/ReactiveCouchbaseRepositoryKeyValueIntegrationTests.java index 0f6e7317..55288ada 100644 --- a/src/test/java/org/springframework/data/couchbase/repository/ReactiveCouchbaseRepositoryKeyValueIntegrationTests.java +++ b/src/test/java/org/springframework/data/couchbase/repository/ReactiveCouchbaseRepositoryKeyValueIntegrationTests.java @@ -37,8 +37,7 @@ import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; @IgnoreWhen(clusterTypes = ClusterType.MOCKED) public class ReactiveCouchbaseRepositoryKeyValueIntegrationTests extends ClusterAwareIntegrationTests { - @Autowired - ReactiveUserRepository userRepository; + @Autowired ReactiveUserRepository userRepository; @Test void saveAndFindById() { diff --git a/src/test/java/org/springframework/data/couchbase/repository/ReactiveCouchbaseRepositoryQueryIntegrationTests.java b/src/test/java/org/springframework/data/couchbase/repository/ReactiveCouchbaseRepositoryQueryIntegrationTests.java index e96187e3..09bf4465 100644 --- a/src/test/java/org/springframework/data/couchbase/repository/ReactiveCouchbaseRepositoryQueryIntegrationTests.java +++ b/src/test/java/org/springframework/data/couchbase/repository/ReactiveCouchbaseRepositoryQueryIntegrationTests.java @@ -20,7 +20,6 @@ import static org.junit.jupiter.api.Assertions.*; import java.util.List; import java.util.stream.Collectors; -import java.util.stream.StreamSupport; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -29,9 +28,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.data.couchbase.CouchbaseClientFactory; import org.springframework.data.couchbase.config.AbstractCouchbaseConfiguration; import org.springframework.data.couchbase.domain.Airport; -import org.springframework.data.couchbase.domain.AirportRepository; import org.springframework.data.couchbase.domain.ReactiveAirportRepository; -import org.springframework.data.couchbase.repository.config.EnableCouchbaseRepositories; import org.springframework.data.couchbase.repository.config.EnableReactiveCouchbaseRepositories; import org.springframework.data.couchbase.util.Capabilities; import org.springframework.data.couchbase.util.ClusterAwareIntegrationTests; @@ -63,8 +60,7 @@ public class ReactiveCouchbaseRepositoryQueryIntegrationTests extends ClusterAwa Airport vie = new Airport("airports::vie", "vie", "loww"); airportRepository.save(vie).block(); - List all = airportRepository.findAll().toStream() - .collect(Collectors.toList()); + List all = airportRepository.findAll().toStream().collect(Collectors.toList()); assertFalse(all.isEmpty()); assertTrue(all.stream().anyMatch(a -> a.getId().equals("airports::vie"))); diff --git a/src/test/java/org/springframework/data/couchbase/repository/query/N1qlQueryCreatorTests.java b/src/test/java/org/springframework/data/couchbase/repository/query/N1qlQueryCreatorTests.java index 73490452..bd5c2e5e 100644 --- a/src/test/java/org/springframework/data/couchbase/repository/query/N1qlQueryCreatorTests.java +++ b/src/test/java/org/springframework/data/couchbase/repository/query/N1qlQueryCreatorTests.java @@ -16,6 +16,11 @@ package org.springframework.data.couchbase.repository.query; +import static org.junit.jupiter.api.Assertions.*; +import static org.springframework.data.couchbase.core.query.QueryCriteria.*; + +import java.lang.reflect.Method; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.data.couchbase.core.convert.CouchbaseConverter; @@ -33,11 +38,6 @@ import org.springframework.data.repository.query.Parameters; import org.springframework.data.repository.query.ParametersParameterAccessor; import org.springframework.data.repository.query.parser.PartTree; -import java.lang.reflect.Method; - -import static org.junit.jupiter.api.Assertions.*; -import static org.springframework.data.couchbase.core.query.QueryCriteria.*; - class N1qlQueryCreatorTests { MappingContext, CouchbasePersistentProperty> context; @@ -81,4 +81,4 @@ class N1qlQueryCreatorTests { return new DefaultParameters(method); } -} \ No newline at end of file +}