DLV
Class JDBCPredicate

java.lang.Object
  extended byDLV.Predicate
      extended byDLV.JDBCPredicate

public class JDBCPredicate
extends Predicate

This class allows to handle ground predicates stored in realtional database tables. This class provides database import/export feature through JDBC.
Please note that JDBCPredicates are Predicates, the only difference is the storage device used to store EDB.
The JDBCPredicate handles a java.sql.ResultSet to get-put data from a realtional database. You must build the java.sql.ResultSet object externally specifying in an SQL statement data to be handled.

YOU MUST USE ResultSet.TYPE_SCROLL_INSENSITIVE and ResultSet.CONCUR_UPDATABLE options when you build a java.sql.Statement
VERY IMPORTANTLY YOU CAN EXPORT DATA ONLY IF THE QUERY SPECIFIED IN THE RESULT SET CONTAINS ALL PRIMARY KEYS (accoriding to JDBC 2.1 API Specification) AND IS PERFORMED ON A SIGLE TABLE (NO JOINS)

Notice that true negation is not supported by this Predicate implementation and you cannot store predicates with arity 0 (like p.). The JDBCPredicate class never closes the underlying ResultSet object, you must take care of this fact.

In order to import non constant string from databases, you can set the quoted property for each term of a JDBCPredicate. If the i-th term is quoted the underlying implementation automatically adds quotes when import data from database and remove quotes when export data to dadabase. This feature works only if you set ConversionType.STRING type in the predicate metadata for the i-th term, otherwise the quoted property is ignored. Please note that JDBC interface counts columns starting from 1, conversely setQuoted() and getQuoted counts columns strting from 0. Very important, we add quotes only if necessary (double quoted strings like ""string"" are non valid DLV strings), this could lead to inconsistencies, an example follows.
Ex. Import the string (long string example) from a database column with quoted property set:
long string example == is imported as ==> "long string example" == is exported as ==> long string example
but
"long string example" == is imported as ==> "long string example" == is exported as ==> long string example
In the second case JDBCPredicate changes the original string.
There is an important side effect if you set quoted property for a term. An example follows:
The following two staements have the same effect if you suppose that the quoted property is set for first term of predicate "pred".
pred.addLiteral(pred.new Literal(new String[]{"ggg","jjjj"}));
and pred.addLiteral(pred.new Literal(new String[]{"\"ggg\"","jjjj"}));
That is, both statements add "pred("ggg",jjjj)." literal!!!!

Version:
3.0
Author:
Francesco Ricca
See Also:
Predicate, FilePredicate, DlvHandler, Model, java.sql.ResultSet, java.sql.Statement

Nested Class Summary
 
Nested classes inherited from class DLV.Predicate
Predicate.Literal
 
Constructor Summary
JDBCPredicate(java.sql.ResultSet rs)
          Builds a JDBCPredicate from a java.sql.ResultSet object.
JDBCPredicate(java.sql.ResultSet rs, PredicateMetaData pmd)
          Builds a JDBCPredicate, described by PredicateMetadata object "pmd", from a java.sql.ResultSet object.
JDBCPredicate(java.lang.String name, java.sql.ResultSet rs)
          Builds a JDBCPredicate from a java.sql.ResultSet object.
JDBCPredicate(java.lang.String name, java.sql.ResultSet rs, PredicateMetaData pmd)
          Builds a JDBCPredicate, described by PredicateMetadata object "pmd", from a java.sql.ResultSet object.
 
Method Summary
 boolean getQuoted(int i)
          Gets the quoted property for the i-th term.
 java.sql.ResultSet getResultSet()
          Gets the underlying java.sql.ResultSet obejct.
 void setQuoted(int i, boolean quoted)
          Sets the quoted property for the i-th term.
 
Methods inherited from class DLV.Predicate
absolute, addLiteral, afterLast, appendTo, arity, beforeFirst, cancelRowUpdates, first, firstLiteral, getBigDecimal, getBoolean, getByte, getCursor, getDate, getDouble, getFloat, getInt, getIsPositive, getIsPositive, getLiteral, getLiteral, getLiterals, getLong, getModel, getPredicateMetaData, getRow, getShort, getString, getTermAt, getTime, hasMoreLiterals, insertRow, isFirst, isLast, last, lastLiteral, moveToCurrentRow, moveToInsertRow, name, next, nextLiteral, previous, previousLiteral, relative, removeLiteral, removeLiteral, saveTo, setIsPositive, setName, setPredicateMetaData, setTermAt, size, toString, updateBigDecimal, updateBoolean, updateByte, updateDate, updateDouble, updateFloat, updateInt, updateIsPositive, updateLiteral, updateLiteral, updateLong, updateNull, updateRow, updateShort, updateString, updateTime
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JDBCPredicate

public JDBCPredicate(java.sql.ResultSet rs)
              throws java.sql.SQLException
Builds a JDBCPredicate from a java.sql.ResultSet object.
Name, arity and PredicateMetadata are automatically built from the java.sqlResultSetMetadata associated with "rs".

Parameters:
rs - a java.sql.ResultSet.
Throws:
java.sql.SQLException - if a database access error occurs.

JDBCPredicate

public JDBCPredicate(java.lang.String name,
                     java.sql.ResultSet rs)
              throws java.sql.SQLException
Builds a JDBCPredicate from a java.sql.ResultSet object.
Arity and PredicateMetadata are automatically built from the java.sqlResultSetMetadata associated with "rs".

Parameters:
name - The name of this predicate.
rs - a java.sql.ResultSet.
Throws:
java.sql.SQLException - if a database access error occurs.

JDBCPredicate

public JDBCPredicate(java.sql.ResultSet rs,
                     PredicateMetaData pmd)
              throws java.sql.SQLException
Builds a JDBCPredicate, described by PredicateMetadata object "pmd", from a java.sql.ResultSet object.
Name and Arity are automatically built from the java.sqlResultSetMetadata associated with "rs".

Parameters:
pmd - a PredicateMetadata descriptor.
rs - a java.sql.ResultSet.
Throws:
java.sql.SQLException - if a database access error occurs.

JDBCPredicate

public JDBCPredicate(java.lang.String name,
                     java.sql.ResultSet rs,
                     PredicateMetaData pmd)
              throws java.sql.SQLException
Builds a JDBCPredicate, described by PredicateMetadata object "pmd", from a java.sql.ResultSet object.
Name and Arity are automatically built from the java.sqlResultSetMetadata associated with "rs".

Parameters:
name - The name of this predicate.
pmd - a PredicateMetadata descriptor.
rs - a java.sql.ResultSet.
Throws:
java.sql.SQLException - if a database access error occurs.
Method Detail

getResultSet

public java.sql.ResultSet getResultSet()
Gets the underlying java.sql.ResultSet obejct.

Returns:
The underlying java.sql.ResultSet obejct.

setQuoted

public void setQuoted(int i,
                      boolean quoted)
Sets the quoted property for the i-th term.

Parameters:
i - An integer.
quoted - A boolean.
Throws:
java.lang.IllegalArgumentException - if i<0 or i>=arity.

getQuoted

public boolean getQuoted(int i)
Gets the quoted property for the i-th term.

Parameters:
i - An integer.
Returns:
The quoted property for the i-th term.
Throws:
java.lang.IllegalArgumentException - if i<0 or i>=arity.