Gremlinq / ExRam.Gremlinq

A .NET object-graph-mapper for Apache TinkerPop™ Gremlin enabled databases.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Possibility to manipulate Update

MartinDemberger opened this issue · comments

Is your feature request related to a problem? Please describe.
We have the properties LastModifiedAt and LastModifiedBy in each of our vertexes. On every change on the vertex this values should be updated with User-ID and the time the action was triggered (not the current time)

Describe the solution you'd like
It would be nice to have a possibility to hook into the Update-method so I can do the poperty change there.

A even better solution would be if I can use a context object in IAddStepHandler.Override which can be filled with dynamic values. So I can do a override on PropertyStep and do the additional PropertySteps on the first one.

Describe alternatives you've considered
Currently I add the Property-step to every data change.

Additional context
Add any other context or screenshots about the feature request here.

Consider sponsoring me
Your ideas might look even more fun to me to implement with a little bit of sponsoring!

There's the Property method on any vertex/edge query. It let's you set individual properties on any element. Wouldn't that work?

This enables me to add the properties but I have to add them to every query I write. I'm looking for a way to add them in one generic place.

Another way would be if here is a step which I can Override that is execute at the beginning or at the end of each query.

I found another way to do this:
I use a ThreadLocal<QueryContext> _queryContext which is reset when the query is started.

With the following logic I set the modified-values on every changed vertex.

.Override<AddVStep>((steps, step, env, overriden, recurse) => {
    _queryContext.Value.ModifiedSet = false;
    return overriden(steps, step, env, recurse);
})
.Override<AddEStep>((steps, step, env, overriden, recurse) => {
    _queryContext.Value.ModifiedSet = false;
    return overriden(steps, step, env, recurse);
})
.Override<OutEStep>((steps, step, env, overriden, recurse) => {
    _queryContext.Value.ModifiedSet = false;
    return overriden(steps, step, env, recurse);
})
.Override<InEStep>((steps, step, env, overriden, recurse) => {
    _queryContext.Value.ModifiedSet = false;
    return overriden(steps, step, env, recurse);
})
.Override<BothEStep>((steps, step, env, overriden, recurse) => {
    _queryContext.Value.ModifiedSet = false;
    return overriden(steps, step, env, recurse);
})
.Override<OutVStep>((steps, step, env, overriden, recurse) => {
    _queryContext.Value.ModifiedSet = false;
    return overriden(steps, step, env, recurse);
})
.Override<InVStep>((steps, step, env, overriden, recurse) => {
    _queryContext.Value.ModifiedSet = false;
    return overriden(steps, step, env, recurse);
})
.Override<OtherVStep>((steps, step, env, overriden, recurse) => {
    _queryContext.Value.ModifiedSet = false;
    return overriden(steps, step, env, recurse);
})
.Override<PropertyStep>((steps, step, env, overriden, recurse) =>
{
    var result = steps;

    if (!_queryContext.Value.ModifiedSet)
    {
        _queryContext.Value.ModifedSet = true;
        result = result
                .Push(new PropertyStep(Constants.Properties.ModifiedAt, _context.StartOfAction))
                .Push(new PropertyStep(Constants.Properties.ModifiedBy, _context.User.Id))
            ;
    }
    return result;
}