Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 4.1.0 #567

Merged
merged 45 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
93d0919
Update documentation for insertOrUpdate and bulkInsertOrUpdate
ipalo Apr 7, 2023
87d166e
provide access to changed properties
HC-224 Nov 13, 2023
a5b1be8
restore repositories from local testing
HC-224 Nov 13, 2023
45e6c5e
Fixed a binary compatibility error when using a higher version of Kot…
k163377 Nov 18, 2023
2e03877
add open modifier for BaseTable.asExpression function
qumn Jun 13, 2024
8360f33
fix: reduce memory allocation on Column.label used for accessing in q…
AlexRiedler Jun 20, 2024
33a631f
prepare for 4.1.0
vincentlauvlwj Jun 24, 2024
f395aa6
Merge pull request #527 from k163377/fix/526
vincentlauvlwj Jun 24, 2024
c31b425
Merge pull request #560 from qumn/basetable-asexpression-open
vincentlauvlwj Jun 24, 2024
1bcc905
fix typo
vincentlauvlwj Jun 24, 2024
da835e3
Merge pull request #501 from ipalo/patch-1
vincentlauvlwj Jun 29, 2024
733494a
update comment
vincentlauvlwj Jul 1, 2024
59583df
update comment
vincentlauvlwj Jul 1, 2024
e47924c
update comment
vincentlauvlwj Jul 1, 2024
6bc8c41
update comment
vincentlauvlwj Jul 1, 2024
6dba151
update comment
vincentlauvlwj Jul 1, 2024
46c5f9e
update comment
vincentlauvlwj Jul 6, 2024
0a03a29
fix typo
vincentlauvlwj Jul 6, 2024
55cb324
Merge pull request #525 from HC-224/changed-properties
vincentlauvlwj Jul 6, 2024
3747ce7
update comment
vincentlauvlwj Jul 7, 2024
0e3925b
fix code style
vincentlauvlwj Jul 7, 2024
8bdb8a7
fix detekt rule
vincentlauvlwj Jul 7, 2024
41821a4
fix skip property names
vincentlauvlwj Jul 8, 2024
8f0390e
refactor
vincentlauvlwj Jul 8, 2024
91730de
test internal changed properties for nested binding
vincentlauvlwj Jul 8, 2024
0bb6d3d
find changed properties
vincentlauvlwj Jul 8, 2024
56638d6
add api to check if entity is attached
vincentlauvlwj Jul 8, 2024
5fdd30e
test changed properties for nested binding
vincentlauvlwj Jul 8, 2024
fb0c257
test changed properties for reference binding
vincentlauvlwj Jul 8, 2024
46e18c9
flushChanges & delete throw SQLException
vincentlauvlwj Jul 8, 2024
4c3d904
fix detekt rules
vincentlauvlwj Jul 8, 2024
94b95c7
fix failed tests
vincentlauvlwj Jul 9, 2024
1377e38
fix code style
vincentlauvlwj Jul 9, 2024
2e2ab58
Merge pull request #564 from AlexRiedler/reduce-allocation-on-label
vincentlauvlwj Jul 12, 2024
493aa76
fix code style
vincentlauvlwj Jul 12, 2024
bd9990f
init Column's properties when constructing the instance
vincentlauvlwj Jul 12, 2024
94e4f6f
upgrade github actions
vincentlauvlwj Jul 13, 2024
57e09c1
fix failed build
vincentlauvlwj Jul 13, 2024
2c75fec
build on jdk 21 & 22
vincentlauvlwj Jul 13, 2024
14f43da
upgrade to gradle 8.9
vincentlauvlwj Jul 13, 2024
c44626b
upgrade kotlin version
vincentlauvlwj Jul 15, 2024
a7edb4a
upgrade detekt version
vincentlauvlwj Jul 15, 2024
cdc7eb9
remove jdk 22 build
vincentlauvlwj Jul 15, 2024
ea8d2c0
remove moditet plugin
vincentlauvlwj Jul 16, 2024
c4b9347
release 4.1.0
vincentlauvlwj Jul 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ jobs:
strategy:
fail-fast: true
matrix:
java: [8, 11, 17, 20]
java: [8, 11, 17, 21]
steps:
- name: Checkout Code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup Java
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: zulu
java-version: ${{ matrix.java }}

- name: Setup Gradle
uses: gradle/gradle-build-action@v2
uses: gradle/actions/setup-gradle@v3

- name: Assemble the Project
run: ./gradlew assemble
Expand All @@ -45,6 +45,8 @@ jobs:
ktorm-core/build/reports/jacoco/test/jacocoTestReport.csv
ktorm-global/build/reports/jacoco/test/jacocoTestReport.csv
ktorm-jackson/build/reports/jacoco/test/jacocoTestReport.csv
ktorm-ksp-annotations/build/reports/jacoco/test/jacocoTestReport.csv
ktorm-ksp-compiler/build/reports/jacoco/test/jacocoTestReport.csv
ktorm-support-mysql/build/reports/jacoco/test/jacocoTestReport.csv
ktorm-support-oracle/build/reports/jacoco/test/jacocoTestReport.csv
ktorm-support-postgresql/build/reports/jacoco/test/jacocoTestReport.csv
Expand Down Expand Up @@ -78,16 +80,16 @@ jobs:
needs: build
steps:
- name: Checkout Code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup Java
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: zulu
java-version: 8

- name: Setup Gradle
uses: gradle/gradle-build-action@v2
uses: gradle/actions/setup-gradle@v3

- name: Assemble the Project
run: ./gradlew assemble
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ object Employees : Table<Employee>("t_employee") {
}
```

> Naming Strategy: It's highly recommended to name your entity classes by singular nouns, name table objects by plurals (eg. Employee/Employees, Department/Departments).
> Naming Strategy: It's highly recommended to name your entity classes by singular nouns, name table objects by plurals (e.g. Employee/Employees, Department/Departments).

Now that column bindings are configured, so we can use [sequence APIs](#Entity-Sequence-APIs) to perform many operations on entities. Let's add two extension properties for `Database` first. These properties return new created sequence objects via `sequenceOf` and they can help us improve the readability of the code:

Expand Down
6 changes: 3 additions & 3 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repositories {
}

dependencies {
api("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.0")
api("org.moditect:moditect-gradle-plugin:1.0.0-rc3")
api("io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.23.1")
api("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.23")
api("org.moditect:moditect:1.0.0.RC1")
api("io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.23.6")
}
43 changes: 25 additions & 18 deletions buildSrc/src/main/kotlin/ktorm.modularity.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,30 +1,37 @@

plugins {
id("kotlin")
id("org.moditect.gradleplugin")
}

moditect {
// Generate a multi-release jar, the module descriptor will be located at META-INF/versions/9/module-info.class
addMainModuleInfo {
jvmVersion.set("9")
overwriteExistingFiles.set(true)
module {
moduleInfoFile = file("src/main/moditect/module-info.java")
val moditect by tasks.registering {
doLast {
// Generate a multi-release modulized jar, module descriptor position: META-INF/versions/9/module-info.class
val inputJar = tasks.jar.flatMap { it.archiveFile }.map { it.asFile.toPath() }.get()
val outputDir = file("build/moditect").apply { mkdirs() }.toPath()
val moduleInfo = file("src/main/moditect/module-info.java").readText()
val version = project.version.toString()
org.moditect.commands.AddModuleInfo(moduleInfo, null, version, inputJar, outputDir, "9", true).run()

// Replace the original jar with the modulized jar.
copy {
from(outputDir.resolve(inputJar.fileName))
into(inputJar.parent)
}
}
}

// Let kotlin compiler know the module descriptor.
if (JavaVersion.current() >= JavaVersion.VERSION_1_9) {
sourceSets.main {
kotlin.srcDir("src/main/moditect")
}
tasks {
moditect {
dependsOn(jar)
}
jar {
finalizedBy(moditect)
}
}

// Workaround to avoid circular task dependencies, see https://github.com/moditect/moditect-gradle-plugin/issues/14
afterEvaluate {
val compileJava = tasks.compileJava.get()
val addDependenciesModuleInfo = tasks.addDependenciesModuleInfo.get()
compileJava.setDependsOn(compileJava.dependsOn - addDependenciesModuleInfo)
if (JavaVersion.current() >= JavaVersion.VERSION_1_9) {
// Let kotlin compiler know the module descriptor.
sourceSets.main {
kotlin.srcDir("src/main/moditect")
}
}
5 changes: 5 additions & 0 deletions buildSrc/src/main/kotlin/ktorm.publish.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ publishing {
id.set("brohacz")
name.set("Michal Brosig")
}
developer {
id.set("hc224")
name.set("hc224")
email.set("[email protected]")
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ complexity:
active: true
threshold: 4
ComplexInterface:
active: true
active: false
threshold: 12
includeStaticDeclarations: false
CyclomaticComplexMethod:
Expand All @@ -75,7 +75,7 @@ complexity:
active: false
threshold: 7
NestedBlockDepth:
active: true
active: false
threshold: 5
StringLiteralDuplication:
active: false
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion ktorm-core/ktorm-core.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ val testOutput by configurations.creating {
}

val testJar by tasks.registering(Jar::class) {
dependsOn("testClasses")
dependsOn(tasks.testClasses)
from(sourceSets.test.map { it.output })
archiveClassifier.set("test")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,7 @@ public open class CachedRowSet(rs: ResultSet) : ResultSet {
return index
}
}

throw SQLException("Invalid column name: $columnLabel")
}

Expand Down
2 changes: 1 addition & 1 deletion ktorm-core/src/main/kotlin/org/ktorm/database/Database.kt
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public class Database(
public val name: String

/**
* The name of the connected database product, eg. MySQL, H2.
* The name of the connected database product, e.g. MySQL, H2.
*/
public val productName: String

Expand Down
27 changes: 18 additions & 9 deletions ktorm-core/src/main/kotlin/org/ktorm/entity/Entity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import java.io.ObjectInputStream
import java.io.ObjectOutputStream
import java.io.Serializable
import java.lang.reflect.Proxy
import java.sql.SQLException
import kotlin.reflect.KClass
import kotlin.reflect.full.isSubclassOf
import kotlin.reflect.jvm.jvmErasure
Expand Down Expand Up @@ -69,12 +70,12 @@ import kotlin.reflect.jvm.jvmErasure
*
* - For [Boolean] type, the default value is `false`.
* - For [Char] type, the default value is `\u0000`.
* - For number types (such as [Int], [Long], [Double], etc), the default value is zero.
* - For number types (such as [Int], [Long], [Double], etc.), the default value is zero.
* - For [String] type, the default value is an empty string.
* - For entity types, the default value is a new-created entity object which is empty.
* - For enum types, the default value is the first value of the enum, whose ordinal is 0.
* - For array types, the default value is a new-created empty array.
* - For collection types (such as [Set], [List], [Map], etc), the default value is a new created mutable collection
* - For collection types (such as [Set], [List], [Map], etc.), the default value is a new created mutable collection
* of the concrete type.
* - For any other types, the default value is an instance created by its no-args constructor. If the constructor
* doesn't exist, an exception is thrown.
Expand Down Expand Up @@ -128,7 +129,7 @@ import kotlin.reflect.jvm.jvmErasure
* refer to their documentation for more details.
*
* Besides of JDK serialization, the ktorm-jackson module also supports serializing entities in JSON format. This
* module provides an extension for Jackson, the famous JSON framework in Java word. It supports serializing entity
* module provides an extension for Jackson, the famous JSON framework in Java world. It supports serializing entity
* objects into JSON format and parsing JSONs as entity objects. More details can be found in its documentation.
*/
public interface Entity<E : Entity<E>> : Serializable {
Expand All @@ -143,6 +144,13 @@ public interface Entity<E : Entity<E>> : Serializable {
*/
public val properties: Map<String, Any?>

/**
* Return the immutable view of this entity's changed properties and their original values.
*
* @since 4.1.0
*/
public val changedProperties: Map<String, Any?>

/**
* Update the property changes of this entity into the database and return the affected record number.
*
Expand All @@ -156,18 +164,18 @@ public interface Entity<E : Entity<E>> : Serializable {
* `fromDatabase` references point to the database they are obtained from. For entity objects created by
* [Entity.create] or [Entity.Factory], their `fromDatabase` references are `null` initially, so we can not call
* [flushChanges] on them. But once we use them with [add] or [update] function, `fromDatabase` will be modified
* to the current database, so we will be able to call [flushChanges] on them afterwards.
* to the current database, so we will be able to call [flushChanges] on them afterward.
*
* @see add
* @see update
*/
@Throws(SQLException::class)
public fun flushChanges(): Int

/**
* Clear the tracked property changes of this entity.
*
* After calling this function, the [flushChanges] doesn't do anything anymore because the property changes
* are discarded.
* After calling this function, [flushChanges] will do nothing because property changes are discarded.
*/
public fun discardChanges()

Expand All @@ -185,13 +193,14 @@ public interface Entity<E : Entity<E>> : Serializable {
* @see update
* @see flushChanges
*/
@Throws(SQLException::class)
public fun delete(): Int

/**
* Obtain a property's value by its name.
*
* Note that this function doesn't follow the rules of default values discussed in the class level documentation.
* If the value doesn't exist, we will return `null` simply.
* If the value doesn't exist, it will simply return `null`.
*/
public operator fun get(name: String): Any?

Expand Down Expand Up @@ -221,8 +230,8 @@ public interface Entity<E : Entity<E>> : Serializable {
public override fun hashCode(): Int

/**
* Return a string representation of this table.
* The format is like `Employee{id=1, name=Eric, job=contributor, hireDate=2021-05-05, salary=50}`.
* Return a string representation of this entity.
* The format is like `Employee(id=1, name=Eric, job=contributor, hireDate=2021-05-05, salary=50)`.
*/
public override fun toString(): String

Expand Down
Loading