public class Util extends Object
| Modifier and Type | Field and Description |
|---|---|
private static ConcurrentMap<Class<?>,Class<?>[]> |
implementedInterfacesCache
Cache for the implemented interfaces searched.
|
private static ConcurrentMap<Class<?>,Boolean> |
isJdbcInterfaceCache
Cache for the JDBC interfaces already verified
|
private static int |
jvmUpdateNumber |
private static int |
jvmVersion |
| Constructor and Description |
|---|
Util() |
| Modifier and Type | Method and Description |
|---|---|
static Map<Object,Object> |
calculateDifferences(Map<?,?> map1,
Map<?,?> map2) |
static Class<?>[] |
getImplementedInterfaces(Class<?> clazz)
Retrieves a list with all interfaces implemented by the given class.
|
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.
|
static int |
getJVMUpdateNumber() |
static int |
getJVMVersion() |
static String |
getPackageName(Class<?> clazz)
Returns the package name of the given class.
|
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.
|
static boolean |
isCommunityEdition(String serverVersion)
Checks whether the given server version string is a MySQL Community edition.
|
static boolean |
isEnterpriseEdition(String serverVersion)
Checks whether the given server version string is a MySQL Enterprise/Commercial edition.
|
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.
|
static boolean |
isJdbcPackage(String packageName)
Check if the package name is a known JDBC package.
|
static boolean |
isRunningOnWindows()
Checks if the JVM is running on Windows Operating System.
|
static boolean |
jvmMeetsMinimum(int version,
int updateNumber) |
static <T> List<T> |
loadClasses(Class<T> instancesType,
String extensionClassNames,
String errorMessageKey,
ExceptionInterceptor exceptionInterceptor) |
static int |
readBlock(InputStream i,
byte[] b,
ExceptionInterceptor exceptionInterceptor) |
static int |
readBlock(InputStream i,
byte[] b,
int length,
ExceptionInterceptor exceptionInterceptor) |
static int |
readFully(Reader reader,
char[] buf,
int length)
Reads length bytes from reader into buf.
|
static long |
secondsSinceMillis(long timeInMillis)
Computes the number of seconds elapsed since the given time in milliseconds.
|
static String |
stackTraceToString(Throwable ex)
Converts a nested exception into a nicer message.
|
static int |
truncateAndConvertToInt(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.
|
private static int jvmVersion
private static int jvmUpdateNumber
private static final ConcurrentMap<Class<?>,Boolean> isJdbcInterfaceCache
private static final ConcurrentMap<Class<?>,Class<?>[]> implementedInterfacesCache
public static int getJVMVersion()
public static boolean jvmMeetsMinimum(int version,
int updateNumber)
public static int getJVMUpdateNumber()
public static boolean isCommunityEdition(String serverVersion)
serverVersion - full server version stringpublic static boolean isEnterpriseEdition(String serverVersion)
serverVersion - full server version stringpublic static String stackTraceToString(Throwable ex)
ex - the exception to expand into a message.public static <T> T getInstance(Class<T> returnType, String className, Class<?>[] argTypes, Object[] args, ExceptionInterceptor exceptionInterceptor)
T - The return type of the new instance.returnType - the class of the return type of the new instance, usually an interface.className - the name of the class to instantiate through reflection.argTypes - the type of the arguments of the constructor to be used for instantiating the class.args - the arguments to supply when exectuing the new instance constructor.exceptionInterceptor - the ExceptionInterceptor to handle new exceptions thrown.public static <T> T handleNewInstance(Constructor<T> ctor, Object[] args, ExceptionInterceptor exceptionInterceptor)
T - The type of the new class instance to return.ctor - constructorargs - arguments for constructorexceptionInterceptor - exception interceptorpublic static Map<Object,Object> calculateDifferences(Map<?,?> map1, Map<?,?> map2)
public static <T> List<T> loadClasses(Class<T> instancesType, String extensionClassNames, String errorMessageKey, ExceptionInterceptor exceptionInterceptor)
public static boolean isJdbcInterface(Class<?> clazz)
clazz - The class to investigate.public static boolean isJdbcPackage(String packageName)
packageName - The package name to check.public static Class<?>[] getImplementedInterfaces(Class<?> clazz)
clazz - The class from which the interface list will be retrieved.public static long secondsSinceMillis(long timeInMillis)
timeInMillis - The past instant in milliseconds.public static int truncateAndConvertToInt(long longValue)
longValue - long valuepublic static int[] truncateAndConvertToInt(long[] longArray)
longArray - log valuespublic static String getPackageName(Class<?> clazz)
clazz - the Class from which to get the package namepublic static boolean isRunningOnWindows()
true if currently running on Windows, false otherwise.public static int readFully(Reader reader, char[] buf, int length) throws IOException
reader - Readerbuf - char array to read intolength - number of chars to readIOException - if an error occurspublic static final int readBlock(InputStream i, byte[] b, ExceptionInterceptor exceptionInterceptor)
public static final int readBlock(InputStream i, byte[] b, int length, ExceptionInterceptor exceptionInterceptor)