Skip to content

Commit

Permalink
Updated deprecated methods
Browse files Browse the repository at this point in the history
  • Loading branch information
EpicSquid committed Mar 29, 2023
1 parent 5fd5a80 commit b0bb883
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,32 @@ import org.apache.commons.text.CaseUtils
import schemacrawler.schema.Column
import schemacrawler.schema.Index
import schemacrawler.schema.Table
import java.util.*

fun String.toCamelCase(capitalizeFirst: Boolean = false): String =
CaseUtils.toCamelCase(this, capitalizeFirst, '_')

// kotlin property names should be in camel case without capitalization
fun getPropertyNameForColumn(column: Column) = when {
column.name.contains('_') -> column.name.toCamelCase()
column.name.all { it.isUpperCase() } -> column.name.toLowerCase()
else -> column.name.decapitalize()
column.name.all { it.isUpperCase() } -> column.name.lowercase()
else -> column.name.replaceFirstChar { it.lowercase(Locale.getDefault()) }
}

// column names should be exactly as in the database; using lowercase for uniformity
fun getColumnName(column: Column) = column.name.toLowerCase()
fun getColumnName(column: Column) = column.name.lowercase()

fun getObjectNameForTable(table: Table) = when {
table.name.contains('_') -> table.name.toCamelCase(true)
table.name.all { it.isUpperCase() } -> table.name.toLowerCase().capitalize()
else -> table.name.capitalize()
table.name.all { it.isUpperCase() } -> table.name.lowercase()
.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }

else -> table.name.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }
}

fun getTableName(table: Table) = table.name.toLowerCase()
fun getTableName(table: Table) = table.name.lowercase()

// used in config files for mappings and such
fun getColumnConfigName(column: Column) = "${column.parent.name}.${column.name}".toLowerCase()
fun getColumnConfigName(column: Column) = "${column.parent.name}.${column.name}".lowercase()

fun getIndexName(index: Index) = index.name.toLowerCase()
fun getIndexName(index: Index) = index.name.lowercase()
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,15 @@ open class ColumnBuilder(column: Column, private val data: TableBuilderData) {
}
// char, varchar, binary -> length
String::class, ByteArray::class -> {
val collate = if (columnKClass == String::class && data.configuration?.collate != null) {
val collate = if (columnKClass == String::class && data.configuration.collate != null) {
CodeBlock.of(", %S", data.configuration.collate)
} else {
CodeBlock.of("")
}
if (columnExposedFunction?.name in listOf("char", "varchar", "binary")) {
val size = when {
arguments.isNotEmpty() -> arguments[0]
column.size >= 0 && column.size <= MaxSize.MAX_VARCHAR_SIZE -> column.size.toString()
column.size >= 0 -> column.size.toString()
else -> MaxSize.MAX_VARCHAR_SIZE.toString()
}
add("%M(%S, $size$collate)", memberName, columnInfo.columnName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ data class ColumnInfo(val column: Column, private val data: TableBuilderData) {
}

fun initializeInteger() {
when (column.columnDataType.name.toLowerCase()) {
when (column.columnDataType.name.lowercase()) {
"tinyint" -> initializeColumnParameters(Byte::class, getExposedFunction("byte"))
"smallint", "int2" -> initializeColumnParameters(Short::class, getExposedFunction("short"))
"int8" -> initializeColumnParameters(Long::class, getExposedFunction("long"))
Expand All @@ -67,7 +67,7 @@ data class ColumnInfo(val column: Column, private val data: TableBuilderData) {
}

fun initializeDouble() {
val name = column.columnDataType.name.toLowerCase()
val name = column.columnDataType.name.lowercase()
if (name.contains("decimal") || name.contains("numeric")) {
initializeColumnParameters(
BigDecimal::class,
Expand All @@ -79,7 +79,7 @@ data class ColumnInfo(val column: Column, private val data: TableBuilderData) {
}

fun initializeString() {
val name = column.columnDataType.name.toLowerCase()
val name = column.columnDataType.name.lowercase()
when {
name.contains("varchar") || name.contains("varying") ->
initializeColumnParameters(String::class, getExposedFunction("varchar"))
Expand All @@ -102,7 +102,7 @@ data class ColumnInfo(val column: Column, private val data: TableBuilderData) {
}

fun initializeObject() {
when (column.columnDataType.name.toLowerCase()) {
when (column.columnDataType.name.lowercase()) {
"uuid" -> initializeColumnParameters(UUID::class, getExposedFunction("uuid"))
}
}
Expand All @@ -125,7 +125,7 @@ data class ColumnInfo(val column: Column, private val data: TableBuilderData) {
initializeColumnParameters(dateTimeProvider.dateTimeClass, dateTimeProvider.dateTimeTableFun())

else -> {
val name = column.columnDataType.name.toLowerCase()
val name = column.columnDataType.name.lowercase()
when {
name.contains("uuid") -> initializeColumnParameters(UUID::class, getExposedFunction("uuid"))
// can be 'varbinary'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class CompilationResultChecker(private val result: KotlinCompilation.Result) {
result.classLoader.loadClass("${formPackageName(packageName)}$foreignKeyTargetTable").kotlin.objectInstance
}!!
val target = foreignKeyTargetTableObject::class.memberProperties
.find { it.name == foreignKey.targetColumn.toLowerCase() }!!.getter.call(foreignKeyTargetTableObject)
.find { it.name == foreignKey.targetColumn.lowercase() }!!.getter.call(foreignKeyTargetTableObject)
assertThat(foreignKey.target).isEqualTo(target)
} else {
assertThat(columnValue.foreignKey).isNull()
Expand Down

0 comments on commit b0bb883

Please sign in to comment.