Example usage for org.hibernate Query setBigInteger

List of usage examples for org.hibernate Query setBigInteger

Introduction

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

Prototype

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

Source Link

Document

Bind a named BigInteger-valued parameter.

Usage

From source file:com.cloud.bridge.util.QueryHelper.java

License:Open Source License

public static void bindParameters(Query query, Object[] params) {
    int pos = 0;/*w w  w  .java 2  s  . c o  m*/
    if (params != null && params.length > 0) {
        for (Object param : params) {
            if (param instanceof Byte)
                query.setByte(pos++, ((Byte) param).byteValue());
            else if (param instanceof Short)
                query.setShort(pos++, ((Short) param).shortValue());
            else if (param instanceof Integer)
                query.setInteger(pos++, ((Integer) param).intValue());
            else if (param instanceof Long)
                query.setLong(pos++, ((Long) param).longValue());
            else if (param instanceof Float)
                query.setFloat(pos++, ((Float) param).floatValue());
            else if (param instanceof Double)
                query.setDouble(pos++, ((Double) param).doubleValue());
            else if (param instanceof Boolean)
                query.setBoolean(pos++, ((Boolean) param).booleanValue());
            else if (param instanceof Character)
                query.setCharacter(pos++, ((Character) param).charValue());
            else if (param instanceof Date)
                query.setDate(pos++, (Date) param);
            else if (param instanceof Calendar)
                query.setCalendar(pos++, (Calendar) param);
            else if (param instanceof CalendarDateParam)
                query.setCalendarDate(pos++, ((CalendarDateParam) param).dateValue());
            else if (param instanceof TimestampParam)
                query.setTimestamp(pos++, ((TimestampParam) param).timestampValue());
            else if (param instanceof TimeParam)
                query.setTime(pos++, ((TimeParam) param).timeValue());
            else if (param instanceof String)
                query.setString(pos++, (String) param);
            else if (param instanceof TextParam)
                query.setText(pos++, ((TextParam) param).textValue());
            else if (param instanceof byte[])
                query.setBinary(pos++, (byte[]) param);
            else if (param instanceof BigDecimal)
                query.setBigDecimal(pos++, (BigDecimal) param);
            else if (param instanceof BigInteger)
                query.setBigInteger(pos++, (BigInteger) param);
            else if (param instanceof Locale)
                query.setLocale(pos++, (Locale) param);
            else if (param instanceof EntityParam)
                query.setEntity(pos++, ((EntityParam) param).entityValue());
            else if (param instanceof Serializable)
                query.setSerializable(pos++, (Serializable) param);
            else
                query.setEntity(pos++, param);
        }
    }
}

From source file:com.enonic.cms.store.dao.ContentIndexEntityDao.java

License:Open Source License

public List<ContentKey> findContentKeysByQuery(final String hqlQuery, final Map<String, Object> parameters,
        final boolean cacheable) {
    return executeListResult(ContentKey.class, new HibernateCallback() {

        public Object doInHibernate(Session session) throws HibernateException, SQLException {
            Query compiled = session.createQuery(hqlQuery);
            compiled.setCacheable(cacheable);

            for (String key : parameters.keySet()) {
                Object value = parameters.get(key);
                if (value instanceof Date) {
                    compiled.setTimestamp(key, (Date) value);
                } else if (value instanceof String) {
                    compiled.setString(key, (String) value);
                } else if (value instanceof Boolean) {
                    compiled.setBoolean(key, (Boolean) value);
                } else if (value instanceof Long) {
                    compiled.setLong(key, (Long) value);
                } else if (value instanceof Integer) {
                    compiled.setInteger(key, (Integer) value);
                } else if (value instanceof Byte) {
                    compiled.setByte(key, (Byte) value);
                } else if (value instanceof byte[]) {
                    compiled.setBinary(key, (byte[]) value);
                } else if (value instanceof Float) {
                    compiled.setFloat(key, (Float) value);
                } else if (value instanceof Double) {
                    compiled.setDouble(key, (Double) value);
                } else if (value instanceof BigDecimal) {
                    compiled.setBigDecimal(key, (BigDecimal) value);
                } else if (value instanceof Short) {
                    compiled.setShort(key, (Short) value);
                } else if (value instanceof BigInteger) {
                    compiled.setBigInteger(key, (BigInteger) value);
                } else if (value instanceof Character) {
                    compiled.setCharacter(key, (Character) value);
                } else {
                    compiled.setParameter(key, value);
                }/*from   ww  w. ja v a 2 s  . c o m*/
            }

            final List result = compiled.list();

            LinkedHashSet<ContentKey> distinctContentKeySet = new LinkedHashSet<ContentKey>(result.size());

            for (Object value : result) {
                if (value instanceof ContentKey) {
                    distinctContentKeySet.add((ContentKey) value);
                } else {
                    Object[] valueList = (Object[]) value;
                    distinctContentKeySet.add(((ContentKey) valueList[0]));
                }
            }

            List<ContentKey> distinctContentKeyList = new ArrayList<ContentKey>(distinctContentKeySet.size());
            distinctContentKeyList.addAll(distinctContentKeySet);
            return distinctContentKeyList;
        }
    });
}

From source file:com.exilant.eGov.src.domain.GeneralLedger.java

License:Open Source License

@SuppressWarnings("deprecation")
@Transactional/*from   www .  jav a  2 s .c  o  m*/
public void insert() throws SQLException, TaskFailedException {
    final EGovernCommon commommethods = new EGovernCommon();
    Query pst = null;
    try {
        effectiveDate = String.valueOf(commommethods.getCurrentDate());
        Date dt = new Date();
        final SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
        final SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy");
        dt = sdf.parse(effectiveDate);
        effectiveDate = formatter.format(dt);

        description = commommethods.formatString(description);
        setId(String.valueOf(PrimaryKeyGenerator.getNextKey("GeneralLedger")));

        if (functionId == null || functionId.equals(""))
            functionId = null;
        String insertQuery;
        insertQuery = "INSERT INTO generalledger (id, voucherLineID, effectiveDate, glCodeID, "
                + "glCode, debitAmount, creditAmount,";
        insertQuery += "description,voucherHeaderId,functionId) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";

        if (LOGGER.isInfoEnabled())
            LOGGER.info(insertQuery);
        pst = persistenceService.getSession().createSQLQuery(insertQuery);
        pst.setBigInteger(0, BigInteger.valueOf(Long.valueOf(id)));
        pst.setBigInteger(1,
                voucherLineId == null ? BigInteger.ZERO : BigInteger.valueOf(Long.valueOf(voucherLineId)));
        pst.setTimestamp(2, dt);
        pst.setBigInteger(3,
                glCodeId.equalsIgnoreCase("null") ? null : BigInteger.valueOf(Long.valueOf(glCodeId)));
        pst.setString(4, glCode);
        pst.setDouble(5, debitAmount.equalsIgnoreCase("null") ? null : Double.parseDouble(debitAmount));
        pst.setDouble(6, creditAmount.equalsIgnoreCase("null") ? null : Double.parseDouble(creditAmount));
        pst.setString(7, description);
        pst.setBigInteger(8, voucherHeaderId.equalsIgnoreCase("null") ? null
                : BigInteger.valueOf(Long.valueOf(voucherHeaderId)));
        pst.setBigInteger(9, functionId == null ? null : BigInteger.valueOf(Long.valueOf(functionId)));
        pst.executeUpdate();
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
        throw taskExc;
    } finally {
    }

}

From source file:com.mangocity.util.dao.GenericDAOHibernateImpl.java

License:Open Source License

private void setObjectFromType(Object value, Query query, int i) {
    if (value instanceof Date) {
        query.setDate(i, (Date) value);
    } else if (value instanceof BigDecimal) {
        query.setBigDecimal(i, (BigDecimal) value);
    } else if (value instanceof BigInteger) {
        query.setBigInteger(i, (BigInteger) value);
    } else {/*from  w  ww .  j  a  v  a  2  s .c o  m*/
        query.setParameter(i, value);
    }
}

From source file:org.egov.ptis.actions.bills.BillGenerationAction.java

License:Open Source License

@SuppressWarnings("unchecked")
@Action(value = "/bills/billGeneration-billGenStatusByPartNo")
public String billGenStatusByPartNo() {
    LOGGER.debug("Entered into billGenStatusByPartNo, wardNum=" + wardNum);

    ReportInfo reportInfo;/*from  www  . j av  a2 s  .c  o m*/
    Integer totalProps = 0;
    Integer totalBillsGen = 0;
    final Installment currInst = propertyTaxCommonUtils.getCurrentInstallment();

    final StringBuilder billQueryString = new StringBuilder();
    final StringBuilder propQueryString = new StringBuilder();

    billQueryString.append("select bp.partNo, count(bp.partNo) ")
            .append("from EgBill bill, Boundary bndry, PtNotice notice left join notice.basicProperty bp ")
            .append("where bp.propertyID.ward.id=bndry.id ").append("and bndry.boundaryNum = :bndryNum ")
            .append("and bill.is_History = 'N' ").append("and :FromDate <= bill.issueDate ")
            .append("and :ToDate >= bill.issueDate ").append("and bill.egBillType.code = :BillType ")
            .append("and bill.billNo = notice.noticeNo ").append("and notice.noticeType = 'Bill' ")
            .append("and notice.fileStore is not null ").append("group by bp.partNo ")
            .append("order by bp.partNo");

    propQueryString.append("select bp.partNo, count(bp.partNo) ")
            .append("from Boundary bndry, PropertyID pid left join pid.basicProperty bp ")
            .append("where bp.active = true and pid.ward.id = bndry.id ")
            .append("and bndry.boundaryNum = :bndryNum ").append("group by bp.partNo ")
            .append("order by bp.partNo");

    final Query billQuery = getPersistenceService().getSession().createQuery(billQueryString.toString());
    billQuery.setBigInteger("bndryNum", new BigInteger(wardNum));
    billQuery.setDate("FromDate", currInst.getFromDate());
    billQuery.setDate("ToDate", currInst.getToDate());
    billQuery.setString("BillType", BILLTYPE_MANUAL);

    final List<Object> billList = billQuery.list();

    final Query propQuery = getPersistenceService().getSession().createQuery(propQueryString.toString());
    propQuery.setBigInteger("bndryNum", new BigInteger(wardNum));
    final List<Object> propList = propQuery.list();

    for (final Object props : propList) {
        reportInfo = new ReportInfo();
        final Object[] propObj = (Object[]) props;
        reportInfo.setPartNo(String.valueOf(propObj[0]));
        reportInfo.setTotalNoProps(Integer.valueOf(((Long) propObj[1]).toString()));

        reportInfo.setTotalGenBills(0);
        String partNo;

        for (final Object bills : billList) {

            final Object[] billObj = (Object[]) bills;
            partNo = String.valueOf(billObj[0]);

            if (reportInfo.getPartNo().equals(partNo)) {
                reportInfo.setTotalGenBills(Integer.valueOf(((Long) billObj[1]).toString()));
                break;
            }
        }

        totalProps = totalProps + reportInfo.getTotalNoProps();
        totalBillsGen = totalBillsGen + reportInfo.getTotalGenBills();
        getReportInfos().add(reportInfo);
    }

    final ReportInfo reportInfoCount = new ReportInfo();
    reportInfoCount.setPartNo("Total :");
    reportInfoCount.setTotalNoProps(totalProps);
    reportInfoCount.setTotalGenBills(totalBillsGen);
    getReportInfos().add(reportInfoCount);

    LOGGER.debug("Exiting from billGenStatusByPartNo");
    return STATUS_BILLGEN_BY_PARTNO;
}