Skip to content

Commit

Permalink
dep v bump
Browse files Browse the repository at this point in the history
  • Loading branch information
mvysny committed Jan 22, 2024
1 parent 23d71b4 commit cf0ae09
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 40 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ tasks.withType<KotlinCompile> {
dependencies {
api(kotlin("stdlib-jdk8"))
api("com.github.mvysny.vokdataloader:vok-dataloader:0.9.1")
api("com.gitlab.mvysny.jdbiorm:jdbi-orm:1.0")
api("com.gitlab.mvysny.jdbiorm:jdbi-orm:2.1")

// logging
implementation("org.slf4j:slf4j-api:$slf4jVersion")
Expand Down
10 changes: 5 additions & 5 deletions src/main/kotlin/com/github/vokorm/Dao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import com.gitlab.mvysny.jdbiorm.EntityMeta
import com.gitlab.mvysny.jdbiorm.JdbiOrm
import org.jdbi.v3.core.statement.Query

internal val <E> DaoOfAny<E>.meta: EntityMeta<E> get() = EntityMeta(entityClass)
internal val <E> DaoOfAny<E>.meta: EntityMeta<E> get() = EntityMeta.of(entityClass)

/**
* Retrieves single entity matching given [filter]. Fails if there is no such entity, or if there are two or more entities matching the criteria.
Expand Down Expand Up @@ -91,7 +91,7 @@ public fun <T : Any> DaoOfAny<T>.count(filter: Filter<T>): Long {
* db { con.createQuery("delete from Foo where name = :name").addParameter("name", name).executeUpdate() }
* ```
*/
public fun <T : Any> DaoOfAny<T>.deleteBy(block: FilterBuilder<T>.() -> Filter<T>) {
public fun <T : Any> DaoOfAny<T>.deleteBy2(block: FilterBuilder<T>.() -> Filter<T>) {
deleteBy(FilterBuilder<T>(entityClass).block())
}

Expand All @@ -118,7 +118,7 @@ public fun <T : Any> DaoOfAny<T>.deleteBy(filter: Filter<T>) {
* @param range use LIMIT+OFFSET to fetch given page of data. Defaults to all data.
* @param block the filter to use.
*/
public fun <T : Any> DaoOfAny<T>.findAllBy(
public fun <T : Any> DaoOfAny<T>.findAllBy2(
vararg orderBy: SortClause = arrayOf(),
range: IntRange = IntRange(0, Int.MAX_VALUE),
block: FilterBuilder<T>.() -> Filter<T>
Expand Down Expand Up @@ -171,7 +171,7 @@ public fun <T : Any> DaoOfAny<T>.findAllBy(
*
* ```
* Person.existsBy { "name = :name"("name" to "Albedo") } // raw sql where clause with parameters, preferred
* Person.existsBy { Person::name eq "Rubedo" } // fancy type-safe criteria, useful when you need to construct queries programatically.
* Person.existsBy { Person::name eq "Rubedo" } // fancy type-safe criteria, useful when you need to construct queries programmatically.
* ```
*
* If you want more complex stuff or even joins, fall back and just write SQL:
Expand All @@ -181,7 +181,7 @@ public fun <T : Any> DaoOfAny<T>.findAllBy(
* ```
* @param block the filter to use.
*/
public fun <T : Any> DaoOfAny<T>.existsBy(block: FilterBuilder<T>.() -> Filter<T>): Boolean =
public fun <T : Any> DaoOfAny<T>.existsBy2(block: FilterBuilder<T>.() -> Filter<T>): Boolean =
existsBy(block(FilterBuilder(entityClass)))

/**
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/com/github/vokorm/Filters.kt
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ public class DefaultFilterToSqlConverter : FilterToSqlConverter {
mapOf(parameterName to filter.words.joinToString(" & ") { "$it:*" }))
}
DatabaseVariant.H2 -> {
val meta: EntityMeta<*> = EntityMeta(clazz)
val idColumn: String = meta.idProperty[0].dbColumnName
val meta: EntityMeta<*> = EntityMeta.of(clazz)
val idColumn: String = meta.idProperty[0].dbName.qualifiedName
val query: String = filter.words.joinToString(" AND ") { "$it*" }
// Need to CAST(FT.KEYS[1] AS BIGINT) otherwise IN won't match anything
ParametrizedSql("$idColumn IN (SELECT CAST(FT.KEYS[1] AS BIGINT) AS ID FROM FTL_SEARCH_DATA(:$parameterName, 0, 0) FT WHERE FT.`TABLE`='${meta.databaseTableName.uppercase()}')",
Expand Down
8 changes: 4 additions & 4 deletions src/main/kotlin/com/github/vokorm/KEntity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public interface KEntity<ID: Any> : AbstractEntity<ID> {
* @throws ConstraintViolationException when validation fails.
*/
public fun validate() {
EntityMeta<KEntity<ID>>(javaClass).defaultValidate(this)
EntityMeta.of<KEntity<ID>>(javaClass).defaultValidate(this)
}

/**
Expand Down Expand Up @@ -109,7 +109,7 @@ public interface KEntity<ID: Any> : AbstractEntity<ID> {
if (validate) {
validate()
}
EntityMeta<KEntity<ID>>(javaClass).defaultCreate(this)
EntityMeta.of<KEntity<ID>>(javaClass).defaultCreate(this)
}

/**
Expand Down Expand Up @@ -141,7 +141,7 @@ public interface KEntity<ID: Any> : AbstractEntity<ID> {
if (id == null) {
create(false) // no need to validate again
} else {
EntityMeta<KEntity<ID>>(javaClass).defaultSave(this)
EntityMeta.of<KEntity<ID>>(javaClass).defaultSave(this)
}
}

Expand All @@ -152,6 +152,6 @@ public interface KEntity<ID: Any> : AbstractEntity<ID> {
*/
public fun reload() {
checkNotNull(id) { "Invalid state: id is null" }
EntityMeta<KEntity<*>>(javaClass).defaultReload(this)
EntityMeta.of<KEntity<*>>(javaClass).defaultReload(this)
}
}
4 changes: 2 additions & 2 deletions src/main/kotlin/com/github/vokorm/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ internal fun List<SortClause>.toSql92OrderByClause(entityClass: Class<*>): Strin
* property then it assumes that the data loader property name is already the column name and simply returns this.
*/
internal fun DataLoaderPropertyName.toNativeColumnName(clazz: Class<*>): NativePropertyName {
val property: PropertyMeta = EntityMeta(clazz).properties.firstOrNull { it.name == this } ?: return this
return property.dbColumnName
val property: PropertyMeta = EntityMeta.of(clazz).properties.firstOrNull { it.name.name == this } ?: return this
return property.dbName.unqualifiedName
}
16 changes: 8 additions & 8 deletions src/test/kotlin/com/github/vokorm/DaoTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ fun DynaNodeGroup.dbDaoTests() {
}
test("DeleteBy") {
listOf("Albedo", "Nigredo", "Rubedo").forEach { Person(name = it, age = 129).save() }
Person.deleteBy { "name = :name"("name" to "Albedo") } // raw sql where
Person.deleteBy2 { "name = :name"("name" to "Albedo") } // raw sql where
expect(listOf("Nigredo", "Rubedo")) { Person.findAll().map { it.name } }
Person.deleteBy { Person::name eq "Rubedo" } // fancy type-safe criteria
Person.deleteBy2 { Person::name eq "Rubedo" } // fancy type-safe criteria
expect(listOf("Nigredo")) { Person.findAll().map { it.name } }
}
group("findOneBy() tests") {
Expand Down Expand Up @@ -130,21 +130,21 @@ fun DynaNodeGroup.dbDaoTests() {
test("returns false on empty table") {
expect(false) { Person.existsAny() }
expect(false) { Person.existsById(25) }
expect(false) { Person.existsBy { Person::age le 26 } }
expect(false) { Person.existsBy2 { Person::age le 26 } }
}
test("returns true on matching entity") {
val p = Person(name = "Albedo", age = 134)
p.save()
expect(true) { Person.existsAny() }
expect(true) { Person.existsById(p.id!!) }
expect(true) { Person.existsBy { Person::age ge 26 } }
expect(true) { Person.existsBy2 { Person::age ge 26 } }
}
test("returns false on non-matching entity") {
val p = Person(name = "Albedo", age = 135)
p.save()
expect(true) { Person.existsAny() }
expect(false) { Person.existsById(p.id!! + 1) }
expect(false) { Person.existsBy { Person::age le 26 } }
expect(false) { Person.existsBy2 { Person::age le 26 } }
}
}
test("sql92 filter works") {
Expand Down Expand Up @@ -205,7 +205,7 @@ fun DynaNodeGroup.dbDaoTests() {
}
test("DeleteBy") {
listOf("Albedo", "Nigredo", "Rubedo").forEach { EntityWithAliasedId(name = it).save() }
EntityWithAliasedId.deleteBy { "name = :name"("name" to "Albedo") } // raw sql where
EntityWithAliasedId.deleteBy2 { "name = :name"("name" to "Albedo") } // raw sql where
expect(listOf("Nigredo", "Rubedo")) { EntityWithAliasedId.findAll().map { it.name } }
}
group("findOneBy() tests") {
Expand All @@ -219,14 +219,14 @@ fun DynaNodeGroup.dbDaoTests() {
test("returns false on empty table") {
expect(false) { EntityWithAliasedId.existsAny() }
expect(false) { EntityWithAliasedId.existsById(25) }
expect(false) { EntityWithAliasedId.existsBy { EntityWithAliasedId::name le "a" } }
expect(false) { EntityWithAliasedId.existsBy2 { EntityWithAliasedId::name le "a" } }
}
test("returns true on matching entity") {
val p = EntityWithAliasedId(name = "Albedo")
p.save()
expect(true) { EntityWithAliasedId.existsAny() }
expect(true) { EntityWithAliasedId.existsById(p.id!!) }
expect(true) { EntityWithAliasedId.existsBy { EntityWithAliasedId::name eq "Albedo" } }
expect(true) { EntityWithAliasedId.existsBy2 { EntityWithAliasedId::name eq "Albedo" } }
}
}
}
Expand Down
28 changes: 14 additions & 14 deletions src/test/kotlin/com/github/vokorm/FiltersTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,67 +48,67 @@ fun DynaNodeGroup.dbFiltersTest(info: DatabaseInfo) {

test("eq filter test") {
expectList() {
Person.findAllBy { Person::age eq 40 }.map { it.name }
Person.findAllBy2 { Person::age eq 40 }.map { it.name }
}
expectList("Jerry") {
Person.findAllBy { Person::age eq 26 }.map { it.name }
Person.findAllBy2 { Person::age eq 26 }.map { it.name }
}
}

test("ne filter test") {
expectList("Moby", "Jerry", "Paul") {
Person.findAllBy { Person::age ne 40 }.map { it.name }
Person.findAllBy2 { Person::age ne 40 }.map { it.name }
}
expectList("Jerry", "Paul") {
Person.findAllBy { Person::age ne 25 }.map { it.name }
Person.findAllBy2 { Person::age ne 25 }.map { it.name }
}
}

test("le filter test") {
expectList("Moby", "Jerry", "Paul") {
Person.findAllBy { Person::age le 40 }.map { it.name }
Person.findAllBy2 { Person::age le 40 }.map { it.name }
}
expectList("Moby", "Jerry") {
Person.findAllBy { Person::age le 26 }.map { it.name }
Person.findAllBy2 { Person::age le 26 }.map { it.name }
}
}

test("lt filter test") {
expectList("Moby", "Jerry", "Paul") {
Person.findAllBy { Person::age lt 40 }.map { it.name }
Person.findAllBy2 { Person::age lt 40 }.map { it.name }
}
expectList("Moby") {
Person.findAllBy { Person::age lt 26 }.map { it.name }
Person.findAllBy2 { Person::age lt 26 }.map { it.name }
}
}

test("ge filter test") {
expectList() {
Person.findAllBy { Person::age ge 40 }.map { it.name }
Person.findAllBy2 { Person::age ge 40 }.map { it.name }
}
expectList("Jerry", "Paul") {
Person.findAllBy { Person::age ge 26 }.map { it.name }
Person.findAllBy2 { Person::age ge 26 }.map { it.name }
}
}

test("gt filter test") {
expectList() {
Person.findAllBy { Person::age gt 40 }.map { it.name }
Person.findAllBy2 { Person::age gt 40 }.map { it.name }
}
expectList("Paul") {
Person.findAllBy { Person::age gt 26 }.map { it.name }
Person.findAllBy2 { Person::age gt 26 }.map { it.name }
}
}

test("not filter test") {
expectList("Moby", "Paul") {
Person.findAllBy { !(Person::age eq 26) }.map { it.name }
Person.findAllBy2 { !(Person::age eq 26) }.map { it.name }
}
}

test("in filter test") {
expectList("Moby", "Jerry") {
Person.findAllBy { Person::age `in` listOf(25, 26, 28) }.map { it.name }
Person.findAllBy2 { Person::age `in` listOf(25, 26, 28) }.map { it.name }
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/test/kotlin/com/github/vokorm/MappingTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ fun DynaNodeGroup.dbMappingTests() {
test("Meta") {
val meta = Person.meta
expect("Test") { meta.databaseTableName } // since Person is annotated with @Entity("Test")
expect("id") { meta.idProperty[0].dbColumnName }
expect("Test.id") { meta.idProperty[0].dbName.qualifiedName }
expect(Person::class.java) { meta.entityClass }
expect(Long::class.java) { meta.idProperty[0].valueType }
expect(
Expand All @@ -91,7 +91,7 @@ fun DynaNodeGroup.dbMappingTests() {
"maritalStatus",
"modified"
)
) { meta.persistedFieldDbNames }
) { meta.persistedFieldDbNames.map { it.unqualifiedName } .toSet() }
}
}
group("EntityWithAliasedId") {
Expand All @@ -117,10 +117,10 @@ fun DynaNodeGroup.dbMappingTests() {
test("Meta") {
val meta = EntityWithAliasedId.meta
expect("EntityWithAliasedId") { meta.databaseTableName }
expect("myid") { meta.idProperty[0].dbColumnName }
expect("myid") { meta.idProperty[0].dbName.unqualifiedName }
expect(EntityWithAliasedId::class.java) { meta.entityClass }
expect(Long::class.java) { meta.idProperty[0].valueType }
expect(setOf("myid", "name")) { meta.persistedFieldDbNames }
expect(setOf("myid", "name")) { meta.persistedFieldDbNames.map { it.unqualifiedName } .toSet() }
}
}
group("NaturalPerson") {
Expand Down

0 comments on commit cf0ae09

Please sign in to comment.