Search code examples
c#db4o

Query objects by commit timestamps


Is it possible in db4o to query objects that have changed since some certain time using internal commit timestamps(since version 8.0 db4o allows to generate commit timestamps)?

I know its possible this way:

long last = DateTime.Now.Ticks;
var objectsChanged = from obj in GetAllObjectsInDatabase(session)
                     where session.Ext().GetObjectInfo(obj).GetCommitTimestamp() > last
                     select obj;

but for 10milion objects, it takes ages to iterate through all of them (to get 3 objects as result) - it would be much faster to create on each object my own commit timestamp and index it.

Is there some faster way of getting changes in DB since certain moment?


Solution

  • Hmm, not officially. However dRS needs to do this for replication (source). So it is internally supported. I didn't check it properly. It is pulled out from the replication code.

    Java:

    Query query = container.query();
    query.descend(VirtualField.COMMIT_TIMESTAMP)
        .constrain(lastCommitTimestamp).greater();
    List<Object> result = query.execute();
    

    So in C# it should be:

    IQuery query = container.Query();
    query.Descend(VirtualField.COMMIT_TIMESTAMP)
       .Constrain(lastCommitTimestamp).Greater();
    IList result = query.execute();
    

    Anyway, no grantees. It is not considered as a public API. But I think very close to what you need.