-
-
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
8025281
commit 5931c0f
Showing
24 changed files
with
697 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); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...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,47 @@ | ||
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"; | ||
public static final String LICENSE_TEST_CONTAINER_FILE = "container-license-acceptance.txt"; | ||
|
||
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.SQLServer2012Dialect"); | ||
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:sqlserver:latest://;database=" + baseName + ";trustServerCertificate=true?TC_TMPFS=/testtmpfs:rw" | ||
); | ||
result.put("spring.datasource.username", "SA"); | ||
result.put("spring.datasource.password", "yourStrong(!)Password"); | ||
result.put("spring.datasource.hikari.maximum-pool-size", 2); | ||
return result; | ||
} | ||
} |
132 changes: 132 additions & 0 deletions
132
...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,132 @@ | ||
package tech.jhipster.lite.generator.server.springboot.database.mssql.domain; | ||
|
||
import static tech.jhipster.lite.generator.project.domain.Constants.*; | ||
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.project.domain.ProjectFile; | ||
import tech.jhipster.lite.generator.project.domain.ProjectRepository; | ||
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 { | ||
|
||
public static final String SOURCE = "server/sql"; | ||
|
||
private final BuildToolService buildToolService; | ||
private final SpringBootCommonService springBootCommonService; | ||
private final SQLCommonService sqlCommonService; | ||
private final DockerService dockerService; | ||
private final ProjectRepository projectRepository; | ||
|
||
public MssqlDomainService( | ||
BuildToolService buildToolService, | ||
SpringBootCommonService springBootCommonService, | ||
SQLCommonService sqlCommonService, | ||
DockerService dockerService, | ||
ProjectRepository projectRepository | ||
) { | ||
this.buildToolService = buildToolService; | ||
this.springBootCommonService = springBootCommonService; | ||
this.sqlCommonService = sqlCommonService; | ||
this.dockerService = dockerService; | ||
this.projectRepository = projectRepository; | ||
} | ||
|
||
@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")) | ||
); | ||
this.projectRepository.add( | ||
ProjectFile.forProject(project).withSource(SOURCE, Mssql.LICENSE_TEST_CONTAINER_FILE).withDestinationFolder(TEST_RESOURCES) | ||
); | ||
} | ||
|
||
@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); | ||
} |
40 changes: 40 additions & 0 deletions
40
...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,40 @@ | ||
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.project.domain.ProjectRepository; | ||
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; | ||
private final ProjectRepository projectRepository; | ||
|
||
public MssqlBeanConfiguration( | ||
BuildToolService buildToolService, | ||
SpringBootCommonService springBootCommonService, | ||
SQLCommonService sqlCommonService, | ||
DockerService dockerService, | ||
ProjectRepository projectRepository | ||
) { | ||
this.buildToolService = buildToolService; | ||
this.springBootCommonService = springBootCommonService; | ||
this.sqlCommonService = sqlCommonService; | ||
this.dockerService = dockerService; | ||
this.projectRepository = projectRepository; | ||
} | ||
|
||
@Bean | ||
public MssqlService mssqlService() { | ||
return new MssqlDomainService(buildToolService, springBootCommonService, sqlCommonService, dockerService, projectRepository); | ||
} | ||
} |
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.mssqlserver; | ||
|
||
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;' |
1 change: 1 addition & 0 deletions
1
src/main/resources/generator/server/sql/container-license-acceptance.txt
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 @@ | ||
mcr.microsoft.com/mssql/server:latest |
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.