Example usage for org.hibernate SQLQuery addScalar

List of usage examples for org.hibernate SQLQuery addScalar

Introduction

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

Prototype

SQLQuery<T> addScalar(String columnAlias, Type type);

Source Link

Document

Declare a scalar query result.

Usage

From source file:com.viettel.logistic.wms.dao.StockTransDAO.java

License:Open Source License

public List<StockTransDTO> getListStockTrans2Inventory(StockTransDTO stockTrans, String fromDate, String toDate,
        String stockTransType) {/*from ww w.  j a  va2 s  .com*/
    List<StockTransDTO> lstReturns = null;
    try {
        StringBuilder sql = new StringBuilder();
        sql.append("SELECT a.STOCK_TRANS_ID stockTransId, ");
        sql.append("       a.stock_trans_code stockTransCode, ");
        sql.append("       a.DEPT_ID deptId, ");
        sql.append("       a.STOCK_TRANS_TYPE stockTransType, ");
        sql.append("       to_char(a.stock_trans_date,'dd/MM/yyyy hh24:mi:ss') stockTransDate, ");
        sql.append("       a.OWNER_ID ownerId, ");
        sql.append("       a.owner_type ownerType, ");
        sql.append("       a.IE_OWNER_ID ieOwnerId, ");
        sql.append("       a.IE_OWNER_TYPE ieOwnerType, ");
        sql.append("       a.CUST_CODE custCode, ");
        sql.append("       a.CUST_ID custId, ");
        sql.append("       a.REASON_ID reasonId, ");
        sql.append("       a.STOCK_TRANS_STATUS stockTransStatus, ");
        sql.append("       a.FROM_STOCK_TRANS_ID fromStockTransId, ");
        sql.append("       a.NOTES notes, ");
        sql.append("       a.ORDER_ID_LIST orderIdList, ");
        sql.append("       to_char(a.ORDER_DATE,'dd/MM/yyyy hh24:mi:ss') orderDate, ");
        sql.append("       a.ORDER_CODE orderCode, ");
        sql.append("       to_char(a.CREATE_DATETIME,'dd/MM/yyyy hh24:mi:ss') createDatetime, ");
        sql.append("       a.CUST_NAME custName, ");
        sql.append("       a.IS_UPDATE_CELL isUpdateCell, ");
        sql.append("       a.PARTNER_ID partnerId, ");
        sql.append("       to_char(a.REAL_STOCK_TRANS_DATE,'dd/MM/yyyy hh24:mi:ss') realStockTransDate, ");
        sql.append("       a.ATTACH_FILE_NAME attachFileName, ");
        sql.append("       a.ORDER_ACTION_CODE orderActionCode, ");
        sql.append("       a.TRANS_USER_ID transUserId, ");
        sql.append("       a.TRANS_USER_NAME transUserName, ");
        sql.append("       a.SYN_TRANS_CODE synTransCode, ");
        sql.append("       a.ADD_INFOR addInfor, ");
        sql.append("       a.VOFFICE_TRANSACTION_CODE vofficeTransCode, ");
        sql.append("       a.ORDER_COMMAND_CODE orderCommandCode ");
        sql.append(" FROM stock_trans a ");
        sql.append(" WHERE  a.CUST_ID          = :idx0 ");
        sql.append("    AND a.OWNER_ID         = :idx1 ");
        sql.append("    AND a.STOCK_TRANS_TYPE IN ( :idx2 ) ");
        sql.append("    AND a.STOCK_TRANS_STATUS IN ( :idx3 ) ");
        sql.append("    AND TRUNC(a.CREATE_DATETIME)   >= TO_DATE(:idx4, 'dd/MM/yyyy') ");
        sql.append("    AND TRUNC(a.CREATE_DATETIME)   <= TO_DATE(:idx5, 'dd/MM/yyyy') ");
        sql.append("    AND EXISTS                 ");
        sql.append("            (SELECT st.STOCK_TRANS_CODE ");
        sql.append("            FROM stock_trans st ");
        sql.append("            WHERE   a.STOCK_TRANS_CODE   =  st.STOCK_TRANS_CODE ");
        sql.append("            GROUP BY st.STOCK_TRANS_CODE ");
        sql.append("            HAVING COUNT(st.STOCK_TRANS_CODE) <= 1 ");
        sql.append("            )");
        sql.append(" ORDER By a.stock_trans_date asc, stockTransType asc ");
        SQLQuery query = getSession().createSQLQuery(sql.toString());
        query.setResultTransformer(Transformers.aliasToBean(StockTransDTO.class));
        //Truyen cac tham so
        List lstParams = new ArrayList();
        lstParams.add(stockTrans.getCustId());
        lstParams.add(stockTrans.getOwnerId());
        lstParams.add(DataUtil.parseInputListString(stockTransType));
        //Chi lay cac giao dich co trang thai = 1, 2
        String stockTransStatus = "1,2";
        lstParams.add(DataUtil.parseInputListString(stockTransStatus));
        lstParams.add(fromDate);
        lstParams.add(toDate);
        //Kieu cua du lieu tra ra
        query.addScalar("stockTransId", new StringType());
        query.addScalar("stockTransCode", new StringType());
        query.addScalar("deptId", new StringType());
        query.addScalar("stockTransType", new StringType());
        query.addScalar("stockTransDate", new StringType());
        query.addScalar("ownerId", new StringType());
        query.addScalar("ownerType", new StringType());
        query.addScalar("ieOwnerId", new StringType());
        query.addScalar("ieOwnerType", new StringType());
        query.addScalar("custCode", new StringType());
        query.addScalar("custId", new StringType());
        query.addScalar("reasonId", new StringType());
        query.addScalar("stockTransStatus", new StringType());
        query.addScalar("fromStockTransId", new StringType());
        query.addScalar("notes", new StringType());
        query.addScalar("orderIdList", new StringType());
        query.addScalar("orderDate", new StringType());
        query.addScalar("orderCode", new StringType());
        query.addScalar("createDatetime", new StringType());
        query.addScalar("isUpdateCell", new StringType());
        query.addScalar("partnerId", new StringType());
        query.addScalar("realStockTransDate", new StringType());
        query.addScalar("attachFileName", new StringType());
        query.addScalar("orderActionCode", new StringType());
        query.addScalar("transUserId", new StringType());
        query.addScalar("transUserName", new StringType());
        query.addScalar("synTransCode", new StringType());
        query.addScalar("addInfor", new StringType());
        query.addScalar("vofficeTransCode", new StringType());
        query.addScalar("orderCommandCode", new StringType());

        for (int i = 0; i < lstParams.size(); i++) {
            if (lstParams.get(i) instanceof String[]) {
                query.setParameterList("idx" + String.valueOf(i), (Object[]) lstParams.get(i));
            } else {
                query.setParameter("idx" + String.valueOf(i), lstParams.get(i));
            }
        }
        lstReturns = query.list();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return lstReturns;
}

From source file:com.viettel.logistic.wms.dao.StockTransDetailDAO.java

License:Open Source License

public List<StockTransDetailDTO> getListStockTransDetailByOrderId(String orderId) {
    StringBuilder sql = new StringBuilder();
    List lstParams = new ArrayList();

    sql.append("  SELECT    std.stock_trans_detail_id stockTransDetailId,");
    sql.append("            st.stock_trans_id stockTransId,");
    sql.append("            std.goods_id goodsId,");
    sql.append("            std.goods_code goodsCode,");
    sql.append("            std.goods_name goodsName,");
    sql.append("            std.goods_state goodsState,");
    sql.append("            g.goods_type goodsType,");
    sql.append("            std.goods_unit_type goodsUnitType,");
    sql.append("            std.goods_unit_type_name goodsUnitTypeName,");
    sql.append("            std.goods_is_serial goodsIsSerial,");
    sql.append("            std.goods_is_serial_strip goodsIsSerialStrip,");
    sql.append("            std.amount_order amountOrder,");
    sql.append("            std.amount_real amountReal,");
    sql.append("            std.create_datetime createDatetime");
    sql.append("    FROM   stock_trans st,");
    sql.append("           goods g,");
    sql.append("           stock_trans_detail std");
    sql.append("   WHERE       st.stock_trans_id = std.stock_trans_id");
    sql.append("           AND std.goods_id = g.goods_id");
    sql.append("           AND st.stock_trans_status <> 0");
    sql.append("           AND st.order_id_list = ? ");

    lstParams.add(orderId);//  w  w w . j  av  a2  s . c  om

    SQLQuery query = getSession().createSQLQuery(sql.toString());
    query.setResultTransformer(Transformers.aliasToBean(StockTransDetailDTO.class));

    query.addScalar("stockTransDetailId", new StringType());
    query.addScalar("stockTransId", new StringType());
    query.addScalar("goodsId", new StringType());
    query.addScalar("goodsCode", new StringType());
    query.addScalar("goodsName", new StringType());
    query.addScalar("goodsState", new StringType());
    query.addScalar("goodsType", new StringType());
    query.addScalar("goodsUnitType", new StringType());
    query.addScalar("goodsUnitTypeName", new StringType());
    query.addScalar("goodsIsSerial", new StringType());
    query.addScalar("goodsIsSerialStrip", new StringType());
    query.addScalar("amountOrder", new StringType());
    query.addScalar("amountReal", new StringType());
    query.addScalar("createDatetime", new StringType());
    //
    for (int i = 0; i < lstParams.size(); i++) {
        query.setParameter(i, lstParams.get(i));
    }
    return query.list();
}

From source file:com.viettel.logistic.wms.dao.StockTransSerialDAO.java

License:Open Source License

public List<StockTransSerial> getListStockTransSerialBySerial(StockTransSerialDTO stockTransSerialDTO) {
    List<StockTransSerial> lst = new ArrayList();
    StringBuffer sql = new StringBuffer();
    List lstParams = new ArrayList();

    sql.append("SELECT   a.stock_trans_serial_id stockTransSerialId,");
    sql.append("         a.stock_trans_id stockTransId,");
    sql.append("         a.stock_trans_detail_id stockTransDetailId,");
    sql.append("         a.stock_trans_date stockTransDate,");
    sql.append("         a.goods_id goodsId,");
    sql.append("         a.goods_code goodsCode,");
    sql.append("         a.goods_name goodsName,");
    sql.append("         a.goods_state goodsState,");
    sql.append("         a.goods_unit_type goodsUnitType,");
    sql.append("         a.goods_unit_type_name goodsUnitTypeName,");
    sql.append("         a.from_serial fromSerial,");
    sql.append("         a.to_serial toserial,");
    sql.append("         a.amount_order amountOrder,");
    sql.append("         a.amount_real amountReal,");
    sql.append("         a.bincode bincode,");
    sql.append("         a.barcode barcode,");
    sql.append("         a.cell_code cellCode,");
    sql.append("         a.notes notes,");
    sql.append("         a.create_datetime createDatetime,");
    sql.append("         a.add_infor addInfor");
    sql.append("  FROM   stock_trans_serial a");
    sql.append(" WHERE   1 = 1 AND");
    sql.append("        goods_id = ?");
    sql.append("        AND");
    sql.append("        from_serial <= ?");
    sql.append("        AND");
    sql.append("        to_serial >= ?");
    sql.append("        AND stock_trans_date >= TO_DATE(?,'dd/mm/yyyy')");
    sql.append("        AND stock_trans_date <= TO_DATE(?,'dd/mm/yyyy') + 1");
    sql.append("        Order by stock_trans_date ASC");

    ///*  w  ww  .j  a  v a2  s  .com*/
    lstParams.add(stockTransSerialDTO.getGoodsId());
    lstParams.add(stockTransSerialDTO.getFromSerial());
    lstParams.add(stockTransSerialDTO.getToSerial());
    lstParams.add(stockTransSerialDTO.getFromDateSearch());
    lstParams.add(stockTransSerialDTO.getToDateSearch());
    //
    SQLQuery query = getSession().createSQLQuery(sql.toString());
    query.setResultTransformer(Transformers.aliasToBean(StockTransSerial.class));
    //
    query.addScalar("stockTransSerialId", new LongType());
    query.addScalar("stockTransId", new LongType());
    query.addScalar("stockTransDetailId", new LongType());
    query.addScalar("stockTransDate", new DateType());
    query.addScalar("goodsId", new LongType());
    query.addScalar("goodsCode", new StringType());
    query.addScalar("goodsName", new StringType());
    query.addScalar("goodsState", new StringType());
    query.addScalar("goodsUnitType", new StringType());
    query.addScalar("goodsUnitTypeName", new StringType());
    query.addScalar("fromSerial", new StringType());
    query.addScalar("toSerial", new StringType());
    query.addScalar("amountOrder", new LongType());
    query.addScalar("amountReal", new LongType());
    query.addScalar("bincode", new StringType());
    query.addScalar("barcode", new StringType());
    query.addScalar("cellCode", new StringType());
    query.addScalar("notes", new StringType());
    query.addScalar("createDatetime", new DateType());
    query.addScalar("addInfor", new StringType());
    //
    for (int i = 0; i < lstParams.size(); i++) {
        query.setParameter(i, lstParams.get(i));
    }
    lst = query.list();

    return lst;
}

From source file:com.viettel.logistic.wms.dao.StockTransSerialDAO.java

License:Open Source License

public List<StockTransSerial> getListStockTransSerialBySerialStrip(StockTransSerialDTO stockTransSerialDTO) {
    List<StockTransSerial> lst = new ArrayList();
    StringBuffer sql = new StringBuffer();
    List lstParams = new ArrayList();
    sql.append("SELECT   a.stock_trans_serial_id stockTransSerialId,");
    sql.append("         a.stock_trans_id stockTransId,");
    sql.append("         a.stock_trans_detail_id stockTransDetailId,");
    sql.append("         a.stock_trans_date stockTransDate,");
    sql.append("         a.goods_id goodsId,");
    sql.append("         a.goods_code goodsCode,");
    sql.append("         a.goods_name goodsName,");
    sql.append("         a.goods_state goodsState,");
    sql.append("         a.goods_unit_type goodsUnitType,");
    sql.append("         a.goods_unit_type_name goodsUnitTypeName,");
    sql.append("         a.from_serial fromSerial,");
    sql.append("         a.to_serial toserial,");
    sql.append("         a.amount_order amountOrder,");
    sql.append("         a.amount_real amountReal,");
    sql.append("         a.bincode bincode,");
    sql.append("         a.barcode barcode,");
    sql.append("         a.cell_code cellCode,");
    sql.append("         a.notes notes,");
    sql.append("         a.create_datetime createDatetime,");
    sql.append("         a.add_infor addInfor");
    sql.append("  FROM   stock_trans_serial a");
    sql.append(" WHERE   1 = 1 AND");
    sql.append("        goods_id = ?");
    sql.append("        AND");
    sql.append("        from_serial <= ?");
    sql.append("        AND");
    sql.append("        to_serial >= ? ");
    sql.append("        AND stock_trans_date >= TO_DATE(?,'dd/mm/yyyy')");
    sql.append("        AND stock_trans_date <= TO_DATE(?,'dd/mm/yyyy') + 1");
    sql.append("        Order by stock_trans_date ASC");

    ////w  ww  .j a v  a2s.co  m
    lstParams.add(stockTransSerialDTO.getGoodsId());
    lstParams.add(stockTransSerialDTO.getToSerial());
    lstParams.add(stockTransSerialDTO.getFromSerial());
    lstParams.add(stockTransSerialDTO.getFromDateSearch());
    lstParams.add(stockTransSerialDTO.getToDateSearch());
    //
    SQLQuery query = getSession().createSQLQuery(sql.toString());
    query.setResultTransformer(Transformers.aliasToBean(StockTransSerial.class));
    //
    query.addScalar("stockTransSerialId", new LongType());
    query.addScalar("stockTransId", new LongType());
    query.addScalar("stockTransDetailId", new LongType());
    query.addScalar("stockTransDate", new DateType());
    query.addScalar("goodsId", new LongType());
    query.addScalar("goodsCode", new StringType());
    query.addScalar("goodsName", new StringType());
    query.addScalar("goodsState", new StringType());
    query.addScalar("goodsUnitType", new StringType());
    query.addScalar("goodsUnitTypeName", new StringType());
    query.addScalar("fromSerial", new StringType());
    query.addScalar("toSerial", new StringType());
    query.addScalar("amountOrder", new LongType());
    query.addScalar("amountReal", new LongType());
    query.addScalar("bincode", new StringType());
    query.addScalar("barcode", new StringType());
    query.addScalar("cellCode", new StringType());
    query.addScalar("notes", new StringType());
    query.addScalar("createDatetime", new DateType());
    query.addScalar("addInfor", new StringType());
    //
    for (int i = 0; i < lstParams.size(); i++) {
        query.setParameter(i, lstParams.get(i));
    }
    lst = query.list();

    return lst;
}

From source file:com.viettel.logistic.wms.dao.StockTransSerialDAO.java

License:Open Source License

public List<StockTransSerialDTO> getListStockTransSerialByOrderId(String orderId) {
    StringBuilder sql = new StringBuilder();
    List lstParams = new ArrayList();

    sql.append("  SELECT    sts.stock_trans_serial_id stockTransSerialId, ");
    sql.append("            sts.stock_trans_id stockTransId,");
    sql.append("            sts.stock_trans_detail_id stockTransDetailId,");
    sql.append("            sts.goods_id goodsId,");
    sql.append("            sts.goods_code goodsCode,");
    sql.append("            sts.goods_name goodsName,");
    sql.append("            sts.goods_state goodsState,");
    sql.append("            sts.from_serial fromSerial,");
    sql.append("            sts.to_serial toSerial,");
    sql.append("            sts.amount_order amountOrder,");
    sql.append("            sts.amount_real amountReal");
    sql.append("    FROM   stock_trans st,");
    sql.append("           stock_trans_serial sts");
    sql.append("   WHERE       st.stock_trans_id = sts.stock_trans_id");
    sql.append("           AND st.stock_trans_status <> 0");
    sql.append("           AND st.order_id_list = ?");

    lstParams.add(orderId);/*from   ww w .  j  a v a  2  s . c o m*/

    SQLQuery query = getSession().createSQLQuery(sql.toString());
    query.setResultTransformer(Transformers.aliasToBean(StockTransSerialDTO.class));

    query.addScalar("stockTransSerialId", new StringType());
    query.addScalar("stockTransId", new StringType());
    query.addScalar("stockTransDetailId", new StringType());
    query.addScalar("goodsId", new StringType());
    query.addScalar("goodsCode", new StringType());
    query.addScalar("goodsName", new StringType());
    query.addScalar("goodsState", new StringType());
    query.addScalar("fromSerial", new StringType());
    query.addScalar("toSerial", new StringType());
    query.addScalar("amountOrder", new StringType());
    query.addScalar("amountReal", new StringType());

    //
    for (int i = 0; i < lstParams.size(); i++) {
        query.setParameter(i, lstParams.get(i));
    }
    return query.list();
}

From source file:com.yougou.api.service.impl.ApiKeyServiceImpl.java

@Override
public PageFinder<ApiKey> queryApiKey(ApiKeyMetadata apiKeyMetadata, Query query) throws Exception {
    StringBuilder sqlPrefixBuilder = new StringBuilder();
    sqlPrefixBuilder.append(" select ");
    sqlPrefixBuilder.append(/*from w ww  . j a va  2s. c o  m*/
            " t1.id, t1.app_key as appKey, t1.app_secret as appSecret, t1.status, t1.update_user as updateUser, t1.update_time as updateTime ");
    StringBuilder sqlSuffixBuilder = new StringBuilder();
    sqlSuffixBuilder.append(" from ");
    sqlSuffixBuilder.append(" tbl_merchant_api_key t1 ");
    sqlSuffixBuilder.append(" left join ");
    sqlSuffixBuilder.append(" tbl_merchant_api_key_metadata t2 ");
    sqlSuffixBuilder.append(" on(t1.id = t2.key_id) ");
    sqlSuffixBuilder.append(" left join ");
    sqlSuffixBuilder.append(" ( ");
    sqlSuffixBuilder.append(apiKeyDao.getApiKeyPotentialCustomersSqlStatement());
    sqlSuffixBuilder.append(" ) t3 ");
    sqlSuffixBuilder.append(" on (t2.metadata_val = t3.metadata_val) ");
    sqlSuffixBuilder.append(" where 1 = 1 ");

    // ?
    Map<String, Object> properties = new HashMap<String, Object>();
    if (apiKeyMetadata != null) {
        if (StringUtils.isNotBlank(apiKeyMetadata.getMetadataTag())) {
            sqlSuffixBuilder.append(" and t3.metadata_tag like :metadata_tag");
            properties.put("metadata_tag", '%' + apiKeyMetadata.getMetadataTag() + '%');
        }
        if (apiKeyMetadata.getMetadataKey() != null) {
            sqlSuffixBuilder.append(" and t2.metadata_key = :metadata_key ");
            properties.put("metadata_key", apiKeyMetadata.getMetadataKey().name());
        }
        if (StringUtils.isNotBlank(apiKeyMetadata.getMetadataVal())) {
            sqlSuffixBuilder.append(" and t2.metadata_val = :metadata_val ");
            properties.put("metadata_val", apiKeyMetadata.getMetadataVal());
        }
        if (apiKeyMetadata.getApiKey() != null) {
            if (apiKeyMetadata.getApiKey().getStatus() != null) {
                sqlSuffixBuilder.append(" and t1.status = :status ");
                properties.put("status", apiKeyMetadata.getApiKey().getStatus().ordinal());
            }
        }
    }

    Session session = null;
    PageFinder<ApiKey> pageFinder = null;
    try {
        session = apiKeyDao.getHibernateSession();
        SQLQuery sqlQuery = session.createSQLQuery("select count(1) " + sqlSuffixBuilder.toString());
        sqlQuery.setProperties(properties);
        int rowCount = ((Number) sqlQuery.uniqueResult()).intValue();
        pageFinder = new PageFinder<ApiKey>(query.getPage(), query.getPageSize(), rowCount);
        if (rowCount > 0) {
            // ?
            sqlSuffixBuilder.append(" group by ");
            sqlSuffixBuilder
                    .append(" t1.id, t1.app_key, t1.app_secret, t1.status, t1.update_user, t1.update_time ");
            sqlSuffixBuilder.append(" order by ");
            sqlSuffixBuilder.append(" t1.update_time desc ");
            // ?APP
            sqlQuery = session.createSQLQuery(sqlPrefixBuilder.append(sqlSuffixBuilder).toString());
            sqlQuery.setFirstResult(pageFinder.getStartOfPage());
            sqlQuery.setMaxResults(pageFinder.getPageSize());
            sqlQuery.setProperties(properties);
            sqlQuery.addScalar("id", Hibernate.STRING);
            sqlQuery.addScalar("appKey", Hibernate.STRING);
            sqlQuery.addScalar("appSecret", Hibernate.STRING);
            sqlQuery.addScalar("status", customApiKeyStatus);
            sqlQuery.addScalar("updateTime", Hibernate.STRING);
            sqlQuery.addScalar("updateUser", Hibernate.STRING);
            sqlQuery.setResultTransformer(Transformers.aliasToBean(ApiKey.class));
            List<ApiKey> merchantApiKeys = sqlQuery.list();
            // ?APP?
            sqlPrefixBuilder.setLength(0);
            sqlPrefixBuilder.append(" select ");
            sqlPrefixBuilder.append(
                    " t1.metadata_key as metadataKey, t1.metadata_val as metadataVal, t2.metadata_tag as metadataTag ");
            sqlPrefixBuilder.append(" from ");
            sqlPrefixBuilder.append(" tbl_merchant_api_key_metadata t1 ");
            sqlPrefixBuilder.append(" left join ");
            sqlPrefixBuilder.append(" ( ");
            sqlPrefixBuilder.append(apiKeyDao.getApiKeyPotentialCustomersSqlStatement());
            sqlPrefixBuilder.append(" ) t2 ");
            sqlPrefixBuilder.append(" on(t1.metadata_val = t2.metadata_val) ");
            sqlPrefixBuilder.append(" where ");
            sqlPrefixBuilder.append(" t1.key_id = ? ");
            sqlQuery = session.createSQLQuery(sqlPrefixBuilder.toString());
            sqlQuery.addScalar("metadataKey", customAppType);
            sqlQuery.addScalar("metadataVal", Hibernate.STRING);
            sqlQuery.addScalar("metadataTag", Hibernate.STRING);
            sqlQuery.setResultTransformer(Transformers.aliasToBean(ApiKeyMetadata.class));
            for (ApiKey merchantApiKey : merchantApiKeys) {
                sqlQuery.setParameter(0, merchantApiKey.getId());
                merchantApiKey.setApiKeyMetadatas(new HashSet<ApiKeyMetadata>(sqlQuery.list()));
            }
            pageFinder.setData(merchantApiKeys);
        }
    } finally {
        apiKeyDao.releaseHibernateSession(session);
    }
    return pageFinder;
}

From source file:com.yougou.api.service.impl.ApiKeyServiceImpl.java

@Override
public List<ApiKeyMetadata> queryApiKeyCustomers(String apiKeyId) throws Exception {
    StringBuilder sqlBuilder = new StringBuilder();
    sqlBuilder.append(" select ");
    sqlBuilder.append(//  ww  w.  j  a  v a2 s .c  o m
            " t1.metadata_key as metadataKey, t1.metadata_val as metadataVal, t1.metadata_tag as metadataTag ");
    sqlBuilder.append(" from ");
    sqlBuilder.append(" ( ");
    sqlBuilder.append(apiKeyDao.getApiKeyPotentialCustomersSqlStatement());
    sqlBuilder.append(" ) t1 ");
    sqlBuilder.append(" inner join ");
    sqlBuilder.append(" tbl_merchant_api_key_metadata t2 ");
    sqlBuilder.append(" on(t1.metadata_val = t2.metadata_val) ");
    sqlBuilder.append(" where ");
    sqlBuilder.append(" t2.key_id = ? ");

    Session session = null;
    try {
        session = apiKeyDao.getHibernateSession();
        SQLQuery sqlQuery = session.createSQLQuery(sqlBuilder.toString());
        sqlQuery.setParameter(0, apiKeyId);
        sqlQuery.addScalar("metadataKey", customAppType);
        sqlQuery.addScalar("metadataVal", Hibernate.STRING);
        sqlQuery.addScalar("metadataTag", Hibernate.STRING);
        sqlQuery.setResultTransformer(Transformers.aliasToBean(ApiKeyMetadata.class));
        return sqlQuery.list();
    } finally {
        apiKeyDao.releaseHibernateSession(session);
    }
}

From source file:com.yougou.api.service.impl.ApiKeyServiceImpl.java

@Override
public List<ApiKeyMetadata> queryApiKeyPotentialCustomers() throws Exception {
    StringBuilder sqlBuilder = new StringBuilder();
    sqlBuilder.append(" select ");
    sqlBuilder.append(/*  w ww  .  ja  va2s  . com*/
            " t1.metadata_key as metadataKey, t1.metadata_val as metadataVal, t1.metadata_tag as metadataTag ");
    sqlBuilder.append(" from ");
    sqlBuilder.append(" ( ");
    sqlBuilder.append(apiKeyDao.getApiKeyPotentialCustomersSqlStatement());
    sqlBuilder.append(" ) t1 ");
    sqlBuilder.append(" left join ");
    sqlBuilder.append(" tbl_merchant_api_key_metadata t2 ");
    sqlBuilder.append(" on(t1.metadata_val = t2.metadata_val) ");
    sqlBuilder.append(" where ");
    sqlBuilder.append(" t2.id is null ");

    Session session = null;
    try {
        session = apiKeyDao.getHibernateSession();
        SQLQuery sqlQuery = session.createSQLQuery(sqlBuilder.toString());
        sqlQuery.addScalar("metadataKey", customAppType);
        sqlQuery.addScalar("metadataVal", Hibernate.STRING);
        sqlQuery.addScalar("metadataTag", Hibernate.STRING);
        sqlQuery.setResultTransformer(Transformers.aliasToBean(ApiKeyMetadata.class));
        return sqlQuery.list();
    } finally {
        apiKeyDao.releaseHibernateSession(session);
    }
}

From source file:com.yougou.api.service.impl.ApiKeyServiceImpl.java

@Override
public List<ApiKeyMetadata> queryApiKeyByType(String type) throws Exception {
    StringBuilder sqlBuilder = new StringBuilder();
    sqlBuilder.append(" SELECT km.metadata_key as metadataKey,km.metadata_val as metadataVal ");
    sqlBuilder.append(" FROM tbl_merchant_api_key_metadata km ");
    sqlBuilder.append(" WHERE km.metadata_key = ? ");

    Session session = null;//from  ww w  .j  a  v  a2s. c om
    try {
        session = apiKeyDao.getHibernateSession();
        SQLQuery sqlQuery = session.createSQLQuery(sqlBuilder.toString());
        sqlQuery.setParameter(0, type);
        sqlQuery.addScalar("metadataKey", customAppType);
        sqlQuery.addScalar("metadataVal", Hibernate.STRING);
        sqlQuery.setResultTransformer(Transformers.aliasToBean(ApiKeyMetadata.class));
        return sqlQuery.list();
    } finally {
        apiKeyDao.releaseHibernateSession(session);
    }
}

From source file:com.yougou.api.service.impl.ApiKeyServiceImpl.java

@Override
public List<ApiKeyMetadata> queryApiKeyByapiKeyIdAndType(String apiKeyId, String type) throws Exception {
    StringBuilder sqlBuilder = new StringBuilder();
    sqlBuilder.append(" SELECT km.metadata_key as metadataKey,km.metadata_val as metadataVal ");
    sqlBuilder.append(" FROM tbl_merchant_api_key_metadata km ");
    sqlBuilder.append(" WHERE km.key_id = ? ");
    sqlBuilder.append(" AND km.metadata_key = ? ");

    Session session = null;// w  ww.  ja v a  2s . c o  m
    try {
        session = apiKeyDao.getHibernateSession();
        SQLQuery sqlQuery = session.createSQLQuery(sqlBuilder.toString());
        sqlQuery.setParameter(0, apiKeyId);
        sqlQuery.setParameter(1, type);
        sqlQuery.addScalar("metadataKey", customAppType);
        sqlQuery.addScalar("metadataVal", Hibernate.STRING);
        sqlQuery.setResultTransformer(Transformers.aliasToBean(ApiKeyMetadata.class));
        return sqlQuery.list();
    } finally {
        apiKeyDao.releaseHibernateSession(session);
    }
}