com.caucho.db.sql
Class Expr

java.lang.Object
  extended by com.caucho.db.sql.Expr
Direct Known Subclasses:
ExistsEvalExpr, FunExpr, GroupResultExpr, SubSelectEvalExpr, SubSelectExpr, SubSelectParamExpr

@Module
public abstract class Expr
extends java.lang.Object


Field Summary
static int FALSE
           
protected static L10N L
           
static int TRUE
           
static int UNKNOWN
           
 
Constructor Summary
Expr()
           
 
Method Summary
 Expr bind(Query query)
           
 long cost(java.util.ArrayList<FromItem> fromList)
          Returns the cost based on the given FromList.
 com.caucho.db.sql.Order createOrder(int index)
          Returns the order.
 int evalBoolean(QueryContext context)
          Evaluates the expression as a boolean.
 byte[] evalBytes(QueryContext context)
          Evaluates the expression as a stream.
 long evalDate(QueryContext context)
          Evaluates the expression as a date.
 double evalDouble(QueryContext context)
          Evaluates the expression as a double.
 boolean evalEqual(QueryContext context, byte[] data)
           
 boolean evalEqual(QueryContext context, java.lang.String evalString)
           
 void evalGroup(QueryContext context)
          Evaluates aggregate functions during the group phase.
 long evalLong(QueryContext context)
          Evaluates the expression as a long.
 java.io.InputStream evalStream(QueryContext context)
          Evaluates the expression as a stream.
 java.lang.String evalString(QueryContext context)
          Evaluates the expression as a string.
 int evalToBuffer(QueryContext context, byte[] buffer, int offset)
          Evaluates the expression to a buffer
 int evalToBuffer(QueryContext context, byte[] buffer, int off, Column.ColumnType columnType)
          Evaluates the expression to a buffer
 void evalToResult(QueryContext context, SelectResult result)
          Evaluates the expression, writing to the result stream.
 com.caucho.db.sql.RowIterateExpr getIndexExpr(FromItem fromItem)
          Returns an index expression if available.
 java.lang.String getName()
          Returns any column name.
 int getSQLType()
          Returns the column type.
 Table getTable()
          Returns the table.
 java.lang.Class<?> getType()
          Returns the expected result type of the expression.
 Column.ColumnType getTypeCode()
          Returns the java type code if known.
 long indexCost(java.util.ArrayList<FromItem> costItems)
          Returns the cost bonus for an index.
 long indexSubCost(java.util.ArrayList<FromItem> costItems)
          Returns the cost bonus for an index.
 void initGroup(QueryContext context)
          Initializes aggregate functions during the group phase.
 boolean isBinaryStream(QueryContext context)
          Returns true if the expression returns a binary stream.
 boolean isBoolean()
          Returns true if the expression returns a boolean.
 boolean isDouble()
          Returns true if the expression returns a double.
 boolean isLong()
          Returns true if the expression returns a long.
 boolean isNull(QueryContext context)
          Returns true if result is null
 boolean isNullable()
          Returns true if the expression can return a null value.
 boolean isParam()
          Returns true for a parameter expression.
 boolean isSelect(QueryContext context)
          Returns true if the expression selects the row.
 void splitAnd(java.util.ArrayList<Expr> andProduct)
          Splits the expr into and blocks.
 long subCost(java.util.ArrayList<FromItem> fromList)
          Returns the cost based on the given FromList.
 void updateDouble(QueryContext context, double value)
          Updates the expression as a double
 void updateLong(QueryContext context, long value)
          Updates the expression as a long
 void updateString(QueryContext context, java.lang.String value)
          Updates the expression as a string
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

L

protected static final L10N L

UNKNOWN

public static final int UNKNOWN
See Also:
Constant Field Values

FALSE

public static final int FALSE
See Also:
Constant Field Values

TRUE

public static final int TRUE
See Also:
Constant Field Values
Constructor Detail

Expr

public Expr()
Method Detail

bind

public Expr bind(Query query)
          throws java.sql.SQLException
Throws:
java.sql.SQLException

getType

public java.lang.Class<?> getType()
Returns the expected result type of the expression.


getTypeCode

public Column.ColumnType getTypeCode()
Returns the java type code if known.


isLong

public boolean isLong()
Returns true if the expression returns a long.


isDouble

public boolean isDouble()
Returns true if the expression returns a double.


isBoolean

public boolean isBoolean()
Returns true if the expression returns a boolean.


isBinaryStream

public boolean isBinaryStream(QueryContext context)
Returns true if the expression returns a binary stream.


isParam

public boolean isParam()
Returns true for a parameter expression.


isNullable

public boolean isNullable()
Returns true if the expression can return a null value.


getName

public java.lang.String getName()
Returns any column name.


getSQLType

public int getSQLType()
Returns the column type.


getTable

public Table getTable()
Returns the table.


splitAnd

public void splitAnd(java.util.ArrayList<Expr> andProduct)
Splits the expr into and blocks.


cost

public long cost(java.util.ArrayList<FromItem> fromList)
Returns the cost based on the given FromList.


subCost

public long subCost(java.util.ArrayList<FromItem> fromList)
Returns the cost based on the given FromList.


indexCost

public long indexCost(java.util.ArrayList<FromItem> costItems)
Returns the cost bonus for an index.


indexSubCost

public long indexSubCost(java.util.ArrayList<FromItem> costItems)
Returns the cost bonus for an index.


getIndexExpr

public com.caucho.db.sql.RowIterateExpr getIndexExpr(FromItem fromItem)
Returns an index expression if available.


createOrder

public com.caucho.db.sql.Order createOrder(int index)
Returns the order.


isNull

public boolean isNull(QueryContext context)
               throws java.sql.SQLException
Returns true if result is null

Parameters:
rows - the current database tuple
Returns:
true if null
Throws:
java.sql.SQLException

isSelect

public boolean isSelect(QueryContext context)
                 throws java.sql.SQLException
Returns true if the expression selects the row.

Parameters:
rows - the current database tuple
Returns:
the boolean value
Throws:
java.sql.SQLException

evalBoolean

public int evalBoolean(QueryContext context)
                throws java.sql.SQLException
Evaluates the expression as a boolean.

Parameters:
rows - the current database tuple
Returns:
the boolean value
Throws:
java.sql.SQLException

evalString

public java.lang.String evalString(QueryContext context)
                            throws java.sql.SQLException
Evaluates the expression as a string.

Parameters:
rows - the current database tuple
Returns:
the string value
Throws:
java.sql.SQLException

updateString

public void updateString(QueryContext context,
                         java.lang.String value)
                  throws java.sql.SQLException
Updates the expression as a string

Throws:
java.sql.SQLException

evalLong

public long evalLong(QueryContext context)
              throws java.sql.SQLException
Evaluates the expression as a long.

Parameters:
rows - the current database tuple
Returns:
the long value
Throws:
java.sql.SQLException

updateLong

public void updateLong(QueryContext context,
                       long value)
                throws java.sql.SQLException
Updates the expression as a long

Throws:
java.sql.SQLException

evalDouble

public double evalDouble(QueryContext context)
                  throws java.sql.SQLException
Evaluates the expression as a double.

Parameters:
rows - the current database tuple
Returns:
the double value
Throws:
java.sql.SQLException

updateDouble

public void updateDouble(QueryContext context,
                         double value)
                  throws java.sql.SQLException
Updates the expression as a double

Throws:
java.sql.SQLException

evalDate

public long evalDate(QueryContext context)
              throws java.sql.SQLException
Evaluates the expression as a date.

Parameters:
rows - the current database tuple
Returns:
the double value
Throws:
java.sql.SQLException

evalToResult

public void evalToResult(QueryContext context,
                         SelectResult result)
                  throws java.sql.SQLException
Evaluates the expression, writing to the result stream.

Parameters:
result - the output result
Throws:
java.sql.SQLException

evalStream

public java.io.InputStream evalStream(QueryContext context)
                               throws java.sql.SQLException
Evaluates the expression as a stream.

Parameters:
rows - the current database tuple
Returns:
the string value
Throws:
java.sql.SQLException

evalBytes

public byte[] evalBytes(QueryContext context)
                 throws java.sql.SQLException
Evaluates the expression as a stream.

Parameters:
rows - the current database tuple
Returns:
the string value
Throws:
java.sql.SQLException

evalToBuffer

public int evalToBuffer(QueryContext context,
                        byte[] buffer,
                        int offset)
                 throws java.sql.SQLException
Evaluates the expression to a buffer

Parameters:
result - the result buffer
Returns:
the length of the result
Throws:
java.sql.SQLException

evalToBuffer

public int evalToBuffer(QueryContext context,
                        byte[] buffer,
                        int off,
                        Column.ColumnType columnType)
                 throws java.sql.SQLException
Evaluates the expression to a buffer

Parameters:
result - the result buffer
Returns:
the length of the result
Throws:
java.sql.SQLException

initGroup

public void initGroup(QueryContext context)
               throws java.sql.SQLException
Initializes aggregate functions during the group phase.

Parameters:
context - the current database tuple
Throws:
java.sql.SQLException

evalGroup

public void evalGroup(QueryContext context)
               throws java.sql.SQLException
Evaluates aggregate functions during the group phase.

Parameters:
context - the current database tuple
Throws:
java.sql.SQLException

evalEqual

public boolean evalEqual(QueryContext context,
                         java.lang.String evalString)
                  throws java.sql.SQLException
Throws:
java.sql.SQLException

evalEqual

public boolean evalEqual(QueryContext context,
                         byte[] data)
                  throws java.sql.SQLException
Throws:
java.sql.SQLException