-
-
Notifications
You must be signed in to change notification settings - Fork 70
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
Introduce QueryDsl to unify Entityql and NativeSql APIs #1203
Conversation
import org.seasar.doma.kotlin.jdbc.criteria.declaration.KValuesDeclaration | ||
import java.util.* | ||
|
||
class KUnifiedInsertStating<ENTITY : Any>(private val statement: UnifiedInsertStarting<ENTITY>) { |
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.
I found typo.
x: KUnifiedInsertStating
o: KUnifiedInsertStarting
The following class is the same.
org.seasar.doma.kotlin.jdbc.criteria.statement.KUnifiedDeleteStating
org.seasar.doma.kotlin.jdbc.criteria.statement.KUnifiedInsertStating
org.seasar.doma.kotlin.jdbc.criteria.statement.KUnifiedSelectStating
org.seasar.doma.kotlin.jdbc.criteria.statement.KUnifiedUpdateStating
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.
Good catch! Thanks!
/** | ||
* Deletes all the entities. | ||
* | ||
* @return the delete statement | ||
*/ | ||
public Statement<Integer> all() { | ||
settings.setAllowEmptyWhere(true); | ||
return asNativeSqlDeleteStarting(); | ||
} |
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.
It good to consistency with the single
and batch
methods. 👍
Previously, Require set to DeleteCofig { allowEmptyWhere = true }.
return asEntityqlSelectStarting().createCommand(); | ||
} | ||
|
||
private UnifiedSelectTerminal<ENTITY> asUnifiedSelectTerminal() { |
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.
I want to use this method by client-code.
Because I want to prevent the class of the receiver for the associate method changes between the first and subsequent calls.
val query = queryDsl.from(a)
.leftJoin(b) {
eq(a.id, b.aId)
}
val associatedQuery = query
.associate( /* omission */ ) // receiver class is UnifiedSelectStarting
.associate( /* omission */ ) // receiver class is UnifiedSelectTerminal
.associate( /* omission */ ) // receiver class is UnifiedSelectTerminal
I accept automatically change to UnifiedSelectTerminal, when call UnifiedSelectStarting#associate method. but, I want manually change receiver.
When decomposed query into a separate method, it would require double implementation through overloading like bellow code.
fun findList1() {
val query = queryDsl.from(a)
.leftJoin(b) {
eq(a.id, b.aId)
}
.associateTableB() // use first associateTableB method
}
fun findList2() {
val query = queryDsl.from(a)
.leftJoin(b) {
eq(a.id, b.aId)
}
.associateTableA()
.associateTableB() // use second associateTableB method
}
fun UnifiedSelectStarting<TableA>.associateTableA(): UnifiedSelectTerminal<TableA> {
return this.associate( /* omission */ )
}
// overload
fun UnifiedSelectTerminal<TableA>.associateTableA(): UnifiedSelectTerminal<TableA> {
return this.associate( /* omission */ )
}
fun UnifiedSelectStarting<TableB>.associateTableB(): UnifiedSelectTerminal<TableB> {
return this.associate( /* omission */ )
}
// overload
fun UnifiedSelectTerminal<TableB>.associateTableB(): UnifiedSelectTerminal<TableB> {
return this.associate( /* omission */ )
}
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.
In commit 40107f4, we introduced the EntityQueryable
and KEntityQueryable
interfaces to abstract the common elements of UnifiedSelectStarting
and UnifiedSelectTerminal
. Do these changes help resolve the issues mentioned above?
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.
This abstract receiver class for consistent logic. that is helpful.
thank you.
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.
Good that the separation of queries and concerns. 👍
Previously, put code everything EntityqlSelectStarting
.
In the previous Criteria API, it was necessary to use two different types of DSL as needed:
This pull request introduces a new DSL called QueryDsl. QueryDsl provides users with an intuitive API and determines the need to consider entity identity based on the invoked API.
By using QueryDsl, users no longer have to worry about switching between Entityql and NativeSql.
Here is a sample code comparing cases with and without using QueryDsl.
with QueryDsl
without QueryDsl