Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hazelcast.shaded.org.apache.calcite.avatica;
import com.hazelcast.shaded.org.apache.calcite.avatica.util.UnsynchronizedBuffer;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.reflect.Field;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.AbstractList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
/** Avatica utilities. */
public class AvaticaUtils {
private static final Map BOX;
private static final MethodHandle SET_LARGE_MAX_ROWS =
method(void.class, Statement.class, "setLargeMaxRows", long.class);
private static final MethodHandle GET_LARGE_MAX_ROWS =
method(long.class, Statement.class, "getLargeMaxRows");
private static final MethodHandle GET_LARGE_UPDATE_COUNT =
method(void.class, Statement.class, "getLargeUpdateCount");
private static final MethodHandle EXECUTE_LARGE_BATCH =
method(long[].class, Statement.class, "executeLargeBatch");
private static final Set UNIQUE_STRINGS = new HashSet<>();
private static final ThreadLocal PER_THREAD_BUFFER = new ThreadLocal() {
@Override protected byte[] initialValue() {
return new byte[4096];
}
};
private static final int SKIP_BUFFER_SIZE = 4096;
private AvaticaUtils() {}
static {
BOX = new HashMap<>();
BOX.put(boolean.class, Boolean.class);
BOX.put(byte.class, Byte.class);
BOX.put(char.class, Character.class);
BOX.put(short.class, Short.class);
BOX.put(int.class, Integer.class);
BOX.put(long.class, Long.class);
BOX.put(float.class, Float.class);
BOX.put(double.class, Double.class);
}
private static MethodHandle method(Class returnType, Class targetType,
String name, Class... argTypes) {
final MethodHandles.Lookup lookup = MethodHandles.lookup();
try {
return lookup.findVirtual(targetType, name,
MethodType.methodType(returnType, targetType, argTypes));
} catch (NoSuchMethodException e) {
return null;
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
/**
* 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.
*/
public static void discard(Object o) {
if (false) {
discard(o);
}
}
/**
* Use this method to flag temporary code.
*
*
* /** @see AvaticaUtils#remark Remove before checking in */
* void uselessMethod() {}
*
*/
public static T remark(T remark) {
return 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 {@link Deprecated} annotation followed by a comment such as
* "to be removed before 2.0".
*/
public static boolean upgrade(String remark) {
discard(remark);
return false;
}
/**
* Adapts a primitive array into a {@link List}. For example,
* {@code asList(new double[2])} returns a {@code List<Double>}.
*/
public static List> primitiveList(final Object array) {
// REVIEW: A per-type list might be more efficient. (Or might not.)
return new AbstractList