List of usage examples for java.math BigInteger intValue
public int intValue()
From source file:com.zl.bgec.basicapi.shop.service.impl.ShopServiceImpl.java
@Override @Transactional(readOnly = true)//w w w.jav a 2 s.c om public PageFinder<Map<String, Object>> pagedGroupBuyProduct(Map<String, String> map) throws Exception { String shopNo = String.valueOf(map.get("shopNo")); int pageNo = Integer.parseInt(map.get("pageNo")); int pageSize = Integer.parseInt(map.get("pageSize")); String catNo = String.valueOf(map.get("catNo") == null ? "" : map.get("catNo")); String sqlProduct = "select IF(tp.prod_name is null,'',tp.prod_name) prodName," + " IF(tp.default_pic is null,'',tp.default_pic) prodPic," + " tp.price prodPrice," + " tp.prod_no prodNo," + " tpromotion.start_time startTime," + " tpromotion.end_time endTime," + " tpromotion.discount_amount groupPrice," + " ifnull(tp.stock,0) stock," + " ifnull(tp.stock_preemption,0) stockPreemption," + " IF(tp.sell_num is null,0,tp.sell_num) sellNum ," + " tc.is_recommend isRecommend " + " from tbl_product tp left join tbl_commodity tc on tc.commo_no = tp.commo_no" + " left join tbl_promotion tpromotion on tpromotion.ref_commo_no = tc.commo_no" + " where tc.seller_no = :shopNo and tc.publish_state ='1' and tp.is_groupbuy ='2' "; if (catNo != null && !catNo.isEmpty()) { sqlProduct = sqlProduct + " and tc.cat_no=:catNo "; } sqlProduct = sqlProduct + "and tp.delete_flag ='0' " + " and tpromotion.status='2' " + " and now() between tpromotion.start_time and tpromotion.end_time " + " and tp.delete_flag ='0' " + " order by ifnull(tp.sort,2147483647) asc, tp.sell_num desc,tc.publish_time desc"; String countSql = "select count(*) " + " from tbl_product tp left join tbl_commodity tc on tc.commo_no = tp.commo_no" + " left join tbl_promotion tpromotion on tpromotion.ref_commo_no = tc.commo_no" + " where tc.seller_no = :shopNo" + " and tpromotion.status='2' " + " and now() between tpromotion.start_time and tpromotion.end_time " + " and tc.publish_state ='1' and tp.delete_flag ='0' "; if (catNo != null && !catNo.isEmpty()) { sqlProduct = sqlProduct + " and tc.cat_no=:catNo "; } Query query = shopDao.createSQLQuery(sqlProduct); query = productDao.createSQLQuery(sqlProduct); query.setParameter("shopNo", shopNo); if (catNo != null && !catNo.isEmpty()) { query.setParameter("catNo", catNo); } query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP); Query queryCount = shopDao.createSQLQuery(countSql.toString()); queryCount.setParameter("shopNo", shopNo); if (catNo != null && !catNo.isEmpty()) { queryCount.setParameter("catNo", catNo); } BigInteger totalRows = (BigInteger) queryCount.uniqueResult(); if (totalRows.intValue() == 0) { return new PageFinder<Map<String, Object>>(pageNo, pageSize, 0); } PageFinder<Map<String, Object>> pageFinder = new PageFinder<Map<String, Object>>(pageNo, pageSize, totalRows.intValue()); query.setMaxResults(pageFinder.getPageSize()); query.setFirstResult(pageFinder.getStartOfPage()); pageFinder.setData(query.list()); return pageFinder; }
From source file:org.opencms.cmis.CmsCmisTypeManager.java
/** * Collects the children of a type.<p> * * @param typeId the id of the type// w ww . ja va 2s.c o m * @param includePropertyDefinitions true if the property definitions should be included * @param maxItems the maximum number of items to return * @param skipCount the number of items to skip * * @return the children of the type */ public TypeDefinitionList getTypeChildren( String typeId, boolean includePropertyDefinitions, BigInteger maxItems, BigInteger skipCount) { refresh(); TypeDefinitionListImpl result = new TypeDefinitionListImpl(new ArrayList<TypeDefinition>()); int skip = (skipCount == null ? 0 : skipCount.intValue()); if (skip < 0) { skip = 0; } int max = (maxItems == null ? Integer.MAX_VALUE : maxItems.intValue()); if (max < 1) { return result; } if (typeId == null) { if (skip < 1) { result.getList().add(copyTypeDefintion(m_types.get(FOLDER_TYPE_ID).getTypeDefinition())); max--; } if ((skip < 2) && (max > 0)) { result.getList().add(copyTypeDefintion(m_types.get(DOCUMENT_TYPE_ID).getTypeDefinition())); max--; } result.setHasMoreItems(Boolean.valueOf((result.getList().size() + skip) < 2)); result.setNumItems(BigInteger.valueOf(2)); } else { TypeDefinitionContainer tc = m_types.get(typeId); if ((tc == null) || (tc.getChildren() == null)) { return result; } for (TypeDefinitionContainer child : tc.getChildren()) { if (skip > 0) { skip--; continue; } result.getList().add(copyTypeDefintion(child.getTypeDefinition())); max--; if (max == 0) { break; } } result.setHasMoreItems(Boolean.valueOf((result.getList().size() + skip) < tc.getChildren().size())); result.setNumItems(BigInteger.valueOf(tc.getChildren().size())); } if (!includePropertyDefinitions) { for (TypeDefinition type : result.getList()) { type.getPropertyDefinitions().clear(); } } return result; }
From source file:org.opencms.cmis.CmsCmisTypeManager.java
/** * Gets the descendants of a type.<p> * * @param typeId the parent type id// w w w.j a va 2 s. c o m * @param depth the depth up to which the descendant types should be collected * @param includePropertyDefinitions true if the property definitions should be included * * @return the descendants of the type */ public List<TypeDefinitionContainer> getTypeDescendants( String typeId, BigInteger depth, boolean includePropertyDefinitions) { refresh(); List<TypeDefinitionContainer> result = new ArrayList<TypeDefinitionContainer>(); // check depth int d = (depth == null ? -1 : depth.intValue()); if (d == 0) { throw new CmisInvalidArgumentException("Depth must not be 0!"); } if (typeId == null) { result.add(getTypeDescendants(d, m_types.get(FOLDER_TYPE_ID), includePropertyDefinitions)); result.add(getTypeDescendants(d, m_types.get(DOCUMENT_TYPE_ID), includePropertyDefinitions)); result.add(getTypeDescendants(d, m_types.get(RELATIONSHIP_TYPE_ID), includePropertyDefinitions)); } else { TypeDefinitionContainer tc = m_types.get(typeId); if (tc != null) { result.add(getTypeDescendants(d, tc, includePropertyDefinitions)); } } return result; }
From source file:com.zl.bgec.basicapi.shop.service.impl.ShopServiceImpl.java
@Override @Transactional(readOnly = true)/* ww w .jav a2 s . com*/ public Map<String, Object> getShopIndexInfo(String memberNo) throws Exception { String sql = "select tsi.shop_name shopName," + "tsi.shop_address shopAddress," + "tsi.shop_logo shopLogo," + "tsi.status status, " + "tsi.shop_no shopNo " + "from tbl_shop_info tsi where tsi.merch_no=:shopNo and tsi.status!='3'"; Query query = shopDao.createSQLQuery(sql); query.setParameter("shopNo", memberNo); query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP); List<Map<String, Object>> results = query.list(); Map<String, Object> result = new HashMap<String, Object>(); if (results != null && !results.isEmpty()) { result = results.get(0); } else { return null; } String shopNo = String.valueOf(result.get("shopNo")); Criteria criteria = commodityDao.createCriteria(Restrictions.eq("sellerNo", shopNo)); criteria.add(Restrictions.eq("deleteFlag", (byte) 0));// criteria.add(Restrictions.eq("publishState", "1"));// int commodityCount = commodityDao.getRowCount(criteria);// ?? result.put("commodityCount", String.valueOf(commodityCount)); criteria = shopCollectDao.createCriteria(Restrictions.eq("shopNo", shopNo)); int collectCount = shopCollectDao.getRowCount(criteria); result.put("collectCount", String.valueOf(collectCount)); Criteria promotionCriteria = promotionDao.createCriteria(Restrictions.eq("shopNo", shopNo)); promotionCriteria.add(Restrictions.ge("endTime", new Date()));// promotionCriteria.add(Restrictions.eq("status", "2"));// promotionCriteria.add(Restrictions.eq("lockFlag", "0"));//? promotionCriteria.add(Restrictions.ne("promotionType", "2"));//? int count = promotionDao.getRowCount(promotionCriteria); result.put("promotionCount", count); List<String> values = new ArrayList<String>(); // values.add(OrderConstants.BASIC_STATE_REFUND); // values.add(OrderConstants.BASIC_STATE_ALREADY_RECEIVE); // values.add(OrderConstants.BASIC_STATE_REFUND_APPLY); values.add(OrderConstants.BASIC_STATE_WAITING_DELIVERY); // values.add(OrderConstants.BASIC_STATE_WAITING_RETURN); // values.add(OrderConstants.BASIC_STATE_WAITING_PAY); // values.add(OrderConstants.BASIC_STATE_ALREADY_DELIVERY); Criteria criteriaOrder = orderDao.createCriteria(Restrictions.in("basicState", values)); criteriaOrder.add(Restrictions.eq("deleteFlag", (byte) 0)); criteriaOrder.add(Restrictions.eq("shopNo", shopNo)); String sqlGroupBuy = "select count(*) " + " from tbl_promotion tp " + " left join tbl_product tpr on tp.ref_commo_no = tpr.commo_no" + " where tp.promotion_type='2' and tp.delete_flag='0' and tp.shop_no=:shopNo and :curentTime between tp.start_time and tp.end_time "; Query groupBuyQuery = promotionDao.createSQLQuery(sqlGroupBuy); groupBuyQuery.setParameter("shopNo", shopNo); groupBuyQuery.setParameter("curentTime", new Date()); BigInteger totalRows = (BigInteger) groupBuyQuery.uniqueResult(); result.put("groupBuyCount", totalRows.intValue()); result.put("orderCount", orderDao.getRowCount(criteriaOrder)); String gradeSql = "select avg(tcc.service_grade) serviceGrade," + " avg(tcc.delivery_grade) deliveryGrade" + " from tbl_commodity_comment tcc " + " where tcc.shop_no = :shopNo " + " group by(tcc.shop_no) "; Query queryGrade = shopDao.createSQLQuery(gradeSql); queryGrade.setParameter("shopNo", shopNo); queryGrade.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP); List<Map<String, Object>> list = queryGrade.list(); if (list != null && !list.isEmpty()) { Double servGrade = list.get(0).get("serviceGrade") == null ? 0 : Double.valueOf(list.get(0).get("serviceGrade").toString()); BigDecimal serviceGrade = new BigDecimal(servGrade); serviceGrade = serviceGrade.setScale(1, BigDecimal.ROUND_HALF_EVEN); result.put("serviceGrade", serviceGrade.doubleValue()); Double delGrade = list.get(0).get("deliveryGrade") == null ? 0 : Double.valueOf(list.get(0).get("deliveryGrade").toString()); BigDecimal deliveryGrade = new BigDecimal(delGrade); deliveryGrade = deliveryGrade.setScale(1, BigDecimal.ROUND_HALF_EVEN); result.put("deliveryGrade", deliveryGrade.doubleValue()); } else { result.put("serviceGrade", "0"); result.put("deliveryGrade", "0"); } return result; }
From source file:com.buildabrand.gsb.util.URLUtils.java
private String convertIpAddress(String ipAddr) { String[] ipAddrSplit = StringUtils.split(ipAddr, '.'); if (ipAddrSplit.length == 0 || ipAddrSplit.length > 4) { return null; }/* w w w .j a v a2 s . co m*/ // Basically we should parse octal if we can, but if there are illegal octal // numbers, i.e. 08 or 09, then we should just look at decimal and hex. boolean allowOctal = !FIND_BAD_OCTAL_REGEXP.matcher(ipAddr).find(); BigInteger ipNumeric = BigInteger.ZERO; int i = 0; while (i < ipAddrSplit.length - 1) { ipNumeric = ipNumeric.shiftLeft(8); BigInteger componentBigInt = convertComponent(ipAddrSplit[i], allowOctal); if (componentBigInt == null) { return null; } ipNumeric = ipNumeric.add(componentBigInt); i++; } while (i < 4) { ipNumeric = ipNumeric.shiftLeft(8); i++; } BigInteger componentBigInt = convertComponent(ipAddrSplit[ipAddrSplit.length - 1], allowOctal); if (componentBigInt == null) { return null; } ipNumeric = ipNumeric.add(componentBigInt); return InetAddresses.fromInteger((ipNumeric.intValue())).getHostAddress(); }
From source file:org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.source.WfsSourceTest.java
/** * Given 10 features (and metacards) exist that match search criteria, since page size=4 and * startIndex=0, should get 4 results back - metacards 1 thru 4. * * @throws WfsException, SecurityServiceException * @throws TransformerConfigurationException * @throws UnsupportedQueryException//from w w w. ja va 2 s .c o m */ @Test public void testPagingStartIndexZero() throws WfsException, SecurityServiceException, TransformerConfigurationException, UnsupportedQueryException { // Setup int pageSize = 4; int startIndex = 0; WfsSource source = getWfsSource(ONE_TEXT_PROPERTY_SCHEMA, MockWfsServer.getFilterCapabilities(), GeospatialUtil.EPSG_4326_URN, 10, false); Filter filter = builder.attribute(Metacard.ANY_TEXT).is().like().text(LITERAL); Query query = new QueryImpl(filter, startIndex, pageSize, null, false, 0); // Execute GetFeatureType featureType = source.buildGetFeatureRequest(query); BigInteger startIndexGetFeature = featureType.getStartIndex(); BigInteger countGetFeature = featureType.getCount(); // Verify assertThat(countGetFeature.intValue(), is(pageSize)); assertThat(startIndexGetFeature.intValue(), is(startIndex)); }
From source file:com.ephesoft.dcma.tablefinder.share.TableRowFinderUtility.java
/** * Runs regex validation for the column extraction. */*from ww w . ja v a 2 s .c o m*/ * @param expressionEvaluator {@list ExpressionEvaluator}<{@list Boolean}> * @param columnHeaderValidationRequired boolean * @param columnCoordinateValidationRequired boolean * @param columnRowList {@link List}<{@link Column> * @param colHeaderDataCarrier {@link DataCarrier} * @param regexValidationDataCarrier {@link RegexValidationDataCarrier} * @return boolean True if regex validation is passed. * @throws DCMAApplicationException */ public static boolean runRegexValidation(final ExpressionEvaluator<Boolean> expressionEvaluator, final boolean columnHeaderValidationRequired, final boolean columnCoordinateValidationRequired, final List<Column> columnRowList, final DataCarrier colHeaderDataCarrier, final RegexValidationDataCarrier regexValidationDataCarrier) throws DCMAApplicationException { boolean isRegexValidationPassed = false; LOGGER.info("Applying Regex Validation for table extraction ..... "); TableColumnVO tableColumn = regexValidationDataCarrier.getTableColumn(); if (EphesoftStringUtil.isNullOrEmpty(tableColumn.getExtractedDataColumnName())) { // columnHeadStartCoordinate and columnHeadEndCoordinate are used to take help of column data position // knowledge from column header/column coordinate, for Regex Validation based extraction. int columnHeadStartCoordinate = TableExtractionConstants.MINIMUM_POSITIVE_COORDINATE_VALUE; int columnHeadEndCoordinate = TableExtractionConstants.MINIMUM_POSITIVE_COORDINATE_VALUE; // Preparing a new column object. final Column column = regexValidationDataCarrier.getColumn(); Column regexExtractionColumn = new Column(); regexExtractionColumn.setValid(false); regexExtractionColumn.setValidationRequired(false); regexExtractionColumn.setConfidence(0.0f); regexExtractionColumn.setForceReview(false); regexExtractionColumn.setOcrConfidence(0.0f); regexExtractionColumn.setOcrConfidenceThreshold(0.0f); regexExtractionColumn.setValid(false); regexExtractionColumn.setValidationRequired(false); TableRowFinderUtility.setColumnProperties(regexValidationDataCarrier.getPageID(), regexExtractionColumn, null, 0); regexExtractionColumn.setName(tableColumn.getColumnName()); if (isDataValid(expressionEvaluator, true, false, false)) { if (columnHeaderValidationRequired && null != colHeaderDataCarrier) { LOGGER.info("Fetching column coordinate start and end headers for Regex Validation."); Coordinates spanCoordinates = colHeaderDataCarrier.getCoordinates(); if (null != spanCoordinates) { BigInteger X0 = spanCoordinates.getX0(); BigInteger X1 = spanCoordinates.getX1(); if (null != X0 && null != X1) { columnHeadStartCoordinate = X0.intValue(); columnHeadEndCoordinate = X1.intValue(); } } } else if (columnCoordinateValidationRequired) { ColumnCoordinates columnCoordinates = TableRowFinderUtility.getXColumncoordinates(tableColumn); Integer columnCoordX0 = columnCoordinates.getX0Coordinate(); Integer columnCoordX1 = columnCoordinates.getX1coordinate(); if (null != columnCoordX0 && null != columnCoordX1) { LOGGER.info("Fetching column coordinate start and end for Regex Validation."); columnHeadStartCoordinate = columnCoordX0.intValue(); columnHeadEndCoordinate = columnCoordX1.intValue(); } } LOGGER.debug("Column start coordinate is: ", columnHeadStartCoordinate, ". Column End Coordinate is: ", columnHeadEndCoordinate); regexValidationDataCarrier.setColumnCoordinates(null); } regexValidationDataCarrier.setColumn(regexExtractionColumn); isRegexValidationPassed = applyRegexValidation(columnRowList, columnHeadStartCoordinate, columnHeadEndCoordinate, regexValidationDataCarrier); if (isRegexValidationPassed) { TableRowFinderUtility.setColumnConfidence(tableColumn, regexExtractionColumn); if (EphesoftStringUtil.isNullOrEmpty(column.getValue()) && column.getConfidence() == 0 || regexExtractionColumn.getConfidence() > column.getConfidence()) { TableRowFinderUtility.swapColumnContents(regexExtractionColumn, column); } // Add columnCoordinateColumn to alternate values of column. if (null != regexExtractionColumn.getValue()) { column.getAlternateValues().getAlternateValue().add(regexExtractionColumn); } } } return isRegexValidationPassed; }
From source file:com.sun.honeycomb.admin.mgmt.server.HCCellAdapterBase.java
/** * Update the service tag data associated with a single cell. This routine * must be called on ever cell in order to keep the silo_info.xml * up to date./*w w w . j a v a 2s . co m*/ * <P> * On the master cell this routine will clear the service tag registry * and attempt to repopulate it with the new service tag registry * information. * @param evt the callback handle * @param tagData the service tag data to update * @param updateRegistry boolean to indicate whether the registry * file should be rebuilt. If the callee already knows the * service tag data is invalid they will call this value with a * value of 0. In this case this api is getting used to clear the * registry and the instanceURNs * @return BigInteger, 0 for SUCCESS, -1 for failure. * Currently always returns 0 * @throws com.sun.honeycomb.mgmt.common.MgmtException */ public BigInteger updateAllServiceTagData(EventSender evt, HCServiceTags tagData, BigInteger updateRegistry) throws MgmtException { boolean updateRegistryFile = updateRegistry.intValue() == 1; MultiCellLib multiCell = MultiCellLib.getInstance(); boolean isStandAlone = multiCell.isCellStandalone(); StringBuffer buf = new StringBuffer(); buf.append(" service tag data for cell"); if (isStandAlone == false) { buf.append(" ").append(getCellId()); } buf.append("."); Reassure reassureThread = null; try { reassureThread = new Reassure(evt); reassureThread.start(); boolean isSupported = ServiceTagsRegistry.isSupported(); boolean isMaster = multiCell.isCellMaster(); if (isSupported && isMaster) { // If we modify an service tag data the service tag registry // is considered out of date. As such we clear the registry // of all ST5800 service tags. clearRegistry(); } List<HCServiceTagCellData> list = tagData.getData(); HCServiceTagCellData[] hCellData = (HCServiceTagCellData[]) list .toArray(new HCServiceTagCellData[list.size()]); ServiceTagCellData[] cellData = new ServiceTagCellData[hCellData.length]; for (int i = 0; i < hCellData.length; i++) { ServiceTagData data = new ServiceTagData(hCellData[i].getProductNumber(), hCellData[i].getProductSerialNumber(), hCellData[i].getMarketingNumber(), hCellData[i].getInstanceURN()); ServiceTagCellData cell = new ServiceTagCellData(hCellData[i].getCellId(), data); cellData[i] = cell; } multiCell.updateServiceTagData(cellData); buf.insert(0, "Successfully updated"); logger.log(Level.INFO, buf.toString()); //evt.sendAsynchronousEvent(buf.toString()); if (updateRegistryFile && isMaster) { // Reset the buf to new action in case of exception buf = new StringBuffer(" service tag registry."); if (isSupported == false) { evt.sendAsynchronousEvent(SERVICE_TAG_REGISTRY_IS_NOT_AVAILABLE_MSG); return BigInteger.valueOf(CliConstants.FAILURE); } // The silo_info.xml has been updated. // Now update the service tag registry ServiceTagsGenerator generator = new ServiceTagsGenerator(cellData); if (generator.isValid() == false) { // This should technically never happen is everything is // done via the cli since the validation check on the cli // side should of failed and prevented this call from // ever occurring buf = new StringBuffer(); buf.append("Failed to update service tag registry due to a "); buf.append("validation error.\nSee logs for further details."); // Validation errors found via ServiceTagsGenerator are // logged by default evt.sendAsynchronousEvent(buf.toString()); return BigInteger.valueOf(CliConstants.SERVICE_TAG_REGISTRY_VALIDATION_FAILURE); } else { ServiceTagsRegistry.update(generator.getServiceTags()); buf.insert(0, "Successfully updated"); logger.log(Level.INFO, buf.toString()); } } return BigInteger.ZERO; } catch (MultiCellLibError mcle) { buf.insert(0, "Failed to update"); logger.log(Level.SEVERE, buf.toString(), mcle); buf.append(" Reason: "); buf.append(mcle.getMessage()); buf.append(".\n"); buf.append("Ensure that the servicetag entries are all valid by invoking the command,\n"); buf.append("'servicetags --refresh'."); evt.sendAsynchronousEvent(buf.toString()); return BigInteger.valueOf(CliConstants.FAILURE); } catch (Exception ex) { buf.insert(0, "Failed to update"); logger.log(Level.SEVERE, buf.toString(), ex); buf.append(" Reason: "); buf.append(ex.getMessage()); buf.append(".\n"); buf.append("Ensure that the servicetag entries are all valid by invoking the command,\n"); buf.append("'servicetags --refresh'"); evt.sendAsynchronousEvent(buf.toString()); return BigInteger.valueOf(CliConstants.FAILURE); } finally { if (reassureThread != null) reassureThread.safeStop(); } }
From source file:de.tudarmstadt.ukp.csniper.webapp.project.ProjectRepository.java
/** * Gets the maximum column length.<br> * Why is this method located here? For convenience reasons - we already have access to * projectRepository on the relevant pages (EvaluationPage, AnnotationTypePage). * //from ww w . j a va 2 s . c om * @param aColumn * the column for which the maximum length shall be returned * @return the maximum length of the specified column in the specified table */ @Transactional public int getDbColumnLength(String aEntityName, String aColumn) { BigInteger length = new BigInteger("255"); final List<String> query = new ArrayList<String>(); query.add("SELECT CHARACTER_MAXIMUM_LENGTH"); query.add("FROM INFORMATION_SCHEMA.COLUMNS"); Session session = entityManager.unwrap(Session.class); session.doWork(new Work() { @Override public void execute(Connection aConnection) throws SQLException { query.add("WHERE table_schema = '" + aConnection.getCatalog() + "'"); } }); query.add("AND table_name = '" + aEntityName + "'"); query.add("AND column_name = '" + aColumn + "'"); try { length = (BigInteger) entityManager.createNativeQuery(StringUtils.join(query, " ")).getSingleResult(); } catch (NoResultException e) { // log.debug("No results for query: " + StringUtils.join(query, " ")); } if (length.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) > 0) { return Integer.MAX_VALUE; } else { return length.intValue(); } }
From source file:org.openmrs.module.sdmxhddataexport.db.hibernate.HibernateSDMXHDDataExportDAO.java
public Integer executeQuery(String query, String startDate, String endDate) throws DAOException { query = query.toLowerCase();// ww w. ja v a 2 s . c o m if (!query.startsWith("select")) { //////////// return 0; return -1; } BigInteger result = new BigInteger("0"); String start = DateUtils.getDateFromRange(startDate) + " 00:00:00"; String end = DateUtils.getDateFromRange(endDate) + " 23:59:59"; try { if (query.indexOf("?") != -1) { query = query.replaceFirst("\\?", " '" + start + "' "); query = query.replaceFirst("\\?", " '" + end + "' "); while (query.contains("?")) { query = query.replaceFirst("\\?", " '" + start + "' "); query = query.replaceFirst("\\?", " '" + end + "' "); } } org.hibernate.Query q = sessionFactory.getCurrentSession().createSQLQuery(query); Object l = q.uniqueResult(); if (l != null) { result = (BigInteger) l; } } catch (Exception e) { return -1; } return result != null ? result.intValue() : -1; }