[history/serdha] Improvements in module creation interfaces
This commit is contained in:
parent
d0f5bd8386
commit
6e9349f80b
@ -1,7 +1,7 @@
|
|||||||
package ru.landgrafhomyak.db.serdha0.api.module
|
package ru.landgrafhomyak.db.serdha0.api.module
|
||||||
|
|
||||||
import ru.landgrafhomyak.db.serdha0.api.table.Table
|
import ru.landgrafhomyak.db.serdha0.api.table.Table
|
||||||
import ru.landgrafhomyak.db.serdha0.api.queries.QueryConstructor
|
import ru.landgrafhomyak.db.serdha0.api.queries._Query
|
||||||
import ru.landgrafhomyak.db.serdha0.api.runtime.SynchronizedDatabase
|
import ru.landgrafhomyak.db.serdha0.api.runtime.SynchronizedDatabase
|
||||||
import ru.landgrafhomyak.db.serdha0.api.runtime.Transaction
|
import ru.landgrafhomyak.db.serdha0.api.runtime.Transaction
|
||||||
import ru.landgrafhomyak.db.serdha0.api.table.TableConstructor
|
import ru.landgrafhomyak.db.serdha0.api.table.TableConstructor
|
||||||
@ -13,6 +13,7 @@ import ru.landgrafhomyak.db.serdha0.api.table.TableConstructor
|
|||||||
* @see ModuleTemplate.ModuleCreator.createSchema
|
* @see ModuleTemplate.ModuleCreator.createSchema
|
||||||
*/
|
*/
|
||||||
public interface CreateModuleScope {
|
public interface CreateModuleScope {
|
||||||
|
public val rootNs: Namespace
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates table in [specified namespace][namespace] with [specified name][name] and stores it in the database.
|
* Creates table in [specified namespace][namespace] with [specified name][name] and stores it in the database.
|
||||||
@ -20,49 +21,49 @@ public interface CreateModuleScope {
|
|||||||
*
|
*
|
||||||
* On [module upgrading][ModuleTemplate.CreateModuleTemplatesScope.upgradeTemplate] this table must be [kept][UpgradeModuleScope.upgradeTable] (or [renamed][UpgradeModuleScope.renameTable]) or [deleted][UpgradeModuleScope.deleteTable].
|
* On [module upgrading][ModuleTemplate.CreateModuleTemplatesScope.upgradeTemplate] this table must be [kept][UpgradeModuleScope.upgradeTable] (or [renamed][UpgradeModuleScope.renameTable]) or [deleted][UpgradeModuleScope.deleteTable].
|
||||||
*
|
*
|
||||||
* @param TableUserExtension User's type for containing table-related descriptors.
|
* @param tUE User's type for containing table-related descriptors.
|
||||||
* @param namespace Way to group tables if there is a lot.
|
* @param namespace Way to group tables if there is a lot.
|
||||||
* @param name Name of table for debugging.
|
* @param name Name of table for debugging.
|
||||||
* @param initializer Table-related descriptors initializer.
|
* @param initializer Table-related descriptors initializer.
|
||||||
* @return Table descriptor.
|
* @return Table descriptor.
|
||||||
*/
|
*/
|
||||||
public fun <TableUserExtension : Any> createTable(namespace: Namespace, name: String, initializer: TableConstructor<TableUserExtension>): Table<TableUserExtension, Nothing>
|
public fun <tUE : Any> createTable(namespace: Namespace = this.rootNs, name: String, initializer: TableConstructor<tUE>): Table<tUE, Nothing>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a temporary table that exits only until connection to the database not [closed][SynchronizedDatabase._close].
|
* Creates a temporary table that exits only until connection to the database not [closed][SynchronizedDatabase._close].
|
||||||
*
|
*
|
||||||
* On [module upgrading][ModuleTemplate.CreateModuleTemplatesScope.upgradeTemplate] must be recreated if needed.
|
* On [module upgrading][ModuleTemplate.CreateModuleTemplatesScope.upgradeTemplate] must be recreated if needed.
|
||||||
*
|
*
|
||||||
* @param TableUserExtension User's type for containing table-related descriptors.
|
* @param tUE User's type for containing table-related descriptors.
|
||||||
* @param namespace Way to group tables if there is a lot.
|
* @param namespace Way to group tables if there is a lot.
|
||||||
* @param name Name of table for debugging.
|
* @param name Name of table for debugging.
|
||||||
* @param initializer Table-related descriptors initializer.
|
* @param initializer Table-related descriptors initializer.
|
||||||
* @return Table descriptor.
|
* @return Table descriptor.
|
||||||
*/
|
*/
|
||||||
public fun <TableUserExtension : Any> createSessionScopeTemporaryTable(namespace: Namespace, name: String, initializer: TableConstructor<TableUserExtension>): Table<TableUserExtension, Nothing>
|
public fun <tUE : Any> createSessionScopeTemporaryTable(namespace: Namespace = this.rootNs, name: String, initializer: TableConstructor<tUE>): Table<tUE, Nothing>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a temporary table that exits only inside [transaction][Transaction] and auto-deleted (or cleared, depends on driver implementation) when it [finished][Transaction._assertTransactionFinishedAndReleaseResources].
|
* Creates a temporary table that exits only inside [transaction][Transaction] and auto-deleted (or cleared, depends on driver implementation) when it [finished][Transaction._assertTransactionFinishedAndReleaseResources].
|
||||||
*
|
*
|
||||||
* On [module upgrading][ModuleTemplate.CreateModuleTemplatesScope.upgradeTemplate] must be recreated if needed.
|
* On [module upgrading][ModuleTemplate.CreateModuleTemplatesScope.upgradeTemplate] must be recreated if needed.
|
||||||
*
|
*
|
||||||
* @param TableUserExtension User's type for containing table-related descriptors.
|
* @param tUE User's type for containing table-related descriptors.
|
||||||
* @param namespace Way to group tables if there is a lot.
|
* @param namespace Way to group tables if there is a lot.
|
||||||
* @param name Name of table for debugging.
|
* @param name Name of table for debugging.
|
||||||
* @param initializer Table-related descriptors initializer.
|
* @param initializer Table-related descriptors initializer.
|
||||||
* @return Table descriptor.
|
* @return Table descriptor.
|
||||||
*/
|
*/
|
||||||
public fun <TableUserExtension : Any> createTransactionScopeTemporaryTable(namespace: Namespace, name: String, initializer: TableConstructor<TableUserExtension>): Table<TableUserExtension, Nothing>
|
public fun <tUE : Any> createTransactionScopeTemporaryTable(namespace: Namespace = this.rootNs, name: String, initializer: TableConstructor<tUE>): Table<tUE, Nothing>
|
||||||
|
|
||||||
public val queries: QueryConstructor.Scope
|
public val queries: _Query.Constructor.Scope
|
||||||
|
|
||||||
public val temporarySubqueries: QueryConstructor.Scope
|
public val temporarySubqueries: _Query.Constructor.Scope
|
||||||
|
|
||||||
public val moduleConfiguringTemporaryQueries: QueryConstructor.Scope
|
public val moduleConfiguringTemporaryQueries: _Query.Constructor.Scope
|
||||||
|
|
||||||
public fun <qUE : Any> createQuery(creator: QueryConstructor<qUE>): qUE
|
public fun <qUE : Any> createQuery(creator: _Query.Constructor<qUE>): qUE
|
||||||
|
|
||||||
public fun <qUE : Any> createModuleConfiguringTemporaryQuery(creator: QueryConstructor<qUE>): qUE
|
public fun <qUE : Any> createModuleConfiguringTemporaryQuery(creator: _Query.Constructor<qUE>): qUE
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replaces [specified namespace][rootNs] with schema provided by [template].
|
* Replaces [specified namespace][rootNs] with schema provided by [template].
|
||||||
@ -72,5 +73,5 @@ public interface CreateModuleScope {
|
|||||||
* @param template Schema template.
|
* @param template Schema template.
|
||||||
* @return Module descriptor.
|
* @return Module descriptor.
|
||||||
*/
|
*/
|
||||||
public fun <ModuleUserExtension : Any> substituteModule(rootNs: Namespace, template: ModuleTemplate<ModuleUserExtension>): Module<ModuleUserExtension>
|
public fun <mUE : Any> substituteModule(rootNs: Namespace, template: ModuleTemplate<mUE>): Module<mUE>
|
||||||
}
|
}
|
@ -3,9 +3,9 @@ package ru.landgrafhomyak.db.serdha0.api.module
|
|||||||
import kotlin.jvm.JvmName
|
import kotlin.jvm.JvmName
|
||||||
import ru.landgrafhomyak.db.serdha0.api.runtime.SynchronizedDatabase
|
import ru.landgrafhomyak.db.serdha0.api.runtime.SynchronizedDatabase
|
||||||
|
|
||||||
public interface Module<ModuleUserExtension : Any> {
|
public interface Module<mUE : Any> {
|
||||||
|
|
||||||
public val userExtension: ModuleUserExtension
|
public val uExt: mUE
|
||||||
|
|
||||||
public val versionKey: String
|
public val versionKey: String
|
||||||
|
|
||||||
|
@ -20,13 +20,13 @@ public interface ModuleTemplate<@Suppress("unused") ModuleUserExtension : Any> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public interface ModuleCreator<ModuleUserExtension : Any> {
|
public interface ModuleCreator<ModuleUserExtension : Any> {
|
||||||
public fun createSchema(rootNs: Namespace, creator: CreateModuleScope): ModuleUserExtension
|
public fun createSchema(context: CreateModuleScope): ModuleUserExtension
|
||||||
|
|
||||||
public suspend fun initData(ext: ModuleUserExtension, transaction: Transaction) {}
|
public suspend fun initData(ext: ModuleUserExtension, transaction: Transaction) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface ModuleUpgrade<OldModuleUserExtension : Any, NewModuleUserExtension : Any> {
|
public interface ModuleUpgrade<OldModuleUserExtension : Any, NewModuleUserExtension : Any> {
|
||||||
public fun upgradeSchema(oldModule: Module<OldModuleUserExtension>, rootNs: Namespace, upgrader: CreateModuleScope): NewModuleUserExtension
|
public fun upgradeSchema(context: UpgradeModuleScope<OldModuleUserExtension>): NewModuleUserExtension
|
||||||
|
|
||||||
public suspend fun upgradeData(ext: NewModuleUserExtension, transaction: Transaction) {}
|
public suspend fun upgradeData(ext: NewModuleUserExtension, transaction: Transaction) {}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user