Package com.db4o.query

Examples of com.db4o.query.Query


    }
  }

  @SuppressWarnings("unchecked")
  private List<INews> getNewsFromLink(INews newsItem) {
    Query query = fDb.query();
    query.constrain(News.class);
    query.descend("fLinkText").constrain(newsItem.getLink().toString()); //$NON-NLS-1$
    return activateAll(query.execute());
  }
View Full Code Here


    return activateAll(query.execute());
  }

  @SuppressWarnings("unchecked")
  private List<INews> getNewsFromGuid(INews newsItem) {
    Query query = fDb.query();
    query.constrain(News.class);
    query.descend("fGuidValue").constrain(newsItem.getGuid().getValue()); //$NON-NLS-1$
    return activateAll(query.execute());
  }
View Full Code Here

    INews newsCopy = fTypesFactory.createNews(news, newsBin);
    DynamicDAO.save(newsCopy);
    DynamicDAO.save(newsBin);

    Query query = fDb.query();
    query.constrain(News.class);
    query.descend("fParentId").constrain(0).not();
    List<?> newsCopies = query.execute();
    assertEquals(1, newsCopies.size());
    assertEquals(newsCopy, newsCopies.get(0));

    query = fDb.query();
    query.constrain(News.class);
    query.descend("fParentId").constrain(0);
    List<?> newsList = query.execute();
    assertEquals(1, newsList.size());
    assertEquals(news, newsList.get(0));

    query = fDb.query();
    query.constrain(News.class);
    query.descend("fGuidValue").constrain(news.getGuid().getValue());
    query.descend("fParentId").constrain(0).not();
    newsCopies = query.execute();
    assertEquals(1, newsCopies.size());
    assertEquals(newsCopy, newsCopies.get(0));

    query = fDb.query();
    query.constrain(News.class);
    query.descend("fGuidValue").constrain(news.getGuid().getValue());
    query.descend("fParentId").constrain(0);
    newsList = query.execute();
    assertEquals(1, newsList.size());
    assertEquals(news, newsList.get(0));
  }
View Full Code Here

    /* Assert Number of Entities */
    List<IEntity> entities = db.query(IEntity.class);
    assertEquals(entities.size(), defragmentedDb.query(IEntity.class).size());
    for (IEntity entity : entities) {
      Query query = defragmentedDb.query();
      query.constrain(entity.getClass());
      query.descend("fId").constrain(Long.valueOf(entity.getId())); //$NON-NLS-1$

      List<?> result = query.execute();
      assertEquals(1, result.size());
      assertEquals(entity, result.get(0));

      if (entity instanceof Attachment)
        assertTrue(((Attachment) entity).isIdentical((Attachment) result.get(0)));
      else if (entity instanceof BookMark)
        assertTrue(((BookMark) entity).isIdentical((BookMark) result.get(0)));
      else if (entity instanceof Category)
        assertTrue(((Category) entity).isIdentical((Category) result.get(0)));
      else if (entity instanceof Feed)
        assertTrue(((Feed) entity).isIdentical((Feed) result.get(0)));
      else if (entity instanceof Folder)
        assertTrue(((Folder) entity).isIdentical((Folder) result.get(0)));
      else if (entity instanceof Label)
        assertTrue(((Label) entity).isIdentical((Label) result.get(0)));
      else if (entity instanceof News)
        assertTrue(((News) entity).isIdentical((News) result.get(0)));
      else if (entity instanceof Person)
        assertTrue(((Person) entity).isIdentical((Person) result.get(0)));
      else if (entity instanceof SearchCondition)
        assertTrue(((SearchCondition) entity).isIdentical((SearchCondition) result.get(0)));
      else if (entity instanceof SearchMark)
        assertTrue(((SearchMark) entity).isIdentical((SearchMark) result.get(0)));
    }

    /* Assert News */
    List<INews> newsList = db.query(INews.class);
    assertEquals(newsList.size(), defragmentedDb.query(INews.class).size());
    for (INews news : newsList) {
      Query query = defragmentedDb.query();
      query.constrain(news.getClass());
      query.descend("fId").constrain(Long.valueOf(news.getId())); //$NON-NLS-1$

      List<INews> result = query.execute();
      assertEquals(1, result.size());
      assertEquals(news.getTitle(), result.get(0).getTitle());
    }

    /* Assert Description */
    List<Description> descriptions = db.query(Description.class);
    assertEquals(descriptions.size(), defragmentedDb.query(Description.class).size());
    for (Description description : descriptions) {
      Query query = defragmentedDb.query();
      query.constrain(description.getClass());
      query.descend("fNewsId").constrain(Long.valueOf(description.getNews().getId())); //$NON-NLS-1$

      List<Description> result = query.execute();
      assertEquals(1, result.size());
      assertEquals(description.getValue(), result.get(0).getValue());
    }

    /* Assert News Bins */
    List<INewsBin> newsBins = db.query(INewsBin.class);
    assertEquals(newsBins.size(), defragmentedDb.query(INewsBin.class).size());
    for (INewsBin newsBin : newsBins) {
      Query query = defragmentedDb.query();
      query.constrain(newsBin.getClass());
      query.descend("fId").constrain(Long.valueOf(newsBin.getId())); //$NON-NLS-1$

      List<INewsBin> result = query.execute();
      assertEquals(1, result.size());
      assertEquals(newsBin.getNews(), result.get(0).getNews());
    }

    /* Assert Folders, Bookmarks and Searchmarks */
    List<IFolder> folders = db.query(IFolder.class);
    assertEquals(folders.size(), defragmentedDb.query(IFolder.class).size());
    for (IFolder folder : folders) {
      Query query = defragmentedDb.query();
      query.constrain(folder.getClass());
      query.descend("fId").constrain(Long.valueOf(folder.getId())); //$NON-NLS-1$

      List<IFolder> result = query.execute();
      assertEquals(1, result.size());

      IFolder otherFolder = result.get(0);
      assertTrue(folder.getName().equals(otherFolder.getName()));
      assertTrue(folder.getProperties().equals(otherFolder.getProperties()));

      IBookMark bm = null;
      ISearchMark sm = null;
      List<IFolderChild> children = folder.getChildren();
      for (IFolderChild child : children) {
        if (child instanceof IBookMark)
          bm = (IBookMark) child;
        else if (child instanceof ISearchMark)
          sm = (ISearchMark) child;
      }

      IBookMark otherBM = null;
      ISearchMark otherSM = null;
      List<IFolderChild> otherChildren = otherFolder.getChildren();
      for (IFolderChild otherChild : otherChildren) {
        if (otherChild instanceof IBookMark)
          otherBM = (IBookMark) otherChild;
        else if (otherChild instanceof ISearchMark)
          otherSM = (ISearchMark) otherChild;
      }

      assertNotNull(bm);
      assertNotNull(sm);
      assertNotNull(otherBM);
      assertNotNull(otherSM);

      assertTrue(bm.getName().equals(otherBM.getName()));
      assertTrue(bm.getProperties().equals(otherBM.getProperties()));

      assertTrue(sm.getSearchConditions().size() == otherSM.getSearchConditions().size());
    }

    /* Assert Preference */
    List<IPreference> preferences = db.query(IPreference.class);
    assertEquals(preferences.size(), defragmentedDb.query(IPreference.class).size());
    for (IPreference preference : preferences) {
      Query query = defragmentedDb.query();
      query.constrain(preference.getClass());
      query.descend("fId").constrain(Long.valueOf(preference.getId())); //$NON-NLS-1$

      List<IPreference> result = query.execute();
      assertEquals(1, result.size());

      IPreference otherPreference = result.get(0);

      assertEquals(preference.getKey(), otherPreference.getKey());
      if ("string".equals(preference.getKey()))
        assertEquals(preference.getString(), otherPreference.getString());

      if ("strings".equals(preference.getKey()))
        assertTrue(Arrays.equals(preference.getStrings(), otherPreference.getStrings()));

      if ("boolean".equals(preference.getKey()))
        assertEquals(preference.getBoolean(), otherPreference.getBoolean());

      if ("booleans".equals(preference.getKey()))
        assertTrue(Arrays.equals(preference.getBooleans(), otherPreference.getBooleans()));

      if ("integer".equals(preference.getKey()))
        assertEquals(preference.getInteger(), otherPreference.getInteger());

      if ("integers".equals(preference.getKey()))
        assertTrue(Arrays.equals(preference.getIntegers(), otherPreference.getIntegers()));

      if ("long".equals(preference.getKey()))
        assertEquals(preference.getLong(), otherPreference.getLong());

      if ("longs".equals(preference.getKey()))
        assertTrue(Arrays.equals(preference.getLongs(), otherPreference.getLongs()));
    }

    /* Assert Label */
    List<ILabel> labels = db.query(ILabel.class);
    assertEquals(labels.size(), defragmentedDb.query(ILabel.class).size());
    for (ILabel label : labels) {
      Query query = defragmentedDb.query();
      query.constrain(label.getClass());
      query.descend("fId").constrain(Long.valueOf(label.getId())); //$NON-NLS-1$

      List<INewsBin> result = query.execute();
      assertEquals(1, result.size());
      assertTrue(((Label) label).isIdentical((ILabel) result.get(0)));
    }

    /* Assert Counter */
    assertEquals(db.query(Counter.class).get(0).getValue(), defragmentedDb.query(Counter.class).get(0).getValue());

    /* Assert Search Filter */
    List<ISearchFilter> filters = db.query(ISearchFilter.class);
    assertEquals(filters.size(), defragmentedDb.query(ISearchFilter.class).size());
    for (ISearchFilter filter : filters) {
      Query query = defragmentedDb.query();
      query.constrain(filter.getClass());
      query.descend("fId").constrain(Long.valueOf(filter.getId())); //$NON-NLS-1$

      List<INewsBin> result = query.execute();
      assertEquals(1, result.size());

      ISearchFilter otherFilter = (ISearchFilter) result.get(0);
      assertTrue(filter.getName().equals(otherFilter.getName()));
      assertEquals(filter.getActions().size(), otherFilter.getActions().size());

      ISearch search = filter.getSearch();
      ISearch otherSearch = otherFilter.getSearch();

      assertEquals(search.getSearchConditions().size(), otherSearch.getSearchConditions().size());
    }

    /* Assert Conditional Get */
    List<IConditionalGet> condGets = db.query(IConditionalGet.class);
    assertEquals(condGets.size(), defragmentedDb.query(IConditionalGet.class).size());
    for (IConditionalGet condGet : condGets) {
      Query query = defragmentedDb.query();
      query.constrain(condGet.getClass());
      query.descend("fLink").constrain(condGet.getLink().toString()); //$NON-NLS-1$

      List<IConditionalGet> result = query.execute();
      assertEquals(1, result.size());

      IConditionalGet otherCondGet = result.get(0);
      assertEquals(condGet.getIfModifiedSince(), otherCondGet.getIfModifiedSince());
      assertEquals(condGet.getIfNoneMatch(), otherCondGet.getIfNoneMatch());
View Full Code Here

    return new FolderEvent(entity, null, true);
  }

  public Collection<IFolder> loadRoots() {
    try {
      Query query = fDb.query();
      query.constrain(fEntityClass);
      query.descend("fParent").constrain(null); //$NON-NLS-1$
      List<IFolder> folders = getList(query);
      activateAll(folders);
      return new ArrayList<IFolder>(folders);
    } catch (Db4oException e) {
      throw new PersistenceException(e);
View Full Code Here

      throw new PersistenceException(e);
    }
  }

  private List<T> loadList(long id) throws Db4oException   {
    Query query = fDb.query();
    query.constrain(fEntityClass);
    query.descend("fId").constrain(Long.valueOf(id)); //$NON-NLS-1$
    return getList(query);
  }
View Full Code Here

      listener.resultsChanged(events);
    }
  }

  public ISearchMark load(ISearchCondition searchCondition) {
    Query query = fDb.query();
    query.constrain(fEntityClass);
    query.descend("fSearchConditions").constrain(searchCondition); //$NON-NLS-1$
    return getSingleResult(query);
  }
View Full Code Here

  public DescriptionDAOImpl() {
    super(Description.class, true);
  }

  public Description load(long newsId) {
    Query query = fDb.query();
    query.constrain(Description.class);
    query.descend("fNewsId").constrain(newsId); //$NON-NLS-1$
    Description description = getSingleResult(query);
    fDb.activate(description, Integer.MAX_VALUE);
    return description;
  }
View Full Code Here

  }

  public IConditionalGet load(URI link) {
    Assert.isNotNull(link, "link cannot be null"); //$NON-NLS-1$
    try {
      Query query = fDb.query();
      query.constrain(fEntityClass);
      query.descend("fLink").constrain(link.toString()); //$NON-NLS-1$

      for (IConditionalGet entity : getList(query)) {
        fDb.activate(entity, Integer.MAX_VALUE);
        return entity;
      }
View Full Code Here

  protected PreferenceEvent createSaveEventTemplate(IPreference entity) {
    return null;
  }

  public IPreference load(String key) throws PersistenceException {
    Query query = fDb.query();
    query.constrain(fEntityClass);
    query.descend("fKey").constrain(key); //$NON-NLS-1$
    List<IPreference> prefs = getList(query);
    activateAll(prefs);
    if (!prefs.isEmpty()) {
      return prefs.iterator().next();
    }
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.