📄 querytreenode.java
字号:
* is out of date. * * @return An optimized QueryTree * * @exception StandardException Thrown on error */ public QueryTreeNode optimize() throws StandardException { return this; } /** * this implementation of generate() is * a place-holder until all of the nodes that need to, * implement it. Only the root, statement nodes * implement this flavor of generate; the other nodes * will implement the version that returns Generators * and takes an activation class builder as an * argument. * * @param ignored - ignored (he he) * * @return A GeneratedClass for this statement * * @exception StandardException Thrown on error */ public GeneratedClass generate(ByteArray ignored) throws StandardException { throw StandardException.newException(SQLState.LANG_UNABLE_TO_GENERATE, this.nodeHeader()); } /** * Do the code generation for this node. This is a place-holder * method - it should be over-ridden in the sub-classes. * * @param acb The ActivationClassBuilder for the class being built * @param mb The method for the generated code to go into * * @exception StandardException Thrown on error */ protected void generate( ActivationClassBuilder acb, MethodBuilder mb) throws StandardException { throw StandardException.newException(SQLState.LANG_UNABLE_TO_GENERATE, this.nodeHeader()); } /** * Only DML statements have result descriptions - for all others * return null. This method is overridden in DMLStatementNode. * * @return null * * @exception StandardException never actually thrown here, * but thrown by subclasses */ public ResultDescription makeResultDescription() throws StandardException { return null; } /** * Parameter info is stored in the compiler context. * Hide this from the callers. * * * @return null * * @exception StandardException on error */ public DataTypeDescriptor[] getParameterTypes() throws StandardException { return getCompilerContext().getParameterTypes(); } /** * This creates a class that will do the work that's constant * across all Executions of a PreparedStatement. It's up to * our subclasses to override this method if they need to compile * constant actions into PreparedStatements. * * @exception StandardException Thrown on failure */ public ConstantAction makeConstantAction() throws StandardException { return null; } /** * Returns whether or not this Statement requires a set/clear savepoint * around its execution. The following statement "types" do not require them: * Cursor - unnecessary and won't work in a read only environment * Xact - savepoint will get blown away underneath us during commit/rollback * <p> * ONLY CALLABLE AFTER GENERATION * * @return boolean Whether or not this Statement requires a set/clear savepoint */ public boolean needsSavepoint() { return true; } /** * Returns the name of statement in EXECUTE STATEMENT command. * Returns null for all other commands. * @return String null unless overridden for Execute Statement command */ public String executeStatementName() { return null; } /** * Returns name of schema in EXECUTE STATEMENT command. * Returns null for all other commands. * @return String schema for EXECUTE STATEMENT null for all others */ public String executeSchemaName() { return null; } /** * Set the node type for this node. * * @param nodeType The node type. * * @return Nothing. */ public void setNodeType(int nodeType) { this.nodeType = nodeType; } protected int getNodeType() { return nodeType; } /** * For final nodes, return whether or not * the node represents the specified nodeType. * * @param nodeType The nodeType of interest. * * @return Whether or not * the node represents the specified nodeType. */ protected boolean isInstanceOf(int nodeType) { return (this.nodeType == nodeType); } /** * Get the DataDictionary * * @return The DataDictionary * */ public final DataDictionary getDataDictionary() { return getLanguageConnectionContext().getDataDictionary(); } public final DependencyManager getDependencyManager() { return getDataDictionary().getDependencyManager(); } /** * Get the CompilerContext * * @return The CompilerContext */ protected final CompilerContext getCompilerContext() { return (CompilerContext) getContextManager(). getContext(CompilerContext.CONTEXT_ID); } /** * Get the TypeCompiler associated with the given TypeId * * @param typeId The TypeId to get a TypeCompiler for * * @return The corresponding TypeCompiler * */ protected final TypeCompiler getTypeCompiler(TypeId typeId) { return getCompilerContext().getTypeCompilerFactory().getTypeCompiler(typeId); } /** * Accept a visitor, and call v.visit() * on child nodes as necessary. * * @param v the visitor * * @exception StandardException on error */ public Visitable accept(Visitor v) throws StandardException { return v.visit(this); } /** * Get the int value of a Property * * @param value Property value as a String * @param key Key value of property * * @return The int value of the property * * @exception StandardException Thrown on failure */ protected int getIntProperty(String value, String key) throws StandardException { int intVal = -1; try { intVal = Integer.parseInt(value); } catch (NumberFormatException nfe) { throw StandardException.newException(SQLState.LANG_INVALID_NUMBER_FORMAT_FOR_OVERRIDE, value, key); } return intVal; } /** * Parse some query text and return a parse tree. * * @param compilerContext The CompilerContext to use * @param createViewText Query text to parse. * @param paramDefaults array of parameter defaults used to * initialize parameter nodes, and ultimately * for the optimization of statements with * parameters. * @param lcc Current LanguageConnectionContext * * @return ResultSetNode The parse tree. * * @exception StandardException Thrown on error */ public static QueryTreeNode parseQueryText ( CompilerContext compilerContext, String queryText, Object[] paramDefaults, LanguageConnectionContext lcc ) throws StandardException { LanguageConnectionFactory lcf; Parser p; QueryTreeNode qtn; p = compilerContext.getParser(); /* Get a Statement to pass to the parser */ lcf = lcc.getLanguageConnectionFactory(); /* Finally, we can call the parser */ qtn = (QueryTreeNode)p.parseStatement(queryText, paramDefaults); return qtn; } /** * Return the type of statement, something from * StatementType. * * @return the type of statement */ protected int getStatementType() { return StatementType.UNKNOWN; } public boolean foundString(String[] list, String search) { if (list == null) { return false; } for (int i = 0; i < list.length; i++) { if (list[i].equals(search)) { return true; } } return false; } /** * Get a ConstantNode to represent a typed null value * * @param typeId The TypeId of the datatype of the null value * @param cm The ContextManager * * @return A ConstantNode with the specified type, and a value of null * * @exception StandardException Thrown on error */ public ConstantNode getNullNode(TypeId typeId, ContextManager cm) throws StandardException { QueryTreeNode constantNode = null; NodeFactory nf = getNodeFactory(); switch (typeId.getJDBCTypeId()) { case Types.VARCHAR: constantNode = nf.getNode( C_NodeTypes.VARCHAR_CONSTANT_NODE, typeId, cm); break; case Types.CHAR: constantNode = nf.getNode( C_NodeTypes.CHAR_CONSTANT_NODE, typeId, cm); break; case Types.TINYINT: constantNode = nf.getNode( C_NodeTypes.TINYINT_CONSTANT_NODE, typeId, cm); break; case Types.SMALLINT: constantNode = nf.getNode( C_NodeTypes.SMALLINT_CONSTANT_NODE, typeId, cm); break; case Types.INTEGER: constantNode = nf.getNode( C_NodeTypes.INT_CONSTANT_NODE, typeId, cm); break; case Types.BIGINT: constantNode = nf.getNode( C_NodeTypes.LONGINT_CONSTANT_NODE, typeId, cm); break; case Types.REAL: constantNode = nf.getNode( C_NodeTypes.FLOAT_CONSTANT_NODE, typeId, cm); break; case Types.DOUBLE: constantNode = nf.getNode( C_NodeTypes.DOUBLE_CONSTANT_NODE, typeId, cm); break; case Types.NUMERIC: case Types.DECIMAL: constantNode = nf.getNode( C_NodeTypes.DECIMAL_CONSTANT_NODE, typeId, cm); break; case Types.DATE: case Types.TIME: case Types.TIMESTAMP: constantNode = nf.getNode( C_NodeTypes.USERTYPE_CONSTANT_NODE, typeId, cm); break; case Types.BINARY: constantNode = nf.getNode( C_NodeTypes.BIT_CONSTANT_NODE, typeId, cm); break; case Types.VARBINARY: constantNode = nf.getNode( C_NodeTypes.VARBIT_CONSTANT_NODE, typeId, cm); break; case Types.LONGVARCHAR: constantNode = nf.getNode( C_NodeTypes.LONGVARCHAR_CONSTANT_NODE, typeId, cm); break; case Types.CLOB: constantNode = nf.getNode( C_NodeTypes.CLOB_CONSTANT_NODE, typeId, cm); break; case Types.LONGVARBINARY: constantNode = nf.getNode( C_NodeTypes.LONGVARBIT_CONSTANT_NODE, typeId, cm); break; case Types.BLOB: constantNode = nf.getNode( C_NodeTypes.BLOB_CONSTANT_NODE, typeId, cm); break; case StoredFormatIds.XML_TYPE_ID: constantNode = nf.getNode( C_NodeTypes.XML_CONSTANT_NODE, typeId, cm); break; default: if (typeId.getSQLTypeName().equals("BOOLEAN")) { constantNode = nf.getNode( C_NodeTypes.BOOLEAN_CONSTANT_NODE, typeId, cm); } else if ( ! typeId.builtIn()) { constantNode = nf.getNode( C_NodeTypes.USERTYPE_CONSTANT_NODE, typeId, cm); } else { if (SanityManager.DEBUG) SanityManager.THROWASSERT( "Unknown type " + typeId.getSQLTypeName() + " in getNullNode"); return null; } } return (ConstantNode) constantNode; } /** * Translate a Default node into a default value, given a type descriptor. * * @param typeDescriptor A description of the required data type. * * @exception StandardException Thrown on error */ public DataValueDescriptor convertDefaultNode(DataTypeDescriptor typeDescriptor) throws StandardException { /* ** Override in cases where node type ** can be converted to default value. */ return null; } /* Initializable methods */ /** * Initialize a query tree node. * * @exception StandardException Thrown on error */ public void init(Object arg1) throws StandardException { if (SanityManager.DEBUG) { SanityManager.THROWASSERT("Single-argument init() not implemented for " + getClass().getName()); } } /** * Initialize a query tree node. * * @exception StandardException Thrown on error */ public void init(Object arg1, Object arg2) throws StandardException { if (SanityManager.DEBUG) { SanityManager.THROWASSERT("Two-argument init() not implemented for " + getClass().getName()); } } /** * Initialize a query tree node. * * @exception StandardException Thrown on error */ public void init(Object arg1, Object arg2, Object arg3) throws StandardException { if (SanityManager.DEBUG) { SanityManager.THROWASSERT("Three-argument init() not implemented for " + getClass().getName()); } } /** * Initialize a query tree node. *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -