[history/serdha] Fixes in table methods in module creator
This commit is contained in:
parent
c447770d71
commit
659cca27fc
@ -8,81 +8,363 @@ import ru.landgrafhomyak.serdha.api.v0.dml.Select
|
||||
import ru.landgrafhomyak.serdha.api.v0.dml.SelectCreator
|
||||
import ru.landgrafhomyak.serdha.api.v0.dml.Update
|
||||
import ru.landgrafhomyak.serdha.api.v0.dml.UpdateCreator
|
||||
import ru.landgrafhomyak.serdha.api.v0.runtime.SynchronizedDatabase
|
||||
import ru.landgrafhomyak.serdha.api.v0.runtime.Transaction
|
||||
|
||||
/**
|
||||
* Interface providing factory methods for descriptors of tables and queries.
|
||||
*/
|
||||
public interface ModuleCreator {
|
||||
/**
|
||||
* Functional interface for creating table.
|
||||
*
|
||||
* Can be implemented like a companion object that just calls [TableUserExtension]'s constructor with the same or similar signature.
|
||||
*
|
||||
* @param TableUserExtension User's type for containing table-related descriptors.
|
||||
*
|
||||
* @see ModuleCreator.createTable
|
||||
* @see ModuleCreator.createSessionScopeTemporaryTable
|
||||
* @see ModuleCreator.createTransactionScopeTemporaryTable
|
||||
* @see ModuleCreator.UpdateTable
|
||||
*/
|
||||
public interface CreateTable<TableUserExtension : Any> {
|
||||
/**
|
||||
* Scope method that uses [creator] to initialize table schema.
|
||||
*
|
||||
* @param creator Object with descriptor providers and factories.
|
||||
* @return User's object with descriptors for future access.
|
||||
*
|
||||
* @see ModuleCreator.createTable
|
||||
* @see ModuleCreator.createSessionScopeTemporaryTable
|
||||
* @see ModuleCreator.createTransactionScopeTemporaryTable
|
||||
* @see ModuleCreator.UpdateTable
|
||||
*/
|
||||
public fun createTable(creator: TableCreator<TableUserExtension>): TableUserExtension
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates table in [specified namespace][namespace] with [specified name][name] and stores it in the database.
|
||||
* If table was created by previous synchronizations, asserts that table at the specified path in the database is same as table provided by [initializer].
|
||||
*
|
||||
* On [module upgrading][ModuleTemplate.Creator.upgradeTemplate] this table must be [kept][ModuleCreator.updateTable] (or [renamed][ModuleCreator.renameTable]) or [deleted][ModuleCreator.deleteTable].
|
||||
*
|
||||
* @param TableUserExtension User's type for containing table-related descriptors.
|
||||
* @param namespace Way to group tables if there is a lot.
|
||||
* @param name Name of table for debugging.
|
||||
* @param initializer Table-related descriptors initializer.
|
||||
* @return Table descriptor.
|
||||
*/
|
||||
public fun <TableUserExtension : Any> createTable(namespace: Namespace, name: String, initializer: CreateTable<TableUserExtension>): Table<TableUserExtension, Nothing>
|
||||
public fun <TableUserExtension : Any> createSessionScopeTemporaryTable(initializer: CreateTable<TableUserExtension>): Table<TableUserExtension, Nothing>
|
||||
public fun <TableUserExtension : Any> createTransactionScopeTemporaryTable(initializer: CreateTable<TableUserExtension>): Table<TableUserExtension, Nothing>
|
||||
|
||||
/**
|
||||
* Creates a temporary table that exits only until connection to the database not [closed][SynchronizedDatabase._close].
|
||||
*
|
||||
* On [module upgrading][ModuleTemplate.Creator.upgradeTemplate] must be recreated if needed.
|
||||
*
|
||||
* @param TableUserExtension User's type for containing table-related descriptors.
|
||||
* @param namespace Way to group tables if there is a lot.
|
||||
* @param name Name of table for debugging.
|
||||
* @param initializer Table-related descriptors initializer.
|
||||
* @return Table descriptor.
|
||||
*/
|
||||
public fun <TableUserExtension : Any> createSessionScopeTemporaryTable(namespace: Namespace, name: String, initializer: CreateTable<TableUserExtension>): Table<TableUserExtension, 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].
|
||||
*
|
||||
* On [module upgrading][ModuleTemplate.Creator.upgradeTemplate] must be recreated if needed.
|
||||
*
|
||||
* @param TableUserExtension User's type for containing table-related descriptors.
|
||||
* @param namespace Way to group tables if there is a lot.
|
||||
* @param name Name of table for debugging.
|
||||
* @param initializer Table-related descriptors initializer.
|
||||
* @return Table descriptor.
|
||||
*/
|
||||
public fun <TableUserExtension : Any> createTransactionScopeTemporaryTable(namespace: Namespace, name: String, initializer: CreateTable<TableUserExtension>): Table<TableUserExtension, Nothing>
|
||||
|
||||
/**
|
||||
* Functional interface for updating table.
|
||||
*
|
||||
* Can be implemented like a companion object that just calls [TableNewUserExtension]'s constructor with the same or similar signature.
|
||||
*
|
||||
* @param TableNewUserExtension User's type with table's descriptors from the previous table version.
|
||||
* @param TableOldUserExtension User's type with descriptors of updated table.
|
||||
*
|
||||
* @see ModuleCreator.updateTable
|
||||
* @see ModuleCreator.renameTable
|
||||
* @see ModuleCreator.updateAndRenameTable
|
||||
* @see ModuleCreator.CreateTable
|
||||
*/
|
||||
public interface UpdateTable<TableNewUserExtension : Any, TableOldUserExtension : Any> {
|
||||
/**
|
||||
* Scope method that uses [updater] to update table schema.
|
||||
*
|
||||
* @param oldTable Descriptor to the previous version of table from which can be got user's extension with old descriptors.
|
||||
* @param updater Object with descriptor providers and factories.
|
||||
* @return User's object with updated descriptors for future access.
|
||||
*
|
||||
* @see ModuleCreator.updateTable
|
||||
* @see ModuleCreator.renameTable
|
||||
* @see ModuleCreator.updateAndRenameTable
|
||||
* @see ModuleCreator.CreateTable
|
||||
*/
|
||||
public fun updateTable(oldTable: Table<TableOldUserExtension, *>, updater: TableUpdater<TableNewUserExtension, TableOldUserExtension>): TableNewUserExtension
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Marks that table wouldn't be changed in this module version.
|
||||
*
|
||||
* @param TableUserExtension User's type with descriptors of related to table.
|
||||
* @param oldTable Descriptor of table created in a previous template version.
|
||||
* @return New table descriptor.
|
||||
*/
|
||||
public fun <TableUserExtension : Any> keepTable(
|
||||
oldTable: Table<TableUserExtension, *>,
|
||||
): Table<TableUserExtension, *>
|
||||
|
||||
/**
|
||||
* Renames or moves table without changing its schema.
|
||||
*
|
||||
* @param TableUserExtension User's type with descriptors of related to table.
|
||||
* @param table Descriptor to table which should be renamed.
|
||||
* @param newNamespace New namespace of the table. May be `null` if not changed.
|
||||
* @param newName New namespace of the table. May be `null` if not changed.
|
||||
* @return New table descriptor.
|
||||
* @throws IllegalArgumentException If both [newName] and [newNamespace] are same as old or `null`.
|
||||
*/
|
||||
public fun <TableUserExtension : Any> renameTable(
|
||||
table: Table<TableUserExtension, *>,
|
||||
newNamespace: Namespace? = null,
|
||||
newName: String? = null
|
||||
): Table<TableUserExtension, *>
|
||||
|
||||
/**
|
||||
* Updates table's descriptors without changing its [name][Table.name] or [namespace][Table.namespacesFromModuleRoot].
|
||||
*
|
||||
* @param TableNewUserExtension User's type with descriptors of updated table.
|
||||
* @param TableOldUserExtension User's type with table's descriptors from the previous table version.
|
||||
* @param oldTable Descriptor to the previous version of table from which can be got user's extension with old descriptors.
|
||||
* @param updater Object with descriptor providers and factories.
|
||||
* @return New table descriptor.
|
||||
*/
|
||||
public fun <TableNewUserExtension : Any, TableOldUserExtension : Any> updateTable(
|
||||
oldTable: Table<TableOldUserExtension, *>,
|
||||
initializer: UpdateTable<TableNewUserExtension, TableOldUserExtension>
|
||||
updater: UpdateTable<TableNewUserExtension, TableOldUserExtension>
|
||||
): Table<TableNewUserExtension, TableOldUserExtension>
|
||||
|
||||
public fun <TableNewUserExtension : Any, TableOldUserExtension : Any> renameTable(
|
||||
table: Table<TableNewUserExtension, TableOldUserExtension>,
|
||||
newName: String
|
||||
): Table<TableNewUserExtension, TableOldUserExtension>
|
||||
|
||||
public fun <TableNewUserExtension : Any, TableOldUserExtension : Any> renameTable(
|
||||
table: Table<TableNewUserExtension, TableOldUserExtension>,
|
||||
newNamespace: Namespace,
|
||||
newName: String
|
||||
): Table<TableNewUserExtension, TableOldUserExtension>
|
||||
|
||||
/**
|
||||
* Both updates table's schema and renames or moves table.
|
||||
*
|
||||
* @param TableNewUserExtension User's type with descriptors of updated table.
|
||||
* @param TableOldUserExtension User's type with table's descriptors from the previous table version.
|
||||
* @param oldTable Descriptor of table which should be renamed and updated.
|
||||
* @param newNamespace New namespace of the table. May be `null` if not changed.
|
||||
* @param newName New namespace of the table. May be `null` if not changed.
|
||||
* @param updater Object with descriptor providers and factories.
|
||||
* @return New table descriptor.
|
||||
* @throws IllegalArgumentException If both [newName] and [newNamespace] are same as old or `null`.
|
||||
*/
|
||||
public fun <TableNewUserExtension : Any, TableOldUserExtension : Any> updateAndRenameTable(
|
||||
table: Table<TableOldUserExtension, *>,
|
||||
newName: String,
|
||||
initializer: UpdateTable<TableNewUserExtension, TableOldUserExtension>
|
||||
oldTable: Table<TableNewUserExtension, TableOldUserExtension>,
|
||||
newNamespace: Namespace? = null,
|
||||
newName: String? = null,
|
||||
updater: UpdateTable<TableNewUserExtension, TableOldUserExtension>
|
||||
): Table<TableNewUserExtension, TableOldUserExtension>
|
||||
|
||||
public fun <TableNewUserExtension : Any, TableOldUserExtension : Any> updateAndRenameTable(
|
||||
table: Table<TableNewUserExtension, TableOldUserExtension>,
|
||||
newNamespace: Namespace,
|
||||
newName: String,
|
||||
initializer: UpdateTable<TableNewUserExtension, TableOldUserExtension>
|
||||
): Table<TableNewUserExtension, TableOldUserExtension>
|
||||
|
||||
public fun <TableUserExtension : Any> createTempTable(namespace: Namespace, name: String, initializer: CreateTable<TableUserExtension>): Table<TableUserExtension, Nothing>
|
||||
/**
|
||||
* Deletes table and all data in it.
|
||||
*
|
||||
* @param table Descriptor of table which should be deleted.
|
||||
*/
|
||||
public fun deleteTable(table: Table<*, *>)
|
||||
|
||||
/**
|
||||
* Functional interface for creating 'SELECT' query.
|
||||
*
|
||||
* Can be implemented like a companion object that just calls [QueryUserWrapper]'s constructor with the same or similar signature.
|
||||
*
|
||||
* @param QueryUserWrapper User's type with descriptors related to query.
|
||||
*
|
||||
* @see ModuleCreator.createSelect
|
||||
*/
|
||||
public interface CreateSelect<QueryUserWrapper : Any> {
|
||||
/**
|
||||
* Scope method that uses [creator] to create a query.
|
||||
*
|
||||
* @param creator Object with descriptor providers and factories.
|
||||
* @return User's object with updated descriptors for future access.
|
||||
*
|
||||
* @see ModuleCreator.createSelect
|
||||
*/
|
||||
public fun createSelect(creator: SelectCreator<QueryUserWrapper>): QueryUserWrapper
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates 'SELECT' query.
|
||||
*
|
||||
* On [module upgrading][ModuleTemplate.Creator.upgradeTemplate] must be recreated if needed.
|
||||
*
|
||||
* @param QueryUserWrapper User's type for containing query-related descriptors.
|
||||
* @param initializer Query-related descriptors initializer.
|
||||
* @return Query descriptor.
|
||||
*/
|
||||
public fun <QueryUserWrapper : Any> createSelect(initializer: CreateSelect<QueryUserWrapper>): Select<QueryUserWrapper>
|
||||
|
||||
/**
|
||||
* Functional interface for creating 'INSERT ... VALUES' query.
|
||||
*
|
||||
* Can be implemented like a companion object that just calls [QueryUserWrapper]'s constructor with the same or similar signature.
|
||||
*
|
||||
* @param TableUserExtension User's type with descriptors related to table to which values will be inserted.
|
||||
* @param QueryUserWrapper User's type with descriptors related to query.
|
||||
*
|
||||
* @see ModuleCreator.createInsertParams
|
||||
*/
|
||||
public interface CreateInsertParams<TableUserExtension : Any, QueryUserWrapper : Any> {
|
||||
/**
|
||||
* Scope method that uses [creator] to create a query.
|
||||
*
|
||||
* @param table Descriptor of table to which values will be inserted.
|
||||
* @param creator Object with descriptor providers and factories.
|
||||
* @return User's object with updated descriptors for future access.
|
||||
*
|
||||
* @see ModuleCreator.createInsertParams
|
||||
*/
|
||||
public fun createInsert(table: Table<TableUserExtension, *>, creator: InsertCreator.InsertParams<TableUserExtension, QueryUserWrapper>): QueryUserWrapper
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates 'INSERT ... VALUES' query.
|
||||
*
|
||||
* On [module upgrading][ModuleTemplate.Creator.upgradeTemplate] must be recreated if needed.
|
||||
*
|
||||
* @param TableUserExtension User's type with descriptors related to table to which values will be inserted.
|
||||
* @param QueryUserWrapper User's type for containing query-related descriptors.
|
||||
* @param initializer Query-related descriptors initializer.
|
||||
* @return Query descriptor.
|
||||
*/
|
||||
public fun <TableUserExtension : Any, QueryUserWrapper : Any> createInsertParams(table: Table<TableUserExtension, *>, initializer: CreateInsertParams<TableUserExtension, QueryUserWrapper>): Insert.InsertParams<QueryUserWrapper>
|
||||
|
||||
/**
|
||||
* Functional interface for creating 'INSERT ... FROM' query.
|
||||
*
|
||||
* Can be implemented like a companion object that just calls [QueryUserWrapper]'s constructor with the same or similar signature.
|
||||
*
|
||||
* @param TableUserExtension User's type with descriptors related to table to which values will be inserted.
|
||||
* @param QueryUserWrapper User's type with descriptors related to query.
|
||||
*
|
||||
* @see ModuleCreator.createInsertFromQuery
|
||||
*/
|
||||
public interface CreateInsertFromQuery<TableUserExtension : Any, QueryUserWrapper : Any> {
|
||||
/**
|
||||
* Scope method that uses [creator] to create a query.
|
||||
*
|
||||
* @param table Descriptor of table to which values will be inserted.
|
||||
* @param creator Object with descriptor providers and factories.
|
||||
* @return User's object with updated descriptors for future access.
|
||||
*
|
||||
* @see ModuleCreator.createInsertFromQuery
|
||||
*/
|
||||
public fun createInsert(table: Table<TableUserExtension, *>, creator: InsertCreator.InsertFromQuery<TableUserExtension, QueryUserWrapper>): QueryUserWrapper
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates 'INSERT ... FROM' query.
|
||||
*
|
||||
* On [module upgrading][ModuleTemplate.Creator.upgradeTemplate] must be recreated if needed.
|
||||
*
|
||||
* @param TableUserExtension User's type with descriptors related to table to which values will be inserted.
|
||||
* @param initializer Query-related descriptors initializer.
|
||||
* @return Query descriptor.
|
||||
*/
|
||||
public fun <TableUserExtension : Any, QueryUserWrapper : Any> createInsertFromQuery(table: Table<TableUserExtension, *>, initializer: CreateInsertFromQuery<TableUserExtension, QueryUserWrapper>): Insert.InsertFromQuery<QueryUserWrapper>
|
||||
|
||||
/**
|
||||
* Functional interface for creating 'UPDATE' query.
|
||||
*
|
||||
* Can be implemented like a companion object that just calls [QueryUserWrapper]'s constructor with the same or similar signature.
|
||||
*
|
||||
* @param TableUserExtension User's type with descriptors related to table, whose rows will be updated.
|
||||
* @param QueryUserWrapper User's type with descriptors related to query.
|
||||
*
|
||||
* @see ModuleCreator.createUpdate
|
||||
*/
|
||||
public interface CreateUpdate<TableUserExtension : Any, QueryUserWrapper : Any> {
|
||||
/**
|
||||
* Scope method that uses [creator] to create a query.
|
||||
*
|
||||
* @param table Descriptor of table which rows will be updated.
|
||||
* @param creator Object with descriptor providers and factories.
|
||||
* @return User's object with updated descriptors for future access.
|
||||
*
|
||||
* @see ModuleCreator.createUpdate
|
||||
*/
|
||||
public fun createUpdate(table: Table<TableUserExtension, *>, creator: UpdateCreator<TableUserExtension, QueryUserWrapper>): QueryUserWrapper
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates 'UPDATE' query.
|
||||
*
|
||||
* On [module upgrading][ModuleTemplate.Creator.upgradeTemplate] must be recreated if needed.
|
||||
*
|
||||
* @param TableUserExtension User's type with descriptors related to table to which values will be inserted.
|
||||
* @param initializer Query-related descriptors initializer.
|
||||
* @return Query descriptor.
|
||||
*/
|
||||
public fun <TableUserExtension : Any, QueryUserWrapper : Any> createUpdate(table: Table<TableUserExtension, *>, initializer: CreateUpdate<TableUserExtension, QueryUserWrapper>): Update<QueryUserWrapper>
|
||||
|
||||
/**
|
||||
* Functional interface for creating 'DELETE' query.
|
||||
*
|
||||
* Can be implemented like a companion object that just calls [QueryUserWrapper]'s constructor with the same or similar signature.
|
||||
*
|
||||
* @param TableUserExtension User's type with descriptors related to table from which data will be deleted.
|
||||
* @param QueryUserWrapper User's type with descriptors related to query.
|
||||
*
|
||||
* @see ModuleCreator.createDelete
|
||||
*/
|
||||
public interface CreateDelete<TableUserExtension : Any, QueryUserWrapper : Any> {
|
||||
/**
|
||||
* Scope method that uses [creator] to create a query.
|
||||
*
|
||||
* @param table Descriptor of table from which data will be deleted.
|
||||
* @param creator Object with descriptor providers and factories.
|
||||
* @return User's object with updated descriptors for future access.
|
||||
*
|
||||
* @see ModuleCreator.createDelete
|
||||
*/
|
||||
public fun createDelete(table: Table<TableUserExtension, *>, creator: DeleteCreator<TableUserExtension, QueryUserWrapper>): QueryUserWrapper
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates 'DELETE' query.
|
||||
*
|
||||
* On [module upgrading][ModuleTemplate.Creator.upgradeTemplate] must be recreated if needed.
|
||||
*
|
||||
* @param TableUserExtension User's type with descriptors related to table from which data will be deleted.
|
||||
* @param initializer Query-related descriptors initializer.
|
||||
* @return Query descriptor.
|
||||
*/
|
||||
public fun <TableUserExtension : Any, QueryUserWrapper : Any> createDelete(table: Table<TableUserExtension, *>, initializer: CreateDelete<TableUserExtension, QueryUserWrapper>): Delete<QueryUserWrapper>
|
||||
|
||||
/**
|
||||
* Replaces [specified namespace][rootNs] with schema provided by [template].
|
||||
* [This namespace][rootNs] will be root namespace for module and shouldn't contain any other definitions.
|
||||
*
|
||||
* @param rootNs Namespace where the new module will be located.
|
||||
* @param template Schema template.
|
||||
* @return Module descriptor.
|
||||
*/
|
||||
public fun <ModuleUserExtension : Any> substituteModule(rootNs: Namespace, template: ModuleTemplate<ModuleUserExtension>): Module<ModuleUserExtension>
|
||||
|
||||
/**
|
||||
* Upgrades [module][oldModule] located at [rootNs] with new schema template.
|
||||
*
|
||||
* @param rootNs Namespace where the [old module][oldModule] is located and where upgaded module will be.
|
||||
* @param template Schema template.
|
||||
* @return Module descriptor.
|
||||
*/
|
||||
public fun <ModuleUserExtension : Any> upgradeModule(oldModule: Module<*>, rootNs: Namespace, template: ModuleTemplate<ModuleUserExtension>): Module<ModuleUserExtension>
|
||||
}
|
Loading…
Reference in New Issue
Block a user