Skip to content

Commit

Permalink
WIP working but need to be reworked, add feature test, ci test, canno…
Browse files Browse the repository at this point in the history
…t test on mssql
  • Loading branch information
fabienpuissant committed Oct 12, 2024
1 parent 0c7ee08 commit dff693e
Show file tree
Hide file tree
Showing 24 changed files with 985 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package tech.jhipster.lite.generator.server.springboot.database.jooq.application;

import org.springframework.stereotype.Service;
import tech.jhipster.lite.generator.server.springboot.database.jooq.domain.JooqModuleFactory;
import tech.jhipster.lite.module.domain.JHipsterModule;
import tech.jhipster.lite.module.domain.docker.DockerImages;
import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties;

@Service
public class JooqApplicationService {

private final JooqModuleFactory factory;

public JooqApplicationService(DockerImages dockerImages) {
factory = new JooqModuleFactory(dockerImages);
}

public JHipsterModule buildPostgresql(JHipsterModuleProperties properties) {
return factory.buildPostgresql(properties);
}

public JHipsterModule buildMariaDB(JHipsterModuleProperties properties) {
return factory.buildMariaDB(properties);
}

public JHipsterModule buildMsSQL(JHipsterModuleProperties properties) {
return factory.buildMsSQL(properties);
}

public JHipsterModule buildMySQL(JHipsterModuleProperties properties) {
return factory.buildMySQL(properties);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package tech.jhipster.lite.generator.server.springboot.database.jooq.domain;

import static tech.jhipster.lite.module.domain.JHipsterModule.*;

import tech.jhipster.lite.module.domain.DocumentationTitle;
import tech.jhipster.lite.module.domain.JHipsterModule;
import tech.jhipster.lite.module.domain.docker.DockerImageVersion;
import tech.jhipster.lite.module.domain.file.JHipsterSource;
import tech.jhipster.lite.module.domain.javabuild.ArtifactId;
import tech.jhipster.lite.module.domain.javadependency.JavaDependency;
import tech.jhipster.lite.module.domain.javadependency.JavaDependencyScope;
import tech.jhipster.lite.module.domain.javaproperties.PropertyValue;
import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties;
import tech.jhipster.lite.shared.error.domain.Assert;

final class CommonModuleBuilder {

private static final PropertyValue FALSE = propertyValue(false);

private CommonModuleBuilder() {}

public static JHipsterModule.JHipsterModuleBuilder commonModuleBuilder(
JHipsterModuleProperties properties,
DatabaseType databaseType,
DockerImageVersion dockerImage,
DocumentationTitle documentationTitle,
ArtifactId testContainerArtifactId
) {
Assert.notNull("properties", properties);
Assert.notNull("databaseType", databaseType);
Assert.notNull("dockerImage", dockerImage);
Assert.notNull("documentationTitle", documentationTitle);
Assert.notNull("testContainerArtifactId", testContainerArtifactId);

String databaseId = databaseType.id();
JHipsterSource source = from("server/springboot/database/common");

//@formatter:off
return moduleBuilder(properties)
.context()
.put("srcMainDocker", "src/main/docker") // To be used in <databaseId>>.md file
.put("databaseType", databaseId)
.put(databaseId + "DockerImageWithVersion", dockerImage.fullName()) // To be used in <databaseId>.yml docker-compose file
.and()
.documentation(documentationTitle, source.template("databaseType.md"))
.startupCommands()
.dockerCompose(startupCommand(databaseId))
.and()
.files()
.add(source.append("docker").template(databaseId + ".yml"), toSrcMainDocker().append(databaseId + ".yml"))
.and()
.javaDependencies()
.addDependency(groupId("org.springframework.boot"), artifactId("spring-boot-starter-jooq"))
.addDependency(groupId("com.zaxxer"), artifactId("HikariCP"))
.addDependency(testContainer(testContainerArtifactId))
.and()
.springMainProperties()
.set(propertyKey("spring.datasource.password"), propertyValue(""))
.set(propertyKey("spring.datasource.type"), propertyValue("com.zaxxer.hikari.HikariDataSource"))
.set(propertyKey("spring.datasource.hikari.poolName"), propertyValue("Hikari"))
.set(propertyKey("spring.datasource.hikari.auto-commit"), FALSE)
.and()
.springTestProperties()
.set(
propertyKey("spring.datasource.url"),
propertyValue("jdbc:tc:" + dockerImage.fullName() + ":///" + properties.projectBaseName().name())
)
.set(propertyKey("spring.datasource.username"), propertyValue(properties.projectBaseName().name()))
.set(propertyKey("spring.datasource.password"), propertyValue(""))
.set(propertyKey("spring.datasource.driver-class-name"), propertyValue("org.testcontainers.jdbc.ContainerDatabaseDriver"))
.set(propertyKey("spring.datasource.hikari.maximum-pool-size"), propertyValue(2))
.and();
//@formatter:on
}

private static String startupCommand(String databaseId) {
return "src/main/docker/" + databaseId + ".yml";
}

private static JavaDependency testContainer(ArtifactId testContainerArtifactId) {
return javaDependency()
.groupId("org.testcontainers")
.artifactId(testContainerArtifactId)
.dependencySlug("%s-%s".formatted("testcontainers", testContainerArtifactId))
.versionSlug("testcontainers")
.scope(JavaDependencyScope.TEST)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package tech.jhipster.lite.generator.server.springboot.database.jooq.domain;

enum DatabaseType {
POSTGRESQL("postgresql"),
MYSQL("mysql"),
MARIADB("mariadb"),
MSSQL("mssql");

private final String id;

DatabaseType(String id) {
this.id = id;
}

public String id() {
return id;
}
}
Loading

0 comments on commit dff693e

Please sign in to comment.