Package com.im.commons.db.util
Class DBUtils
- java.lang.Object
-
- com.im.commons.db.util.DBUtils
-
public final class DBUtils extends java.lang.ObjectClass 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 intcompareTwoStringVersions(java.lang.String versionA, java.lang.String versionB)Compares two version strings, ie.static org.springframework.jdbc.core.PreparedStatementCreatorcreatePreparedStatementCreator(java.lang.String sql, int fetchSize)Creates aPreparedStatementCreatorfor a SQL statement and a fetch size.static org.springframework.jdbc.core.PreparedStatementCreatorcreatePreparedStatementCreator(java.lang.String sql, DBType dbType)Creates aPreparedStatementCreatorfor a SQL statement and a database type.static java.lang.StringfindStringNotPresent(java.util.List<java.lang.String> values)Gets a character that is not contained in any of thevalues.static java.lang.StringgetIdentifierQuoteString(javax.sql.DataSource ds)static java.util.List<java.util.UUID>getUUIDsFromParams(java.lang.Object[] params)Used for gettingusrOpIdUUID fromJChemSearchOptionsstring representation.static java.lang.Stringjoin(java.lang.Object[] values, java.lang.String separator)Deprecated.5.12 UseJoinerinstead.static voidjoin(java.lang.StringBuilder buf, java.lang.Object[] values, java.lang.String separator)Deprecated.5.12 UseJoinerinstead.static java.lang.Stringjoin(java.util.Collection<?> values, java.lang.String separator)Deprecated.5.12 UseJoinerinstead.static java.lang.Stringrepeat(java.lang.String val, java.lang.String sep, int count)static java.lang.StringstripParenthesis(java.lang.String txt)Strips the parenthesis "()" from a string.static java.lang.StringstripQuotes(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 UseJoinerinstead.Concatenates a collection of values into a string.- Parameters:
values- Values to concatenate.separator- The separator to use.- Returns:
- A
Stringwith allvaluesconcatenated 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 UseJoinerinstead.Concatenates an array of values into aStringBuilder.- Parameters:
buf- TheStringBuilderto 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 UseJoinerinstead.Concatenates an array of values into a string.- Parameters:
values- Values to concatenate.separator- The separator to use.- Returns:
- A
Stringwith allvaluesconcatenated 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 benullor 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 aPreparedStatementCreatorfor a SQL statement and a fetch size.- Parameters:
sql- The sql statement to use.fetchSize- The JDBC fetch size. SeeStatement.setFetchSize(int)- Returns:
- The
PreparedStatementCreatorinstance.
-
createPreparedStatementCreator
public static org.springframework.jdbc.core.PreparedStatementCreator createPreparedStatementCreator(java.lang.String sql, DBType dbType)Creates aPreparedStatementCreatorfor 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
PreparedStatementCreatorinstance.
-
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 gettingusrOpIdUUID fromJChemSearchOptionsstring 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
-
-