Java Code Examples for org.apache.jena.sparql.util.Context#set()

The following examples show how to use org.apache.jena.sparql.util.Context#set() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BindPlan.java    From sparql-generate with Apache License 2.0 6 votes vote down vote up
@Override
protected final Binding exec(Binding binding, Context context) {
    LOG.debug("Start " + this);
    context.set(ARQConstants.sysCurrentTime, NodeFactoryExtra.nowAsDateTime());
    final FunctionEnv env = new FunctionEnvBase(context);
    try {
        final NodeValue n = expr.eval(binding, env);
        if (LOG.isTraceEnabled()) {
            LOG.trace("New binding " + var + " = " + LogUtils.compress(n.asNode()));
        }
        return BindingFactory.binding(binding, var, n.asNode());
    } catch(ExprEvalException ex) {
        LOG.trace("No evaluation for " + this + " " + ex.getMessage());
        return binding;
    }
}
 
Example 2
Source File: JenaUtil.java    From shacl with Apache License 2.0 6 votes vote down vote up
private static Node invokeFunction(Resource function, ExprList args, Dataset dataset) {

		if (dataset == null) {
	        dataset = ARQFactory.get().getDataset(ModelFactory.createDefaultModel());
	    }
		
		E_Function expr = new E_Function(function.getURI(), args);
		DatasetGraph dsg = dataset.asDatasetGraph();
		Context cxt = ARQ.getContext().copy();
		cxt.set(ARQConstants.sysCurrentTime, NodeFactoryExtra.nowAsDateTime());
		FunctionEnv env = new ExecutionContext(cxt, dsg.getDefaultGraph(), dsg, null);
		try {
			NodeValue r = expr.eval(BindingRoot.create(), env);
			if(r != null) {
				return r.asNode();
			}
		}
		catch(ExprEvalException ex) {
		}
		return null;
	}
 
Example 3
Source File: ContextUtils.java    From sparql-generate with Apache License 2.0 5 votes vote down vote up
public static synchronized Node[] getInfo(final Context context, final Node_List list) {
	final int size = (Integer) context.get(SIZE);
	if (size == 0) {
		return NIL;
	}
	if (context.isUndef(LIST_NODES)) {
		context.set(LIST_NODES, new HashMap<>());
	}
	final Map<Node_List, Node[]> listNodes = context.get(LIST_NODES);
	if (!listNodes.containsKey(list)) {
		createListNodes(listNodes, list, size);
	}
	return listNodes.get(list);
}
 
Example 4
Source File: ContextUtils.java    From sparql-generate with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * @param ctx
 *            the context to fork
 */
private Forker(Context ctx, boolean isRoot) {
	context = new Context(ctx);
	context.set(SysRIOT.sysStreamManager,
			context.get(SysRIOT.sysStreamManager, SPARQLExtStreamManager.makeStreamManager()));
	context.set(BASE, context.get(BASE));
	context.set(PREFIX_MANAGER, context.get(PREFIX_MANAGER, PrefixMapping.Standard));
	context.set(SIZE, 0);
	if(!isRoot) {
		context.set(PARENT_CONTEXT, ctx);
	}
}
 
Example 5
Source File: ManagedDatasetBuilder.java    From rdf-delta with Apache License 2.0 4 votes vote down vote up
public DatasetGraph build() {
    if ( zone == null )         throw new DeltaConfigException("zone not set");
    if ( deltaLink == null )    throw new DeltaConfigException("deltaLink not set");
    if ( logName == null )      throw new DeltaConfigException("logName not set");
    if ( syncPolicy == null )   throw new DeltaConfigException("syncPolicy not set");

    if ( externalDataset != null && storageType == null )
        this.storageType = LocalStorageType.EXTERNAL;

    if ( externalDataset != null && storageType != LocalStorageType.EXTERNAL )
        throw new DeltaConfigException("External dataset but storage is not 'external'");

    DeltaClient deltaClient = DeltaClient.create(zone, deltaLink);
    deltaLink.ping();

    DataSourceDescription dsd = deltaLink.getDataSourceDescriptionByName(logName);
    Id dsRef;
    if ( dsd == null )
        dsRef = deltaClient.newDataSource(logName, "delta:"+logName);
    else
        dsRef = dsd.getId();
    if ( zone.exists(dsRef)) {
        if ( externalDataset == null )
            deltaClient.connect(dsRef, syncPolicy);
        else
            deltaClient.connectExternal(dsRef, externalDataset, syncPolicy);
    }
    else {
        // Zones are always cached ahead of time by the startup disk scan.
        // Should not be here if restarting and now using a zone.
        // storageType required because we will create a new zone-log.
        if ( storageType == null )
            throw new DeltaConfigException("storageType not set");
        // Register, which is "attach" then "connect".
        // "attach" creates the zone dataset storage.
        if ( externalDataset == null )
            deltaClient.register(dsRef, storageType, syncPolicy);
        else
            deltaClient.registerExternal(dsRef, externalDataset, syncPolicy);
    }

    DeltaConnection deltaConnection = deltaClient.getLocal(dsRef);
    DatasetGraph dsg = deltaConnection.getDatasetGraph();
    // Put state into dsg Context "for the record".
    Context cxt = dsg.getContext();
    cxt.set(symDeltaClient, deltaClient);
    cxt.set(symDeltaConnection, deltaConnection);
    cxt.set(symDeltaZone, zone);
    return dsg;
}
 
Example 6
Source File: IteratorFunctionRegistry.java    From sparql-generate with Apache License 2.0 4 votes vote down vote up
public static void set(Context context, IteratorFunctionRegistry reg) {
	context.set(SPARQLExt.REGISTRY_ITERATORS, reg);
}