Skip to content

Commit

Permalink
Merge pull request #725 from lserveriiev/feature/replace-thymeleaf-wi…
Browse files Browse the repository at this point in the history
…th-jte

Replace Thymeleaf with JTE
  • Loading branch information
kdhrubo authored Oct 4, 2024
2 parents 94cc409 + b48833a commit 5d979bb
Show file tree
Hide file tree
Showing 31 changed files with 390 additions and 276 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@
import com.homihq.db2rest.multidb.DatabaseProperties;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import gg.jte.CodeResolver;
import gg.jte.ContentType;
import gg.jte.TemplateEngine;
import gg.jte.resolve.ResourceCodeResolver;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.thymeleaf.spring6.SpringTemplateEngine;

import javax.sql.DataSource;
import java.util.HashMap;
Expand Down Expand Up @@ -116,12 +118,16 @@ public JdbcOperationService operationService() {


@Bean
@DependsOn("textTemplateResolver")
public SqlCreatorTemplate sqlCreatorTemplate(SpringTemplateEngine templateEngine, JdbcManager jdbcManager
) {
public SqlCreatorTemplate sqlCreatorTemplate(TemplateEngine templateEngine, JdbcManager jdbcManager) {
return new SqlCreatorTemplate(templateEngine, jdbcManager);
}

@Bean
public TemplateEngine templateEngine() {
CodeResolver codeResolver =
new ResourceCodeResolver("sql-templates", this.getClass().getClassLoader());
return TemplateEngine.create(codeResolver, ContentType.Plain);
}

//START ::: Processors
@Bean
Expand Down
4 changes: 0 additions & 4 deletions api-rest/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ spring:
banner:
location: classpath:banner.txt

thymeleaf:
check-template-location: false
cache: true


db2rest:

Expand Down
10 changes: 10 additions & 0 deletions api-rest/src/main/resources/sql-templates/count.jte
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@param String rootTable
@param String rootWhere

SELECT
COUNT(*)
FROM
${rootTable}
@if(rootWhere != null)
WHERE ${rootWhere}
@endif
6 changes: 0 additions & 6 deletions api-rest/src/main/resources/sql-templates/count.sql

This file was deleted.

10 changes: 10 additions & 0 deletions api-rest/src/main/resources/sql-templates/delete-mssql.jte
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@param String rootTable
@param String rootWhere
@param String rootTableAlias

DELETE FROM ${rootTableAlias}
FROM ${rootTable}

@if(rootWhere != null)
WHERE ${rootWhere}
@endif
5 changes: 0 additions & 5 deletions api-rest/src/main/resources/sql-templates/delete-mssql.sql

This file was deleted.

8 changes: 8 additions & 0 deletions api-rest/src/main/resources/sql-templates/delete.jte
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@param String rootTable
@param String rootWhere

DELETE FROM
${rootTable}
@if(rootWhere != null)
WHERE ${rootWhere}
@endif
4 changes: 0 additions & 4 deletions api-rest/src/main/resources/sql-templates/delete.sql

This file was deleted.

17 changes: 17 additions & 0 deletions api-rest/src/main/resources/sql-templates/exists-mssql.jte
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@import com.homihq.db2rest.jdbc.config.model.DbJoin
@import java.util.List

@param String rootTable
@param String rootWhere
@param List<DbJoin> joins

SELECT TOP 1 1
FROM ${rootTable}
@if(joins != null)
@for(DbJoin join : joins)
${join.render()}
@endfor
@endif
@if(rootWhere != null)
WHERE ${rootWhere}
@endif
9 changes: 0 additions & 9 deletions api-rest/src/main/resources/sql-templates/exists-mssql.sql

This file was deleted.

19 changes: 19 additions & 0 deletions api-rest/src/main/resources/sql-templates/exists.jte
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@import com.homihq.db2rest.jdbc.config.model.DbJoin
@import java.util.List

@param String rootTable
@param String rootWhere
@param List<DbJoin> joins

SELECT
1
FROM ${rootTable}
@if(joins != null)
@for(DbJoin join : joins)
${join.render()}
@endfor
@endif
@if(rootWhere != null)
WHERE ${rootWhere}
@endif
LIMIT 1
8 changes: 0 additions & 8 deletions api-rest/src/main/resources/sql-templates/exists.sql

This file was deleted.

11 changes: 11 additions & 0 deletions api-rest/src/main/resources/sql-templates/find-one.jte
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@param String rootTable
@param String rootWhere
@param String columns

SELECT
${columns}
FROM
${rootTable}
@if(rootWhere != null)
WHERE ${rootWhere}
@endif
6 changes: 0 additions & 6 deletions api-rest/src/main/resources/sql-templates/find-one.sql

This file was deleted.

8 changes: 8 additions & 0 deletions api-rest/src/main/resources/sql-templates/insert.jte
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@param String columns
@param String table
@param String parameters

INSERT INTO ${table}
(${columns})
VALUES
(${parameters})
4 changes: 0 additions & 4 deletions api-rest/src/main/resources/sql-templates/insert.sql

This file was deleted.

70 changes: 70 additions & 0 deletions api-rest/src/main/resources/sql-templates/read-mssql.jte
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
@import com.homihq.db2rest.jdbc.config.model.DbJoin
@import java.util.List

@param List<DbJoin> joins
@param String rootTable
@param String columns
@param String rootWhere
@param String sorts
@param Integer limit
@param Long offset

@if(sorts != null)
SELECT
${columns}
FROM ${rootTable}
@if(joins != null)
@for(DbJoin join : joins)
${join.render()}
@endfor
@endif
@if(rootWhere != null)
WHERE ${rootWhere}
@endif
ORDER BY ${sorts}
@if(limit != null)
OFFSET ${(offset == null ? 0 : offset)} ROWS FETCH NEXT ${limit} ROWS ONLY
@endif
@elseif(limit != null)
@if(offset != null)
SELECT T.* FROM
(
SELECT
${columns},
ROW_NUMBER() OVER(ORDER BY (SELECT 1)) AS rowIndex
FROM ${rootTable}
@if(joins != null)
@for(DbJoin join : joins)
${join.render()}
@endfor
@endif
@if(rootWhere != null)
WHERE ${rootWhere}
@endif
) AS T
WHERE rowIndex > ${offset} AND rowIndex <= ${offset + limit}
@else
SELECT TOP ${limit} ${columns}
FROM ${rootTable}
@if(joins != null)
@for(DbJoin join : joins)
${join.render()}
@endfor
@endif
@if(rootWhere != null)
WHERE ${rootWhere}
@endif
@endif
@else
SELECT
${columns}
FROM ${rootTable}
@if(joins != null)
@for(DbJoin join : joins)
${join.render()}
@endfor
@endif
@if(rootWhere != null)
WHERE ${rootWhere}
@endif
@endif
46 changes: 0 additions & 46 deletions api-rest/src/main/resources/sql-templates/read-mssql.sql

This file was deleted.

34 changes: 34 additions & 0 deletions api-rest/src/main/resources/sql-templates/read-ora-12.jte
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
@import com.homihq.db2rest.jdbc.config.model.DbJoin
@import java.util.List

@param List<DbJoin> joins
@param String rootTable
@param String columns
@param String rootWhere
@param String sorts
@param Integer limit
@param Long offset

SELECT
${columns}
FROM
${rootTable}
@if(joins != null)
@for(DbJoin join : joins)
${join.render()}
@endfor
@endif
@if(rootWhere != null)
WHERE ${rootWhere}
@endif
@if(sorts != null)
ORDER BY ${sorts}
@endif
@if(limit != null)
@if(offset != null)
OFFSET ${offset} ROWS
FETCH NEXT ${limit} ROWS ONLY
@else
FETCH FIRST ${limit} ROWS ONLY
@endif
@endif
18 changes: 0 additions & 18 deletions api-rest/src/main/resources/sql-templates/read-ora-12.sql

This file was deleted.

Loading

0 comments on commit 5d979bb

Please sign in to comment.