|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectDLV.Predicate
This class allows to handle predicates (which corresponds to tables in a relational database).
A Predicate object may be part of a Model or it can be created to handle the input of DLV in a object oriented modality.
You may use a predicate object which is part of a model as input for a new DLV invocation but if you would modify it without modifying the model you must clone it before using Object.clone()
.
Predicate class stores data in main memory, if you want to store data in a different storage device see JDBCPredicate
and FilePredicate
.
Two interfaces are provided. The first is java.util.Enumeration like the latter is java.sql.ResultSet like.
Ex. 1.1 - How to work with predicates (Enumeration like) ... Model m=... // given a Model object m ... while (m.hasMorePredicates()) {Predicate pred=m.nextPredicate(); // gets a predicate from m while(pred.hasMoreLiterals()) // iterate Literals contained in pred { Literal f=pred.nextLiteral(); // gets a Literal f.invert(); // inverts Literal .. // do something else with f } } Ex. 1.2 - How to work with predicates (ResultSet like) ... Model m=... // given a Model object m ... while (m.next()) {Predicate pred=m.getPredicate(); // gets a predicate from m while(pred.next()) // iterate Literals contained in pred { Literal f=pred.getLiteral(); // gets a Literal f.invert(); // inverts Literal .. // do something else with f } } Ex. 2.1 - How to build a predicate (built in method) // we want build a predicate like that user("John","Red"). user("James","Bond"). Predicate pred=new Predicate("user",2); // builds a Predicate object ( a table ) String[2] terms={"John","Red"}; // adds Literals pred.addLiteral(pred.new Literal(terms)); terms={"James","Bond"} pred.addLiteral(pred.new Literal(terms));Ex. 2.2 - How to build a predicate (ResultSet like method) // we want build a predicate like that user("John","Red"). user("James","Bond"). Predicate pred=new Predicate("user",2); // builds a Predicate object ( a table ) pred.moveToInsertRow(); // add Literals pred.updateString(1,"John"); pred.updateString(2,"Red"); pred.insertRow(); pred.moveToInsertRow(); pred.updateString(1,"James"); pred.updateString(2,"Bond"); pred.insertRow();
JDBCPredicate
,
FilePredicate
,
DlvHandler
,
Model
Nested Class Summary | |
class |
Predicate.Literal
This class represents Literals. |
Constructor Summary | |
Predicate(java.lang.String name,
int arity)
Constructs a new Predicate instance. |
|
Predicate(java.lang.String name,
PredicateMetaData metadata)
Constructs a new Predicate instance described by "meta". |
Method Summary | |
boolean |
absolute(int row)
Moves the cursor to the given "row number" (in a relational view) in this Predicate object. |
void |
addLiteral(Predicate.Literal literal)
This method append a new Literal to this Predicate. |
void |
afterLast()
Moves the cursor to the end of this Predicate object, just after the last Literal. |
void |
appendTo(java.io.PrintWriter out)
This method allows to save this Predicate in the file handled by "out". |
int |
arity()
Returns the arity of this predicate. |
void |
beforeFirst()
Moves the cursor to the front of this Predicate object, just before the first Literal. |
void |
cancelRowUpdates()
Cancels the updates made to the current row in this Predicate object. |
boolean |
first()
This method moves the cursor to the first Literal in this Predicate object. |
Predicate.Literal |
firstLiteral()
This method returns the first literal and sets the cursor at the first position of this Predicate. |
java.math.BigDecimal |
getBigDecimal(int columnIndex)
Gets the value of the designated column in the current row of this Predicate object as a java.math.BigDecimal object in the Java programming language. |
boolean |
getBoolean(int columnIndex)
Gets the value of the designated column in the current row of this Predicate object as a boolean in the Java programming language. |
byte |
getByte(int columnIndex)
Gets the value of the designated column in the current row of this Predicate object as a byte in the Java programming language. |
int |
getCursor()
This method returns the position of current Literal. |
java.sql.Date |
getDate(int columnIndex)
Gets the value of the designated column in the current row of this Predicate object as a java.sql.Date object in the Java programming language. |
double |
getDouble(int columnIndex)
Gets the value of the designated column in the current row of this Predicate object as a double in the Java programming language. |
float |
getFloat(int columnIndex)
Gets the value of the designated column in the current row of this Predicate object as a float in the Java programming language. |
int |
getInt(int columnIndex)
Gets the value of the designated column in the current row of this Predicate object as a int in the Java programming language. |
boolean |
getIsPositive()
Returns true if the i-th Literal is positive. |
boolean |
getIsPositive(int row)
Returns true if the row-th Literal is positive. |
Predicate.Literal |
getLiteral()
Returns the literal currently pointed by the cursor. |
Predicate.Literal |
getLiteral(int i)
Returns the i-th literal. |
java.util.Enumeration |
getLiterals()
This method returns an Enumeration of the Literals of this Predicate. |
long |
getLong(int columnIndex)
Gets the value of the designated column in the current row of this Predicate object as a long in the Java programming language. |
Model |
getModel()
Returns the model which contains this predicate, null otherwise. |
PredicateMetaData |
getPredicateMetaData()
Gets meta information for this Predicate |
int |
getRow()
Retrieves the current row number. |
short |
getShort(int columnIndex)
Gets the value of the designated column in the current row of this Predicate object as a short in the Java programming language. |
java.lang.String |
getString(int columnIndex)
Gets the value of the designated column in the current row of this Predicate object as a String object in the Java programming language. |
java.lang.String |
getTermAt(int i,
int j)
Returns the term contained in the j-th argument of the i-th Literal. |
java.sql.Time |
getTime(int columnIndex)
Gets the value of the designated column in the current row of this Predicate object as a java.sql.Time object in the Java programming language. |
boolean |
hasMoreLiterals()
This method returns true if there are more literals. |
void |
insertRow()
Inserts the contents of the insert row into this Predicate object and into the database. |
boolean |
isFirst()
Indicates whether the cursor is on the first Literal of this Predicate object. |
boolean |
isLast()
Indicates whether the cursor is on the last Literal of this Predicate object. |
boolean |
last()
This method moves the cursor to the last Literal in this Predicate object. |
Predicate.Literal |
lastLiteral()
This method returns the last literal and set the cursor at the last position of this Predicate. |
void |
moveToCurrentRow()
Moves the cursor to the remembered cursor position, usually the current row. |
void |
moveToInsertRow()
|
java.lang.String |
name()
Returns the name of this predicate. |
boolean |
next()
Moves the cursor down one position from its current. |
Predicate.Literal |
nextLiteral()
This method returns the next literal. |
boolean |
previous()
Moves the cursor to the previous Literal in this Predicate object. |
Predicate.Literal |
previousLiteral()
This method returns the previous literal. |
boolean |
relative(int i)
Moves the cursor a relative number of positions, either positive or negative. |
void |
removeLiteral()
This method removes the current literal if it exists, otherwise no operation is performed. |
void |
removeLiteral(int i)
This method removes the i-th literal if it exists, otherwise no operation is performed. |
void |
saveTo(java.lang.String file)
This method allows to save this Predicate in the file "file". |
void |
setIsPositive(int row,
boolean positive)
Updates the designated row (literal) with a boolean value indicating if row-th Literal must be positive. |
void |
setName(java.lang.String name)
Sets predicate name. |
void |
setPredicateMetaData(PredicateMetaData meta)
Sets meta information for this Predicate. |
void |
setTermAt(int i,
int j,
java.lang.String term)
Sets the term contained in the j-th argument of the i-th Literal. |
int |
size()
Returns the size of this predicate (number of tuples in a "relational view"). |
java.lang.String |
toString()
|
void |
updateBigDecimal(int columnIndex,
java.math.BigDecimal x)
Updates the designated column with a |
void |
updateBoolean(int columnIndex,
boolean x)
Updates the designated column with a boolean value. |
void |
updateByte(int columnIndex,
byte x)
Updates the designated column with an byte value. |
void |
updateDate(int columnIndex,
java.sql.Date x)
Updates the designated column with a java.sql.Date value.
|
void |
updateDouble(int columnIndex,
double x)
Updates the designated column with a double value. |
void |
updateFloat(int columnIndex,
float x)
Updates the designated column with a Float value. |
void |
updateInt(int columnIndex,
int x)
Updates the designated column with an int value. |
void |
updateIsPositive(boolean positive)
Updates the designated row (literal) with a boolean value indicating if current Literal must be positive. |
void |
updateLiteral(int i,
Predicate.Literal literal)
This method updates (replace) the i-th literal if it exists, otherwise NoSuchLiteralException is thrown. |
void |
updateLiteral(Predicate.Literal literal)
This method updates (replace) the literal currently pointed by the cursor if it exists, otherwise NoSuchLiteralException is thrown. |
void |
updateLong(int columnIndex,
long x)
Updates the designated column with a long value. |
void |
updateNull(int columnIndex)
Gives a nullable column a null value. |
void |
updateRow()
Updates the underlying Predicate object with the new contents of the current row. |
void |
updateShort(int columnIndex,
short x)
Updates the designated column with a Short value. |
void |
updateString(int columnIndex,
java.lang.String x)
Updates the designated column with a String value. |
void |
updateTime(int columnIndex,
java.sql.Time x)
Updates the designated column with a Time value. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public Predicate(java.lang.String name, int arity)
name
- Is the name of this predicate.arity
- Is the arity of this predicate.
java.lang.NullPointerException
- if "name" is null.public Predicate(java.lang.String name, PredicateMetaData metadata)
name
- Is the name of this predicate.metadata
- A PredicateMetaData object.
java.lang.NullPointerException
- if "name" is null.Method Detail |
public void setName(java.lang.String name)
name
- A predicate name.public void setPredicateMetaData(PredicateMetaData meta)
meta
- A PredicateMetaData object.
BadArityException
- if "meta" is invalid.public PredicateMetaData getPredicateMetaData()
public java.lang.String name()
public int arity()
public int size()
public Model getModel()
public java.lang.String getTermAt(int i, int j)
i
- identifies the i-th Literal.j
- identifies the j-th argument.
NoSuchLiteralException
- if you try to get a Literal which doesn't exist.
NoSuchTermException
- if you try to get a term which doesn't exist.public void setTermAt(int i, int j, java.lang.String term)
i
- identifies the i-th Literal.j
- identifies the j-th argument.term
- a term.
NoSuchLiteralException
- if you try to get a Literal which doesn't exist.
NoSuchTermException
- if you try to get a term which doesn't exist.
MalformedtermException
- if the term "term" is malformed.public Predicate.Literal getLiteral()
NoSuchLiteralException
- if you try to get a Literal which doesn't exist.public Predicate.Literal getLiteral(int i)
NoSuchLiteralException
- if you try to get a Literal which doesn't exist.public void updateLiteral(Predicate.Literal literal)
literal
- the new version of the literal.
NoSuchLiteralException
- if you try to update a literal which doesn't exist.
BadArityException
- if term length is less than the arity of the Predicate.
TrueNegationNotSupportedException
- if you try to insert a negative literal and the implementation of the current Predicate does not support true negation.public void updateLiteral(int i, Predicate.Literal literal)
literal
- the new version of the i-th literal.
NoSuchLiteralException
- if you try to update a literal which doesn't exist.
BadArityException
- if term length is less than the arity of the Predicate.
java.lang.NullPointerException
- if literal is null.
TrueNegationNotSupportedException
- if you try to insert a negative literal and the implementation of the current Predicate does not support true negation.public void removeLiteral()
public void removeLiteral(int i)
i
- the position of the literal that you would remove from this Predicate.public void addLiteral(Predicate.Literal literal)
literal
- The Literal object you would add.
java.lang.NullPointerException
- if "literal" is null
BadArityException
- if "literal" arity differs from the arity of this Predicate.
TrueNegationNotSupportedException
- if you try to insert a negative literal and the implementation of the current Predicate does not support true negation.public boolean hasMoreLiterals()
public Predicate.Literal nextLiteral()
NoSuchLiteralException
- if you try to get a literal which doesn't exist.public Predicate.Literal previousLiteral()
NoSuchLiteralException
- if you try to get a literal which doesn't exist.public Predicate.Literal firstLiteral()
NoSuchLiteralException
- if you try to get a literal which doesn't exist.public Predicate.Literal lastLiteral()
NoSuchLiteralException
- if you try to get a literal which doesn't exist.public int getCursor()
public boolean first()
public boolean last()
public void beforeFirst()
public void afterLast()
public boolean isFirst()
public boolean isLast()
public boolean relative(int i)
public boolean previous()
public boolean next()
public int getRow()
0
if there is no current rowpublic boolean absolute(int row)
If the given row number is negative, the cursor moves to an absolute row position with respect to
the end of the result set. For example, calling absolute(-1)
positions the
cursor on the last row (the cursor points the last Literal); calling absolute(-2)
moves the cursor to the next-to-last row (the cursor points the next-to-last Literal), and so on.
An attempt to position the cursor beyond the first/last row in the Predicate leaves the cursor before the first Literal or after the last Literal.
Note: Calling absolute(1)
is the same
as calling first()
. Calling absolute(-1)
is the same as calling last()
.
row
- the number of the row which the cursor should move to.
A positive number indicates the row number counting from the
beginning of the Predicate; a negative number indicates the
row number counting from the end of the Predicate
true
if the cursor is on the Predicate;
false
otherwisepublic void saveTo(java.lang.String file) throws java.io.IOException
java.io.IOException
- if an error occurs during file creation.public void appendTo(java.io.PrintWriter out)
java.io.IOException
- if an error occurs processing "out".public java.util.Enumeration getLiterals()
public java.lang.String toString()
public boolean getIsPositive(int row)
row
- identifies the row-th Literal.
NoSuchLiteralException
- if you try to get a Literal which doesn't exist.public void setIsPositive(int row, boolean positive)
row
- A row.positive
- true if row-th literal must be a positive literal, false otherwise.
NoSuchLiteralException
- if you try to update a Literal which doesn't exist.
TrueNegationNotSupportedException
- if the implementation of the current Predicate does not support true negation and positive is false.public boolean getIsPositive()
NoSuchLiteralException
- if you try to get a Literal which doesn't exist.public void updateIsPositive(boolean positive)
positive
- A boolean.
NoSuchLiteralException
- if you try to get a Literal which doesn't exist.
TrueNegationNotSupportedException
- if the implementation of the current Predicate does not support true negation and positive is false.public void updateBoolean(int columnIndex, boolean x)
columnIndex
- The first column is 1, the second is 2, ...x
- The new column value.public void updateBigDecimal(int columnIndex, java.math.BigDecimal x)
columnIndex
- The first column is 1, the second is 2, ...x
- The new column value.public void updateByte(int columnIndex, byte x)
columnIndex
- The first column is 1, the second is 2, ...x
- The new column value.public void updateDate(int columnIndex, java.sql.Date x)
java.sql.Date
value.
The updateXXX methods are used to update column values in the current row or the insert row.
The updateXXX methods do not update the underlying Predicate; instead the updateRow or insertRow methods are called to update the Predicate.
columnIndex
- The first column is 1, the second is 2, ...x
- The new column value.public void updateDouble(int columnIndex, double x)
columnIndex
- The first column is 1, the second is 2, ...x
- The new column value.public void updateFloat(int columnIndex, float x)
columnIndex
- The first column is 1, the second is 2, ...x
- The new column value.public void updateInt(int columnIndex, int x)
columnIndex
- The first column is 1, the second is 2, ...x
- The new column value.public void updateLong(int columnIndex, long x)
columnIndex
- The first column is 1, the second is 2, ...x
- The new column value.public void updateNull(int columnIndex)
columnIndex
- The first column is 1, the second is 2, ...public void updateShort(int columnIndex, short x)
columnIndex
- The first column is 1, the second is 2, ...x
- The new column value.public void updateString(int columnIndex, java.lang.String x)
columnIndex
- The first column is 1, the second is 2, ...x
- The new column value.public void updateTime(int columnIndex, java.sql.Time x)
columnIndex
- The first column is 1, the second is 2, ...x
- The new column value.public boolean getBoolean(int columnIndex)
columnIndex
- The first column is 1, the second is 2, ...
public java.math.BigDecimal getBigDecimal(int columnIndex)
columnIndex
- The first column is 1, the second is 2, ...
public byte getByte(int columnIndex)
columnIndex
- The first column is 1, the second is 2, ...
public java.sql.Date getDate(int columnIndex)
columnIndex
- The first column is 1, the second is 2, ...
public double getDouble(int columnIndex)
columnIndex
- The first column is 1, the second is 2, ...
public float getFloat(int columnIndex)
columnIndex
- The first column is 1, the second is 2, ...
public int getInt(int columnIndex)
columnIndex
- The first column is 1, the second is 2, ...
public long getLong(int columnIndex)
columnIndex
- The first column is 1, the second is 2, ...
public short getShort(int columnIndex)
columnIndex
- The first column is 1, the second is 2, ...
public java.lang.String getString(int columnIndex)
columnIndex
- The first column is 1, the second is 2, ...
public java.sql.Time getTime(int columnIndex)
columnIndex
- The first column is 1, the second is 2, ...
public void moveToInsertRow()
public void cancelRowUpdates()
public void moveToCurrentRow()
public void insertRow()
public void updateRow()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |