Package org.rssowl.core.persist.event.runnable

Examples of org.rssowl.core.persist.event.runnable.NewsEventRunnable


        fDb.ext().store(o, 2);
      } else
        fDb.ext().store(o, 1);
    }

    NewsEventRunnable eventRunnables = DBHelper.getNewsEventRunnables(EventsMap.getInstance().getEventRunnables());
    if (eventRunnables != null) {
      for (NewsEvent event : eventRunnables.getAllEvents())
        descriptionUpdatedIds.removeByElement(event.getEntity().getId().longValue());
    }

    INewsDAO newsDao = DynamicDAO.getDAO(INewsDAO.class);
    for (int i = 0, c = descriptionUpdatedIds.size(); i < c; ++i) {
View Full Code Here


    return (INews) super.getEntity();
  }

  @Override
  public NewsEventRunnable createEventRunnable() {
    return new NewsEventRunnable();
  }
View Full Code Here

  @SuppressWarnings("unused")
  private void asyncSetState(final Collection<INews> news, final State state, final boolean affectEquivalentNews, final boolean force) throws PersistenceException {
    if (news.isEmpty())
      return;
    final NewsEventRunnable eventRunnable = new NewsEventRunnable();;
    final Lock setStateLock = new ReentrantLock();
    setStateLock.lock();
    final Condition condition = setStateLock.newCondition();
    fExecutorService.execute(new Runnable() {
      public void run() {
        Set<INews> changedNews = null;
        try {
          fWriteLock.lock();
          setStateLock.lock();

          if (affectEquivalentNews) {
            /*
             * Give extra 25% size to take into account news that have same guid or
             * link.
             */
            int capacity = news.size() + (news.size() / 4);
            changedNews = new HashSet<INews>(capacity);
            for (INews newsItem : news) {
              if (newsItem.getId() == null)
                throw new IllegalArgumentException("newsItem was never saved to the database"); //$NON-NLS-1$

              List<INews> equivalentNews;

              if (newsItem.getGuid() != null) {
                equivalentNews = getNewsFromGuid(newsItem, true);
                if (equivalentNews.isEmpty()) {
                  throw createIllegalException("No news were found with guid: " + //$NON-NLS-1$
                      newsItem.getGuid().getValue(), newsItem);
                }
              } else if (newsItem.getLinkAsText() != null) {
                equivalentNews = getNewsFromLink(newsItem, true);
                if (equivalentNews.isEmpty()) {
                  throw createIllegalException("No news were found with link: " + //$NON-NLS-1$
                      newsItem.getLinkAsText(), newsItem);
                }
              } else
                equivalentNews = Collections.singletonList(newsItem);

              changedNews.addAll(setState(equivalentNews, state, force));
            }
          } else {
            changedNews = setState(news, state, force);
          }
          for (INews changedNewsItem : changedNews) {
            //TODO Investigate why we add the news twice to the event runnable
            //(we do the same in the finally block). This is harmless but
            //wasteful. Also we should not release the news locks before firing
            //the events.
            ((News) changedNewsItem).acquireReadLockSpecial();
            eventRunnable.addCheckedUpdateEvent(createSaveEventTemplate(changedNewsItem));
          }
          condition.signal();
          setStateLock.unlock();
          save(changedNews);
          fDb.commit();
        } catch (Db4oException e) {
          throw new PersistenceException(e);
        } finally {
          if (changedNews != null) {
            for (INews changedNewsItem : changedNews) {
              ((News) changedNewsItem).releaseReadLockSpecial();
              eventRunnable.addCheckedUpdateEvent(createSaveEventTemplate(changedNewsItem));
            }
          }
          DBHelper.cleanUpEvents();
          fWriteLock.unlock();
        }
      }
    });
    try {
      condition.awaitUninterruptibly();
    } finally {
      setStateLock.unlock();
    }
    eventRunnable.run();
  }
View Full Code Here

    }
    return null;
  }

  private static void updateNewsToBeIndexed(ObjectContainer db) {
    NewsEventRunnable newsEventRunnables = getNewsEventRunnables(EventsMap.getInstance().getEventRunnables());
    if (newsEventRunnables == null)
      return;

    EntitiesToBeIndexedDAOImpl dao = getEntitiesToBeIndexedDAO();
    EntityIdsByEventType newsToBeIndexed = dao.load();
    Set<NewsEvent> updateEvents = new HashSet<NewsEvent>(newsEventRunnables.getUpdateEvents().size());
    Set<NewsEvent> deleteEvents = new HashSet<NewsEvent>(newsEventRunnables.getRemoveEvents());
    Set<NewsEvent> persistEvents = filterPersistedNewsForIndexing(newsEventRunnables.getPersistEvents());
    for (NewsEvent event : newsEventRunnables.getUpdateEvents())
      indexTypeForNewsUpdate(event, persistEvents, updateEvents, deleteEvents);

    NewsEventRunnable copy = new NewsEventRunnable();
    for (NewsEvent persistEvent : persistEvents)
      copy.addCheckedPersistEvent(persistEvent);
    for (NewsEvent updateEvent : updateEvents)
      copy.addCheckedUpdateEvent(updateEvent);
    for (NewsEvent deleteEvent : deleteEvents)
      copy.addCheckedRemoveEvent(deleteEvent);

    newsToBeIndexed.addAllEntities(copy.getPersistEvents(), copy.getUpdateEvents(), copy.getRemoveEvents());
    newsToBeIndexed.compact();
    db.ext().store(newsToBeIndexed, Integer.MAX_VALUE);
  }
View Full Code Here

    }
    return null;
  }

  private static void updateNewsBins(ObjectContainer db) {
    NewsEventRunnable newsEventRunnable = getNewsEventRunnables(EventsMap.getInstance().getEventRunnables());

    if (newsEventRunnable == null)
      return;

    Map<Long, List<StatesUpdateInfo>> statesUpdateInfos = new HashMap<Long, List<StatesUpdateInfo>>(5);
    for (NewsEvent newsEvent : newsEventRunnable.getUpdateEvents()) {
      INews news = newsEvent.getEntity();
      if (news.getParentId() != 0 && (newsEvent.getOldNews().getState() != news.getState())) {
        List<StatesUpdateInfo> list = statesUpdateInfos.get(news.getParentId());
        if (list == null) {
          list = new ArrayList<StatesUpdateInfo>();
          statesUpdateInfos.put(news.getParentId(), list);
        }
        list.add(new StatesUpdateInfo(newsEvent.getOldNews().getState(), news.getState(), news.toReference()));
      }
    }
    for (NewsEvent newsEvent : newsEventRunnable.getPersistEvents()) {
      INews news = newsEvent.getEntity();
      if (news.getParentId() != 0) {
        List<StatesUpdateInfo> list = statesUpdateInfos.get(news.getParentId());
        if (list == null) {
          list = new ArrayList<StatesUpdateInfo>();
View Full Code Here

  }

  public static void updateNewsCounter(ObjectContainer db) {
    List<EventRunnable<?>> eventRunnables = EventsMap.getInstance().getEventRunnables();
    NewsCounterService newsCounterService = new NewsCounterService(Owl.getPersistenceService().getDAOService().getNewsCounterDAO(), db);
    NewsEventRunnable newsEventRunnable = getNewsEventRunnables(eventRunnables);
    if (newsEventRunnable != null) {
      newsCounterService.onNewsAdded(newsEventRunnable.getPersistEvents());
      newsCounterService.onNewsRemoved((newsEventRunnable.getRemoveEvents()));
      newsCounterService.onNewsUpdated(newsEventRunnable.getUpdateEvents());
    }
    for (EventRunnable<?> eventRunnable : eventRunnables) {
      if (eventRunnable instanceof FeedEventRunnable) {
        FeedEventRunnable feedEventRunnable = (FeedEventRunnable) eventRunnable;
        newsCounterService.onFeedRemoved(feedEventRunnable.getRemoveEvents());
View Full Code Here

  /*
   * @see org.rssowl.core.persist.event.ModelEvent#createEventRunnable()
   */
  @Override
  public NewsEventRunnable createEventRunnable() {
    return new NewsEventRunnable();
  }
View Full Code Here

    return null;
  }

  private static void updateNewsToBeIndexed(ObjectContainer db) {
    NewsEventRunnable newsEventRunnables = getNewsEventRunnables(EventsMap.getInstance().getEventRunnables());
    if (newsEventRunnables == null)
      return;

    EntitiesToBeIndexedDAOImpl dao = getEntitiesToBeIndexedDAO();
    EntityIdsByEventType newsToBeIndexed = dao.load();
    Set<NewsEvent> updateEvents = new HashSet<NewsEvent>(newsEventRunnables.getUpdateEvents().size());
    Set<NewsEvent> deleteEvents = new HashSet<NewsEvent>(newsEventRunnables.getRemoveEvents());
    Set<NewsEvent> persistEvents = filterPersistedNewsForIndexing(newsEventRunnables.getPersistEvents());
    for (NewsEvent event : newsEventRunnables.getUpdateEvents())
      indexTypeForNewsUpdate(event, persistEvents, updateEvents, deleteEvents);

    NewsEventRunnable copy = new NewsEventRunnable();
    for (NewsEvent persistEvent : persistEvents)
      copy.addCheckedPersistEvent(persistEvent);
    for (NewsEvent updateEvent : updateEvents)
      copy.addCheckedUpdateEvent(updateEvent);
    for (NewsEvent deleteEvent : deleteEvents)
      copy.addCheckedRemoveEvent(deleteEvent);

    newsToBeIndexed.addAllEntities(copy.getPersistEvents(), copy.getUpdateEvents(), copy.getRemoveEvents());
    newsToBeIndexed.compact();
    db.ext().set(newsToBeIndexed, Integer.MAX_VALUE);
  }
View Full Code Here

    return null;
  }

  private static void updateNewsBins(ObjectContainer db) {
    NewsEventRunnable newsEventRunnable = getNewsEventRunnables(EventsMap.getInstance().getEventRunnables());
    if (newsEventRunnable == null)
      return;

    Map<Long, List<StatesUpdateInfo>> statesUpdateInfos = new HashMap<Long, List<StatesUpdateInfo>>(5);
    for (NewsEvent newsEvent : newsEventRunnable.getUpdateEvents()) {
      INews news = newsEvent.getEntity();
      if (news.getParentId() != 0 && (newsEvent.getOldNews().getState() != news.getState())) {
        List<StatesUpdateInfo> list = statesUpdateInfos.get(news.getParentId());
        if (list == null) {
          list = new ArrayList<StatesUpdateInfo>();
          statesUpdateInfos.put(news.getParentId(), list);
        }
        list.add(new StatesUpdateInfo(newsEvent.getOldNews().getState(), news.getState(), news.toReference()));
      }
    }

    for (NewsEvent newsEvent : newsEventRunnable.getPersistEvents()) {
      INews news = newsEvent.getEntity();
      if (news.getParentId() != 0) {
        List<StatesUpdateInfo> list = statesUpdateInfos.get(news.getParentId());
        if (list == null) {
          list = new ArrayList<StatesUpdateInfo>();
View Full Code Here

  }

  public static void updateNewsCounter(ObjectContainer db) {
    List<EventRunnable<?>> eventRunnables = EventsMap.getInstance().getEventRunnables();
    NewsCounterService newsCounterService = new NewsCounterService(Owl.getPersistenceService().getDAOService().getNewsCounterDAO(), db);
    NewsEventRunnable newsEventRunnable = getNewsEventRunnables(eventRunnables);
    if (newsEventRunnable != null) {
      newsCounterService.onNewsAdded(newsEventRunnable.getPersistEvents());
      newsCounterService.onNewsRemoved((newsEventRunnable.getRemoveEvents()));
      newsCounterService.onNewsUpdated(newsEventRunnable.getUpdateEvents());
    }
    for (EventRunnable<?> eventRunnable : eventRunnables) {
      if (eventRunnable instanceof FeedEventRunnable) {
        FeedEventRunnable feedEventRunnable = (FeedEventRunnable) eventRunnable;
        newsCounterService.onFeedRemoved(feedEventRunnable.getRemoveEvents());
View Full Code Here

TOP

Related Classes of org.rssowl.core.persist.event.runnable.NewsEventRunnable

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.