Top Description Fields Constructors Methods
com.mysql.cj.util

public Class Util

extends Object
Class Inheritance
Imports
java.io.IOException, .InputStream, .PrintWriter, .Reader, .StringWriter, java.lang.reflect.Constructor, .InvocationTargetException, java.math.BigDecimal, .BigInteger, java.util.Collections, .HashMap, .LinkedHashSet, .LinkedList, .List, .Map, .Set, java.util.concurrent.ConcurrentHashMap, .ConcurrentMap, java.util.stream.Collectors, com.mysql.cj.Constants, .Messages, com.mysql.cj.exceptions.CJException, .ExceptionFactory, .ExceptionInterceptor, .WrongArgumentException

Various utility methods for the driver.

Field Summary

Modifier and TypeField and Description
private static final ConcurrentMap<Class<?>, Class<?>[]>
implementedInterfacesCache

Cache for the implemented interfaces searched.

private static final ConcurrentMap<Class<?>, Boolean>
isJdbcInterfaceCache

Cache for the JDBC interfaces already verified

private static int
private static int

Constructor Summary

AccessConstructor and Description
public
Util()

Method Summary

Modifier and TypeMethod and Description
public static Map<Object, Object>
calculateDifferences(Map<?, ?> map1, Map<?, ?> map2)

public static Class<?>[]

Returns:

An array with all the interfaces for the given class.
getImplementedInterfaces
(Class<?>
The class from which the interface list will be retrieved.
clazz
)

Retrieves a list with all interfaces implemented by the given class.

public static <
The return type of the new instance.
T
>
T

Returns:

if all validations succeed, an instance of the class with the specified name.
getInstance
(Class<T>
the class of the return type of the new instance, usually an interface.
returnType
,
String
the name of the class to instantiate through reflection.
className
,
Class<?>[]
the type of the arguments of the constructor to be used for instantiating the class.
argTypes
,
Object[]
the arguments to supply when exectuing the new instance constructor.
args
,
ExceptionInterceptor
the ExceptionInterceptor to handle new exceptions thrown.
exceptionInterceptor
)

Creates an instance of the specified class name through reflection using the given arguments, as long as the class implements the return type specified.

public static int
public static int
public static String

Returns:

the package name
getPackageName
(Class<?>
the Class from which to get the package name
clazz
)

Returns the package name of the given class.

public static <
The type of the new class instance to return.
T
>
T

Returns:

object
handleNewInstance
(Constructor<T>
constructor
ctor
,
Object[]
arguments for constructor
args
,
ExceptionInterceptor
exception interceptor
exceptionInterceptor
)

Handles constructing new instance with the given constructor and wrapping (or not, as required) the exceptions that could possibly be generated.

public static boolean

Returns:

true if version does not contain "enterprise", "commercial" or "advanced"
isCommunityEdition
(String
full server version string
serverVersion
)

Checks whether the given server version string is a MySQL Community edition.

public static boolean

Returns:

true if version contains "enterprise", "commercial" or "advanced"
isEnterpriseEdition
(String
full server version string
serverVersion
)

Checks whether the given server version string is a MySQL Enterprise/Commercial edition.

public static boolean

Returns:

boolean
isJdbcInterface
(Class<?>
The class to investigate.
clazz
)

Recursively checks for interfaces on the given class to determine if it implements a java.sql, javax.sql or com.mysql.cj.jdbc interface.

public static boolean

Returns:

boolean
isJdbcPackage
(String
The package name to check.
packageName
)

Check if the package name is a known JDBC package.

public static boolean

Returns:

true if currently running on Windows, false otherwise.
isRunningOnWindows
()

Checks if the JVM is running on Windows Operating System.

public static boolean
jvmMeetsMinimum(int version, int updateNumber)

public static <T> List<T>
loadClasses(Class<T> instancesType, String extensionClassNames, String errorMessageKey, ExceptionInterceptor exceptionInterceptor)

public static final int
readBlock(InputStream i, byte[] b, ExceptionInterceptor exceptionInterceptor)

public static final int
readBlock(InputStream i, byte[] b, int length, ExceptionInterceptor exceptionInterceptor)

public static int

Returns:

the actual number of chars read
readFully
(Reader reader, char[]
char array to read into
buf
,
int
number of chars to read
length
)

Reads length bytes from reader into buf.

public static long

Returns:

The number of seconds, truncated, elapsed since timeInMillis.
secondsSinceMillis
(long
The past instant in milliseconds.
timeInMillis
)

Computes the number of seconds elapsed since the given time in milliseconds.

public static String

Returns:

a message containing the exception, the message (if any), and a stacktrace.
stackTraceToString
(Throwable
the exception to expand into a message.
ex
)

Converts a nested exception into a nicer message.

public static int

Returns:

int value
truncateAndConvertToInt
(long
long value
longValue
)

Converts long to int, truncating to maximum/minimum value if needed.

public static int[]

Returns:

int values
truncateAndConvertToInt
(long[]
log values
longArray
)

Converts long[] to int[], truncating to maximum/minimum value if needed.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

implementedInterfacesCacheback to summary
private static final ConcurrentMap<Class<?>, Class<?>[]> implementedInterfacesCache

Cache for the implemented interfaces searched.

isJdbcInterfaceCacheback to summary
private static final ConcurrentMap<Class<?>, Boolean> isJdbcInterfaceCache

Cache for the JDBC interfaces already verified

jvmUpdateNumberback to summary
private static int jvmUpdateNumber
jvmVersionback to summary
private static int jvmVersion

Constructor Detail

Utilback to summary
public Util()

Method Detail

calculateDifferencesback to summary
public static Map<Object, Object> calculateDifferences(Map<?, ?> map1, Map<?, ?> map2)
getImplementedInterfacesback to summary
public static Class<?>[] getImplementedInterfaces(Class<?> clazz)

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:Class<?>

The class from which the interface list will be retrieved.

Returns:Class<?>[]

An array with all the interfaces for the given class.

getInstanceback to summary
public static <T> T getInstance(Class<T> returnType, String className, Class<?>[] argTypes, Object[] args, ExceptionInterceptor exceptionInterceptor)

Creates an instance of the specified class name through reflection using the given arguments, as long as the class implements the return type specified.

Parameters
<T>
The return type of the new instance.
returnType:Class<T>

the class of the return type of the new instance, usually an interface.

className:String

the name of the class to instantiate through reflection.

argTypes:Class<?>[]

the type of the arguments of the constructor to be used for instantiating the class.

args:Object[]

the arguments to supply when exectuing the new instance constructor.

exceptionInterceptor:ExceptionInterceptor

the ExceptionInterceptor to handle new exceptions thrown.

Returns:T

if all validations succeed, an instance of the class with the specified name.

Annotations
@SuppressWarnings:unchecked
getJVMUpdateNumberback to summary
public static int getJVMUpdateNumber()
getJVMVersionback to summary
public static int getJVMVersion()
getPackageNameback to summary
public static String getPackageName(Class<?> clazz)

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:Class<?>

the Class from which to get the package name

Returns:String

the package name

handleNewInstanceback to summary
public static <T> T handleNewInstance(Constructor<T> 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 generated.

Parameters
<T>
The type of the new class instance to return.
ctor:Constructor<T>

constructor

args:Object[]

arguments for constructor

exceptionInterceptor:ExceptionInterceptor

exception interceptor

Returns:T

object

isCommunityEditionback to summary
public static boolean isCommunityEdition(String serverVersion)

Checks whether the given server version string is a MySQL Community edition.

Parameters
serverVersion:String

full server version string

Returns:boolean

true if version does not contain "enterprise", "commercial" or "advanced"

isEnterpriseEditionback to summary
public static boolean isEnterpriseEdition(String serverVersion)

Checks whether the given server version string is a MySQL Enterprise/Commercial edition.

Parameters
serverVersion:String

full server version string

Returns:boolean

true if version contains "enterprise", "commercial" or "advanced"

isJdbcInterfaceback to summary
public static boolean isJdbcInterface(Class<?> clazz)

Recursively checks for interfaces on the given class to determine if it implements a java.sql, javax.sql or com.mysql.cj.jdbc interface.

Parameters
clazz:Class<?>

The class to investigate.

Returns:boolean

boolean

isJdbcPackageback to summary
public static boolean isJdbcPackage(String packageName)

Check if the package name is a known JDBC package.

Parameters
packageName:String

The package name to check.

Returns:boolean

boolean

isRunningOnWindowsback to summary
public static boolean isRunningOnWindows()

Checks if the JVM is running on Windows Operating System.

Returns:boolean

true if currently running on Windows, false otherwise.

jvmMeetsMinimumback to summary
public static boolean jvmMeetsMinimum(int version, int updateNumber)
loadClassesback to summary
public static <T> List<T> loadClasses(Class<T> instancesType, String extensionClassNames, String errorMessageKey, ExceptionInterceptor exceptionInterceptor)
readBlockback to summary
public static final int readBlock(InputStream i, byte[] b, ExceptionInterceptor exceptionInterceptor)
readBlockback to summary
public static final int readBlock(InputStream i, byte[] b, int length, ExceptionInterceptor exceptionInterceptor)
readFullyback to summary
public static int readFully(Reader reader, char[] buf, int length) throws IOException

Reads length bytes from reader into buf. Blocks until enough input is available

Parameters
reader:Reader

Reader

buf:char[]

char array to read into

length:int

number of chars to read

Returns:int

the actual number of chars read

Exceptions
IOException:
if an error occurs
secondsSinceMillisback to summary
public static long secondsSinceMillis(long timeInMillis)

Computes the number of seconds elapsed since the given time in milliseconds.

Parameters
timeInMillis:long

The past instant in milliseconds.

Returns:long

The number of seconds, truncated, elapsed since timeInMillis.

stackTraceToStringback to summary
public static String stackTraceToString(Throwable ex)

Converts a nested exception into a nicer message.

Parameters
ex:Throwable

the exception to expand into a message.

Returns:String

a message containing the exception, the message (if any), and a stacktrace.

truncateAndConvertToIntback to summary
public static int truncateAndConvertToInt(long longValue)

Converts long to int, truncating to maximum/minimum value if needed.

Parameters
longValue:long

long value

Returns:int

int value

truncateAndConvertToIntback to summary
public static int[] truncateAndConvertToInt(long[] longArray)

Converts long[] to int[], truncating to maximum/minimum value if needed.

Parameters
longArray:long[]

log values

Returns:int[]

int values