Package com.db4o.query

Examples of com.db4o.query.Query


        default: throw new DuplicateMessageException("index: " + index);
      }
    }
   
    public final synchronized int getDownloadedMessageCount() {
      final Query query = mDB.query();
      query.constrain(DownloadedMessageLink.class);
      query.descend("mBoard").constrain(this).identity();
      return query.execute().size();
    }
View Full Code Here


  }
 
  @SuppressWarnings("unchecked")
  public void testOnMessageListFetchFailed() {
    WoTOwnIdentity author = mOwnIdentities[0];
    Query q;
    ObjectSet<FetchFailedMarker> markers;
    ObjectSet<MessageList> messageLists;
    MessageListFetchFailedMarker marker;
   
    q = db.query();
    q.constrain(FetchFailedMarker.class);
    assertEquals(0, q.execute().size());
   
    q = db.query();
    q.constrain(MessageList.class);
    assertEquals(0, q.execute().size());
   
    mMessageManager.onMessageListFetchFailed(author, WoTMessageList.assembleURI(author.getRequestURI(), 1), FetchFailedMarker.Reason.DataNotFound);
   
    q = db.query();
    q.constrain(FetchFailedMarker.class);
    assertEquals(1, q.execute().size());
   
    mMessageManager.clearExpiredFetchFailedMarkers();
   
    q = db.query();
    q.constrain(FetchFailedMarker.class);
    markers = q.execute();
    assertEquals(1, markers.size());
   
    marker = (MessageListFetchFailedMarker)markers.next();
   
    assertTrue((CurrentTimeUTC.getInMillis() - marker.getDate().getTime()) < 10 * 1000);
    assertEquals(marker.getDate().getTime() + MessageManager.MINIMAL_MESSAGELIST_FETCH_RETRY_DELAY, marker.getDateOfNextRetry().getTime());
    assertEquals(false, marker.isRetryAllowedNow());
   
    q = db.query();
    q.constrain(MessageList.class);
    messageLists = q.execute();
    assertEquals(1, messageLists.size());
    assertEquals(messageLists.next().getID(), marker.getMessageListID());
   
    // Now we simulate a retry of the message list fetch
   
    marker.setDateOfNextRetry(marker.getDate());
    marker.setAllowRetryNow(false); // Needed for clearExpiredFetchFailedMarkers to process the marker
    marker.storeWithoutCommit();
    Persistent.checkedCommit(db, this);
       
    mMessageManager.clearExpiredFetchFailedMarkers();
   
    q = db.query();
    q.constrain(FetchFailedMarker.class);
    markers = q.execute();
    assertEquals(1, markers.size());
    assertEquals(marker, markers.next());
   
    q = db.query();
    q.constrain(MessageList.class);
    messageLists = q.execute();
    assertEquals(0, messageLists.size());
   
    mMessageManager.onMessageListFetchFailed(author, WoTMessageList.assembleURI(author.getRequestURI(), 1), FetchFailedMarker.Reason.DataNotFound);
   
    q = db.query();
    q.constrain(FetchFailedMarker.class);
    markers = q.execute();
    assertEquals(1, markers.size());
    assertEquals(marker, markers.next());
    assertTrue((CurrentTimeUTC.getInMillis() - marker.getDate().getTime()) < 10 * 1000);
    assertEquals(marker.getDate().getTime() + Math.min(MessageManager.MINIMAL_MESSAGELIST_FETCH_RETRY_DELAY*2, MessageManager.MAXIMAL_MESSAGELIST_FETCH_RETRY_DELAY),
          marker.getDateOfNextRetry().getTime());
    assertEquals(1, marker.getNumberOfRetries());
    assertEquals(false, marker.isRetryAllowedNow());
   
    q = db.query();
    q.constrain(MessageList.class);
    messageLists = q.execute();
    assertEquals(1, messageLists.size());
    assertEquals(messageLists.next().getID(), marker.getMessageListID());
   
    // Simulate failure with existing marker and existing ghost message list, i.e. the message list fetcher tried to fetch even though it shouldn't.
   
    mMessageManager.onMessageListFetchFailed(author, WoTMessageList.assembleURI(author.getRequestURI(), 1), FetchFailedMarker.Reason.DataNotFound);
   
    q = db.query();
    q.constrain(FetchFailedMarker.class);
    markers = q.execute();
    assertEquals(1, markers.size());
    assertEquals(marker, markers.next());
   
    q = db.query();
    q.constrain(MessageList.class);
    messageLists = q.execute();
    assertEquals(1, messageLists.size());
    assertEquals(messageLists.next().getID(), marker.getMessageListID());
  }
View Full Code Here

    return postMessage(myParentThreadURI, myParentMessage, boardSet, replyToBoard, myAuthor, myTitle, myDate, myText, myAttachments);
  }
 
  @SuppressWarnings("unchecked")
  public synchronized int countUnsentMessages() {
    Query q = db.query();
    q.constrain(OwnMessage.class);
    q.descend("mFreenetURI").constrain(null).identity();
    int unsentCount = 0;
   
    for(OwnMessage m : new Persistent.InitializingObjectSet<OwnMessage>(mFreetalk, q)) {
      // TODO: Remove this workaround for the db4o bug as soon as we are sure that it does not happen anymore.
      if(!m.testFreenetURIisNull()) // Logs an error for us
        continue;
   
      ++unsentCount;
    }
   
    q = db.query();
    q.constrain(OwnMessageList.class);
    q.descend("mWasInserted").constrain(false);
    ObjectSet<OwnMessageList> notInsertedLists = new Persistent.InitializingObjectSet<OwnMessageList>(mFreetalk, q);
    for(OwnMessageList list : notInsertedLists)
      unsentCount += list.getMessageCount();
   
    return unsentCount;
View Full Code Here

 
  /**
   * You have to synchronize on this MessageManager and on Persistent.transactionLock(db) when using this function.
   */
  private void addMessageToMessageList(WoTOwnMessage message) {
    Query query = db.query();
    query.constrain(WoTOwnMessageList.class);
    query.descend("mAuthor").constrain(message.getAuthor()).identity();
    query.descend("mWasInserted").constrain(false);
    query.descend("mIsBeingInserted").constrain(false);
   
    for(WoTOwnMessageList list : new Persistent.InitializingObjectSet<WoTOwnMessageList>(mFreetalk, query)) {
      try {
        synchronized(list) {
        list.addMessage(message);
View Full Code Here

  /**
   * ATTENTION: Due to a db4o bug you must check whether the messages are really not inserted by using testFreenetURIisNull() on them
   * TODO: Remove this workaround notice for the db4o bug as soon as we are sure that it does not happen anymore.
   */
  public synchronized ObjectSet<WoTOwnMessage> getNotInsertedOwnMessages() {
    final Query query = db.query();
    query.constrain(WoTOwnMessage.class);
    query.descend("mFreenetURI").constrain(null).identity();
    return new Persistent.InitializingObjectSet<WoTOwnMessage>(mFreetalk, query);
  }
View Full Code Here

  /**
   * Returns <code>OwnMessageList</code> objects which are marked as not inserted and not being inserted.
   */
  public synchronized ObjectSet<WoTOwnMessageList> getNotInsertedOwnMessageLists() {
    Query query = db.query();
    query.constrain(WoTOwnMessageList.class);
    query.descend("mWasInserted").constrain(false);
    query.descend("mIsBeingInserted").constrain(false);
    return new Persistent.InitializingObjectSet<WoTOwnMessageList>(mFreetalk, query);
  }
View Full Code Here

    query.descend("mIsBeingInserted").constrain(false);
    return new Persistent.InitializingObjectSet<WoTOwnMessageList>(mFreetalk, query);
  }
 
  public synchronized ObjectSet<WoTOwnMessageList> getBeingInsertedOwnMessageLists() {
    Query query = db.query();
    query.constrain(WoTOwnMessageList.class);
    query.descend("mWasInserted").constrain(false);
    query.descend("mIsBeingInserted").constrain(true);
    return new Persistent.InitializingObjectSet<WoTOwnMessageList>(mFreetalk, query);
  }
View Full Code Here

   * function does not provide synchronization.
   */
  public long getFreeOwnMessageListIndex(final WoTOwnIdentity messageAuthor)  {
    // We do not use IdentityStatistics since it does not guarantee to return the highest existing list, it just guarantees that
    // the index after the one which it has returned does not exist. We must of course not re-use own message list indices.
    final Query q = db.query();
    // We query for MessageList and not OwnMessageList because the user might have deleted his own messages or lost his database
    q.constrain(MessageList.class);
    q.descend("mAuthor").constrain(messageAuthor).identity();
    q.descend("mIndex").orderDescending(); // TODO: This is inefficient!
    final ObjectSet<MessageList> result = new Persistent.InitializingObjectSet<MessageList>(mFreetalk, q);
   
    // We must look for the latest message list which was not marked as fetch failed and return its index + 1
    // Further, if a list is marked as fetch failed but the reason is NOT data not found, we must return its index + 1; explanation:
    // There are 2 things which could go wrong here:
View Full Code Here

      throw new IllegalArgumentException("No WoT identity: " + rater);
   
    if(!(message instanceof WoTMessage))
      throw new IllegalArgumentException("No WoT message: " + message);
   
    final Query query = db.query();
    query.constrain(WoTMessageRating.class);
    query.descend("mRater").constrain(rater).identity();
    query.descend("mMessage").constrain(message).identity();
    final InitializingObjectSet<WoTMessageRating> result = new Persistent.InitializingObjectSet<WoTMessageRating>(mFreetalk, query);
   
    switch(result.size()) {
      case 0: throw new NoSuchMessageRatingException();
      case 1: return result.next();
View Full Code Here

      default: throw new DuplicateElementException("Duplicate rating from " + rater + " of " + message);
    }
  }
 
  public ObjectSet<WoTMessageRating> getAllMessageRatings(final Message message) {
    final Query query = db.query();
    query.constrain(WoTMessageRating.class);
    query.descend("mMessage").constrain(message).identity();
    return new Persistent.InitializingObjectSet<WoTMessageRating>(mFreetalk, query);
  }
View Full Code Here

TOP

Related Classes of com.db4o.query.Query

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.