-
Notifications
You must be signed in to change notification settings - Fork 102
feat: implement cast, right, left, replace expressions #894
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
1ccf936
bef6134
77cb87f
ff21748
ae90af2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1705,6 +1705,78 @@ open class Jpql : JpqlDsl { | |
) | ||
} | ||
|
||
/** | ||
* Creates an expression that represents the casting of a value to a different type. | ||
*/ | ||
@SinceJdsl("3.6.0") | ||
fun <T : Any> cast(value: Expressionable<*>, type: KClass<T>): Expression<T> { | ||
return Expressions.cast(value.toExpression(), type) | ||
} | ||
|
||
/** | ||
* Creates an expression that represents the casting of a value to a different type. | ||
*/ | ||
@SinceJdsl("3.6.0") | ||
inline fun <reified T : Any> cast(value: Expressionable<*>): Expression<T> { | ||
return Expressions.cast(value.toExpression(), T::class) | ||
} | ||
|
||
/** | ||
* Creates an expression that returns the leftmost count characters from a string. | ||
*/ | ||
@SinceJdsl("3.6.0") | ||
fun left(value: Expressionable<String>, count: Expressionable<Int>): Expression<String> { | ||
return Expressions.left(value.toExpression(), count.toExpression()) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://jakarta.ee/specifications/persistence/3.2/jakarta-persistence-spec-3.2#_criteriabuilder_
It would be best to follow the parameter naming conventions of CriteriaBuilder. The parameter name x is not ideal, so it would be best to use the value as is. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thank you. your reviews applied |
||
|
||
/** | ||
* Creates an expression that returns the leftmost count characters from a string. | ||
*/ | ||
@SinceJdsl("3.6.0") | ||
fun left(value: Expressionable<String>, count: Int): Expression<String> { | ||
return Expressions.left(value.toExpression(), intLiteral(count)) | ||
} | ||
|
||
/** | ||
* Creates an expression that returns the rightmost count characters from a string. | ||
*/ | ||
@SinceJdsl("3.6.0") | ||
fun right(value: Expressionable<String>, count: Expressionable<Int>): Expression<String> { | ||
return Expressions.right(value.toExpression(), count.toExpression()) | ||
} | ||
|
||
/** | ||
* Creates an expression that returns the rightmost count characters from a string. | ||
*/ | ||
@SinceJdsl("3.6.0") | ||
fun right(value: Expressionable<String>, count: Int): Expression<String> { | ||
return Expressions.right(value.toExpression(), intLiteral(count)) | ||
} | ||
|
||
/** | ||
* Creates an expression that replaces all occurrences of a search string with a replacement string. | ||
*/ | ||
@SinceJdsl("3.6.0") | ||
fun replace( | ||
value: Expressionable<String>, | ||
search: Expressionable<String>, | ||
replacement: Expressionable<String>, | ||
): Expression<String> { | ||
return Expressions.replace(value.toExpression(), search.toExpression(), replacement.toExpression()) | ||
} | ||
|
||
/** | ||
* Creates an expression that replaces all occurrences of a search string with a replacement string. | ||
*/ | ||
@SinceJdsl("3.6.0") | ||
fun replace( | ||
value: Expressionable<String>, | ||
search: String, | ||
replacement: String, | ||
): Expression<String> { | ||
return Expressions.replace(value.toExpression(), stringLiteral(search), stringLiteral(replacement)) | ||
} | ||
|
||
/** | ||
* Creates an expression that represents predefined database functions and user-defined database functions. | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl | ||
|
||
import com.linecorp.kotlinjdsl.SinceJdsl | ||
import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expression | ||
import kotlin.reflect.KClass | ||
|
||
@SinceJdsl("3.6.0") | ||
data class JpqlCast<T : Any> internal constructor( | ||
|
||
val value: Expression<*>, | ||
val type: KClass<T>, | ||
) : Expression<T> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.linecorp.kotlinjdsl.querymodel.jpql.expression.impl | ||
|
||
import com.linecorp.kotlinjdsl.SinceJdsl | ||
import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expression | ||
|
||
@SinceJdsl("3.6.0") | ||
data class JpqlLeft internal constructor( | ||
val value: Expression<String>, | ||
val length: Expression<Int>, | ||
) : Expression<String> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://jakarta.ee/specifications/persistence/3.2/jakarta-persistence-spec-3.2#typecasts
Looking at the Jakarta specification, the range of castable types is limited depending on whether
cast
is a scalar type or a string type.I believe this information should also be included in the function specification.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And I think it would be best to create a function form that is as similar as possible to the JPQL specification.
Therefore, I think it would be good to create CastStep, similar to TrimFromStep. Creating CastStep would also make it easier to implement type restrictions.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah. applied
Users can use the cast operator as follows: