Namespace refactoring
This commit is contained in:
parent
b972cffc17
commit
7760b38549
@ -1,26 +1,31 @@
|
||||
package ru.landgrafhomyak.db.raw_sql_skeleton
|
||||
|
||||
public class Namespace(
|
||||
public val _name: String,
|
||||
private val path: Array<String>
|
||||
public val name: String,
|
||||
private val _path: Array<String>
|
||||
) {
|
||||
private val usedNames = HashSet<String>()
|
||||
private val _usedNames = HashSet<String>()
|
||||
|
||||
public fun subnamespace(name: String): Namespace {
|
||||
if (name in this.usedNames)
|
||||
throw IllegalArgumentException("Name is already used: $name")
|
||||
this.usedNames.add(name)
|
||||
return Namespace(name, this.path + this._name)
|
||||
private fun _allocName(name: String): String {
|
||||
if (!this._usedNames.add(name))
|
||||
throw IllegalArgumentException("Name duplication: $name")
|
||||
return name
|
||||
}
|
||||
|
||||
private fun _formatTableName(name: String) = this._path.joinToString(prefix = "::", separator = "::", postfix = "::${this.name}::${name}")
|
||||
|
||||
public fun subnamespace(name: String): Namespace =
|
||||
Namespace(this._allocName(name), this._path + this.name)
|
||||
|
||||
|
||||
public fun table(name: String): Table {
|
||||
if (name in this.usedNames)
|
||||
throw IllegalArgumentException("Name is already used: $name")
|
||||
this.usedNames.add(name)
|
||||
|
||||
return Table(this, this.formatTableName(name))
|
||||
return Table(this, this._formatTableName(this._allocName(name)))
|
||||
}
|
||||
|
||||
public val _path: List<String> = this.path.asList()
|
||||
private fun formatTableName(name: String) = this.path.joinToString(prefix = "::", separator = "::", postfix = "::${this._name}::${name}")
|
||||
public fun <tUE : Any> table(name: String, constructor: TableConstructor<tUE>): tUE {
|
||||
val table = this.table(name)
|
||||
return constructor.createTable(table, TableConstructor.Scope(table))
|
||||
}
|
||||
|
||||
public val path: List<String> = this._path.asList()
|
||||
}
|
Loading…
Reference in New Issue
Block a user