This is an automated email from the ASF dual-hosted git repository.
adamsaghy pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract.git
The following commit(s) were added to refs/heads/develop by this push:
new f640c790c FINERACT-1724: Fix `update last cob date of loan update`
query
f640c790c is described below
commit f640c790c3b9fd66fa5c18086d0e976b3fdcd60c
Author: Adam Saghy <[email protected]>
AuthorDate: Tue Aug 1 12:53:58 2023 +0200
FINERACT-1724: Fix `update last cob date of loan update` query
---
.../domain/CustomLoanAccountLockRepository.java | 24 ++++++++++
.../CustomLoanAccountLockRepositoryImpl.java | 52 ++++++++++++++++++++++
.../cob/domain/LoanAccountLockRepository.java | 17 +------
3 files changed, 78 insertions(+), 15 deletions(-)
diff --git
a/fineract-provider/src/main/java/org/apache/fineract/cob/domain/CustomLoanAccountLockRepository.java
b/fineract-provider/src/main/java/org/apache/fineract/cob/domain/CustomLoanAccountLockRepository.java
new file mode 100644
index 000000000..765db8e28
--- /dev/null
+++
b/fineract-provider/src/main/java/org/apache/fineract/cob/domain/CustomLoanAccountLockRepository.java
@@ -0,0 +1,24 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.cob.domain;
+
+public interface CustomLoanAccountLockRepository {
+
+ void updateLoanFromAccountLocks();
+}
diff --git
a/fineract-provider/src/main/java/org/apache/fineract/cob/domain/CustomLoanAccountLockRepositoryImpl.java
b/fineract-provider/src/main/java/org/apache/fineract/cob/domain/CustomLoanAccountLockRepositoryImpl.java
new file mode 100644
index 000000000..1a4a3e908
--- /dev/null
+++
b/fineract-provider/src/main/java/org/apache/fineract/cob/domain/CustomLoanAccountLockRepositoryImpl.java
@@ -0,0 +1,52 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.cob.domain;
+
+import jakarta.persistence.EntityManager;
+import lombok.RequiredArgsConstructor;
+import
org.apache.fineract.infrastructure.core.service.database.DatabaseSpecificSQLGenerator;
+import org.springframework.stereotype.Repository;
+
+@Repository
+@RequiredArgsConstructor
+public class CustomLoanAccountLockRepositoryImpl implements
CustomLoanAccountLockRepository {
+
+ private final EntityManager entityManager;
+ private final DatabaseSpecificSQLGenerator databaseSpecificSQLGenerator;
+
+ @Override
+ public void updateLoanFromAccountLocks() {
+ String sql = "UPDATE m_loan SET last_closed_business_date = (select "
+ +
databaseSpecificSQLGenerator.subDate("lck.lock_placed_on_cob_business_date",
"1", "DAY")
+ + """
+ from
m_loan_account_locks lck
+ where lck.loan_id
= id
+ and
lck.lock_placed_on_cob_business_date is not null
+ and lck.error
is not null
+ and
lck.lock_owner in ('LOAN_COB_CHUNK_PROCESSING','LOAN_INLINE_COB_PROCESSING'))
+ where last_closed_business_date is null and exists
(select lck.loan_id
+ from m_loan_account_locks lck where
lck.loan_id = id
+ and
lck.lock_placed_on_cob_business_date is not null and lck.error is not null
+ and lck.lock_owner in
('LOAN_COB_CHUNK_PROCESSING','LOAN_INLINE_COB_PROCESSING'))
+ """;
+
+ entityManager.createNativeQuery(sql).executeUpdate();
+ entityManager.flush();
+ }
+}
diff --git
a/fineract-provider/src/main/java/org/apache/fineract/cob/domain/LoanAccountLockRepository.java
b/fineract-provider/src/main/java/org/apache/fineract/cob/domain/LoanAccountLockRepository.java
index 40550a517..46d6dc9dd 100644
---
a/fineract-provider/src/main/java/org/apache/fineract/cob/domain/LoanAccountLockRepository.java
+++
b/fineract-provider/src/main/java/org/apache/fineract/cob/domain/LoanAccountLockRepository.java
@@ -25,7 +25,8 @@ import
org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
-public interface LoanAccountLockRepository extends
JpaRepository<LoanAccountLock, Long>, JpaSpecificationExecutor<LoanAccountLock>
{
+public interface LoanAccountLockRepository
+ extends CustomLoanAccountLockRepository,
JpaRepository<LoanAccountLock, Long>, JpaSpecificationExecutor<LoanAccountLock>
{
Optional<LoanAccountLock> findByLoanIdAndLockOwner(Long loanId, LockOwner
lockOwner);
@@ -35,20 +36,6 @@ public interface LoanAccountLockRepository extends
JpaRepository<LoanAccountLock
boolean existsByLoanIdAndLockOwner(Long loanId, LockOwner lockOwner);
- @Query(value = """
- update m_loan set
last_closed_business_date = (select lck.lock_placed_on_cob_business_date - 1
- from m_loan_account_locks lck
- where lck.loan_id = id
- and
lck.lock_placed_on_cob_business_date is not null
- and lck.error is not null
- and lck.lock_owner in
('LOAN_COB_CHUNK_PROCESSING','LOAN_INLINE_COB_PROCESSING'))
- where last_closed_business_date is null and exists (select
lck.loan_id
- from m_loan_account_locks lck where lck.loan_id = id
- and lck.lock_placed_on_cob_business_date is not
null and lck.error is not null
- and lck.lock_owner in
('LOAN_COB_CHUNK_PROCESSING','LOAN_INLINE_COB_PROCESSING'))""", nativeQuery =
true)
- @Modifying(flushAutomatically = true)
- void updateLoanFromAccountLocks();
-
@Query("""
delete from LoanAccountLock lck where
lck.lockPlacedOnCobBusinessDate is not null and lck.error is not null and
lck.lockOwner in
(org.apache.fineract.cob.domain.LockOwner.LOAN_COB_CHUNK_PROCESSING,org.apache.fineract.cob.domain.LockOwner.LOAN_INLINE_COB_PROCESSING)