Skip to content

Commit baf581b

Browse files
authored
Feature/storm 27 (#28)
* Add Kotlin extension functions. Relates to #27
1 parent 97557fc commit baf581b

File tree

19 files changed

+180
-21
lines changed

19 files changed

+180
-21
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.5</version>
48+
<version>1.3.6</version>
4949
<scope>compile</scope>
5050
</dependency>
5151
----
5252
Gradle::
5353
+
5454
[source,groovy]
5555
----
56-
implementation 'st.orm:storm:1.3.5'
56+
implementation 'st.orm:storm:1.3.6'
5757
----
5858
====
5959

@@ -846,15 +846,15 @@ Maven::
846846
<dependency>
847847
<groupId>st.orm</groupId>
848848
<artifactId>storm-oracle</artifactId>
849-
<version>1.3.5</version>
849+
<version>1.3.6</version>
850850
<scope>runtime</scope>
851851
</dependency>
852852
----
853853
Gradle::
854854
+
855855
[source,groovy]
856856
----
857-
runtimeOnly 'st.orm:storm-oracle:1.3.5'
857+
runtimeOnly 'st.orm:storm-oracle:1.3.6'
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.5</version>
879+
<version>1.3.6</version>
880880
<scope>provided</scope>
881881
</dependency>
882882
----
883883
Gradle::
884884
+
885885
[source,groovy]
886886
----
887-
annotationProcessor 'st.orm:storm-metamodel-processor:1.3.5'
887+
annotationProcessor 'st.orm:storm-metamodel-processor:1.3.6'
888888
----
889889
====
890890

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

@@ -1096,15 +1096,15 @@ Maven::
10961096
<dependency>
10971097
<groupId>st.orm</groupId>
10981098
<artifactId>storm-spring</artifactId>
1099-
<version>1.3.5</version>
1099+
<version>1.3.6</version>
11001100
<scope>compile</scope>
11011101
</dependency>
11021102
----
11031103
Gradle::
11041104
+
11051105
[source,groovy]
11061106
----
1107-
implementation 'st.orm:storm-spring:1.3.5'
1107+
implementation 'st.orm:storm-spring:1.3.6'
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.5</version>
15+
<version>1.3.6</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.5</version>
9+
<version>1.3.6</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.5</version>
9+
<version>1.3.6</version>
1010
<relativePath>../pom.xml</relativePath>
1111
</parent>
1212
<artifactId>storm-kotlin</artifactId>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package st.orm.kotlin.repository
2+
3+
import st.orm.repository.Entity
4+
import st.orm.repository.Projection
5+
6+
/**
7+
* Extensions for [KRepositoryLookup] to provide convenient access to entity repositories.
8+
*/
9+
inline fun <reified T, ID> KRepositoryLookup.typedEntity(): KEntityRepository<T, ID>
10+
where T : Record, T : Entity<ID> {
11+
return entity(T::class.java)
12+
}
13+
14+
/**
15+
* Extensions for [KRepositoryLookup] to provide convenient access to entity repositories.
16+
*/
17+
inline fun <reified T> KRepositoryLookup.entity(): KEntityRepository<T, *>
18+
where T : Record, T : Entity<*> {
19+
// Use reflection to prevent the need for the ID parameter. The compiler takes care of the type-safety but is
20+
// unable to infer the type of the ID parameter at compile time.
21+
val method = this::class.java.getMethod("entity", Class::class.java)
22+
@Suppress("UNCHECKED_CAST")
23+
return method.invoke(this, T::class.java) as KEntityRepository<T, *>
24+
}
25+
26+
/**
27+
* Extensions for [KRepositoryLookup] to provide convenient access to projection repositories.
28+
*/
29+
inline fun <reified T, ID> KRepositoryLookup.typedProjection(): KProjectionRepository<T, ID>
30+
where T : Record, T : Projection<ID> {
31+
return projection(T::class.java)
32+
}
33+
34+
/**
35+
* Extensions for [KRepositoryLookup] to provide convenient access to projection repositories.
36+
*/
37+
inline fun <reified T> KRepositoryLookup.projection(): KProjectionRepository<T, *>
38+
where T : Record, T : Projection<*> {
39+
// Use reflection to prevent the need for the ID parameter. The compiler takes care of the type-safety but is
40+
// unable to infer the type of the ID parameter at compile time.
41+
val method = this::class.java.getMethod("projection", Class::class.java)
42+
@Suppress("UNCHECKED_CAST")
43+
return method.invoke(this, T::class.java) as KProjectionRepository<T, *>
44+
}
45+
46+
/**
47+
* Extensions for [KRepositoryLookup] to provide convenient access to repositories.
48+
*/
49+
inline fun <reified R : KRepository> KRepositoryLookup.repository(): R {
50+
return repository(R::class)
51+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package st.orm.kotlin.repository
2+
3+
import st.orm.repository.Entity
4+
import st.orm.repository.EntityRepository
5+
import st.orm.repository.Projection
6+
import st.orm.repository.ProjectionRepository
7+
import st.orm.repository.Repository
8+
import st.orm.repository.RepositoryLookup
9+
10+
/**
11+
* Extensions for [RepositoryLookup] to provide convenient access to entity repositories.
12+
*/
13+
inline fun <reified T, ID> RepositoryLookup.typedEntity(): EntityRepository<T, ID>
14+
where T : Record, T : Entity<ID> {
15+
return entity(T::class.java)
16+
}
17+
18+
/**
19+
* Extensions for [RepositoryLookup] to provide convenient access to entity repositories.
20+
*/
21+
inline fun <reified T> RepositoryLookup.entity(): EntityRepository<T, *>
22+
where T : Record, T : Entity<*> {
23+
// Use reflection to prevent the need for the ID parameter. The compiler takes care of the type-safety but is
24+
// unable to infer the type of the ID parameter at compile time.
25+
val method = this::class.java.getMethod("entity", Class::class.java)
26+
@Suppress("UNCHECKED_CAST")
27+
return method.invoke(this, T::class.java) as EntityRepository<T, *>
28+
}
29+
30+
/**
31+
* Extensions for [RepositoryLookup] to provide convenient access to projection repositories.
32+
*/
33+
inline fun <reified T, ID> RepositoryLookup.typedProjection(): ProjectionRepository<T, ID>
34+
where T : Record, T : Projection<ID> {
35+
return projection(T::class.java)
36+
}
37+
38+
/**
39+
* Extensions for [RepositoryLookup] to provide convenient access to projection repositories.
40+
*/
41+
inline fun <reified T> RepositoryLookup.projection(): ProjectionRepository<T, *>
42+
where T : Record, T : Projection<*> {
43+
// Use reflection to prevent the need for the ID parameter. The compiler takes care of the type-safety but is
44+
// unable to infer the type of the ID parameter at compile time.
45+
val method = this::class.java.getMethod("entity", Class::class.java)
46+
@Suppress("UNCHECKED_CAST")
47+
return method.invoke(this, T::class.java) as ProjectionRepository<T, *>
48+
}
49+
50+
/**
51+
* Extensions for [RepositoryLookup] to provide convenient access to repositories.
52+
*/
53+
inline fun <reified R : Repository> RepositoryLookup.repository(): R {
54+
return repository(R::class.java)
55+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package st.orm.kotlin.template
2+
3+
import st.orm.kotlin.KTemplates
4+
import st.orm.kotlin.template.KORMTemplate
5+
import java.sql.Connection
6+
7+
/**
8+
* Extension property to convert a [Connection] to a [KORMTemplate].
9+
*/
10+
val Connection.orm: KORMTemplate
11+
get() = KTemplates.ORM(this)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package st.orm.kotlin.template
2+
3+
import st.orm.kotlin.KTemplates
4+
import st.orm.kotlin.template.KORMTemplate
5+
import javax.sql.DataSource
6+
7+
/**
8+
* Extension property to convert a [DataSource] to a [KORMTemplate].
9+
*/
10+
val DataSource.orm: KORMTemplate
11+
get() = KTemplates.ORM(this)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package st.orm.kotlin.template
2+
3+
import jakarta.persistence.EntityManager
4+
import st.orm.kotlin.KTemplates
5+
import st.orm.kotlin.template.KORMTemplate
6+
7+
/**
8+
* Extension property to convert an [EntityManager] to a [KORMTemplate].
9+
*/
10+
val EntityManager.orm: KORMTemplate
11+
get() = KTemplates.ORM(this)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package st.orm.kotlin.template
2+
3+
import st.orm.kotlin.template.KORMTemplate
4+
import st.orm.template.JpaTemplate
5+
6+
/**
7+
* Extension property to convert a [JpaTemplate] to a [KORMTemplate].
8+
*/
9+
val JpaTemplate.orm: KORMTemplate
10+
get() = KORMTemplate.from(this.toORM())

0 commit comments

Comments
 (0)