|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectDLV.Predicate
DLV.JDBCPredicate
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!!!!
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 java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public JDBCPredicate(java.sql.ResultSet rs) throws java.sql.SQLException
rs
- a java.sql.ResultSet.
java.sql.SQLException
- if a database access error occurs.public JDBCPredicate(java.lang.String name, java.sql.ResultSet rs) throws java.sql.SQLException
name
- The name of this predicate.rs
- a java.sql.ResultSet.
java.sql.SQLException
- if a database access error occurs.public JDBCPredicate(java.sql.ResultSet rs, PredicateMetaData pmd) throws java.sql.SQLException
pmd
- a PredicateMetadata descriptor.rs
- a java.sql.ResultSet.
java.sql.SQLException
- if a database access error occurs.public JDBCPredicate(java.lang.String name, java.sql.ResultSet rs, PredicateMetaData pmd) throws java.sql.SQLException
name
- The name of this predicate.pmd
- a PredicateMetadata descriptor.rs
- a java.sql.ResultSet.
java.sql.SQLException
- if a database access error occurs.Method Detail |
public java.sql.ResultSet getResultSet()
public void setQuoted(int i, boolean quoted)
i
- An integer.quoted
- A boolean.
java.lang.IllegalArgumentException
- if i<0 or i>=arity.public boolean getQuoted(int i)
i
- An integer.
java.lang.IllegalArgumentException
- if i<0 or i>=arity.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |