Example usage for org.hibernate Query setInteger

List of usage examples for org.hibernate Query setInteger

Introduction

In this page you can find the example usage for org.hibernate Query setInteger.

Prototype

@Deprecated
@SuppressWarnings("unchecked")
default Query<R> setInteger(String name, int val) 

Source Link

Document

Bind a named int-valued parameter.

Usage

From source file:com.exilant.eGov.src.reports.GeneralLedgerReport.java

License:Open Source License

private String getFundName(final String fundId) throws TaskFailedException {
    String fundName = "";
    Query pst = null;
    try {/*from   w  w  w.j a  va2 s .co  m*/
        final String query = "select name  as \"name\" from fund where id=?";
        pst = persistenceService.getSession().createSQLQuery(query);
        if (fundId.isEmpty())
            pst.setInteger(0, 0);
        else
            pst.setInteger(0, Integer.valueOf(fundId));
        final List<Object[]> list = pst.list();
        final Object[] objects = list.toArray();
        if (objects.length == 0)
            fundName = "";
        else
            fundName = objects[0].toString();

    } catch (final Exception e) {
        LOGGER.error("Exp in getFundName" + e.getMessage(), e);
        throw taskExc;
    }
    return fundName;
}

From source file:com.exilant.eGov.src.transactions.CommonMethodsImpl.java

License:Open Source License

/**
 * Get the cash in hand code account for the boundary
 *//*from  www  .  j  av a  2s  . co  m*/
@Override
public String getCashInHand(final int BoundaryId, final Connection connection) throws Exception {
    String cashinHandCode = "";
    try {
        final String query = " SELECT a.glcode FROM CHARTOFACCOUNTS a,EG_BOUNDARY b,eg_boundary_type c "
                + " WHERE id=(SELECT cashinhand FROM CODEMAPPING WHERE EG_BOUNDARYID= ? )  and b.ID_BNDRY_TYPE=c.ID_BNDRY_TYPE and b.ID_BNDRY= ?";
        Query pst = persistenceService.getSession().createSQLQuery(query);
        pst.setInteger(0, BoundaryId);
        pst.setInteger(1, BoundaryId);
        List<Object[]> rset = pst.list();
        for (final Object[] element : rset)
            cashinHandCode = element[0].toString();
        if (rset == null || rset.size() == 0)
            throw new Exception();
        if (LOGGER.isInfoEnabled())
            LOGGER.info(">>>cashinHandCode " + cashinHandCode);
    } catch (final Exception e) {
        LOGGER.error(" Glcode for cashinhand not found " + e.toString(), e);
        throw new Exception(e.toString());
    }
    return cashinHandCode;
}

From source file:com.exilant.eGov.src.transactions.CommonMethodsImpl.java

License:Open Source License

/**
 * Get the Cheque in hand code account for the boundary
 *//*from   w w w.  j ava2  s.c  o m*/
@Override
public String getChequeInHand(final int BoundaryId, final Connection connection) throws Exception {
    String chequeinHandCode = "";
    try {
        final String query = " SELECT a.glcode FROM CHARTOFACCOUNTS a,EG_BOUNDARY b,eg_boundary_type c "
                + " WHERE id=(SELECT chequeinhand FROM CODEMAPPING WHERE EG_BOUNDARYID= ? )  and b.ID_BNDRY_TYPE=c.ID_BNDRY_TYPE and b.ID_BNDRY= ?";
        Query pst = persistenceService.getSession().createSQLQuery(query);
        pst.setInteger(0, BoundaryId);
        pst.setInteger(1, BoundaryId);
        List<Object[]> rset = pst.list();
        for (final Object[] element : rset)
            chequeinHandCode = element[0].toString();
        if (rset == null || rset.size() == 0)
            throw new Exception("Chequeinhand Code not Found");
        if (LOGGER.isInfoEnabled())
            LOGGER.info(">>>chequeinHandCode " + chequeinHandCode);
    } catch (final Exception e) {
        LOGGER.error(" Glcode for chequeinHandCode not found ", e);
        throw new Exception(e.toString());
    }

    return chequeinHandCode;
}

From source file:com.exilant.eGov.src.transactions.CommonMethodsImpl.java

License:Open Source License

/**
 * Get the account code for the bank account
 *//*from www .  j av  a  2 s  . co  m*/
@Override
public String getBankCode(final int bankAccountId, final Connection connection) throws Exception {
    String bankCodeAndName = "";
    try {
        final String query = "select glcode,name from chartofaccounts where id=(select glcodeid from bankaccount where id= ?)";
        Query pst = persistenceService.getSession().createSQLQuery(query);
        pst.setInteger(0, bankAccountId);
        List<Object[]> rset = pst.list();
        for (final Object[] element : rset) {
            bankCodeAndName = element[0].toString();
            bankCodeAndName = bankCodeAndName + "#" + element[1].toString();
            if (LOGGER.isInfoEnabled())
                LOGGER.info(">>>bankCodeAndName " + bankCodeAndName);
        }
        if (rset == null || rset.size() == 0)
            throw new Exception("BAnk Code Not Found");
    } catch (final Exception e) {
        LOGGER.error(" Bank code not found " + e.toString(), e);
        throw new Exception(e.toString());
    }
    return bankCodeAndName;
}

From source file:com.exilant.eGov.src.transactions.CommonMethodsImpl.java

License:Open Source License

/**
 * Get the bank and bank branch of the bank acocunt
 *//*from w  ww . j av a 2s .com*/
@Override
public String getBankId(final int bankAccountId, final Connection connection) throws Exception {
    String bankAndBranchId = "null";
    try {
        final String sql = "select b.id,c.id from bankaccount a,bankbranch b,bank c where a.branchid=b.id and b.bankid=c.id and a.id= ?";
        Query pst = persistenceService.getSession().createSQLQuery(sql);
        pst.setInteger(0, bankAccountId);
        List<Object[]> rset = pst.list();
        for (final Object[] element : rset) {
            bankAndBranchId = element[0].toString();
            bankAndBranchId = bankAndBranchId + "#" + element[1].toString();
            if (LOGGER.isInfoEnabled())
                LOGGER.info(">>>bankAndBranchId " + bankAndBranchId);
        }
        if (rset == null || rset.size() == 0)
            throw new Exception("Bank Code Not Found");
    } catch (final Exception e) {
        LOGGER.error(" Bank Id not found " + e.toString(), e);
        throw new Exception(e.toString());
    }
    return bankAndBranchId;
}

From source file:com.exilant.eGov.src.transactions.CommonMethodsImpl.java

License:Open Source License

/**
 * Get the bank balance for the bank account
 *///from w ww  .j a va  2s . com
@Override
public double getAccountBalance(final int bankAccountId, final String vcDate, final Connection connection)
        throws Exception {
    double opeAvailable = 0, totalAvailable = 0;
    try {

        final String str = "SELECT case when sum(openingDebitBalance) = null then 0 ELSE sum(openingDebitBalance) end - case when sum(openingCreditBalance) = null then 0 else sum(openingCreditBalance) end AS \"openingBalance\" "
                + "FROM transactionSummary WHERE financialYearId=( SELECT id FROM financialYear WHERE startingDate <= ?"
                + "AND endingDate >= ?)  AND glCodeId =(select glcodeid from bankaccount where id= ?)";
        if (LOGGER.isInfoEnabled())
            LOGGER.info(str);
        Query pst = persistenceService.getSession().createSQLQuery(str);
        pst.setString(0, vcDate);
        pst.setString(1, vcDate);
        pst.setInteger(2, bankAccountId);
        List<Object[]> rset = pst.list();
        for (final Object[] element : rset)
            opeAvailable = Double.parseDouble(element[0].toString());
        if (LOGGER.isInfoEnabled())
            LOGGER.info("opening balance  " + opeAvailable);

        final String str1 = "SELECT (case when sum(gl.debitAmount) = null then 0 else sum(gl.debitAmount) end - case when sum(gl.creditAmount)  = null then 0 else sum(gl.creditAmount) end) + "
                + opeAvailable + ""
                + " as \"totalAmount\" FROM   generalLedger gl, voucherHeader vh WHERE vh.id = gl.voucherHeaderId AND gl.glCodeid = (select glcodeid from bankaccount where id= ?) AND  "
                + " vh.voucherDate >=( SELECT TO_CHAR(startingDate, 'dd-Mon-yyyy') FROM financialYear WHERE startingDate <= ? AND endingDate >= ?) AND vh.voucherDate <= ?";
        if (LOGGER.isInfoEnabled())
            LOGGER.info(str1);
        pst = persistenceService.getSession().createSQLQuery(str1);
        pst.setInteger(0, bankAccountId);
        pst.setString(1, vcDate);
        pst.setString(2, vcDate);
        pst.setString(3, vcDate);
        rset = pst.list();
        for (final Object[] element : rset) {
            totalAvailable = Double.parseDouble(element[0].toString());
            if (LOGGER.isInfoEnabled())
                LOGGER.info("total balance  " + totalAvailable);
        }

    } catch (final Exception e) {
        LOGGER.error(" could not get Bankbalance  " + e.toString(), e);
        throw new Exception(e.toString());
    }
    return totalAvailable;
}

From source file:com.exilant.eGov.src.transactions.CommonMethodsImpl.java

License:Open Source License

/**
 * This is to check if a record already exist in integrationlog
 *//*  ww  w.  ja  v  a2 s  . co  m*/
@Override
public String checkRecordIdInLog(final String recordId, final int userId, final Connection connection)
        throws Exception {
    String cgn = null;
    try {
        final String query = "SELECT VOUCHERNUMBER FROM integrationlog WHERE RECORDID= ? and USERID= ? order by id desc";
        if (LOGGER.isInfoEnabled())
            LOGGER.info("  query   " + query);
        Query pst = persistenceService.getSession().createSQLQuery(query);
        pst.setString(0, recordId);
        pst.setInteger(1, userId);
        List<Object[]> rset = pst.list();
        for (final Object[] element : rset) {
            cgn = element[0].toString();
            if (LOGGER.isInfoEnabled())
                LOGGER.info("  cgn in log  " + cgn);
        }
    } catch (final Exception e) {
        LOGGER.error("Exp=" + e.getMessage(), e);
        throw new Exception(e.toString());
    }
    return cgn;
}

From source file:com.exilant.eGov.src.transactions.CommonMethodsImpl.java

License:Open Source License

/**
 * Get the division code of the id passed
 *//* w ww.ja  v  a 2  s.  c  o m*/
@Override
public String getDivisionCode(final Integer divid, final Connection connection) throws Exception {
    String divCode = null;
    final String sql = "SELECT distinct BNDRY_NUM FROM EG_BOUNDARY where ID_BNDRY= ?";
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("Divisio code query-->>>>>>>> " + sql);
    try {

        Query pst = persistenceService.getSession().createSQLQuery(sql);
        pst.setInteger(0, divid);
        List<Object[]> rset = pst.list();
        for (final Object[] element : rset) {
            divCode = element[0].toString();
            if (LOGGER.isDebugEnabled())
                LOGGER.debug("divCode >>>>>>>" + divCode);
        }

    } catch (final Exception e) {
        LOGGER.error("Exp=" + e.getMessage(), e);
        throw new Exception(e.toString());
    }
    return divCode;
}

From source file:com.exilant.GLEngine.ChartOfAccounts.java

License:Open Source License

private boolean updateInGL(final Transaxtion txnList[], final DataCollection dc)
        throws TaskFailedException, ParseException, SQLException {
    List<Object[]> resultset;
    CGeneralLedger gLedger = null;//from   w  w w  .  j  a  v a2  s  . c o  m
    ;
    CGeneralLedgerDetail gLedgerDet = null;
    EgRemittanceGldtl egRemitGldtl = null;
    // DataExtractor de=DataExtractor.getExtractor();
    final ArrayList glHeaderId = new ArrayList();
    final Transaxtion txn1 = txnList[0];
    final int VoucherHeaderId = Integer.parseInt(txn1.getVoucherHeaderId());
    if (LOGGER.isInfoEnabled())
        LOGGER.info("VoucherHeaderId----" + VoucherHeaderId);
    final String query = "select id from generalledger where voucherheaderid= ? order by id";
    Query pst = persistenceService.getSession().createSQLQuery(query);
    pst.setInteger(0, VoucherHeaderId);
    if (LOGGER.isInfoEnabled())
        LOGGER.info("select id from generalledger where voucherheaderid=" + VoucherHeaderId + " order by id");

    resultset = pst.list();
    int c = 0;
    for (final Object[] element : resultset) {

        glHeaderId.add(c, element[0].toString());
        c++;
    }

    final int count = glHeaderId.size();
    if (LOGGER.isInfoEnabled())
        LOGGER.info("count**********" + count);
    for (int k = 0; k < count; k++)
        try {
            final String delremitsql = "delete from eg_remittance_gldtl where gldtlid in (select id from generalledgerdetail where generalledgerid='"
                    + glHeaderId.get(k).toString() + "')";
            pst = persistenceService.getSession().createSQLQuery(delremitsql);
            pst.setString(0, glHeaderId.get(k).toString());
            if (LOGGER.isInfoEnabled())
                LOGGER.info("deleting remittance Query " + delremitsql);
            pst.executeUpdate();
            if (LOGGER.isInfoEnabled())
                LOGGER.info("delete from generalledgerdetail where generalledgerid='"
                        + glHeaderId.get(k).toString() + "'");
            final String delGenLedDet = "delete from generalledgerdetail where generalledgerid= ?";
            pst = persistenceService.getSession().createSQLQuery(delGenLedDet);
            pst.setString(0, glHeaderId.get(k).toString());
            final int del = pst.executeUpdate();
            if (del > 0)
                if (LOGGER.isInfoEnabled())
                    LOGGER.info("Records deleted from general ledger detail for GLH "
                            + glHeaderId.get(k).toString());
        } catch (final Exception e) {
            LOGGER.error("Exp in reading from generalledgerdetail: " + e, e);
            throw new TaskFailedException(e.getMessage());
        }

    if (count > 0)
        try {

            final String genLed = "DELETE FROM generalledger WHERE voucherheaderid= ?";
            pst = persistenceService.getSession().createSQLQuery(genLed);
            pst.setInteger(0, VoucherHeaderId);
            final int del = pst.executeUpdate();
            if (del > 0)
                if (LOGGER.isInfoEnabled())
                    LOGGER.info("DELETE FROM generalledger WHERE voucherheaderid=" + VoucherHeaderId);

        } catch (final Exception e) {
            if (LOGGER.isInfoEnabled())
                LOGGER.info("Exp in reading from generalledger: " + e, e);
        }

    for (final Transaxtion txn : txnList) {
        final GLAccount glAcc = (GLAccount) getGlAccountCodes().get(txn.getGlCode());
        gLedger = new CGeneralLedger();
        if (txn.getVoucherLineId() != null)
            gLedger.setVoucherlineId(Integer.parseInt(txn.getVoucherLineId()));
        CChartOfAccounts cChartOfAccounts = (CChartOfAccounts) persistenceService
                .find("from CChartOfAccounts where id=?", glAcc.getId());
        gLedger.setGlcodeId(cChartOfAccounts);
        gLedger.setGlcode(txn.getGlCode());
        gLedger.setDebitAmount(Double.parseDouble(txn.getDrAmount()));
        gLedger.setCreditAmount(Double.parseDouble(txn.getCrAmount()));
        gLedger.setDescription(txn.getNarration());
        CVoucherHeader cVoucherHeader = (CVoucherHeader) persistenceService
                .find("from CVoucherHeader where id=?", Long.parseLong(txn.getVoucherHeaderId()));
        gLedger.setVoucherHeaderId(cVoucherHeader);
        gLedger.setEffectiveDate(new Date());
        gLedger.setFunctionId(Integer.parseInt(txn.getFunctionId()));
        try {
            // if(LOGGER.isInfoEnabled())
            // LOGGER.info("inside the postin gl function before insert ----");
            generalLedgerPersistenceService.persist(gLedger);
        } catch (final Exception e) {
            if (LOGGER.isInfoEnabled())
                LOGGER.info("error in the gl++++++++++" + e, e);
            dc.addMessage("exilSQLError", e.toString());
            return false;
        }
        // if that code doesnot require any details no nedd to insert in GL
        // details
        if (glAcc.getGLParameters().size() <= 0)
            continue;
        final ArrayList glParamList = glAcc.getGLParameters();
        final ArrayList txnPrm = txn.getTransaxtionParam();
        String detKeyId = "";
        for (int a = 0; a < glParamList.size(); a++)
            try {
                // post the defaults set for details
                final GLParameter glPrm = (GLParameter) glParamList.get(a);
                /*
                 * if(!glPrm.getDetailKey().equalsIgnoreCase("0")&&glPrm.
                 * getDetailKey().length()>0){
                 * gLedgerDet.setGLId(String.valueOf(gLedger.getId()));
                 * gLedgerDet
                 * .setDetailTypeId(String.valueOf(glPrm.getDetailId()));
                 * gLedgerDet.setDetailKeyId(glPrm.getDetailKey());
                 * gLedgerDet.setDetailAmt(glPrm.getDetailAmt());
                 * gLedgerDet.insert(con); try {
                 * if(validRecoveryGlcode(gLedger.getglCodeId(),con) &&
                 * Double.parseDouble(gLedger.getcreditAmount())>0) {
                 * egRemitGldtl
                 * .setGldtlId(String.valueOf(gLedgerDet.getId()));
                 * egRemitGldtl.setGldtlAmt(gLedgerDet.getDetailAmt());
                 * if(glPrm.getTdsId()!=null)
                 * egRemitGldtl.setTdsId(glPrm.getTdsId());
                 * egRemitGldtl.insert(con); } } catch(Exception e) {
                 * LOGGER.
                 * error("Error while inserting to eg_remittance_gldtl "+e);
                 * return false; } }else
                 */ { // Post the details sent apart from defaults
                    for (int z = 0; z < txnPrm.size(); z++) {
                        final TransaxtionParameter tParam = (TransaxtionParameter) txnPrm.get(z);
                        if (tParam.getDetailName().equalsIgnoreCase(glPrm.getDetailName())
                                && tParam.getGlcodeId().equals(gLedger.getGlcodeId().getId().toString())) {
                            detKeyId = tParam.getDetailKey();
                            gLedgerDet = new CGeneralLedgerDetail();
                            gLedgerDet.setGeneralLedgerId(gLedger);
                            Accountdetailtype acctype = (Accountdetailtype) persistenceService
                                    .find("from Accountdetailtype where id=?", glPrm.getDetailId());
                            gLedgerDet.setDetailTypeId(acctype);
                            gLedgerDet.setDetailKeyId(Integer.parseInt(detKeyId));
                            gLedgerDet.setAmount(new BigDecimal(tParam.getDetailAmt()));
                            generalLedgerDetPersistenceService.persist(gLedgerDet);
                            try {
                                if (validRecoveryGlcode(String.valueOf(gLedger.getGlcodeId().getId()))
                                        && gLedger.getCreditAmount() > 0) {
                                    egRemitGldtl = new EgRemittanceGldtl();
                                    if (LOGGER.isDebugEnabled())
                                        LOGGER.debug("----------" + gLedger.getGlcode());
                                    egRemitGldtl.setGeneralledgerdetail(gLedgerDet);
                                    egRemitGldtl.setGldtlamt(gLedgerDet.getAmount());
                                    Recovery tdsentry = null;
                                    if (tParam.getTdsId() != null)
                                        tdsentry = (Recovery) persistenceService.find(
                                                "from Recovery where id=?", Long.parseLong(tParam.getTdsId()));
                                    egRemitGldtl.setRecovery(tdsentry);
                                    remitanceDetPersistenceService.persist(egRemitGldtl);
                                }
                            } catch (final Exception e) {
                                LOGGER.error("Error while inserting to eg_remittance_gldtl " + e, e);
                                return false;
                            }
                        }
                    }
                }
                // post the gldetailid, gldtlamt to eg_remittance_gldtl
                // table
                /*
                 * try { if(validRecoveryGlcode(gLedger.getglCodeId(),con)
                 * && Double.parseDouble(gLedger.getcreditAmount())>0) {
                 * egRemitGldtl
                 * .setGldtlId(String.valueOf(gLedgerDet.getId()));
                 * egRemitGldtl.setGldtlAmt(gLedgerDet.getDetailAmt());
                 * egRemitGldtl.insert(con); } } catch(Exception e) {
                 * LOGGER.
                 * error("Error while inserting to eg_remittance_gldtl "+e);
                 * return false; }
                 */
            } catch (final Exception e) {
                LOGGER.error("Inside updateInGl" + e.getMessage(), e);
                throw new TaskFailedException();
            }
    }
    // if(LOGGER.isInfoEnabled()) LOGGER.info("HI- 396-6");// TBR
    return true;
}

From source file:com.finalcuestionario.DAOPruebaImpl.java

public Prueba buscarporID(int id) {
    begin();/*  w w  w  .j  a  va2  s.  c  o m*/
    Query q = getSession().createQuery("from Prueba where id=:id");
    q.setInteger("id", id);
    Prueba p = (Prueba) q.uniqueResult();
    commit();
    return p;
}