Пример #1
0
  @Override
  public void addTrend(String name, Kwet kwet) {
    Query q = em.createQuery("select trend from Trends trend where trend.name = :name ");
    q.setParameter("name", name);
    List<Trend> trends = q.getResultList();
    Trend trend = null;

    if (trends.isEmpty()) {
      trend = new Trend(name);
      em.persist(trend);

      trend.addKwet(kwet);
      kwet.addTrend(trend);

      em.merge(trend);
      em.merge(kwet);
    } else {
      trend = trends.get(0);
      if (!trend.getKwets().contains(kwet)) {
        trend.addKwet(kwet);
        kwet.addTrend(trend);

        em.merge(trend);
        em.merge(kwet);
      }
    }
  }
Пример #2
0
  @Override
  public void addTrends(@Observes @ProcessKwet KwetEvent event) {
    this.em.getEntityManagerFactory().getCache().evictAll();
    Kwet kwet = event.kwet;
    String[] split = kwet.getBody().split(" ");
    for (String s : split) {
      if (s.length() > 1 && s.charAt(0) == "#".charAt(0)) {
        this.addTrend(s, kwet);
      }
    }

    em.merge(kwet);
  }