Skip to content

Commit

Permalink
Migrate mssql domain service to new module system
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielFran committed Jul 6, 2022
1 parent 6fb0ad9 commit ebf205d
Show file tree
Hide file tree
Showing 20 changed files with 215 additions and 579 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public enum DatabaseType {
MYSQL("mysql"),
MARIADB("mariadb"),
ORACLE("oracle"),
MSSQL("mssqlserver"),
MSSQL("mssql"),
MONGODB("mongodb"),
CASSANDRA("cassandra"),
COUCHBASE("couchbase"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package tech.jhipster.lite.generator.server.springboot.database.mssql.domain;

import static tech.jhipster.lite.generator.server.springboot.core.domain.SpringBoot.NEEDLE_LOGBACK_LOGGER;
import static tech.jhipster.lite.generator.server.springboot.database.sqlcommon.domain.SQLCommonModuleBuilder.logger;
import static tech.jhipster.lite.generator.server.springboot.database.sqlcommon.domain.SQLCommonModuleBuilder.sqlCommonModuleBuilder;
import static tech.jhipster.lite.module.domain.JHipsterModule.*;

import tech.jhipster.lite.docker.domain.DockerImage;
import tech.jhipster.lite.docker.domain.DockerImages;
import tech.jhipster.lite.error.domain.Assert;
import tech.jhipster.lite.generator.project.domain.DatabaseType;
import tech.jhipster.lite.generator.server.springboot.common.domain.Level;
import tech.jhipster.lite.module.domain.JHipsterModule;
import tech.jhipster.lite.module.domain.JHipsterSource;
import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties;

public class MsSQLModuleFactory {

private static final String DEST_SECONDARY = "technical/infrastructure/secondary/mssql";

private final DockerImages dockerImages;

public MsSQLModuleFactory(DockerImages dockerImages) {
Assert.notNull("dockerImages", dockerImages);

this.dockerImages = dockerImages;
}

public JHipsterModule buildModule(JHipsterModuleProperties properties) {
Assert.notNull("properties", properties);

DockerImage dockerImage = dockerImages.get("mcr.microsoft.com/mssql/server");
JHipsterSource source = from("server/springboot/database/" + DatabaseType.MSSQL.id());

return sqlCommonModuleBuilder(properties, DatabaseType.MSSQL, dockerImage, documentationTitle("MsSQL"), artifactId("mssqlserver"))
.files()
.add(source.template("container-license-acceptance.txt"), to("src/test/resources/container-license-acceptance.txt"))
.add(
source.template("MsSQLTestContainerExtension.java"),
toSrcTestJava().append(properties.basePackage().path()).append(DEST_SECONDARY).append("MsSQLTestContainerExtension.java")
)
.and()
.javaDependencies()
.dependency(groupId("com.microsoft.sqlserver"), artifactId("mssql-jdbc"))
.and()
.springMainProperties()
.set(
propertyKey("spring.datasource.url"),
propertyValue("jdbc:sqlserver://localhost:1433;database=" + properties.projectBaseName().name() + ";trustServerCertificate=true")
)
.set(propertyKey("spring.datasource.username"), propertyValue("SA"))
.set(propertyKey("spring.datasource.password"), propertyValue("yourStrong(!)Password"))
.set(propertyKey("spring.datasource.driver-class-name"), propertyValue("com.microsoft.sqlserver.jdbc.SQLServerDriver"))
.set(propertyKey("spring.jpa.hibernate.ddl-auto"), propertyValue("update"))
.set(propertyKey("spring.jpa.properties.hibernate.criteria.literal_handling_mode"), propertyValue("BIND"))
.set(propertyKey("spring.jpa.properties.hibernate.dialect"), propertyValue("org.hibernate.dialect.SQLServer2012Dialect"))
.set(propertyKey("spring.jpa.properties.hibernate.format_sql"), propertyValue("true"))
.set(propertyKey("spring.jpa.properties.hibernate.jdbc.fetch_size"), propertyValue("150"))
.and()
.springTestProperties()
.set(
propertyKey("spring.datasource.url"),
propertyValue(
"jdbc:tc:sqlserver:" +
dockerImage.version() +
":///;database=" +
properties.projectBaseName().name() +
";trustServerCertificate=true?TC_TMPFS=/testtmpfs:rw"
)
)
.set(propertyKey("spring.datasource.username"), propertyValue("SA"))
.set(propertyKey("spring.datasource.password"), propertyValue("yourStrong(!)Password"))
.and()
.optionalReplacements()
.in("src/main/resources/logback-spring.xml")
.add(text(NEEDLE_LOGBACK_LOGGER), logger("com.microsoft.sqlserver", Level.WARN))
.add(text(NEEDLE_LOGBACK_LOGGER), logger("org.reflections", Level.WARN))
.and()
.and()
.build();
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package tech.jhipster.lite.generator.server.springboot.database.mssql.infrastructure.primary;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import tech.jhipster.lite.generator.server.springboot.database.mssql.application.MsSQLApplicationService;
import tech.jhipster.lite.module.domain.properties.JHipsterModulePropertiesDefinition;
import tech.jhipster.lite.module.infrastructure.primary.JHipsterModuleApiDoc;
import tech.jhipster.lite.module.infrastructure.primary.JHipsterModuleResource;

@Configuration
class MsSQLModuleConfiguration {

public static final String URL_MSSQL_MODULE = "/api/servers/spring-boot/databases/mssql";

@Bean
JHipsterModuleResource msSQLModule(MsSQLApplicationService applicationService) {
return JHipsterModuleResource
.builder()
.legacyUrl(URL_MSSQL_MODULE)
.slug("mssql")
.propertiesDefinition(JHipsterModulePropertiesDefinition.builder().addBasePackage().addIndentation().addProjectBaseName().build())
.apiDoc(new JHipsterModuleApiDoc("Spring Boot - Database", "Add MsSQL to project"))
.factory(applicationService::build);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package {{packageName}}.technical.infrastructure.secondary.mssqlserver;
package {{packageName}}.technical.infrastructure.secondary.mssql;

import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
Expand Down
Loading

0 comments on commit ebf205d

Please sign in to comment.