-
-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6706f44
commit afc7d65
Showing
23 changed files
with
667 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -134,6 +134,7 @@ jobs: | |
- oauth2app | ||
- mysqlapp | ||
- mariadbapp | ||
- mssqlapp | ||
- flywayapp | ||
- undertowapp | ||
- eurekaapp | ||
|
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
19 changes: 19 additions & 0 deletions
19
.../lite/generator/server/springboot/database/mssql/application/MssqlApplicationService.java
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,19 @@ | ||
package tech.jhipster.lite.generator.server.springboot.database.mssql.application; | ||
|
||
import org.springframework.stereotype.Service; | ||
import tech.jhipster.lite.generator.project.domain.Project; | ||
import tech.jhipster.lite.generator.server.springboot.database.mssql.domain.MssqlService; | ||
|
||
@Service | ||
public class MssqlApplicationService { | ||
|
||
private final MssqlService mssqlService; | ||
|
||
public MssqlApplicationService(MssqlService mssqlService) { | ||
this.mssqlService = mssqlService; | ||
} | ||
|
||
public void init(Project project) { | ||
mssqlService.init(project); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...main/java/tech/jhipster/lite/generator/server/springboot/database/mssql/domain/Mssql.java
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,43 @@ | ||
package tech.jhipster.lite.generator.server.springboot.database.mssql.domain; | ||
|
||
import java.util.Map; | ||
import java.util.TreeMap; | ||
import tech.jhipster.lite.generator.buildtool.generic.domain.Dependency; | ||
|
||
public class Mssql { | ||
|
||
public static final String MSSQL_DOCKER_IMAGE_NAME = "mcr.microsoft.com/mssql/server"; | ||
|
||
private Mssql() {} | ||
|
||
public static String getDockerImageName() { | ||
return MSSQL_DOCKER_IMAGE_NAME; | ||
} | ||
|
||
public static Dependency driver() { | ||
return Dependency.builder().groupId("com.microsoft.sqlserver").artifactId("mssql-jdbc").build(); | ||
} | ||
|
||
public static Map<String, Object> springProperties(String baseName) { | ||
TreeMap<String, Object> result = new TreeMap<>(); | ||
result.put("spring.datasource.url", "jdbc:sqlserver://localhost:1433;database=" + baseName + ";trustServerCertificate=true"); | ||
result.put("spring.datasource.driver-class-name", "com.microsoft.sqlserver.jdbc.SQLServerDriver"); | ||
result.put("spring.datasource.username", "SA"); | ||
result.put("spring.datasource.password", "yourStrong(!)Password"); | ||
|
||
result.put("spring.jpa.hibernate.ddl-auto", "update"); | ||
result.put("spring.jpa.properties.hibernate.format_sql", true); | ||
result.put("spring.jpa.properties.hibernate.dialect", "org.hibernate.dialect.SQLServer2008Dialect"); | ||
return result; | ||
} | ||
|
||
public static Map<String, Object> springPropertiesForTest(String baseName) { | ||
TreeMap<String, Object> result = new TreeMap<>(); | ||
result.put("spring.datasource.driver-class-name", "org.testcontainers.jdbc.ContainerDatabaseDriver"); | ||
result.put("spring.datasource.url", "jdbc:tc:" + Mssql.getDockerImageName() + ":///" + baseName + ";trustServerCertificate=true"); | ||
result.put("spring.datasource.username", "SA"); | ||
result.put("spring.datasource.password", "yourStrong(!)Password"); | ||
result.put("spring.datasource.hikari.maximum-pool-size", 2); | ||
return result; | ||
} | ||
} |
121 changes: 121 additions & 0 deletions
121
...h/jhipster/lite/generator/server/springboot/database/mssql/domain/MssqlDomainService.java
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,121 @@ | ||
package tech.jhipster.lite.generator.server.springboot.database.mssql.domain; | ||
|
||
import static tech.jhipster.lite.generator.project.domain.DefaultConfig.*; | ||
|
||
import tech.jhipster.lite.error.domain.Assert; | ||
import tech.jhipster.lite.error.domain.GeneratorException; | ||
import tech.jhipster.lite.generator.buildtool.generic.domain.BuildToolService; | ||
import tech.jhipster.lite.generator.docker.domain.DockerService; | ||
import tech.jhipster.lite.generator.project.domain.DatabaseType; | ||
import tech.jhipster.lite.generator.project.domain.Project; | ||
import tech.jhipster.lite.generator.server.springboot.common.domain.Level; | ||
import tech.jhipster.lite.generator.server.springboot.common.domain.SpringBootCommonService; | ||
import tech.jhipster.lite.generator.server.springboot.database.sqlcommon.domain.SQLCommonService; | ||
|
||
public class MssqlDomainService implements MssqlService { | ||
|
||
private final BuildToolService buildToolService; | ||
private final SpringBootCommonService springBootCommonService; | ||
private final SQLCommonService sqlCommonService; | ||
private final DockerService dockerService; | ||
|
||
public MssqlDomainService( | ||
BuildToolService buildToolService, | ||
SpringBootCommonService springBootCommonService, | ||
SQLCommonService sqlCommonService, | ||
DockerService dockerService | ||
) { | ||
this.buildToolService = buildToolService; | ||
this.springBootCommonService = springBootCommonService; | ||
this.sqlCommonService = sqlCommonService; | ||
this.dockerService = dockerService; | ||
} | ||
|
||
@Override | ||
public void init(Project project) { | ||
Assert.notNull("project", project); | ||
|
||
addSpringData(project); | ||
addDriver(project); | ||
addDockerCompose(project); | ||
addJavaFiles(project); | ||
addHikari(project); | ||
addProperties(project); | ||
addHibernateCore(project); | ||
addTestcontainers(project); | ||
addLoggerInConfiguration(project); | ||
} | ||
|
||
@Override | ||
public void addSpringData(Project project) { | ||
sqlCommonService.addSpringDataJpa(project); | ||
} | ||
|
||
@Override | ||
public void addDriver(Project project) { | ||
buildToolService.addDependency(project, Mssql.driver()); | ||
} | ||
|
||
@Override | ||
public void addDockerCompose(Project project) { | ||
project.addDefaultConfig(BASE_NAME); | ||
|
||
dockerService | ||
.getImageNameWithVersion(Mssql.getDockerImageName()) | ||
.ifPresentOrElse( | ||
imageName -> project.addConfig("dockerImageName", imageName), | ||
() -> { | ||
throw new GeneratorException("Version not found for docker image: " + Mssql.getDockerImageName()); | ||
} | ||
); | ||
sqlCommonService.addDockerComposeTemplate(project, DatabaseType.MSSQL.id()); | ||
} | ||
|
||
@Override | ||
public void addHikari(Project project) { | ||
sqlCommonService.addHikari(project); | ||
} | ||
|
||
@Override | ||
public void addJavaFiles(Project project) { | ||
sqlCommonService.addJavaFiles(project, DatabaseType.MSSQL.id()); | ||
} | ||
|
||
@Override | ||
public void addProperties(Project project) { | ||
springBootCommonService.addPropertiesComment(project, "Database Configuration"); | ||
|
||
Mssql | ||
.springProperties(project.getBaseName().orElse("jhipster")) | ||
.forEach((k, v) -> springBootCommonService.addProperties(project, k, v)); | ||
springBootCommonService.addPropertiesNewLine(project); | ||
} | ||
|
||
private void addTestcontainers(Project project) { | ||
this.sqlCommonService.addTestcontainers( | ||
project, | ||
DatabaseType.MSSQL.id(), | ||
Mssql.springPropertiesForTest(project.getBaseName().orElse("jhipster")) | ||
); | ||
} | ||
|
||
@Override | ||
public void addHibernateCore(Project project) { | ||
sqlCommonService.addHibernateCore(project); | ||
} | ||
|
||
@Override | ||
public void addLoggerInConfiguration(Project project) { | ||
sqlCommonService.addLoggers(project); | ||
addLogger(project, "org.reflections", Level.WARN); | ||
addLogger(project, Mssql.driver().getGroupId(), Level.WARN); | ||
|
||
springBootCommonService.addLoggerTest(project, "com.github.dockerjava", Level.WARN); | ||
springBootCommonService.addLoggerTest(project, "org.testcontainers", Level.WARN); | ||
} | ||
|
||
public void addLogger(Project project, String packageName, Level level) { | ||
springBootCommonService.addLogger(project, packageName, level); | ||
springBootCommonService.addLoggerTest(project, packageName, level); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...va/tech/jhipster/lite/generator/server/springboot/database/mssql/domain/MssqlService.java
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,16 @@ | ||
package tech.jhipster.lite.generator.server.springboot.database.mssql.domain; | ||
|
||
import tech.jhipster.lite.generator.project.domain.Project; | ||
|
||
public interface MssqlService { | ||
void init(Project project); | ||
|
||
void addSpringData(Project project); | ||
void addDriver(Project project); | ||
void addHikari(Project project); | ||
void addHibernateCore(Project project); | ||
void addDockerCompose(Project project); | ||
void addJavaFiles(Project project); | ||
void addProperties(Project project); | ||
void addLoggerInConfiguration(Project project); | ||
} |
36 changes: 36 additions & 0 deletions
36
...erator/server/springboot/database/mssql/infrastructure/config/MssqlBeanConfiguration.java
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,36 @@ | ||
package tech.jhipster.lite.generator.server.springboot.database.mssql.infrastructure.config; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import tech.jhipster.lite.generator.buildtool.generic.domain.BuildToolService; | ||
import tech.jhipster.lite.generator.docker.domain.DockerService; | ||
import tech.jhipster.lite.generator.server.springboot.common.domain.SpringBootCommonService; | ||
import tech.jhipster.lite.generator.server.springboot.database.mssql.domain.MssqlDomainService; | ||
import tech.jhipster.lite.generator.server.springboot.database.mssql.domain.MssqlService; | ||
import tech.jhipster.lite.generator.server.springboot.database.sqlcommon.domain.SQLCommonService; | ||
|
||
@Configuration | ||
public class MssqlBeanConfiguration { | ||
|
||
private final BuildToolService buildToolService; | ||
private final SpringBootCommonService springBootCommonService; | ||
private final SQLCommonService sqlCommonService; | ||
private final DockerService dockerService; | ||
|
||
public MssqlBeanConfiguration( | ||
BuildToolService buildToolService, | ||
SpringBootCommonService springBootCommonService, | ||
SQLCommonService sqlCommonService, | ||
DockerService dockerService | ||
) { | ||
this.buildToolService = buildToolService; | ||
this.springBootCommonService = springBootCommonService; | ||
this.sqlCommonService = sqlCommonService; | ||
this.dockerService = dockerService; | ||
} | ||
|
||
@Bean | ||
public MssqlService mssqlService() { | ||
return new MssqlDomainService(buildToolService, springBootCommonService, sqlCommonService, dockerService); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...generator/server/springboot/database/mssql/infrastructure/primary/rest/MssqlResource.java
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,35 @@ | ||
package tech.jhipster.lite.generator.server.springboot.database.mssql.infrastructure.primary.rest; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import tech.jhipster.lite.generator.project.domain.GeneratorAction; | ||
import tech.jhipster.lite.generator.project.domain.Project; | ||
import tech.jhipster.lite.generator.project.infrastructure.primary.dto.ProjectDTO; | ||
import tech.jhipster.lite.generator.server.springboot.database.mssql.application.MssqlApplicationService; | ||
import tech.jhipster.lite.technical.infrastructure.primary.annotation.GeneratorStep; | ||
|
||
@RestController | ||
@RequestMapping("/api/servers/spring-boot/databases/mssql") | ||
@Tag(name = "Spring Boot - Database") | ||
class MssqlResource { | ||
|
||
private final MssqlApplicationService mongodbApplicationService; | ||
|
||
public MssqlResource(MssqlApplicationService mongodbApplicationService) { | ||
this.mongodbApplicationService = mongodbApplicationService; | ||
} | ||
|
||
@Operation(summary = "Add MSSQL drivers and dependencies, with testcontainers") | ||
@ApiResponse(responseCode = "500", description = "An error occurred while adding MSSQL") | ||
@PostMapping | ||
@GeneratorStep(id = GeneratorAction.MSSQL) | ||
public void init(@RequestBody ProjectDTO projectDTO) { | ||
Project project = ProjectDTO.toProject(projectDTO); | ||
mongodbApplicationService.init(project); | ||
} | ||
} |
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
10 changes: 10 additions & 0 deletions
10
...rces/generator/server/springboot/database/mssqlserver/DatabaseConfiguration.java.mustache
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,10 @@ | ||
package {{packageName}}.technical.infrastructure.secondary.mariadb; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories; | ||
import org.springframework.transaction.annotation.EnableTransactionManagement; | ||
|
||
@Configuration | ||
@EnableJpaRepositories({ "{{packageName}}" }) | ||
@EnableTransactionManagement | ||
public class DatabaseConfiguration {} |
18 changes: 18 additions & 0 deletions
18
src/main/resources/generator/server/springboot/database/mssqlserver/mssqlserver.yml.mustache
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,18 @@ | ||
# This configuration is intended for development purpose, it's **your** responsibility to harden it for production | ||
version: '2' | ||
services: | ||
msmssql-mssql: | ||
image: {{dockerImageName}} | ||
# volumes: | ||
# - ~/volumes/jhipster/{{baseName}}/mssql/:/var/lib/mssql/ | ||
environment: | ||
- ACCEPT_EULA=Y | ||
- SA_PASSWORD=yourStrong(!)Password | ||
- MSSQL_DATABASE={{baseName}} | ||
- MSSQL_PID=Express | ||
- MSSQL_SLEEP=60 | ||
# If you want to expose these ports outside your dev PC, | ||
# remove the "127.0.0.1:" prefix | ||
ports: | ||
- 127.0.0.1:1433:1433 | ||
command: /bin/bash -c '/opt/mssql/bin/sqlservr & echo "wait $$MSSQL_SLEEP sec for DB to start "; sleep $$MSSQL_SLEEP; /opt/mssql-tools/bin/sqlcmd -U sa -P $$SA_PASSWORD -d tempdb -q "EXIT(CREATE DATABASE $$MSSQL_DATABASE)"; wait;' |
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.