Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
gkysaad committed Jul 14, 2021
1 parent eada912 commit 3c8c090
Show file tree
Hide file tree
Showing 34 changed files with 1,287 additions and 263 deletions.
8 changes: 4 additions & 4 deletions generators/cleanup.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,16 +483,16 @@ function cleanupOldServerFiles(generator, javaDir, testDir, mainResourceDir, tes
if (generator.searchEngine === 'elasticsearch') {
generator.removeFile(`${testDir}config/ElasticsearchTestConfiguration.java`);
}
}
if (generator.isJhipsterVersionLessThan('7.0.0-beta.1')) {
generator.removeFile(`${javaDir}config/CloudDatabaseConfiguration.java`);
if (generator.databaseType === 'couchbase') {
generator.removeFile(`${javaDir}repository/N1qlCouchbaseRepository.java`);
generator.removeFile(`${testDir}config/DatabaseConfigurationIT.java`);
if (generator.searchEngine !== 'couchbase') {
generator.removeFile(`${javaDir}Frepository/CustomN1qlCouchbaseRepository.java`);
generator.removeFile(`${javaDir}Frepository/CustomN1qlCouchbaseRepository.java`);
}
}
}
if (generator.isJhipsterVersionLessThan('7.0.0-beta.1')) {
generator.removeFile(`${javaDir}config/CloudDatabaseConfiguration.java`);
}
}

Expand Down
4 changes: 2 additions & 2 deletions generators/entity-server/templates/partials/save_template.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const mapper = entityInstance + 'Mapper';
const dtoToEntity = mapper + '.' + 'toEntity';
const entityToDto = mapper + '.' + 'toDto';
const entityToDtoReference = mapper + '::' + 'toDto';
const returnPrefix = (returnDirectly && !searchEngine) ? 'return' : instanceType + ' result =';
const returnPrefix = (returnDirectly && searchEngine !== 'elasticsearch') ? 'return' : instanceType + ' result =';
let resultEntity;
let mapsIdEntityInstance;
let mapsIdRepoInstance;
Expand Down Expand Up @@ -56,7 +56,7 @@ if (isUsingMapsId) {
<%_ } _%>
<%= returnPrefix %> <%= entityInstance %>Repository.save(<%= persistInstance %>);
<%_ } _%>
<%_ if (searchEngine) { _%>
<%_ if (searchEngine === 'elasticsearch') { _%>
<%= entityInstance %>SearchRepository.save(<%= resultEntity %>);
<%_ if (returnDirectly) { _%>
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,12 @@ public class <%= persistClass %> implements Serializable {
@Column(name = "<%- fieldNameAsDatabaseColumn %>"<% if (fieldValidate === true) { %><% if (field.fieldValidationMaxLength) { %>, length = <%= fieldValidateRulesMaxlength %><% } %><% if (required) { %>, nullable = false<% } %><% if (unique) { %>, unique = true<% } %><% } %>)
<%_ } _%>
<%_ } _%>
<%_ if (databaseTypeMongodb || databaseTypeCouchbase) { _%>
<%_ if (databaseTypeMongodb) { _%>
@Field("<%= fieldNameUnderscored %>")
<%_ } _%>
<%_ } _%>
<%_ if (databaseTypeCouchbase) { _%>
@Field
<%_ } _%>
<%_ if (databaseTypeNeo4j) { _%>
@Property("<%=fieldNameUnderscored %>")
<%_ } _%>
Expand All @@ -273,10 +276,13 @@ public class <%= persistClass %> implements Serializable {
@NotNull
<%_ } _%>
<%_ } _%>
<%_ if (databaseTypeMongodb || databaseTypeCouchbase) { _%>
<%_ if (databaseTypeMongodb) { _%>
@Field("<%= fieldNameUnderscored %>_content_type")
<%_ } _%>
<%_ if (databaseTypeNeo4j) { _%>
<%_ } _%>
<%_ if (databaseTypeCouchbase) { _%>
@Field
<%_ } _%>
<%_ if (databaseTypeNeo4j) { _%>
@Property("<%=fieldNameUnderscored %>_content_type")
<%_ } _%>
private String <%= fieldName %>ContentType;
Expand Down Expand Up @@ -322,13 +328,15 @@ public class <%= persistClass %> implements Serializable {
@OneToMany(mappedBy = "<%= otherEntityRelationshipName %>")
<%_ if (enableHibernateCache) { _%>
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
<%_ } _%>
<%_ } else if (databaseTypeMongodb || databaseTypeCouchbase) {
if (databaseTypeMongodb && !otherEntityIsEmbedded) { _%>
<%_ }
} else if (databaseTypeMongodb) {
if (!otherEntityIsEmbedded) { _%>
@DBRef
<%_ } _%>
<%_ } _%>
@Field("<%= relationshipFieldName %>")
<%_ if (databaseTypeCouchbase && !otherEntityIsEmbedded) { _%>
<%_ } else if (databaseTypeCouchbase) { _%>
@Field
<%_ if (!otherEntityIsEmbedded) { _%>
private Set<String> <%= relationshipFieldName %>Ids = new HashSet<>();
@N1qlJoin(on = "lks.<%= relationshipFieldName %>=meta(rks).id", fetchType = FetchType.IMMEDIATE)
Expand Down Expand Up @@ -356,9 +364,10 @@ public class <%= persistClass %> implements Serializable {
<%_ } else if ((databaseTypeMongodb || databaseTypeCouchbase) && !otherEntityIsEmbedded) {
if (databaseTypeMongodb) { _%>
@DBRef
<%_ } _%>
@Field("<%= relationshipFieldName %>")
<%_ if (databaseTypeCouchbase) { _%>
<%_ } _%>
<%_ if (databaseTypeCouchbase) { _%>
@Field
private String <%= relationshipFieldName %>Id;
@N1qlJoin(on = "lks.<%= relationshipFieldName %>=meta(rks).id", fetchType = FetchType.IMMEDIATE)
Expand Down Expand Up @@ -411,9 +420,10 @@ public class <%= persistClass %> implements Serializable {
<%_ } else if ((databaseTypeMongodb || databaseTypeCouchbase) && !otherEntityIsEmbedded) { _%>
<%_ if (databaseTypeMongodb) { _%>
@DBRef
<%_ } _%>
@Field("<%= relationshipFieldNamePlural %>")
<%_ if (databaseTypeCouchbase) { _%>
<%_ } _%>
<%_ if (databaseTypeCouchbase) { _%>
@Field
private Set<String> <%= relationshipFieldName %>Ids = new HashSet<>();
@N1qlJoin(on = "lks.<%= relationshipFieldNamePlural %>=meta(rks).id", fetchType = FetchType.IMMEDIATE)
Expand Down Expand Up @@ -461,9 +471,9 @@ public class <%= persistClass %> implements Serializable {
<%_ } else if ((databaseTypeMongodb || databaseTypeCouchbase) && !otherEntityIsEmbedded) { _%>
<%_ if (databaseTypeMongodb) { _%>
@DBRef
<%_ } _%>
@Field("<%= relationshipFieldName %>")
<%_ if (databaseTypeCouchbase) { _%>
<%_ } if (databaseTypeCouchbase) { _%>
@Field
private String <%= relationshipFieldName %>Id;
@N1qlJoin(on = "lks.<%= relationshipFieldName %>=meta(rks).id", fetchType = FetchType.IMMEDIATE)
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 (databaseTypeMongodb) { _%>
<%_} else if (databaseTypeMongodb) { _%>
import org.springframework.data.mongodb.repository.Query;
import org.springframework.data.mongodb.repository.MongoRepository;
<%_ } _%>
<%_ if (databaseTypeNeo4j) { _%>
<%_} else if (databaseTypeNeo4j) { _%>
import org.springframework.data.neo4j.repository.Neo4jRepository;
<%_} else if (databaseTypeCouchbase) { _%>
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 (databaseTypeCouchbase) { _%>
<%_ if (searchEngineCouchbase) { _%>
import <%= packageName %>.repository.search.SearchCouchbaseRepository;
<%_ if (relationshipsContainEagerLoad) { _%>
<%_ } _%>
<%_ if (relationshipsContainEagerLoad && databaseTypeCouchbase) { _%>
import org.springframework.data.couchbase.repository.Query;
<%_ } _%>
<%_ } _%>
<%_ if (databaseTypeCassandra) { _%>
import org.springframework.data.cassandra.repository.CassandraRepository;
Expand All @@ -56,7 +61,7 @@ if (databaseTypeSql || databaseTypeMongodb || databaseTypeCouchbase) {
}
}
_%>
<%_ if (importList) { _%>
<%_ if (importList || databaseTypeCouchbase) { _%>
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 (databaseTypeSql) { %>JpaRepository<% } %><% if (databaseTypeMongodb) { %>MongoRepository<% } %><% if (databaseTypeNeo4j) { %>Neo4jRepository<% } %><% if (databaseTypeCassandra) { %>CassandraRepository<% } %><% if (databaseTypeCouchbase) { %>N1qlCouchbaseRepository<% } %><<%= persistClass %>, <%= primaryKey.type %>><% if (jpaMetamodelFiltering) { %>, JpaSpecificationExecutor<<%= persistClass %>><% } %><% if (searchEngineCouchbase) { %>, SearchCouchbaseRepository<<%= persistClass %>, <%= primaryKey.type %>><% } %> {
public interface <%= entityClass %>Repository extends <% if (databaseTypeSql) { %>JpaRepository<% } %><% if (databaseTypeMongodb) { %>MongoRepository<% } %><% if (databaseTypeNeo4j) { %>Neo4jRepository<% } %><% if (databaseTypeCassandra) { %>CassandraRepository<% } %><% if (databaseTypeCouchbase) { %>CouchbaseRepository<% } %><<%= persistClass %>, <%= primaryKey.type %>><% if (jpaMetamodelFiltering) { %>, JpaSpecificationExecutor<<%= persistClass %>><% } %><% if (searchEngineCouchbase) { %>, SearchCouchbaseRepository<<%= persistClass %>, <%= primaryKey.type %>><% } %> {
<%_
for (const relationship of relationships) {
if (relationship.relationshipManyToOne && relationship.otherEntityUser && databaseTypeSql) { _%>
Expand Down Expand Up @@ -118,6 +123,21 @@ public interface <%= entityClass %>Repository extends <% if (databaseTypeSql) {
@Query("<%- (databaseTypeMongodb) ? "{'id': ?0}" : "#{#n1ql.selectEntity} USE KEYS $1 WHERE #{#n1ql.filter}" %>")
Optional<<%= persistClass %>> findOneWithEagerRelationships(<%= primaryKey.type %> id);
<%_
}
} _%>
}
} _%>
<%_ if (databaseTypeCouchbase) { _%>
@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<<%= persistClass %>> findAll();

@Override
@ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS)
List<<%= persistClass %>> findAll(Sort sort);

@Override
@ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS)
Page<<%= persistClass %>> 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 (databaseTypeCouchbase) { _%>
import com.couchbase.client.java.query.QueryScanConsistency;
import org.springframework.data.domain.Sort;
import org.springframework.data.couchbase.repository.Query;
import org.springframework.data.couchbase.repository.ReactiveCouchbaseSortingRepository;
import org.springframework.data.repository.reactive.ReactiveSortingRepository;
import org.springframework.data.couchbase.repository.ScanConsistency;
<%_ } _%>
<%_ if (databaseTypeNeo4j) { _%>
import org.springframework.data.neo4j.repository.ReactiveNeo4jRepository;
Expand Down Expand Up @@ -74,12 +77,15 @@ public interface <%= entityClass %>Repository extends <% if (databaseTypeSql) {
<%_ if (databaseTypeCouchbase || databaseTypeMongodb) { _%>
@Query("<%= (databaseTypeMongodb) ? '{}' : '#{#n1ql.selectEntity} WHERE #{#n1ql.filter}' %>")
<% if (databaseTypeCouchbase) { %>@ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS)<% } %>
Flux<<%= persistClass %>> findAllWithEagerRelationships(Pageable pageable);
@Query("<%= (databaseTypeMongodb) ? '{}' : '#{#n1ql.selectEntity} WHERE #{#n1ql.filter}' %>")
<% if (databaseTypeCouchbase) { %>@ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS)<% } %>
Flux<<%= persistClass %>> findAllWithEagerRelationships();
@Query("<%- (databaseTypeMongodb) ? "{'id': ?0}" : "#{#n1ql.selectEntity} USE KEYS $1 WHERE #{#n1ql.filter}" %>")
<% if (databaseTypeCouchbase) { %>@ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS)<% } %>
Mono<<%= persistClass %>> findOneWithEagerRelationships(<%= primaryKey.type %> id);
<%_ } _%>
<%_ if (databaseTypeNeo4j) { _%>
Expand All @@ -93,8 +99,18 @@ public interface <%= entityClass %>Repository extends <% if (databaseTypeSql) {
Mono<<%= persistClass %>> findOneWithEagerRelationships(<%= primaryKey.type %> id);
<%_ } _%>
<%_ } _%>
<%_
if (databaseTypeSql) {
<%_ if (databaseTypeCouchbase) { _%>
// 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 (databaseTypeSql) {
if (fieldsContainOwnerManyToMany) { _%>
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@
}
},
"sourceType": "couchbase",
"sourceName": "${bucket}"
"sourceName": "${bucket}",
"name": "<%= entityClass %>"
}
Original file line number Diff line number Diff line change
Expand Up @@ -1739,7 +1739,8 @@ _%>
<%_ } else if (searchEngineCouchbase) { _%>

// Wait for the <%= entityInstance %> to be indexed
TestUtil.retryUntilNotEmpty(() -> <%= entityInstance %>Repository.search(<%= entityClass %>.PREFIX, "id:" + <%= entityInstance %>.get<%= primaryKey.nameCapitalized %>())<% if (reactive) { %>.collectList().block()<% } %>);
// TestUtil.retryUntilNotEmpty(() -> <%= entityInstance %>Repository.search(<%= entityClass %>.PREFIX, "id:" + <%= entityInstance %>.get<%= primaryKey.nameCapitalized %>())<% if (reactive) { %>.collectList().block()<% } %>);
<%= entityInstance %>Repository.search(<%= entityClass %>.PREFIX, "id:" + <%= entityInstance %>.get<%= primaryKey.nameCapitalized %>())<% if (reactive) { %>.collectList().block()<% } %>;
<%_ } _%>
// Search the <%= entityInstance %>
Expand Down
Loading

0 comments on commit 3c8c090

Please sign in to comment.