Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15645 from gkysaad/main
Couchbase SDK 3, Spring Data Couchbase 4 Integration
- Loading branch information
Showing
53 changed files
with
1,259 additions
and
421 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
...ity-server/templates/src/main/java/package/repository/EntityRepository_couchbase.java.ejs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<%# | ||
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 %>.repository; | ||
import <%= packageName %>.domain.<%= persistClass %>; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import com.couchbase.client.java.query.QueryScanConsistency; | ||
import org.springframework.data.couchbase.repository.ScanConsistency; | ||
<%_ if (relationships.length !== 0) { _%> | ||
import org.springframework.data.couchbase.repository.Query; | ||
import org.springframework.data.domain.PageImpl; | ||
import java.util.Optional; | ||
import static <%= packageName %>.repository.N1qlCouchbaseRepository.pageableStatement; | ||
<%_ } _%> | ||
import org.springframework.stereotype.Repository; | ||
<%_ | ||
let importList = fieldsContainOwnerManyToMany; | ||
for (r of relationships) { | ||
if (r.relationshipManyToOne && r.otherEntityUser) { | ||
importList = true; | ||
} | ||
} | ||
_%> | ||
import java.util.List; | ||
<%_ if (relationshipsContainEagerLoad) { _%> | ||
import java.util.Optional; | ||
<%_ } _%> | ||
<%_ if (primaryKey.typeUUID) { _%> | ||
import java.util.UUID; | ||
<%_ } _%> | ||
/** | ||
* Spring Data Couchbase repository for the <%= persistClass %> entity. | ||
*/ | ||
<%_ if (!relationshipsContainEagerLoad) { _%> | ||
@SuppressWarnings("unused") | ||
<%_ } _%> | ||
@Repository | ||
public interface <%= entityClass %>Repository extends N1qlCouchbaseRepository<<%= persistClass %>, <%= primaryKey.type %>><% if (jpaMetamodelFiltering) { %>, JpaSpecificationExecutor<<%= persistClass %>><% } %> { | ||
<%_ | ||
if (relationships.length !== 0) { %> | ||
String SELECT = "SELECT meta(b).id as __id, meta(b).cas as __cas, b.*" + <% | ||
for (const relationship of relationships) { | ||
if (relationship.collection) { | ||
%> ", (SELECT `<%= relationship.relationshipFieldName %>`.*, meta(`<%= relationship.relationshipFieldName %>`).id FROM `<%= relationship.relationshipFieldNamePlural %>` `<%= relationship.relationshipFieldName %>`) as `<%= relationship.relationshipFieldNamePlural %>`" + <% | ||
} else { | ||
%> ", (SELECT `<%= relationship.relationshipFieldName %>`.*, meta(`<%= relationship.relationshipFieldName %>`).id)[0] as `<%= relationship.relationshipFieldName %>`" + <% | ||
} | ||
} %> | ||
" FROM #{#n1ql.bucket} b"; | ||
String JOIN = <% | ||
relationships.forEach(function (relationship, index) { | ||
if (!relationship.collection) { %> | ||
" LEFT JOIN #{#n1ql.bucket} `<%= relationship.relationshipFieldName %>` ON KEYS b.`<%= relationship.relationshipFieldName %>`"<% | ||
} else { %> | ||
" LEFT NEST #{#n1ql.bucket} `<%= relationship.relationshipFieldNamePlural %>` ON KEYS b.`<%= relationship.relationshipFieldNamePlural %>`"<% | ||
} | ||
if (index < relationships.length - 1) { %> | ||
+ <% | ||
} | ||
}); %>; | ||
default Page<<%= persistClass %>> findAll(Pageable pageable) { | ||
return new PageImpl<>( | ||
findAllWithPagination(pageableStatement(pageable, "b")), | ||
pageable, | ||
count() | ||
); | ||
} | ||
@Query(SELECT + JOIN + " WHERE b.#{#n1ql.filter} #{[0]}") | ||
@ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS) | ||
List<<%= persistClass %>> findAllWithPagination(String pageableStatement); | ||
@Query(SELECT + JOIN + " WHERE b.#{#n1ql.filter}") | ||
@ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS) | ||
List<<%= persistClass %>> findAll(); | ||
@Query(SELECT + " USE KEYS $1" + JOIN) | ||
@ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS) | ||
Optional<<%= persistClass %>> findById(String id);<% | ||
} _%> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.