Aleksandar Vidakovic created FINERACT-3062:
----------------------------------------------
Summary: Type safe query: [SQL 021] Find lock IDs by loan ID in
(AbstractLockingService:70)
Key: FINERACT-3062
URL: https://issues.apache.org/jira/browse/FINERACT-3062
Project: Apache Fineract
Issue Type: Sub-task
Reporter: Aleksandar Vidakovic
*Entry 21* of the native SQL inventory \(SELECT, module fineract\-cob\).
Source:
[AbstractLockingService.java#L70|https://github.com/apache/fineract/blob/0f677b99aa453ea5be4f2e0115562e85ad1db012/fineract-cob/src/main/java/org/apache/fineract/cob/domain/AbstractLockingService.java#L70]
Status: Translation generated automatically; needs review and compilation.
h3. Native SQL \(as built by the Java code\)
{code:language=sql}
SELECT loan_id
FROM ${getTableName()}
WHERE loan_id IN (${loanIds})
{code}
h3. Proposed QueryDSL translation
{code:language=java}
// imports
import com.querydsl.core.types.dsl.PathBuilder;
import com.querydsl.sql.SQLQueryFactory;
import java.util.Collection;
import java.util.List;
// method parameters used below
// Collection<Long> loanIds (was concatenated into the SQL: loanIds)
// table name is only known at runtime (getTableName())
PathBuilder<Object> dynTable = new PathBuilder<>(Object.class, getTableName());
List<Object> result = queryFactory.select(dynTable.getComparable("loan_id",
Comparable.class))
.from(dynTable)
.where(dynTable.getComparable("loan_id", Comparable.class).in(loanIds))
.fetch();
{code}
h3. Done when
* QueryDSL version compiles against the generated Q\-types
* Behaviour matches the native query \(same rows, same parameters\) on
MySQL/MariaDB and PostgreSQL
* Existing tests pass, or a test covering the query was added
* The native SQL string is removed
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)