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

Split database repositories #24727

Merged
merged 12 commits into from
Jan 3, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { TestBed } from '@angular/core/testing';
import { HttpErrorResponse } from '@angular/common/http';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';

<%_ if (databaseTypeSql || databaseTypeMongodb || databaseTypeCouchbase) { _%>
<%_ if (generateBuiltInAuthorityEntity) { _%>
import { Authority } from 'app/config/authority.constants';
<%_ } _%>
import { User } from '../user-management.model';
Expand Down Expand Up @@ -60,7 +60,7 @@ describe('User Service', () => {
expect(expectedResult).toEqual('user');
});

<%_ if (databaseTypeSql || databaseTypeMongodb || databaseTypeCouchbase) { _%>
<%_ if (generateBuiltInAuthorityEntity) { _%>
it('should return Authorities', () => {
let expectedResult: string[] = [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
-%>
import { inject, Injectable } from '@angular/core';
import { HttpClient, HttpResponse } from '@angular/common/http';
import { Observable<% if (!authenticationTypeOauth2 && !databaseTypeSql && !databaseTypeMongodb && !databaseTypeCouchbase) { %>, of<% } %> } from 'rxjs';
import { Observable<% if (generateUserManagement && !generateBuiltInAuthorityEntity) { %>, of<% } %> } from 'rxjs';

import { ApplicationConfigService } from 'app/core/config/application-config.service';
import { createRequestOption } from 'app/core/request/request-util';
import { Pagination } from 'app/core/request/request.model';
import { IUser } from '../user-management.model';
<%_ if (!authenticationTypeOauth2 && !databaseTypeSql && !databaseTypeMongodb && !databaseTypeCouchbase) { _%>
<%_ if (generateUserManagement && !generateBuiltInAuthorityEntity) { _%>
import { Authority } from 'app/config/authority.constants';
<%_ } _%>

Expand All @@ -35,7 +35,7 @@ export class UserManagementService {

private resourceUrl = this.applicationConfigService.getEndpointFor('api/admin/users');

<%_ if (!authenticationTypeOauth2) { _%>
<%_ if (generateUserManagement) { _%>
create(user: IUser): Observable<IUser> {
return this.http.post<IUser>(this.resourceUrl, user);
}
Expand All @@ -54,13 +54,13 @@ export class UserManagementService {
return this.http.get<IUser[]>(this.resourceUrl, { params: options, observe: 'response' });
}

<%_ if (!authenticationTypeOauth2) { _%>
<%_ if (generateUserManagement) { _%>
delete(login: string): Observable<{}> {
return this.http.delete(`${this.resourceUrl}/${login}`);
}

authorities(): Observable<string[]> {
<%_ if (databaseTypeSql || databaseTypeMongodb || databaseTypeCouchbase) { _%>
<%_ if (generateBuiltInAuthorityEntity) { _%>
return this.http.get<string[]>(this.applicationConfigService.getEndpointFor('api/authorities'));
<%_ } else { _%>
return of([Authority.ADMIN, Authority.USER]);
Expand Down
16 changes: 0 additions & 16 deletions generators/server/entity-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,6 @@ const filteringReactiveFiles = {
],
};

export const repositoryFiles = {
repositoryFiles: [
{
condition: generator => !generator.reactive && !generator.embedded && generator.databaseType !== COUCHBASE,
...javaMainPackageTemplatesBlock('_entityPackage_/'),
templates: ['repository/_entityClass_Repository.java'],
},
{
condition: generator => generator.reactive && !generator.embedded && generator.databaseType !== COUCHBASE,
...javaMainPackageTemplatesBlock('_entityPackage_/'),
templates: ['repository/_entityClass_Repository_reactive.java'],
},
],
};

export const serviceFiles = {
serviceFiles: [
{
Expand Down Expand Up @@ -184,7 +169,6 @@ export const serverFiles = {
...restFiles,
...filteringFiles,
...filteringReactiveFiles,
...repositoryFiles,
...serviceFiles,
...dtoFiles,
};
Expand Down
21 changes: 13 additions & 8 deletions generators/server/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,19 @@ export default class JHipsterServerGenerator extends BaseApplicationGenerator {
entityConfig.jpaMetamodelFiltering = false;
}
},
configurePagination({ application, entityName, entityConfig }) {
const entityDatabaseType = entityConfig.databaseType ?? application.databaseType;
// disable pagination if there is no database, unless it’s a microservice entity published by a gateway
if (entityDatabaseType === NO_DATABASE && (application.applicationType !== GATEWAY || !entityConfig.microserviceName)) {
const errorMessage = `Pagination is not supported for entity ${entityName} when the app doesn't use a database.`;
if (!this.skipChecks) {
throw new Error(errorMessage);
}

this.log.warn(errorMessage);
entityConfig.pagination = NO_PAGINATION;
}
},
configureEntityTable({ application, entityName, entityConfig }) {
if ((application.applicationTypeGateway && entityConfig.microserviceName) || entityConfig.skipServer) return;

Expand All @@ -526,14 +539,6 @@ export default class JHipsterServerGenerator extends BaseApplicationGenerator {
throw new Error(validation);
}

// disable pagination if there is no database, unless it’s a microservice entity published by a gateway
if (
![SQL, MONGODB, COUCHBASE, NEO4J].includes(entityConfig.databaseType ?? application.databaseType) &&
(application.applicationType !== GATEWAY || !entityConfig.microserviceName)
) {
entityConfig.pagination = NO_PAGINATION;
}

if (entityConfig.incrementalChangelog === undefined) {
// Keep entity's original incrementalChangelog option.
entityConfig.incrementalChangelog =
Expand Down
3 changes: 3 additions & 0 deletions generators/server/templates/README.md.jhi.spring-boot.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
<%_ if (applicationTypeGateway || applicationTypeMicroservice) { _%>

This is a "<%= applicationType %>" application intended to be part of a microservice architecture, please refer to the [Doing microservices with JHipster][] page of the documentation for more information.
<%_ } _%>
<%_ if (serviceDiscoveryAny) { _%>

This application is configured for Service Discovery and Configuration with <% if (serviceDiscoveryEureka) { %>the JHipster-Registry<% } %><% if (serviceDiscoveryConsul) { %>Consul<% } %>. On launch, it will refuse to start if it is not able to connect to <% if (serviceDiscoveryEureka) { %>the JHipster-Registry at [http://localhost:8761](http://localhost:8761)<% } %><% if (serviceDiscoveryConsul) { %>Consul at [http://localhost:8500](http://localhost:8500)<% } %>.<% if (serviceDiscoveryEureka) { %> For more information, read our documentation on [Service Discovery and Configuration with the JHipster-Registry][].<% } %><% if (serviceDiscoveryConsul) { %> For more information, read our documentation on [Service Discovery and Configuration with Consul][].<% } %>
<%_ } _%>

Expand Down
2 changes: 1 addition & 1 deletion generators/spring-data-cassandra/entity-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const entityFiles = {
server: [
{
...javaMainPackageTemplatesBlock('_entityPackage_'),
templates: ['domain/_persistClass_.java.jhi.spring_data_cassandra'],
templates: ['repository/_entityClass_Repository.java', 'domain/_persistClass_.java.jhi.spring_data_cassandra'],
},
],
};
Expand Down
15 changes: 12 additions & 3 deletions generators/spring-data-cassandra/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import { GENERATOR_SPRING_DATA_CASSANDRA, GENERATOR_BOOTSTRAP_APPLICATION } from
import writeCassandraFilesTask from './files.js';
import cleanupCassandraFilesTask from './cleanup.js';
import writeCassandraEntityFilesTask, { cleanupCassandraEntityFilesTask } from './entity-files.js';
import { PaginationTypes } from '../../jdl/jhipster/entity-options.js';

const { NO: NO_PAGINATION } = PaginationTypes;

export default class CassandraGenerator extends BaseApplicationGenerator {
async beforeQueue() {
Expand All @@ -36,9 +39,15 @@ export default class CassandraGenerator extends BaseApplicationGenerator {

get configuringEachEntity() {
return this.asConfiguringEachEntityTaskGroup({
checkEntities({ entityConfig }) {
if (entityConfig.pagination && entityConfig.pagination !== 'no') {
throw new Error("Pagination isn't allowed when the app uses Cassandra.");
checkEntities({ entityName, entityConfig }) {
if (entityConfig.pagination && entityConfig.pagination !== NO_PAGINATION) {
const errorMessage = `Pagination is not supported for entity ${entityName} when the app uses Cassandra.`;
if (!this.skipChecks) {
throw new Error(errorMessage);
}

this.log.warn(errorMessage);
entityConfig.pagination = NO_PAGINATION;
}
},
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<%#
Copyright 2013-2024 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 <%= entityAbsolutePackage %>.repository;

import <%= entityAbsolutePackage %>.domain.<%= persistClass %>;

import org.springframework.data.cassandra.repository.<% if (reactive) { %>Reactive<% } %>CassandraRepository;
import org.springframework.stereotype.Repository;
<%_ if (primaryKey.typeUUID) { _%>

import java.util.UUID;
<%_ } _%>

/**
* <%= springDataDescription %> repository for the <%= persistClass %> entity.
*/
@Repository
public interface <%= entityClass %>Repository extends <% if (reactive) { %>Reactive<% } %>CassandraRepository<<%= persistClass %>, <%= primaryKey.type %>> {
}
Loading
Loading