Class SqlUtil
java.lang.Object
net.sf.jailer.util.SqlUtil
-
Field Summary
FieldsModifier and TypeFieldDescriptionList of all jailer tables (upper case).List of all jailer tables (upper case).static final longstatic final longstatic final longstatic final longstatic final StringCondition formulated in standard SQL that is always fulfilled.Maps SQL types fromTypesto clear text types. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringcolumnLabel(Quoting quoting, Session session, DBMS targetDBMSConfiguration, Table table, String columnLabel) Gets the properly quoted column label for use in a SQL statement.static StringcreateSQLFragmentSearchPattern(String sql, boolean withFlags) Creates a regular expression pattern that matches a SQL fragment, ignoring differences in whitespace and case.static intgetColumnType(ResultSet resultSet, ResultSetMetaData resultSetMetaData, String columnName, Map<String, Integer> typeCache) Gets type of column from result-set.static intgetColumnType(DBMS configuration, ResultSet resultSet, ResultSetMetaData resultSetMetaData, int i, Map<Integer, Integer> typeCache) Gets type of column from result-set.static CharsetGets the default character set for SQL script files, taking the native encoding system property into account.static intindexOfDot(String fullName) Gets the index of the schema-table name separator dot in a fully qualified table name.static booleanisLetterOrDigit(char c) Checks whether a character is a letter, digit, or underscore as used in SQL identifiers.static StringmappedSchema(Map<String, String> schemaMapping, String tableName) Replaces schema of qualified table name according to a schema-map.static StringNormalizes a restriction condition by reordering the column references into a canonical form.Reads a table-list from CSV-file.static StringremoveComments(String statement) Removes comments from SQL statement.static StringremoveCommentsAndLiterals(String statement) Removes comments and literals from SQL statement.static StringremoveNonMeaningfulFragments(String sqlStatement) Removes all non-meaningful fragments of an SQL statement that might interfere with the SQL parser (comments, literals, etc.).static StringremoveSubQueries(String sqlSelect) Removes sub-queries from SQL statement.static StringreplaceAlias(String condition, String alias) Replaces the alias T with given alias in a SQL-condition.static StringreplaceAliases(String condition, String aliasA, String aliasB) Replaces the aliases A and B with given aliases in a SQL-condition.static StringresolvePseudoColumns(String condition, int today, int birthdayOfSubject, boolean reversed, boolean inDeleteMode) Resolves the pseudo-columns in a restriction condition.static StringresolvePseudoColumns(String condition, String entityAAlias, String entityBAlias, int today, int birthdayOfSubject, boolean inDeleteMode) Resolves the pseudo-columns in a restriction condition.static StringresolvePseudoColumns(String condition, String entityAAlias, String entityBAlias, int today, int birthdayOfSubject, String birthdayColumnName, Boolean inDeleteMode) Resolves the pseudo-columns in a restriction condition.static CharsetretrieveEncoding(String scriptFileName) Retrieves SQL script file encoding.static StringreversRestrictionCondition(String condition) Change alias A to B and B to A in a SQL-condition.static StringsplitDMLStatement(String sql, int maxLength) Splits a DML statement into several lines with limited length.static StringConverts aDoubleto a plain string representation without scientific notation.static StringtoString(BigDecimal content) Converts aBigDecimalto a plain string representation without scientific notation.
-
Field Details
-
JAILER_TABLES
-
JAILER_MH_TABLES
-
SQL_TRUE
Condition formulated in standard SQL that is always fulfilled.- See Also:
-
SQL_TYPE
-
PG_NEGATIVE_INFINITY
public static final long PG_NEGATIVE_INFINITY- See Also:
-
PG_NEGATIVE_SMALLER_INFINITY
public static final long PG_NEGATIVE_SMALLER_INFINITY- See Also:
-
PG_POSITIVE_INFINITY
public static final long PG_POSITIVE_INFINITY- See Also:
-
PG_POSITIVE_SMALLER_INFINITY
public static final long PG_POSITIVE_SMALLER_INFINITY- See Also:
-
-
Constructor Details
-
SqlUtil
public SqlUtil()
-
-
Method Details
-
reversRestrictionCondition
-
replaceAliases
-
replaceAlias
-
resolvePseudoColumns
public static String resolvePseudoColumns(String condition, String entityAAlias, String entityBAlias, int today, int birthdayOfSubject, boolean inDeleteMode) Resolves the pseudo-columns in a restriction condition.- Parameters:
condition- the conditionentityAAlias- alias for entity table joined with AentityBAlias- alias for entity table joined with Btoday- today's day counterbirthdayOfSubject- birthday of subjectinDeleteMode-trueif processing is in delete mode- Returns:
- the condition with pseudo-columns resolved
-
resolvePseudoColumns
public static String resolvePseudoColumns(String condition, String entityAAlias, String entityBAlias, int today, int birthdayOfSubject, String birthdayColumnName, Boolean inDeleteMode) Resolves the pseudo-columns in a restriction condition.- Parameters:
condition- the conditionentityAAlias- alias for entity table joined with AentityBAlias- alias for entity table joined with Btoday- today's day counterbirthdayOfSubject- birthday of subjectbirthdayColumnName- name of the column which holds the birthday of an entity ('birthday' or 'orig_birthday')inDeleteMode-trueif processing is in delete mode,nullto leave the pseudo-column unresolved- Returns:
- the condition with pseudo-columns resolved
-
resolvePseudoColumns
public static String resolvePseudoColumns(String condition, int today, int birthdayOfSubject, boolean reversed, boolean inDeleteMode) Resolves the pseudo-columns in a restriction condition.- Parameters:
condition- the conditiontoday- today's day counterbirthdayOfSubject- birthday of subjectreversed-trueif the direction of the association is reversedinDeleteMode-trueif processing is in delete mode- Returns:
- the condition with pseudo-columns resolved
-
readTableList
public static Set<Table> readTableList(CsvFile tableFile, DataModel dataModel, Map<String, String> sourceSchemaMapping) Reads a table-list from CSV-file.- Parameters:
tableFile- the file containing the listdataModel- to get tables fromsourceSchemaMapping- schema mapping to apply to table names, ornull- Returns:
- set of tables, empty set if file contains no tables
-
mappedSchema
-
getColumnType
public static int getColumnType(DBMS configuration, ResultSet resultSet, ResultSetMetaData resultSetMetaData, int i, Map<Integer, Integer> typeCache) throws SQLExceptionGets type of column from result-set.- Parameters:
configuration- the DBMS configurationresultSet- result-setresultSetMetaData- meta data of the result seti- column indextypeCache- for caching types- Returns:
- type according to
Types - Throws:
SQLException
-
getColumnType
public static int getColumnType(ResultSet resultSet, ResultSetMetaData resultSetMetaData, String columnName, Map<String, Integer> typeCache) throws SQLExceptionGets type of column from result-set.- Parameters:
resultSet- result-setresultSetMetaData- meta data of the result setcolumnName- column nametypeCache- for caching types- Returns:
- type according to
Types - Throws:
SQLException
-
splitDMLStatement
-
toString
-
toString
Converts aBigDecimalto a plain string representation without scientific notation.- Parameters:
content- the value to convert- Returns:
- plain string representation of the value
-
normalizeRestrictionCondition
Normalizes a restriction condition by reordering the column references into a canonical form.- Parameters:
cond- the restriction condition to normalize- Returns:
- the normalized condition, or the original condition if normalization is not possible
-
removeNonMeaningfulFragments
Removes all non-meaningful fragments of an SQL statement that might interfere with the SQL parser (comments, literals, etc.).- Parameters:
sqlStatement- the SQL statement to process- Returns:
- the SQL statement with non-meaningful fragments removed
-
removeComments
-
removeCommentsAndLiterals
-
removeSubQueries
-
columnLabel
public static String columnLabel(Quoting quoting, Session session, DBMS targetDBMSConfiguration, Table table, String columnLabel) Gets the properly quoted column label for use in a SQL statement.- Parameters:
quoting- the quoting to usesession- the current database sessiontargetDBMSConfiguration- the target DBMS configurationtable- the table containing the columncolumnLabel- the column label from the result set- Returns:
- the properly quoted column name
-
isLetterOrDigit
public static boolean isLetterOrDigit(char c) Checks whether a character is a letter, digit, or underscore as used in SQL identifiers.- Parameters:
c- the character to check- Returns:
trueif the character is alphabetic, a digit, or an underscore
-
createSQLFragmentSearchPattern
Creates a regular expression pattern that matches a SQL fragment, ignoring differences in whitespace and case.- Parameters:
sql- the SQL fragment to create a pattern forwithFlags-trueto include case-insensitive and dot-all flags in the pattern- Returns:
- the regular expression pattern string
-
indexOfDot
Gets the index of the schema-table name separator dot in a fully qualified table name.- Parameters:
fullName- the fully qualified table name- Returns:
- the index of the dot separator, or -1 if not present
-
retrieveEncoding
public static Charset retrieveEncoding(String scriptFileName) throws FileNotFoundException, IOException Retrieves SQL script file encoding.- Parameters:
scriptFileName- file name of script- Returns:
- encoding or null
- Throws:
FileNotFoundExceptionIOException
-
getDefaultCharset
-