Пример #1
0
 @Transactional(readOnly = true)
 public int buildAll() {
   int buildCount = 0;
   for (int i = 0; i < articleDao.count(); i += 20) {
     List<Article> articles = articleDao.findList(i, 20, null, null);
     for (Article article : articles) {
       buildCount += build(article);
     }
     articleDao.clear();
   }
   for (int i = 0; i < productDao.count(); i += 20) {
     List<Product> products = productDao.findList(i, 20, null, null);
     for (Product product : products) {
       buildCount += build(product);
     }
     productDao.clear();
   }
   buildIndex();
   buildSitemap();
   buildOther();
   return buildCount;
 }
Пример #2
0
 @Transactional(readOnly = true)
 public int buildSitemap() {
   int buildCount = 0;
   Template sitemapIndexTemplate = templateService.get("sitemapIndex");
   Template sitemapTemplate = templateService.get("sitemap");
   Map<String, Object> model = new HashMap<String, Object>();
   List<String> staticPaths = new ArrayList<String>();
   for (int step = 0, index = 0, first = 0, count = SITEMAP_MAX_SIZE; ; ) {
     try {
       model.put("index", index);
       String templatePath = sitemapTemplate.getTemplatePath();
       String staticPath = FreemarkerUtils.process(sitemapTemplate.getStaticPath(), model);
       if (step == 0) {
         List<Article> articles = articleDao.findList(first, count, null, null);
         model.put("articles", articles);
         if (articles.size() < count) {
           step++;
           first = 0;
           count -= articles.size();
         } else {
           buildCount += build(templatePath, staticPath, model);
           articleDao.clear();
           articleDao.flush();
           staticPaths.add(staticPath);
           model.clear();
           index++;
           first += articles.size();
           count = SITEMAP_MAX_SIZE;
         }
       } else if (step == 1) {
         List<Product> products = productDao.findList(first, count, null, null);
         model.put("products", products);
         if (products.size() < count) {
           step++;
           first = 0;
           count -= products.size();
         } else {
           buildCount += build(templatePath, staticPath, model);
           productDao.clear();
           productDao.flush();
           staticPaths.add(staticPath);
           model.clear();
           index++;
           first += products.size();
           count = SITEMAP_MAX_SIZE;
         }
       } else if (step == 2) {
         List<Brand> brands = brandDao.findList(first, count, null, null);
         model.put("brands", brands);
         if (brands.size() < count) {
           step++;
           first = 0;
           count -= brands.size();
         } else {
           buildCount += build(templatePath, staticPath, model);
           brandDao.clear();
           brandDao.flush();
           staticPaths.add(staticPath);
           model.clear();
           index++;
           first += brands.size();
           count = SITEMAP_MAX_SIZE;
         }
       } else if (step == 3) {
         List<Promotion> promotions = promotionDao.findList(first, count, null, null);
         model.put("promotions", promotions);
         buildCount += build(templatePath, staticPath, model);
         promotionDao.clear();
         promotionDao.flush();
         staticPaths.add(staticPath);
         if (promotions.size() < count) {
           model.put("staticPaths", staticPaths);
           buildCount +=
               build(
                   sitemapIndexTemplate.getTemplatePath(),
                   sitemapIndexTemplate.getStaticPath(),
                   model);
           break;
         } else {
           model.clear();
           index++;
           first += promotions.size();
           count = SITEMAP_MAX_SIZE;
         }
       }
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
   return buildCount;
 }