@Override public Long getValLong(Ident fieldID, Long defaultVal) { Literal lit = getLiteralVal(fieldID, false); if (lit != null) { return lit.getLong(); } else { return defaultVal; } }
public long getLong() { return getLiteral().getLong(); }
public static long getSecondsValue(Resource x, Property p, long ifAbsent) { Statement s = x.getProperty( p ); if (s == null) return ifAbsent; RDFNode n = s.getObject(); if (n.isResource()) return ifAbsent; if (n.asLiteral().getDatatypeURI() == null) { String spelling = n.asLiteral().getLexicalForm(); char last = spelling.charAt(spelling.length() - 1); if (Character.isDigit(last)) { return Long.parseLong(spelling); } else { long l = Long.parseLong(spelling.substring(0, spelling.length() - 1)); return l * scale(last); } } else { return n.asLiteral().getLong(); } }
static public List<ThingActionSpec> reapActionSpecList(SolutionList actionsList, RepoClient rc, Ident srcGraphID, Ident srcAgentID, Logger theLogger) { List<ThingActionSpec> actionSpecList = new ArrayList<ThingActionSpec>(); SolutionHelper sh = new SolutionHelper(); for (Object actionSoln0 : actionsList.javaList()) { Solution actionSoln = (Solution) actionSoln0; Ident actionID = sh.pullIdent(actionSoln, ThingCN.V_actionID); Ident verbID = sh.pullIdent(actionSoln, ThingCN.V_verbID); Ident targetID = sh.pullIdent(actionSoln, ThingCN.V_targetThingID); Ident targetTypeID = sh.pullIdent(actionSoln, ThingCN.V_targetThingTypeID); // calls rc.queryIndirectForAllSolutions(ThingCN.PARAM_QUERY_URI, srcGraphID, ThingCN.V_attachedActionID, actionIdent); // which we want to be transactionally consistent with whatever generated the actionsList. SerTypedValueMap actionParams = buildActionParameterValueMap(rc, srcGraphID, sh, actionID, theLogger); Literal tstampLiteral = actionSoln.getLiteralResultVar(ThingCN.V_postedTStampMsec); Long actionPostedTStampMsec = (tstampLiteral != null) ? tstampLiteral.getLong() : null; ThingActionSpec spec = new BasicThingActionSpec(actionID, targetID, targetTypeID, verbID, srcAgentID, actionParams, actionPostedTStampMsec); theLogger.debug("Found new ThingAction: {}", spec); actionSpecList.add(spec); } return actionSpecList; }
protected List<ThingActionSpec> reapActionSpecList(SolutionList actionsList, RepoClient rc, Ident srcGraphID, Ident srcAgentID) { List<ThingActionSpec> actionSpecList = new ArrayList<ThingActionSpec>(); SolutionHelper sh = new SolutionHelper(); for (Solution actionSoln: actionsList.javaList()) { Ident actionID = sh.pullIdent(actionSoln, ThingCN.V_actionID); Ident verbID = sh.pullIdent(actionSoln, ThingCN.V_verbID); Ident targetID = sh.pullIdent(actionSoln, ThingCN.V_targetThingID); Ident targetTypeID = sh.pullIdent(actionSoln, ThingCN.V_targetThingTypeID); TypedValueMap actionParams = buildActionParameterValueMap(rc, srcGraphID, sh, actionID); Literal tstampLiteral = actionSoln.getLiteralResultVar(ThingCN.V_postedTStampMsec); Long actionPostedTStampMsec = (tstampLiteral != null) ? tstampLiteral.getLong() : null; ThingActionSpec spec = new BasicThingActionSpec(actionID, targetID, targetTypeID, verbID, srcAgentID, actionParams, actionPostedTStampMsec); getLogger().debug("Found new ThingAction: {}", spec); actionSpecList.add(spec); } return actionSpecList; } protected TypedValueMap buildActionParameterValueMap(RepoClient rc, Ident srcGraphID, SolutionHelper sh, Ident actionIdent) {
@Test public void special4() { Dataset ds = create() ; load1(ds.getDefaultModel()) ; load2(ds.getNamedModel("http://example/graph1")) ; load3(ds.getNamedModel("http://example/graph2")) ; Model m = ModelFactory.createDefaultModel() ; load2(m) ; load3(m) ; TDB.sync(ds) ; String qs = "PREFIX : <"+baseNS+"> SELECT (COUNT(?x) as ?c) WHERE { ?x (:p1|:p2) 'x1' }" ; Query q = QueryFactory.create(qs, Syntax.syntaxARQ) ; QueryExecution qExec = QueryExecutionFactory.create(q, ds) ; qExec.getContext().set(TDB.symUnionDefaultGraph, true) ; long c1 = qExec.execSelect().next().getLiteral("c").getLong() ; qExec.close() ; qExec = QueryExecutionFactory.create(q, m) ; long c2 = qExec.execSelect().next().getLiteral("c").getLong() ; assertEquals(c1, c2) ; qExec.close() ; }