|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.eclipse.datatools.enablement.sybase.asa.schemaobjecteditor.examples.utils.SQLUtil
public class SQLUtil
Utility class for database/SQL related stuff.
Field Summary | |
---|---|
static int |
MATCHING_DOUBLE_QUOTES
|
static int |
MATCHING_SINGLE_QUOTES
|
static int |
MAX_NAME_LENGTH_FOR_MESSAGE_DIALOGS
|
static int |
NO_MATCHING_QUOTES
|
static int |
NO_QUOTES
|
static int |
TYPE_MUTIL_RECORDS
|
static int |
TYPE_XML_RESULT
|
Constructor Summary | |
---|---|
SQLUtil()
|
Method Summary | |
---|---|
static java.lang.String |
addDefOfAss(java.lang.String sql,
org.eclipse.datatools.sqltools.core.DatabaseIdentifier databaseIdentifier,
java.util.Map varDecs,
java.util.ArrayList refWithoutDef)
add definition of assigned params to the orginal SQL string, add the referenced params to list "refWithoutDef". |
static java.lang.String |
addDefOfAssAndRef(java.lang.String sql,
org.eclipse.datatools.sqltools.core.DatabaseIdentifier databaseIdentifier,
java.util.Map varDecs)
add definitions statements of referenced or assigned variables/params to the original sql statement |
static java.lang.String |
constructDetailCALLSPUDFString(org.eclipse.datatools.sqltools.core.ProcIdentifier proc,
java.util.List values,
org.eclipse.datatools.sqltools.core.dbitem.ParameterDescriptor[] pds,
boolean quoted_id)
|
static java.lang.String |
constructSPUDFString(org.eclipse.datatools.sqltools.core.ProcIdentifier proc,
java.util.List values,
org.eclipse.datatools.sqltools.core.dbitem.ParameterDescriptor[] pds,
boolean quoted_id)
|
static java.lang.String |
constructTriggerEventString(org.eclipse.datatools.sqltools.core.ProcIdentifier proc,
java.util.Map values,
boolean quoted_id)
|
static int |
convert2SQLType(java.lang.String typeName)
|
static boolean |
equals(int parserType,
int procType,
java.lang.String objstr,
java.lang.String defDB,
java.lang.String defOwner,
org.eclipse.datatools.sqltools.core.ProcIdentifier proc,
boolean caseSensitive)
Return whether objstr and proc represent the same database object. |
static boolean |
equalsIgnoreQuote(java.lang.String s1,
java.lang.String s2,
boolean caseSensitive)
Returns whether the 2 Strings are equal by ignoring the surrounding quotes |
static int |
findQuotes(java.lang.String content)
|
static java.lang.String[] |
getAvaiableCurrencySymbols()
return the all currencySymbols |
static java.lang.String |
getCallablePrefix(int type)
|
static java.lang.String |
getCallableStatementPrefix(int type)
|
static java.sql.Connection |
getConnection(org.eclipse.datatools.sqltools.core.DatabaseIdentifier databaseIdentifier)
Returns the reusable connection from the control connection. |
static org.eclipse.datatools.sqltools.core.IControlConnection |
getControlConnection(org.eclipse.datatools.sqltools.core.DatabaseIdentifier databaseIdentifier)
Get Control Connection from profile name |
static IDatatype |
getDatatypeByName(java.lang.String typeName,
DBObject[] dTypes)
given the name and UDT list,return the IDatatype object |
static int |
getDefaultPrecision(int sqlType)
|
static int |
getDefaultScale(int sqlType)
|
static char |
getEscapeCharacter(char character)
|
static java.lang.String[] |
getEventParameters(org.eclipse.datatools.sqltools.core.ProcIdentifier proc)
parse the event handler body and return all the parameters of "event_parameter" function(ASA) |
static org.eclipse.datatools.sqltools.core.dbitem.ParameterDescriptor[] |
getParameterDescriptors(org.eclipse.datatools.sqltools.core.DatabaseIdentifier databaseIdentifier,
java.sql.Connection connection,
int type,
org.eclipse.datatools.sqltools.core.ProcIdentifier proc)
|
static char |
getPeerCharacter(char character)
|
static java.lang.String |
getQuotedString(java.lang.String dataType,
java.lang.String inputValue,
org.eclipse.datatools.sqltools.core.DatabaseIdentifier databaseIdentifier)
This method is to convert the String(quoted or unquoted) to quoted String. |
static java.util.Map |
getSPParamDefaultValues(org.eclipse.datatools.sqltools.core.DatabaseIdentifier databaseIdentifier,
java.lang.String sp)
Parse the given sp definition and returns the parameter name/default value pairs. |
static java.util.HashMap |
getSPParams(org.eclipse.datatools.sqltools.core.DatabaseIdentifier databaseIdentifier,
java.lang.String sp)
Parse the given sp definition and returns the parameter name/IASTSQLParam pairs. |
static java.util.Map |
getSPParamTypeNameMapFromParser(org.eclipse.datatools.sqltools.core.DatabaseIdentifier databaseIdentifier,
java.lang.String sp)
|
static int |
getSQLType(org.eclipse.datatools.sqltools.core.ProcIdentifier procId)
|
static int |
getSQLType(SQLEditor sqlEditor)
|
static boolean |
isBinaryType(IDatatype datatype)
|
static boolean |
isBinaryType(java.lang.String datatype)
|
static boolean |
isNumericType(IDatatype datatype)
|
static boolean |
isNumericType(int datatype)
|
static boolean |
isNumericType(java.lang.String datatype)
|
static boolean |
isSameType(int parserType,
int procType)
Return whether the object type represented by parserType and that by procType are of the same type |
static boolean |
isStringType(IDatatype datatype)
|
static boolean |
isStringType(int sqlType)
|
static boolean |
isStringType(java.lang.String datatype)
|
static boolean |
justWarnings(java.sql.SQLException sqlexception)
test whether a SQLException is warning only. |
static java.lang.String[] |
parseDatabaseObject(java.lang.String objstr)
"objstr" is a string representing a database object. |
static java.lang.String |
quote(java.lang.String in,
char quoteChar)
|
static java.lang.String |
quote(java.lang.String content,
java.lang.String quoteMark)
surround content with quoteMark and double every quoteMark inside content |
static java.lang.String |
quoteStringWhenNecessary(java.lang.String objstr)
Quotes the string when it contains space or single quote and is not properly quoted. |
static java.lang.String |
quoteWhenNecessary(java.lang.String content,
org.eclipse.datatools.sqltools.core.DatabaseIdentifier databaseIdentifier)
This is a convenience method of quoteWhenNecessary(String content, DatabaseIdentifier _databaseIdentifier, String
quote) |
static java.lang.String |
quoteWhenNecessary(java.lang.String id,
org.eclipse.datatools.sqltools.core.DatabaseIdentifier databaseIdentifier,
java.lang.String quote)
Checks the validity and quoted identifier setting and surrounds content with proper quotation mark if necessary. |
static java.lang.String |
quoteWhenNecessary(java.lang.String id,
org.eclipse.datatools.sqltools.core.DatabaseIdentifier databaseIdentifier,
java.lang.String quote,
int identiferType)
Checks the validity and quoted identifier setting and surrounds content with proper quotation mark if necessary. |
static java.sql.SQLException |
retrieveDetailException(java.lang.Throwable throwable)
Returns an instance of SQLException containing detailed error information |
static void |
saveResultToStream(java.io.ObjectOutputStream oos,
java.lang.Object result)
|
static java.lang.String |
stripNameForMessages(java.lang.String name)
This method chops out a given String to a string with lenthg MAX_NAME_LENGTH_FOR_MESSAGE_DIALOGS, The usage is when an identifier is too long as much as 255 characters the message dialog cannot accomodate it |
static java.lang.String |
unquote(java.lang.String quoted)
remove the surrounding quotation mark and restore 2 successive quotation marks to 1 |
static java.lang.String |
unquoteWhenNecessary(java.lang.String id,
org.eclipse.datatools.sqltools.core.DatabaseIdentifier databaseIdentifier)
Checks the validity of the unquoted identifier and unquotes content if necessary. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int TYPE_MUTIL_RECORDS
public static final int TYPE_XML_RESULT
public static final int NO_QUOTES
public static final int MATCHING_SINGLE_QUOTES
public static final int MATCHING_DOUBLE_QUOTES
public static final int NO_MATCHING_QUOTES
public static int MAX_NAME_LENGTH_FOR_MESSAGE_DIALOGS
Constructor Detail |
---|
public SQLUtil()
Method Detail |
---|
public static java.lang.String[] parseDatabaseObject(java.lang.String objstr)
objstr
- a string identifying a database object.
public static boolean equals(int parserType, int procType, java.lang.String objstr, java.lang.String defDB, java.lang.String defOwner, org.eclipse.datatools.sqltools.core.ProcIdentifier proc, boolean caseSensitive)
objstr
- proc
-
public static boolean equalsIgnoreQuote(java.lang.String s1, java.lang.String s2, boolean caseSensitive)
s1
- s2
- caseSensitive
- whether to consider case
public static boolean isSameType(int parserType, int procType)
parserType
- type defined in SQLParserContantsprocType
- type defined in ProcIdentifier
public static org.eclipse.datatools.sqltools.core.dbitem.ParameterDescriptor[] getParameterDescriptors(org.eclipse.datatools.sqltools.core.DatabaseIdentifier databaseIdentifier, java.sql.Connection connection, int type, org.eclipse.datatools.sqltools.core.ProcIdentifier proc) throws java.sql.SQLException
con
- type
- runstring
-
java.sql.SQLException
public static java.lang.String[] getEventParameters(org.eclipse.datatools.sqltools.core.ProcIdentifier proc) throws java.sql.SQLException, org.eclipse.datatools.sqltools.core.profile.NoSuchProfileException
profileName
- eventName
-
org.eclipse.datatools.sqltools.core.profile.NoSuchProfileException
java.sql.SQLException
public static java.lang.String getCallablePrefix(int type)
public static java.lang.String getCallableStatementPrefix(int type)
public static java.lang.String constructDetailCALLSPUDFString(org.eclipse.datatools.sqltools.core.ProcIdentifier proc, java.util.List values, org.eclipse.datatools.sqltools.core.dbitem.ParameterDescriptor[] pds, boolean quoted_id)
proc
- can be nulllist
- must be valid value listpds
- quoted_id
-
public static java.lang.String constructSPUDFString(org.eclipse.datatools.sqltools.core.ProcIdentifier proc, java.util.List values, org.eclipse.datatools.sqltools.core.dbitem.ParameterDescriptor[] pds, boolean quoted_id)
proc
- can be nulllist
- must be valid value listpds
- quoted_id
-
public static java.lang.String quote(java.lang.String in, char quoteChar)
public static java.lang.String constructTriggerEventString(org.eclipse.datatools.sqltools.core.ProcIdentifier proc, java.util.Map values, boolean quoted_id)
proc
- can be nullquoted_id
- triggerParams
-
public static boolean justWarnings(java.sql.SQLException sqlexception)
sqlexception
-
public static void saveResultToStream(java.io.ObjectOutputStream oos, java.lang.Object result) throws java.io.IOException
java.io.IOException
public static java.util.Map getSPParamDefaultValues(org.eclipse.datatools.sqltools.core.DatabaseIdentifier databaseIdentifier, java.lang.String sp)
profileName
- used to determine the db typesp
- the sp definition
public static java.util.Map getSPParamTypeNameMapFromParser(org.eclipse.datatools.sqltools.core.DatabaseIdentifier databaseIdentifier, java.lang.String sp)
public static java.util.HashMap getSPParams(org.eclipse.datatools.sqltools.core.DatabaseIdentifier databaseIdentifier, java.lang.String sp)
databaseIdentifier
- used to determine the db typesp
- the sp definition
public static int convert2SQLType(java.lang.String typeName)
public static int getDefaultPrecision(int sqlType)
public static int getDefaultScale(int sqlType)
public static int getSQLType(org.eclipse.datatools.sqltools.core.ProcIdentifier procId)
public static int getSQLType(SQLEditor sqlEditor)
public static java.lang.String getQuotedString(java.lang.String dataType, java.lang.String inputValue, org.eclipse.datatools.sqltools.core.DatabaseIdentifier databaseIdentifier) throws java.lang.Exception
pd
- inputeValue
-
java.lang.Exception
public static int findQuotes(java.lang.String content)
public static java.lang.String quoteStringWhenNecessary(java.lang.String objstr)
objstr
-
public static java.lang.String quoteWhenNecessary(java.lang.String content, org.eclipse.datatools.sqltools.core.DatabaseIdentifier databaseIdentifier)
quoteWhenNecessary(String content, DatabaseIdentifier _databaseIdentifier, String
quote)
content
- original identifier
public static java.lang.String quoteWhenNecessary(java.lang.String id, org.eclipse.datatools.sqltools.core.DatabaseIdentifier databaseIdentifier, java.lang.String quote, int identiferType)
id
- IdentifierdatabaseIdentifier
- database Identfierquote
- quotes, maybe single quote or double quoteIdentifierType
- identfierType,see IIdentfierValidator API
public static java.lang.String quoteWhenNecessary(java.lang.String id, org.eclipse.datatools.sqltools.core.DatabaseIdentifier databaseIdentifier, java.lang.String quote)
id
- original identifier
public static java.lang.String unquoteWhenNecessary(java.lang.String id, org.eclipse.datatools.sqltools.core.DatabaseIdentifier databaseIdentifier)
id
- original identifier
public static java.lang.String quote(java.lang.String content, java.lang.String quoteMark)
content
- quoteMark
-
public static java.lang.String unquote(java.lang.String quoted)
quoted
-
public static char getPeerCharacter(char character)
public static char getEscapeCharacter(char character)
public static IDatatype getDatatypeByName(java.lang.String typeName, DBObject[] dTypes)
typeName
- dTypes
-
public static boolean isBinaryType(IDatatype datatype)
public static boolean isBinaryType(java.lang.String datatype)
public static boolean isNumericType(java.lang.String datatype)
public static boolean isNumericType(int datatype)
public static boolean isNumericType(IDatatype datatype)
public static boolean isStringType(java.lang.String datatype)
public static boolean isStringType(IDatatype datatype)
public static boolean isStringType(int sqlType)
public static java.lang.String addDefOfAss(java.lang.String sql, org.eclipse.datatools.sqltools.core.DatabaseIdentifier databaseIdentifier, java.util.Map varDecs, java.util.ArrayList refWithoutDef)
sql
- databaseIdentifier
-
public static java.lang.String addDefOfAssAndRef(java.lang.String sql, org.eclipse.datatools.sqltools.core.DatabaseIdentifier databaseIdentifier, java.util.Map varDecs)
sql
- databaseIdentifier
- varDecs
-
public static java.sql.Connection getConnection(org.eclipse.datatools.sqltools.core.DatabaseIdentifier databaseIdentifier)
databaseIdentifier
-
public static org.eclipse.datatools.sqltools.core.IControlConnection getControlConnection(org.eclipse.datatools.sqltools.core.DatabaseIdentifier databaseIdentifier)
profile
-
public static java.lang.String[] getAvaiableCurrencySymbols()
public static java.lang.String stripNameForMessages(java.lang.String name)
name
-
public static java.sql.SQLException retrieveDetailException(java.lang.Throwable throwable)
SQLException
containing detailed error information
throwable
-
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |