Discussion:
proper way to pass app context
Zen 98052
2016-06-09 19:01:29 UTC
Permalink
Hi,

I implement our own Sparql endpoint service, and I am trying to pass the session id (unique per each client request), so that it can be accessed from the code in OpExecutor implementation.

I store the session id in my graph object, the code looks something like:

MyGraph graph = createGraph(appContext); // appContext contains session id and other application state

Model graphModel = ModelFactory.createModelForGraph(graph);


Then inside the class MyOpExecutor (extends Jena's OpExecutor class), I tried to access the session id thru this way:


protected QueryIterator execute(OpBGP opBGP, QueryIterator input) {\
if (this.execCxt.getActiveGraph() instanceof MyGraph) {
MyGraph g = (MyGraph)this.execCxt.getActiveGraph();

// get the session id which can be passed to logging
String sid = g.getAppContext().getSessionId();
...
}
}



The problem I am having is the sid will be always the same sid (from the first client request), though I create a new MyGraph object for each request.

Do you know how to pass the current graph, so that getActiveGraph() code above will get correct graph (for that session) instead of the graph from first client request?



Thanks,

Z
Zen 98052
2016-06-10 00:13:41 UTC
Permalink
I tried following:


Model graphModel = ModelFactory.createModelForGraph(graph);
Query query = QueryFactory.create(queryStr);
QueryExecution qe = QueryExecutionFactory.create(query, graphModel);


// create my custom stageGenerator and set it for per-query context

...

StageBuilder.setGenerator(qe.getContext(), stageGenerator);


// create my custom executor factory (this is where i pass the app context)

...

QC.setFactory(qe.getContext(), opExecutorFactory);


Somehow it doesn't use my custom stage generator or executor factory for per-query context, but it works for ARQ.getContext(), do you know what I missed here?


Thanks,
Z


________________________________
From: Zen 98052 <***@outlook.com>
Sent: Thursday, June 9, 2016 3:01:29 PM
To: ***@jena.apache.org
Subject: proper way to pass app context

Hi,

I implement our own Sparql endpoint service, and I am trying to pass the session id (unique per each client request), so that it can be accessed from the code in OpExecutor implementation.

I store the session id in my graph object, the code looks something like:

MyGraph graph = createGraph(appContext); // appContext contains session id and other application state

Model graphModel = ModelFactory.createModelForGraph(graph);


Then inside the class MyOpExecutor (extends Jena's OpExecutor class), I tried to access the session id thru this way:


protected QueryIterator execute(OpBGP opBGP, QueryIterator input) {\
if (this.execCxt.getActiveGraph() instanceof MyGraph) {
MyGraph g = (MyGraph)this.execCxt.getActiveGraph();

// get the session id which can be passed to logging
String sid = g.getAppContext().getSessionId();
...
}
}



The problem I am having is the sid will be always the same sid (from the first client request), though I create a new MyGraph object for each request.

Do you know how to pass the current graph, so that getActiveGraph() code above will get correct graph (for that session) instead of the graph from first client request?



Thanks,

Z
Zen 98052
2016-06-10 13:16:46 UTC
Permalink
I figured it out, my bad. Somewhere I re-created a new QueryExecution, and passed that one (instead of the one below), hence it'll never work.
________________________________
From: Zen 98052 <***@outlook.com>
Sent: Thursday, June 9, 2016 8:13:41 PM
To: ***@jena.apache.org
Subject: Re: proper way to pass app context

I tried following:


Model graphModel = ModelFactory.createModelForGraph(graph);
Query query = QueryFactory.create(queryStr);
QueryExecution qe = QueryExecutionFactory.create(query, graphModel);


// create my custom stageGenerator and set it for per-query context

...

StageBuilder.setGenerator(qe.getContext(), stageGenerator);


// create my custom executor factory (this is where i pass the app context)

...

QC.setFactory(qe.getContext(), opExecutorFactory);


Somehow it doesn't use my custom stage generator or executor factory for per-query context, but it works for ARQ.getContext(), do you know what I missed here?


Thanks,
Z


________________________________
From: Zen 98052 <***@outlook.com>
Sent: Thursday, June 9, 2016 3:01:29 PM
To: ***@jena.apache.org
Subject: proper way to pass app context

Hi,

I implement our own Sparql endpoint service, and I am trying to pass the session id (unique per each client request), so that it can be accessed from the code in OpExecutor implementation.

I store the session id in my graph object, the code looks something like:

MyGraph graph = createGraph(appContext); // appContext contains session id and other application state

Model graphModel = ModelFactory.createModelForGraph(graph);


Then inside the class MyOpExecutor (extends Jena's OpExecutor class), I tried to access the session id thru this way:


protected QueryIterator execute(OpBGP opBGP, QueryIterator input) {\
if (this.execCxt.getActiveGraph() instanceof MyGraph) {
MyGraph g = (MyGraph)this.execCxt.getActiveGraph();

// get the session id which can be passed to logging
String sid = g.getAppContext().getSessionId();
...
}
}



The problem I am having is the sid will be always the same sid (from the first client request), though I create a new MyGraph object for each request.

Do you know how to pass the current graph, so that getActiveGraph() code above will get correct graph (for that session) instead of the graph from first client request?



Thanks,

Z
Andy Seaborne
2016-06-10 15:09:12 UTC
Permalink
Hi there,

The usual way to pass in information into the execution is to use the
Context.

e.g. its where NOW() puts the timestampe that is returned on each call
inside a single query.

There is a global context, a per dataset context and each query
execution has it's own Context (the accumulation from global and
datasets at the point the query starts).

Andy
Post by Zen 98052
I figured it out, my bad. Somewhere I re-created a new QueryExecution, and passed that one (instead of the one below), hence it'll never work.
________________________________
Sent: Thursday, June 9, 2016 8:13:41 PM
Subject: Re: proper way to pass app context
Model graphModel = ModelFactory.createModelForGraph(graph);
Query query = QueryFactory.create(queryStr);
QueryExecution qe = QueryExecutionFactory.create(query, graphModel);
// create my custom stageGenerator and set it for per-query context
...
StageBuilder.setGenerator(qe.getContext(), stageGenerator);
// create my custom executor factory (this is where i pass the app context)
...
QC.setFactory(qe.getContext(), opExecutorFactory);
Somehow it doesn't use my custom stage generator or executor factory for per-query context, but it works for ARQ.getContext(), do you know what I missed here?
Thanks,
Z
________________________________
Sent: Thursday, June 9, 2016 3:01:29 PM
Subject: proper way to pass app context
Hi,
I implement our own Sparql endpoint service, and I am trying to pass the session id (unique per each client request), so that it can be accessed from the code in OpExecutor implementation.
MyGraph graph = createGraph(appContext); // appContext contains session id and other application state
Model graphModel = ModelFactory.createModelForGraph(graph);
protected QueryIterator execute(OpBGP opBGP, QueryIterator input) {\
if (this.execCxt.getActiveGraph() instanceof MyGraph) {
MyGraph g = (MyGraph)this.execCxt.getActiveGraph();
// get the session id which can be passed to logging
String sid = g.getAppContext().getSessionId();
...
}
}
The problem I am having is the sid will be always the same sid (from the first client request), though I create a new MyGraph object for each request.
Do you know how to pass the current graph, so that getActiveGraph() code above will get correct graph (for that session) instead of the graph from first client request?
Thanks,
Z
Zen 98052
2016-06-10 15:39:38 UTC
Permalink
Thanks Andy!

Based on your suggestion, and looking at the code, it looks like I can do something like:

// create a new symbol, then set it of current context that I want

Symbol mySymbol = .. ;

Context ctx = qe.getContext();

ctx.set(mySymbol, myObjectToPass);


Is this correct?



Thanks,

Z


________________________________
From: Andy Seaborne <***@apache.org>
Sent: Friday, June 10, 2016 11:09:12 AM
To: ***@jena.apache.org
Subject: Re: proper way to pass app context

Hi there,

The usual way to pass in information into the execution is to use the
Context.

e.g. its where NOW() puts the timestampe that is returned on each call
inside a single query.

There is a global context, a per dataset context and each query
execution has it's own Context (the accumulation from global and
datasets at the point the query starts).

Andy
Post by Zen 98052
I figured it out, my bad. Somewhere I re-created a new QueryExecution, and passed that one (instead of the one below), hence it'll never work.
________________________________
Sent: Thursday, June 9, 2016 8:13:41 PM
Subject: Re: proper way to pass app context
Model graphModel = ModelFactory.createModelForGraph(graph);
Query query = QueryFactory.create(queryStr);
QueryExecution qe = QueryExecutionFactory.create(query, graphModel);
// create my custom stageGenerator and set it for per-query context
...
StageBuilder.setGenerator(qe.getContext(), stageGenerator);
// create my custom executor factory (this is where i pass the app context)
...
QC.setFactory(qe.getContext(), opExecutorFactory);
Somehow it doesn't use my custom stage generator or executor factory for per-query context, but it works for ARQ.getContext(), do you know what I missed here?
Thanks,
Z
________________________________
Sent: Thursday, June 9, 2016 3:01:29 PM
Subject: proper way to pass app context
Hi,
I implement our own Sparql endpoint service, and I am trying to pass the session id (unique per each client request), so that it can be accessed from the code in OpExecutor implementation.
MyGraph graph = createGraph(appContext); // appContext contains session id and other application state
Model graphModel = ModelFactory.createModelForGraph(graph);
protected QueryIterator execute(OpBGP opBGP, QueryIterator input) {\
if (this.execCxt.getActiveGraph() instanceof MyGraph) {
MyGraph g = (MyGraph)this.execCxt.getActiveGraph();
// get the session id which can be passed to logging
String sid = g.getAppContext().getSessionId();
...
}
}
The problem I am having is the sid will be always the same sid (from the first client request), though I create a new MyGraph object for each request.
Do you know how to pass the current graph, so that getActiveGraph() code above will get correct graph (for that session) instead of the graph from first client request?
Thanks,
Z
Andy Seaborne
2016-06-10 16:02:01 UTC
Permalink
Post by Zen 98052
Thanks Andy!
// create a new symbol, then set it of current context that I want
Symbol mySymbol = .. ;
Context ctx = qe.getContext();
ctx.set(mySymbol, myObjectToPass);
Is this correct?
Yes.
Post by Zen 98052
Thanks,
Z
________________________________
Sent: Friday, June 10, 2016 11:09:12 AM
Subject: Re: proper way to pass app context
Hi there,
The usual way to pass in information into the execution is to use the
Context.
e.g. its where NOW() puts the timestampe that is returned on each call
inside a single query.
There is a global context, a per dataset context and each query
execution has it's own Context (the accumulation from global and
datasets at the point the query starts).
Andy
Post by Zen 98052
I figured it out, my bad. Somewhere I re-created a new QueryExecution, and passed that one (instead of the one below), hence it'll never work.
________________________________
Sent: Thursday, June 9, 2016 8:13:41 PM
Subject: Re: proper way to pass app context
Model graphModel = ModelFactory.createModelForGraph(graph);
Query query = QueryFactory.create(queryStr);
QueryExecution qe = QueryExecutionFactory.create(query, graphModel);
// create my custom stageGenerator and set it for per-query context
...
StageBuilder.setGenerator(qe.getContext(), stageGenerator);
// create my custom executor factory (this is where i pass the app context)
...
QC.setFactory(qe.getContext(), opExecutorFactory);
Somehow it doesn't use my custom stage generator or executor factory for per-query context, but it works for ARQ.getContext(), do you know what I missed here?
Thanks,
Z
________________________________
Sent: Thursday, June 9, 2016 3:01:29 PM
Subject: proper way to pass app context
Hi,
I implement our own Sparql endpoint service, and I am trying to pass the session id (unique per each client request), so that it can be accessed from the code in OpExecutor implementation.
MyGraph graph = createGraph(appContext); // appContext contains session id and other application state
Model graphModel = ModelFactory.createModelForGraph(graph);
protected QueryIterator execute(OpBGP opBGP, QueryIterator input) {\
if (this.execCxt.getActiveGraph() instanceof MyGraph) {
MyGraph g = (MyGraph)this.execCxt.getActiveGraph();
// get the session id which can be passed to logging
String sid = g.getAppContext().getSessionId();
...
}
}
The problem I am having is the sid will be always the same sid (from the first client request), though I create a new MyGraph object for each request.
Do you know how to pass the current graph, so that getActiveGraph() code above will get correct graph (for that session) instead of the graph from first client request?
Thanks,
Z
Zen 98052
2016-06-10 17:52:02 UTC
Permalink
Hi Andy,

I passed the graph object per my previous code, i.e. ctx.set(mySymbol, myGraph);

When I retrieve it back in my own implementation of OpExecutor, i.e. MyGraph g = (MyGraph)this.execCxt.getContext().get(mySymbol);, it seems to me it always pick the first graph I assigned.

I'd assume this.execCtx.getContext() is per request, not global one, since I explicitly created QueryExecution and called its getContext().set(...), so it must be per request. This is bizarre.


Thanks,

Z

________________________________
From: Andy Seaborne <***@apache.org>
Sent: Friday, June 10, 2016 12:02:01 PM
To: ***@jena.apache.org
Subject: Re: proper way to pass app context
Post by Zen 98052
Thanks Andy!
// create a new symbol, then set it of current context that I want
Symbol mySymbol = .. ;
Context ctx = qe.getContext();
ctx.set(mySymbol, myObjectToPass);
Is this correct?
Yes.
Post by Zen 98052
Thanks,
Z
________________________________
Sent: Friday, June 10, 2016 11:09:12 AM
Subject: Re: proper way to pass app context
Hi there,
The usual way to pass in information into the execution is to use the
Context.
e.g. its where NOW() puts the timestampe that is returned on each call
inside a single query.
There is a global context, a per dataset context and each query
execution has it's own Context (the accumulation from global and
datasets at the point the query starts).
Andy
Post by Zen 98052
I figured it out, my bad. Somewhere I re-created a new QueryExecution, and passed that one (instead of the one below), hence it'll never work.
________________________________
Sent: Thursday, June 9, 2016 8:13:41 PM
Subject: Re: proper way to pass app context
Model graphModel = ModelFactory.createModelForGraph(graph);
Query query = QueryFactory.create(queryStr);
QueryExecution qe = QueryExecutionFactory.create(query, graphModel);
// create my custom stageGenerator and set it for per-query context
...
StageBuilder.setGenerator(qe.getContext(), stageGenerator);
// create my custom executor factory (this is where i pass the app context)
...
QC.setFactory(qe.getContext(), opExecutorFactory);
Somehow it doesn't use my custom stage generator or executor factory for per-query context, but it works for ARQ.getContext(), do you know what I missed here?
Thanks,
Z
________________________________
Sent: Thursday, June 9, 2016 3:01:29 PM
Subject: proper way to pass app context
Hi,
I implement our own Sparql endpoint service, and I am trying to pass the session id (unique per each client request), so that it can be accessed from the code in OpExecutor implementation.
MyGraph graph = createGraph(appContext); // appContext contains session id and other application state
Model graphModel = ModelFactory.createModelForGraph(graph);
protected QueryIterator execute(OpBGP opBGP, QueryIterator input) {\
if (this.execCxt.getActiveGraph() instanceof MyGraph) {
MyGraph g = (MyGraph)this.execCxt.getActiveGraph();
// get the session id which can be passed to logging
String sid = g.getAppContext().getSessionId();
...
}
}
The problem I am having is the sid will be always the same sid (from the first client request), though I create a new MyGraph object for each request.
Do you know how to pass the current graph, so that getActiveGraph() code above will get correct graph (for that session) instead of the graph from first client request?
Thanks,
Z
Andy Seaborne
2016-06-10 21:03:15 UTC
Permalink
Post by Zen 98052
Hi Andy,
I passed the graph object per my previous code, i.e. ctx.set(mySymbol, myGraph);
When I retrieve it back in my own implementation of OpExecutor, i.e. MyGraph g = (MyGraph)this.execCxt.getContext().get(mySymbol);, it seems to me it always pick the first graph I assigned.
I'd assume this.execCtx.getContext() is per request,
Yes - that's what it should be.

You can print it out and see for example the time stamp is changing.
Post by Zen 98052
not global one, since I explicitly created QueryExecution and called its getContext().set(...), so it must be per request. This is bizarre.
Thanks,
Z
________________________________
Sent: Friday, June 10, 2016 12:02:01 PM
Subject: Re: proper way to pass app context
Post by Zen 98052
Thanks Andy!
// create a new symbol, then set it of current context that I want
Symbol mySymbol = .. ;
Context ctx = qe.getContext();
ctx.set(mySymbol, myObjectToPass);
Is this correct?
Yes.
Post by Zen 98052
Thanks,
Z
________________________________
Sent: Friday, June 10, 2016 11:09:12 AM
Subject: Re: proper way to pass app context
Hi there,
The usual way to pass in information into the execution is to use the
Context.
e.g. its where NOW() puts the timestampe that is returned on each call
inside a single query.
There is a global context, a per dataset context and each query
execution has it's own Context (the accumulation from global and
datasets at the point the query starts).
Andy
Post by Zen 98052
I figured it out, my bad. Somewhere I re-created a new QueryExecution, and passed that one (instead of the one below), hence it'll never work.
________________________________
Sent: Thursday, June 9, 2016 8:13:41 PM
Subject: Re: proper way to pass app context
Model graphModel = ModelFactory.createModelForGraph(graph);
Query query = QueryFactory.create(queryStr);
QueryExecution qe = QueryExecutionFactory.create(query, graphModel);
// create my custom stageGenerator and set it for per-query context
...
StageBuilder.setGenerator(qe.getContext(), stageGenerator);
// create my custom executor factory (this is where i pass the app context)
...
QC.setFactory(qe.getContext(), opExecutorFactory);
Somehow it doesn't use my custom stage generator or executor factory for per-query context, but it works for ARQ.getContext(), do you know what I missed here?
Thanks,
Z
________________________________
Sent: Thursday, June 9, 2016 3:01:29 PM
Subject: proper way to pass app context
Hi,
I implement our own Sparql endpoint service, and I am trying to pass the session id (unique per each client request), so that it can be accessed from the code in OpExecutor implementation.
MyGraph graph = createGraph(appContext); // appContext contains session id and other application state
Model graphModel = ModelFactory.createModelForGraph(graph);
protected QueryIterator execute(OpBGP opBGP, QueryIterator input) {\
if (this.execCxt.getActiveGraph() instanceof MyGraph) {
MyGraph g = (MyGraph)this.execCxt.getActiveGraph();
// get the session id which can be passed to logging
String sid = g.getAppContext().getSessionId();
...
}
}
The problem I am having is the sid will be always the same sid (from the first client request), though I create a new MyGraph object for each request.
Do you know how to pass the current graph, so that getActiveGraph() code above will get correct graph (for that session) instead of the graph from first client request?
Thanks,
Z
Zen 98052
2016-06-14 00:06:25 UTC
Permalink
Hi Andy,

How to set the custom op executor for UPDATE?
My code for update is:


InputStream stream = new ByteArrayInputStream(postData.getBytes("UTF-8"));
UpdateAction.parseExecute(null, graphDataset, stream, Syntax.syntaxARQ);



Thanks,

Z

________________________________
From: Andy Seaborne <***@apache.org>
Sent: Friday, June 10, 2016 5:03:15 PM
To: ***@jena.apache.org
Subject: Re: proper way to pass app context
Post by Zen 98052
Hi Andy,
I passed the graph object per my previous code, i.e. ctx.set(mySymbol, myGraph);
When I retrieve it back in my own implementation of OpExecutor, i.e. MyGraph g = (MyGraph)this.execCxt.getContext().get(mySymbol);, it seems to me it always pick the first graph I assigned.
I'd assume this.execCtx.getContext() is per request,
Yes - that's what it should be.

You can print it out and see for example the time stamp is changing.
Post by Zen 98052
not global one, since I explicitly created QueryExecution and called its getContext().set(...), so it must be per request. This is bizarre.
Thanks,
Z
________________________________
Sent: Friday, June 10, 2016 12:02:01 PM
Subject: Re: proper way to pass app context
Post by Zen 98052
Thanks Andy!
// create a new symbol, then set it of current context that I want
Symbol mySymbol = .. ;
Context ctx = qe.getContext();
ctx.set(mySymbol, myObjectToPass);
Is this correct?
Yes.
Post by Zen 98052
Thanks,
Z
________________________________
Sent: Friday, June 10, 2016 11:09:12 AM
Subject: Re: proper way to pass app context
Hi there,
The usual way to pass in information into the execution is to use the
Context.
e.g. its where NOW() puts the timestampe that is returned on each call
inside a single query.
There is a global context, a per dataset context and each query
execution has it's own Context (the accumulation from global and
datasets at the point the query starts).
Andy
Post by Zen 98052
I figured it out, my bad. Somewhere I re-created a new QueryExecution, and passed that one (instead of the one below), hence it'll never work.
________________________________
Sent: Thursday, June 9, 2016 8:13:41 PM
Subject: Re: proper way to pass app context
Model graphModel = ModelFactory.createModelForGraph(graph);
Query query = QueryFactory.create(queryStr);
QueryExecution qe = QueryExecutionFactory.create(query, graphModel);
// create my custom stageGenerator and set it for per-query context
...
StageBuilder.setGenerator(qe.getContext(), stageGenerator);
// create my custom executor factory (this is where i pass the app context)
...
QC.setFactory(qe.getContext(), opExecutorFactory);
Somehow it doesn't use my custom stage generator or executor factory for per-query context, but it works for ARQ.getContext(), do you know what I missed here?
Thanks,
Z
________________________________
Sent: Thursday, June 9, 2016 3:01:29 PM
Subject: proper way to pass app context
Hi,
I implement our own Sparql endpoint service, and I am trying to pass the session id (unique per each client request), so that it can be accessed from the code in OpExecutor implementation.
MyGraph graph = createGraph(appContext); // appContext contains session id and other application state
Model graphModel = ModelFactory.createModelForGraph(graph);
protected QueryIterator execute(OpBGP opBGP, QueryIterator input) {\
if (this.execCxt.getActiveGraph() instanceof MyGraph) {
MyGraph g = (MyGraph)this.execCxt.getActiveGraph();
// get the session id which can be passed to logging
String sid = g.getAppContext().getSessionId();
...
}
}
The problem I am having is the sid will be always the same sid (from the first client request), though I create a new MyGraph object for each request.
Do you know how to pass the current graph, so that getActiveGraph() code above will get correct graph (for that session) instead of the graph from first client request?
Thanks,
Z
Andy Seaborne
2016-06-14 08:44:48 UTC
Permalink
Post by Zen 98052
Hi Andy,
How to set the custom op executor for UPDATE?
InputStream stream = new ByteArrayInputStream(postData.getBytes("UTF-8"));
UpdateAction.parseExecute(null, graphDataset, stream, Syntax.syntaxARQ);
Thanks,
Z
The class UpdateAction is a collection of convenience operations. The
full API is via UpdateExecutionFactory which includes
passing in a context.

Andy
Zen 98052
2016-06-15 12:35:32 UTC
Permalink
Hi Andy,

I see the code parseExecute in UpdateAction, which I can copy and pass the context object.

Before that, how do I get that per-request context at first place?


For SELECT request, I am able to call QueryExecutionFactory.create to get the QueryExecution object, which has the per-request context object.

I don't see there is UpdateExecution or something like that.


Once I got the per-request context object, I want to pass it to StageBuilder.setGenerator(context, ...), and QC.setFactory(context, ...)



Thanks,

Z

________________________________
From: Andy Seaborne <***@apache.org>
Sent: Tuesday, June 14, 2016 4:44:48 AM
To: ***@jena.apache.org
Subject: Re: proper way to pass app context
Post by Zen 98052
Hi Andy,
How to set the custom op executor for UPDATE?
InputStream stream = new ByteArrayInputStream(postData.getBytes("UTF-8"));
UpdateAction.parseExecute(null, graphDataset, stream, Syntax.syntaxARQ);
Thanks,
Z
The class UpdateAction is a collection of convenience operations. The
full API is via UpdateExecutionFactory which includes
passing in a context.

Andy
Andy Seaborne
2016-06-15 20:22:45 UTC
Permalink
Post by Zen 98052
Hi Andy,
I see the code parseExecute in UpdateAction, which I can copy and pass the context object.
Before that, how do I get that per-request context at first place?
For SELECT request, I am able to call QueryExecutionFactory.create to get the QueryExecution object, which has the per-request context object.
I don't see there is UpdateExecution or something like that.
pass it when

UpdateExecutionFactory.
create(UpdateRequest updateRequest, Dataset dataset, Context context)

or manipulate the returned UpdateProcessor

Andy
Post by Zen 98052
Once I got the per-request context object, I want to pass it to StageBuilder.setGenerator(context, ...), and QC.setFactory(context, ...)
Thanks,
Z
________________________________
Sent: Tuesday, June 14, 2016 4:44:48 AM
Subject: Re: proper way to pass app context
Post by Zen 98052
Hi Andy,
How to set the custom op executor for UPDATE?
InputStream stream = new ByteArrayInputStream(postData.getBytes("UTF-8"));
UpdateAction.parseExecute(null, graphDataset, stream, Syntax.syntaxARQ);
Thanks,
Z
The class UpdateAction is a collection of convenience operations. The
full API is via UpdateExecutionFactory which includes
passing in a context.
Andy
Zen 98052
2016-06-15 22:01:02 UTC
Permalink
Below is the Jena code that I can copy (I am doing this because UpdateAction API doesn't return the UpdateProcessor, or in this case UpdateProcessorStreaming, which what I need).

Unfortunately, UpdateFactory.setupParser is 'protected' instead of 'public'. Does it mean I have to subclass the UpdateFactory class?

Or can I simply call UpdateFactory.create? I am not sure if I need UpdateSink in my case (which is using input stream)



Thanks,

Z



public static void parseExecute(UsingList usingList, DatasetGraph dataset, InputStream input, Binding inputBinding, String baseURI, Syntax syntax)
{
GraphStore graphStore = GraphStoreFactory.create(dataset);

UpdateProcessorStreaming uProc = UpdateExecutionFactory.createStreaming(graphStore, inputBinding) ;
if (uProc == null)
throw new ARQException("No suitable update procesors are registered/able to execute your updates");

uProc.startRequest();
try
{
UpdateSink sink = new UsingUpdateSink(uProc.getUpdateSink(), usingList) ;
try
{
UpdateParser parser = UpdateFactory.setupParser(sink.getPrologue(), baseURI, syntax) ;
parser.parse(sink, input) ;
}
finally
{
sink.close() ;
}
}
finally
{
uProc.finishRequest();
}
}


________________________________
From: Andy Seaborne <***@apache.org>
Sent: Wednesday, June 15, 2016 4:22:45 PM
To: ***@jena.apache.org
Subject: Re: proper way to pass app context
Post by Zen 98052
Hi Andy,
I see the code parseExecute in UpdateAction, which I can copy and pass the context object.
Before that, how do I get that per-request context at first place?
For SELECT request, I am able to call QueryExecutionFactory.create to get the QueryExecution object, which has the per-request context object.
I don't see there is UpdateExecution or something like that.
pass it when

UpdateExecutionFactory.
create(UpdateRequest updateRequest, Dataset dataset, Context context)

or manipulate the returned UpdateProcessor

Andy
Post by Zen 98052
Once I got the per-request context object, I want to pass it to StageBuilder.setGenerator(context, ...), and QC.setFactory(context, ...)
Thanks,
Z
________________________________
Sent: Tuesday, June 14, 2016 4:44:48 AM
Subject: Re: proper way to pass app context
Post by Zen 98052
Hi Andy,
How to set the custom op executor for UPDATE?
InputStream stream = new ByteArrayInputStream(postData.getBytes("UTF-8"));
UpdateAction.parseExecute(null, graphDataset, stream, Syntax.syntaxARQ);
Thanks,
Z
The class UpdateAction is a collection of convenience operations. The
full API is via UpdateExecutionFactory which includes
passing in a context.
Andy
Zen 98052
2016-06-15 22:18:11 UTC
Permalink
I don't think I can use UpdateFactory.create, because it expects a String arg (while my case is I want to pass an InputStream)

________________________________
From: Zen 98052
Sent: Wednesday, June 15, 2016 6:01:02 PM
To: ***@jena.apache.org
Subject: Re: proper way to pass app context


Below is the Jena code that I can copy (I am doing this because UpdateAction API doesn't return the UpdateProcessor, or in this case UpdateProcessorStreaming, which what I need).

Unfortunately, UpdateFactory.setupParser is 'protected' instead of 'public'. Does it mean I have to subclass the UpdateFactory class?

Or can I simply call UpdateFactory.create? I am not sure if I need UpdateSink in my case (which is using input stream)



Thanks,

Z



public static void parseExecute(UsingList usingList, DatasetGraph dataset, InputStream input, Binding inputBinding, String baseURI, Syntax syntax)
{
GraphStore graphStore = GraphStoreFactory.create(dataset);

UpdateProcessorStreaming uProc = UpdateExecutionFactory.createStreaming(graphStore, inputBinding) ;
if (uProc == null)
throw new ARQException("No suitable update procesors are registered/able to execute your updates");

uProc.startRequest();
try
{
UpdateSink sink = new UsingUpdateSink(uProc.getUpdateSink(), usingList) ;
try
{
UpdateParser parser = UpdateFactory.setupParser(sink.getPrologue(), baseURI, syntax) ;
parser.parse(sink, input) ;
}
finally
{
sink.close() ;
}
}
finally
{
uProc.finishRequest();
}
}


________________________________
From: Andy Seaborne <***@apache.org>
Sent: Wednesday, June 15, 2016 4:22:45 PM
To: ***@jena.apache.org
Subject: Re: proper way to pass app context
Post by Zen 98052
Hi Andy,
I see the code parseExecute in UpdateAction, which I can copy and pass the context object.
Before that, how do I get that per-request context at first place?
For SELECT request, I am able to call QueryExecutionFactory.create to get the QueryExecution object, which has the per-request context object.
I don't see there is UpdateExecution or something like that.
pass it when

UpdateExecutionFactory.
create(UpdateRequest updateRequest, Dataset dataset, Context context)

or manipulate the returned UpdateProcessor

Andy
Post by Zen 98052
Once I got the per-request context object, I want to pass it to StageBuilder.setGenerator(context, ...), and QC.setFactory(context, ...)
Thanks,
Z
________________________________
Sent: Tuesday, June 14, 2016 4:44:48 AM
Subject: Re: proper way to pass app context
Post by Zen 98052
Hi Andy,
How to set the custom op executor for UPDATE?
InputStream stream = new ByteArrayInputStream(postData.getBytes("UTF-8"));
UpdateAction.parseExecute(null, graphDataset, stream, Syntax.syntaxARQ);
Thanks,
Z
The class UpdateAction is a collection of convenience operations. The
full API is via UpdateExecutionFactory which includes
passing in a context.
Andy
Zen 98052
2016-06-15 22:19:04 UTC
Permalink
I don't think I can use UpdateFactory.create, because it expects a String arg (while my case is I want to pass an InputStream)

________________________________
From: Andy Seaborne <***@apache.org>
Sent: Wednesday, June 15, 2016 4:22:45 PM
To: ***@jena.apache.org
Subject: Re: proper way to pass app context
Post by Zen 98052
Hi Andy,
I see the code parseExecute in UpdateAction, which I can copy and pass the context object.
Before that, how do I get that per-request context at first place?
For SELECT request, I am able to call QueryExecutionFactory.create to get the QueryExecution object, which has the per-request context object.
I don't see there is UpdateExecution or something like that.
pass it when

UpdateExecutionFactory.
create(UpdateRequest updateRequest, Dataset dataset, Context context)

or manipulate the returned UpdateProcessor

Andy
Post by Zen 98052
Once I got the per-request context object, I want to pass it to StageBuilder.setGenerator(context, ...), and QC.setFactory(context, ...)
Thanks,
Z
________________________________
Sent: Tuesday, June 14, 2016 4:44:48 AM
Subject: Re: proper way to pass app context
Post by Zen 98052
Hi Andy,
How to set the custom op executor for UPDATE?
InputStream stream = new ByteArrayInputStream(postData.getBytes("UTF-8"));
UpdateAction.parseExecute(null, graphDataset, stream, Syntax.syntaxARQ);
Thanks,
Z
The class UpdateAction is a collection of convenience operations. The
full API is via UpdateExecutionFactory which includes
passing in a context.
Andy
Andy Seaborne
2016-06-16 08:07:03 UTC
Permalink
Post by Zen 98052
I don't think I can use UpdateFactory.create, because it expects a String arg (while my case is I want to pass an InputStream)
UpdateExecutionFactory.create (not UpdateFactory.create).

and

UpdateFactory.read takes a InputStream.

"read" for an indirected source (file, inputstream)
"create" for a string.

Andy

Continue reading on narkive:
Loading...