Class Util
java.lang.Object
com.mysql.jdbc.Util
Various utility methods for the driver.
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncalculateDifferences(Map<?, ?> map1, Map<?, ?> map2) static Class<?>[]getImplementedInterfaces(Class<?> clazz) Retrieves a list with all interfaces implemented by the given class.static ObjectgetInstance(String className, Class<?>[] argTypes, Object[] args, ExceptionInterceptor exceptionInterceptor) static intstatic intstatic StringgetPackageName(Class<?> clazz) Returns the package name of the given class.static final ObjecthandleNewInstance(Constructor<?> ctor, Object[] args, ExceptionInterceptor exceptionInterceptor) Handles constructing new instance with the given constructor and wrapping (or not, as required) the exceptions that could possibly be generatedstatic long[]hashPre41Password(String password) static long[]hashPre41Password(String password, String encoding) static booleaninterfaceExists(String hostname) Does a network interface exist locally with the given hostname?static booleanstatic booleanisCommunityEdition(String serverVersion) Checks whether the given server version string is a MySQL Community editionstatic booleanisEnterpriseEdition(String serverVersion) Checks whether the given server version string is a MySQL Enterprise editionstatic booleanisJdbc4()static booleanisJdbc42()static booleanisJdbcInterface(Class<?> clazz) Recursively checks for interfaces on the given class to determine if it implements a java.sql, javax.sql or com.mysql.jdbc interface.static booleanisJdbcPackage(String packageName) Check if the package name is a known JDBC package.static booleanjvmMeetsMinimum(int version, int updateNumber) loadExtensions(Connection conn, Properties props, String extensionClassNames, String errorMessageKey, ExceptionInterceptor exceptionInterceptor) Returns initialized instances of classes listed in extensionClassNames.static String(package private) static long[]newHash(byte[] password) static String(package private) static longstatic Stringstatic longsecondsSinceMillis(long timeInMillis) Computes the number of seconds elapsed since the given time in milliseconds.static StringConverts a nested exception into a nicer messagestatic inttruncateAndConvertToInt(long longValue) Converts long to int, truncating to maximum/minimum value if needed.static int[]truncateAndConvertToInt(long[] longArray) Converts long[] to int[], truncating to maximum/minimum value if needed.
-
Constructor Details
-
Util
public Util()
-
-
Method Details
-
isJdbc4
public static boolean isJdbc4() -
isJdbc42
public static boolean isJdbc42() -
getJVMVersion
public static int getJVMVersion() -
jvmMeetsMinimum
public static boolean jvmMeetsMinimum(int version, int updateNumber) -
getJVMUpdateNumber
public static int getJVMUpdateNumber() -
isColdFusion
public static boolean isColdFusion() -
isCommunityEdition
Checks whether the given server version string is a MySQL Community edition -
isEnterpriseEdition
Checks whether the given server version string is a MySQL Enterprise edition -
newCrypt
-
hashPre41Password
-
hashPre41Password
-
newHash
static long[] newHash(byte[] password) -
oldCrypt
-
oldHash
-
scramble
-
stackTraceToString
-
getInstance
public static Object getInstance(String className, Class<?>[] argTypes, Object[] args, ExceptionInterceptor exceptionInterceptor) throws SQLException - Throws:
SQLException
-
handleNewInstance
public static final Object handleNewInstance(Constructor<?> ctor, Object[] args, ExceptionInterceptor exceptionInterceptor) throws SQLException Handles constructing new instance with the given constructor and wrapping (or not, as required) the exceptions that could possibly be generated- Throws:
SQLException
-
interfaceExists
Does a network interface exist locally with the given hostname?- Parameters:
hostname- the hostname (or IP address in string form) to check- Returns:
- true if it exists, false if no, or unable to determine due to VM version support of java.net.NetworkInterface
-
calculateDifferences
-
loadExtensions
public static List<Extension> loadExtensions(Connection conn, Properties props, String extensionClassNames, String errorMessageKey, ExceptionInterceptor exceptionInterceptor) throws SQLException Returns initialized instances of classes listed in extensionClassNames. There is no need to call Extension.init() method after that if you don't change connection or properties.- Parameters:
conn-props-extensionClassNames-errorMessageKey-exceptionInterceptor-- Throws:
SQLException
-
isJdbcInterface
Recursively checks for interfaces on the given class to determine if it implements a java.sql, javax.sql or com.mysql.jdbc interface.- Parameters:
clazz- The class to investigate.
-
isJdbcPackage
Check if the package name is a known JDBC package.- Parameters:
packageName- The package name to check.
-
getImplementedInterfaces
Retrieves a list with all interfaces implemented by the given class. If possible gets this information from a cache instead of navigating through the object hierarchy. Results are stored in a cache for future reference.- Parameters:
clazz- The class from which the interface list will be retrieved.- Returns:
- An array with all the interfaces for the given class.
-
secondsSinceMillis
public static long secondsSinceMillis(long timeInMillis) Computes the number of seconds elapsed since the given time in milliseconds.- Parameters:
timeInMillis- The past instant in milliseconds.- Returns:
- The number of seconds, truncated, elapsed since timeInMillis.
-
truncateAndConvertToInt
public static int truncateAndConvertToInt(long longValue) Converts long to int, truncating to maximum/minimum value if needed.- Parameters:
longValue-- Returns:
-
truncateAndConvertToInt
public static int[] truncateAndConvertToInt(long[] longArray) Converts long[] to int[], truncating to maximum/minimum value if needed.- Parameters:
longArray-- Returns:
-
getPackageName
Returns the package name of the given class. Using clazz.getPackage().getName() is not an alternative because under some class loaders the method getPackage() just returns null.- Parameters:
clazz- the Class from which to get the package name- Returns:
- the package name
-