Class Statement
- java.lang.Object
-
- com.sun.jdo.spi.persistence.support.sqlstore.sql.generator.Statement
-
- All Implemented Interfaces:
Cloneable
- Direct Known Subclasses:
SelectStatement
,UpdateStatement
public abstract class Statement extends Object implements Cloneable
This class is used to represent a SQL statement.
-
-
Field Summary
Fields Modifier and Type Field Description protected ArrayList
columns
array of ColumnRefprotected InputDesc
inputDesc
protected static ResourceBundle
messages
I18N message handlerprotected static int
OP_BINOP_MASK
protected static int
OP_FUNC_MASK
protected static int
OP_INFIX_MASK
protected static int
OP_IRREGULAR_MASK
protected static int
OP_ORDERBY_MASK
protected static int
OP_OTHER_MASK
protected static int
OP_PARAM_MASK
protected static int
OP_PAREN_MASK
protected static int
OP_PCOUNT_MASK
protected static int
OP_POSTFIX_MASK
protected static int
OP_PREFIX_MASK
protected static int
OP_WHERE_MASK
protected ArrayList
secondaryTableStatements
protected StringBuilder
statementText
ArrayList
tableList
array of QueryTableprotected DBVendorType
vendorType
-
Constructor Summary
Constructors Constructor Description Statement(DBVendorType vendorType)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
addColumnRef(ColumnRef columnRef)
void
addConstraint(LocalFieldDesc lf, Object value)
Adds a comparison on local fieldlf
and valuevalue
.void
addQueryTable(QueryTable table)
void
addSecondaryTableStatement(Statement s)
protected void
appendQuotedText(StringBuilder buffer, String text)
Appendtext
surrounded by quote char tobuffer
void
appendTableText(StringBuilder text, QueryTable table)
void
bindInputValues(DBStatement s)
Binds input valus corrsponding to thisStatement
object to database statement s.Object
clone()
protected QueryTable
findQueryTable(org.netbeans.modules.dbschema.TableElement tableElement)
Matches the table elementtableElement
to the corresponding query table from the listtableList
.protected static String
formatSqlText(String sqlText, Object[] input)
The formatSqlText method returns a string containing the text of the SQL statement about to be executed and the input values for the placeholders.protected void
generateColumnText(LocalFieldDesc desc, QueryPlan thePlan, StringBuilder sb)
Generates the column text for fielddesc
.protected void
generateInputValueForConstraintValueNode(ConstraintValue node)
Generates InputValue fornode
.protected abstract void
generateStatementText()
Generates the SQL text for the query described by this object.int
getAction()
protected ColumnRef
getColumnRef(org.netbeans.modules.dbschema.ColumnElement columnElement)
ArrayList
getColumnRefs()
String
getFormattedSQLText()
Gets formatted sql text corrsponding to this statement object.protected QueryPlan
getOriginalPlan(ConstraintField fieldNode)
abstract QueryPlan
getQueryPlan()
Get QueryPlan for this statementArrayList
getQueryTables()
ArrayList
getSecondaryTableStatements()
String
getText()
Returns the SQL text for the query described by this object.DBVendorType
getVendorType()
protected String
getWhereText(List stack)
Constructs the where clause for the statement from the constraint stack.protected String
infixOperator(int operation, int position)
protected int
operationFormat(int operation)
protected String
postfixOperator(int operation)
protected String
prefixOperator(int operation)
protected void
processConstraintParamIndex(ConstraintParamIndex node, StringBuilder result)
StringBuilder
processConstraints()
Processes the constraint stack and adds it to the query.protected void
processConstraintValue(ConstraintValue node, StringBuilder result)
protected void
processIrregularOperation(ConstraintOperation opNode, int opCode, List stack, StringBuilder result)
protected void
processRootConstraint(ConstraintOperation opNode, List stack, StringBuilder whereText)
void
setAction(int action)
-
-
-
Field Detail
-
OP_PREFIX_MASK
protected static final int OP_PREFIX_MASK
- See Also:
- Constant Field Values
-
OP_INFIX_MASK
protected static final int OP_INFIX_MASK
- See Also:
- Constant Field Values
-
OP_POSTFIX_MASK
protected static final int OP_POSTFIX_MASK
- See Also:
- Constant Field Values
-
OP_PAREN_MASK
protected static final int OP_PAREN_MASK
- See Also:
- Constant Field Values
-
OP_ORDERBY_MASK
protected static final int OP_ORDERBY_MASK
- See Also:
- Constant Field Values
-
OP_WHERE_MASK
protected static final int OP_WHERE_MASK
- See Also:
- Constant Field Values
-
OP_IRREGULAR_MASK
protected static final int OP_IRREGULAR_MASK
- See Also:
- Constant Field Values
-
OP_OTHER_MASK
protected static final int OP_OTHER_MASK
- See Also:
- Constant Field Values
-
OP_PARAM_MASK
protected static final int OP_PARAM_MASK
- See Also:
- Constant Field Values
-
OP_BINOP_MASK
protected static final int OP_BINOP_MASK
- See Also:
- Constant Field Values
-
OP_FUNC_MASK
protected static final int OP_FUNC_MASK
- See Also:
- Constant Field Values
-
OP_PCOUNT_MASK
protected static final int OP_PCOUNT_MASK
- See Also:
- Constant Field Values
-
statementText
protected StringBuilder statementText
-
columns
protected ArrayList columns
array of ColumnRef
-
inputDesc
protected InputDesc inputDesc
-
tableList
public ArrayList tableList
array of QueryTable
-
vendorType
protected DBVendorType vendorType
-
secondaryTableStatements
protected ArrayList secondaryTableStatements
-
messages
protected static final ResourceBundle messages
I18N message handler
-
-
Constructor Detail
-
Statement
public Statement(DBVendorType vendorType)
-
-
Method Detail
-
addQueryTable
public void addQueryTable(QueryTable table)
-
getColumnRef
protected ColumnRef getColumnRef(org.netbeans.modules.dbschema.ColumnElement columnElement)
-
addColumnRef
protected void addColumnRef(ColumnRef columnRef)
-
addConstraint
public void addConstraint(LocalFieldDesc lf, Object value)
Adds a comparison on local fieldlf
and valuevalue
.
-
getVendorType
public DBVendorType getVendorType()
-
appendTableText
public void appendTableText(StringBuilder text, QueryTable table)
-
appendQuotedText
protected void appendQuotedText(StringBuilder buffer, String text)
Appendtext
surrounded by quote char tobuffer
- Parameters:
buffer
- The given buffertext
- The given text
-
getText
public String getText()
Returns the SQL text for the query described by this object.- Returns:
- The text of the SQL query described by this object.
-
generateStatementText
protected abstract void generateStatementText()
Generates the SQL text for the query described by this object.
-
processConstraints
public StringBuilder processConstraints()
Processes the constraint stack and adds it to the query. This means turning the constraint stack into SQL text and adding it to the where clause.- Returns:
- Where clause based on the constraint stack.
-
processRootConstraint
protected void processRootConstraint(ConstraintOperation opNode, List stack, StringBuilder whereText)
-
getQueryPlan
public abstract QueryPlan getQueryPlan()
Get QueryPlan for this statement- Returns:
- QueryPlan for this statement
-
getWhereText
protected String getWhereText(List stack)
Constructs the where clause for the statement from the constraint stack.- Parameters:
stack
- The stack parameter holds the constraint stack to be decoded. RESOLVE: We don't support constraints on multiple statements yet. We would need to sort constraints out by statement and do something about constraints that span statements (e.g. t1.c1 = t2.c2).
-
processConstraintParamIndex
protected void processConstraintParamIndex(ConstraintParamIndex node, StringBuilder result)
-
processConstraintValue
protected void processConstraintValue(ConstraintValue node, StringBuilder result)
-
getOriginalPlan
protected QueryPlan getOriginalPlan(ConstraintField fieldNode)
-
generateColumnText
protected void generateColumnText(LocalFieldDesc desc, QueryPlan thePlan, StringBuilder sb)
Generates the column text for fielddesc
. The column has to be associated to the corresponding query table from the listtableList
. For fields mapped to multiple columns choose one column to be included, as all mapped columns should have the same value.- Parameters:
desc
- Local field descriptor to be included in the constraint text.thePlan
- Query plan corresponding todesc
.sb
- String buffer taking the resulting text.
-
findQueryTable
protected QueryTable findQueryTable(org.netbeans.modules.dbschema.TableElement tableElement)
Matches the table elementtableElement
to the corresponding query table from the listtableList
.- Parameters:
tableElement
- Table element to be found.- Returns:
- Query table object corresponding to table element.
- See Also:
QueryPlan.findQueryTable(TableElement)
-
processIrregularOperation
protected void processIrregularOperation(ConstraintOperation opNode, int opCode, List stack, StringBuilder result)
-
generateInputValueForConstraintValueNode
protected void generateInputValueForConstraintValueNode(ConstraintValue node)
Generates InputValue fornode
.- Parameters:
node
- The input node.
-
infixOperator
protected String infixOperator(int operation, int position)
-
operationFormat
protected int operationFormat(int operation)
-
postfixOperator
protected String postfixOperator(int operation)
-
prefixOperator
protected String prefixOperator(int operation)
-
addSecondaryTableStatement
public void addSecondaryTableStatement(Statement s)
-
getSecondaryTableStatements
public ArrayList getSecondaryTableStatements()
-
getQueryTables
public ArrayList getQueryTables()
-
getColumnRefs
public ArrayList getColumnRefs()
-
setAction
public void setAction(int action)
-
getAction
public int getAction()
-
bindInputValues
public void bindInputValues(DBStatement s) throws SQLException
Binds input valus corrsponding to thisStatement
object to database statement s.- Parameters:
s
- The database statement- Throws:
SQLException
-
getFormattedSQLText
public String getFormattedSQLText()
Gets formatted sql text corrsponding to this statement object. The text also contains values for input to the statement.- Returns:
- formatted sql text corrsponding to this statement object.
-
formatSqlText
protected static String formatSqlText(String sqlText, Object[] input)
The formatSqlText method returns a string containing the text of the SQL statement about to be executed and the input values for the placeholders.- Parameters:
sqlText
- Specifies the text of the SQL statement to be executed.input
- Holds the input values used for the SQL statement.- Returns:
- The SQL text and the input values formatted into a printable string.
-
-