Package com.im.commons.db.util
Class DBUtils
- java.lang.Object
-
- com.im.commons.db.util.DBUtils
-
public final class DBUtils extends java.lang.Object
Class collecting a few generic static utility methods mostly related to SQL generation.
-
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static int
compareTwoStringVersions(java.lang.String versionA, java.lang.String versionB)
Compares two version strings, ie.static org.springframework.jdbc.core.PreparedStatementCreator
createPreparedStatementCreator(java.lang.String sql, int fetchSize)
Creates aPreparedStatementCreator
for a SQL statement and a fetch size.static org.springframework.jdbc.core.PreparedStatementCreator
createPreparedStatementCreator(java.lang.String sql, DBType dbType)
Creates aPreparedStatementCreator
for a SQL statement and a database type.static java.lang.String
findStringNotPresent(java.util.List<java.lang.String> values)
Gets a character that is not contained in any of thevalues
.static java.lang.String
getIdentifierQuoteString(javax.sql.DataSource ds)
static java.util.List<java.util.UUID>
getUUIDsFromParams(java.lang.Object[] params)
Used for gettingusrOpId
UUID fromJChemSearchOptions
string representation.static java.lang.String
join(java.lang.Object[] values, java.lang.String separator)
Deprecated.5.12 UseJoiner
instead.static void
join(java.lang.StringBuilder buf, java.lang.Object[] values, java.lang.String separator)
Deprecated.5.12 UseJoiner
instead.static java.lang.String
join(java.util.Collection<?> values, java.lang.String separator)
Deprecated.5.12 UseJoiner
instead.static java.lang.String
repeat(java.lang.String val, java.lang.String sep, int count)
static java.lang.String
stripParenthesis(java.lang.String txt)
Strips the parenthesis "()" from a string.static java.lang.String
stripQuotes(java.lang.String txt)
Strips the quotes (' or ") from a string.
-
-
-
Method Detail
-
repeat
public static java.lang.String repeat(java.lang.String val, java.lang.String sep, int count)
-
join
@Deprecated public static java.lang.String join(java.util.Collection<?> values, java.lang.String separator)
Deprecated.5.12 UseJoiner
instead.Concatenates a collection of values into a string.- Parameters:
values
- Values to concatenate.separator
- The separator to use.- Returns:
- A
String
with allvalues
concatenated and separated by theseparator
.
-
join
@Deprecated public static void join(java.lang.StringBuilder buf, java.lang.Object[] values, java.lang.String separator)
Deprecated.5.12 UseJoiner
instead.Concatenates an array of values into aStringBuilder
.- Parameters:
buf
- TheStringBuilder
to receive the concatenated values.values
- Values to concatenate.separator
- The separator to use.
-
join
@Deprecated public static java.lang.String join(java.lang.Object[] values, java.lang.String separator)
Deprecated.5.12 UseJoiner
instead.Concatenates an array of values into a string.- Parameters:
values
- Values to concatenate.separator
- The separator to use.- Returns:
- A
String
with allvalues
concatenated and separated by theseparator
.
-
stripQuotes
public static java.lang.String stripQuotes(java.lang.String txt)
Strips the quotes (' or ") from a string. For example converts 'hello' to hello. The string consisting from only two quote characters (eg. '' or "") is left untouched. Empty ornull
} strings are left untouched too.- Parameters:
txt
- The string to remove quotes from. Can benull
or empty.- Returns:
- The string with the starting and ending quote removed.
-
stripParenthesis
public static java.lang.String stripParenthesis(java.lang.String txt)
Strips the parenthesis "()" from a string. For example converts ((hello)) to hello.- Parameters:
txt
- The string to remove parenthesis from.- Returns:
- The string with the starting and ending parenthesis removed. The string containing just "()" is left untouched.
-
findStringNotPresent
public static java.lang.String findStringNotPresent(java.util.List<java.lang.String> values)
Gets a character that is not contained in any of thevalues
.- Parameters:
values
- The list of string to check.- Returns:
- One of the
,!#^*%@~`_£\\/?$¬;|&
.
-
createPreparedStatementCreator
public static org.springframework.jdbc.core.PreparedStatementCreator createPreparedStatementCreator(java.lang.String sql, int fetchSize)
Creates aPreparedStatementCreator
for a SQL statement and a fetch size.- Parameters:
sql
- The sql statement to use.fetchSize
- The JDBC fetch size. SeeStatement.setFetchSize(int)
- Returns:
- The
PreparedStatementCreator
instance.
-
createPreparedStatementCreator
public static org.springframework.jdbc.core.PreparedStatementCreator createPreparedStatementCreator(java.lang.String sql, DBType dbType)
Creates aPreparedStatementCreator
for a SQL statement and a database type. It determines the optimal fetchsize fromDBType.getPreferedFetchSize()
.- Parameters:
sql
- The sql statement to use.dbType
- The database type.- Returns:
- The
PreparedStatementCreator
instance.
-
compareTwoStringVersions
public static int compareTwoStringVersions(java.lang.String versionA, java.lang.String versionB)
Compares two version strings, ie. 5.5.0 and 5.7.1.- Parameters:
versionA
- first version to compareversionB
- second version to compare- Returns:
- 1 if versionA is greater than versionB, -1 if opposite, 0 if equal.
-
getUUIDsFromParams
public static java.util.List<java.util.UUID> getUUIDsFromParams(java.lang.Object[] params)
Used for gettingusrOpId
UUID fromJChemSearchOptions
string representation.- Parameters:
params
- takes an Object array as input- Returns:
- list of UUIDs if found between params
-
getIdentifierQuoteString
public static java.lang.String getIdentifierQuoteString(javax.sql.DataSource ds) throws org.springframework.jdbc.support.MetaDataAccessException
- Parameters:
ds
- dataSaurce to get db-specific quote string from- Returns:
- valid identifier quote string suitable for escaping DB tables, schemas etc.
- Throws:
org.springframework.jdbc.support.MetaDataAccessException
- if metadata access failed, no likely
-
-