Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade Couchbase support for Spring Boot 2.4 #14184

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
c6cac46
Couchbase: Update to Spring Data Couchbase 4.0 and Couchbase SDK 3
murdos May 24, 2020
02b417a
Workaround for DATACOUCH-546 and DATACOUCH-576 bugs
murdos Jun 27, 2020
b106334
Remove generated N1qlCouchbaseRepository in favor of Spring Couchbase…
murdos Jun 27, 2020
7c28f62
Fix deprecated media type
Jan 23, 2021
683806c
Attempt to fix Couchbase CI failure
Jan 30, 2021
658ed1d
Revert to getId() for Couchbase
Jan 30, 2021
5456593
Add version for com.couchbase.client.encryption.
Jan 30, 2021
6f0d31b
Add version to Couchbase java-client
Jan 30, 2021
878bf48
Update imports for Spring Data Couchbase
Jan 30, 2021
fd6516f
Update primaryKey logic based on code review
Jan 30, 2021
52e9f83
Update primaryKey logic based on code review
Jan 30, 2021
fbca067
Fix otherEntity primary key
mshima Jan 30, 2021
e9e23c5
Update class for Spring Data Couchbase
Jan 30, 2021
1a69554
Merge branch 'fix-couchbase' of github.com:mraible/generator-jhipster…
Jan 30, 2021
878bcff
Fix imports
Jan 30, 2021
1ecac87
Remove encryption version since it's managed by jhipster-bom.
Jan 30, 2021
66b9f1e
Remove workarounds for Spring Data Couchbase
Jan 30, 2021
cc06968
Merge branch 'main' of github.com:mraible/generator-jhipster into main
Jan 30, 2021
03b9ac1
Merge branch 'main' of github.com:jhipster/generator-jhipster into main
Jan 30, 2021
74c8264
Merge branch 'main' into fix-couchbase
Jan 30, 2021
8a516e5
Merge branch 'spring-boot-2.3-couchbase' into fix-couchbase
Jan 30, 2021
1957351
Update based on @murdos' spring-boot-2.3-couchbase branch
Jan 30, 2021
c416550
Polishing after testing
Jan 30, 2021
cc978c9
Fix Docker image
Jan 30, 2021
625389b
Fix typo in test
Jan 30, 2021
82e8b59
Fix tests by adding @ScanConsistency to findAll() methods
Jan 30, 2021
f828926
Add @ScanConsistency to all findAll*() methods
Jan 31, 2021
329edf8
Fix Couchbase + reactive so it compiles and runs
Jan 31, 2021
0cbee31
Integrate @mmonti's changes from https://github.com/mraible/ngx-couch…
Feb 4, 2021
a504560
Import `org.springframework.data.domain.Page` for everyone
Feb 4, 2021
c6031f1
Fix javadoc
Feb 4, 2021
99e4507
Updates after code review
Feb 4, 2021
f857f0b
Try to fix reactive couchbase
Feb 4, 2021
a930ad8
Fix User types
Feb 4, 2021
46d6ce1
Fix Couchbase file location test
Feb 5, 2021
226d2b2
Merge branch 'main' into fix-couchbase
Mar 5, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions generators/cleanup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -56,7 +61,7 @@ if (databaseType === 'sql' || databaseType === 'mongodb' || databaseType === 'co
}
}
_%>
<%_ if (importList) { _%>
<%_ if (importList || databaseType === 'couchbase') { _%>
import java.util.List;
<%_ } _%>
<%_ if (relationshipsContainEagerLoad) { _%>
Expand All @@ -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') { _%>

Expand Down Expand Up @@ -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);
<%_ } _%>
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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') { _%>

Expand All @@ -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') { _%>
Expand All @@ -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) { _%>

Expand Down Expand Up @@ -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();

Expand Down
60 changes: 41 additions & 19 deletions generators/server/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
},
],
},
Expand Down Expand Up @@ -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`,
},
],
},
Expand Down
1 change: 0 additions & 1 deletion generators/server/templates/build.gradle.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 0 additions & 4 deletions generators/server/templates/pom.xml.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -365,10 +365,6 @@
<groupId>com.couchbase.client</groupId>
<artifactId>java-client</artifactId>
</dependency>
<dependency>
<groupId>com.couchbase.client</groupId>
<artifactId>encryption</artifactId>
</dependency>
<%_ } _%>
<%_ if (databaseType === 'neo4j') { _%>
<dependency>
Expand Down
Loading