Skip to content

Commit eb7a5ab

Browse files
committed
Merge branch 'refs/heads/feature/STORM-32'
# Conflicts: # README.adoc # pom.xml # storm-json/pom.xml # storm-kotlin/pom.xml # storm-kotlin/src/main/java/st/orm/kotlin/template/KQueryBuilder.java # storm-kotlin/src/main/kotlin/st/orm/kotlin/repository/KRepositoryLookupExtensions.kt # storm-kotlin/src/main/kotlin/st/orm/kotlin/repository/RepositoryLookupExtensions.kt # storm-mariadb/pom.xml # storm-metamodel-processor/pom.xml # storm-mssqlserver/pom.xml # storm-mysql/pom.xml # storm-oracle/pom.xml # storm-postgresql/pom.xml # storm-spring/pom.xml # storm/pom.xml # storm/src/main/java/st/orm/template/impl/QueryBuilderImpl.java
2 parents 498beba + 0557059 commit eb7a5ab

File tree

34 files changed

+310
-212
lines changed

34 files changed

+310
-212
lines changed

README.adoc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ Maven::
4545
<dependency>
4646
<groupId>st.orm</groupId>
4747
<artifactId>storm</artifactId>
48-
<version>1.3.7</version>
48+
<version>1.3.8</version>
4949
<scope>compile</scope>
5050
</dependency>
5151
----
5252
Gradle::
5353
+
5454
[source,groovy]
5555
----
56-
implementation 'st.orm:storm:1.3.7'
56+
implementation 'st.orm:storm:1.3.8'
5757
----
5858
====
5959

@@ -846,15 +846,15 @@ Maven::
846846
<dependency>
847847
<groupId>st.orm</groupId>
848848
<artifactId>storm-oracle</artifactId>
849-
<version>1.3.7</version>
849+
<version>1.3.8</version>
850850
<scope>runtime</scope>
851851
</dependency>
852852
----
853853
Gradle::
854854
+
855855
[source,groovy]
856856
----
857-
runtimeOnly 'st.orm:storm-oracle:1.3.7'
857+
runtimeOnly 'st.orm:storm-oracle:1.3.8'
858858
----
859859
====
860860

@@ -876,15 +876,15 @@ Maven::
876876
<dependency>
877877
<groupId>st.orm</groupId>
878878
<artifactId>storm-metamodel-processor</artifactId>
879-
<version>1.3.7</version>
879+
<version>1.3.8</version>
880880
<scope>provided</scope>
881881
</dependency>
882882
----
883883
Gradle::
884884
+
885885
[source,groovy]
886886
----
887-
annotationProcessor 'st.orm:storm-metamodel-processor:1.3.7'
887+
annotationProcessor 'st.orm:storm-metamodel-processor:1.3.8'
888888
----
889889
====
890890

@@ -952,15 +952,15 @@ Maven::
952952
<dependency>
953953
<groupId>st.orm</groupId>
954954
<artifactId>storm-json</artifactId>
955-
<version>1.3.7</version>
955+
<version>1.3.8</version>
956956
<scope>compile</scope>
957957
</dependency>
958958
----
959959
Gradle::
960960
+
961961
[source,groovy]
962962
----
963-
implementation 'st.orm:storm-json:1.3.7'
963+
implementation 'st.orm:storm-json:1.3.8'
964964
----
965965
====
966966

@@ -1096,15 +1096,15 @@ Maven::
10961096
<dependency>
10971097
<groupId>st.orm</groupId>
10981098
<artifactId>storm-spring</artifactId>
1099-
<version>1.3.7</version>
1099+
<version>1.3.8</version>
11001100
<scope>compile</scope>
11011101
</dependency>
11021102
----
11031103
Gradle::
11041104
+
11051105
[source,groovy]
11061106
----
1107-
implementation 'st.orm:storm-spring:1.3.7'
1107+
implementation 'st.orm:storm-spring:1.3.8'
11081108
----
11091109
====
11101110

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
</properties>
1313
<groupId>st.orm</groupId>
1414
<artifactId>storm-framework</artifactId>
15-
<version>1.3.7</version>
15+
<version>1.3.8</version>
1616
<packaging>pom</packaging>
1717
<name>Storm Framework</name>
1818
<description>A SQL Template and ORM framework, focusing on modernizing and simplifying database programming.</description>

storm-json/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>st.orm</groupId>
88
<artifactId>storm-framework</artifactId>
9-
<version>1.3.7</version>
9+
<version>1.3.8</version>
1010
<relativePath>../pom.xml</relativePath>
1111
</parent>
1212
<artifactId>storm-json</artifactId>

storm-kotlin/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>st.orm</groupId>
88
<artifactId>storm-framework</artifactId>
9-
<version>1.3.7</version>
9+
<version>1.3.8</version>
1010
<relativePath>../pom.xml</relativePath>
1111
</parent>
1212
<artifactId>storm-kotlin</artifactId>

storm-kotlin/src/main/java/st/orm/kotlin/repository/KEntityRepository.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import st.orm.kotlin.template.KModel;
2828
import st.orm.kotlin.template.KQueryBuilder;
2929
import st.orm.repository.Entity;
30+
import st.orm.template.TemplateFunction;
3031

3132
import java.util.List;
3233
import java.util.Optional;
@@ -133,6 +134,18 @@ public interface KEntityRepository<E extends Record & Entity<ID>, ID> extends KR
133134
*/
134135
<R> KQueryBuilder<E, R, ID> select(@Nonnull KClass<R> selectType, @Nonnull StringTemplate template);
135136

137+
/**
138+
* Creates a new query builder for the custom {@code selectType} and custom {@code template} for the select clause.
139+
*
140+
* @param selectType the result type of the query.
141+
* @param function the custom template for the select clause.
142+
* @return a new query builder for the custom {@code selectType}.
143+
* @param <R> the result type of the query.
144+
*/
145+
default <R> KQueryBuilder<E, R, ID> select(@Nonnull KClass<R> selectType, @Nonnull TemplateFunction function) {
146+
return select(selectType, TemplateFunction.template(function));
147+
}
148+
136149
/**
137150
* Creates a new query builder for selecting refs to entities of the type managed by this repository.
138151
*

storm-kotlin/src/main/java/st/orm/kotlin/repository/KProjectionRepository.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import st.orm.kotlin.template.KModel;
2626
import st.orm.kotlin.template.KQueryBuilder;
2727
import st.orm.repository.Projection;
28+
import st.orm.template.TemplateFunction;
2829

2930
import java.util.List;
3031
import java.util.Optional;
@@ -121,6 +122,18 @@ public interface KProjectionRepository<P extends Record & Projection<ID>, ID> ex
121122
*/
122123
<R> KQueryBuilder<P, R, ID> select(@Nonnull Class<R> selectType, @Nonnull StringTemplate template);
123124

125+
/**
126+
* Creates a new query builder for the custom {@code selectType} and custom {@code template} for the select clause.
127+
*
128+
* @param selectType the result type of the query.
129+
* @param function the custom template for the select clause.
130+
* @return a new query builder for the custom {@code selectType}.
131+
* @param <R> the result type of the query.
132+
*/
133+
default <R> KQueryBuilder<P, R, ID> select(@Nonnull Class<R> selectType, @Nonnull TemplateFunction function) {
134+
return select(selectType, TemplateFunction.template(function));
135+
}
136+
124137
// Base methods.
125138

126139
/**

storm-kotlin/src/main/java/st/orm/kotlin/spi/KORMReflectionImpl.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,15 @@ public boolean isAnnotationPresent(@Nonnull Class<?> type, @Nonnull Class<? exte
8787
return getAnnotation(type, annotationType) != null;
8888
}
8989

90-
record ComponentCacheKey(@Nonnull Constructor<?> constructor, @Nonnull String componentName) {
90+
record ComponentCacheKey(@Nonnull Class<? extends Record> recordType, @Nonnull String componentName) {
9191
ComponentCacheKey(RecordComponent component) throws IllegalArgumentException {
9292
//noinspection unchecked
93-
this(defaultReflection.findCanonicalConstructor(
94-
(Class<? extends Record>) component.getDeclaringRecord()).orElseThrow(
95-
() -> new IllegalArgumentException(STR."No canonical constructor found for record type: \{component.getDeclaringRecord().getSimpleName()}.")),
96-
component.getName());
93+
this((Class<? extends Record>) component.getDeclaringRecord(), component.getName());
94+
}
95+
96+
private Constructor<?> constructor() {
97+
return defaultReflection.findCanonicalConstructor(recordType)
98+
.orElseThrow(() -> new IllegalArgumentException(STR."No canonical constructor found for record type: \{recordType.getSimpleName()}."));
9799
}
98100
}
99101

storm-kotlin/src/main/java/st/orm/kotlin/template/KQueryBuilder.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import st.orm.template.Operator;
3131
import st.orm.template.QueryBuilder;
3232
import st.orm.template.TemplateFunction;
33-
import st.orm.template.WhereBuilder;
3433
import st.orm.template.impl.Elements.ObjectExpression;
3534

3635
import java.util.List;
@@ -203,26 +202,26 @@ public final KJoinBuilder<T, R, ID> rightJoin(@Nonnull TemplateFunction function
203202
public abstract KJoinBuilder<T, R, ID> join(@Nonnull JoinType type, @Nonnull StringTemplate template, @Nonnull String alias);
204203

205204
/**
206-
* Adds a join of the specified type to the query using a subquery.
205+
* Adds a join of the specified type to the query.
207206
*
208207
* @param type the join type.
209-
* @param subquery the subquery to join.
208+
* @param function the function used to define the condition to join.
210209
* @param alias the alias to use for the joined relation.
211210
* @return the query builder.
212211
*/
213-
public abstract KJoinBuilder<T, R, ID> join(@Nonnull JoinType type, @Nonnull KQueryBuilder<?, ?, ?> subquery, @Nonnull String alias);
212+
public final KJoinBuilder<T, R, ID> join(@Nonnull JoinType type, @Nonnull TemplateFunction function, @Nonnull String alias) {
213+
return join(type, TemplateFunction.template(function), alias);
214+
}
214215

215216
/**
216-
* Adds a join of the specified type to the query.
217+
* Adds a join of the specified type to the query using a subquery.
217218
*
218219
* @param type the join type.
219-
* @param function the function used to define the condition to join.
220+
* @param subquery the subquery to join.
220221
* @param alias the alias to use for the joined relation.
221222
* @return the query builder.
222-
*/
223-
public final KJoinBuilder<T, R, ID> join(@Nonnull JoinType type, @Nonnull TemplateFunction function, @Nonnull String alias) {
224-
return join(type, TemplateFunction.template(function), alias);
225-
}
223+
*/
224+
public abstract KJoinBuilder<T, R, ID> join(@Nonnull JoinType type, @Nonnull KQueryBuilder<?, ?, ?> subquery, @Nonnull String alias);
226225

227226
/**
228227
* Adds a WHERE clause that matches the specified primary key of the table.

storm-kotlin/src/main/java/st/orm/kotlin/template/KSubqueryTemplate.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import jakarta.annotation.Nonnull;
1919
import kotlin.reflect.KClass;
20+
import st.orm.template.TemplateFunction;
2021

2122
import static java.lang.StringTemplate.RAW;
2223

@@ -65,5 +66,18 @@ public interface KSubqueryTemplate {
6566
* @param <T> the table type.
6667
*/
6768
<T extends Record> KQueryBuilder<T, ?, ?> subquery(@Nonnull KClass<T> fromType,
68-
@Nonnull StringTemplate template);
69+
@Nonnull StringTemplate template);
70+
71+
/**
72+
* Create a subquery for the given table and select type using the given template.
73+
*
74+
* @param fromType the table to create the subquery for.
75+
* @param function the template to use for the subquery.
76+
* @return the subquery builder.
77+
* @param <T> the table type.
78+
*/
79+
default <T extends Record> KQueryBuilder<T, ?, ?> subquery(@Nonnull KClass<T> fromType,
80+
@Nonnull TemplateFunction function) {
81+
return subquery(fromType, TemplateFunction.template(function));
82+
}
6983
}

storm-kotlin/src/main/kotlin/st/orm/kotlin/repository/KRepositoryLookupExtensions.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,7 +1173,7 @@ inline fun <reified T, V> KRepositoryLookup.countBy(
11731173
* @return the count of matching entities.
11741174
*/
11751175
@Suppress("UNCHECKED_CAST")
1176-
inline fun <reified T, V> KRepositoryLookup.count(
1176+
inline fun <reified T> KRepositoryLookup.count(
11771177
noinline predicate: KWhereBuilder<T, *, *>.() -> KPredicateBuilder<T, *, *>
11781178
): Long where T : Record = when {
11791179
Entity::class.java.isAssignableFrom(T::class.java) -> {
@@ -1194,7 +1194,7 @@ inline fun <reified T, V> KRepositoryLookup.count(
11941194
* @return the count of matching entities.
11951195
*/
11961196
@Suppress("UNCHECKED_CAST")
1197-
inline fun <reified T, V> KRepositoryLookup.count(predicateBuilder: KPredicateBuilder<T, *, *>): Long
1197+
inline fun <reified T> KRepositoryLookup.count(predicateBuilder: KPredicateBuilder<T, *, *>): Long
11981198
where T : Record = when {
11991199
Entity::class.java.isAssignableFrom(T::class.java) -> {
12001200
val method = this::class.java.getMethod("entity", Class::class.java)

0 commit comments

Comments
 (0)