Example usage for org.hibernate SQLQuery setLong

List of usage examples for org.hibernate SQLQuery setLong

Introduction

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

Prototype

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

Source Link

Document

Bind a positional long-valued parameter.

Usage

From source file:org.egov.wtms.application.service.BaseRegisterReportService.java

License:Open Source License

@ReadOnly
public List<BaseRegisterResult> getBaseRegisterReportDetails(final String ward) throws ParseException {

    final StringBuilder queryStr = new StringBuilder();
    queryStr.append(//from  w w  w  .ja  v  a2 s .co  m
            "select dcbinfo.hscno as \"consumerNo\", dcbinfo.oldhscno as \"oldConsumerNo\", dcbinfo.propertyid as \"assementNo\", ");
    queryStr.append(
            "dcbinfo.username as \"ownerName\",dcbinfo.categorytype as \"categoryType\",dcbinfo.username as \"period\",dcbinfo.houseno as \"doorNo\",");
    queryStr.append(
            " dcbinfo.connectiontype as \"connectionType\" , dcbinfo.arr_demand as \"arrears\" ,  dcbinfo.curr_demand as \"current\" , ");
    queryStr.append(
            " dcbinfo.arr_coll as \"arrearsCollection\" ,  dcbinfo.curr_coll as \"currentCollection\" , ");
    queryStr.append(
            " dcbinfo.arr_demand+dcbinfo.curr_demand as \"totalDemand\" , dcbinfo.usagetype as \"usageType\" , dcbinfo.waterSource as \"waterSource\" ,");
    queryStr.append(
            " dcbinfo.pipesize as \"pipeSize\" , dcbinfo.arr_coll+dcbinfo.curr_coll as \"totalCollection\" , wrd.monthlyrate as \"monthlyRate\" ");
    queryStr.append(
            " from  egwtr_usage_type ut, egwtr_water_source wt, egwtr_pipesize ps, egwtr_water_rates_header wrh,egwtr_water_rates_details wrd ,");
    queryStr.append(
            " egwtr_mv_dcb_view dcbinfo INNER JOIN eg_boundary wardboundary on dcbinfo.wardid = wardboundary.id ");
    queryStr.append(" INNER JOIN eg_boundary localboundary on dcbinfo.locality = localboundary.id");
    queryStr.append(
            " where ut.id=wrh.usagetype and wt.id=wrh.watersource and ps.id=wrh.pipesize and dcbinfo.usagetype =ut.name and  dcbinfo.watersource = wt.watersourcetype and dcbinfo.pipesize = ps.code and wrd.waterratesheader=wrh.id and wrh.active=true  and wrd.fromdate <= now() and  wrd.todate >= now() and dcbinfo.connectionstatus = '"
                    + ConnectionStatus.ACTIVE.toString() + "'");
    if (StringUtils.isNotBlank(ward))
        queryStr.append(" and wardboundary.id = :ward");
    queryStr.append(
            " UNION select dcbinfo.hscno as \"consumerNo\", dcbinfo.oldhscno as \"oldConsumerNo\", dcbinfo.propertyid as \"assementNo\", ");
    queryStr.append(
            "dcbinfo.username as \"ownerName\",dcbinfo.categorytype as \"categoryType\",dcbinfo.username as \"period\",dcbinfo.houseno as \"doorNo\",");
    queryStr.append(
            " dcbinfo.connectiontype as \"connectionType\" , dcbinfo.arr_demand as \"arrears\" ,  dcbinfo.curr_demand as \"current\" , ");
    queryStr.append(
            " dcbinfo.arr_coll as \"arrearsCollection\" ,  dcbinfo.curr_coll as \"currentCollection\" , ");
    queryStr.append(
            " dcbinfo.arr_demand+dcbinfo.curr_demand as \"totalDemand\" , dcbinfo.usagetype as \"usageType\" , dcbinfo.waterSource as \"waterSource\" ,");
    queryStr.append(
            " dcbinfo.pipesize as \"pipeSize\" , dcbinfo.arr_coll+dcbinfo.curr_coll as \"totalCollection\" , 0 as \"monthlyRate\" ");
    queryStr.append(
            " from  egwtr_usage_type ut, egwtr_water_source wt, egwtr_pipesize ps, egwtr_water_rates_header wrh,egwtr_water_rates_details wrd ,");
    queryStr.append(
            " egwtr_mv_dcb_view dcbinfo INNER JOIN eg_boundary wardboundary on dcbinfo.wardid = wardboundary.id ");
    queryStr.append(" INNER JOIN eg_boundary localboundary on dcbinfo.locality = localboundary.id");
    queryStr.append(
            " where ut.id=wrh.usagetype and wt.id=wrh.watersource and ps.id=wrh.pipesize and dcbinfo.usagetype =ut.name and  dcbinfo.watersource = wt.watersourcetype and dcbinfo.pipesize = ps.code and wrd.waterratesheader=wrh.id and wrh.active=false and dcbinfo.connectionstatus = '"
                    + ConnectionStatus.ACTIVE.toString() + "'" + " and dcbinfo.hscno not in (");
    queryStr.append(
            " select dcbinfo.hscno from  egwtr_usage_type ut, egwtr_water_source wt, egwtr_pipesize ps, egwtr_water_rates_header wrh,egwtr_water_rates_details wrd ,");
    queryStr.append(
            " egwtr_mv_dcb_view dcbinfo INNER JOIN eg_boundary wardboundary on dcbinfo.wardid = wardboundary.id ");
    queryStr.append(" INNER JOIN eg_boundary localboundary on dcbinfo.locality = localboundary.id");
    queryStr.append(
            " where ut.id=wrh.usagetype and wt.id=wrh.watersource and ps.id=wrh.pipesize and dcbinfo.usagetype =ut.name and  dcbinfo.watersource = wt.watersourcetype and dcbinfo.pipesize = ps.code and wrd.waterratesheader=wrh.id and wrh.active=true  and wrd.fromdate <= now() and  wrd.todate >= now() and dcbinfo.connectionstatus = '"
                    + ConnectionStatus.ACTIVE.toString() + "')");
    if (StringUtils.isNotBlank(ward))
        queryStr.append(" and wardboundary.id = :ward");
    final SQLQuery query = getCurrentSession().createSQLQuery(queryStr.toString());
    if (StringUtils.isNotBlank(ward))
        query.setLong("ward", Long.valueOf(ward));
    query.setResultTransformer(new AliasToBeanResultTransformer(BaseRegisterResult.class));
    return query.list();

}

From source file:org.egov.wtms.masters.service.BoundaryWiseReportService.java

License:Open Source License

private SQLQuery setParameterForDrillDownReportQuery(final String querykey, final String ward,
        final String block) {
    final SQLQuery query = entityQueryService.getSession().createSQLQuery(querykey);
    if (StringUtils.isNotBlank(ward))
        query.setLong("ward", Long.valueOf(ward));
    if (StringUtils.isNotBlank(block))
        query.setLong("block", Long.valueOf(block));
    query.setResultTransformer(Transformers.aliasToBean(WaterConnectionReportResult.class));
    return query;

}

From source file:org.jcvi.ometa.hibernate.dao.ProjectDAO.java

License:Open Source License

public List<Project> getChildProjects(Long projectId, Session session) throws DAOException {
    List<Project> returnVal = new ArrayList<Project>();
    try {/*from w w w.  j  a  v  a  2  s  .  com*/
        SQLQuery query = session.createSQLQuery(CHILD_PROJECTS_SQL_QUERY);
        /*query.addScalar(RTN_PROJECT_NAME, Hibernate.STRING );
        query.addScalar(RTN_PROJECT_ID, Hibernate.LONG );*/
        query.setLong("parantId", projectId); //ParentProjectId
        query.addEntity("P", Project.class);
        returnVal = query.list();

    } catch (Exception ex) {
        throw new DAOException(ex);
    }

    return returnVal;
}

From source file:org.kimios.kernel.reporting.impl.EntityInformationsReport.java

License:Open Source License

public String getData() throws ConfigException, DataSourceException {
    Vector<Cell> cells = new Vector<Cell>();
    Report report = new Report("EntityInformations");
    report.addColumn("Position");
    report.addColumn("AllVersionsVolume");
    report.addColumn("CurrentVersionsVolume");
    report.addColumn("EntitiesNumber");

    /* get informations about entity */
    String rqInformationsAboutEntity = "SELECT e.dm_entity_path as Position, e.dm_entity_type as EntityType ";
    rqInformationsAboutEntity += "FROM dm_entity e ";
    rqInformationsAboutEntity += "WHERE e.dm_entity_id=:dmEntityUid ";
    SQLQuery sqlInformationsAboutEntity = FactoryInstantiator.getInstance().getDtrFactory().getSession()
            .createSQLQuery(rqInformationsAboutEntity);
    sqlInformationsAboutEntity.addScalar("Position", StringType.INSTANCE);
    sqlInformationsAboutEntity.addScalar("EntityType", IntegerType.INSTANCE);
    sqlInformationsAboutEntity.setLong("dmEntityUid", dmEntity.getUid());

    List<Object[]> reports = sqlInformationsAboutEntity.list();
    for (Object[] r : reports) {
        cells.add(new Cell("Position", (String) r[0]));
    }/*from   w  w w.j  a  v  a  2 s .com*/

    /* get all versions volume */
    String rqAllVersionsVolume = "SELECT SUM(v.version_length) as AllVersionsVolume "
            + "FROM dm_entity e, document_version v " + "WHERE e.dm_entity_id=v.document_id "
            + "AND e.dm_entity_path LIKE :dmEntityPath";
    SQLQuery sqlAllVersionsVolume = FactoryInstantiator.getInstance().getDtrFactory().getSession()
            .createSQLQuery(rqAllVersionsVolume);
    sqlAllVersionsVolume.addScalar("AllVersionsVolume", LongType.INSTANCE);
    sqlAllVersionsVolume.setString("dmEntityPath", dmEntity.getPath() + "/%");
    Object allVersionsVolume = sqlAllVersionsVolume.list().get(0);
    if (allVersionsVolume == null) {
        allVersionsVolume = new Long(0);
    }
    cells.add(new Cell("AllVersionsVolume", allVersionsVolume));

    /* get current versions volume */

    String rqCurrentVersionsVolume = "SELECT SUM(v.version_length) as AllVersionsVolume "
            + "FROM document_version v, dm_entity e " + "WHERE v.document_id=e.dm_entity_id "
            + "AND e.dm_entity_path LIKE :dmEntityPath " + "AND v.creation_date IN ( "
            + "SELECT MAX(creation_date) as creationDate " + "FROM document_version v "
            + "GROUP BY document_id " + ")";
    SQLQuery sqlCurrentVersionsVolume = FactoryInstantiator.getInstance().getDtrFactory().getSession()
            .createSQLQuery(rqCurrentVersionsVolume);
    sqlCurrentVersionsVolume.addScalar("AllVersionsVolume", LongType.INSTANCE);
    sqlCurrentVersionsVolume.setString("dmEntityPath", dmEntity.getPath() + "/%");
    Object currentVersionsVolume = sqlCurrentVersionsVolume.list().get(0);
    if (currentVersionsVolume == null) {
        currentVersionsVolume = new Long(0);
    }
    cells.add(new Cell("CurrentVersionsVolume", currentVersionsVolume));

    /* get entities number */

    String rqEntitiesNumber = "SELECT COUNT(dm_entity_id) as EntitiesNumber " + "FROM dm_entity e "
            + "WHERE e.dm_entity_path LIKE :dmEntityPath ";
    SQLQuery sqlEntitiesNumber = getSession().createSQLQuery(rqEntitiesNumber);
    sqlEntitiesNumber.addScalar("EntitiesNumber", LongType.INSTANCE);
    sqlEntitiesNumber.setString("dmEntityPath", dmEntity.getPath() + "/%");
    cells.add(new Cell("EntitiesNumber", sqlEntitiesNumber.list().get(0)));

    report.addRow(new Row(cells));
    return report.toXML();
}

From source file:org.kimios.kernel.reporting.impl.factory.DocumentTransactionsReportFactory.java

License:Open Source License

public void removeGhostTransaction(long transactionUid) {
    String rq = "DELETE FROM data_transaction " + "WHERE uid=:transactionUid";
    SQLQuery sql = getSession().createSQLQuery(rq);
    sql.setLong("transactionUid", transactionUid);
    sql.executeUpdate();/*from   w ww.j  a v  a 2s .co m*/
}

From source file:org.linagora.linshare.core.repository.hibernate.ContainerQuotaRepositoryImpl.java

License:Open Source License

public List<Long> getQuotaIdforDefaultMaxFileSizeInSubDomains(AbstractDomain domain, QuotaType type,
        ContainerQuotaType containerType) {
    HibernateCallback<List<Long>> action = new HibernateCallback<List<Long>>() {
        public List<Long> doInHibernate(final Session session) throws HibernateException, SQLException {
            StringBuilder sb = new StringBuilder();
            sb.append("SELECT DISTINCT child.id AS child_id FROM quota AS father");
            sb.append(" JOIN quota AS child");
            sb.append(" ON child.domain_parent_id = father.domain_id");
            sb.append(" AND child.quota_type = :domainType ");
            sb.append(" AND father.domain_parent_id = :domainId ");
            sb.append(" AND father.default_max_file_size_override = false");
            sb.append(" WHERE father.quota_type = :domainType");
            if (containerType != null) {
                sb.append(" AND child.container_type = :containerType");
            }/* w  w  w  . j  ava  2 s . c o m*/
            sb.append(" AND child.default_max_file_size_override = false");
            sb.append(";");
            final SQLQuery query = session.createSQLQuery(sb.toString());
            query.setLong("domainId", domain.getPersistenceId());
            query.addScalar("child_id", LongType.INSTANCE);
            query.setString("domainType", type.name());
            if (containerType != null) {
                query.setString("containerType", containerType.name());
            }
            @SuppressWarnings("unchecked")
            List<Long> res = query.list();
            logger.debug("child_ids :" + res);
            return res;
        }
    };
    return getHibernateTemplate().execute(action);
}

From source file:org.linagora.linshare.core.repository.hibernate.ContainerQuotaRepositoryImpl.java

License:Open Source License

public List<Long> getQuotaIdforDefaultMaxFileSizeInTopDomains(AbstractDomain domain, QuotaType type,
        ContainerQuotaType containerType) {
    HibernateCallback<List<Long>> action = new HibernateCallback<List<Long>>() {
        public List<Long> doInHibernate(final Session session) throws HibernateException, SQLException {
            StringBuilder sb = new StringBuilder();
            sb.append("SELECT DISTINCT id FROM quota ");
            sb.append(" WHERE quota_type = :domainType");
            sb.append(" AND container_type = :containerType");
            sb.append(" AND max_file_size_override = false");
            sb.append(" AND domain_parent_id = :domainId ");
            sb.append(";");
            final SQLQuery query = session.createSQLQuery(sb.toString());
            query.setLong("domainId", domain.getPersistenceId());
            query.addScalar("id", LongType.INSTANCE);
            query.setString("domainType", type.name());
            query.setString("containerType", containerType.name());
            @SuppressWarnings("unchecked")
            List<Long> res = query.list();
            logger.debug("ids :" + res);
            return res;
        }//from  ww w.j av  a2s.com
    };
    return getHibernateTemplate().execute(action);
}

From source file:org.linagora.linshare.core.repository.hibernate.ContainerQuotaRepositoryImpl.java

License:Open Source License

public List<Long> getQuotaIdforMaxFileSizeInSubDomains(AbstractDomain domain, QuotaType type,
        ContainerQuotaType containerType) {
    HibernateCallback<List<Long>> action = new HibernateCallback<List<Long>>() {
        public List<Long> doInHibernate(final Session session) throws HibernateException, SQLException {
            StringBuilder sb = new StringBuilder();
            sb.append("SELECT DISTINCT child.id AS child_id FROM quota AS father");
            sb.append(" JOIN quota AS child");
            sb.append(" ON child.domain_parent_id = father.domain_id");
            sb.append(" AND child.quota_type = :domainType ");
            sb.append(" AND father.domain_parent_id = :domainId ");
            sb.append(" AND father.max_file_size_override = false");
            if (containerType != null) {
                sb.append(" AND father.container_type = :containerType");
            }/* w  ww .ja va  2s  . c o m*/
            sb.append(" WHERE father.quota_type = :domainType");
            if (containerType != null) {
                sb.append(" AND child.container_type = :containerType");
            }
            sb.append(" AND child.max_file_size_override = false");
            sb.append(";");
            final SQLQuery query = session.createSQLQuery(sb.toString());
            query.setLong("domainId", domain.getPersistenceId());
            query.addScalar("child_id", LongType.INSTANCE);
            query.setString("domainType", type.name());
            if (containerType != null) {
                query.setString("containerType", containerType.name());
            }
            @SuppressWarnings("unchecked")
            List<Long> res = query.list();
            logger.debug("child_ids :" + res);
            return res;
        }
    };
    return getHibernateTemplate().execute(action);
}

From source file:org.linagora.linshare.core.repository.hibernate.ContainerQuotaRepositoryImpl.java

License:Open Source License

public List<Long> getQuotaIdforDefaultAccountQuotaInTopDomains(AbstractDomain domain, QuotaType type,
        ContainerQuotaType containerType) {
    HibernateCallback<List<Long>> action = new HibernateCallback<List<Long>>() {
        public List<Long> doInHibernate(final Session session) throws HibernateException, SQLException {
            StringBuilder sb = new StringBuilder();
            sb.append("SELECT DISTINCT id FROM quota ");
            sb.append(" WHERE quota_type = :domainType");
            sb.append(" AND container_type = :containerType");
            sb.append(" AND account_quota_override = false");
            sb.append(" AND domain_parent_id = :domainId ");
            sb.append(";");
            final SQLQuery query = session.createSQLQuery(sb.toString());
            query.setLong("domainId", domain.getPersistenceId());
            query.addScalar("id", LongType.INSTANCE);
            query.setString("domainType", type.name());
            query.setString("containerType", containerType.name());
            @SuppressWarnings("unchecked")
            List<Long> res = query.list();
            logger.debug("ids :" + res);
            return res;
        }/*w ww.  ja  v a 2 s . co  m*/
    };
    return getHibernateTemplate().execute(action);
}

From source file:org.linagora.linshare.core.repository.hibernate.ContainerQuotaRepositoryImpl.java

License:Open Source License

public List<Long> getQuotaIdforDefaultAccountQuotaInSubDomains(AbstractDomain domain, QuotaType type,
        ContainerQuotaType containerType) {
    HibernateCallback<List<Long>> action = new HibernateCallback<List<Long>>() {
        public List<Long> doInHibernate(final Session session) throws HibernateException, SQLException {
            StringBuilder sb = new StringBuilder();
            sb.append("SELECT DISTINCT child.id AS child_id FROM quota AS father");
            sb.append(" JOIN quota AS child");
            sb.append(" ON child.domain_parent_id = father.domain_id");
            sb.append(" AND child.quota_type = :domainType ");
            sb.append(" AND father.domain_parent_id = :domainId ");
            sb.append(" AND father.default_account_quota_override = false");
            sb.append(" WHERE father.quota_type = :domainType");
            if (containerType != null) {
                sb.append(" AND child.container_type = :containerType");
            }//from w w w .j a  v  a  2s  .c o m
            sb.append(" AND child.account_quota_override = false");
            sb.append(";");
            final SQLQuery query = session.createSQLQuery(sb.toString());
            query.setLong("domainId", domain.getPersistenceId());
            query.addScalar("child_id", LongType.INSTANCE);
            query.setString("domainType", type.name());
            if (containerType != null) {
                query.setString("containerType", containerType.name());
            }
            @SuppressWarnings("unchecked")
            List<Long> res = query.list();
            logger.debug("child_ids :" + res);
            return res;
        }
    };
    return getHibernateTemplate().execute(action);
}