Skip to content

Commit

Permalink
Merge pull request #35 from ergon/feature/dope-188-use-keys-clause
Browse files Browse the repository at this point in the history
DOPE-188: refactoring use keys clause, added information for annotation
  • Loading branch information
martinagallati-ergon authored Jul 8, 2024
2 parents 43715c4 + fb68c7d commit 16130de
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package ch.ergon.dope.resolvable.clause

import ch.ergon.dope.resolvable.clause.model.DeleteLimitClause
import ch.ergon.dope.resolvable.clause.model.DeleteOffsetClause
import ch.ergon.dope.resolvable.clause.model.DeleteUseKeysArrayClause
import ch.ergon.dope.resolvable.clause.model.DeleteUseKeysStringClause
import ch.ergon.dope.resolvable.clause.model.DeleteUseKeysClause.Companion.DeleteUseKeysClause
import ch.ergon.dope.resolvable.clause.model.DeleteWhereClause
import ch.ergon.dope.resolvable.clause.model.ReturningClause
import ch.ergon.dope.resolvable.expression.TypeExpression
Expand Down Expand Up @@ -36,9 +35,10 @@ interface IDeleteUseKeysClause : IDeleteWhereClause {
}

interface IDeleteClause : IDeleteUseKeysClause {
fun useKeys(key: TypeExpression<StringType>) = DeleteUseKeysStringClause(key, this)
fun useKeys(key: TypeExpression<StringType>) = DeleteUseKeysClause(key, this)

// JvmName annotation in interfaces is currently not supported. https://youtrack.jetbrains.com/issue/KT-20068
@Suppress("INAPPLICABLE_JVM_NAME")
@JvmName("useKeysArray")
fun useKeys(key: TypeExpression<ArrayType<StringType>>) = DeleteUseKeysArrayClause(key, this)
fun useKeys(key: TypeExpression<ArrayType<StringType>>) = DeleteUseKeysClause(key, this)
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import ch.ergon.dope.resolvable.clause.model.SelectLimitClause
import ch.ergon.dope.resolvable.clause.model.SelectOffsetClause
import ch.ergon.dope.resolvable.clause.model.SelectOrderByClause
import ch.ergon.dope.resolvable.clause.model.SelectOrderByTypeClause
import ch.ergon.dope.resolvable.clause.model.SelectUseKeysArrayClause
import ch.ergon.dope.resolvable.clause.model.SelectUseKeysStringClause
import ch.ergon.dope.resolvable.clause.model.SelectUseKeysClause.Companion.SelectUseKeysClause
import ch.ergon.dope.resolvable.clause.model.SelectWhereClause
import ch.ergon.dope.resolvable.clause.model.StandardJoinClause
import ch.ergon.dope.resolvable.clause.model.UnnestClause
Expand Down Expand Up @@ -57,11 +56,12 @@ interface ISelectUseKeysClause : ISelectWhereClause {
}

interface ISelectFromClause : ISelectUseKeysClause {
fun useKeys(key: TypeExpression<StringType>) = SelectUseKeysStringClause(key, this)
fun useKeys(key: TypeExpression<StringType>) = SelectUseKeysClause(key, this)

// JvmName annotation in interfaces is currently not supported. https://youtrack.jetbrains.com/issue/KT-20068
@Suppress("INAPPLICABLE_JVM_NAME")
@JvmName("useKeysArray")
fun useKeys(keys: TypeExpression<ArrayType<StringType>>) = SelectUseKeysArrayClause(keys, this)
fun useKeys(keys: TypeExpression<ArrayType<StringType>>) = SelectUseKeysClause(keys, this)
}

interface ISelectJoinClause : ISelectFromClause {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,66 @@ import ch.ergon.dope.validtype.ValidType

private const val USE_KEYS = "USE KEYS"

sealed class SelectUseKeysClause(
private val parentClause: ISelectFromClause,
private val keys: TypeExpression<out ValidType>,
) : ISelectUseKeysClause {
class SelectUseKeysClause : ISelectUseKeysClause {
private lateinit var useKeys: TypeExpression<out ValidType>
private lateinit var parentClause: ISelectFromClause

companion object {
@JvmName("selectSingleUseKeysClauseConstructor")
fun SelectUseKeysClause(key: TypeExpression<StringType>, parentClause: ISelectFromClause): SelectUseKeysClause {
val instance = SelectUseKeysClause()
instance.useKeys = key
instance.parentClause = parentClause
return instance
}

@JvmName("selectMultipleUseKeysClauseConstructor")
fun SelectUseKeysClause(keys: TypeExpression<ArrayType<StringType>>, parentClause: ISelectFromClause): SelectUseKeysClause {
val instance = SelectUseKeysClause()
instance.useKeys = keys
instance.parentClause = parentClause
return instance
}
}

override fun toDopeQuery(): DopeQuery {
val parentDopeQuery = parentClause.toDopeQuery()
val keysDopeQuery = keys.toDopeQuery()
val keysDopeQuery = useKeys.toDopeQuery()
return DopeQuery(
queryString = formatToQueryStringWithSymbol(parentDopeQuery.queryString, USE_KEYS, keysDopeQuery.queryString),
parameters = parentDopeQuery.parameters + keysDopeQuery.parameters,
)
}
}

class SelectUseKeysStringClause(key: TypeExpression<StringType>, parentClause: ISelectFromClause) :
SelectUseKeysClause(parentClause, key)
class DeleteUseKeysClause : IDeleteUseKeysClause {
private lateinit var useKeys: TypeExpression<out ValidType>
private lateinit var parentClause: IDeleteClause

class SelectUseKeysArrayClause(keys: TypeExpression<ArrayType<StringType>>, parentClause: ISelectFromClause) :
SelectUseKeysClause(parentClause, keys)
companion object {
@JvmName("deleteSingleUseKeysClauseConstructor")
fun DeleteUseKeysClause(key: TypeExpression<StringType>, parentClause: IDeleteClause): DeleteUseKeysClause {
val instance = DeleteUseKeysClause()
instance.useKeys = key
instance.parentClause = parentClause
return instance
}

@JvmName("deleteMultipleUseKeysClauseConstructor")
fun DeleteUseKeysClause(keys: TypeExpression<ArrayType<StringType>>, parentClause: IDeleteClause): DeleteUseKeysClause {
val instance = DeleteUseKeysClause()
instance.useKeys = keys
instance.parentClause = parentClause
return instance
}
}

sealed class DeleteUseKeysClause(
private val parentClause: IDeleteClause,
private val keys: TypeExpression<out ValidType>,
) : IDeleteUseKeysClause {
override fun toDopeQuery(): DopeQuery {
val parentDopeQuery = parentClause.toDopeQuery()
val keysDopeQuery = keys.toDopeQuery()
val keysDopeQuery = useKeys.toDopeQuery()
return DopeQuery(
queryString = formatToQueryStringWithSymbol(parentDopeQuery.queryString, USE_KEYS, keysDopeQuery.queryString),
parameters = parentDopeQuery.parameters + keysDopeQuery.parameters,
)
}
}

class DeleteUseKeysStringClause(key: TypeExpression<StringType>, parentClause: IDeleteClause) :
DeleteUseKeysClause(parentClause, key)

class DeleteUseKeysArrayClause(keys: TypeExpression<ArrayType<StringType>>, parentClause: IDeleteClause) :
DeleteUseKeysClause(parentClause, keys)

0 comments on commit 16130de

Please sign in to comment.