Package org.teiid.translator.jdbc
Class SQLConversionVisitor
- java.lang.Object
-
- org.teiid.language.visitor.AbstractLanguageVisitor
-
- org.teiid.language.visitor.SQLStringVisitor
-
- org.teiid.translator.jdbc.SQLConversionVisitor
-
- All Implemented Interfaces:
LanguageObjectVisitor
,SQLStringVisitor.Substitutor
- Direct Known Subclasses:
HiveSQLConversionVisitor
,PhoenixSQLConversionVisitor
,PISQLConversionVisitor
,PostgreSQLConversionVisitor
,TeradataSQLConversionVisitor
public class SQLConversionVisitor extends SQLStringVisitor implements SQLStringVisitor.Substitutor
This visitor takes an ICommand and does DBMS-specific conversion on it to produce a SQL String. This class is expected to be subclassed.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.teiid.language.visitor.SQLStringVisitor
SQLStringVisitor.Substitutor
-
-
Field Summary
Fields Modifier and Type Field Description static String
TEIID_NON_PREPARED
-
Fields inherited from class org.teiid.language.visitor.SQLStringVisitor
buffer, shortNameOnly, TEIID_NATIVE_QUERY, UNDEFINED, UNDEFINED_PARAM
-
-
Constructor Summary
Constructors Constructor Description SQLConversionVisitor(JDBCExecutionFactory ef)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addBinding(LanguageObject value)
Add a bind ? value to the sql string and to the binding value listvoid
append(LanguageObject obj)
Appends the string form of the LanguageObject to the current buffer.protected void
appendBaseName(NamedTable obj)
protected void
appendLateralKeyword()
protected void
appendSetOperation(SetQuery.Operation operation)
protected void
generateSqlForStoredProcedure(Call exec)
This is a generic implementation.protected ExecutionContext
getExecutionContext()
Retrieve the per-command execution context for this visitor (intended for subclasses to use).protected String
getLikeRegexString()
protected String
getSourceComment(Command command)
protected boolean
isNonAscii(String val)
boolean
isPrepared()
boolean
isUsingBinding()
protected String
removeCharacters(String value)
protected String
replaceElementName(String group, String element)
Take the specified derived group and element short names and determine a replacement element name to use instead.void
setExecutionContext(ExecutionContext context)
Set the per-command execution context on this visitor.void
setPrepared(boolean prepared)
void
substitute(Argument arg, StringBuilder builder, int index)
protected void
translateSQLType(Class<?> type, Object obj, StringBuilder valuesbuffer)
For the given type, append a literal SQL valueprotected boolean
useAsInGroupAlias()
Indicates whether group alias should be of the form "...FROM groupA AS X" or "...FROM groupA X".protected boolean
useParensForJoins()
protected boolean
useParensForSetQueries()
protected boolean
useSelectLimit()
protected boolean
useUnicodePrefix()
void
visit(Call obj)
void
visit(Comparison obj)
void
visit(DerivedColumn obj)
void
visit(ExpressionValueSource obj)
void
visit(Function obj)
void
visit(GroupBy obj)
void
visit(In obj)
void
visit(Like obj)
void
visit(Literal obj)
void
visit(Parameter obj)
void
visit(SearchedCase obj)
void
visit(SetClause obj)
-
Methods inherited from class org.teiid.language.visitor.SQLStringVisitor
append, append, appendCallStart, appendLiteral, appendNestedCondition, appendQuantifier, appendRightComparison, appendSetQuery, appendWithKeyword, escapeString, getInsertKeyword, getName, getRecordName, getShortName, getSQLString, getUpsertKeyword, isInfixFunction, parseNativeQueryParts, shouldNestSetChild, toString, useParensForLHSJoins, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit
-
Methods inherited from class org.teiid.language.visitor.AbstractLanguageVisitor
visit, visitNode, visitNodes, visitNodes
-
-
-
-
Field Detail
-
TEIID_NON_PREPARED
public static final String TEIID_NON_PREPARED
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SQLConversionVisitor
public SQLConversionVisitor(JDBCExecutionFactory ef)
-
-
Method Detail
-
append
public void append(LanguageObject obj)
Description copied from class:SQLStringVisitor
Appends the string form of the LanguageObject to the current buffer.- Overrides:
append
in classSQLStringVisitor
- Parameters:
obj
- the language object instance
-
translateSQLType
protected void translateSQLType(Class<?> type, Object obj, StringBuilder valuesbuffer)
For the given type, append a literal SQL value- Parameters:
type
-obj
-valuesbuffer
-
-
isNonAscii
protected boolean isNonAscii(String val)
-
useUnicodePrefix
protected boolean useUnicodePrefix()
-
visit
public void visit(Call obj)
- Specified by:
visit
in interfaceLanguageObjectVisitor
- Overrides:
visit
in classSQLStringVisitor
- See Also:
SQLStringVisitor.visit(org.teiid.language.Call)
-
visit
public void visit(Function obj)
- Specified by:
visit
in interfaceLanguageObjectVisitor
- Overrides:
visit
in classSQLStringVisitor
-
visit
public void visit(Parameter obj)
- Specified by:
visit
in interfaceLanguageObjectVisitor
- Overrides:
visit
in classSQLStringVisitor
-
addBinding
protected void addBinding(LanguageObject value)
Add a bind ? value to the sql string and to the binding value list
-
visit
public void visit(Literal obj)
- Specified by:
visit
in interfaceLanguageObjectVisitor
- Overrides:
visit
in classSQLStringVisitor
- See Also:
SQLStringVisitor.visit(org.teiid.language.Literal)
-
visit
public void visit(In obj)
- Specified by:
visit
in interfaceLanguageObjectVisitor
- Overrides:
visit
in classSQLStringVisitor
-
visit
public void visit(Like obj)
- Specified by:
visit
in interfaceLanguageObjectVisitor
- Overrides:
visit
in classSQLStringVisitor
-
visit
public void visit(Comparison obj)
- Specified by:
visit
in interfaceLanguageObjectVisitor
- Overrides:
visit
in classSQLStringVisitor
-
visit
public void visit(ExpressionValueSource obj)
- Specified by:
visit
in interfaceLanguageObjectVisitor
- Overrides:
visit
in classSQLStringVisitor
-
visit
public void visit(SetClause obj)
- Specified by:
visit
in interfaceLanguageObjectVisitor
- Overrides:
visit
in classSQLStringVisitor
-
visit
public void visit(DerivedColumn obj)
- Specified by:
visit
in interfaceLanguageObjectVisitor
- Overrides:
visit
in classSQLStringVisitor
-
visit
public void visit(SearchedCase obj)
- Specified by:
visit
in interfaceLanguageObjectVisitor
- Overrides:
visit
in classSQLStringVisitor
-
setExecutionContext
public void setExecutionContext(ExecutionContext context)
Set the per-command execution context on this visitor.- Parameters:
context
- ExecutionContext- Since:
- 4.3
-
getExecutionContext
protected ExecutionContext getExecutionContext()
Retrieve the per-command execution context for this visitor (intended for subclasses to use).- Returns:
- Since:
- 4.3
-
getSourceComment
protected String getSourceComment(Command command)
- Overrides:
getSourceComment
in classSQLStringVisitor
-
generateSqlForStoredProcedure
protected void generateSqlForStoredProcedure(Call exec)
This is a generic implementation. Subclass should override this method if necessary.- Parameters:
exec
- The command for the stored procedure.
-
isPrepared
public boolean isPrepared()
-
setPrepared
public void setPrepared(boolean prepared)
-
isUsingBinding
public boolean isUsingBinding()
-
useAsInGroupAlias
protected boolean useAsInGroupAlias()
Description copied from class:SQLStringVisitor
Indicates whether group alias should be of the form "...FROM groupA AS X" or "...FROM groupA X". Certain data sources (such as Oracle) may not support the first form.- Overrides:
useAsInGroupAlias
in classSQLStringVisitor
- Returns:
- boolean
-
useParensForSetQueries
protected boolean useParensForSetQueries()
- Overrides:
useParensForSetQueries
in classSQLStringVisitor
-
replaceElementName
protected String replaceElementName(String group, String element)
Description copied from class:SQLStringVisitor
Take the specified derived group and element short names and determine a replacement element name to use instead. Most commonly, this is used to strip the group name if the group is a pseudo-group (DUAL) or the element is a pseudo-group (ROWNUM). It may also be used to strip special information out of the name in source value in some specialized cases. By default, this method returns null, indicating that the normal group and element name logic should be used (group + "." + element). Subclasses should override and implement this method if desired.- Overrides:
replaceElementName
in classSQLStringVisitor
- Parameters:
group
- Group name, may be nullelement
- Element name, never null- Returns:
- Replacement element name to be used as is (no modification will occur)
-
appendSetOperation
protected void appendSetOperation(SetQuery.Operation operation)
- Overrides:
appendSetOperation
in classSQLStringVisitor
-
useParensForJoins
protected boolean useParensForJoins()
- Overrides:
useParensForJoins
in classSQLStringVisitor
-
useSelectLimit
protected boolean useSelectLimit()
- Overrides:
useSelectLimit
in classSQLStringVisitor
-
getLikeRegexString
protected String getLikeRegexString()
- Overrides:
getLikeRegexString
in classSQLStringVisitor
-
appendBaseName
protected void appendBaseName(NamedTable obj)
- Overrides:
appendBaseName
in classSQLStringVisitor
-
substitute
public void substitute(Argument arg, StringBuilder builder, int index)
- Specified by:
substitute
in interfaceSQLStringVisitor.Substitutor
-
visit
public void visit(GroupBy obj)
- Specified by:
visit
in interfaceLanguageObjectVisitor
- Overrides:
visit
in classSQLStringVisitor
-
appendLateralKeyword
protected void appendLateralKeyword()
- Overrides:
appendLateralKeyword
in classSQLStringVisitor
-
-