xxl.relational
Class Selection

java.lang.Object
  |
  +--xxl.relational.AbstractResultSet
        |
        +--xxl.relational.Selection

public class Selection
extends AbstractResultSet

The operator for selection.
Some tuples of the given ResultSet are selected to the output ResultSet by a specified predicate.

Examples:


	new Selection("name", "!=", "Smith", resultSet);
	
selects all tuples where the value of column "name" is not "Smith".

	new Selection("birth year", ">", new BigDecimal(1960), resultSet);
	
selects all tuples where the year of birth is greater than 1960.


More formally:
A selection predicate is a Function with the following syntax:


	predicate.invoke((Object) tuple)
	
returns The constructor therefor requires only a predicate (as xxl.functions.Function) and a ResultSet.

For more complicated selection predicates another technique is provided:
One can create the predicates like above with static methods "predicate" and then put them together by using the and, or and not methods, that create the special predicates from the given ones.

These boolean methods handle the trivalently logik from SQL. That means, that there are three boolean values: true, false and null.
null represents the value "unknown".

For testing a column of being null there is a static method "isNull". It returns a special predicate.

Examples:


	new Selection( Selection.and(
		Selection.predicate(resultSet.findColumn("name"), "==", "Smith"),
		Selection.predicate(resultSet.findColumn("birth year"), "<=", new BigDecimal(1960))
		), resultSet);
	
selects all "Smith"s who are born before 1961.

	new Selection(Selection.not(Selection.isNull(resultSet.findColumn("birth year"))), resultSet);
	
selects all tuples where "birth year" is not null.


Field Summary
protected  Function predicate
           
protected  java.sql.ResultSet resultSet
           
 
Constructor Summary
Selection(Function predicate, java.sql.ResultSet resultSet)
           
Selection(int columnIndex1, java.lang.String op, int columnIndex2, java.sql.ResultSet resultSet)
           
Selection(int columnIndex, java.lang.String op, java.lang.Object referenceObject, java.sql.ResultSet resultSet)
           
Selection(java.lang.String columnName, java.lang.String op, int columnIndex, java.sql.ResultSet resultSet)
           
Selection(java.lang.String columnName, java.lang.String op, java.lang.Object referenceObject, java.sql.ResultSet resultSet)
           
 
Method Summary
static Function and(Function[] functions)
           
static Function and(Function f1, Function f2)
           
 void close()
           
protected static Function compareToFunction(int cmpValue, int factor, int columnIndex, java.lang.Comparable ref)
           
protected static Function compareToFunction(int cmpValue, int factor, int columnIndex1, int columnIndex2)
           
protected static Function equalsFunction(boolean not, int columnIndex1, int columnIndex2)
           
protected static Function equalsFunction(boolean not, int columnIndex, java.lang.Object ref)
           
 int findColumn(java.lang.String columnName)
           
 byte[] getBytes(int columnIndex)
           
 java.sql.ResultSetMetaData getMetaData()
           
 java.lang.Object getObject(int columnIndex)
           
static Function isNull(int columnIndex)
           
 boolean next()
           
static Function not(Function f)
           
static Function or(Function[] functions)
           
static Function or(Function f1, Function f2)
           
static Function predicate(int columnIndex1, java.lang.String op, int columnIndex2)
           
static Function predicate(int columnIndex, java.lang.String op, java.lang.Object referenceObject)
           
 boolean wasNull()
           
 
Methods inherited from class xxl.relational.AbstractResultSet
absolute, afterLast, beforeFirst, cancelRowUpdates, clearWarnings, deleteRow, first, getArray, getArray, getAsciiStream, getAsciiStream, getBigDecimal, getBigDecimal, getBigDecimal, getBigDecimal, getBinaryStream, getBinaryStream, getBlob, getBlob, getBoolean, getBoolean, getByte, getByte, getBytes, getCharacterStream, getCharacterStream, getClob, getClob, getColumnCount, getConcurrency, getCursorName, getDate, getDate, getDate, getDate, getDouble, getDouble, getFetchDirection, getFetchSize, getFloat, getFloat, getInt, getInt, getLong, getLong, getObject, getObject, getObject, getRef, getRef, getRow, getShort, getShort, getStatement, getString, getString, getTime, getTime, getTime, getTime, getTimestamp, getTimestamp, getTimestamp, getTimestamp, getType, getUnicodeStream, getUnicodeStream, getWarnings, insertRow, isAfterLast, isBeforeFirst, isFirst, isLast, last, moveToCurrentRow, moveToInsertRow, previous, refreshRow, relative, rowDeleted, rowInserted, rowUpdated, setFetchDirection, setFetchSize, updateAsciiStream, updateAsciiStream, updateBigDecimal, updateBigDecimal, updateBinaryStream, updateBinaryStream, updateBoolean, updateBoolean, updateByte, updateByte, updateBytes, updateBytes, updateCharacterStream, updateCharacterStream, updateDate, updateDate, updateDouble, updateDouble, updateFloat, updateFloat, updateInt, updateInt, updateLong, updateLong, updateNull, updateNull, updateObject, updateObject, updateObject, updateObject, updateRow, updateShort, updateShort, updateString, updateString, updateTime, updateTime, updateTimestamp, updateTimestamp
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

resultSet

protected java.sql.ResultSet resultSet

predicate

protected Function predicate
Constructor Detail

Selection

public Selection(Function predicate,
                 java.sql.ResultSet resultSet)

Selection

public Selection(int columnIndex,
                 java.lang.String op,
                 java.lang.Object referenceObject,
                 java.sql.ResultSet resultSet)

Selection

public Selection(java.lang.String columnName,
                 java.lang.String op,
                 java.lang.Object referenceObject,
                 java.sql.ResultSet resultSet)

Selection

public Selection(int columnIndex1,
                 java.lang.String op,
                 int columnIndex2,
                 java.sql.ResultSet resultSet)

Selection

public Selection(java.lang.String columnName,
                 java.lang.String op,
                 int columnIndex,
                 java.sql.ResultSet resultSet)
Method Detail

predicate

public static Function predicate(int columnIndex,
                                 java.lang.String op,
                                 java.lang.Object referenceObject)

predicate

public static Function predicate(int columnIndex1,
                                 java.lang.String op,
                                 int columnIndex2)

isNull

public static Function isNull(int columnIndex)

and

public static Function and(Function f1,
                           Function f2)

and

public static Function and(Function[] functions)

or

public static Function or(Function f1,
                          Function f2)

or

public static Function or(Function[] functions)

not

public static Function not(Function f)

equalsFunction

protected static Function equalsFunction(boolean not,
                                         int columnIndex,
                                         java.lang.Object ref)

equalsFunction

protected static Function equalsFunction(boolean not,
                                         int columnIndex1,
                                         int columnIndex2)

compareToFunction

protected static Function compareToFunction(int cmpValue,
                                            int factor,
                                            int columnIndex,
                                            java.lang.Comparable ref)

compareToFunction

protected static Function compareToFunction(int cmpValue,
                                            int factor,
                                            int columnIndex1,
                                            int columnIndex2)

next

public boolean next()
             throws java.sql.SQLException
Overrides:
next in class AbstractResultSet

getMetaData

public java.sql.ResultSetMetaData getMetaData()
                                       throws java.sql.SQLException
Overrides:
getMetaData in class AbstractResultSet

findColumn

public int findColumn(java.lang.String columnName)
               throws java.sql.SQLException
Overrides:
findColumn in class AbstractResultSet

getObject

public java.lang.Object getObject(int columnIndex)
                           throws java.sql.SQLException
Overrides:
getObject in class AbstractResultSet

getBytes

public byte[] getBytes(int columnIndex)
                throws java.sql.SQLException
Overrides:
getBytes in class AbstractResultSet

wasNull

public boolean wasNull()
                throws java.sql.SQLException
Overrides:
wasNull in class AbstractResultSet

close

public void close()
           throws java.sql.SQLException
Overrides:
close in class AbstractResultSet