edu.stanford.smi.protegex.owl.swrl.bridge.query
Class ResultImpl
java.lang.Object
edu.stanford.smi.protegex.owl.swrl.bridge.query.ResultImpl
- All Implemented Interfaces:
- Result, ResultGenerator
public class ResultImpl
- extends Object
- implements ResultGenerator, Result
This class implements the interfaces Result and ResultGenerator. It can be used to generate a result structure and populate it with data;
it can also be used to retrieve those data from the result.
This class operates in three phases:
(1) Configuration Phase: In this phase the structure of the result is defined. This phase opened by a call to the configure() method (which
will also clear any existing data). In this phase the columns are defined; aggregation or ordering is also specified in this phase. This
phase is closed by a call to the configured() method.
(2) Preparation Phase: In this phase data are added to the result. This phase is implicitly opened by the call to the configured() method. It
is closed by a call to the prepared() method.
The interface ResultGenerator defines the calls used in these two phases.
(3) Processing Phase: In this phase data may be retrieved from the result. This phase is implicitly opened by the call to the closed()
method.
The interface Result defines the calls used in the processing phase.
An example configuration and data generation is:
Result result = new ResultImpl("TestResult");
result.addColumn("name");
result.addAggregateColumn("average", ResultGenerator.AvgAggregateFunction);
result.configured();
result.openRow();
result.addData(new IndividualInfo("Fred"));
result.addData(new LiteralInfo(27));
result.closeRow();
result.openRow();
result.addData(new IndividualInfo("Joe"));
result.addData(new LiteralInfo(34));
result.closeRow();
result.openRow();
result.addData(new IndividualInfo("Joe"));
result.addData(new LiteralInfo(21));
result.closeRow();
result.prepared();
The result is now available for reading. The interface Result defines the assessor methods. A row consists of a list of objects defined
by the interface ResultValue. There are four possible types of values (1) DatatypeValue, representing literals; (2) ObjectValue,
representing OWL individuals; (3) ClassValue, representing OWL classes; and (4) PropertyValue, representing OWL properties.
while (result.hasNext()) {
ObjectValue nameValue = result.getObjectValue("name");
DatatypeValue averageValue = result.getDatatypeValue("average");
System.out.println("Name: " + nameValue.getIndividualName());
System.out.println("Average: " + averageValue.getInt());
} // while
A convenience method addColumns that takes a list of column names is also supplied.
There is also a convenience method addRow, which takes a list of ResultValues. This method automatically does a row open and close. It
is expecting the exact same number of list elements as there are columns in the result.
ResultImpl
public ResultImpl()
isConfigured
public boolean isConfigured()
- Specified by:
isConfigured
in interface ResultGenerator
isRowOpen
public boolean isRowOpen()
- Specified by:
isRowOpen
in interface ResultGenerator
isDistinct
public boolean isDistinct()
isPrepared
public boolean isPrepared()
- Specified by:
isPrepared
in interface ResultGenerator
isOrdered
public boolean isOrdered()
- Specified by:
isOrdered
in interface ResultGenerator
isAscending
public boolean isAscending()
- Specified by:
isAscending
in interface ResultGenerator
initialize
public void initialize()
- Specified by:
initialize
in interface ResultGenerator
addColumns
public void addColumns(List<String> columnNames)
throws ResultException
- Specified by:
addColumns
in interface ResultGenerator
- Throws:
ResultException
addColumn
public void addColumn(String columnName)
throws ResultException
- Specified by:
addColumn
in interface ResultGenerator
- Throws:
ResultException
addAggregateColumn
public void addAggregateColumn(String columnName,
String aggregateFunctionName)
throws ResultException
- Specified by:
addAggregateColumn
in interface ResultGenerator
- Throws:
ResultException
addOrderByColumn
public void addOrderByColumn(int orderedColumnIndex,
boolean ascending)
throws ResultException
- Specified by:
addOrderByColumn
in interface ResultGenerator
- Throws:
ResultException
addColumnDisplayName
public void addColumnDisplayName(String columnName)
throws ResultException
- Specified by:
addColumnDisplayName
in interface ResultGenerator
- Throws:
ResultException
configured
public void configured()
throws ResultException
- Specified by:
configured
in interface ResultGenerator
- Throws:
ResultException
setIsDistinct
public void setIsDistinct()
- Specified by:
setIsDistinct
in interface ResultGenerator
getNumberOfColumns
public int getNumberOfColumns()
throws ResultException
- Specified by:
getNumberOfColumns
in interface Result
- Throws:
ResultException
getColumnNames
public List<String> getColumnNames()
throws ResultException
- Specified by:
getColumnNames
in interface Result
- Throws:
ResultException
getColumnName
public String getColumnName(int columnIndex)
throws ResultException
- Specified by:
getColumnName
in interface Result
- Throws:
ResultException
addRow
public void addRow(List<ResultValue> resultValues)
throws ResultException
- Specified by:
addRow
in interface ResultGenerator
- Throws:
ResultException
openRow
public void openRow()
throws ResultException
- Specified by:
openRow
in interface ResultGenerator
- Throws:
ResultException
addRowData
public void addRowData(ResultValue value)
throws ResultException
- Specified by:
addRowData
in interface ResultGenerator
- Throws:
ResultException
closeRow
public void closeRow()
throws ResultException
- Specified by:
closeRow
in interface ResultGenerator
- Throws:
ResultException
prepared
public void prepared()
throws ResultException
- Specified by:
prepared
in interface ResultGenerator
- Throws:
ResultException
getNumberOfRows
public int getNumberOfRows()
throws ResultException
- Specified by:
getNumberOfRows
in interface Result
- Throws:
ResultException
reset
public void reset()
throws ResultException
- Specified by:
reset
in interface Result
- Throws:
ResultException
next
public void next()
throws ResultException
- Specified by:
next
in interface Result
- Throws:
ResultException
hasNext
public boolean hasNext()
throws ResultException
- Specified by:
hasNext
in interface Result
- Throws:
ResultException
getRow
public List<ResultValue> getRow()
throws ResultException
- Specified by:
getRow
in interface Result
- Throws:
ResultException
getValue
public ResultValue getValue(String columnName)
throws ResultException
- Specified by:
getValue
in interface Result
- Throws:
ResultException
getValue
public ResultValue getValue(int columnIndex)
throws ResultException
- Specified by:
getValue
in interface Result
- Throws:
ResultException
getValue
public ResultValue getValue(int columnIndex,
int rowIndex)
throws ResultException
- Specified by:
getValue
in interface Result
- Throws:
ResultException
getObjectValue
public ObjectValue getObjectValue(String columnName)
throws ResultException
- Specified by:
getObjectValue
in interface Result
- Throws:
ResultException
getObjectValue
public ObjectValue getObjectValue(int columnIndex)
throws ResultException
- Specified by:
getObjectValue
in interface Result
- Throws:
ResultException
getDatatypeValue
public DatatypeValue getDatatypeValue(String columnName)
throws ResultException
- Specified by:
getDatatypeValue
in interface Result
- Throws:
ResultException
getClassValue
public ClassValue getClassValue(String columnName)
throws ResultException
- Specified by:
getClassValue
in interface Result
- Throws:
ResultException
getClassValue
public ClassValue getClassValue(int columnIndex)
throws ResultException
- Specified by:
getClassValue
in interface Result
- Throws:
ResultException
getPropertyValue
public PropertyValue getPropertyValue(int columnIndex)
throws ResultException
- Specified by:
getPropertyValue
in interface Result
- Throws:
ResultException
getPropertyValue
public PropertyValue getPropertyValue(String columnName)
throws ResultException
- Specified by:
getPropertyValue
in interface Result
- Throws:
ResultException
getDatatypeValue
public DatatypeValue getDatatypeValue(int columnIndex)
throws ResultException
- Specified by:
getDatatypeValue
in interface Result
- Throws:
ResultException
getColumn
public List<ResultValue> getColumn(String columnName)
throws ResultException
- Specified by:
getColumn
in interface Result
- Throws:
ResultException
getColumn
public List<ResultValue> getColumn(int columnIndex)
throws ResultException
- Specified by:
getColumn
in interface Result
- Throws:
ResultException
hasObjectValue
public boolean hasObjectValue(String columnName)
throws ResultException
- Specified by:
hasObjectValue
in interface Result
- Throws:
ResultException
hasObjectValue
public boolean hasObjectValue(int columnIndex)
throws ResultException
- Specified by:
hasObjectValue
in interface Result
- Throws:
ResultException
hasDatatypeValue
public boolean hasDatatypeValue(String columnName)
throws ResultException
- Specified by:
hasDatatypeValue
in interface Result
- Throws:
ResultException
hasDatatypeValue
public boolean hasDatatypeValue(int columnIndex)
throws ResultException
- Specified by:
hasDatatypeValue
in interface Result
- Throws:
ResultException
hasClassValue
public boolean hasClassValue(String columnName)
throws ResultException
- Specified by:
hasClassValue
in interface Result
- Throws:
ResultException
hasClassValue
public boolean hasClassValue(int columnIndex)
throws ResultException
- Specified by:
hasClassValue
in interface Result
- Throws:
ResultException
hasPropertyValue
public boolean hasPropertyValue(String columnName)
throws ResultException
- Specified by:
hasPropertyValue
in interface Result
- Throws:
ResultException
hasPropertyValue
public boolean hasPropertyValue(int columnIndex)
throws ResultException
- Specified by:
hasPropertyValue
in interface Result
- Throws:
ResultException
toString
public String toString()
- Overrides:
toString
in class Object
Submit a bug report or feature request
Copyright (c) 1998-2007 Stanford University.