diff --git a/storm-kotlin/src/main/kotlin/st/orm/template/ORMTemplate.kt b/storm-kotlin/src/main/kotlin/st/orm/template/ORMTemplate.kt index 042ccc184..f78aab426 100644 --- a/storm-kotlin/src/main/kotlin/st/orm/template/ORMTemplate.kt +++ b/storm-kotlin/src/main/kotlin/st/orm/template/ORMTemplate.kt @@ -24,6 +24,7 @@ import st.orm.repository.RepositoryLookup import st.orm.template.impl.ORMTemplateImpl import java.sql.Connection import javax.sql.DataSource +import kotlin.reflect.KClass /** * The primary entry point for Storm's ORM functionality in Kotlin, combining SQL template query construction with @@ -113,7 +114,7 @@ interface ORMTemplate : * @throws st.orm.PersistenceException if the template does not support schema validation. * @since 1.9 */ - fun validateSchema(types: Iterable>): List + fun validateSchema(vararg types: KClass): List /** * Validates all discovered types and throws if any errors are found. @@ -136,7 +137,7 @@ interface ORMTemplate : * @throws st.orm.PersistenceException if validation fails or the template does not support schema validation. * @since 1.9 */ - fun validateSchemaOrThrow(types: Iterable>) + fun validateSchemaOrThrow(vararg types: KClass) companion object { /** diff --git a/storm-kotlin/src/main/kotlin/st/orm/template/impl/ORMTemplateImpl.kt b/storm-kotlin/src/main/kotlin/st/orm/template/impl/ORMTemplateImpl.kt index 8c206d7e9..5350e3feb 100644 --- a/storm-kotlin/src/main/kotlin/st/orm/template/impl/ORMTemplateImpl.kt +++ b/storm-kotlin/src/main/kotlin/st/orm/template/impl/ORMTemplateImpl.kt @@ -88,11 +88,11 @@ class ORMTemplateImpl(private val core: st.orm.core.template.ORMTemplate) : override fun validateSchema(): List = core.validateSchema() - override fun validateSchema(types: Iterable>): List = core.validateSchema(types) + override fun validateSchema(vararg types: KClass): List = core.validateSchema(types.map { it.java }) override fun validateSchemaOrThrow() = core.validateSchemaOrThrow() - override fun validateSchemaOrThrow(types: Iterable>) = core.validateSchemaOrThrow(types) + override fun validateSchemaOrThrow(vararg types: KClass) = core.validateSchemaOrThrow(types.map { it.java }) /** * Returns the repository for the given entity type. diff --git a/storm-kotlin/src/test/kotlin/st/orm/template/ORMTemplateFactoryTest.kt b/storm-kotlin/src/test/kotlin/st/orm/template/ORMTemplateFactoryTest.kt index 8600ba8ab..99e58924f 100644 --- a/storm-kotlin/src/test/kotlin/st/orm/template/ORMTemplateFactoryTest.kt +++ b/storm-kotlin/src/test/kotlin/st/orm/template/ORMTemplateFactoryTest.kt @@ -167,7 +167,7 @@ open class ORMTemplateFactoryTest( @Test fun `validateSchema should return list of errors or empty`() { - val errors = orm.validateSchema(listOf(City::class.java)) + val errors = orm.validateSchema(City::class) // City should validate fine against H2 errors shouldHaveSize 0 } diff --git a/storm-kotlin/src/test/kotlin/st/orm/template/ORMTemplateTest.kt b/storm-kotlin/src/test/kotlin/st/orm/template/ORMTemplateTest.kt index 1d2013acf..e87db35c4 100644 --- a/storm-kotlin/src/test/kotlin/st/orm/template/ORMTemplateTest.kt +++ b/storm-kotlin/src/test/kotlin/st/orm/template/ORMTemplateTest.kt @@ -106,29 +106,29 @@ open class ORMTemplateTest( @Test fun `validateSchema should return empty for valid types`() { - val errors = orm.validateSchema(listOf(City::class.java)) + val errors = orm.validateSchema(City::class) errors shouldHaveSize 0 } @Test fun `validateSchema should return errors for invalid types`() { - @st.orm.DbTable("nonexistent_table") - data class NonExistentEntity(@st.orm.PK val id: Int = 0) : Entity - val errors = orm.validateSchema(listOf(NonExistentEntity::class.java)) + @DbTable("nonexistent_table") + data class NonExistentEntity(@PK val id: Int = 0) : Entity + val errors = orm.validateSchema(NonExistentEntity::class) errors.size shouldBe 1 } @Test fun `validateSchemaOrThrow should not throw for valid types`() { - orm.validateSchemaOrThrow(listOf(City::class.java)) + orm.validateSchemaOrThrow(City::class) } @Test fun `validateSchemaOrThrow should throw for invalid types`() { - @st.orm.DbTable("nonexistent_table") - data class NonExistentEntity(@st.orm.PK val id: Int = 0) : Entity + @DbTable("nonexistent_table") + data class NonExistentEntity(@PK val id: Int = 0) : Entity assertThrows { - orm.validateSchemaOrThrow(listOf(NonExistentEntity::class.java)) + orm.validateSchemaOrThrow(NonExistentEntity::class) } } diff --git a/storm-kotlin/src/test/kotlin/st/orm/template/SchemaValidationTest.kt b/storm-kotlin/src/test/kotlin/st/orm/template/SchemaValidationTest.kt index a6b9f16c8..c8025f739 100644 --- a/storm-kotlin/src/test/kotlin/st/orm/template/SchemaValidationTest.kt +++ b/storm-kotlin/src/test/kotlin/st/orm/template/SchemaValidationTest.kt @@ -28,51 +28,49 @@ open class SchemaValidationTest( @Test fun `validateSchema with City should return no errors`() { - val errors = orm.validateSchema(listOf(City::class.java)) + val errors = orm.validateSchema(City::class) errors.shouldBeEmpty() } @Test fun `validateSchema with Owner should return no errors`() { - val errors = orm.validateSchema(listOf(Owner::class.java)) + val errors = orm.validateSchema(Owner::class) errors.shouldBeEmpty() } @Test fun `validateSchema with Pet should return no errors`() { - val errors = orm.validateSchema(listOf(Pet::class.java)) + val errors = orm.validateSchema(Pet::class) errors.shouldBeEmpty() } @Test fun `validateSchema with Vet should return no errors`() { - val errors = orm.validateSchema(listOf(Vet::class.java)) + val errors = orm.validateSchema(Vet::class) errors.shouldBeEmpty() } @Test fun `validateSchema with PetType should return no errors`() { - val errors = orm.validateSchema(listOf(PetType::class.java)) + val errors = orm.validateSchema(PetType::class) errors.shouldBeEmpty() } @Test fun `validateSchema with Visit should return no errors`() { - val errors = orm.validateSchema(listOf(Visit::class.java)) + val errors = orm.validateSchema(Visit::class) errors.shouldBeEmpty() } @Test fun `validateSchema with multiple valid types should return no errors`() { val errors = orm.validateSchema( - listOf( - City::class.java, - Owner::class.java, - Pet::class.java, - PetType::class.java, - Vet::class.java, - Visit::class.java, - ), + City::class, + Owner::class, + Pet::class, + PetType::class, + Vet::class, + Visit::class, ) errors.shouldBeEmpty() } @@ -88,7 +86,7 @@ open class SchemaValidationTest( @Test fun `validateSchema with nonexistent table entity should return errors`() { - val errors = orm.validateSchema(listOf(NonExistentEntity::class.java)) + val errors = orm.validateSchema(NonExistentEntity::class) errors.shouldNotBeEmpty() } @@ -102,7 +100,7 @@ open class SchemaValidationTest( @Test fun `validateSchema with mismatched columns should return errors`() { - val errors = orm.validateSchema(listOf(CityMismatch::class.java)) + val errors = orm.validateSchema(CityMismatch::class) errors.shouldNotBeEmpty() } @@ -111,37 +109,24 @@ open class SchemaValidationTest( @Test fun `validateSchemaOrThrow with valid types should not throw`() { // Should complete without exception for valid entity types. - orm.validateSchemaOrThrow(listOf(City::class.java, Vet::class.java)) + orm.validateSchemaOrThrow(City::class, Vet::class) } @Test fun `validateSchemaOrThrow with invalid type should throw PersistenceException`() { assertThrows { - orm.validateSchemaOrThrow(listOf(NonExistentEntity::class.java)) + orm.validateSchemaOrThrow(NonExistentEntity::class) } } @Test fun `validateSchemaOrThrow with mixed valid and invalid types should throw`() { assertThrows { - orm.validateSchemaOrThrow(listOf(City::class.java, NonExistentEntity::class.java)) + orm.validateSchemaOrThrow(City::class, NonExistentEntity::class) } } - // validateSchema with empty list - - @Test - fun `validateSchema with empty list should return no errors`() { - val errors = orm.validateSchema(emptyList()) - errors.shouldBeEmpty() - } - - @Test - fun `validateSchemaOrThrow with empty list should not throw`() { - orm.validateSchemaOrThrow(emptyList()) - } - - // validateSchema on connection-backed template + // validateSchema with no args (zero varargs) @Test fun `validateSchema on connection-backed template should throw PersistenceException`() { @@ -168,12 +153,12 @@ open class SchemaValidationTest( @Test fun `validateSchema with OwnerView projection should return no errors`() { - val errors = orm.validateSchema(listOf(OwnerView::class.java)) + val errors = orm.validateSchema(OwnerView::class) errors.shouldBeEmpty() } @Test fun `validateSchemaOrThrow with OwnerView projection should not throw`() { - orm.validateSchemaOrThrow(listOf(OwnerView::class.java)) + orm.validateSchemaOrThrow(OwnerView::class) } }