db4o Developer Community

db4o open source object database, native to Java and .NET
Welcome to db4o Developer Community Sign in | Join
in Search
More Search Options

Reusable queries patch

Last post 07-17-2008, 05:57 PM by ErikNRC. 1 replies.
Sort Posts: Previous Next
  •  07-17-2008, 05:55 PM 50189

    Reusable queries patch

    Attachment: db4o-7.4.52.11131.zip

    Here we go, attached is the patch against trunk and jar for reusable and caching queries. The patch also contains unit tests. It seems to work quite fine even for complex queries. For about 10000 objects, when indexing can be used, the improvement are about 15-20%. Without index, improvement are about 40-50%.

    The main objective is to cache subsets of queries. There is one catch though, caching and reusing queries are explicit. Otherwise, there is no existing mechanism to specify which subset of a query should be cached. It might be possible to enable reusing an existing query without touching the API but it looks rather difficult (it would require to compare constraints) and not necessarily exact.

    An example on how this works

    if (_cachedQuery == null) {
    // creates a reusable query
    _cachedQuery = db().query().cached();
    // defines the subset cached
    _cachedQuery.onCache().constrain(SensorObject.class);
    _cachedQuery.onCache().descend("value").constrain(new Integer(10)).greater();
    _cachedQuery.onCache().descend("value").constrain(new Integer(dataSize()-10)).smaller();
    }
    _cachedQuery.descend("type").constrain(new Integer(3));
    Collection result = _cachedQuery.execute();

    This will create a cached subset of SensorObject where value > 10 and < n-10. And this subset can be queried against other criterias. One point missing is the invalidation of the cache.

    Erik.

  •  07-17-2008, 05:57 PM 50190 in reply to 50189

    Re: Reusable queries patch

    Attachment: patch.txt
    oops forgot to attach the patch...
View as RSS news feed in XML