@Override
  public List<CcAndInferredLocationRecord> getAllLastKnownRecords(
      final Map<CcAndInferredLocationFilter, String> filter) {

    HQLBuilder queryBuilder = new HQLBuilder();
    StringBuilder hql = queryBuilder.from(new StringBuilder(), "CcAndInferredLocationRecord");

    hql =
        addQueryParam(
            queryBuilder,
            hql,
            CcAndInferredLocationFilter.DEPOT_ID,
            filter.get(CcAndInferredLocationFilter.DEPOT_ID));
    hql =
        addQueryParam(
            queryBuilder,
            hql,
            CcAndInferredLocationFilter.INFERRED_ROUTEID,
            filter.get(CcAndInferredLocationFilter.INFERRED_ROUTEID));
    hql =
        addQueryParam(
            queryBuilder,
            hql,
            CcAndInferredLocationFilter.INFERRED_PHASE,
            filter.get(CcAndInferredLocationFilter.INFERRED_PHASE));

    String boundingBox = filter.get(CcAndInferredLocationFilter.BOUNDING_BOX);
    if (StringUtils.isNotBlank(boundingBox)) {
      hql = addBoundingBoxParam(hql);
    }

    hql = queryBuilder.order(hql, "vehicleId", null);

    final StringBuilder hqlQuery = hql;

    List<CcAndInferredLocationRecord> list =
        _template.execute(
            new HibernateCallback<List<CcAndInferredLocationRecord>>() {

              @SuppressWarnings("unchecked")
              @Override
              public List<CcAndInferredLocationRecord> doInHibernate(Session session)
                  throws HibernateException, SQLException {

                Query query = buildQuery(filter, hqlQuery, session);

                _log.debug("Executing query : " + hqlQuery.toString());

                return query.list();
              }
            });

    return list;
  }
Exemplo n.º 2
0
 /* (non-Javadoc)
  * @see org.inbio.m3s.dao.core.StatisticsDAO#allMediaCount()
  */
 public Long allMediaCount() throws IllegalArgumentException {
   HibernateTemplate template = getHibernateTemplate();
   return (Long)
       template.execute(
           new HibernateCallback() {
             public Object doInHibernate(Session session) {
               Query query = session.createQuery("select count(m) from Media m");
               query.setCacheable(true);
               return query.list().get(0);
             }
           });
 }
Exemplo n.º 3
0
 @SuppressWarnings("unchecked")
 @Override
 public void execute(final String hql, final Object... values) {
   hibernateTemplate.execute(
       new HibernateCallback() {
         public Object doInHibernate(Session session) throws HibernateException, SQLException {
           Query q = session.createQuery(hql);
           for (int i = 0; i < values.length; i++) q.setParameter(i, values[i]);
           q.executeUpdate();
           return null;
         }
       });
 }
  protected Object execute(final InternalCallback action) throws StoreException {
    HibernateTemplate template = new HibernateTemplate(getSessionFactory());

    return template.execute(
        new HibernateCallback() {
          public Object doInHibernate(Session session) throws HibernateException, SQLException {
            try {
              return action.doInHibernate(session);
            } catch (StoreException e) {
              throw new RuntimeException(e);
            }
          }
        });
  }
Exemplo n.º 5
0
 /* (non-Javadoc)
  * @see org.inbio.m3s.dao.core.StatisticsDAO#DSCPhotosCount()
  */
 public Long DSCPhotosCount() throws IllegalArgumentException {
   HibernateTemplate template = getHibernateTemplate();
   return (Long)
       template.execute(
           new HibernateCallback() {
             public Object doInHibernate(Session session) {
               Query query =
                   session.createQuery(
                       "select count(m) from Media m where m.mediaTypeId = " + DSC_MEDIA_TYPE_ID);
               query.setCacheable(true);
               return query.list().get(0);
             }
           });
 }
Exemplo n.º 6
0
 /**
  * Returns the total of elements that could be retrived using that search criteria
  *
  * @return number of results
  */
 public Integer getTotalResults(final String HSQL) throws IllegalArgumentException {
   logger.debug("query: " + HSQL);
   HibernateTemplate template = getHibernateTemplate();
   return (Integer)
       template.execute(
           new HibernateCallback() {
             public Object doInHibernate(Session session) {
               Query query = session.createQuery(HSQL);
               query.setCacheable(false);
               logger.debug("result: " + new Integer(query.uniqueResult().toString()));
               return new Integer(query.uniqueResult().toString());
             }
           });
 }
Exemplo n.º 7
0
 public List getGeoRegionsForCountry(final String isoCountryCode) {
   HibernateTemplate template = getHibernateTemplate();
   return (List)
       template.execute(
           new HibernateCallback() {
             public Object doInHibernate(Session session) {
               Query query =
                   session.createQuery(
                       "select id, name from GeoRegion where isoCountryCode=? order by name");
               query.setParameter(0, isoCountryCode);
               query.setCacheable(true);
               return query.list();
             }
           });
 }
Exemplo n.º 8
0
  // 发货级---货源单管理查询总数
  public int orderCheckCount(final String hql, final String companyAccion) {
    @SuppressWarnings("unchecked")
    int i =
        template.execute(
            new HibernateCallback() {

              public Object doInHibernate(Session arg0) throws HibernateException, SQLException {
                // TODO Auto-generated method stub
                Query query = arg0.createQuery(hql);
                query.setParameter(0, companyAccion);
                /*new Integer(query.uniqueResult().toString()).intValue();*/
                return query.list().size();
              }
            });
    return i;
  }
 public int deleteAllByExamination(final Examination examination) {
   HibernateTemplate hibernateTemplate = getHibernateTemplate();
   int result =
       hibernateTemplate.execute(
           new HibernateCallback<Integer>() {
             @Override
             public Integer doInHibernate(Session arg0) throws HibernateException, SQLException {
               String sql =
                   "delete from "
                       + entityBeanType.getSimpleName()
                       + " where examination_id=:examination_id";
               SQLQuery query = arg0.createSQLQuery(sql);
               query.setLong("examination_id", examination.getId());
               return query.executeUpdate();
             }
           });
   return result;
 }
 public double sumByExamination(final Examination examination) {
   HibernateTemplate hibernateTemplate = getHibernateTemplate();
   double result =
       hibernateTemplate.execute(
           new HibernateCallback<Double>() {
             @Override
             public Double doInHibernate(Session session) throws HibernateException, SQLException {
               String sql =
                   "select sum(exd.medicine.price) from "
                       + entityBeanType.getSimpleName()
                       + " exd where exd.examination=:examination";
               Query query = session.createQuery(sql);
               query.setEntity("examination", examination);
               return (Double) query.list().get(0);
             }
           });
   return result;
 }
Exemplo n.º 11
0
  /**
   * @param searchCriteria
   * @param first
   * @param last
   * @return
   */
  @SuppressWarnings("unchecked")
  public List<Integer> getResults(final String HSQL, final int first, final int last)
      throws IllegalArgumentException {

    logger.debug("query getResults: " + HSQL);
    HibernateTemplate template = getHibernateTemplate();
    return (List<Integer>)
        template.execute(
            new HibernateCallback() {
              public Object doInHibernate(Session session) {
                Query query = session.createQuery(HSQL);
                // query.setParameter(0, nomenclaturalGroupId);
                query.setCacheable(false);
                query.setFirstResult(first - 1);
                query.setMaxResults(last - (first - 1));
                return query.list();
              }
            });
  }
Exemplo n.º 12
0
 @SuppressWarnings("unchecked")
 public List<Media> getLastPublicMedia(final int quantity) throws IllegalArgumentException {
   logger.debug("getting last public media in the DB");
   HibernateTemplate template = getHibernateTemplate();
   return (List<Media>)
       template.execute(
           new HibernateCallback() {
             public Object doInHibernate(Session session) {
               Query query =
                   session.createQuery(
                       "select m from Media as m"
                           + " where m.isPublic = 'Y'"
                           + " order by m.mediaId desc");
               query.setCacheable(true);
               query.setFirstResult(0);
               query.setMaxResults(quantity);
               return query.list();
             }
           });
 }
Exemplo n.º 13
0
  private static DataServiceMetaData initMetaData(
      String configurationName,
      Configuration cfg,
      HibernateTemplate htemp,
      final boolean useIndividualCRUDOperations,
      final Map<String, String> properties) {
    final DataServiceMetaData rtn =
        new DataServiceMetaData_Hib(configurationName, cfg, properties); // salesforce

    htemp.execute(
        new HibernateCallback() {

          @Override
          public Object doInHibernate(Session session) {
            rtn.init(session, useIndividualCRUDOperations);
            return null;
          }
        });

    return rtn;
  }