Package org.apache.calcite.avatica
Class AvaticaUtils
- java.lang.Object
-
- org.apache.calcite.avatica.AvaticaUtils
-
public class AvaticaUtils extends java.lang.ObjectAvatica utilities.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.Map<java.lang.Class,java.lang.Class>BOXprivate static java.lang.invoke.MethodHandleEXECUTE_LARGE_BATCHprivate static java.lang.invoke.MethodHandleGET_LARGE_MAX_ROWSprivate static java.lang.invoke.MethodHandleGET_LARGE_UPDATE_COUNTprivate static java.lang.ThreadLocal<byte[]>PER_THREAD_BUFFERprivate static java.lang.invoke.MethodHandleSET_LARGE_MAX_ROWSprivate static java.util.Set<java.lang.String>UNIQUE_STRINGS
-
Constructor Summary
Constructors Modifier Constructor Description privateAvaticaUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description (package private) static byte[]_readFully(java.io.InputStream inputStream, UnsynchronizedBuffer buffer)Reads the contents of an input stream and returns a byte array.static java.lang.Classbox(java.lang.Class clazz)Returns the boxed class.static java.lang.StringcamelToUpper(java.lang.String name)Converts a camelCase name into an upper-case underscore-separated name.static voiddiscard(java.lang.Object o)Does nothing with its argument.static long[]executeLargeBatch(java.sql.Statement statement)InvokesStatement#executeLargeBatch, falling back onStatement.executeBatch()if the method does not exist (before JDK 1.8) or throwsUnsupportedOperationException.static longgetLargeMaxRows(java.sql.Statement statement)InvokesStatement#getLargeMaxRows, falling back onStatement.getMaxRows()if the method does not exist (before JDK 1.8) or throwsUnsupportedOperationException.static longgetLargeUpdateCount(java.sql.Statement statement)InvokesStatement#getLargeUpdateCount, falling back onStatement.getUpdateCount()if the method does not exist (before JDK 1.8) or throwsUnsupportedOperationException.static <T> TinstantiatePlugin(java.lang.Class<T> pluginClass, java.lang.String className)Creates an instance of a plugin class.private static java.lang.invoke.MethodHandlemethod(java.lang.Class returnType, java.lang.Class targetType, java.lang.String name, java.lang.Class... argTypes)static java.util.List<?>primitiveList(java.lang.Object array)Adapts a primitive array into aList.static java.lang.StringreadFully(java.io.InputStream inputStream)Reads the contents of an input stream and returns as a string.static java.lang.StringreadFully(java.io.InputStream inputStream, UnsynchronizedBuffer buffer)Reads the contents of an input stream and returns as a string.static byte[]readFullyToBytes(java.io.InputStream inputStream)Reads the contents of an input stream and returns as a string.static byte[]readFullyToBytes(java.io.InputStream inputStream, UnsynchronizedBuffer buffer)Reads the contents of an input stream and returns as a string.static <T> Tremark(T remark)Use this method to flag temporary code.static voidsetLargeMaxRows(java.sql.Statement statement, long n)InvokesStatement#setLargeMaxRows, falling back onStatement.setMaxRows(int)if the method does not exist (before JDK 1.8) or throwsUnsupportedOperationException.static java.lang.StringtoCamelCase(java.lang.String name)Converts an underscore-separated name into a camelCase name.static long[]toLongs(int[] ints)Converts an array ofintvalues to an array oflongvalues.static inttoSaturatedInt(long value)Converts alongtoint, rounding as little as possible if the value is outside the legal range for anint.static int[]toSaturatedInts(long[] longs)Converts an array oflongvalues to an array ofintvalues, truncating values outside the legal range for aninttoInteger.MIN_VALUEorInteger.MAX_VALUE.static java.lang.Stringunique(java.lang.String base)Generates a string that is unique in the execution of the JVM.static booleanupgrade(java.lang.String remark)Use this method to flag code that should be re-visited after upgrading a component.
-
-
-
Field Detail
-
BOX
private static final java.util.Map<java.lang.Class,java.lang.Class> BOX
-
SET_LARGE_MAX_ROWS
private static final java.lang.invoke.MethodHandle SET_LARGE_MAX_ROWS
-
GET_LARGE_MAX_ROWS
private static final java.lang.invoke.MethodHandle GET_LARGE_MAX_ROWS
-
GET_LARGE_UPDATE_COUNT
private static final java.lang.invoke.MethodHandle GET_LARGE_UPDATE_COUNT
-
EXECUTE_LARGE_BATCH
private static final java.lang.invoke.MethodHandle EXECUTE_LARGE_BATCH
-
UNIQUE_STRINGS
private static final java.util.Set<java.lang.String> UNIQUE_STRINGS
-
PER_THREAD_BUFFER
private static final java.lang.ThreadLocal<byte[]> PER_THREAD_BUFFER
-
-
Method Detail
-
method
private static java.lang.invoke.MethodHandle method(java.lang.Class returnType, java.lang.Class targetType, java.lang.String name, java.lang.Class... argTypes)
-
discard
public static void discard(java.lang.Object o)
Does nothing with its argument. Call this method when you have a value you are not interested in, but you don't want the compiler to warn that you are not using it.
-
remark
public static <T> T remark(T remark)
Use this method to flag temporary code.Example #1:
if (AvaticaUtils.remark("baz fixed") == null) { baz(); }Example #2:
/** @see AvaticaUtils#remark Remove before checking in */ void uselessMethod() {}
-
upgrade
public static boolean upgrade(java.lang.String remark)
Use this method to flag code that should be re-visited after upgrading a component.If the intended change is that a class or member be removed, flag instead using a
Deprecatedannotation followed by a comment such as "to be removed before 2.0".
-
primitiveList
public static java.util.List<?> primitiveList(java.lang.Object array)
Adapts a primitive array into aList. For example,asList(new double[2])returns aList<Double>.
-
camelToUpper
public static java.lang.String camelToUpper(java.lang.String name)
Converts a camelCase name into an upper-case underscore-separated name. For example,camelToUpper("myJdbcDriver")returns "MY_JDBC_DRIVER".
-
toCamelCase
public static java.lang.String toCamelCase(java.lang.String name)
Converts an underscore-separated name into a camelCase name. For example,uncamel("MY_JDBC_DRIVER")returns "myJdbcDriver".
-
box
public static java.lang.Class box(java.lang.Class clazz)
Returns the boxed class. For example,box(int.class)returnsjava.lang.Integer.
-
instantiatePlugin
public static <T> T instantiatePlugin(java.lang.Class<T> pluginClass, java.lang.String className)Creates an instance of a plugin class. First looks for a static member called INSTANCE, then calls a public default constructor.If className contains a "#" instead looks for a static field.
- Type Parameters:
T- Class- Parameters:
pluginClass- Class (or interface) to instantiateclassName- Name of implementing class- Returns:
- Plugin instance
-
readFully
public static java.lang.String readFully(java.io.InputStream inputStream) throws java.io.IOExceptionReads the contents of an input stream and returns as a string.- Throws:
java.io.IOException
-
readFully
public static java.lang.String readFully(java.io.InputStream inputStream, UnsynchronizedBuffer buffer) throws java.io.IOExceptionReads the contents of an input stream and returns as a string.- Throws:
java.io.IOException
-
readFullyToBytes
public static byte[] readFullyToBytes(java.io.InputStream inputStream) throws java.io.IOExceptionReads the contents of an input stream and returns as a string.- Throws:
java.io.IOException
-
readFullyToBytes
public static byte[] readFullyToBytes(java.io.InputStream inputStream, UnsynchronizedBuffer buffer) throws java.io.IOExceptionReads the contents of an input stream and returns as a string.- Throws:
java.io.IOException
-
_readFully
static byte[] _readFully(java.io.InputStream inputStream, UnsynchronizedBuffer buffer) throws java.io.IOExceptionReads the contents of an input stream and returns a byte array.- Parameters:
inputStream- the input to read from.- Returns:
- A byte array whose length is equal to the number of bytes contained.
- Throws:
java.io.IOException
-
setLargeMaxRows
public static void setLargeMaxRows(java.sql.Statement statement, long n) throws java.sql.SQLExceptionInvokesStatement#setLargeMaxRows, falling back onStatement.setMaxRows(int)if the method does not exist (before JDK 1.8) or throwsUnsupportedOperationException.- Throws:
java.sql.SQLException
-
getLargeMaxRows
public static long getLargeMaxRows(java.sql.Statement statement) throws java.sql.SQLExceptionInvokesStatement#getLargeMaxRows, falling back onStatement.getMaxRows()if the method does not exist (before JDK 1.8) or throwsUnsupportedOperationException.- Throws:
java.sql.SQLException
-
getLargeUpdateCount
public static long getLargeUpdateCount(java.sql.Statement statement) throws java.sql.SQLExceptionInvokesStatement#getLargeUpdateCount, falling back onStatement.getUpdateCount()if the method does not exist (before JDK 1.8) or throwsUnsupportedOperationException.- Throws:
java.sql.SQLException
-
executeLargeBatch
public static long[] executeLargeBatch(java.sql.Statement statement) throws java.sql.SQLExceptionInvokesStatement#executeLargeBatch, falling back onStatement.executeBatch()if the method does not exist (before JDK 1.8) or throwsUnsupportedOperationException.- Throws:
java.sql.SQLException
-
unique
public static java.lang.String unique(java.lang.String base)
Generates a string that is unique in the execution of the JVM. It is used by tests to ensure that they create distinct temporary tables. The strings are never thrown away, so don't put too much in there! Thread safe.
-
toSaturatedInt
public static int toSaturatedInt(long value)
Converts alongtoint, rounding as little as possible if the value is outside the legal range for anint.
-
toSaturatedInts
public static int[] toSaturatedInts(long[] longs)
Converts an array oflongvalues to an array ofintvalues, truncating values outside the legal range for aninttoInteger.MIN_VALUEorInteger.MAX_VALUE.- Parameters:
longs- An array oflongs- Returns:
- An array of
ints
-
toLongs
public static long[] toLongs(int[] ints)
Converts an array ofintvalues to an array oflongvalues.
-
-