List of usage examples for java.lang Long intValue
public int intValue()
From source file:com.gst.infrastructure.dataqueries.service.EntityDatatableChecksWritePlatformServiceImpl.java
@Override public void runTheCheckForProduct(final Long entityId, final String entityName, final Long statusCode, String foreignKeyColumn, long productId) { List<EntityDatatableChecks> tableRequiredBeforAction = entityDatatableChecksRepository .findByEntityStatusAndProduct(entityName, statusCode, productId); if (tableRequiredBeforAction == null || tableRequiredBeforAction.size() < 1) { tableRequiredBeforAction = entityDatatableChecksRepository.findByEntityStatusAndNoProduct(entityName, statusCode);/*from w w w. ja va 2 s .c om*/ } if (tableRequiredBeforAction != null) { List<String> reqDatatables = new ArrayList<>(); for (EntityDatatableChecks t : tableRequiredBeforAction) { final String datatableName = t.getDatatableName(); final Long countEntries = readWriteNonCoreDataService.countDatatableEntries(datatableName, entityId, foreignKeyColumn); logger.info("The are " + countEntries + " entries in the table " + datatableName); if (countEntries.intValue() == 0) { reqDatatables.add(datatableName); } } if (reqDatatables.size() > 0) { throw new DatatableEntryRequiredException(reqDatatables.toString()); } } }
From source file:info.bluefoot.componentsexample.dao.support.HeroDao.java
@Override public Integer count(Map<String, String> filter) { Long result = 0L; DetachedCriteria criteria = DetachedCriteria.forClass(Hero.class).setProjection(Projections.rowCount()); if (filter != null) { for (String key : filter.keySet()) { criteria.add(Restrictions.ilike(key, filter.get(key))); }// ww w .j a v a 2s. c o m } List results = ht.findByCriteria(criteria); if (results != null && results.size() > 0) { result = (Long) results.get(0); } return result.intValue(); }
From source file:strat.mining.stratum.proxy.json.JsonRpcRequest.java
protected JsonRpcRequest() { Long nextId = nextRequestId.getAndIncrement(); // Use an integer as id instead of a long when possible. Else, it is // harder to match a response with a request since Jackson will parse // response with Integer when needed, and long if the value overflow an // integer. (Thus, in request maps, Long of the request will never match // with the Integer id of the response, even if values are the same). if (Integer.MAX_VALUE >= nextId) { id = nextId.intValue(); } else {/* w ww . j ava 2 s . c om*/ id = nextId; } }
From source file:mx.edu.um.mateo.inventario.dao.impl.ProductoDaoHibernate.java
@Override @Transactional(readOnly = true)/* w w w. ja v a2s .c om*/ public Map<String, Object> historial(Long id, Map<String, Object> params) { StringBuilder sb = new StringBuilder(); sb.append("select new map("); sb.append("p.actividad as actividad, p.creador as creador "); sb.append(", p.precioUnitario as precioUnitario, p.ultimoPrecio as ultimoPrecio "); sb.append(", p.existencia as existencia "); sb.append(", p.fechaCreacion as fecha "); sb.append(", p.entradaId as entradaId "); sb.append(", p.salidaId as salidaId "); sb.append(", p.cancelacionId as cancelacionId "); sb.append(", (select e.folio from Entrada e where e.id = p.entradaId) as folioEntrada "); sb.append(", (select s.folio from Salida s where s.id = p.salidaId) as folioSalida "); sb.append(", (select c.folio from Cancelacion c where c.id = p.cancelacionId) as folioCancelacion "); sb.append(") from XProducto p where p.productoId = :productoId order by p.id desc"); Query query = currentSession().createQuery(sb.toString()); query.setLong("productoId", id); if (params.containsKey("max")) { Integer max = (Integer) params.get("max"); query.setMaxResults(max); params.put("max", max); } else { query.setMaxResults(10); params.put("max", 10); } if (params.containsKey("pagina")) { Long pagina = (Long) params.get("pagina"); Long offset = (pagina - 1) * (Integer) params.get("max"); params.put("offset", offset.intValue()); } if (params.containsKey("offset")) { Integer offset = (Integer) params.get("offset"); query.setFirstResult(offset); params.put("offset", offset); } else { query.setFirstResult(0); params.put("offset", 0); } params.put("historial", query.list()); sb = new StringBuilder(); sb.append("select count(*) as cantidad from XProducto p where p.productoId = :productoId"); query = currentSession().createQuery(sb.toString()); query.setLong("productoId", id); params.put("cantidad", query.uniqueResult()); return params; }
From source file:com.gisgraphy.domain.valueobject.FeatureCodeTest.java
@Test public void testAllPlaceTypeShouldbeMappedWithHibernate() { Long count = 1L; for (FeatureCode featureCode : FeatureCode.values()) { Object feature = featureCode.getObject(); if (feature instanceof Country) { Country typedFeature = (Country) feature; typedFeature.setIso3166Alpha2Code(RandomStringUtils.random(2)); typedFeature.setIso3166Alpha3Code(RandomStringUtils.random(3)); typedFeature.setIso3166NumericCode(count.intValue()); typedFeature.setFeatureId(count++); typedFeature.setLocation(GeolocHelper.createPoint(1.5F, 3.2F)); typedFeature.setName("name" + count); typedFeature.setSource(GISSource.PERSONAL); gisFeatureDao.save(typedFeature); } else {//from w w w.ja v a2 s .co m GisFeature typedFeature = (GisFeature) feature; typedFeature.setFeatureId(count++); typedFeature.setLocation(GeolocHelper.createPoint(1.5F, 3.2F)); typedFeature.setName("name" + count); typedFeature.setSource(GISSource.PERSONAL); gisFeatureDao.save(typedFeature); } } }
From source file:org.querybyexample.jpa.GenericRepository.java
/** * Count the number of E instances.//w w w .ja v a2 s .c o m * * @param entity a sample entity whose non-null properties may be used as * search hint * @param searchParameters carries additional search information * @return the number of entities matching the search. */ @Transactional(readOnly = true) public int findCount(E entity, SearchParameters sp) { checkNotNull(entity, "The entity cannot be null"); checkNotNull(sp, "The searchParameters cannot be null"); if (sp.hasNamedQuery()) { return byNamedQueryUtil.numberByNamedQuery(sp).intValue(); } CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<Long> criteriaQuery = builder.createQuery(Long.class); Root<E> root = criteriaQuery.from(type); if (sp.getDistinct()) { criteriaQuery = criteriaQuery.select(builder.countDistinct(root)); } else { criteriaQuery = criteriaQuery.select(builder.count(root)); } // predicate Predicate predicate = getPredicate(root, builder, entity, sp); if (predicate != null) { criteriaQuery = criteriaQuery.where(predicate); } orderByUtil.forceJoinOrder(root, sp); TypedQuery<Long> typedQuery = entityManager.createQuery(criteriaQuery); applyCacheHints(typedQuery, sp); Long count = typedQuery.getSingleResult(); if (count != null) { return count.intValue(); } else { log.warn("findCount returned null"); return 0; } }
From source file:ch.ksfx.web.services.chart.ObservationChartGenerator.java
public JFreeChart generateChart(TimeSeries timeSeries, Date startDate, Date endDate) { List<Observation> observations = observationDAO.queryObservationsSparse(timeSeries.getId().intValue(), startDate, endDate);//from w w w . j a va 2s. com if (observations == null || observations.size() == 0 || observations.isEmpty()) { Observation o = observationDAO.getLastObservationForTimeSeriesId(timeSeries.getId().intValue()); Long diffInMillis = endDate.getTime() - startDate.getTime(); startDate = DateUtils.addMilliseconds(o.getObservationTime(), diffInMillis.intValue() * -1); System.out.println("[GRAPH] Found 0 Observations trying new query (" + timeSeries.getId() + ") " + "Startdate: " + startDate.toString() + " End date: " + endDate.toString()); observations = observationDAO.queryObservationsSparse(timeSeries.getId().intValue(), startDate, DateUtils.addMilliseconds(o.getObservationTime(), 1000)); } System.out .println("[GRAPH] Observations size: " + observations.size() + " for (" + timeSeries.getId() + ")"); //assetPrices = simplifyAssetPrices(assetPrices); TimePeriodValues assetPriceTimePeriodValues = new TimePeriodValues(timeSeries.getName()); TimePeriodValuesCollection dataset = new TimePeriodValuesCollection(); for (Observation o : observations) { assetPriceTimePeriodValues.add(new SimpleTimePeriod(o.getObservationTime(), o.getObservationTime()), Double.parseDouble(o.getScalarValue())); } dataset.addSeries(assetPriceTimePeriodValues); JFreeChart jFreeChart = ChartFactory.createXYLineChart("Performance", "Time", "Value", dataset, PlotOrientation.VERTICAL, true, false, false); setRange(jFreeChart, observations); return jFreeChart; }
From source file:com.sfs.ucm.controller.SpecificationAction.java
/** * Add business rule action/*from ww w.ja va 2 s .c o m*/ * * @return outcome */ @TransactionAttribute(TransactionAttributeType.REQUIRED) public void addBusinessRule() { Long cnt = getSpecificationRuleCount(); this.specificationRule = new SpecificationRule(cnt.intValue() + 1); }
From source file:gov.abrs.etms.dao.util.ExecuteDAO.java
public int countRows(Class entityClass) { String countHql = "select count(*) from " + entityClass.getSimpleName(); try {//w ww . ja v a2 s. c o m Long count = findUnique(countHql); return count.intValue(); } catch (Exception e) { throw new RuntimeException("hql can't be auto count, hql is:" + countHql, e); } }
From source file:com.abiquo.server.core.enterprise.RoleLdapDAO.java
public Collection<RoleLdap> find(final String filter, final String orderBy, final boolean desc, final Integer offset, final Integer numResults) { Criteria criteria = createCriteria(filter, orderBy, desc); Long total = count(criteria); criteria = createCriteria(filter, orderBy, desc); criteria.setFirstResult(offset * numResults); criteria.setMaxResults(numResults);/*from w w w . j a va 2s . c om*/ List<RoleLdap> result = getResultList(criteria); PagedList<RoleLdap> page = new PagedList<RoleLdap>(); page.addAll(result); page.setCurrentElement(offset); page.setPageSize(numResults); page.setTotalResults(total.intValue()); return page; }