📄 dbqueryhandler.java
字号:
{
DBPattern cheapSource = null;
boolean haveConnectedPattern = false;
int minCost = DBPattern.costMax, minConnCost = DBPattern.costMax;
int selectedPatternIndex = -1;
for (int i = 0; i < patternsToDo.size(); i++)
{
DBPattern unstaged = sources[((Integer) patternsToDo.get( i )).intValue()];
int cost = unstaged.cost( varMap );
if (unstaged.isConnected())
{
if (cost < minConnCost)
{
cheapSource = unstaged;
minConnCost = cost;
haveConnectedPattern = true;
selectedPatternIndex = i;
}
}
else if (haveConnectedPattern == false && cost < minCost)
{
minCost = cost;
cheapSource = unstaged;
selectedPatternIndex = i;
}
}
if (cheapSource == null)
throw new JenaException( "impossible: no cheapest pattern among sources" );
cheapSource.setBusy();
patternsToDo.remove( selectedPatternIndex );
return cheapSource;
}
/**
Answer an array of database pattern objects, each associated with
the specialised graphs that might contain the triples it's trying to
match.
*/
private DBPattern[] createDBPatterns( Mapping varMap, Triple[] givenTriples )
{
DBPattern[] sources = new DBPattern[givenTriples.length];
int reifBehavior = graph.reificationBehavior();
for (int i = 0; i < givenTriples.length; i += 1)
sources[i] = createInitialPattern( varMap, reifBehavior, givenTriples[i] );
return sources;
}
private DBPattern createInitialPattern( Mapping varMap, int reifBehavior, Triple triple )
{
DBPattern src = new DBPattern( triple, varMap );
associateWithSources( src, triple, reifBehavior );
return src;
}
/**
Associate the database pattern <code>src</code> with the sources
which might contain triples it would match.
*/
private void associateWithSources( DBPattern src, Triple pat, int reifBehavior )
{
Iterator it = graph.getSpecializedGraphs();
while (it.hasNext())
{
SpecializedGraph sg = (SpecializedGraph) it.next();
char sub = sg.subsumes( pat, reifBehavior );
if (sub != SpecializedGraph.noTriplesForPattern) src.sourceAdd( sg, sub );
if (sub == SpecializedGraph.allTriplesForPattern) break;
}
}
// getters/setters for query handler options
public void setQueryOnlyAsserted ( boolean opt ) {
if ( (opt == true) && (queryOnlyReif==true) )
throw new JenaException("QueryOnlyAsserted and QueryOnlyReif cannot both be true");
queryOnlyStmt = opt;
}
public boolean getQueryOnlyAsserted() {
return queryOnlyStmt;
}
public void setQueryOnlyReified ( boolean opt ) {
// System.err.println( ">> setQueryOnlyReified: style of graph is " + graph.getReifier().getStyle() );
if ( graph.reificationBehavior() != GraphRDB.OPTIMIZE_ALL_REIFICATIONS_AND_HIDE_NOTHING )
throw new JenaException( "Reified statements cannot be queried for this model's reification style: " + graph.getReifier().getStyle() );
if ( (opt == true) && (queryOnlyStmt==true) )
throw new JenaException("QueryOnlyAsserted and QueryOnlyReif cannot both be true");
queryOnlyReif = opt;
}
public boolean getQueryOnlyReified() {
return queryOnlyReif;
}
public void setQueryFullReified ( boolean opt ) {
if ( graph.reificationBehavior() != GraphRDB.OPTIMIZE_ALL_REIFICATIONS_AND_HIDE_NOTHING )
throw new JenaException("Reified statements cannot be queried for this model's reification style");
queryFullReif = opt;
}
public boolean getQueryFullReified() {
return queryFullReif;
}
private boolean findConstraints ( ExpressionSet constraints, ExpressionSet evalCons, VarDesc vx ) {
boolean res = false;
Iterator it = constraints.iterator();
Expression e;
while (it.hasNext()) {
e = (Expression) it.next();
if (e.isApply() && e.argCount() == 2) {
Expression l = e.getArg(0);
if ( l.isVariable() && vx.var.getName().equals(l.getName()) ) {
String f = e.getFun();
if ( dbPartiallyHandlesExpression( f ) ) {
evalCons.add(e);
// for now, constraints must be reevaluated outside the
// db engine since the db engine may not fully evaluate
// the constraint.
// it.remove();
res = true;
}
}
}
}
return res;
}
/**
Answer true if the database makes at least a partial attempt to evaluate
this constraint.
*/
private boolean dbPartiallyHandlesExpression( String f )
{
return f.equals(ExpressionFunctionURIs.J_startsWith) ||
f.equals(ExpressionFunctionURIs.J_startsWithInsensitive) ||
f.equals(ExpressionFunctionURIs.J_contains) ||
f.equals(ExpressionFunctionURIs.J_containsInsensitive) ||
f.equals(ExpressionFunctionURIs.J_EndsWith) ||
f.equals(ExpressionFunctionURIs.J_endsWithInsensitive);
}
protected static final class StageSequence extends Stage
{
private final int numStages;
private final Stage[] stages;
protected StageSequence( List stages )
{
this.numStages = stages.size();
this.stages = (Stage []) stages.toArray( new Stage[this.numStages] );
}
public Stage connectFrom( Stage s )
{
for (int i = 0; i < numStages; i += 1)
{
stages[i].connectFrom( s );
s = stages[i];
}
return super.connectFrom( s );
}
public Pipe deliver( Pipe L )
{ return stages[numStages - 1].deliver( L ); }
}
}
/*
(c) Copyright 2002, 2002, 2003, 2004, 2005, 2006, 2007 Hewlett-Packard Development Company, LP
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -