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<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<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<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;
  }
  /**
   * 判断Cache中是否有数据
   *
   * @param cache
   * @return
   */
  public static boolean hasData(String cacheName) {

    Cache cache = CacheItemManager.getCache(cacheName);

    if (cache.getKeys() == null || cache.getKeys().size() <= 0) {
      return false;
    }

    return true;
  }