public class Executor
extends java.lang.Object
implements java.io.Serializable
An instance of this class executes on a triple store a set of commands contained in a JSON array.
The following commands can be supplied for execution. A string, a handle, an item, or an access level is supplied as a text string in quotes. A non-item can be a boolean (true or false), an integer, a decimal number, or a text string in quotes. A b64 is a base64-encoded binary value. A source is supplied as an integer. A json object is supplied as the textual representation of a JSON object ({ . . . }). The text string describing an item or an access level can be a handle set in a previous command, the textual representation of an item identifier (sourcenr:itemnr) or a numeric source identifier and the name of a named item in that source, separated by a colon (sourcenr:name). It MUST NOT be a textual source name and the name of a named item in that source.
The result returned from the execution is a map of the values assigned to handles.
Get or create a named item.
"command"="named item"; "source"=source; "name"=string; "handle"=handle
Get the unique subject with a given verb and item object.
"command"="get unique subject with item object"; "verb"=item; "object"=item; "handle"=handle (optional)
Get the unique subject with a given verb and item object,
creating it in the given source and with the given access levels
if it does not exist.
"command"="unique subject with item object"; "source"=source; "read"=access level; "write"=access level; "verb"=item; "object"=item; "handle"=handle (optional)
Get the unique subject with a given verb and boolean, integral,
real or string object.
"command"="get unique subject with non-item object"; "verb"=item; "object"=non-item; "handle"=handle (optional)
Get the unique subject with a given verb and boolean, integral,
real or string object, creating it in the given source and with the
given access levels if it does not exist.
"command"="unique subject with non-item object"; "source"=source; "read"=access level; "write"=access level; "verb"=item; "object"=non-item; "handle"=handle (optional)
Get the unique subject with a given verb and binary object.
"command"="get unique subject with binary object"; "verb"=item; "object"=b64; "handle"=handle (optional)
Get the unique subject with a given verb and binary object,
creating it in the given source and with the given access levels
if it does not exist.
"command"="unique subject with binary object"; "source"=source; "read"=access level; "write"=access level; "verb"=item; "object"=b64; "handle"=handle (optional)
Get the item that is the unique object with a given subject
and verb, creating it in the given source and with the given access
levels, and also creating the appropriate triple, if it does not
exist.
"command"="unique item object"; "source"=source; "subject"=item; "verb"=item; "read"=access level; "write"=access level; "handle"=handle (optional)
Create an item.
"command"="create item"; "source"=source; "read"=access level; "write"=access level; "handle"=handle
Ensure that there is a unique triple with a given subject, verb
and object, where the object is an item.
"command"="put triple with item object"; "subject"=item; "verb"=item; "object"=item
Ensure that there is a unique triple with a given subject, verb
and object, where the object is a boolean, integer, real, or string.
"command"="put triple with non-item object"; "subject"=item; "verb"=item; "object"=non-item
Ensure that there is a unique triple with a given subject, verb
and object, where the object is a binary.
"command"="put triple with non-item object"; "subject"=item; "verb"=item; "object"=b64
Ensure that there is a unique triple with a given subject and verb,
and that it has the given object, which is an item.
"command"="set unique item object"; "subject"=item; "verb"=item; "object"=item
Ensure that there is a unique triple with a given subject and verb,
and that it has the given object, which is a boolean, integer, real or
string.
"command"="set unique non-item object"; "subject"=item; "verb"=item; "object"=non-item
Ensure that there is a unique triple with a given subject and verb,
and that it has the given object, which is a binary.
"command"="set unique non-item object"; "subject"=item; "verb"=item; "object"=b64
Ensure that there is a unique triple with a given subject and verb,
and that it has the given object, which is the textual representation of
a JSON object.
"command"="set unique json object"; "subject"=item; "verb"=item; "object"=json object
Constructor and Description |
---|
Executor(TripleStore store)
Create an executor
|
Modifier and Type | Method and Description |
---|---|
java.util.Map<java.lang.String,Datum> |
execute(org.json.simple.JSONArray script,
java.util.Map<java.lang.String,Datum> binaries,
StoreSession session)
Execute the commands in a JSON array
|
void |
executeJsonCommand(org.json.simple.JSONObject jo,
java.util.Map<java.lang.String,Datum> handles,
java.util.Map<java.lang.String,Datum> binaries,
StoreSession session)
Execute a command
|
AccessLevel |
getAccessLevelFromJson(java.lang.String name,
org.json.simple.JSONObject jo,
java.util.Map<java.lang.String,Datum> assignments,
StoreSession session)
Get an access level specified in a JSON object
|
Datum |
getBinaryFromJson(java.lang.String name,
java.util.Map<java.lang.String,Datum> binaries,
org.json.simple.JSONObject jo)
Get a binary value from a JSON object and a map of binary
values
|
Datum |
getBoolIntRealOrStringFromJson(java.lang.String name,
org.json.simple.JSONObject jo,
StoreSession session)
Get a boolean, integer, real, or string from a JSON object
|
Item |
getItemFromJson(java.lang.String name,
org.json.simple.JSONObject jo,
java.util.Map<java.lang.String,Datum> assignments,
StoreSession session)
Get an item specified in a JSON object
|
org.json.simple.JSONObject |
getJsonCommand(java.lang.Object obj)
Get a command from an object
|
java.lang.Long |
getLongFromJson(java.lang.String name,
org.json.simple.JSONObject jo)
Get a Long value from a JSON object
|
Item |
getNamedItem(java.lang.String spec,
StoreSession session)
Get a named item from its specification
|
java.lang.String |
getStringFromJson(java.lang.String name,
org.json.simple.JSONObject jo)
Get a String value from a JSON object
|
public Executor(TripleStore store)
store
- the triple store on which the commands are executedpublic java.util.Map<java.lang.String,Datum> execute(org.json.simple.JSONArray script, java.util.Map<java.lang.String,Datum> binaries, StoreSession session) throws java.lang.Exception
script
- a JSON array containing commands to be executedsession
- the requesting store sessionjava.lang.Exception
public org.json.simple.JSONObject getJsonCommand(java.lang.Object obj) throws InputException
obj
- an objectInputException
public void executeJsonCommand(org.json.simple.JSONObject jo, java.util.Map<java.lang.String,Datum> handles, java.util.Map<java.lang.String,Datum> binaries, StoreSession session) throws java.lang.Exception
jo
- a JSON object containing the command to be executedhandles
- the handles for items created by previous commands,
and to which a new handle can be added if an item is created by
this command.session
- the requesting store sessionInputException
java.lang.Exception
public java.lang.Long getLongFromJson(java.lang.String name, org.json.simple.JSONObject jo)
name
- the name in a name-value pair in the JSON objectjo
- a JSON objectpublic java.lang.String getStringFromJson(java.lang.String name, org.json.simple.JSONObject jo)
name
- the name in a name-value pair in the JSON objectjo
- a JSON objectpublic Datum getBoolIntRealOrStringFromJson(java.lang.String name, org.json.simple.JSONObject jo, StoreSession session)
name
- the name in a name-value pair in the JSON objectjo
- a JSON objectsession
- the requesting store sessionpublic Datum getBinaryFromJson(java.lang.String name, java.util.Map<java.lang.String,Datum> binaries, org.json.simple.JSONObject jo) throws AccessException
name
- the name in a name-value pair in the JSON objectbinaries
- a map giving the binary values referred to in
the JSON objectjo
- a JSON objectAccessException
public AccessLevel getAccessLevelFromJson(java.lang.String name, org.json.simple.JSONObject jo, java.util.Map<java.lang.String,Datum> assignments, StoreSession session) throws java.lang.Exception
name
- the name in a name-value pair in the JSON objectjo
- a JSON objectassignments
- the assignments created by previous
commandssession
- the requesting store sessionjava.lang.Exception
public Item getItemFromJson(java.lang.String name, org.json.simple.JSONObject jo, java.util.Map<java.lang.String,Datum> assignments, StoreSession session) throws java.lang.Exception
name
- the name in a name-value pair in the JSON objectjo
- a JSON objectassignments
- the assignments created by previous
commandssession
- the requesting store sessionjava.lang.Exception
public Item getNamedItem(java.lang.String spec, StoreSession session) throws TripleStoreNonFatalException, SourceConnectorException, TripleStoreFatalException, NotInOperationException
spec
- a specification of a named itemsession
- the requesting store sessionTripleStoreNonFatalException
SourceConnectorException
TripleStoreFatalException
NotInOperationException