diff --git a/generators/cleanup.js b/generators/cleanup.js
index ccabed28d92a..2b155bad368c 100644
--- a/generators/cleanup.js
+++ b/generators/cleanup.js
@@ -459,6 +459,13 @@ function cleanupOldServerFiles(generator, javaDir, testDir, mainResourceDir, tes
if (generator.searchEngine === 'elasticsearch') {
generator.removeFile(`${testDir}config/ElasticsearchTestConfiguration.java`);
}
+ if (generator.databaseType === 'couchbase') {
+ generator.removeFile(`${javaDir}repository/N1qlCouchbaseRepository.java`);
+ generator.removeFile(`${testDir}config/DatabaseConfigurationIT.java`);
+ if (generator.searchEngine !== 'couchbase') {
+ generator.removeFile(`${javaDir}repository/CustomN1qlCouchbaseRepository.java`);
+ }
+ }
}
if (generator.isJhipsterVersionLessThan('7.0.0-beta.1')) {
generator.removeFile(`${javaDir}config/CloudDatabaseConfiguration.java`);
diff --git a/generators/entity-server/templates/src/main/java/package/domain/Entity.java.ejs b/generators/entity-server/templates/src/main/java/package/domain/Entity.java.ejs
index 39d1f719a4dc..14c4a5c14bfa 100644
--- a/generators/entity-server/templates/src/main/java/package/domain/Entity.java.ejs
+++ b/generators/entity-server/templates/src/main/java/package/domain/Entity.java.ejs
@@ -71,7 +71,7 @@ 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.IdPrefix;
<%_ } _%>
-import com.couchbase.client.java.repository.annotation.Field;
+import org.springframework.data.couchbase.core.mapping.Field;
<%_ if (hasRelationship) { _%>
import org.springframework.data.couchbase.core.query.FetchType;
import org.springframework.data.couchbase.core.query.N1qlJoin;
diff --git a/generators/entity-server/templates/src/main/java/package/repository/EntityRepository.java.ejs b/generators/entity-server/templates/src/main/java/package/repository/EntityRepository.java.ejs
index 4e11663e9f3a..e20c57e11433 100644
--- a/generators/entity-server/templates/src/main/java/package/repository/EntityRepository.java.ejs
+++ b/generators/entity-server/templates/src/main/java/package/repository/EntityRepository.java.ejs
@@ -29,19 +29,24 @@ import org.springframework.data.jpa.repository.*;
<%_ if (relationshipsContainEagerLoad) { _%>
import org.springframework.data.repository.query.Param;
<%_ } _%>
-<%_ } _%>
-<%_ if (databaseType === 'mongodb') { _%>
+<%_ } else if (databaseType === 'mongodb') { _%>
import org.springframework.data.mongodb.repository.Query;
import org.springframework.data.mongodb.repository.MongoRepository;
-<%_ } _%>
-<%_ if (databaseType === 'neo4j') { _%>
+<%_ } else if (databaseType === 'neo4j') { _%>
import org.springframework.data.neo4j.repository.Neo4jRepository;
+<%_ } else if (databaseType === 'couchbase') { _%>
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.domain.Sort;
+import com.couchbase.client.java.query.QueryScanConsistency;
+import org.springframework.data.couchbase.repository.CouchbaseRepository;
+import org.springframework.data.couchbase.repository.ScanConsistency;
<%_ } _%>
<%_ if (searchEngine === 'couchbase') { _%>
import <%= packageName %>.repository.search.SearchCouchbaseRepository;
<%_ } _%>
<%_ if (databaseType === 'couchbase' && relationshipsContainEagerLoad === true) { _%>
-import org.springframework.data.couchbase.core.query.Query;
+import org.springframework.data.couchbase.repository.Query;
<%_ } _%>
<%_ if (databaseType === 'cassandra') { _%>
import org.springframework.data.cassandra.repository.CassandraRepository;
@@ -56,7 +61,7 @@ if (databaseType === 'sql' || databaseType === 'mongodb' || databaseType === 'co
}
}
_%>
- <%_ if (importList) { _%>
+ <%_ if (importList || databaseType === 'couchbase') { _%>
import java.util.List;
<%_ } _%>
<%_ if (relationshipsContainEagerLoad) { _%>
@@ -75,7 +80,7 @@ import java.util.UUID;
@SuppressWarnings("unused")
<%_ } _%>
@Repository
-public interface <%= entityClass %>Repository extends <% if (databaseType === 'sql') { %>JpaRepository<% } %><% if (databaseType === 'mongodb') { %>MongoRepository<% } %><% if (databaseType === 'neo4j') { %>Neo4jRepository<% } %><% if (databaseType === 'cassandra') { %>CassandraRepository<% } %><% if (databaseType === 'couchbase') { %>N1qlCouchbaseRepository<% } %><<%= asEntity(entityClass) %>, <%= primaryKey.type %>><% if (jpaMetamodelFiltering) { %>, JpaSpecificationExecutor<<%= asEntity(entityClass) %>><% } %><% if (searchEngine === 'couchbase') { %>, SearchCouchbaseRepository<<%= asEntity(entityClass) %>, <%= primaryKey.type %>><% } %> {
+public interface <%= entityClass %>Repository extends <% if (databaseType === 'sql') { %>JpaRepository<% } %><% if (databaseType === 'mongodb') { %>MongoRepository<% } %><% if (databaseType === 'neo4j') { %>Neo4jRepository<% } %><% if (databaseType === 'cassandra') { %>CassandraRepository<% } %><% if (databaseType === 'couchbase') { %>CouchbaseRepository<% } %><<%= asEntity(entityClass) %>, <%= primaryKey.type %>><% if (jpaMetamodelFiltering) { %>, JpaSpecificationExecutor<<%= asEntity(entityClass) %>><% } %><% if (searchEngine === 'couchbase') { %>, SearchCouchbaseRepository<<%= asEntity(entityClass) %>, <%= primaryKey.type %>><% } %> {
<%_ for (const relationship of relationships) {
if (relationship.relationshipType === 'many-to-one' && relationship.otherEntityName === 'user' && databaseType === 'sql') { _%>
@@ -107,14 +112,32 @@ public interface <%= entityClass %>Repository extends <% if (databaseType === 's
} else if (databaseType === 'mongodb' || databaseType === 'couchbase') { _%>
@Query("<%= (databaseType === 'mongodb') ? '{}' : '#{#n1ql.selectEntity} WHERE #{#n1ql.filter}' %>")
+ <% if (databaseType === 'couchbase') { %>@ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS)<% } %>
Page<<%= asEntity(entityClass) %>> findAllWithEagerRelationships(Pageable pageable);
@Query("<%= (databaseType === 'mongodb') ? '{}' : '#{#n1ql.selectEntity} WHERE #{#n1ql.filter}' %>")
+ <% if (databaseType === 'couchbase') { %>@ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS)<% } %>
List<<%= asEntity(entityClass) %>> findAllWithEagerRelationships();
@Query("<%- (databaseType === 'mongodb') ? "{'id': ?0}" : "#{#n1ql.selectEntity} USE KEYS $1 WHERE #{#n1ql.filter}" %>")
+ <% if (databaseType === 'couchbase') { %>@ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS)<% } %>
Optional<<%= asEntity(entityClass) %>> findOneWithEagerRelationships(<%= primaryKey.type %> id);
<%_
}
} _%>
+ <%_ if (databaseType === 'couchbase') { _%>
+ @Override
+ // Add ScanConsistency to fix issue with Spring Data Couchbase
+ // https://github.com/spring-projects/spring-data-couchbase/issues/897
+ @ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS)
+ List<<%= asEntity(entityClass) %>> findAll();
+
+ @Override
+ @ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS)
+ List<<%= asEntity(entityClass) %>> findAll(Sort sort);
+
+ @Override
+ @ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS)
+ Page<<%= asEntity(entityClass) %>> findAll(Pageable pageable);
+ <%_ } _%>
}
diff --git a/generators/entity-server/templates/src/main/java/package/repository/EntityRepository_reactive.java.ejs b/generators/entity-server/templates/src/main/java/package/repository/EntityRepository_reactive.java.ejs
index 0fbccaeb6f61..c43ed836b969 100644
--- a/generators/entity-server/templates/src/main/java/package/repository/EntityRepository_reactive.java.ejs
+++ b/generators/entity-server/templates/src/main/java/package/repository/EntityRepository_reactive.java.ejs
@@ -26,8 +26,11 @@ import org.springframework.data.cassandra.repository.ReactiveCassandraRepository
import <%= packageName %>.repository.search.SearchCouchbaseRepository;
<%_ } _%>
<%_ if (databaseType === 'couchbase') { _%>
-import org.springframework.data.couchbase.core.query.Query;
-import org.springframework.data.couchbase.repository.ReactiveCouchbaseSortingRepository;
+import com.couchbase.client.java.query.QueryScanConsistency;
+import org.springframework.data.domain.Sort;
+import org.springframework.data.couchbase.repository.Query;
+import org.springframework.data.repository.reactive.ReactiveSortingRepository;
+import org.springframework.data.couchbase.repository.ScanConsistency;
<%_ } _%>
<%_ if (databaseType === 'neo4j') { _%>
import org.springframework.data.neo4j.repository.ReactiveNeo4jRepository;
@@ -64,7 +67,7 @@ import java.util.UUID;
*/
@SuppressWarnings("unused")
@Repository
-public interface <%= entityClass %>Repository extends <% if (databaseType === 'sql') { %>R2dbc<% } if (databaseType === 'mongodb') { %>ReactiveMongo<% } if (databaseType === 'couchbase') { %>ReactiveN1qlCouchbase<% } if (databaseType === 'neo4j') { %>ReactiveNeo4j<% } if (databaseType === 'cassandra') { %>ReactiveCassandra<% } %>Repository<<%= asEntity(entityClass) %>, <%= primaryKey.type %>><% if (searchEngine === 'couchbase') { %>, SearchCouchbaseRepository<<%= asEntity(entityClass) %>, <%= primaryKey.type %>><% } %><% if (databaseType === 'sql') { %>, <%= entityClass %>RepositoryInternal<% } %> {
+public interface <%= entityClass %>Repository extends <% if (databaseType === 'sql') { %>R2dbc<% } if (databaseType === 'mongodb') { %>ReactiveMongo<% } if (databaseType === 'couchbase') { %>ReactiveSorting<% } if (databaseType === 'neo4j') { %>ReactiveNeo4j<% } if (databaseType === 'cassandra') { %>ReactiveCassandra<% } %>Repository<<%= asEntity(entityClass) %>, <%= primaryKey.type %>><% if (searchEngine === 'couchbase') { %>, SearchCouchbaseRepository<<%= asEntity(entityClass) %>, <%= primaryKey.type %>><% } %><% if (databaseType === 'sql') { %>, <%= entityClass %>RepositoryInternal<% } %> {
<%_ if (pagination !== 'no') { _%>
@@ -74,12 +77,15 @@ public interface <%= entityClass %>Repository extends <% if (databaseType === 's
<%_ if (['couchbase', 'mongodb'].includes(databaseType)) { _%>
@Query("<%= (databaseType === 'mongodb') ? '{}' : '#{#n1ql.selectEntity} WHERE #{#n1ql.filter}' %>")
+ <% if (databaseType === 'couchbase') { %>@ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS)<% } %>
Flux<<%= asEntity(entityClass) %>> findAllWithEagerRelationships(Pageable pageable);
@Query("<%= (databaseType === 'mongodb') ? '{}' : '#{#n1ql.selectEntity} WHERE #{#n1ql.filter}' %>")
+ <% if (databaseType === 'couchbase') { %>@ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS)<% } %>
Flux<<%= asEntity(entityClass) %>> findAllWithEagerRelationships();
@Query("<%- (databaseType === 'mongodb') ? "{'id': ?0}" : "#{#n1ql.selectEntity} USE KEYS $1 WHERE #{#n1ql.filter}" %>")
+ <% if (databaseType === 'couchbase') { %>@ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS)<% } %>
Mono<<%= asEntity(entityClass) %>> findOneWithEagerRelationships(<%= primaryKey.type %> id);
<%_ } _%>
<%_ if (databaseType === 'neo4j') { _%>
@@ -93,6 +99,17 @@ public interface <%= entityClass %>Repository extends <% if (databaseType === 's
Mono<<%= asEntity(entityClass) %>> findOneWithEagerRelationships(<%= primaryKey.type %> id);
<%_ } _%>
<%_ } _%>
+ <%_ if (databaseType === 'couchbase') { _%>
+ // Add ScanConsistency to fix issue with Spring Data Couchbase
+ // https://github.com/spring-projects/spring-data-couchbase/issues/897
+ @Override
+ @ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS)
+ Flux<<%= asEntity(entityClass) %>> findAll();
+
+ @Override
+ @ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS)
+ Flux<<%= asEntity(entityClass) %>> findAll(Sort sort);
+ <%_ } _%>
<%_ if (databaseType === 'sql') {
if (fieldsContainOwnerManyToMany) { _%>
@@ -136,7 +153,7 @@ public interface <%= entityClass %>Repository extends <% if (databaseType === 's
<%_ } _%>
<%_ } _%>
- // just to avoid having unambigous methods
+ // just to avoid having unambiguous methods
@Override
Flux<<%= asEntity(entityClass) %>> findAll();
diff --git a/generators/server/files.js b/generators/server/files.js
index 3d3af18f8b45..97e937d3ccdb 100644
--- a/generators/server/files.js
+++ b/generators/server/files.js
@@ -895,50 +895,72 @@ const serverFiles = {
],
},
{
- condition: generator => !generator.reactive && generator.databaseType === 'couchbase',
+ condition: generator => generator.databaseType === 'couchbase',
path: SERVER_MAIN_SRC_DIR,
templates: [
{
- file: 'package/repository/N1qlCouchbaseRepository.java',
- renameTo: generator => `${generator.javaDir}repository/N1qlCouchbaseRepository.java`,
+ file: 'package/config/couchbase/CustomCouchbaseRepositoryFactory.java',
+ renameTo: generator => `${generator.javaDir}config/couchbase/CustomCouchbaseRepositoryFactory.java`,
+ },
+ {
+ file: 'package/config/couchbase/CustomCouchbaseRepositoryFactoryBean.java',
+ renameTo: generator => `${generator.javaDir}config/couchbase/CustomCouchbaseRepositoryFactoryBean.java`,
+ },
+ {
+ file: 'package/config/couchbase/CustomCouchbaseRepositoryQuery.java',
+ renameTo: generator => `${generator.javaDir}config/couchbase/CustomCouchbaseRepositoryQuery.java`,
+ },
+ {
+ file: 'package/config/couchbase/CustomN1qlQueryCreator.java',
+ renameTo: generator => `${generator.javaDir}config/couchbase/CustomN1qlQueryCreator.java`,
+ },
+ {
+ file: 'package/config/couchbase/CustomN1qlRepositoryQueryExecutor.java',
+ renameTo: generator => `${generator.javaDir}config/couchbase/CustomN1qlRepositoryQueryExecutor.java`,
},
{
- file: 'package/repository/CustomN1qlCouchbaseRepository.java',
- renameTo: generator => `${generator.javaDir}repository/CustomN1qlCouchbaseRepository.java`,
+ file: 'package/config/couchbase/package-info.java',
+ renameTo: generator => `${generator.javaDir}config/couchbase/package-info.java`,
},
],
},
{
- condition: generator => generator.searchEngine === 'couchbase',
+ condition: generator => !generator.reactive && generator.databaseType === 'couchbase',
path: SERVER_MAIN_SRC_DIR,
templates: [
{
- file: 'package/repository/search/SearchCouchbaseRepository.java',
- renameTo: generator => `${generator.javaDir}repository/search/SearchCouchbaseRepository.java`,
+ file: 'package/repository/CustomCouchbaseRepository.java',
+ renameTo: generator => `${generator.javaDir}repository/CustomCouchbaseRepository.java`,
},
],
},
{
- condition: generator => generator.searchEngine === 'couchbase',
- path: SERVER_TEST_SRC_DIR,
+ condition: generator => generator.reactive && generator.databaseType === 'couchbase',
+ path: SERVER_MAIN_SRC_DIR,
templates: [
{
- file: 'package/repository/CustomN1qlCouchbaseRepositoryTest.java',
- renameTo: generator => `${generator.testDir}repository/CustomN1qlCouchbaseRepositoryTest.java`,
+ file: 'package/repository/CustomReactiveCouchbaseRepository.java',
+ renameTo: generator => `${generator.javaDir}repository/CustomReactiveCouchbaseRepository.java`,
},
],
},
{
- condition: generator => generator.reactive && generator.databaseType === 'couchbase',
+ condition: generator => generator.searchEngine === 'couchbase',
path: SERVER_MAIN_SRC_DIR,
templates: [
{
- file: 'package/repository/ReactiveN1qlCouchbaseRepository.java',
- renameTo: generator => `${generator.javaDir}repository/ReactiveN1qlCouchbaseRepository.java`,
+ file: 'package/repository/search/SearchCouchbaseRepository.java',
+ renameTo: generator => `${generator.javaDir}repository/search/SearchCouchbaseRepository.java`,
},
+ ],
+ },
+ {
+ condition: generator => generator.searchEngine === 'couchbase',
+ path: SERVER_TEST_SRC_DIR,
+ templates: [
{
- file: 'package/repository/CustomReactiveN1qlCouchbaseRepository.java',
- renameTo: generator => `${generator.javaDir}repository/CustomReactiveN1qlCouchbaseRepository.java`,
+ file: 'package/repository/CustomCouchbaseRepositoryTest.java',
+ renameTo: generator => `${generator.testDir}repository/CustomCouchbaseRepositoryTest.java`,
},
],
},
@@ -1185,8 +1207,8 @@ const serverFiles = {
path: SERVER_TEST_SRC_DIR,
templates: [
{
- file: 'package/config/DatabaseConfigurationIT.java',
- renameTo: generator => `${generator.testDir}config/DatabaseConfigurationIT.java`,
+ file: 'package/CouchbaseTestContainerExtension.java',
+ renameTo: generator => `${generator.testDir}CouchbaseTestContainerExtension.java`,
},
],
},
diff --git a/generators/server/templates/build.gradle.ejs b/generators/server/templates/build.gradle.ejs
index df48780631a7..08b73a4a6a7b 100644
--- a/generators/server/templates/build.gradle.ejs
+++ b/generators/server/templates/build.gradle.ejs
@@ -501,7 +501,6 @@ dependencies {
<%_ if (databaseType === 'couchbase') { _%>
implementation "com.github.differentway:couchmove"
implementation "com.couchbase.client:java-client"
- implementation "com.couchbase.client:encryption"
<%_ } _%>
implementation ("io.springfox:springfox-oas")
implementation ("io.springfox:springfox-swagger2")
diff --git a/generators/server/templates/pom.xml.ejs b/generators/server/templates/pom.xml.ejs
index 1a126ad29fe6..ab2dc5dc89e8 100644
--- a/generators/server/templates/pom.xml.ejs
+++ b/generators/server/templates/pom.xml.ejs
@@ -365,10 +365,6 @@
com.couchbase.client
java-client
-
- com.couchbase.client
- encryption
-
<%_ } _%>
<%_ if (databaseType === 'neo4j') { _%>
diff --git a/generators/server/templates/src/main/java/package/config/DatabaseConfiguration_couchbase.java.ejs b/generators/server/templates/src/main/java/package/config/DatabaseConfiguration_couchbase.java.ejs
index 4d66976b230a..6183a9b0c62f 100644
--- a/generators/server/templates/src/main/java/package/config/DatabaseConfiguration_couchbase.java.ejs
+++ b/generators/server/templates/src/main/java/package/config/DatabaseConfiguration_couchbase.java.ejs
@@ -20,21 +20,26 @@
package <%= packageName %>.config;
import tech.jhipster.config.JHipsterConstants;
+import tech.jhipster.config.JHipsterProperties;
import com.couchbase.client.java.Bucket;
+import com.couchbase.client.java.Cluster;
import com.github.couchmove.Couchmove;
+<%_ if (searchEngine === 'couchbase') { _%>
import <%= packageName %>.repository.Custom<% if (reactive) { %>Reactive<% } %>N1qlCouchbaseRepository;
-<%_ if (searchEngine === 'elasticsearch') { _%>
-import <%= packageName %>.repository.<% if (reactive) { %>Reactive<% } %>N1qlCouchbaseRepository;
+<%_ } else if (searchEngine === 'elasticsearch') { _%>
+import org.springframework.data.couchbase.repository.<% if (reactive) { %>Reactive<% } %>CouchbaseRepository;
<%_ } _%>
+
+import <%= packageName %>.config.couchbase.CustomCouchbaseRepositoryFactoryBean;
+
import org.apache.commons.codec.binary.Base64;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.boot.autoconfigure.couchbase.CouchbaseAutoConfiguration;
import org.springframework.boot.autoconfigure.couchbase.CouchbaseProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.Import;
<%_ if (searchEngine === 'elasticsearch') { _%>
import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.context.annotation.FilterType;
@@ -46,6 +51,7 @@ import org.springframework.data.elasticsearch.repository.config.Enable<% if (rea
<%_ } _%>
import org.springframework.data.convert.ReadingConverter;
import org.springframework.data.convert.WritingConverter;
+import org.springframework.data.couchbase.config.AbstractCouchbaseConfiguration;
import org.springframework.data.couchbase.config.BeanNames;
import org.springframework.data.couchbase.core.convert.CouchbaseCustomConversions;
import org.springframework.data.couchbase.core.mapping.event.ValidatingCouchbaseEventListener;
@@ -64,22 +70,51 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
+<%_ if (reactive) { _%>
+import java.util.Set;
+import java.lang.reflect.Field;
+import org.springframework.data.repository.util.QueryExecutionConverters;
+import reactor.core.publisher.Flux;
+<%_ } _%>
@Configuration
<%_ if (searchEngine === 'elasticsearch') { _%>
@Enable<% if (reactive) { %>Reactive<% } %>ElasticsearchRepositories("<%= packageName %>.repository.search")
<%_ } _%>
@Profile("!" + JHipsterConstants.SPRING_PROFILE_CLOUD)
-@Enable<% if (reactive) { %>Reactive<% } %>CouchbaseRepositories(repositoryBaseClass = Custom<% if (reactive) { %>Reactive<% } %>N1qlCouchbaseRepository.class, basePackages = "<%= packageName %>.repository"<%_ if (searchEngine === 'elasticsearch') { %>,
- includeFilters = @Filter(type = FilterType.ASSIGNABLE_TYPE, value = <% if (reactive) { %>Reactive<% } %>N1qlCouchbaseRepository.class)<%_ } _%>)
+@Enable<% if (reactive) { %>Reactive<% } %>CouchbaseRepositories(<% if (searchEngine === 'couchbase') { %>repositoryBaseClass = Custom<% if (reactive) { %>Reactive<% } %>CouchbaseRepository.class, <% } %>basePackages = "<%= packageName %>.repository", repositoryFactoryBeanClass = CustomCouchbaseRepositoryFactoryBean.class<%_ if (searchEngine === 'elasticsearch') { %>,
+ includeFilters = @Filter(type = FilterType.ASSIGNABLE_TYPE, value = <% if (reactive) { %>Reactive<% } %>CouchbaseRepository.class)<%_ } _%>)
<%_ if (!reactive) { _%>
-@EnableCouchbaseAuditing(auditorAwareRef = "springSecurityAuditorAware")
+@EnableCouchbaseAuditing(auditorAwareRef = "springSecurityAuditorAware", dateTimeProviderRef = "")
<%_ } _%>
-@Import(value = CouchbaseAutoConfiguration.class)
-public class DatabaseConfiguration {
+public class DatabaseConfiguration extends AbstractCouchbaseConfiguration {
private final Logger log = LoggerFactory.getLogger(DatabaseConfiguration.class);
+ private final JHipsterProperties jHipsterProperties;
+ private final CouchbaseProperties couchbaseProperties;
+
+ public DatabaseConfiguration(JHipsterProperties jHipsterProperties, CouchbaseProperties couchbaseProperties) {
+ this.jHipsterProperties = jHipsterProperties;
+ this.couchbaseProperties = couchbaseProperties;
+ <% if (reactive) { %>allowPageable();<% } %>
+ }
+
+<%_ if (reactive) { _%>
+ // Temporary Hack to fix pageable
+ @SuppressWarnings("unchecked")
+ private void allowPageable() {
+ try {
+ Field allowed_pageable_types = QueryExecutionConverters.class.getDeclaredField("ALLOWED_PAGEABLE_TYPES");
+ allowed_pageable_types.setAccessible(true);
+ Set> ALLOWED_PAGEABLE_TYPES = (Set>) allowed_pageable_types.get(QueryExecutionConverters.class);
+ ALLOWED_PAGEABLE_TYPES.add(Flux.class);
+ } catch (NoSuchFieldException | IllegalAccessException e) {
+ e.printStackTrace();
+ }
+ }
+
+<%_ } _%>
@Bean
public ValidatingCouchbaseEventListener validatingCouchbaseEventListener() {
return new ValidatingCouchbaseEventListener(validator());
@@ -90,6 +125,31 @@ public class DatabaseConfiguration {
return new LocalValidatorFactoryBean();
}
+ @Override
+ public String getConnectionString() {
+ return couchbaseProperties.getConnectionString();
+ }
+
+ @Override
+ public String getUserName() {
+ return couchbaseProperties.getUsername();
+ }
+
+ @Override
+ public String getPassword() {
+ return couchbaseProperties.getPassword();
+ }
+
+ @Override
+ public String getBucketName() {
+ return jHipsterProperties.getDatabase().getCouchbase().getBucketName();
+ }
+
+ @Bean
+ public Bucket bucket(Cluster cluster) {
+ return cluster.bucket(jHipsterProperties.getDatabase().getCouchbase().getBucketName());
+ }
+
@Bean(name = BeanNames.COUCHBASE_CUSTOM_CONVERSIONS)
public CouchbaseCustomConversions customConversions() {
List> converters = new ArrayList<>();
@@ -106,9 +166,9 @@ public class DatabaseConfiguration {
}
@Bean
- public Couchmove couchmove(Bucket couchbaseBucket, CouchbaseProperties properties) {
+ public Couchmove couchmove(Bucket bucket, Cluster cluster) {
log.debug("Configuring Couchmove");
- Couchmove couchmove = new Couchmove(couchbaseBucket, properties.getBucket().getName(), properties.getBucket().getPassword(), "config/couchmove/changelog");
+ Couchmove couchmove = new Couchmove(bucket, cluster, "config/couchmove/changelog");
couchmove.migrate();
return couchmove;
}
@@ -201,9 +261,9 @@ public class DatabaseConfiguration {
}
}
- /**
- * Simple singleton to convert {@link UUID}s to their {@link String} representation.
- */
+ /**
+ * Simple singleton to convert {@link UUID}s to their {@link String} representation.
+ */
@WritingConverter
public enum UUIDToStringConverter implements Converter {
INSTANCE;
@@ -215,8 +275,8 @@ public class DatabaseConfiguration {
}
/**
- * Simple singleton to convert from {@link String} {@link UUID} representation.
- */
+ * Simple singleton to convert from {@link String} {@link UUID} representation.
+ */
@ReadingConverter
public enum StringToUUIDConverter implements Converter {
INSTANCE;
diff --git a/generators/server/templates/src/main/java/package/config/couchbase/CustomCouchbaseRepositoryFactory.java.ejs b/generators/server/templates/src/main/java/package/config/couchbase/CustomCouchbaseRepositoryFactory.java.ejs
new file mode 100644
index 000000000000..431f9a30b322
--- /dev/null
+++ b/generators/server/templates/src/main/java/package/config/couchbase/CustomCouchbaseRepositoryFactory.java.ejs
@@ -0,0 +1,83 @@
+<%#
+ Copyright 2013-2021 the original author or authors from the JHipster project.
+
+ This file is part of the JHipster project, see https://www.jhipster.tech/
+ for more information.
+
+ 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 <%= packageName %>.config.couchbase;
+
+import java.lang.reflect.Method;
+import java.util.Optional;
+import org.springframework.data.couchbase.core.CouchbaseOperations;
+import org.springframework.data.couchbase.repository.config.RepositoryOperationsMapping;
+import org.springframework.data.couchbase.repository.query.CouchbaseQueryMethod;
+import org.springframework.data.couchbase.repository.support.CouchbaseRepositoryFactory;
+import org.springframework.data.mapping.context.MappingContext;
+import org.springframework.data.projection.ProjectionFactory;
+import org.springframework.data.repository.core.NamedQueries;
+import org.springframework.data.repository.core.RepositoryMetadata;
+import org.springframework.data.repository.query.QueryLookupStrategy;
+import org.springframework.data.repository.query.QueryMethodEvaluationContextProvider;
+import org.springframework.data.repository.query.RepositoryQuery;
+
+public class CustomCouchbaseRepositoryFactory extends CouchbaseRepositoryFactory {
+
+ private MappingContext mappingContext;
+ private RepositoryOperationsMapping couchbaseOperationsMapping;
+
+ /**
+ * Create a new factory.
+ *
+ * @param couchbaseOperationsMapping the template for the underlying actions.
+ */
+ public CustomCouchbaseRepositoryFactory(RepositoryOperationsMapping couchbaseOperationsMapping) {
+ super(couchbaseOperationsMapping);
+ this.couchbaseOperationsMapping = couchbaseOperationsMapping;
+ this.mappingContext = this.couchbaseOperationsMapping.getMappingContext();
+ }
+
+ @Override
+ protected Optional getQueryLookupStrategy(
+ QueryLookupStrategy.Key key,
+ QueryMethodEvaluationContextProvider contextProvider
+ ) {
+ return Optional.of(new CustomCouchbaseQueryLookupStrategy(contextProvider));
+ }
+
+ private class CustomCouchbaseQueryLookupStrategy implements QueryLookupStrategy {
+
+ private final QueryMethodEvaluationContextProvider evaluationContextProvider;
+
+ public CustomCouchbaseQueryLookupStrategy(QueryMethodEvaluationContextProvider evaluationContextProvider) {
+ this.evaluationContextProvider = evaluationContextProvider;
+ }
+
+ @Override
+ public RepositoryQuery resolveQuery(
+ final Method method,
+ final RepositoryMetadata metadata,
+ final ProjectionFactory factory,
+ final NamedQueries namedQueries
+ ) {
+ final CouchbaseOperations couchbaseOperations = couchbaseOperationsMapping.resolve(
+ metadata.getRepositoryInterface(),
+ metadata.getDomainType()
+ );
+
+ CouchbaseQueryMethod queryMethod = new CouchbaseQueryMethod(method, metadata, factory, mappingContext);
+ return new CustomCouchbaseRepositoryQuery(couchbaseOperations, queryMethod, namedQueries);
+ }
+ }
+}
diff --git a/generators/server/templates/src/main/java/package/config/couchbase/CustomCouchbaseRepositoryFactoryBean.java.ejs b/generators/server/templates/src/main/java/package/config/couchbase/CustomCouchbaseRepositoryFactoryBean.java.ejs
new file mode 100644
index 000000000000..e146f5eea8bf
--- /dev/null
+++ b/generators/server/templates/src/main/java/package/config/couchbase/CustomCouchbaseRepositoryFactoryBean.java.ejs
@@ -0,0 +1,40 @@
+<%#
+ Copyright 2013-2021 the original author or authors from the JHipster project.
+
+ This file is part of the JHipster project, see https://www.jhipster.tech/
+ for more information.
+
+ 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 <%= packageName %>.config.couchbase;
+
+import org.springframework.data.couchbase.repository.config.RepositoryOperationsMapping;
+import org.springframework.data.couchbase.repository.support.CouchbaseRepositoryFactory;
+import org.springframework.data.couchbase.repository.support.CouchbaseRepositoryFactoryBean;
+
+public class CustomCouchbaseRepositoryFactoryBean extends CouchbaseRepositoryFactoryBean {
+
+ /**
+ * Creates a new {@link CouchbaseRepositoryFactoryBean} for the given repository interface.
+ *
+ * @param repositoryInterface must not be {@literal null}.
+ */
+ public CustomCouchbaseRepositoryFactoryBean(Class repositoryInterface) {
+ super(repositoryInterface);
+ }
+
+ @Override
+ protected CouchbaseRepositoryFactory getFactoryInstance(RepositoryOperationsMapping operationsMapping) {
+ return new CustomCouchbaseRepositoryFactory(operationsMapping);
+ }
+}
diff --git a/generators/server/templates/src/main/java/package/config/couchbase/CustomCouchbaseRepositoryQuery.java.ejs b/generators/server/templates/src/main/java/package/config/couchbase/CustomCouchbaseRepositoryQuery.java.ejs
new file mode 100644
index 000000000000..99f5ae1d77c8
--- /dev/null
+++ b/generators/server/templates/src/main/java/package/config/couchbase/CustomCouchbaseRepositoryQuery.java.ejs
@@ -0,0 +1,44 @@
+<%#
+ Copyright 2013-2021 the original author or authors from the JHipster project.
+
+ This file is part of the JHipster project, see https://www.jhipster.tech/
+ for more information.
+
+ 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 <%= packageName %>.config.couchbase;
+
+import org.springframework.data.couchbase.core.CouchbaseOperations;
+import org.springframework.data.couchbase.repository.query.CouchbaseQueryMethod;
+import org.springframework.data.couchbase.repository.query.CouchbaseRepositoryQuery;
+import org.springframework.data.repository.core.NamedQueries;
+import <%= packageName %>.config.couchbase.CustomN1qlRepositoryQueryExecutor;
+
+public class CustomCouchbaseRepositoryQuery extends CouchbaseRepositoryQuery {
+
+ private CouchbaseOperations couchbaseOperations;
+ private CouchbaseQueryMethod queryMethod;
+ private NamedQueries namedQueries;
+
+ public CustomCouchbaseRepositoryQuery(CouchbaseOperations operations, CouchbaseQueryMethod queryMethod, NamedQueries namedQueries) {
+ super(operations, queryMethod, namedQueries);
+ this.couchbaseOperations = operations;
+ this.queryMethod = queryMethod;
+ this.namedQueries = namedQueries;
+ }
+
+ @Override
+ public Object execute(final Object[] parameters) {
+ return new CustomN1qlRepositoryQueryExecutor(couchbaseOperations, queryMethod, namedQueries).execute(parameters);
+ }
+}
diff --git a/generators/server/templates/src/main/java/package/config/couchbase/CustomN1qlQueryCreator.java.ejs b/generators/server/templates/src/main/java/package/config/couchbase/CustomN1qlQueryCreator.java.ejs
new file mode 100644
index 000000000000..8b4583bbf9d7
--- /dev/null
+++ b/generators/server/templates/src/main/java/package/config/couchbase/CustomN1qlQueryCreator.java.ejs
@@ -0,0 +1,162 @@
+<%#
+ Copyright 2013-2021 the original author or authors from the JHipster project.
+
+ This file is part of the JHipster project, see https://www.jhipster.tech/
+ for more information.
+
+ 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 <%= packageName %>.config.couchbase;
+
+import static org.springframework.data.couchbase.core.query.N1QLExpression.*;
+
+import java.util.Iterator;
+import org.springframework.core.convert.converter.Converter;
+import org.springframework.data.couchbase.core.CouchbaseOperations;
+import org.springframework.data.couchbase.core.convert.CouchbaseConverter;
+import org.springframework.data.couchbase.core.mapping.CouchbasePersistentProperty;
+import org.springframework.data.couchbase.core.query.Query;
+import org.springframework.data.couchbase.core.query.QueryCriteria;
+import org.springframework.data.domain.Sort;
+import org.springframework.data.mapping.PersistentPropertyPath;
+import org.springframework.data.mapping.context.MappingContext;
+import org.springframework.data.repository.query.ParameterAccessor;
+import org.springframework.data.repository.query.QueryMethod;
+import org.springframework.data.repository.query.parser.AbstractQueryCreator;
+import org.springframework.data.repository.query.parser.Part;
+import org.springframework.data.repository.query.parser.PartTree;
+
+public class CustomN1qlQueryCreator extends AbstractQueryCreator {
+
+ private final CouchbaseOperations couchbaseOperations;
+ private final ParameterAccessor accessor;
+ private final MappingContext, CouchbasePersistentProperty> context;
+ private final QueryMethod queryMethod;
+ private final CouchbaseConverter converter;
+
+ public CustomN1qlQueryCreator(
+ final CouchbaseOperations operations,
+ final PartTree tree,
+ final ParameterAccessor accessor,
+ QueryMethod queryMethod,
+ CouchbaseConverter converter
+ ) {
+ super(tree, accessor);
+ this.accessor = accessor;
+ this.context = converter.getMappingContext();
+ this.queryMethod = queryMethod;
+ this.converter = converter;
+ this.couchbaseOperations = operations;
+ }
+
+ static Converter super CouchbasePersistentProperty, String> cvtr = source ->
+ new StringBuilder(source.getFieldName().length() + 2).append('`').append(source.getFieldName()).append('`').toString();
+
+ @Override
+ protected QueryCriteria create(final Part part, final Iterator