public static List<Town> getTownByProvinceFromCache(String provinceCode) {

    Cache cache = CacheItemManager.getCache(CacheName.DB_CACHE_TOWN);

    Attribute<String> provcode = cache.getSearchAttribute("prov_code");

    Query query = cache.createQuery().includeValues().addCriteria(provcode.eq(provinceCode));
    Results results = query.execute();
    List<Result> rs = results.all();

    if (rs == null || rs.size() <= 0) {

      return null;
    }

    int size = rs.size();
    List<Town> list = new ArrayList<Town>();

    for (int i = 0; i < size; ++i) {

      list.add((Town) rs.get(i).getValue());
    }

    results.discard();

    return list;
  }
示例#2
0
  public String anlikOturumSayisiHesapla(boolean detayli) {
    try {
      Attribute<String> oturumZamanAraligiAtt =
          getStatisticCache().getSearchAttribute("oturumZamanAraligi");
      GregorianCalendar gcal = new GregorianCalendar();
      int minute = gcal.get(GregorianCalendar.MINUTE);
      int hour = gcal.get(GregorianCalendar.HOUR_OF_DAY);
      String firstInterval = "" + ((hour * 6) + (minute / 10));
      int fourthRatio = (10 - (minute % 10)) * 10;
      gcal.add(GregorianCalendar.MINUTE, -10);
      minute = gcal.get(GregorianCalendar.MINUTE);
      hour = gcal.get(GregorianCalendar.HOUR_OF_DAY);
      String secondInterval = "" + ((hour * 6) + (minute / 10));
      gcal.add(GregorianCalendar.MINUTE, -10);
      minute = gcal.get(GregorianCalendar.MINUTE);
      hour = gcal.get(GregorianCalendar.HOUR_OF_DAY);
      String thirdInterval = "" + ((hour * 6) + (minute / 10));
      gcal.add(GregorianCalendar.MINUTE, -10);
      minute = gcal.get(GregorianCalendar.MINUTE);
      hour = gcal.get(GregorianCalendar.HOUR_OF_DAY);
      String fourthInterval = "" + ((hour * 6) + (minute / 10));

      Query query = null;
      if (detayli)
        query =
            getStatisticCache()
                .createQuery()
                .includeKeys()
                .includeValues()
                .addCriteria(
                    new Or(
                            oturumZamanAraligiAtt.eq(firstInterval),
                            oturumZamanAraligiAtt.eq(secondInterval))
                        .or(oturumZamanAraligiAtt.eq(thirdInterval))
                        .or(oturumZamanAraligiAtt.eq(fourthInterval)));
      else
        query =
            getStatisticCache()
                .createQuery()
                .includeValues()
                .addCriteria(
                    new Or(
                            oturumZamanAraligiAtt.eq(firstInterval),
                            oturumZamanAraligiAtt.eq(secondInterval))
                        .or(oturumZamanAraligiAtt.eq(thirdInterval))
                        .or(oturumZamanAraligiAtt.eq(fourthInterval)));

      Results resultElement = query.execute();
      int toplamOturumSayisi = 0;
      String denemeMesaj = "";
      if (resultElement.hasValues()) {
        List<Result> resultList = resultElement.all();

        for (Result result : resultList) {
          OturumStatistic obj = (OturumStatistic) result.getValue();
          if (detayli) {
            denemeMesaj +=
                "Key : "
                    + result.getKey()
                    + "   ZAMANA ARALIĞI : "
                    + obj.getOturumZamanAraligi()
                    + "  OTURUM SAYISI : "
                    + obj.getOturumSayisi()
                    + "<br />";
            denemeMesaj += "-----------------------<br />";
          }
          if (obj.getOturumZamanAraligi().equals(fourthInterval)) {
            toplamOturumSayisi += ((obj.getOturumSayisi() * fourthRatio) / 100);
          } else {
            toplamOturumSayisi += obj.getOturumSayisi();
          }
        }

        if (detayli) denemeMesaj += "  TOPLAM OTURUM SAYISI : " + toplamOturumSayisi;
        else denemeMesaj = "" + toplamOturumSayisi;

        return denemeMesaj;

      } else return "-1";

    } catch (SearchException e) {
    }

    return "-1";
  }