diff --git a/example/example-app/example-app-cmd-domain/pom.xml b/example/example-app/example-app-cmd-domain/pom.xml index e78052e5..208de759 100644 --- a/example/example-app/example-app-cmd-domain/pom.xml +++ b/example/example-app/example-app-cmd-domain/pom.xml @@ -6,7 +6,7 @@ com.codingapi.springboot example-app - 3.4.25 + 3.4.26 ../pom.xml diff --git a/example/example-app/example-app-cmd-meta/pom.xml b/example/example-app/example-app-cmd-meta/pom.xml index 3a80d9a1..bd0c20c4 100644 --- a/example/example-app/example-app-cmd-meta/pom.xml +++ b/example/example-app/example-app-cmd-meta/pom.xml @@ -6,7 +6,7 @@ com.codingapi.springboot example-app - 3.4.25 + 3.4.26 ../pom.xml diff --git a/example/example-app/example-app-query/pom.xml b/example/example-app/example-app-query/pom.xml index 7bcba2d6..c1257b92 100644 --- a/example/example-app/example-app-query/pom.xml +++ b/example/example-app/example-app-query/pom.xml @@ -6,7 +6,7 @@ com.codingapi.springboot example-app - 3.4.25 + 3.4.26 ../pom.xml diff --git a/example/example-app/pom.xml b/example/example-app/pom.xml index 0ce8c630..8c07ece8 100644 --- a/example/example-app/pom.xml +++ b/example/example-app/pom.xml @@ -6,7 +6,7 @@ com.codingapi.springboot springboot-example - 3.4.25 + 3.4.26 ../pom.xml pom diff --git a/example/example-domain/example-domain-leave/pom.xml b/example/example-domain/example-domain-leave/pom.xml index c70daa4a..06ef9aa7 100644 --- a/example/example-domain/example-domain-leave/pom.xml +++ b/example/example-domain/example-domain-leave/pom.xml @@ -6,7 +6,7 @@ com.codingapi.springboot example-domain - 3.4.25 + 3.4.26 ../pom.xml diff --git a/example/example-domain/example-domain-user/pom.xml b/example/example-domain/example-domain-user/pom.xml index 68949119..9d9ccbe3 100644 --- a/example/example-domain/example-domain-user/pom.xml +++ b/example/example-domain/example-domain-user/pom.xml @@ -6,7 +6,7 @@ com.codingapi.springboot example-domain - 3.4.25 + 3.4.26 ../pom.xml diff --git a/example/example-domain/pom.xml b/example/example-domain/pom.xml index 42fac3ca..107c326c 100644 --- a/example/example-domain/pom.xml +++ b/example/example-domain/pom.xml @@ -5,7 +5,7 @@ com.codingapi.springboot springboot-example - 3.4.25 + 3.4.26 ../pom.xml 4.0.0 diff --git a/example/example-infra/example-infra-flow/pom.xml b/example/example-infra/example-infra-flow/pom.xml index f43916d2..c9a6e0bb 100644 --- a/example/example-infra/example-infra-flow/pom.xml +++ b/example/example-infra/example-infra-flow/pom.xml @@ -5,7 +5,7 @@ com.codingapi.springboot example-infra - 3.4.25 + 3.4.26 ../pom.xml diff --git a/example/example-infra/example-infra-jpa/pom.xml b/example/example-infra/example-infra-jpa/pom.xml index 5e1243ba..4d9185a6 100644 --- a/example/example-infra/example-infra-jpa/pom.xml +++ b/example/example-infra/example-infra-jpa/pom.xml @@ -5,7 +5,7 @@ com.codingapi.springboot example-infra - 3.4.25 + 3.4.26 ../pom.xml diff --git a/example/example-infra/example-infra-security/pom.xml b/example/example-infra/example-infra-security/pom.xml index c362aa78..642bc563 100644 --- a/example/example-infra/example-infra-security/pom.xml +++ b/example/example-infra/example-infra-security/pom.xml @@ -6,7 +6,7 @@ com.codingapi.springboot example-infra - 3.4.25 + 3.4.26 ../pom.xml diff --git a/example/example-infra/pom.xml b/example/example-infra/pom.xml index 91bc1c05..09eb1740 100644 --- a/example/example-infra/pom.xml +++ b/example/example-infra/pom.xml @@ -6,7 +6,7 @@ com.codingapi.springboot springboot-example - 3.4.25 + 3.4.26 ../pom.xml pom diff --git a/example/example-interface/pom.xml b/example/example-interface/pom.xml index 15edf40c..b724f51b 100644 --- a/example/example-interface/pom.xml +++ b/example/example-interface/pom.xml @@ -6,7 +6,7 @@ com.codingapi.springboot springboot-example - 3.4.25 + 3.4.26 example-interface diff --git a/example/example-server/pom.xml b/example/example-server/pom.xml index fa3017b0..c8bdf781 100644 --- a/example/example-server/pom.xml +++ b/example/example-server/pom.xml @@ -5,7 +5,7 @@ springboot-example com.codingapi.springboot - 3.4.25 + 3.4.26 4.0.0 diff --git a/example/pom.xml b/example/pom.xml index b47025af..b8c3037f 100644 --- a/example/pom.xml +++ b/example/pom.xml @@ -19,7 +19,7 @@ springboot-example - 3.4.25 + 3.4.26 springboot-example springboot-example project for Spring Boot diff --git a/pom.xml b/pom.xml index c6334482..d30cc9c4 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ com.codingapi.springboot springboot-parent - 3.4.25 + 3.4.26 https://github.com/codingapi/springboot-framewrok springboot-parent diff --git a/springboot-starter-data-authorization/pom.xml b/springboot-starter-data-authorization/pom.xml index ebb3a4c6..363d7f78 100644 --- a/springboot-starter-data-authorization/pom.xml +++ b/springboot-starter-data-authorization/pom.xml @@ -6,7 +6,7 @@ com.codingapi.springboot springboot-parent - 3.4.25 + 3.4.26 springboot-starter-data-authorization diff --git a/springboot-starter-data-fast/pom.xml b/springboot-starter-data-fast/pom.xml index 1a4bbf5e..7d1a8d81 100644 --- a/springboot-starter-data-fast/pom.xml +++ b/springboot-starter-data-fast/pom.xml @@ -5,7 +5,7 @@ springboot-parent com.codingapi.springboot - 3.4.25 + 3.4.26 4.0.0 diff --git a/springboot-starter-data-fast/src/main/java/com/codingapi/springboot/fast/generator/DynamicTableGenerator.java b/springboot-starter-data-fast/src/main/java/com/codingapi/springboot/fast/generator/DynamicTableGenerator.java index a4a26b97..bf2710d8 100644 --- a/springboot-starter-data-fast/src/main/java/com/codingapi/springboot/fast/generator/DynamicTableGenerator.java +++ b/springboot-starter-data-fast/src/main/java/com/codingapi/springboot/fast/generator/DynamicTableGenerator.java @@ -6,7 +6,6 @@ import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.cfg.AvailableSettings; -import org.hibernate.dialect.Dialect; import org.hibernate.tool.schema.SourceType; import org.hibernate.tool.schema.TargetType; import org.hibernate.tool.schema.internal.ExceptionHandlerCollectingImpl; @@ -23,7 +22,7 @@ public class DynamicTableGenerator { /** * 数据库方言 */ - private final Dialect dialect; + private final Class dialect; private final StandardServiceRegistry serviceRegistry; private final SchemaManagementTool managementTool; @@ -32,14 +31,9 @@ public DynamicTableGenerator(Class dialectClass, String jdbcUrl) { } public DynamicTableGenerator(Class dialectClass, String jdbcUrl, String username, String password) { - try { - this.dialect = (Dialect) dialectClass.getDeclaredConstructor().newInstance(); - } catch (Exception e) { - throw new RuntimeException("Failed to instantiate dialect", e); - } - + this.dialect = dialectClass; StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder() - .applySetting(AvailableSettings.DIALECT, dialect.getClass().getName()) + .applySetting(AvailableSettings.DIALECT, dialect.getName()) .applySetting("hibernate.connection.url", jdbcUrl); if (StringUtils.hasText(username)) { builder.applySetting("hibernate.connection.username", username); @@ -56,7 +50,7 @@ private class ExecutionOptionsImpl implements ExecutionOptions { @Override public Map getConfigurationValues() { Map config = new HashMap<>(); - config.put(AvailableSettings.DIALECT, dialect.getClass().getName()); + config.put(AvailableSettings.DIALECT, dialect.getName()); return config; } diff --git a/springboot-starter-data-fast/src/main/java/com/codingapi/springboot/fast/jpa/JPAQueryConfiguration.java b/springboot-starter-data-fast/src/main/java/com/codingapi/springboot/fast/jpa/JPAQueryConfiguration.java deleted file mode 100644 index 49033f5d..00000000 --- a/springboot-starter-data-fast/src/main/java/com/codingapi/springboot/fast/jpa/JPAQueryConfiguration.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.codingapi.springboot.fast.jpa; - -import jakarta.persistence.EntityManager; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - - -@Configuration -public class JPAQueryConfiguration { - - @Bean - public JPAQuery dynamicQuery(EntityManager entityManager){ - return new JPAQuery(entityManager); - } - - @Bean - public JPAQueryContextRegister jpaQueryContextRegister(JPAQuery JPAQuery){ - return new JPAQueryContextRegister(JPAQuery); - } - -} diff --git a/springboot-starter-data-fast/src/main/java/com/codingapi/springboot/fast/jpa/JPAQuery.java b/springboot-starter-data-fast/src/main/java/com/codingapi/springboot/fast/jpa/JpaQuery.java similarity index 99% rename from springboot-starter-data-fast/src/main/java/com/codingapi/springboot/fast/jpa/JPAQuery.java rename to springboot-starter-data-fast/src/main/java/com/codingapi/springboot/fast/jpa/JpaQuery.java index 820c20a2..a9e62149 100644 --- a/springboot-starter-data-fast/src/main/java/com/codingapi/springboot/fast/jpa/JPAQuery.java +++ b/springboot-starter-data-fast/src/main/java/com/codingapi/springboot/fast/jpa/JpaQuery.java @@ -13,7 +13,7 @@ import java.util.List; @AllArgsConstructor -public class JPAQuery { +public class JpaQuery { private final EntityManager entityManager; diff --git a/springboot-starter-data-fast/src/main/java/com/codingapi/springboot/fast/jpa/JpaQueryConfiguration.java b/springboot-starter-data-fast/src/main/java/com/codingapi/springboot/fast/jpa/JpaQueryConfiguration.java new file mode 100644 index 00000000..08ee9c9d --- /dev/null +++ b/springboot-starter-data-fast/src/main/java/com/codingapi/springboot/fast/jpa/JpaQueryConfiguration.java @@ -0,0 +1,21 @@ +package com.codingapi.springboot.fast.jpa; + +import jakarta.persistence.EntityManager; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + + +@Configuration +public class JpaQueryConfiguration { + + @Bean + public JpaQuery dynamicQuery(EntityManager entityManager){ + return new JpaQuery(entityManager); + } + + @Bean + public JpaQueryContextRegister jpaQueryContextRegister(JpaQuery jpaQuery){ + return new JpaQueryContextRegister(jpaQuery); + } + +} diff --git a/springboot-starter-data-fast/src/main/java/com/codingapi/springboot/fast/jpa/JpaQueryContext.java b/springboot-starter-data-fast/src/main/java/com/codingapi/springboot/fast/jpa/JpaQueryContext.java index e39b2d5c..e103db08 100644 --- a/springboot-starter-data-fast/src/main/java/com/codingapi/springboot/fast/jpa/JpaQueryContext.java +++ b/springboot-starter-data-fast/src/main/java/com/codingapi/springboot/fast/jpa/JpaQueryContext.java @@ -13,10 +13,10 @@ private JpaQueryContext() { } @Getter - private JPAQuery JPAQuery; + private JpaQuery jpaQuery; - void setJPAQuery(JPAQuery JPAQuery) { - this.JPAQuery = JPAQuery; + void setJpaQuery(JpaQuery jpaQuery) { + this.jpaQuery = jpaQuery; } diff --git a/springboot-starter-data-fast/src/main/java/com/codingapi/springboot/fast/jpa/JPAQueryContextRegister.java b/springboot-starter-data-fast/src/main/java/com/codingapi/springboot/fast/jpa/JpaQueryContextRegister.java similarity index 60% rename from springboot-starter-data-fast/src/main/java/com/codingapi/springboot/fast/jpa/JPAQueryContextRegister.java rename to springboot-starter-data-fast/src/main/java/com/codingapi/springboot/fast/jpa/JpaQueryContextRegister.java index b6fc7198..1d765f9d 100644 --- a/springboot-starter-data-fast/src/main/java/com/codingapi/springboot/fast/jpa/JPAQueryContextRegister.java +++ b/springboot-starter-data-fast/src/main/java/com/codingapi/springboot/fast/jpa/JpaQueryContextRegister.java @@ -4,13 +4,13 @@ import org.springframework.beans.factory.InitializingBean; @AllArgsConstructor -public class JPAQueryContextRegister implements InitializingBean { +public class JpaQueryContextRegister implements InitializingBean { - private JPAQuery JPAQuery; + private JpaQuery jpaQuery; @Override public void afterPropertiesSet() throws Exception { - JpaQueryContext.getInstance().setJPAQuery(JPAQuery); + JpaQueryContext.getInstance().setJpaQuery(jpaQuery); } } diff --git a/springboot-starter-data-fast/src/main/java/com/codingapi/springboot/fast/jpa/repository/DynamicRepository.java b/springboot-starter-data-fast/src/main/java/com/codingapi/springboot/fast/jpa/repository/DynamicRepository.java index a18667e4..77f1758d 100644 --- a/springboot-starter-data-fast/src/main/java/com/codingapi/springboot/fast/jpa/repository/DynamicRepository.java +++ b/springboot-starter-data-fast/src/main/java/com/codingapi/springboot/fast/jpa/repository/DynamicRepository.java @@ -14,39 +14,39 @@ public interface DynamicRepository extends BaseRepository { default List dynamicListQuery(SQLBuilder builder) { - return JpaQueryContext.getInstance().getJPAQuery().listQuery(builder); + return JpaQueryContext.getInstance().getJpaQuery().listQuery(builder); } default List dynamicListQuery(String sql, Object... params) { - return JpaQueryContext.getInstance().getJPAQuery().listQuery(getEntityClass(), sql, params); + return JpaQueryContext.getInstance().getJpaQuery().listQuery(getEntityClass(), sql, params); } default List dynamicListQuery(Class clazz, String sql, Object... params) { - return JpaQueryContext.getInstance().getJPAQuery().listQuery(clazz, sql, params); + return JpaQueryContext.getInstance().getJpaQuery().listQuery(clazz, sql, params); } default Page dynamicPageQuery(SQLBuilder builder, PageRequest request) { - return JpaQueryContext.getInstance().getJPAQuery().pageQuery(builder, request); + return JpaQueryContext.getInstance().getJpaQuery().pageQuery(builder, request); } default Page dynamicPageQuery(String sql, String countSql, PageRequest request, Object... params) { - return JpaQueryContext.getInstance().getJPAQuery().pageQuery(getEntityClass(), sql, countSql, request, params); + return JpaQueryContext.getInstance().getJpaQuery().pageQuery(getEntityClass(), sql, countSql, request, params); } default Page dynamicPageQuery(String sql, PageRequest request, Object... params) { - return JpaQueryContext.getInstance().getJPAQuery().pageQuery(getEntityClass(), sql, request, params); + return JpaQueryContext.getInstance().getJpaQuery().pageQuery(getEntityClass(), sql, request, params); } default Page dynamicPageQuery(Class clazz, String sql, String countSql, PageRequest request, Object... params) { - return JpaQueryContext.getInstance().getJPAQuery().pageQuery(clazz, sql, countSql, request, params); + return JpaQueryContext.getInstance().getJpaQuery().pageQuery(clazz, sql, countSql, request, params); } default Page dynamicMapPageQuery(QueryColumns columns, String sql, String countSql, PageRequest request, Object... params) { - return JpaQueryContext.getInstance().getJPAQuery().pageMapQuery(columns, sql, countSql, request, params); + return JpaQueryContext.getInstance().getJpaQuery().pageMapQuery(columns, sql, countSql, request, params); } default List dynamicMapListQuery(QueryColumns columns, String sql, Object... params) { - return JpaQueryContext.getInstance().getJPAQuery().listMapQuery(columns, sql, params); + return JpaQueryContext.getInstance().getJpaQuery().listMapQuery(columns, sql, params); } } diff --git a/springboot-starter-data-fast/src/main/java/com/codingapi/springboot/fast/script/ScriptRuntime.java b/springboot-starter-data-fast/src/main/java/com/codingapi/springboot/fast/script/ScriptRuntime.java index 2b5a63ba..ef33effc 100644 --- a/springboot-starter-data-fast/src/main/java/com/codingapi/springboot/fast/script/ScriptRuntime.java +++ b/springboot-starter-data-fast/src/main/java/com/codingapi/springboot/fast/script/ScriptRuntime.java @@ -2,7 +2,7 @@ import com.codingapi.springboot.fast.jdbc.JdbcQuery; import com.codingapi.springboot.fast.jdbc.JdbcQueryContext; -import com.codingapi.springboot.fast.jpa.JPAQuery; +import com.codingapi.springboot.fast.jpa.JpaQuery; import com.codingapi.springboot.fast.jpa.JpaQueryContext; import groovy.lang.Binding; import groovy.lang.GroovyShell; @@ -18,7 +18,7 @@ static Object running(String script) { ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes(); ScriptRequest request = new ScriptRequest(attributes.getRequest()); JdbcQuery jdbcQuery = JdbcQueryContext.getInstance().getJdbcQuery(); - JPAQuery jpaQuery = JpaQueryContext.getInstance().getJPAQuery(); + JpaQuery jpaQuery = JpaQueryContext.getInstance().getJpaQuery(); binding.setVariable("$request", request); binding.setVariable("$jpa", jpaQuery); diff --git a/springboot-starter-data-fast/src/main/resources/META-INF/spring.factories b/springboot-starter-data-fast/src/main/resources/META-INF/spring.factories index f2d11256..25372a67 100644 --- a/springboot-starter-data-fast/src/main/resources/META-INF/spring.factories +++ b/springboot-starter-data-fast/src/main/resources/META-INF/spring.factories @@ -1,4 +1,4 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ com.codingapi.springboot.fast.DataFastConfiguration,\ -com.codingapi.springboot.fast.jpa.JPAQueryConfiguration,\ +com.codingapi.springboot.fast.jpa.JpaQueryConfiguration,\ com.codingapi.springboot.fast.jdbc.JdbcQueryConfiguration \ No newline at end of file diff --git a/springboot-starter-data-fast/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/springboot-starter-data-fast/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index 68b400af..526c33d9 100644 --- a/springboot-starter-data-fast/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/springboot-starter-data-fast/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -1,3 +1,3 @@ com.codingapi.springboot.fast.DataFastConfiguration -com.codingapi.springboot.fast.jpa.JPAQueryConfiguration +com.codingapi.springboot.fast.jpa.JpaQueryConfiguration com.codingapi.springboot.fast.jdbc.JdbcQueryConfiguration \ No newline at end of file diff --git a/springboot-starter-data-fast/src/test/java/com/codingapi/springboot/fast/generator/DynamicTableGeneratorQueryTest.java b/springboot-starter-data-fast/src/test/java/com/codingapi/springboot/fast/generator/DynamicTableGeneratorQueryTest.java new file mode 100644 index 00000000..e01d4f69 --- /dev/null +++ b/springboot-starter-data-fast/src/test/java/com/codingapi/springboot/fast/generator/DynamicTableGeneratorQueryTest.java @@ -0,0 +1,71 @@ +package com.codingapi.springboot.fast.generator; + +import com.codingapi.springboot.fast.jdbc.JdbcQuery; +import com.codingapi.springboot.fast.jdbc.JdbcQueryContext; +import com.codingapi.springboot.fast.jpa.JpaQuery; +import com.codingapi.springboot.fast.jpa.JpaQueryContext; +import com.codingapi.springboot.fast.metadata.TableEntityMetadata; +import jakarta.persistence.EntityManagerFactory; +import jakarta.persistence.GenerationType; +import org.hibernate.cfg.AvailableSettings; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.core.env.Environment; +import org.springframework.jdbc.core.JdbcTemplate; + +import java.util.List; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; + +@SpringBootTest +public class DynamicTableGeneratorQueryTest { + + @Autowired + private EntityManagerFactory entityManagerFactory; + + @Autowired + private Environment environment; + + @Autowired + private JdbcTemplate jdbcTemplate; + + + @Test + void generateThenUpdateQuery() throws ClassNotFoundException { + String dialect = entityManagerFactory.getProperties().get(AvailableSettings.DIALECT).toString(); + String jdbcUrl = environment.getProperty("spring.datasource.url"); + String username = environment.getProperty("spring.datasource.username"); + String password = environment.getProperty("spring.datasource.password"); + + DynamicTableGenerator dynamicTableGenerator = new DynamicTableGenerator(Class.forName(dialect), jdbcUrl, username, password); + + TableEntityMetadata tableEntityMetadata = new TableEntityMetadata("com.codingapi.springboot.fast.entity.Test"); + tableEntityMetadata.setTable("test"); + tableEntityMetadata.addPrimaryKeyColumn(Long.class, "id", GenerationType.IDENTITY, "主键"); + tableEntityMetadata.addColumn(String.class, "name", "姓名"); + + Class entityClass = tableEntityMetadata.buildClass(); + + // 创建表 + dynamicTableGenerator.generateMigratorTableDDL(entityClass, true); + + // 通过DynamicTableGenerator 动态创建的entity无法通过jpa的 EntityManager进行数据查询处理, 因为Entity不在JPA扫描支持的范围内。 + JpaQuery jpaQuery = JpaQueryContext.getInstance().getJpaQuery(); + assertThrows(Exception.class,()->{ + jpaQuery.listQuery(entityClass,"select t from com.codingapi.springboot.fast.entity.Test"); + }); + + // 插入数据 + jdbcTemplate.update("insert into test(name) values(?)", "小明"); + + // 查询数据 + JdbcQuery jdbcQuery = JdbcQueryContext.getInstance().getJdbcQuery(); + List> list = jdbcQuery.queryForMapList("select * from test"); + System.out.println(list); + assertFalse(list.isEmpty()); + + } +} diff --git a/springboot-starter-flow/pom.xml b/springboot-starter-flow/pom.xml index c1be9a18..612d15b9 100644 --- a/springboot-starter-flow/pom.xml +++ b/springboot-starter-flow/pom.xml @@ -6,7 +6,7 @@ springboot-parent com.codingapi.springboot - 3.4.25 + 3.4.26 springboot-starter-flow diff --git a/springboot-starter-security/pom.xml b/springboot-starter-security/pom.xml index f6cbc722..9af1aca2 100644 --- a/springboot-starter-security/pom.xml +++ b/springboot-starter-security/pom.xml @@ -6,7 +6,7 @@ springboot-parent com.codingapi.springboot - 3.4.25 + 3.4.26 springboot-starter-security diff --git a/springboot-starter/pom.xml b/springboot-starter/pom.xml index 0a327316..5bf61956 100644 --- a/springboot-starter/pom.xml +++ b/springboot-starter/pom.xml @@ -5,7 +5,7 @@ com.codingapi.springboot springboot-parent - 3.4.25 + 3.4.26 springboot-starter