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