public static List<Province> getAllProvinceFromCache() {

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

    Attribute<Integer> id = cache.getSearchAttribute("id");

    Query query = cache.createQuery().includeValues().addCriteria(id.notNull());

    Results results = query.execute();
    List<Result> rs = results.all();

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

      return null;
    }

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

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

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

    results.discard();

    return list;
  }
  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;
  }
  public static List<AreaView> getAllAreaFromCache() {

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

    Attribute<String> areacode =
        cache.getSearchAttribute(SearchAttributeName.DBCACHE_AREA_AREACODE);

    Query query =
        cache
            .createQuery()
            .includeAttribute(areacode)
            .includeValues()
            .addCriteria(areacode.notNull())
            .addOrderBy(areacode, Direction.ASCENDING);
    Results results = query.execute();

    List<Result> rs = results.all();

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

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

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

      list.add((AreaView) rs.get(i).getValue());
    }
    results.discard();
    return list;
  }
  public static List<Province> getProvinceByAearFromCache(String[] areacodes) {

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

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

    Query query =
        cache
            .createQuery()
            .includeValues()
            .addCriteria(provarea.in(Arrays.asList(areacodes)))
            .addOrderBy(provcode, Direction.ASCENDING);

    Results results = query.execute();
    List<Result> rs = results.all();

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

      return null;
    }

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

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

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

    results.discard();

    return list;
  }
Beispiel #5
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";
  }