Example usage for org.hibernate SQLQuery setCharacter

List of usage examples for org.hibernate SQLQuery setCharacter

Introduction

In this page you can find the example usage for org.hibernate SQLQuery setCharacter.

Prototype

@Deprecated
@SuppressWarnings("unchecked")
default Query<R> setCharacter(int position, char val) 

Source Link

Document

Bind a positional char-valued parameter.

Usage

From source file:ch.systemsx.cisd.openbis.generic.server.dataaccess.db.AbstractDAO.java

License:Apache License

/**
 * Executes given <var>sql</var>.
 * <p>//ww  w .java2s  . c o m
 * Should be an <code>INSERT</code> or <code>UPDATE</code> statement.
 * </p>
 */
protected final void executeUpdate(final String sql, final Serializable... parameters) {
    getHibernateTemplate().execute(new HibernateCallback() {

        //
        // HibernateCallback
        //

        public final Object doInHibernate(final Session session) throws HibernateException, SQLException {
            final SQLQuery sqlQuery = session.createSQLQuery(sql);
            for (int i = 0; i < parameters.length; i++) {
                Serializable parameter = parameters[i];
                if (parameter instanceof Long) {
                    sqlQuery.setLong(i, (Long) parameter);
                } else if (parameter instanceof Integer) {
                    sqlQuery.setInteger(i, (Integer) parameter);
                } else if (parameter instanceof Character) {
                    sqlQuery.setCharacter(i, (Character) parameter);
                } else if (parameter instanceof Date) {
                    sqlQuery.setDate(i, (Date) parameter);
                } else {
                    sqlQuery.setSerializable(i, parameter);
                }
            }
            sqlQuery.executeUpdate();
            return null;
        }
    });
}

From source file:org.egov.egf.web.actions.brs.AutoReconcileHelper.java

License:Open Source License

/**
 * @return/*from w w w. j  a v a 2s.c  o  m*/
 */
@Transactional
public String schedule() {
    // Step1: mark which are all we are going to process
    count = 0;
    // persistenceService.getSession().getTransaction().setTimeout(900);
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("Started at " + new Date());
    markForProcessing(BRS_TRANSACTION_TYPE_CHEQUE);
    persistenceService.getSession().flush();
    // step2 :find duplicate and mark to be processed manually
    findandUpdateDuplicates();

    final List<AutoReconcileBean> detailList = getStatmentsForProcessing(BRS_TRANSACTION_TYPE_CHEQUE);

    final String statusQury = "select id from EgwStatus where upper(moduletype)=upper('instrument') and  upper(description)=upper('"
            + FinancialConstants.INSTRUMENT_RECONCILED_STATUS + "')";
    statusId = (Integer) persistenceService.find(statusQury);
    final Long instrumentTypeId = getInstrumentType(FinancialConstants.INSTRUMENT_TYPE_CHEQUE);
    final Long instrumentTypeDDId = getInstrumentType(FinancialConstants.INSTRUMENT_TYPE_DD);
    // where instrumentheaderid= (select id.....) is used to fetch only one record may be double submit or two instrument
    // entries
    // let the user decide

    final String recociliationQuery = "update EGF_InstrumentHeader set id_status=:statusId,  lastmodifiedby=:userId,lastmodifieddate=CURRENT_DATE"
            + " where id= (select id from egf_instrumentheader where instrumentNumber=:instrumentNo and "
            + " instrumentAmount=:amount and bankaccountid=:accountId and ispaycheque=:ispaycheque and instrumentType in ("
            + instrumentTypeId + "," + instrumentTypeDDId + ")"
            + " and id_status=(select id from Egw_Status where upper(moduletype)=upper('instrument') and  upper(description)=upper(:instrumentStatus)))";

    final String recociliationAmountQuery = "update egf_instrumentOtherdetails set reconciledamount=:amount,instrumentstatusdate=:txDate "
            + " ,lastmodifiedby=:userId,lastmodifieddate=CURRENT_DATE,reconciledOn=:reconciliationDate "
            + " where instrumentheaderid= (select id from egf_instrumentheader where instrumentNumber=:instrumentNo and "
            + " instrumentAmount=:amount and bankaccountid=:accountId and ispaycheque=:ispaycheque and instrumentType in ("
            + instrumentTypeId + "," + instrumentTypeDDId + ")"
            + " and id_status=(select id from Egw_Status where upper(moduletype)=upper('instrument') and  upper(description)=upper(:instrumentStatus)))";

    final SQLQuery updateQuery = persistenceService.getSession().createSQLQuery(recociliationQuery);
    final SQLQuery updateQuery2 = persistenceService.getSession().createSQLQuery(recociliationAmountQuery);

    final String backUpdateBankStmtquery = "update " + TABLENAME + " set action='" + BRS_ACTION_PROCESSED
            + "' ,reconciliationDate=:reconciliationDate where id=:id";

    final String backUpdateFailureBRSquery = "update " + TABLENAME + " set action='"
            + BRS_ACTION_TO_BE_PROCESSED_MANUALLY + "',errormessage=:e where id=:id";
    final SQLQuery backupdateQuery = persistenceService.getSession().createSQLQuery(backUpdateBankStmtquery);
    final SQLQuery backupdateFailureQuery = persistenceService.getSession()
            .createSQLQuery(backUpdateFailureBRSquery);
    rowCount = 0;
    for (final AutoReconcileBean bean : detailList) {
        int updated = -1;
        try {
            updateQuery.setLong("statusId", statusId);
            updateQuery.setLong("accountId", accountId);

            updateQuery.setString("instrumentNo", bean.getInstrumentNo());
            updateQuery.setInteger("userId", ApplicationThreadLocals.getUserId().intValue());

            updateQuery2.setDate("txDate", bean.getTxDate());
            updateQuery2.setDate("reconciliationDate", reconciliationDate);
            updateQuery2.setLong("accountId", accountId);

            updateQuery2.setString("instrumentNo", bean.getInstrumentNo());
            updateQuery2.setInteger("userId", ApplicationThreadLocals.getUserId().intValue());
            if (bean.getDebit() != null && bean.getDebit().compareTo(BigDecimal.ZERO) != 0) {
                updateQuery.setBigDecimal("amount", bean.getDebit());
                updateQuery.setCharacter("ispaycheque", '1');
                updateQuery.setString("instrumentStatus", FinancialConstants.INSTRUMENT_CREATED_STATUS);
                updated = updateQuery.executeUpdate();
                if (updated != 0) {
                    updateQuery2.setBigDecimal("amount", bean.getDebit());
                    updateQuery2.setCharacter("ispaycheque", '1');
                    updateQuery2.setString("instrumentStatus", FinancialConstants.INSTRUMENT_RECONCILED_STATUS);
                    updated = updateQuery2.executeUpdate();
                }

            } else {
                updateQuery.setBigDecimal("amount", bean.getCredit());
                updateQuery.setCharacter("ispaycheque", '0');
                updateQuery.setString("instrumentStatus", FinancialConstants.INSTRUMENT_DEPOSITED_STATUS);
                updated = updateQuery.executeUpdate();
                if (updated != 0) {
                    updateQuery2.setBigDecimal("amount", bean.getCredit());
                    updateQuery2.setCharacter("ispaycheque", '0');
                    updateQuery2.setString("instrumentStatus", FinancialConstants.INSTRUMENT_RECONCILED_STATUS);
                    updated = updateQuery2.executeUpdate();
                }
            }
            // if updated is 0 means nothing got updated means could not find matching row in instrumentheader
            if (updated == 0) {
                backupdateFailureQuery.setLong("id", bean.getId());
                backupdateFailureQuery.setString("e", DID_NOT_FIND_MATCH_IN_BANKBOOK);
                backupdateFailureQuery.executeUpdate();

            } else {
                backupdateQuery.setLong("id", bean.getId());
                backupdateQuery.setDate("reconciliationDate", reconciliationDate);
                backupdateQuery.executeUpdate();
                count++;
                // if(LOGGER.isDebugEnabled()) LOGGER.debug(count);
            }
            rowCount++;
            if (LOGGER.isDebugEnabled())
                LOGGER.debug("out of " + rowCount + "==>succesfull " + count);

            if (rowCount % 20 == 0)
                persistenceService.getSession().flush();

            // These exception might be because the other entires in instrument which is not in egf_brs_bankstatements
            // so any issues leave it for manual update
        } catch (final HibernateException e) {
            if (e.getCause().getMessage().contains("single-row subquery returns more"))
                backupdateFailureQuery.setString("e", BRS_MESSAGE_MORE_THAN_ONE_MATCH);
            else
                backupdateFailureQuery.setString("e", e.getMessage());
            backupdateFailureQuery.setLong("id", bean.getId());
            backupdateFailureQuery.executeUpdate();

        } catch (final Exception e) {
            backupdateFailureQuery.setLong("id", bean.getId());
            backupdateFailureQuery.setString("e", e.getMessage());
            backupdateFailureQuery.executeUpdate();
        }

    }
    processCSL();
    return "result";
}

From source file:org.egov.egf.web.actions.brs.AutoReconcileHelper.java

License:Open Source License

private void processCSL() {
    markForProcessing(BRS_TRANSACTION_TYPE_BANK);
    final List<AutoReconcileBean> CSLList = getStatmentsForProcessing(BRS_TRANSACTION_TYPE_BANK);
    final Long instrumentTypeId = getInstrumentType(FinancialConstants.INSTRUMENT_TYPE_BANK_TO_BANK);
    final String recociliationQuery = "update EGF_InstrumentHeader set id_status=:statusId,  lastmodifiedby=:userId,lastmodifieddate=CURRENT_DATE"
            + " where id = (select ih.id from egf_instrumentheader ih,egf_instrumentvoucher iv,voucherheader vh where  "
            + " instrumentAmount=:amount and bankaccountid=:accountId and ispaycheque=:ispaycheque and instrumentType in ("
            + instrumentTypeId + ")"
            + " and id_status=(select id from Egw_Status where upper(moduletype)=upper('instrument') and  upper(description)="
            + " upper(:instrumentStatus)) and iv.instrumentheaderid=ih.id and iv.voucherheaderid=ih.id and vh.vouchernumber=:cslNo )  ";

    final String recociliationAmountQuery = "update egf_instrumentOtherdetails set reconciledamount=:amount,instrumentstatusdate=:txDate "
            + " ,lastmodifiedby=:userId,lastmodifieddate=CURRENT_DATE,reconciledOn=:reconciliationDate "
            + " where instrumentheaderid =  (select ih.id from egf_instrumentheader ih,egf_instrumentvoucher iv,voucherheader vh where  "
            + " instrumentAmount=:amount and bankaccountid=:accountId and ispaycheque=:ispaycheque and instrumentType in ("
            + instrumentTypeId + ")"
            + " and id_status=(select id from Egw_Status where upper(moduletype)=upper('instrument') and  upper(description)="
            + " upper(:instrumentStatus)) and iv.instrumentheaderid=ih.id and iv.voucherheaderid=ih.id and vh.vouchernumber=:cslNo ) ";

    final SQLQuery updateQuery = persistenceService.getSession().createSQLQuery(recociliationQuery);
    final SQLQuery updateQuery2 = persistenceService.getSession().createSQLQuery(recociliationAmountQuery);

    final String backUpdateBankStmtquery = "update " + TABLENAME + " set action='" + BRS_ACTION_PROCESSED
            + "' ,reconciliationDate=:reconciliationDate where id=:id";

    final String backUpdateFailureBRSquery = "update " + TABLENAME + " set action='"
            + BRS_ACTION_TO_BE_PROCESSED_MANUALLY + "',errormessage=:e where id=:id";
    final SQLQuery backupdateQuery = persistenceService.getSession().createSQLQuery(backUpdateBankStmtquery);
    final SQLQuery backupdateFailureQuery = persistenceService.getSession()
            .createSQLQuery(backUpdateFailureBRSquery);
    for (final AutoReconcileBean bean : CSLList) {
        int updated = -1;
        try {/*from  w  w  w  .j a  va  2  s.com*/
            updateQuery.setLong("statusId", statusId);
            updateQuery.setLong("accountId", accountId);

            updateQuery.setString("cslNo", bean.getCSLno());
            updateQuery.setInteger("userId", ApplicationThreadLocals.getUserId().intValue());

            updateQuery2.setDate("txDate", bean.getTxDate());
            updateQuery2.setDate("reconciliationDate", reconciliationDate);
            updateQuery2.setLong("accountId", accountId);

            updateQuery2.setString("cslNo", bean.getCSLno());
            updateQuery2.setInteger("userId", ApplicationThreadLocals.getUserId().intValue());
            if (bean.getDebit() != null && bean.getDebit().compareTo(BigDecimal.ZERO) != 0) {
                updateQuery.setBigDecimal("amount", bean.getDebit());
                updateQuery.setCharacter("ispaycheque", '1');
                updateQuery.setString("instrumentStatus", FinancialConstants.INSTRUMENT_CREATED_STATUS);
                updated = updateQuery.executeUpdate();
                if (updated != 0) {
                    updateQuery2.setBigDecimal("amount", bean.getDebit());
                    updateQuery2.setCharacter("ispaycheque", '1');
                    updateQuery2.setString("instrumentStatus", FinancialConstants.INSTRUMENT_RECONCILED_STATUS);
                    updated = updateQuery2.executeUpdate();
                }

            } else {
                updateQuery.setBigDecimal("amount", bean.getCredit());
                updateQuery.setCharacter("ispaycheque", '1');
                updateQuery.setString("instrumentStatus", FinancialConstants.INSTRUMENT_CREATED_STATUS);
                updated = updateQuery.executeUpdate();
                if (updated != 0) {
                    updateQuery2.setBigDecimal("amount", bean.getCredit());
                    updateQuery2.setCharacter("ispaycheque", '1');
                    updateQuery2.setString("instrumentStatus", FinancialConstants.INSTRUMENT_RECONCILED_STATUS);
                    updated = updateQuery2.executeUpdate();
                }
                if (updated == 0) {

                }
            }
            // if updated is 0 means nothing got updated means could not find matching row in instrumentheader

            if (updated == 0) {
                backupdateFailureQuery.setLong("id", bean.getId());
                backupdateFailureQuery.setString("e", DID_NOT_FIND_MATCH_IN_BANKBOOK);
                backupdateFailureQuery.executeUpdate();

            } else if (updated == -1) {
                backupdateFailureQuery.setLong("id", bean.getId());
                backupdateFailureQuery.setString("e", DID_NOT_FIND_MATCH_IN_BANKBOOK);
                backupdateFailureQuery.executeUpdate();
                // if(LOGGER.isDebugEnabled()) LOGGER.debug(count);
            } else {
                backupdateQuery.setLong("id", bean.getId());
                backupdateQuery.setDate("reconciliationDate", reconciliationDate);
                backupdateQuery.executeUpdate();
                count++;
                // if(LOGGER.isDebugEnabled()) LOGGER.debug(count);
            }
            rowCount++;
            if (LOGGER.isDebugEnabled())
                LOGGER.debug("out of " + rowCount + "==>succesfull " + count);

            if (rowCount % 20 == 0)
                persistenceService.getSession().flush();

            // These exception might be because the other entires in instrument which is not in egf_brs_bankstatements
            // so any issues leave it for manual update
        } catch (final HibernateException e) {
            if (e.getCause().getMessage().contains("single-row subquery returns more"))
                backupdateFailureQuery.setString("e", BRS_MESSAGE_MORE_THAN_ONE_MATCH);
            else
                backupdateFailureQuery.setString("e", e.getMessage());
            backupdateFailureQuery.setLong("id", bean.getId());
            backupdateFailureQuery.executeUpdate();

        } catch (final Exception e) {
            backupdateFailureQuery.setLong("id", bean.getId());
            backupdateFailureQuery.setString("e", e.getMessage());
            backupdateFailureQuery.executeUpdate();
        }

    }

}