sockets = new LinkedList<>();
@@ -2636,7 +2589,8 @@ private void findSocketUsingThreading(InetAddress[] inetAddrs,
InetSocketAddress inetSocketAddress = new InetSocketAddress(inetAddress, portNumber);
- SocketConnector socketConnector = new SocketConnector(s, inetSocketAddress, timeoutInMilliSeconds, this);
+ SocketConnector socketConnector = new SocketConnector(s, inetSocketAddress, timeoutInMilliSeconds,
+ this);
socketConnectors.add(socketConnector);
}
@@ -2654,8 +2608,9 @@ private void findSocketUsingThreading(InetAddress[] inetAddrs,
long timeRemaining = timerExpire - timerNow;
if (logger.isLoggable(Level.FINER)) {
- logger.finer(this.toString() + " TimeRemaining:" + timeRemaining + "; Result:" + result + "; Max. open thread count: "
- + threadPoolExecutor.getLargestPoolSize() + "; Current open thread count:" + threadPoolExecutor.getActiveCount());
+ logger.finer(this.toString() + " TimeRemaining:" + timeRemaining + "; Result:" + result
+ + "; Max. open thread count: " + threadPoolExecutor.getLargestPoolSize()
+ + "; Current open thread count:" + threadPoolExecutor.getActiveCount());
}
// if there is no time left or if the result is determined, break.
@@ -2683,8 +2638,7 @@ private void findSocketUsingThreading(InetAddress[] inetAddrs,
}
- }
- finally {
+ } finally {
// Close all sockets except the selected one.
// As we close sockets pro-actively in the child threads,
// its possible that we close a socket twice.
@@ -2700,8 +2654,8 @@ private void findSocketUsingThreading(InetAddress[] inetAddrs,
}
}
}
-
- if (selectedSocket != null) {
+
+ if (selectedSocket != null) {
result = Result.SUCCESS;
}
}
@@ -2720,8 +2674,7 @@ void close(Selector selector) {
try {
selector.close();
- }
- catch (IOException e) {
+ } catch (IOException e) {
if (logger.isLoggable(Level.FINE))
logger.log(Level.FINE, this.toString() + ": Ignored the following error while closing Selector", e);
}
@@ -2735,8 +2688,7 @@ void close(Socket socket) {
try {
socket.close();
- }
- catch (IOException e) {
+ } catch (IOException e) {
if (logger.isLoggable(Level.FINE))
logger.log(Level.FINE, this.toString() + ": Ignored the following error while closing socket", e);
}
@@ -2750,29 +2702,28 @@ void close(SocketChannel socketChannel) {
try {
socketChannel.close();
- }
- catch (IOException e) {
+ } catch (IOException e) {
if (logger.isLoggable(Level.FINE))
- logger.log(Level.FINE, this.toString() + "Ignored the following error while closing socketChannel", e);
+ logger.log(Level.FINE, this.toString() + "Ignored the following error while closing socketChannel",
+ e);
}
}
}
/**
- * Used by socketConnector threads to notify the socketFinder of their connection attempt result(a connected socket or exception). It updates the
- * result, socket and exception variables of socketFinder object. This method notifies the parent thread if a socket is found or if all the
- * spawned threads have notified. It also closes a socket if it is not selected for use by socketFinder.
+ * Used by socketConnector threads to notify the socketFinder of their connection attempt result(a connected socket
+ * or exception). It updates the result, socket and exception variables of socketFinder object. This method notifies
+ * the parent thread if a socket is found or if all the spawned threads have notified. It also closes a socket if it
+ * is not selected for use by socketFinder.
*
* @param socket
- * the SocketConnector's socket
+ * the SocketConnector's socket
* @param exception
- * Exception that occurred in socket connector thread
+ * Exception that occurred in socket connector thread
* @param threadId
- * Id of the calling Thread for diagnosis
+ * Id of the calling Thread for diagnosis
*/
- void updateResult(Socket socket,
- IOException exception,
- String threadId) {
+ void updateResult(Socket socket, IOException exception, String threadId) {
if (result.equals(Result.UNKNOWN)) {
if (logger.isLoggable(Level.FINER)) {
logger.finer("The following child thread is waiting for socketFinderLock:" + threadId);
@@ -2844,7 +2795,9 @@ void updateResult(Socket socket,
}
if (logger.isLoggable(Level.FINER)) {
- logger.finer("The following child thread released parentThreadLock and notified the parent thread:" + threadId);
+ logger.finer(
+ "The following child thread released parentThreadLock and notified the parent thread:"
+ + threadId);
}
}
}
@@ -2863,27 +2816,27 @@ void updateResult(Socket socket,
*
* b) ex is a non-socketTimeoutException and selectedException is a socketTimeoutException
*
- * If there are multiple exceptions, that are not related to socketTimeout the first non-socketTimeout exception is picked. If all exceptions are
- * related to socketTimeout, the first exception is picked. Note: This method is not thread safe. The caller should ensure thread safety.
+ * If there are multiple exceptions, that are not related to socketTimeout the first non-socketTimeout exception is
+ * picked. If all exceptions are related to socketTimeout, the first exception is picked. Note: This method is not
+ * thread safe. The caller should ensure thread safety.
*
* @param ex
- * the IOException
+ * the IOException
* @param traceId
- * the traceId of the thread
+ * the traceId of the thread
*/
- public void updateSelectedException(IOException ex,
- String traceId) {
+ public void updateSelectedException(IOException ex, String traceId) {
boolean updatedException = false;
- if (selectedException == null ||
- (!(ex instanceof SocketTimeoutException)) && (selectedException instanceof SocketTimeoutException)) {
+ if (selectedException == null
+ || (!(ex instanceof SocketTimeoutException)) && (selectedException instanceof SocketTimeoutException)) {
selectedException = ex;
updatedException = true;
}
if (updatedException) {
if (logger.isLoggable(Level.FINER)) {
- logger.finer("The selected exception is updated to the following: ExceptionType:" + ex.getClass() + "; ExceptionMessage:"
- + ex.getMessage() + "; by the following thread:" + traceId);
+ logger.finer("The selected exception is updated to the following: ExceptionType:" + ex.getClass()
+ + "; ExceptionMessage:" + ex.getMessage() + "; by the following thread:" + traceId);
}
}
}
@@ -2898,6 +2851,7 @@ public String toString() {
}
}
+
/**
* This is used to connect a socket in a separate thread
*/
@@ -2928,9 +2882,7 @@ final class SocketConnector implements Runnable {
/**
* Constructs a new SocketConnector object with the associated socket and socketFinder
*/
- SocketConnector(Socket socket,
- InetSocketAddress inetSocketAddress,
- int timeOutInMilliSeconds,
+ SocketConnector(Socket socket, InetSocketAddress inetSocketAddress, int timeOutInMilliSeconds,
SocketFinder socketFinder) {
this.socket = socket;
this.inetSocketAddress = inetSocketAddress;
@@ -2941,8 +2893,8 @@ final class SocketConnector implements Runnable {
}
/**
- * If search for socket has not finished, this function tries to connect a socket(with a timeout) synchronously. It further notifies the
- * socketFinder the result of the connection attempt
+ * If search for socket has not finished, this function tries to connect a socket(with a timeout) synchronously. It
+ * further notifies the socketFinder the result of the connection attempt
*/
public void run() {
IOException exception = null;
@@ -2953,13 +2905,12 @@ public void run() {
if (result.equals(SocketFinder.Result.UNKNOWN)) {
try {
if (logger.isLoggable(Level.FINER)) {
- logger.finer(
- this.toString() + " connecting to InetSocketAddress:" + inetSocketAddress + " with timeout:" + timeoutInMilliseconds);
+ logger.finer(this.toString() + " connecting to InetSocketAddress:" + inetSocketAddress
+ + " with timeout:" + timeoutInMilliseconds);
}
socket.connect(inetSocketAddress, timeoutInMilliseconds);
- }
- catch (IOException ex) {
+ } catch (IOException ex) {
if (logger.isLoggable(Level.FINER)) {
logger.finer(this.toString() + " exception:" + ex.getClass() + " with message:" + ex.getMessage()
+ " occured while connecting to InetSocketAddress:" + inetSocketAddress);
@@ -2989,14 +2940,14 @@ private static synchronized long nextThreadID() {
if (logger.isLoggable(Level.FINER))
logger.finer("Resetting the Id count");
lastThreadID = 1;
- }
- else {
+ } else {
lastThreadID++;
}
return lastThreadID;
}
}
+
/**
* TDSWriter implements the client to server TDS data pipe.
*/
@@ -3077,8 +3028,7 @@ boolean isEOMSent() {
private CryptoMetadata cryptoMeta = null;
- TDSWriter(TDSChannel tdsChannel,
- SQLServerConnection con) {
+ TDSWriter(TDSChannel tdsChannel, SQLServerConnection con) {
this.tdsChannel = tdsChannel;
this.con = con;
traceID = "TDSWriter@" + Integer.toHexString(hashCode()) + " (" + con.toString() + ")";
@@ -3089,7 +3039,7 @@ boolean isEOMSent() {
void preparePacket() throws SQLServerException {
if (tdsChannel.isLoggingPackets()) {
Arrays.fill(logBuffer.array(), (byte) 0xFE);
- ((Buffer)logBuffer).clear();
+ ((Buffer) logBuffer).clear();
}
// Write a placeholder packet header. This will be replaced
@@ -3108,7 +3058,8 @@ void writeMessageHeader() throws SQLServerException {
boolean includeTraceHeader = false;
int totalHeaderLength = TDS.MESSAGE_HEADER_LENGTH;
if (TDS.PKT_QUERY == tdsMessageType || TDS.PKT_RPC == tdsMessageType) {
- if (con.isDenaliOrLater() && !ActivityCorrelator.getCurrent().IsSentToServer() && Util.IsActivityTraceOn()) {
+ if (con.isDenaliOrLater() && !ActivityCorrelator.getCurrent().IsSentToServer()
+ && Util.IsActivityTraceOn()) {
includeTraceHeader = true;
totalHeaderLength += TDS.TRACE_HEADER_LENGTH;
}
@@ -3130,9 +3081,9 @@ void writeTraceHeaderData() throws SQLServerException {
ActivityId activityId = ActivityCorrelator.getCurrent();
final byte[] actIdByteArray = Util.asGuidByteArray(activityId.getId());
long seqNum = activityId.getSequence();
- writeShort(TDS.HEADERTYPE_TRACE); // trace header type
- writeBytes(actIdByteArray, 0, actIdByteArray.length); // guid part of ActivityId
- writeInt((int) seqNum); // sequence number of ActivityId
+ writeShort(TDS.HEADERTYPE_TRACE); // trace header type
+ writeBytes(actIdByteArray, 0, actIdByteArray.length); // guid part of ActivityId
+ writeInt((int) seqNum); // sequence number of ActivityId
if (logger.isLoggable(Level.FINER))
logger.finer("Send Trace Header - ActivityID: " + activityId.toString());
@@ -3142,12 +3093,11 @@ void writeTraceHeaderData() throws SQLServerException {
* Convenience method to prepare the TDS channel for writing and start a new TDS message.
*
* @param command
- * The TDS command
+ * The TDS command
* @param tdsMessageType
- * The TDS message type (PKT_QUERY, PKT_RPC, etc.)
+ * The TDS message type (PKT_QUERY, PKT_RPC, etc.)
*/
- void startMessage(TDSCommand command,
- byte tdsMessageType) throws SQLServerException {
+ void startMessage(TDSCommand command, byte tdsMessageType) throws SQLServerException {
this.command = command;
this.tdsMessageType = tdsMessageType;
this.packetNum = 0;
@@ -3166,7 +3116,7 @@ void startMessage(TDSCommand command,
}
((Buffer) socketBuffer).position(((Buffer) socketBuffer).limit());
- ((Buffer)stagingBuffer).clear();
+ ((Buffer) stagingBuffer).clear();
preparePacket();
writeMessageHeader();
@@ -3208,10 +3158,9 @@ void writeByte(byte value) throws SQLServerException {
if (dataIsLoggable)
logBuffer.put(value);
else
- ((Buffer)logBuffer).position(((Buffer)logBuffer).position() + 1);
+ ((Buffer) logBuffer).position(((Buffer) logBuffer).position() + 1);
}
- }
- else {
+ } else {
valueBytes[0] = value;
writeWrappedBytes(valueBytes, 1);
}
@@ -3235,10 +3184,9 @@ void writeChar(char value) throws SQLServerException {
if (dataIsLoggable)
logBuffer.putChar(value);
else
- ((Buffer)logBuffer).position( ((Buffer)logBuffer).position() + 2);
+ ((Buffer) logBuffer).position(((Buffer) logBuffer).position() + 2);
}
- }
- else {
+ } else {
Util.writeShort((short) value, valueBytes, 0);
writeWrappedBytes(valueBytes, 2);
}
@@ -3251,10 +3199,9 @@ void writeShort(short value) throws SQLServerException {
if (dataIsLoggable)
logBuffer.putShort(value);
else
- ((Buffer)logBuffer).position( ((Buffer)logBuffer).position() + 2);
+ ((Buffer) logBuffer).position(((Buffer) logBuffer).position() + 2);
}
- }
- else {
+ } else {
Util.writeShort(value, valueBytes, 0);
writeWrappedBytes(valueBytes, 2);
}
@@ -3267,10 +3214,9 @@ void writeInt(int value) throws SQLServerException {
if (dataIsLoggable)
logBuffer.putInt(value);
else
- ((Buffer)logBuffer).position( ((Buffer)logBuffer).position() + 4);
+ ((Buffer) logBuffer).position(((Buffer) logBuffer).position() + 4);
}
- }
- else {
+ } else {
Util.writeInt(value, valueBytes, 0);
writeWrappedBytes(valueBytes, 4);
}
@@ -3280,7 +3226,7 @@ void writeInt(int value) throws SQLServerException {
* Append a real value in the TDS stream.
*
* @param value
- * the data value
+ * the data value
*/
void writeReal(Float value) throws SQLServerException {
writeInt(Float.floatToRawIntBits(value));
@@ -3290,7 +3236,7 @@ void writeReal(Float value) throws SQLServerException {
* Append a double value in the TDS stream.
*
* @param value
- * the data value
+ * the data value
*/
void writeDouble(double value) throws SQLServerException {
if (stagingBuffer.remaining() >= 8) {
@@ -3299,10 +3245,9 @@ void writeDouble(double value) throws SQLServerException {
if (dataIsLoggable)
logBuffer.putDouble(value);
else
- ((Buffer)logBuffer).position( ((Buffer)logBuffer).position() + 8);
+ ((Buffer) logBuffer).position(((Buffer) logBuffer).position() + 8);
}
- }
- else {
+ } else {
long bits = Double.doubleToLongBits(value);
long mask = 0xFF;
int nShift = 0;
@@ -3318,27 +3263,27 @@ void writeDouble(double value) throws SQLServerException {
* Append a big decimal in the TDS stream.
*
* @param bigDecimalVal
- * the big decimal data value
+ * the big decimal data value
* @param srcJdbcType
- * the source JDBCType
+ * the source JDBCType
* @param precision
- * the precision of the data value
+ * the precision of the data value
* @param scale
- * the scale of the column
+ * the scale of the column
* @throws SQLServerException
*/
- void writeBigDecimal(BigDecimal bigDecimalVal,
- int srcJdbcType,
- int precision,
+ void writeBigDecimal(BigDecimal bigDecimalVal, int srcJdbcType, int precision,
int scale) throws SQLServerException {
/*
- * Length including sign byte One 1-byte unsigned integer that represents the sign of the decimal value (0 => Negative, 1 => positive) One 4-,
- * 8-, 12-, or 16-byte signed integer that represents the decimal value multiplied by 10^scale.
+ * Length including sign byte One 1-byte unsigned integer that represents the sign of the decimal value (0 =>
+ * Negative, 1 => positive) One 4-, 8-, 12-, or 16-byte signed integer that represents the decimal value
+ * multiplied by 10^scale.
*/
/*
- * setScale of all BigDecimal value based on metadata as scale is not sent seperately for individual value. Use the rounding used in Server.
- * Say, for BigDecimal("0.1"), if scale in metdadata is 0, then ArithmeticException would be thrown if RoundingMode is not set
+ * setScale of all BigDecimal value based on metadata as scale is not sent seperately for individual value. Use
+ * the rounding used in Server. Say, for BigDecimal("0.1"), if scale in metdadata is 0, then ArithmeticException
+ * would be thrown if RoundingMode is not set
*/
bigDecimalVal = bigDecimalVal.setScale(scale, RoundingMode.HALF_UP);
@@ -3354,27 +3299,26 @@ void writeBigDecimal(BigDecimal bigDecimalVal,
System.arraycopy(valueBytes, 2, bytes, 0, valueBytes.length - 2);
writeBytes(bytes);
}
-
+
/**
* Append a big decimal inside sql_variant in the TDS stream.
*
* @param bigDecimalVal
- * the big decimal data value
+ * the big decimal data value
* @param srcJdbcType
- * the source JDBCType
+ * the source JDBCType
*/
- void writeSqlVariantInternalBigDecimal(BigDecimal bigDecimalVal,
- int srcJdbcType) throws SQLServerException {
+ void writeSqlVariantInternalBigDecimal(BigDecimal bigDecimalVal, int srcJdbcType) throws SQLServerException {
/*
- * Length including sign byte One 1-byte unsigned integer that represents the sign of the decimal value (0 => Negative, 1 => positive) One
- * 16-byte signed integer that represents the decimal value multiplied by 10^scale. In sql_variant, we send the bigdecimal with precision 38,
- * therefore we use 16 bytes for the maximum size of this integer.
+ * Length including sign byte One 1-byte unsigned integer that represents the sign of the decimal value (0 =>
+ * Negative, 1 => positive) One 16-byte signed integer that represents the decimal value multiplied by 10^scale.
+ * In sql_variant, we send the bigdecimal with precision 38, therefore we use 16 bytes for the maximum size of
+ * this integer.
*/
boolean isNegative = (bigDecimalVal.signum() < 0);
BigInteger bi = bigDecimalVal.unscaledValue();
- if (isNegative)
- {
+ if (isNegative) {
bi = bi.negate();
}
int bLength;
@@ -3390,7 +3334,8 @@ void writeSqlVariantInternalBigDecimal(BigDecimal bigDecimalVal,
// If precession of input is greater than maximum allowed (p><= 38) throw Exception
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_valueOutOfRange"));
Object[] msgArgs = {JDBCType.of(srcJdbcType)};
- throw new SQLServerException(form.format(msgArgs), SQLState.DATA_EXCEPTION_LENGTH_MISMATCH, DriverError.NOT_SET, null);
+ throw new SQLServerException(form.format(msgArgs), SQLState.DATA_EXCEPTION_LENGTH_MISMATCH,
+ DriverError.NOT_SET, null);
}
// Byte array to hold all the reversed and padding bytes.
@@ -3406,8 +3351,7 @@ void writeSqlVariantInternalBigDecimal(BigDecimal bigDecimalVal,
bytes[i++] = unscaledBytes[j--];
// Fill the rest of the array with zeros.
- for (; i < remaining; i++)
- {
+ for (; i < remaining; i++) {
bytes[i] = (byte) 0x00;
}
writeBytes(bytes);
@@ -3415,7 +3359,7 @@ void writeSqlVariantInternalBigDecimal(BigDecimal bigDecimalVal,
void writeSmalldatetime(String value) throws SQLServerException {
GregorianCalendar calendar = initializeCalender(TimeZone.getDefault());
- long utcMillis; // Value to which the calendar is to be set (in milliseconds 1/1/1970 00:00:00 GMT)
+ long utcMillis; // Value to which the calendar is to be set (in milliseconds 1/1/1970 00:00:00 GMT)
java.sql.Timestamp timestampValue = java.sql.Timestamp.valueOf(value);
utcMillis = timestampValue.getTime();
@@ -3423,7 +3367,8 @@ void writeSmalldatetime(String value) throws SQLServerException {
calendar.setTimeInMillis(utcMillis);
// Number of days since the SQL Server Base Date (January 1, 1900)
- int daysSinceSQLBaseDate = DDC.daysSinceBaseDate(calendar.get(Calendar.YEAR), calendar.get(Calendar.DAY_OF_YEAR), TDS.BASE_YEAR_1900);
+ int daysSinceSQLBaseDate = DDC.daysSinceBaseDate(calendar.get(Calendar.YEAR),
+ calendar.get(Calendar.DAY_OF_YEAR), TDS.BASE_YEAR_1900);
// Next, figure out the number of milliseconds since midnight of the current day.
int millisSinceMidnight = 1000 * calendar.get(Calendar.SECOND) + // Seconds into the current minute
@@ -3452,7 +3397,7 @@ void writeSmalldatetime(String value) throws SQLServerException {
void writeDatetime(String value) throws SQLServerException {
GregorianCalendar calendar = initializeCalender(TimeZone.getDefault());
- long utcMillis; // Value to which the calendar is to be set (in milliseconds 1/1/1970 00:00:00 GMT)
+ long utcMillis; // Value to which the calendar is to be set (in milliseconds 1/1/1970 00:00:00 GMT)
int subSecondNanos;
java.sql.Timestamp timestampValue = java.sql.Timestamp.valueOf(value);
utcMillis = timestampValue.getTime();
@@ -3463,10 +3408,13 @@ void writeDatetime(String value) throws SQLServerException {
// Number of days there have been since the SQL Base Date.
// These are based on SQL Server algorithms
- int daysSinceSQLBaseDate = DDC.daysSinceBaseDate(calendar.get(Calendar.YEAR), calendar.get(Calendar.DAY_OF_YEAR), TDS.BASE_YEAR_1900);
+ int daysSinceSQLBaseDate = DDC.daysSinceBaseDate(calendar.get(Calendar.YEAR),
+ calendar.get(Calendar.DAY_OF_YEAR), TDS.BASE_YEAR_1900);
// Number of milliseconds since midnight of the current day.
- int millisSinceMidnight = (subSecondNanos + Nanos.PER_MILLISECOND / 2) / Nanos.PER_MILLISECOND + // Millis into the current second
+ int millisSinceMidnight = (subSecondNanos + Nanos.PER_MILLISECOND / 2) / Nanos.PER_MILLISECOND + // Millis into
+ // the current
+ // second
1000 * calendar.get(Calendar.SECOND) + // Seconds into the current minute
60 * 1000 * calendar.get(Calendar.MINUTE) + // Minutes into the current hour
60 * 60 * 1000 * calendar.get(Calendar.HOUR_OF_DAY); // Hours into the current day
@@ -3488,7 +3436,8 @@ void writeDatetime(String value) throws SQLServerException {
|| daysSinceSQLBaseDate >= DDC.daysSinceBaseDate(10000, 1, TDS.BASE_YEAR_1900)) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_valueOutOfRange"));
Object[] msgArgs = {SSType.DATETIME};
- throw new SQLServerException(form.format(msgArgs), SQLState.DATA_EXCEPTION_DATETIME_FIELD_OVERFLOW, DriverError.NOT_SET, null);
+ throw new SQLServerException(form.format(msgArgs), SQLState.DATA_EXCEPTION_DATETIME_FIELD_OVERFLOW,
+ DriverError.NOT_SET, null);
}
// Number of days since the SQL Server Base Date (January 1, 1900)
@@ -3512,10 +3461,9 @@ void writeDate(String value) throws SQLServerException {
SSType.DATE);
}
- void writeTime(java.sql.Timestamp value,
- int scale) throws SQLServerException {
+ void writeTime(java.sql.Timestamp value, int scale) throws SQLServerException {
GregorianCalendar calendar = initializeCalender(TimeZone.getDefault());
- long utcMillis; // Value to which the calendar is to be set (in milliseconds 1/1/1970 00:00:00 GMT)
+ long utcMillis; // Value to which the calendar is to be set (in milliseconds 1/1/1970 00:00:00 GMT)
int subSecondNanos;
utcMillis = value.getTime();
subSecondNanos = value.getNanos();
@@ -3526,12 +3474,10 @@ void writeTime(java.sql.Timestamp value,
writeScaledTemporal(calendar, subSecondNanos, scale, SSType.TIME);
}
- void writeDateTimeOffset(Object value,
- int scale,
- SSType destSSType) throws SQLServerException {
+ void writeDateTimeOffset(Object value, int scale, SSType destSSType) throws SQLServerException {
GregorianCalendar calendar;
TimeZone timeZone; // Time zone to associate with the value in the Gregorian calendar
- long utcMillis; // Value to which the calendar is to be set (in milliseconds 1/1/1970 00:00:00 GMT)
+ long utcMillis; // Value to which the calendar is to be set (in milliseconds 1/1/1970 00:00:00 GMT)
int subSecondNanos;
int minutesOffset;
@@ -3545,7 +3491,8 @@ void writeDateTimeOffset(Object value,
// Otherwise, when converting from DATETIMEOFFSET to other temporal data types,
// use a local time zone determined by the minutes offset of the value, since
// the writers for those types expect local calendars.
- timeZone = (SSType.DATETIMEOFFSET == destSSType) ? UTC.timeZone : new SimpleTimeZone(minutesOffset * 60 * 1000, "");
+ timeZone = (SSType.DATETIMEOFFSET == destSSType) ? UTC.timeZone
+ : new SimpleTimeZone(minutesOffset * 60 * 1000, "");
calendar = new GregorianCalendar(timeZone, Locale.US);
calendar.setLenient(true);
@@ -3557,8 +3504,7 @@ void writeDateTimeOffset(Object value,
writeShort((short) minutesOffset);
}
- void writeOffsetDateTimeWithTimezone(OffsetDateTime offsetDateTimeValue,
- int scale) throws SQLServerException {
+ void writeOffsetDateTimeWithTimezone(OffsetDateTime offsetDateTimeValue, int scale) throws SQLServerException {
GregorianCalendar calendar;
TimeZone timeZone;
long utcMillis;
@@ -3570,9 +3516,10 @@ void writeOffsetDateTimeWithTimezone(OffsetDateTime offsetDateTimeValue,
// components. So the result of the division will be an integer always. SQL Server also supports
// offsets in minutes precision.
minutesOffset = offsetDateTimeValue.getOffset().getTotalSeconds() / 60;
- }
- catch (Exception e) {
- throw new SQLServerException(SQLServerException.getErrString("R_zoneOffsetError"), null, // SQLState is null as this error is generated in
+ } catch (Exception e) {
+ throw new SQLServerException(SQLServerException.getErrString("R_zoneOffsetError"), null, // SQLState is null
+ // as this error is
+ // generated in
// the driver
0, // Use 0 instead of DriverError.NOT_SET to use the correct constructor
e);
@@ -3592,9 +3539,11 @@ void writeOffsetDateTimeWithTimezone(OffsetDateTime offsetDateTimeValue,
timeZone = UTC.timeZone;
// The behavior is similar to microsoft.sql.DateTimeOffset
- // In Timestamp format, only YEAR needs to have 4 digits. The leading zeros for the rest of the fields can be omitted.
- String offDateTimeStr = String.format("%04d", offsetDateTimeValue.getYear()) + '-' + offsetDateTimeValue.getMonthValue() + '-'
- + offsetDateTimeValue.getDayOfMonth() + ' ' + offsetDateTimeValue.getHour() + ':' + offsetDateTimeValue.getMinute() + ':'
+ // In Timestamp format, only YEAR needs to have 4 digits. The leading zeros for the rest of the fields can be
+ // omitted.
+ String offDateTimeStr = String.format("%04d", offsetDateTimeValue.getYear()) + '-'
+ + offsetDateTimeValue.getMonthValue() + '-' + offsetDateTimeValue.getDayOfMonth() + ' '
+ + offsetDateTimeValue.getHour() + ':' + offsetDateTimeValue.getMinute() + ':'
+ offsetDateTimeValue.getSecond();
utcMillis = Timestamp.valueOf(offDateTimeStr).getTime();
calendar = initializeCalender(timeZone);
@@ -3613,8 +3562,7 @@ void writeOffsetDateTimeWithTimezone(OffsetDateTime offsetDateTimeValue,
writeShort((short) minutesOffset);
}
- void writeOffsetTimeWithTimezone(OffsetTime offsetTimeValue,
- int scale) throws SQLServerException {
+ void writeOffsetTimeWithTimezone(OffsetTime offsetTimeValue, int scale) throws SQLServerException {
GregorianCalendar calendar;
TimeZone timeZone;
long utcMillis;
@@ -3626,9 +3574,10 @@ void writeOffsetTimeWithTimezone(OffsetTime offsetTimeValue,
// components. So the result of the division will be an integer always. SQL Server also supports
// offsets in minutes precision.
minutesOffset = offsetTimeValue.getOffset().getTotalSeconds() / 60;
- }
- catch (Exception e) {
- throw new SQLServerException(SQLServerException.getErrString("R_zoneOffsetError"), null, // SQLState is null as this error is generated in
+ } catch (Exception e) {
+ throw new SQLServerException(SQLServerException.getErrString("R_zoneOffsetError"), null, // SQLState is null
+ // as this error is
+ // generated in
// the driver
0, // Use 0 instead of DriverError.NOT_SET to use the correct constructor
e);
@@ -3651,8 +3600,8 @@ void writeOffsetTimeWithTimezone(OffsetTime offsetTimeValue,
// If date only contains a time part, the return value is 1900, the base year.
// https://msdn.microsoft.com/en-us/library/ms186313.aspx
// In Timestamp format, leading zeros for the fields can be omitted.
- String offsetTimeStr = TDS.BASE_YEAR_1900 + "-01-01" + ' ' + offsetTimeValue.getHour() + ':' + offsetTimeValue.getMinute() + ':'
- + offsetTimeValue.getSecond();
+ String offsetTimeStr = TDS.BASE_YEAR_1900 + "-01-01" + ' ' + offsetTimeValue.getHour() + ':'
+ + offsetTimeValue.getMinute() + ':' + offsetTimeValue.getSecond();
utcMillis = Timestamp.valueOf(offsetTimeStr).getTime();
calendar = initializeCalender(timeZone);
@@ -3677,10 +3626,9 @@ void writeLong(long value) throws SQLServerException {
if (dataIsLoggable)
logBuffer.putLong(value);
else
- ((Buffer)logBuffer).position( ((Buffer)logBuffer).position() + 8);
+ ((Buffer) logBuffer).position(((Buffer) logBuffer).position() + 8);
}
- }
- else {
+ } else {
valueBytes[0] = (byte) ((value >> 0) & 0xFF);
valueBytes[1] = (byte) ((value >> 8) & 0xFF);
valueBytes[2] = (byte) ((value >> 16) & 0xFF);
@@ -3697,9 +3645,7 @@ void writeBytes(byte[] value) throws SQLServerException {
writeBytes(value, 0, value.length);
}
- void writeBytes(byte[] value,
- int offset,
- int length) throws SQLServerException {
+ void writeBytes(byte[] value, int offset, int length) throws SQLServerException {
assert length <= value.length;
int bytesWritten = 0;
@@ -3720,20 +3666,19 @@ void writeBytes(byte[] value,
if (dataIsLoggable)
logBuffer.put(value, offset + bytesWritten, bytesToWrite);
else
- ((Buffer)logBuffer).position( ((Buffer)logBuffer).position() + bytesToWrite);
+ ((Buffer) logBuffer).position(((Buffer) logBuffer).position() + bytesToWrite);
}
bytesWritten += bytesToWrite;
}
}
- void writeWrappedBytes(byte value[],
- int valueLength) throws SQLServerException {
+ void writeWrappedBytes(byte value[], int valueLength) throws SQLServerException {
// This function should only be used to write a value that is longer than
// what remains in the current staging buffer. However, the value must
// be short enough to fit in an empty buffer.
assert valueLength <= value.length;
-
+
int remaining = stagingBuffer.remaining();
assert remaining < valueLength;
@@ -3747,7 +3692,7 @@ void writeWrappedBytes(byte value[],
if (dataIsLoggable)
logBuffer.put(value, 0, remaining);
else
- ((Buffer)logBuffer).position( ((Buffer)logBuffer).position() + remaining);
+ ((Buffer) logBuffer).position(((Buffer) logBuffer).position() + remaining);
}
}
@@ -3760,7 +3705,7 @@ void writeWrappedBytes(byte value[],
if (dataIsLoggable)
logBuffer.put(value, remaining, valueLength - remaining);
else
- ((Buffer)logBuffer).position( ((Buffer)logBuffer).position() + remaining);
+ ((Buffer) logBuffer).position(((Buffer) logBuffer).position() + remaining);
}
}
@@ -3784,8 +3729,7 @@ void writeString(String value) throws SQLServerException {
}
}
- void writeStream(InputStream inputStream,
- long advertisedLength,
+ void writeStream(InputStream inputStream, long advertisedLength,
boolean writeChunkSizes) throws SQLServerException {
assert DataTypes.UNKNOWN_STREAM_LENGTH == advertisedLength || advertisedLength >= 0;
@@ -3795,11 +3739,12 @@ void writeStream(InputStream inputStream,
int bytesToWrite;
do {
// Read in next chunk
- for (bytesToWrite = 0; -1 != bytesRead && bytesToWrite < streamByteBuffer.length; bytesToWrite += bytesRead) {
+ for (bytesToWrite = 0; -1 != bytesRead && bytesToWrite < streamByteBuffer.length;
+ bytesToWrite += bytesRead) {
try {
- bytesRead = inputStream.read(streamByteBuffer, bytesToWrite, streamByteBuffer.length - bytesToWrite);
- }
- catch (IOException e) {
+ bytesRead = inputStream.read(streamByteBuffer, bytesToWrite,
+ streamByteBuffer.length - bytesToWrite);
+ } catch (IOException e) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_errorReadingStream"));
Object[] msgArgs = {e.toString()};
error(form.format(msgArgs), SQLState.DATA_EXCEPTION_NOT_SPECIFIC, DriverError.NOT_SET);
@@ -3822,8 +3767,7 @@ void writeStream(InputStream inputStream,
writeBytes(streamByteBuffer, 0, bytesToWrite);
actualLength += bytesToWrite;
- }
- while (-1 != bytesRead || bytesToWrite > 0);
+ } while (-1 != bytesRead || bytesToWrite > 0);
// If we were given an input stream length that we had to match and
// the actual stream length did not match then cancel the request.
@@ -3835,20 +3779,19 @@ void writeStream(InputStream inputStream,
}
/*
- * Adding another function for writing non-unicode reader instead of re-factoring the writeReader() for performance efficiency. As this method
- * will only be used in bulk copy, it needs to be efficient. Note: Any changes in algorithm/logic should propagate to both writeReader() and
- * writeNonUnicodeReader().
+ * Adding another function for writing non-unicode reader instead of re-factoring the writeReader() for performance
+ * efficiency. As this method will only be used in bulk copy, it needs to be efficient. Note: Any changes in
+ * algorithm/logic should propagate to both writeReader() and writeNonUnicodeReader().
*/
- void writeNonUnicodeReader(Reader reader,
- long advertisedLength,
- boolean isDestBinary,
+ void writeNonUnicodeReader(Reader reader, long advertisedLength, boolean isDestBinary,
Charset charSet) throws SQLServerException {
assert DataTypes.UNKNOWN_STREAM_LENGTH == advertisedLength || advertisedLength >= 0;
long actualLength = 0;
char[] streamCharBuffer = new char[currentPacketSize];
- // The unicode version, writeReader() allocates a byte buffer that is 4 times the currentPacketSize, not sure why.
+ // The unicode version, writeReader() allocates a byte buffer that is 4 times the currentPacketSize, not sure
+ // why.
byte[] streamByteBuffer = new byte[currentPacketSize];
int charsRead = 0;
int charsToWrite;
@@ -3857,11 +3800,11 @@ void writeNonUnicodeReader(Reader reader,
do {
// Read in next chunk
- for (charsToWrite = 0; -1 != charsRead && charsToWrite < streamCharBuffer.length; charsToWrite += charsRead) {
+ for (charsToWrite = 0; -1 != charsRead && charsToWrite < streamCharBuffer.length;
+ charsToWrite += charsRead) {
try {
charsRead = reader.read(streamCharBuffer, charsToWrite, streamCharBuffer.length - charsToWrite);
- }
- catch (IOException e) {
+ } catch (IOException e) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_errorReadingStream"));
Object[] msgArgs = {e.toString()};
error(form.format(msgArgs), SQLState.DATA_EXCEPTION_NOT_SPECIFIC, DriverError.NOT_SET);
@@ -3882,21 +3825,21 @@ void writeNonUnicodeReader(Reader reader,
// Write it out
// This also writes the PLP_TERMINATOR token after all the data in the the stream are sent.
// The Do-While loop goes on one more time as charsToWrite is greater than 0 for the last chunk, and
- // in this last round the only thing that is written is an int value of 0, which is the PLP Terminator token(0x00000000).
+ // in this last round the only thing that is written is an int value of 0, which is the PLP Terminator
+ // token(0x00000000).
writeInt(charsToWrite);
for (int charsCopied = 0; charsCopied < charsToWrite; ++charsCopied) {
if (null == charSet) {
streamByteBuffer[charsCopied] = (byte) (streamCharBuffer[charsCopied] & 0xFF);
- }
- else {
+ } else {
// encoding as per collation
- streamByteBuffer[charsCopied] = new String(streamCharBuffer[charsCopied] + "").getBytes(charSet)[0];
+ streamByteBuffer[charsCopied] = new String(streamCharBuffer[charsCopied] + "")
+ .getBytes(charSet)[0];
}
}
writeBytes(streamByteBuffer, 0, charsToWrite);
- }
- else {
+ } else {
bytesToWrite = charsToWrite;
if (0 != charsToWrite)
bytesToWrite = charsToWrite / 2;
@@ -3907,8 +3850,7 @@ void writeNonUnicodeReader(Reader reader,
writeBytes(bytes, 0, bytesToWrite);
}
actualLength += charsToWrite;
- }
- while (-1 != charsRead || charsToWrite > 0);
+ } while (-1 != charsRead || charsToWrite > 0);
// If we were given an input stream length that we had to match and
// the actual stream length did not match then cancel the request.
@@ -3917,15 +3859,14 @@ void writeNonUnicodeReader(Reader reader,
Object[] msgArgs = {advertisedLength, actualLength};
error(form.format(msgArgs), SQLState.DATA_EXCEPTION_LENGTH_MISMATCH, DriverError.NOT_SET);
}
- }
+ }
/*
- * Note: There is another method with same code logic for non unicode reader, writeNonUnicodeReader(), implemented for performance efficiency. Any
- * changes in algorithm/logic should propagate to both writeReader() and writeNonUnicodeReader().
+ * Note: There is another method with same code logic for non unicode reader, writeNonUnicodeReader(), implemented
+ * for performance efficiency. Any changes in algorithm/logic should propagate to both writeReader() and
+ * writeNonUnicodeReader().
*/
- void writeReader(Reader reader,
- long advertisedLength,
- boolean writeChunkSizes) throws SQLServerException {
+ void writeReader(Reader reader, long advertisedLength, boolean writeChunkSizes) throws SQLServerException {
assert DataTypes.UNKNOWN_STREAM_LENGTH == advertisedLength || advertisedLength >= 0;
long actualLength = 0;
@@ -3935,11 +3876,11 @@ void writeReader(Reader reader,
int charsToWrite;
do {
// Read in next chunk
- for (charsToWrite = 0; -1 != charsRead && charsToWrite < streamCharBuffer.length; charsToWrite += charsRead) {
+ for (charsToWrite = 0; -1 != charsRead && charsToWrite < streamCharBuffer.length;
+ charsToWrite += charsRead) {
try {
charsRead = reader.read(streamCharBuffer, charsToWrite, streamCharBuffer.length - charsToWrite);
- }
- catch (IOException e) {
+ } catch (IOException e) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_errorReadingStream"));
Object[] msgArgs = {e.toString()};
error(form.format(msgArgs), SQLState.DATA_EXCEPTION_NOT_SPECIFIC, DriverError.NOT_SET);
@@ -3972,8 +3913,7 @@ void writeReader(Reader reader,
writeBytes(streamByteBuffer, 0, 2 * charsToWrite);
actualLength += charsToWrite;
- }
- while (-1 != charsRead || charsToWrite > 0);
+ } while (-1 != charsRead || charsToWrite > 0);
// If we were given an input stream length that we had to match and
// the actual stream length did not match then cancel the request.
@@ -4002,22 +3942,21 @@ GregorianCalendar initializeCalender(TimeZone timeZone) {
return calendar;
}
- final void error(String reason,
- SQLState sqlState,
- DriverError driverError) throws SQLServerException {
+ final void error(String reason, SQLState sqlState, DriverError driverError) throws SQLServerException {
assert null != command;
command.interrupt(reason);
throw new SQLServerException(reason, sqlState, driverError, null);
}
/**
- * Sends an attention signal to the server, if necessary, to tell it to stop processing the current command on this connection.
+ * Sends an attention signal to the server, if necessary, to tell it to stop processing the current command on this
+ * connection.
*
- * If no packets of the command's request have yet been sent to the server, then no attention signal needs to be sent. The interrupt will be
- * handled entirely by the driver.
+ * If no packets of the command's request have yet been sent to the server, then no attention signal needs to be
+ * sent. The interrupt will be handled entirely by the driver.
*
- * This method does not need synchronization as it does not manipulate interrupt state and writing is guaranteed to occur only from one thread at
- * a time.
+ * This method does not need synchronization as it does not manipulate interrupt state and writing is guaranteed to
+ * occur only from one thread at a time.
*/
final boolean sendAttention() throws SQLServerException {
// If any request packets were already written to the server then send an
@@ -4071,7 +4010,8 @@ private void writePacket(int tdsMessageStatus) throws SQLServerException {
// If we just sent the first login request packet and SSL encryption was enabled
// for login only, then disable SSL now.
- if (TDS.PKT_LOGON70 == tdsMessageType && 1 == packetNum && TDS.ENCRYPT_OFF == con.getNegotiatedEncryptionLevel()) {
+ if (TDS.PKT_LOGON70 == tdsMessageType && 1 == packetNum
+ && TDS.ENCRYPT_OFF == con.getNegotiatedEncryptionLevel()) {
tdsChannel.disableSSL();
}
@@ -4082,16 +4022,21 @@ private void writePacket(int tdsMessageStatus) throws SQLServerException {
}
private void writePacketHeader(int tdsMessageStatus) {
- int tdsMessageLength = ((Buffer)stagingBuffer).position();
+ int tdsMessageLength = ((Buffer) stagingBuffer).position();
++packetNum;
// Write the TDS packet header back at the start of the staging buffer
stagingBuffer.put(TDS.PACKET_HEADER_MESSAGE_TYPE, tdsMessageType);
stagingBuffer.put(TDS.PACKET_HEADER_MESSAGE_STATUS, (byte) tdsMessageStatus);
- stagingBuffer.put(TDS.PACKET_HEADER_MESSAGE_LENGTH, (byte) ((tdsMessageLength >> 8) & 0xFF)); // Note: message length is 16 bits,
- stagingBuffer.put(TDS.PACKET_HEADER_MESSAGE_LENGTH + 1, (byte) ((tdsMessageLength >> 0) & 0xFF)); // written BIG ENDIAN
- stagingBuffer.put(TDS.PACKET_HEADER_SPID, (byte) ((tdsChannel.getSPID() >> 8) & 0xFF)); // Note: SPID is 16 bits,
- stagingBuffer.put(TDS.PACKET_HEADER_SPID + 1, (byte) ((tdsChannel.getSPID() >> 0) & 0xFF)); // written BIG ENDIAN
+ stagingBuffer.put(TDS.PACKET_HEADER_MESSAGE_LENGTH, (byte) ((tdsMessageLength >> 8) & 0xFF)); // Note: message
+ // length is 16
+ // bits,
+ stagingBuffer.put(TDS.PACKET_HEADER_MESSAGE_LENGTH + 1, (byte) ((tdsMessageLength >> 0) & 0xFF)); // written BIG
+ // ENDIAN
+ stagingBuffer.put(TDS.PACKET_HEADER_SPID, (byte) ((tdsChannel.getSPID() >> 8) & 0xFF)); // Note: SPID is 16
+ // bits,
+ stagingBuffer.put(TDS.PACKET_HEADER_SPID + 1, (byte) ((tdsChannel.getSPID() >> 0) & 0xFF)); // written BIG
+ // ENDIAN
stagingBuffer.put(TDS.PACKET_HEADER_SEQUENCE_NUM, (byte) (packetNum % 256));
stagingBuffer.put(TDS.PACKET_HEADER_WINDOW, (byte) 0); // Window (Reserved/Not used)
@@ -4099,10 +4044,15 @@ private void writePacketHeader(int tdsMessageStatus) {
if (tdsChannel.isLoggingPackets()) {
logBuffer.put(TDS.PACKET_HEADER_MESSAGE_TYPE, tdsMessageType);
logBuffer.put(TDS.PACKET_HEADER_MESSAGE_STATUS, (byte) tdsMessageStatus);
- logBuffer.put(TDS.PACKET_HEADER_MESSAGE_LENGTH, (byte) ((tdsMessageLength >> 8) & 0xFF)); // Note: message length is 16 bits,
- logBuffer.put(TDS.PACKET_HEADER_MESSAGE_LENGTH + 1, (byte) ((tdsMessageLength >> 0) & 0xFF)); // written BIG ENDIAN
- logBuffer.put(TDS.PACKET_HEADER_SPID, (byte) ((tdsChannel.getSPID() >> 8) & 0xFF)); // Note: SPID is 16 bits,
- logBuffer.put(TDS.PACKET_HEADER_SPID + 1, (byte) ((tdsChannel.getSPID() >> 0) & 0xFF)); // written BIG ENDIAN
+ logBuffer.put(TDS.PACKET_HEADER_MESSAGE_LENGTH, (byte) ((tdsMessageLength >> 8) & 0xFF)); // Note: message
+ // length is 16
+ // bits,
+ logBuffer.put(TDS.PACKET_HEADER_MESSAGE_LENGTH + 1, (byte) ((tdsMessageLength >> 0) & 0xFF)); // written BIG
+ // ENDIAN
+ logBuffer.put(TDS.PACKET_HEADER_SPID, (byte) ((tdsChannel.getSPID() >> 8) & 0xFF)); // Note: SPID is 16
+ // bits,
+ logBuffer.put(TDS.PACKET_HEADER_SPID + 1, (byte) ((tdsChannel.getSPID() >> 0) & 0xFF)); // written BIG
+ // ENDIAN
logBuffer.put(TDS.PACKET_HEADER_SEQUENCE_NUM, (byte) (packetNum % 256));
logBuffer.put(TDS.PACKET_HEADER_WINDOW, (byte) 0); // Window (Reserved/Not used);
}
@@ -4110,13 +4060,13 @@ private void writePacketHeader(int tdsMessageStatus) {
void flush(boolean atEOM) throws SQLServerException {
// First, flush any data left in the socket buffer.
- tdsChannel.write(socketBuffer.array(), ((Buffer)socketBuffer).position(), socketBuffer.remaining());
- ((Buffer)socketBuffer).position(((Buffer)socketBuffer).limit());
+ tdsChannel.write(socketBuffer.array(), ((Buffer) socketBuffer).position(), socketBuffer.remaining());
+ ((Buffer) socketBuffer).position(((Buffer) socketBuffer).limit());
// If there is data in the staging buffer that needs to be written
// to the socket, the socket buffer is now empty, so swap buffers
// and start writing data from the staging buffer.
- if (((Buffer)stagingBuffer).position() >= TDS_PACKET_HEADER_SIZE) {
+ if (((Buffer) stagingBuffer).position() >= TDS_PACKET_HEADER_SIZE) {
// Swap the packet buffers ...
ByteBuffer swapBuffer = stagingBuffer;
stagingBuffer = socketBuffer;
@@ -4128,8 +4078,8 @@ void flush(boolean atEOM) throws SQLServerException {
// We need to use flip() rather than rewind() here so that
// the socket buffer's limit is properly set for the last
// packet, which may be shorter than the other packets.
- ((Buffer)socketBuffer).flip();
- ((Buffer)stagingBuffer).clear();
+ ((Buffer) socketBuffer).flip();
+ ((Buffer) stagingBuffer).clear();
// If we are logging TDS packets then log the packet we're about
// to send over the wire now.
@@ -4143,8 +4093,8 @@ void flush(boolean atEOM) throws SQLServerException {
preparePacket();
// Finally, start sending data from the new socket buffer.
- tdsChannel.write(socketBuffer.array(), ((Buffer)socketBuffer).position(), socketBuffer.remaining());
- ((Buffer)socketBuffer).position( ((Buffer)socketBuffer).limit());
+ tdsChannel.write(socketBuffer.array(), ((Buffer) socketBuffer).position(), socketBuffer.remaining());
+ ((Buffer) socketBuffer).position(((Buffer) socketBuffer).limit());
}
}
@@ -4154,21 +4104,19 @@ void flush(boolean atEOM) throws SQLServerException {
* Write out elements common to all RPC values.
*
* @param sName
- * the optional parameter name
+ * the optional parameter name
* @param bOut
- * boolean true if the value that follows is being registered as an ouput parameter
+ * boolean true if the value that follows is being registered as an ouput parameter
* @param tdsType
- * TDS type of the value that follows
+ * TDS type of the value that follows
*/
- void writeRPCNameValType(String sName,
- boolean bOut,
- TDSType tdsType) throws SQLServerException {
+ void writeRPCNameValType(String sName, boolean bOut, TDSType tdsType) throws SQLServerException {
int nNameLen = 0;
if (null != sName)
nNameLen = sName.length() + 1; // The @ prefix is required for the param
- writeByte((byte) nNameLen); // param name len
+ writeByte((byte) nNameLen); // param name len
if (nNameLen > 0) {
writeChar('@');
writeString(sName);
@@ -4178,28 +4126,25 @@ void writeRPCNameValType(String sName,
writeByte((byte) (bOut ? 1 | TDS.AE_METADATA : 0 | TDS.AE_METADATA)); // status
else
writeByte((byte) (bOut ? 1 : 0)); // status
- writeByte(tdsType.byteValue()); // type
+ writeByte(tdsType.byteValue()); // type
}
/**
* Append a boolean value in RPC transmission format.
*
* @param sName
- * the optional parameter name
+ * the optional parameter name
* @param booleanValue
- * the data value
+ * the data value
* @param bOut
- * boolean true if the data value is being registered as an ouput parameter
+ * boolean true if the data value is being registered as an ouput parameter
*/
- void writeRPCBit(String sName,
- Boolean booleanValue,
- boolean bOut) throws SQLServerException {
+ void writeRPCBit(String sName, Boolean booleanValue, boolean bOut) throws SQLServerException {
writeRPCNameValType(sName, bOut, TDSType.BITN);
writeByte((byte) 1); // max length of datatype
if (null == booleanValue) {
writeByte((byte) 0); // len of data bytes
- }
- else {
+ } else {
writeByte((byte) 1); // length of datatype
writeByte((byte) (booleanValue ? 1 : 0));
}
@@ -4209,21 +4154,18 @@ void writeRPCBit(String sName,
* Append a short value in RPC transmission format.
*
* @param sName
- * the optional parameter name
+ * the optional parameter name
* @param shortValue
- * the data value
+ * the data value
* @param bOut
- * boolean true if the data value is being registered as an ouput parameter
+ * boolean true if the data value is being registered as an ouput parameter
*/
- void writeRPCByte(String sName,
- Byte byteValue,
- boolean bOut) throws SQLServerException {
+ void writeRPCByte(String sName, Byte byteValue, boolean bOut) throws SQLServerException {
writeRPCNameValType(sName, bOut, TDSType.INTN);
writeByte((byte) 1); // max length of datatype
if (null == byteValue) {
writeByte((byte) 0); // len of data bytes
- }
- else {
+ } else {
writeByte((byte) 1); // length of datatype
writeByte(byteValue);
}
@@ -4233,21 +4175,18 @@ void writeRPCByte(String sName,
* Append a short value in RPC transmission format.
*
* @param sName
- * the optional parameter name
+ * the optional parameter name
* @param shortValue
- * the data value
+ * the data value
* @param bOut
- * boolean true if the data value is being registered as an ouput parameter
+ * boolean true if the data value is being registered as an ouput parameter
*/
- void writeRPCShort(String sName,
- Short shortValue,
- boolean bOut) throws SQLServerException {
+ void writeRPCShort(String sName, Short shortValue, boolean bOut) throws SQLServerException {
writeRPCNameValType(sName, bOut, TDSType.INTN);
writeByte((byte) 2); // max length of datatype
if (null == shortValue) {
writeByte((byte) 0); // len of data bytes
- }
- else {
+ } else {
writeByte((byte) 2); // length of datatype
writeShort(shortValue);
}
@@ -4257,21 +4196,18 @@ void writeRPCShort(String sName,
* Append an int value in RPC transmission format.
*
* @param sName
- * the optional parameter name
+ * the optional parameter name
* @param intValue
- * the data value
+ * the data value
* @param bOut
- * boolean true if the data value is being registered as an ouput parameter
+ * boolean true if the data value is being registered as an ouput parameter
*/
- void writeRPCInt(String sName,
- Integer intValue,
- boolean bOut) throws SQLServerException {
+ void writeRPCInt(String sName, Integer intValue, boolean bOut) throws SQLServerException {
writeRPCNameValType(sName, bOut, TDSType.INTN);
writeByte((byte) 4); // max length of datatype
if (null == intValue) {
writeByte((byte) 0); // len of data bytes
- }
- else {
+ } else {
writeByte((byte) 4); // length of datatype
writeInt(intValue);
}
@@ -4281,21 +4217,18 @@ void writeRPCInt(String sName,
* Append a long value in RPC transmission format.
*
* @param sName
- * the optional parameter name
+ * the optional parameter name
* @param longValue
- * the data value
+ * the data value
* @param bOut
- * boolean true if the data value is being registered as an ouput parameter
+ * boolean true if the data value is being registered as an ouput parameter
*/
- void writeRPCLong(String sName,
- Long longValue,
- boolean bOut) throws SQLServerException {
+ void writeRPCLong(String sName, Long longValue, boolean bOut) throws SQLServerException {
writeRPCNameValType(sName, bOut, TDSType.INTN);
writeByte((byte) 8); // max length of datatype
if (null == longValue) {
writeByte((byte) 0); // len of data bytes
- }
- else {
+ } else {
writeByte((byte) 8); // length of datatype
writeLong(longValue);
}
@@ -4305,32 +4238,27 @@ void writeRPCLong(String sName,
* Append a real value in RPC transmission format.
*
* @param sName
- * the optional parameter name
+ * the optional parameter name
* @param floatValue
- * the data value
+ * the data value
* @param bOut
- * boolean true if the data value is being registered as an ouput parameter
+ * boolean true if the data value is being registered as an ouput parameter
*/
- void writeRPCReal(String sName,
- Float floatValue,
- boolean bOut) throws SQLServerException {
+ void writeRPCReal(String sName, Float floatValue, boolean bOut) throws SQLServerException {
writeRPCNameValType(sName, bOut, TDSType.FLOATN);
// Data and length
if (null == floatValue) {
writeByte((byte) 4); // max length
writeByte((byte) 0); // actual length (0 == null)
- }
- else {
+ } else {
writeByte((byte) 4); // max length
writeByte((byte) 4); // actual length
writeInt(Float.floatToRawIntBits(floatValue));
}
}
- void writeRPCSqlVariant(String sName,
- SqlVariant sqlVariantValue,
- boolean bOut) throws SQLServerException {
+ void writeRPCSqlVariant(String sName, SqlVariant sqlVariantValue, boolean bOut) throws SQLServerException {
writeRPCNameValType(sName, bOut, TDSType.SQL_VARIANT);
// Data and length
@@ -4344,15 +4272,13 @@ void writeRPCSqlVariant(String sName,
* Append a double value in RPC transmission format.
*
* @param sName
- * the optional parameter name
+ * the optional parameter name
* @param doubleValue
- * the data value
+ * the data value
* @param bOut
- * boolean true if the data value is being registered as an ouput parameter
+ * boolean true if the data value is being registered as an ouput parameter
*/
- void writeRPCDouble(String sName,
- Double doubleValue,
- boolean bOut) throws SQLServerException {
+ void writeRPCDouble(String sName, Double doubleValue, boolean bOut) throws SQLServerException {
writeRPCNameValType(sName, bOut, TDSType.FLOATN);
int l = 8;
@@ -4361,8 +4287,7 @@ void writeRPCDouble(String sName,
// Data and length
if (null == doubleValue) {
writeByte((byte) 0); // len of data bytes
- }
- else {
+ } else {
writeByte((byte) l); // len of data bytes
long bits = Double.doubleToLongBits(doubleValue);
long mask = 0xFF;
@@ -4379,18 +4304,15 @@ void writeRPCDouble(String sName,
* Append a big decimal in RPC transmission format.
*
* @param sName
- * the optional parameter name
+ * the optional parameter name
* @param bdValue
- * the data value
+ * the data value
* @param nScale
- * the desired scale
+ * the desired scale
* @param bOut
- * boolean true if the data value is being registered as an ouput parameter
+ * boolean true if the data value is being registered as an ouput parameter
*/
- void writeRPCBigDecimal(String sName,
- BigDecimal bdValue,
- int nScale,
- boolean bOut) throws SQLServerException {
+ void writeRPCBigDecimal(String sName, BigDecimal bdValue, int nScale, boolean bOut) throws SQLServerException {
writeRPCNameValType(sName, bOut, TDSType.DECIMALN);
writeByte((byte) 0x11); // maximum length
writeByte((byte) SQLServerConnection.maxDecimalPrecision); // precision
@@ -4403,15 +4325,13 @@ void writeRPCBigDecimal(String sName,
* Appends a standard v*max header for RPC parameter transmission.
*
* @param headerLength
- * the total length of the PLP data block.
+ * the total length of the PLP data block.
* @param isNull
- * true if the value is NULL.
+ * true if the value is NULL.
* @param collation
- * The SQL collation associated with the value that follows the v*max header. Null for non-textual types.
+ * The SQL collation associated with the value that follows the v*max header. Null for non-textual types.
*/
- void writeVMaxHeader(long headerLength,
- boolean isNull,
- SQLCollation collation) throws SQLServerException {
+ void writeVMaxHeader(long headerLength, boolean isNull, SQLCollation collation) throws SQLServerException {
// Send v*max length indicator 0xFFFF.
writeShort((short) 0xFFFF);
@@ -4423,15 +4343,13 @@ void writeVMaxHeader(long headerLength,
if (isNull) {
// Null header for v*max types is 0xFFFFFFFFFFFFFFFF.
writeLong(0xFFFFFFFFFFFFFFFFL);
- }
- else if (DataTypes.UNKNOWN_STREAM_LENGTH == headerLength) {
+ } else if (DataTypes.UNKNOWN_STREAM_LENGTH == headerLength) {
// Append v*max length.
// UNKNOWN_PLP_LEN is 0xFFFFFFFFFFFFFFFE
writeLong(0xFFFFFFFFFFFFFFFEL);
// NOTE: Don't send the first chunk length, this will be calculated by caller.
- }
- else {
+ } else {
// For v*max types with known length, length is
// We're sending same total length as chunk length (as we're sending 1 chunk).
writeLong(headerLength);
@@ -4449,17 +4367,15 @@ void writeRPCStringUnicode(String sValue) throws SQLServerException {
* Writes a string value as Unicode for RPC
*
* @param sName
- * the optional parameter name
+ * the optional parameter name
* @param sValue
- * the data value
+ * the data value
* @param bOut
- * boolean true if the data value is being registered as an ouput parameter
+ * boolean true if the data value is being registered as an ouput parameter
* @param collation
- * the collation of the data value
+ * the collation of the data value
*/
- void writeRPCStringUnicode(String sName,
- String sValue,
- boolean bOut,
+ void writeRPCStringUnicode(String sName, String sValue, boolean bOut,
SQLCollation collation) throws SQLServerException {
boolean bValueNull = (sValue == null);
int nValueLen = bValueNull ? 0 : (2 * sValue.length());
@@ -4476,8 +4392,8 @@ void writeRPCStringUnicode(String sName,
writeRPCNameValType(sName, bOut, TDSType.NVARCHAR);
// Handle Yukon v*max type header here.
- writeVMaxHeader(nValueLen, // Length
- bValueNull, // Is null?
+ writeVMaxHeader(nValueLen, // Length
+ bValueNull, // Is null?
collation);
// Send the data.
@@ -4490,15 +4406,13 @@ void writeRPCStringUnicode(String sName,
// Send the terminator PLP chunk.
writeInt(0);
}
- }
- else // non-PLP type
+ } else // non-PLP type
{
// Write maximum length of data
if (isShortValue) {
writeRPCNameValType(sName, bOut, TDSType.NVARCHAR);
writeShort((short) DataTypes.SHORT_VARTYPE_MAX_BYTES);
- }
- else {
+ } else {
writeRPCNameValType(sName, bOut, TDSType.NTEXT);
writeInt(DataTypes.IMAGE_TEXT_MAX_BYTES);
}
@@ -4508,8 +4422,7 @@ void writeRPCStringUnicode(String sName,
// Data and length
if (bValueNull) {
writeShort((short) -1); // actual len
- }
- else {
+ } else {
// Write actual length of data
if (isShortValue)
writeShort((short) nValueLen);
@@ -4518,7 +4431,7 @@ void writeRPCStringUnicode(String sName,
// If length is zero, we're done.
if (0 != nValueLen)
- writeString(sValue); // data
+ writeString(sValue); // data
}
}
}
@@ -4526,8 +4439,7 @@ void writeRPCStringUnicode(String sName,
void writeTVP(TVP value) throws SQLServerException {
if (!value.isNull()) {
writeByte((byte) 0); // status
- }
- else {
+ } else {
// Default TVP
writeByte((byte) TDS.TVP_STATUS_DEFAULT); // default TVP
}
@@ -4541,33 +4453,29 @@ void writeTVP(TVP value) throws SQLServerException {
if (null != value.getDbNameTVP()) {
writeByte((byte) value.getDbNameTVP().length());
writeString(value.getDbNameTVP());
- }
- else
- writeByte((byte) 0x00); // empty DB name
+ } else
+ writeByte((byte) 0x00); // empty DB name
// Schema where TVP type resides
if (null != value.getOwningSchemaNameTVP()) {
writeByte((byte) value.getOwningSchemaNameTVP().length());
writeString(value.getOwningSchemaNameTVP());
- }
- else
- writeByte((byte) 0x00); // empty Schema name
+ } else
+ writeByte((byte) 0x00); // empty Schema name
// TVP type name
if (null != value.getTVPName()) {
writeByte((byte) value.getTVPName().length());
writeString(value.getTVPName());
- }
- else
- writeByte((byte) 0x00); // empty TVP name
+ } else
+ writeByte((byte) 0x00); // empty TVP name
if (!value.isNull()) {
writeTVPColumnMetaData(value);
// optional OrderUnique metadata
writeTvpOrderUnique(value);
- }
- else {
+ } else {
writeShort((short) TDS.TVP_NULL_TOKEN);
}
@@ -4576,11 +4484,9 @@ void writeTVP(TVP value) throws SQLServerException {
try {
writeTVPRows(value);
- }
- catch (NumberFormatException e) {
+ } catch (NumberFormatException e) {
throw new SQLServerException(SQLServerException.getErrString("R_TVPInvalidColumnValue"), e);
- }
- catch (ClassCastException e) {
+ } catch (ClassCastException e) {
throw new SQLServerException(SQLServerException.getErrString("R_TVPInvalidColumnValue"), e);
}
}
@@ -4596,8 +4502,10 @@ void writeTVPRows(TVP value) throws SQLServerException {
if (!value.isNull()) {
- // If the preparedStatement and the ResultSet are created by the same connection, and TVP is set with ResultSet and Server Cursor
- // is used, the tdsWriter of the calling preparedStatement is overwritten by the SQLServerResultSet#next() method when fetching new rows.
+ // If the preparedStatement and the ResultSet are created by the same connection, and TVP is set with
+ // ResultSet and Server Cursor
+ // is used, the tdsWriter of the calling preparedStatement is overwritten by the SQLServerResultSet#next()
+ // method when fetching new rows.
// Therefore, we need to send TVP data row by row before fetching new row.
if (TVPType.ResultSet == value.tvpType) {
if ((null != value.sourceResultSet) && (value.sourceResultSet instanceof SQLServerResultSet)) {
@@ -4607,7 +4515,7 @@ void writeTVPRows(TVP value) throws SQLServerException {
if (con.equals(src_stmt.getConnection()) && 0 != resultSetServerCursorId) {
cachedTVPHeaders = ByteBuffer.allocate(stagingBuffer.capacity()).order(stagingBuffer.order());
- cachedTVPHeaders.put(stagingBuffer.array(), 0, ((Buffer)stagingBuffer).position());
+ cachedTVPHeaders.put(stagingBuffer.array(), 0, ((Buffer) stagingBuffer).position());
cachedCommand = this.command;
@@ -4633,9 +4541,9 @@ void writeTVPRows(TVP value) throws SQLServerException {
if (tdsWritterCached) {
command = cachedCommand;
- ((Buffer)stagingBuffer).clear();
- ((Buffer)logBuffer).clear();
- writeBytes(cachedTVPHeaders.array(), 0, ((Buffer)cachedTVPHeaders).position());
+ ((Buffer) stagingBuffer).clear();
+ ((Buffer) logBuffer).clear();
+ writeBytes(cachedTVPHeaders.array(), 0, ((Buffer) cachedTVPHeaders).position());
}
Object[] rowData = value.getRowData();
@@ -4658,7 +4566,8 @@ void writeTVPRows(TVP value) throws SQLServerException {
Object currentObject = null;
if (null != rowData) {
- // if rowData has value for the current column, retrieve it. If not, current column will stay null.
+ // if rowData has value for the current column, retrieve it. If not, current column will stay
+ // null.
if (rowData.length > currentColumn) {
currentObject = rowData[currentColumn];
if (null != currentObject) {
@@ -4684,7 +4593,8 @@ void writeTVPRows(TVP value) throws SQLServerException {
StreamError databaseError = new StreamError();
databaseError.setFromTDS(tdsReader);
- SQLServerException.makeFromDatabaseError(con, null, databaseError.getMessage(), databaseError, false);
+ SQLServerException.makeFromDatabaseError(con, null, databaseError.getMessage(), databaseError,
+ false);
}
command.setInterruptsEnabled(true);
@@ -4698,18 +4608,14 @@ void writeTVPRows(TVP value) throws SQLServerException {
command.setRequestComplete(cachedRequestComplete);
command.setInterruptsEnabled(cachedInterruptsEnabled);
command.setProcessedResponse(cachedProcessedResponse);
- }
- else {
+ } else {
// TVP_END_TOKEN
writeByte((byte) 0x00);
}
}
- private void writeInternalTVPRowValues(JDBCType jdbcType,
- String currentColumnStringValue,
- Object currentObject,
- Map.Entry columnPair,
- boolean isSqlVariant) throws SQLServerException {
+ private void writeInternalTVPRowValues(JDBCType jdbcType, String currentColumnStringValue, Object currentObject,
+ Map.Entry columnPair, boolean isSqlVariant) throws SQLServerException {
boolean isShortValue, isNull;
int dataLength;
switch (jdbcType) {
@@ -4719,8 +4625,7 @@ private void writeInternalTVPRowValues(JDBCType jdbcType,
else {
if (isSqlVariant) {
writeTVPSqlVariantHeader(10, TDSType.INT8.byteValue(), (byte) 0);
- }
- else {
+ } else {
writeByte((byte) 8);
}
writeLong(Long.valueOf(currentColumnStringValue).longValue());
@@ -4759,8 +4664,7 @@ private void writeInternalTVPRowValues(JDBCType jdbcType,
if (isSqlVariant) {
writeTVPSqlVariantHeader(6, TDSType.INT4.byteValue(), (byte) 0);
writeInt(Integer.valueOf(currentColumnStringValue));
- }
- else {
+ } else {
writeByte((byte) 2); // length of datatype
writeShort(Short.valueOf(currentColumnStringValue).shortValue());
}
@@ -4776,16 +4680,15 @@ private void writeInternalTVPRowValues(JDBCType jdbcType,
writeTVPSqlVariantHeader(21, TDSType.DECIMALN.byteValue(), (byte) 2);
writeByte((byte) 38); // scale (byte)variantType.getScale()
writeByte((byte) 4); // scale (byte)variantType.getScale()
- }
- else {
+ } else {
writeByte((byte) TDSWriter.BIGDECIMAL_MAX_LENGTH); // maximum length
}
BigDecimal bdValue = new BigDecimal(currentColumnStringValue);
/*
- * setScale of all BigDecimal value based on metadata as scale is not sent seperately for individual value. Use the rounding used
- * in Server. Say, for BigDecimal("0.1"), if scale in metdadata is 0, then ArithmeticException would be thrown if RoundingMode is
- * not set
+ * setScale of all BigDecimal value based on metadata as scale is not sent seperately for individual
+ * value. Use the rounding used in Server. Say, for BigDecimal("0.1"), if scale in metdadata is 0,
+ * then ArithmeticException would be thrown if RoundingMode is not set
*/
bdValue = bdValue.setScale(columnPair.getValue().scale, RoundingMode.HALF_UP);
@@ -4829,8 +4732,7 @@ private void writeInternalTVPRowValues(JDBCType jdbcType,
if (isSqlVariant) {
writeTVPSqlVariantHeader(6, TDSType.FLOAT4.byteValue(), (byte) 0);
writeInt(Float.floatToRawIntBits(Float.valueOf(currentColumnStringValue).floatValue()));
- }
- else {
+ } else {
writeByte((byte) 4);
writeInt(Float.floatToRawIntBits(Float.valueOf(currentColumnStringValue).floatValue()));
}
@@ -4860,15 +4762,18 @@ private void writeInternalTVPRowValues(JDBCType jdbcType,
if (isNull) {
// Null header for v*max types is 0xFFFFFFFFFFFFFFFF.
writeLong(0xFFFFFFFFFFFFFFFFL);
- }
- else if (isSqlVariant) {
- // for now we send as bigger type, but is sendStringParameterAsUnicoe is set to false we can't send nvarchar
+ } else if (isSqlVariant) {
+ // for now we send as bigger type, but is sendStringParameterAsUnicoe is set to false we can't
+ // send nvarchar
// since we are writing as nvarchar we need to write as tdstype.bigvarchar value because if we
- // want to supprot varchar(8000) it becomes as nvarchar, 8000*2 therefore we should send as longvarchar,
- // but we cannot send more than 8000 cause sql_variant datatype in sql server does not support it.
+ // want to supprot varchar(8000) it becomes as nvarchar, 8000*2 therefore we should send as
+ // longvarchar,
+ // but we cannot send more than 8000 cause sql_variant datatype in sql server does not support
+ // it.
// then throw exception if user is sending more than that
if (dataLength > 2 * DataTypes.SHORT_VARTYPE_MAX_BYTES) {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidStringValue"));
+ MessageFormat form = new MessageFormat(
+ SQLServerException.getErrString("R_invalidStringValue"));
throw new SQLServerException(null, form.format(new Object[] {}), null, 0, false);
}
int length = currentColumnStringValue.length();
@@ -4897,13 +4802,13 @@ else if (DataTypes.UNKNOWN_STREAM_LENGTH == dataLength)
// Send the terminator PLP chunk.
writeInt(0);
}
- }
- else {
+ } else {
if (isNull)
writeShort((short) -1); // actual len
else {
if (isSqlVariant) {
- // for now we send as bigger type, but is sendStringParameterAsUnicoe is set to false we can't send nvarchar
+ // for now we send as bigger type, but is sendStringParameterAsUnicoe is set to false we
+ // can't send nvarchar
// check for this
int length = currentColumnStringValue.length() * 2;
writeTVPSqlVariantHeader(9 + length, TDSType.NVARCHAR.byteValue(), (byte) 7);
@@ -4918,8 +4823,7 @@ else if (DataTypes.UNKNOWN_STREAM_LENGTH == dataLength)
writeBytes(typevarlen);
writeString(currentColumnStringValue);
break;
- }
- else {
+ } else {
writeShort((short) dataLength);
writeString(currentColumnStringValue);
}
@@ -4960,8 +4864,7 @@ else if (DataTypes.UNKNOWN_STREAM_LENGTH == dataLength)
// Send the terminator PLP chunk.
writeInt(0);
}
- }
- else {
+ } else {
if (isNull)
writeShort((short) -1); // actual len
else {
@@ -4991,20 +4894,18 @@ else if (DataTypes.UNKNOWN_STREAM_LENGTH == dataLength)
/**
* writes Header for sql_variant for TVP
+ *
* @param length
* @param tdsType
* @param probBytes
* @throws SQLServerException
*/
- private void writeTVPSqlVariantHeader(int length,
- byte tdsType,
- byte probBytes) throws SQLServerException {
+ private void writeTVPSqlVariantHeader(int length, byte tdsType, byte probBytes) throws SQLServerException {
writeInt(length);
writeByte(tdsType);
writeByte(probBytes);
}
-
void writeTVPColumnMetaData(TVP value) throws SQLServerException {
boolean isShortValue;
@@ -5023,9 +4924,9 @@ void writeTVPColumnMetaData(TVP value) throws SQLServerException {
// The value will be 0x0000 with the exceptions of TIMESTAMP (0x0050) and alias types (greater than 0x00FF).
writeInt(0);
/*
- * Flags = fNullable ; Column is nullable - %x01 fCaseSen -- Ignored ; usUpdateable -- Ignored ; fIdentity ; Column is identity column -
- * %x10 fComputed ; Column is computed - %x20 usReservedODBC -- Ignored ; fFixedLenCLRType-- Ignored ; fDefault ; Column is default value
- * - %x200 usReserved -- Ignored ;
+ * Flags = fNullable ; Column is nullable - %x01 fCaseSen -- Ignored ; usUpdateable -- Ignored ; fIdentity ;
+ * Column is identity column - %x10 fComputed ; Column is computed - %x20 usReservedODBC -- Ignored ;
+ * fFixedLenCLRType-- Ignored ; fDefault ; Column is default value - %x200 usReserved -- Ignored ;
*/
short flags = TDS.FLAG_NULLABLE;
@@ -5091,12 +4992,12 @@ void writeTVPColumnMetaData(TVP value) throws SQLServerException {
writeByte(TDSType.NVARCHAR.byteValue());
isShortValue = (2L * pair.getValue().precision) <= DataTypes.SHORT_VARTYPE_MAX_BYTES;
// Use PLP encoding on Yukon and later with long values
- if (!isShortValue) // PLP
+ if (!isShortValue) // PLP
{
// Handle Yukon v*max type header here.
writeShort((short) 0xFFFF);
con.getDatabaseCollation().writeCollation(this);
- } else // non PLP
+ } else // non PLP
{
writeShort((short) DataTypes.SHORT_VARTYPE_MAX_BYTES);
con.getDatabaseCollation().writeCollation(this);
@@ -5110,10 +5011,10 @@ void writeTVPColumnMetaData(TVP value) throws SQLServerException {
writeByte(TDSType.BIGVARBINARY.byteValue());
isShortValue = pair.getValue().precision <= DataTypes.SHORT_VARTYPE_MAX_BYTES;
// Use PLP encoding on Yukon and later with long values
- if (!isShortValue) // PLP
+ if (!isShortValue) // PLP
// Handle Yukon v*max type header here.
writeShort((short) 0xFFFF);
- else // non PLP
+ else // non PLP
writeShort((short) DataTypes.SHORT_VARTYPE_MAX_BYTES);
break;
case SQL_VARIANT:
@@ -5174,8 +5075,7 @@ private class TdsOrderUnique {
int columnOrdinal;
byte flags;
- TdsOrderUnique(int ordinal,
- byte flags) {
+ TdsOrderUnique(int ordinal, byte flags) {
this.columnOrdinal = ordinal;
this.flags = flags;
}
@@ -5199,26 +5099,21 @@ void writeEncryptedRPCByteArray(byte bValue[]) throws SQLServerException {
// Handle Shiloh types here.
if (isShortValue) {
writeShort((short) DataTypes.SHORT_VARTYPE_MAX_BYTES);
- }
- else if (isPLP) {
+ } else if (isPLP) {
writeShort((short) DataTypes.SQL_USHORTVARMAXLEN);
- }
- else {
+ } else {
writeInt(DataTypes.IMAGE_TEXT_MAX_BYTES);
}
// Data and length
if (bValueNull) {
writeShort((short) -1); // actual len
- }
- else {
+ } else {
if (isShortValue) {
writeShort((short) nValueLen); // actual len
- }
- else if (isPLP) {
+ } else if (isPLP) {
writeLong(nValueLen); // actual length
- }
- else {
+ } else {
writeInt((int) nValueLen); // actual len
}
@@ -5252,10 +5147,7 @@ void writeCryptoMetaData() throws SQLServerException {
writeByte(cryptoMeta.normalizationRuleVersion);
}
- void writeRPCByteArray(String sName,
- byte bValue[],
- boolean bOut,
- JDBCType jdbcType,
+ void writeRPCByteArray(String sName, byte bValue[], boolean bOut, JDBCType jdbcType,
SQLCollation collation) throws SQLServerException {
boolean bValueNull = (bValue == null);
int nValueLen = bValueNull ? 0 : bValue.length;
@@ -5270,8 +5162,7 @@ void writeRPCByteArray(String sName,
// send encrypted data as BIGVARBINARY
tdsType = (isShortValue || usePLP) ? TDSType.BIGVARBINARY : TDSType.IMAGE;
collation = null;
- }
- else
+ } else
switch (jdbcType) {
case BINARY:
case VARBINARY:
@@ -5317,14 +5208,12 @@ void writeRPCByteArray(String sName,
// Send the terminator PLP chunk.
writeInt(0);
}
- }
- else // non-PLP type
+ } else // non-PLP type
{
// Handle Shiloh types here.
if (isShortValue) {
writeShort((short) DataTypes.SHORT_VARTYPE_MAX_BYTES);
- }
- else {
+ } else {
writeInt(DataTypes.IMAGE_TEXT_MAX_BYTES);
}
@@ -5334,8 +5223,7 @@ void writeRPCByteArray(String sName,
// Data and length
if (bValueNull) {
writeShort((short) -1); // actual len
- }
- else {
+ } else {
if (isShortValue)
writeShort((short) nValueLen); // actual len
else
@@ -5352,21 +5240,21 @@ void writeRPCByteArray(String sName,
* Append a timestamp in RPC transmission format as a SQL Server DATETIME data type
*
* @param sName
- * the optional parameter name
+ * the optional parameter name
* @param cal
- * Pure Gregorian calendar containing the timestamp, including its associated time zone
+ * Pure Gregorian calendar containing the timestamp, including its associated time zone
* @param subSecondNanos
- * the sub-second nanoseconds (0 - 999,999,999)
+ * the sub-second nanoseconds (0 - 999,999,999)
* @param bOut
- * boolean true if the data value is being registered as an ouput parameter
+ * boolean true if the data value is being registered as an ouput parameter
*
*/
- void writeRPCDateTime(String sName,
- GregorianCalendar cal,
- int subSecondNanos,
+ void writeRPCDateTime(String sName, GregorianCalendar cal, int subSecondNanos,
boolean bOut) throws SQLServerException {
- assert (subSecondNanos >= 0) && (subSecondNanos < Nanos.PER_SECOND) : "Invalid subNanoSeconds value: " + subSecondNanos;
- assert (cal != null) || (subSecondNanos == 0) : "Invalid subNanoSeconds value when calendar is null: " + subSecondNanos;
+ assert (subSecondNanos >= 0) && (subSecondNanos < Nanos.PER_SECOND) : "Invalid subNanoSeconds value: "
+ + subSecondNanos;
+ assert (cal != null) || (subSecondNanos == 0) : "Invalid subNanoSeconds value when calendar is null: "
+ + subSecondNanos;
writeRPCNameValType(sName, bOut, TDSType.DATETIMEN);
writeByte((byte) 8); // max length of datatype
@@ -5395,10 +5283,13 @@ void writeRPCDateTime(String sName,
// First, figure out how many days there have been since the SQL Base Date.
// These are based on SQL Server algorithms
- int daysSinceSQLBaseDate = DDC.daysSinceBaseDate(cal.get(Calendar.YEAR), cal.get(Calendar.DAY_OF_YEAR), TDS.BASE_YEAR_1900);
+ int daysSinceSQLBaseDate = DDC.daysSinceBaseDate(cal.get(Calendar.YEAR), cal.get(Calendar.DAY_OF_YEAR),
+ TDS.BASE_YEAR_1900);
// Next, figure out the number of milliseconds since midnight of the current day.
- int millisSinceMidnight = (subSecondNanos + Nanos.PER_MILLISECOND / 2) / Nanos.PER_MILLISECOND + // Millis into the current second
+ int millisSinceMidnight = (subSecondNanos + Nanos.PER_MILLISECOND / 2) / Nanos.PER_MILLISECOND + // Millis into
+ // the current
+ // second
1000 * cal.get(Calendar.SECOND) + // Seconds into the current minute
60 * 1000 * cal.get(Calendar.MINUTE) + // Minutes into the current hour
60 * 60 * 1000 * cal.get(Calendar.HOUR_OF_DAY); // Hours into the current day
@@ -5420,7 +5311,8 @@ void writeRPCDateTime(String sName,
|| daysSinceSQLBaseDate >= DDC.daysSinceBaseDate(10000, 1, TDS.BASE_YEAR_1900)) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_valueOutOfRange"));
Object[] msgArgs = {SSType.DATETIME};
- throw new SQLServerException(form.format(msgArgs), SQLState.DATA_EXCEPTION_DATETIME_FIELD_OVERFLOW, DriverError.NOT_SET, null);
+ throw new SQLServerException(form.format(msgArgs), SQLState.DATA_EXCEPTION_DATETIME_FIELD_OVERFLOW,
+ DriverError.NOT_SET, null);
}
// And put it all on the wire...
@@ -5432,10 +5324,7 @@ void writeRPCDateTime(String sName,
writeInt((3 * millisSinceMidnight + 5) / 10);
}
- void writeRPCTime(String sName,
- GregorianCalendar localCalendar,
- int subSecondNanos,
- int scale,
+ void writeRPCTime(String sName, GregorianCalendar localCalendar, int subSecondNanos, int scale,
boolean bOut) throws SQLServerException {
writeRPCNameValType(sName, bOut, TDSType.TIMEN);
writeByte((byte) scale);
@@ -5449,9 +5338,7 @@ void writeRPCTime(String sName,
writeScaledTemporal(localCalendar, subSecondNanos, scale, SSType.TIME);
}
- void writeRPCDate(String sName,
- GregorianCalendar localCalendar,
- boolean bOut) throws SQLServerException {
+ void writeRPCDate(String sName, GregorianCalendar localCalendar, boolean bOut) throws SQLServerException {
writeRPCNameValType(sName, bOut, TDSType.DATEN);
if (null == localCalendar) {
writeByte((byte) 0);
@@ -5464,10 +5351,7 @@ void writeRPCDate(String sName,
SSType.DATE);
}
- void writeEncryptedRPCTime(String sName,
- GregorianCalendar localCalendar,
- int subSecondNanos,
- int scale,
+ void writeEncryptedRPCTime(String sName, GregorianCalendar localCalendar, int subSecondNanos, int scale,
boolean bOut) throws SQLServerException {
if (con.getSendTimeAsDatetime()) {
throw new SQLServerException(SQLServerException.getErrString("R_sendTimeAsDateTimeForAE"), null);
@@ -5477,22 +5361,22 @@ void writeEncryptedRPCTime(String sName,
if (null == localCalendar)
writeEncryptedRPCByteArray(null);
else
- writeEncryptedRPCByteArray(writeEncryptedScaledTemporal(localCalendar, subSecondNanos, scale, SSType.TIME, (short) 0));
+ writeEncryptedRPCByteArray(
+ writeEncryptedScaledTemporal(localCalendar, subSecondNanos, scale, SSType.TIME, (short) 0));
writeByte(TDSType.TIMEN.byteValue());
writeByte((byte) scale);
writeCryptoMetaData();
}
- void writeEncryptedRPCDate(String sName,
- GregorianCalendar localCalendar,
- boolean bOut) throws SQLServerException {
+ void writeEncryptedRPCDate(String sName, GregorianCalendar localCalendar, boolean bOut) throws SQLServerException {
writeRPCNameValType(sName, bOut, TDSType.BIGVARBINARY);
if (null == localCalendar)
writeEncryptedRPCByteArray(null);
else
- writeEncryptedRPCByteArray(writeEncryptedScaledTemporal(localCalendar, 0, // subsecond nanos (none for a date value)
+ writeEncryptedRPCByteArray(writeEncryptedScaledTemporal(localCalendar, 0, // subsecond nanos (none for a
+ // date value)
0, // scale (dates are not scaled)
SSType.DATE, (short) 0));
@@ -5500,13 +5384,12 @@ void writeEncryptedRPCDate(String sName,
writeCryptoMetaData();
}
- void writeEncryptedRPCDateTime(String sName,
- GregorianCalendar cal,
- int subSecondNanos,
- boolean bOut,
+ void writeEncryptedRPCDateTime(String sName, GregorianCalendar cal, int subSecondNanos, boolean bOut,
JDBCType jdbcType) throws SQLServerException {
- assert (subSecondNanos >= 0) && (subSecondNanos < Nanos.PER_SECOND) : "Invalid subNanoSeconds value: " + subSecondNanos;
- assert (cal != null) || (subSecondNanos == 0) : "Invalid subNanoSeconds value when calendar is null: " + subSecondNanos;
+ assert (subSecondNanos >= 0) && (subSecondNanos < Nanos.PER_SECOND) : "Invalid subNanoSeconds value: "
+ + subSecondNanos;
+ assert (cal != null) || (subSecondNanos == 0) : "Invalid subNanoSeconds value when calendar is null: "
+ + subSecondNanos;
writeRPCNameValType(sName, bOut, TDSType.BIGVARBINARY);
@@ -5518,8 +5401,7 @@ void writeEncryptedRPCDateTime(String sName,
if (JDBCType.SMALLDATETIME == jdbcType) {
writeByte(TDSType.DATETIMEN.byteValue());
writeByte((byte) 4);
- }
- else {
+ } else {
writeByte(TDSType.DATETIMEN.byteValue());
writeByte((byte) 8);
}
@@ -5527,13 +5409,15 @@ void writeEncryptedRPCDateTime(String sName,
}
// getEncryptedDateTimeAsBytes is called if jdbcType/ssType is SMALLDATETIME or DATETIME
- byte[] getEncryptedDateTimeAsBytes(GregorianCalendar cal,
- int subSecondNanos,
+ byte[] getEncryptedDateTimeAsBytes(GregorianCalendar cal, int subSecondNanos,
JDBCType jdbcType) throws SQLServerException {
- int daysSinceSQLBaseDate = DDC.daysSinceBaseDate(cal.get(Calendar.YEAR), cal.get(Calendar.DAY_OF_YEAR), TDS.BASE_YEAR_1900);
+ int daysSinceSQLBaseDate = DDC.daysSinceBaseDate(cal.get(Calendar.YEAR), cal.get(Calendar.DAY_OF_YEAR),
+ TDS.BASE_YEAR_1900);
// Next, figure out the number of milliseconds since midnight of the current day.
- int millisSinceMidnight = (subSecondNanos + Nanos.PER_MILLISECOND / 2) / Nanos.PER_MILLISECOND + // Millis into the current second
+ int millisSinceMidnight = (subSecondNanos + Nanos.PER_MILLISECOND / 2) / Nanos.PER_MILLISECOND + // Millis into
+ // the current
+ // second
1000 * cal.get(Calendar.SECOND) + // Seconds into the current minute
60 * 1000 * cal.get(Calendar.MINUTE) + // Minutes into the current hour
60 * 60 * 1000 * cal.get(Calendar.HOUR_OF_DAY); // Hours into the current day
@@ -5551,13 +5435,15 @@ byte[] getEncryptedDateTimeAsBytes(GregorianCalendar cal,
int minutesSinceMidnight = (secondsSinceMidnight / 60);
// Values that are 29.998 seconds or less are rounded down to the nearest minute
- minutesSinceMidnight = ((secondsSinceMidnight % 60) > 29.998) ? minutesSinceMidnight + 1 : minutesSinceMidnight;
+ minutesSinceMidnight = ((secondsSinceMidnight % 60) > 29.998) ? minutesSinceMidnight + 1
+ : minutesSinceMidnight;
// minutesSinceMidnight for (23:59:30)
int maxMinutesSinceMidnight_SmallDateTime = 1440;
// Verification for smalldatetime to be within valid range of (1900.01.01) to (2079.06.06)
// smalldatetime for unencrypted does not allow insertion of 2079.06.06 23:59:59 and it is rounded up
- // to 2079.06.07 00:00:00, therefore, we are checking minutesSinceMidnight for that condition. If it's not within valid range, then
+ // to 2079.06.07 00:00:00, therefore, we are checking minutesSinceMidnight for that condition. If it's not
+ // within valid range, then
// throw an exception now so that statement execution is safely canceled.
// 157 is the calculated day of year from 06-06 , 1440 is minutesince midnight for (23:59:30)
if ((daysSinceSQLBaseDate < DDC.daysSinceBaseDate(1900, 1, TDS.BASE_YEAR_1900)
@@ -5566,7 +5452,8 @@ byte[] getEncryptedDateTimeAsBytes(GregorianCalendar cal,
&& minutesSinceMidnight >= maxMinutesSinceMidnight_SmallDateTime)) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_valueOutOfRange"));
Object[] msgArgs = {SSType.SMALLDATETIME};
- throw new SQLServerException(form.format(msgArgs), SQLState.DATA_EXCEPTION_DATETIME_FIELD_OVERFLOW, DriverError.NOT_SET, null);
+ throw new SQLServerException(form.format(msgArgs), SQLState.DATA_EXCEPTION_DATETIME_FIELD_OVERFLOW,
+ DriverError.NOT_SET, null);
}
ByteBuffer days = ByteBuffer.allocate(2).order(ByteOrder.LITTLE_ENDIAN);
@@ -5578,8 +5465,7 @@ byte[] getEncryptedDateTimeAsBytes(GregorianCalendar cal,
System.arraycopy(days.array(), 0, value, 0, 2);
System.arraycopy(seconds.array(), 0, value, 2, 2);
return SQLServerSecurityUtility.encryptWithKey(value, cryptoMeta, con);
- }
- else if (JDBCType.DATETIME == jdbcType) {
+ } else if (JDBCType.DATETIME == jdbcType) {
// Last-ditch verification that the value is in the valid range for the
// DATETIMEN TDS data type (1/1/1753 to 12/31/9999). If it's not, then
// throw an exception now so that statement execution is safely canceled.
@@ -5591,7 +5477,8 @@ else if (JDBCType.DATETIME == jdbcType) {
|| daysSinceSQLBaseDate >= DDC.daysSinceBaseDate(10000, 1, TDS.BASE_YEAR_1900)) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_valueOutOfRange"));
Object[] msgArgs = {SSType.DATETIME};
- throw new SQLServerException(form.format(msgArgs), SQLState.DATA_EXCEPTION_DATETIME_FIELD_OVERFLOW, DriverError.NOT_SET, null);
+ throw new SQLServerException(form.format(msgArgs), SQLState.DATA_EXCEPTION_DATETIME_FIELD_OVERFLOW,
+ DriverError.NOT_SET, null);
}
// Number of days since the SQL Server Base Date (January 1, 1900)
@@ -5610,37 +5497,31 @@ else if (JDBCType.DATETIME == jdbcType) {
return null;
}
- void writeEncryptedRPCDateTime2(String sName,
- GregorianCalendar localCalendar,
- int subSecondNanos,
- int scale,
+ void writeEncryptedRPCDateTime2(String sName, GregorianCalendar localCalendar, int subSecondNanos, int scale,
boolean bOut) throws SQLServerException {
writeRPCNameValType(sName, bOut, TDSType.BIGVARBINARY);
if (null == localCalendar)
writeEncryptedRPCByteArray(null);
else
- writeEncryptedRPCByteArray(writeEncryptedScaledTemporal(localCalendar, subSecondNanos, scale, SSType.DATETIME2, (short) 0));
+ writeEncryptedRPCByteArray(
+ writeEncryptedScaledTemporal(localCalendar, subSecondNanos, scale, SSType.DATETIME2, (short) 0));
writeByte(TDSType.DATETIME2N.byteValue());
writeByte((byte) (scale));
writeCryptoMetaData();
}
- void writeEncryptedRPCDateTimeOffset(String sName,
- GregorianCalendar utcCalendar,
- int minutesOffset,
- int subSecondNanos,
- int scale,
- boolean bOut) throws SQLServerException {
+ void writeEncryptedRPCDateTimeOffset(String sName, GregorianCalendar utcCalendar, int minutesOffset,
+ int subSecondNanos, int scale, boolean bOut) throws SQLServerException {
writeRPCNameValType(sName, bOut, TDSType.BIGVARBINARY);
if (null == utcCalendar)
writeEncryptedRPCByteArray(null);
else {
assert 0 == utcCalendar.get(Calendar.ZONE_OFFSET);
- writeEncryptedRPCByteArray(
- writeEncryptedScaledTemporal(utcCalendar, subSecondNanos, scale, SSType.DATETIMEOFFSET, (short) minutesOffset));
+ writeEncryptedRPCByteArray(writeEncryptedScaledTemporal(utcCalendar, subSecondNanos, scale,
+ SSType.DATETIMEOFFSET, (short) minutesOffset));
}
writeByte(TDSType.DATETIMEOFFSETN.byteValue());
@@ -5649,10 +5530,7 @@ void writeEncryptedRPCDateTimeOffset(String sName,
}
- void writeRPCDateTime2(String sName,
- GregorianCalendar localCalendar,
- int subSecondNanos,
- int scale,
+ void writeRPCDateTime2(String sName, GregorianCalendar localCalendar, int subSecondNanos, int scale,
boolean bOut) throws SQLServerException {
writeRPCNameValType(sName, bOut, TDSType.DATETIME2N);
writeByte((byte) scale);
@@ -5666,12 +5544,8 @@ void writeRPCDateTime2(String sName,
writeScaledTemporal(localCalendar, subSecondNanos, scale, SSType.DATETIME2);
}
- void writeRPCDateTimeOffset(String sName,
- GregorianCalendar utcCalendar,
- int minutesOffset,
- int subSecondNanos,
- int scale,
- boolean bOut) throws SQLServerException {
+ void writeRPCDateTimeOffset(String sName, GregorianCalendar utcCalendar, int minutesOffset, int subSecondNanos,
+ int scale, boolean bOut) throws SQLServerException {
writeRPCNameValType(sName, bOut, TDSType.DATETIMEOFFSETN);
writeByte((byte) scale);
@@ -5688,43 +5562,42 @@ void writeRPCDateTimeOffset(String sName,
writeShort((short) minutesOffset);
}
-
/**
- * Returns subSecondNanos rounded to the maximum precision supported. The maximum fractional scale is MAX_FRACTIONAL_SECONDS_SCALE(7). Eg1: if you
- * pass 456,790,123 the function would return 456,790,100 Eg2: if you pass 456,790,150 the function would return 456,790,200 Eg3: if you pass
- * 999,999,951 the function would return 1,000,000,000 This is done to ensure that we have consistent rounding behaviour in setters and getters.
- * Bug #507919
+ * Returns subSecondNanos rounded to the maximum precision supported. The maximum fractional scale is
+ * MAX_FRACTIONAL_SECONDS_SCALE(7). Eg1: if you pass 456,790,123 the function would return 456,790,100 Eg2: if you
+ * pass 456,790,150 the function would return 456,790,200 Eg3: if you pass 999,999,951 the function would return
+ * 1,000,000,000 This is done to ensure that we have consistent rounding behaviour in setters and getters. Bug
+ * #507919
*/
private int getRoundedSubSecondNanos(int subSecondNanos) {
- int roundedNanos = ((subSecondNanos + (Nanos.PER_MAX_SCALE_INTERVAL / 2)) / Nanos.PER_MAX_SCALE_INTERVAL) * Nanos.PER_MAX_SCALE_INTERVAL;
+ int roundedNanos = ((subSecondNanos + (Nanos.PER_MAX_SCALE_INTERVAL / 2)) / Nanos.PER_MAX_SCALE_INTERVAL)
+ * Nanos.PER_MAX_SCALE_INTERVAL;
return roundedNanos;
}
/**
- * Writes to the TDS channel a temporal value as an instance instance of one of the scaled temporal SQL types: DATE, TIME, DATETIME2, or
- * DATETIMEOFFSET.
+ * Writes to the TDS channel a temporal value as an instance instance of one of the scaled temporal SQL types: DATE,
+ * TIME, DATETIME2, or DATETIMEOFFSET.
*
* @param cal
- * Calendar representing the value to write, except for any sub-second nanoseconds
+ * Calendar representing the value to write, except for any sub-second nanoseconds
* @param subSecondNanos
- * the sub-second nanoseconds (0 - 999,999,999)
+ * the sub-second nanoseconds (0 - 999,999,999)
* @param scale
- * the scale (in digits: 0 - 7) to use for the sub-second nanos component
+ * the scale (in digits: 0 - 7) to use for the sub-second nanos component
* @param ssType
- * the SQL Server data type (DATE, TIME, DATETIME2, or DATETIMEOFFSET)
+ * the SQL Server data type (DATE, TIME, DATETIME2, or DATETIMEOFFSET)
*
* @throws SQLServerException
- * if an I/O error occurs or if the value is not in the valid range
+ * if an I/O error occurs or if the value is not in the valid range
*/
- private void writeScaledTemporal(GregorianCalendar cal,
- int subSecondNanos,
- int scale,
+ private void writeScaledTemporal(GregorianCalendar cal, int subSecondNanos, int scale,
SSType ssType) throws SQLServerException {
assert con.isKatmaiOrLater();
- assert SSType.DATE == ssType || SSType.TIME == ssType || SSType.DATETIME2 == ssType || SSType.DATETIMEOFFSET == ssType : "Unexpected SSType: "
- + ssType;
+ assert SSType.DATE == ssType || SSType.TIME == ssType || SSType.DATETIME2 == ssType
+ || SSType.DATETIMEOFFSET == ssType : "Unexpected SSType: " + ssType;
// First, for types with a time component, write the scaled nanos since midnight
if (SSType.TIME == ssType || SSType.DATETIME2 == ssType || SSType.DATETIMEOFFSET == ssType) {
@@ -5733,7 +5606,8 @@ private void writeScaledTemporal(GregorianCalendar cal,
assert scale >= 0;
assert scale <= TDS.MAX_FRACTIONAL_SECONDS_SCALE;
- int secondsSinceMidnight = cal.get(Calendar.SECOND) + 60 * cal.get(Calendar.MINUTE) + 60 * 60 * cal.get(Calendar.HOUR_OF_DAY);
+ int secondsSinceMidnight = cal.get(Calendar.SECOND) + 60 * cal.get(Calendar.MINUTE)
+ + 60 * 60 * cal.get(Calendar.HOUR_OF_DAY);
// Scale nanos since midnight to the desired scale, rounding the value as necessary
long divisor = Nanos.PER_MAX_SCALE_INTERVAL * (long) Math.pow(10, TDS.MAX_FRACTIONAL_SECONDS_SCALE - scale);
@@ -5742,7 +5616,8 @@ private void writeScaledTemporal(GregorianCalendar cal,
// indicated by the scale variable. So, for example, scaledNanos = 3 means 300 nanoseconds
// at scale TDS.MAX_FRACTIONAL_SECONDS_SCALE, but 3000 nanoseconds at
// TDS.MAX_FRACTIONAL_SECONDS_SCALE - 1
- long scaledNanos = ((long) Nanos.PER_SECOND * secondsSinceMidnight + getRoundedSubSecondNanos(subSecondNanos) + divisor / 2) / divisor;
+ long scaledNanos = ((long) Nanos.PER_SECOND * secondsSinceMidnight
+ + getRoundedSubSecondNanos(subSecondNanos) + divisor / 2) / divisor;
// SQL Server rounding behavior indicates that it always rounds up unless
// we are at the max value of the type(NOT every day), in which case it truncates.
@@ -5756,7 +5631,8 @@ private void writeScaledTemporal(GregorianCalendar cal,
}
// If the type is datetime2 or datetimeoffset, truncate only if its the max value supported
else {
- assert SSType.DATETIME2 == ssType || SSType.DATETIMEOFFSET == ssType : "Unexpected SSType: " + ssType;
+ assert SSType.DATETIME2 == ssType || SSType.DATETIMEOFFSET == ssType : "Unexpected SSType: "
+ + ssType;
// ... then bump the date, provided that the resulting date is still within
// the valid date range.
@@ -5773,8 +5649,7 @@ private void writeScaledTemporal(GregorianCalendar cal,
if (cal.get(Calendar.YEAR) <= 9999) {
scaledNanos = 0;
- }
- else {
+ } else {
cal.add(Calendar.SECOND, -1);
--scaledNanos;
}
@@ -5821,7 +5696,8 @@ private void writeScaledTemporal(GregorianCalendar cal,
if (daysIntoCE < 0 || daysIntoCE >= DDC.daysSinceBaseDate(10000, 1, 1)) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_valueOutOfRange"));
Object[] msgArgs = {ssType};
- throw new SQLServerException(form.format(msgArgs), SQLState.DATA_EXCEPTION_DATETIME_FIELD_OVERFLOW, DriverError.NOT_SET, null);
+ throw new SQLServerException(form.format(msgArgs), SQLState.DATA_EXCEPTION_DATETIME_FIELD_OVERFLOW,
+ DriverError.NOT_SET, null);
}
byte encodedBytes[] = new byte[3];
@@ -5833,31 +5709,28 @@ private void writeScaledTemporal(GregorianCalendar cal,
}
/**
- * Writes to the TDS channel a temporal value as an instance instance of one of the scaled temporal SQL types: DATE, TIME, DATETIME2, or
- * DATETIMEOFFSET.
+ * Writes to the TDS channel a temporal value as an instance instance of one of the scaled temporal SQL types: DATE,
+ * TIME, DATETIME2, or DATETIMEOFFSET.
*
* @param cal
- * Calendar representing the value to write, except for any sub-second nanoseconds
+ * Calendar representing the value to write, except for any sub-second nanoseconds
* @param subSecondNanos
- * the sub-second nanoseconds (0 - 999,999,999)
+ * the sub-second nanoseconds (0 - 999,999,999)
* @param scale
- * the scale (in digits: 0 - 7) to use for the sub-second nanos component
+ * the scale (in digits: 0 - 7) to use for the sub-second nanos component
* @param ssType
- * the SQL Server data type (DATE, TIME, DATETIME2, or DATETIMEOFFSET)
+ * the SQL Server data type (DATE, TIME, DATETIME2, or DATETIMEOFFSET)
* @param minutesOffset
- * the offset value for DATETIMEOFFSET
+ * the offset value for DATETIMEOFFSET
* @throws SQLServerException
- * if an I/O error occurs or if the value is not in the valid range
+ * if an I/O error occurs or if the value is not in the valid range
*/
- byte[] writeEncryptedScaledTemporal(GregorianCalendar cal,
- int subSecondNanos,
- int scale,
- SSType ssType,
+ byte[] writeEncryptedScaledTemporal(GregorianCalendar cal, int subSecondNanos, int scale, SSType ssType,
short minutesOffset) throws SQLServerException {
assert con.isKatmaiOrLater();
- assert SSType.DATE == ssType || SSType.TIME == ssType || SSType.DATETIME2 == ssType || SSType.DATETIMEOFFSET == ssType : "Unexpected SSType: "
- + ssType;
+ assert SSType.DATE == ssType || SSType.TIME == ssType || SSType.DATETIME2 == ssType
+ || SSType.DATETIMEOFFSET == ssType : "Unexpected SSType: " + ssType;
// store the time and minutesOffset portion of DATETIME2 and DATETIMEOFFSET to be used with date portion
byte encodedBytesForEncryption[] = null;
@@ -5873,7 +5746,8 @@ byte[] writeEncryptedScaledTemporal(GregorianCalendar cal,
assert scale >= 0;
assert scale <= TDS.MAX_FRACTIONAL_SECONDS_SCALE;
- secondsSinceMidnight = cal.get(Calendar.SECOND) + 60 * cal.get(Calendar.MINUTE) + 60 * 60 * cal.get(Calendar.HOUR_OF_DAY);
+ secondsSinceMidnight = cal.get(Calendar.SECOND) + 60 * cal.get(Calendar.MINUTE)
+ + 60 * 60 * cal.get(Calendar.HOUR_OF_DAY);
// Scale nanos since midnight to the desired scale, rounding the value as necessary
divisor = Nanos.PER_MAX_SCALE_INTERVAL * (long) Math.pow(10, TDS.MAX_FRACTIONAL_SECONDS_SCALE - scale);
@@ -5882,13 +5756,14 @@ byte[] writeEncryptedScaledTemporal(GregorianCalendar cal,
// indicated by the scale variable. So, for example, scaledNanos = 3 means 300 nanoseconds
// at scale TDS.MAX_FRACTIONAL_SECONDS_SCALE, but 3000 nanoseconds at
// TDS.MAX_FRACTIONAL_SECONDS_SCALE - 1
- scaledNanos = (((long) Nanos.PER_SECOND * secondsSinceMidnight + getRoundedSubSecondNanos(subSecondNanos) + divisor / 2) / divisor)
- * divisor / 100;
+ scaledNanos = (((long) Nanos.PER_SECOND * secondsSinceMidnight + getRoundedSubSecondNanos(subSecondNanos)
+ + divisor / 2) / divisor) * divisor / 100;
// for encrypted time value, SQL server cannot do rounding or casting,
// So, driver needs to cast it before encryption.
if (SSType.TIME == ssType && 864000000000L <= scaledNanos) {
- scaledNanos = (((long) Nanos.PER_SECOND * secondsSinceMidnight + getRoundedSubSecondNanos(subSecondNanos)) / divisor) * divisor / 100;
+ scaledNanos = (((long) Nanos.PER_SECOND * secondsSinceMidnight
+ + getRoundedSubSecondNanos(subSecondNanos)) / divisor) * divisor / 100;
}
// SQL Server rounding behavior indicates that it always rounds up unless
@@ -5903,7 +5778,8 @@ byte[] writeEncryptedScaledTemporal(GregorianCalendar cal,
}
// If the type is datetime2 or datetimeoffset, truncate only if its the max value supported
else {
- assert SSType.DATETIME2 == ssType || SSType.DATETIMEOFFSET == ssType : "Unexpected SSType: " + ssType;
+ assert SSType.DATETIME2 == ssType || SSType.DATETIMEOFFSET == ssType : "Unexpected SSType: "
+ + ssType;
// ... then bump the date, provided that the resulting date is still within
// the valid date range.
@@ -5920,8 +5796,7 @@ byte[] writeEncryptedScaledTemporal(GregorianCalendar cal,
if (cal.get(Calendar.YEAR) <= 9999) {
scaledNanos = 0;
- }
- else {
+ } else {
cal.add(Calendar.SECOND, -1);
--scaledNanos;
}
@@ -5935,13 +5810,11 @@ byte[] writeEncryptedScaledTemporal(GregorianCalendar cal,
if (SSType.TIME == ssType) {
byte[] cipherText = SQLServerSecurityUtility.encryptWithKey(encodedBytes, cryptoMeta, con);
return cipherText;
- }
- else if (SSType.DATETIME2 == ssType) {
+ } else if (SSType.DATETIME2 == ssType) {
// for DATETIME2 sends both date and time part together for encryption
encodedBytesForEncryption = new byte[encodedLength + 3];
System.arraycopy(encodedBytes, 0, encodedBytesForEncryption, 0, encodedBytes.length);
- }
- else if (SSType.DATETIMEOFFSET == ssType) {
+ } else if (SSType.DATETIMEOFFSET == ssType) {
// for DATETIMEOFFSET sends date, time and offset part together for encryption
encodedBytesForEncryption = new byte[encodedLength + 5];
System.arraycopy(encodedBytes, 0, encodedBytesForEncryption, 0, encodedBytes.length);
@@ -5981,7 +5854,8 @@ else if (SSType.DATETIMEOFFSET == ssType) {
if (daysIntoCE < 0 || daysIntoCE >= DDC.daysSinceBaseDate(10000, 1, 1)) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_valueOutOfRange"));
Object[] msgArgs = {ssType};
- throw new SQLServerException(form.format(msgArgs), SQLState.DATA_EXCEPTION_DATETIME_FIELD_OVERFLOW, DriverError.NOT_SET, null);
+ throw new SQLServerException(form.format(msgArgs), SQLState.DATA_EXCEPTION_DATETIME_FIELD_OVERFLOW,
+ DriverError.NOT_SET, null);
}
byte encodedBytes[] = new byte[3];
@@ -5992,14 +5866,13 @@ else if (SSType.DATETIMEOFFSET == ssType) {
byte[] cipherText;
if (SSType.DATE == ssType) {
cipherText = SQLServerSecurityUtility.encryptWithKey(encodedBytes, cryptoMeta, con);
- }
- else if (SSType.DATETIME2 == ssType) {
+ } else if (SSType.DATETIME2 == ssType) {
// for Max value, does not round up, do casting instead.
- if (3652058 == daysIntoCE) { // 9999-12-31
- if (864000000000L == scaledNanos) { // 24:00:00 in nanoseconds
+ if (3652058 == daysIntoCE) { // 9999-12-31
+ if (864000000000L == scaledNanos) { // 24:00:00 in nanoseconds
// does not round up
- scaledNanos = (((long) Nanos.PER_SECOND * secondsSinceMidnight + getRoundedSubSecondNanos(subSecondNanos)) / divisor)
- * divisor / 100;
+ scaledNanos = (((long) Nanos.PER_SECOND * secondsSinceMidnight
+ + getRoundedSubSecondNanos(subSecondNanos)) / divisor) * divisor / 100;
int encodedLength = TDS.nanosSinceMidnightLength(TDS.MAX_FRACTIONAL_SECONDS_SCALE);
byte[] encodedNanoBytes = scaledNanosToEncodedBytes(scaledNanos, encodedLength);
@@ -6013,14 +5886,13 @@ else if (SSType.DATETIME2 == ssType) {
System.arraycopy(encodedBytes, 0, encodedBytesForEncryption, (encodedBytesForEncryption.length - 3), 3);
cipherText = SQLServerSecurityUtility.encryptWithKey(encodedBytesForEncryption, cryptoMeta, con);
- }
- else {
+ } else {
// for Max value, does not round up, do casting instead.
- if (3652058 == daysIntoCE) { // 9999-12-31
- if (864000000000L == scaledNanos) { // 24:00:00 in nanoseconds
+ if (3652058 == daysIntoCE) { // 9999-12-31
+ if (864000000000L == scaledNanos) { // 24:00:00 in nanoseconds
// does not round up
- scaledNanos = (((long) Nanos.PER_SECOND * secondsSinceMidnight + getRoundedSubSecondNanos(subSecondNanos)) / divisor)
- * divisor / 100;
+ scaledNanos = (((long) Nanos.PER_SECOND * secondsSinceMidnight
+ + getRoundedSubSecondNanos(subSecondNanos)) / divisor) * divisor / 100;
int encodedLength = TDS.nanosSinceMidnightLength(TDS.MAX_FRACTIONAL_SECONDS_SCALE);
byte[] encodedNanoBytes = scaledNanosToEncodedBytes(scaledNanos, encodedLength);
@@ -6034,8 +5906,10 @@ else if (SSType.DATETIME2 == ssType) {
// Copy the 3 byte date value
System.arraycopy(encodedBytes, 0, encodedBytesForEncryption, (encodedBytesForEncryption.length - 5), 3);
// Copy the 2 byte minutesOffset value
- System.arraycopy(ByteBuffer.allocate(Short.SIZE / Byte.SIZE).order(ByteOrder.LITTLE_ENDIAN).putShort(minutesOffset).array(), 0,
- encodedBytesForEncryption, (encodedBytesForEncryption.length - 2), 2);
+ System.arraycopy(
+ ByteBuffer.allocate(Short.SIZE / Byte.SIZE).order(ByteOrder.LITTLE_ENDIAN)
+ .putShort(minutesOffset).array(),
+ 0, encodedBytesForEncryption, (encodedBytesForEncryption.length - 2), 2);
cipherText = SQLServerSecurityUtility.encryptWithKey(encodedBytesForEncryption, cryptoMeta, con);
}
@@ -6050,8 +5924,7 @@ else if (SSType.DATETIME2 == ssType) {
return null;
}
- private byte[] scaledNanosToEncodedBytes(long scaledNanos,
- int encodedLength) {
+ private byte[] scaledNanosToEncodedBytes(long scaledNanos, int encodedLength) {
byte encodedBytes[] = new byte[encodedLength];
for (int i = 0; i < encodedLength; i++)
encodedBytes[i] = (byte) ((scaledNanos >> (8 * i)) & 0xFF);
@@ -6062,31 +5935,28 @@ private byte[] scaledNanosToEncodedBytes(long scaledNanos,
* Append the data in a stream in RPC transmission format.
*
* @param sName
- * the optional parameter name
+ * the optional parameter name
* @param stream
- * is the stream
+ * is the stream
* @param streamLength
- * length of the stream (may be unknown)
+ * length of the stream (may be unknown)
* @param bOut
- * boolean true if the data value is being registered as an ouput parameter
+ * boolean true if the data value is being registered as an ouput parameter
* @param jdbcType
- * The JDBC type used to determine whether the value is textual or non-textual.
+ * The JDBC type used to determine whether the value is textual or non-textual.
* @param collation
- * The SQL collation associated with the value. Null for non-textual SQL Server types.
+ * The SQL collation associated with the value. Null for non-textual SQL Server types.
* @throws SQLServerException
*/
- void writeRPCInputStream(String sName,
- InputStream stream,
- long streamLength,
- boolean bOut,
- JDBCType jdbcType,
+ void writeRPCInputStream(String sName, InputStream stream, long streamLength, boolean bOut, JDBCType jdbcType,
SQLCollation collation) throws SQLServerException {
assert null != stream;
assert DataTypes.UNKNOWN_STREAM_LENGTH == streamLength || streamLength >= 0;
// Send long values and values with unknown length
// using PLP chunking on Yukon and later.
- boolean usePLP = (DataTypes.UNKNOWN_STREAM_LENGTH == streamLength || streamLength > DataTypes.SHORT_VARTYPE_MAX_BYTES);
+ boolean usePLP = (DataTypes.UNKNOWN_STREAM_LENGTH == streamLength
+ || streamLength > DataTypes.SHORT_VARTYPE_MAX_BYTES);
if (usePLP) {
assert DataTypes.UNKNOWN_STREAM_LENGTH == streamLength || streamLength <= DataTypes.MAX_VARTYPE_MAX_BYTES;
@@ -6119,9 +5989,9 @@ void writeRPCInputStream(String sName,
baos.write(buff);
streamLength += bytesRead;
}
- }
- catch (IOException e) {
- throw new SQLServerException(e.getMessage(), SQLState.DATA_EXCEPTION_NOT_SPECIFIC, DriverError.NOT_SET, e);
+ } catch (IOException e) {
+ throw new SQLServerException(e.getMessage(), SQLState.DATA_EXCEPTION_NOT_SPECIFIC,
+ DriverError.NOT_SET, e);
}
if (streamLength >= maxStreamLength) {
@@ -6139,7 +6009,8 @@ void writeRPCInputStream(String sName,
boolean useVarType = streamLength <= DataTypes.SHORT_VARTYPE_MAX_BYTES;
writeRPCNameValType(sName, bOut,
- jdbcType.isTextual() ? (useVarType ? TDSType.BIGVARCHAR : TDSType.TEXT) : (useVarType ? TDSType.BIGVARBINARY : TDSType.IMAGE));
+ jdbcType.isTextual() ? (useVarType ? TDSType.BIGVARCHAR : TDSType.TEXT)
+ : (useVarType ? TDSType.BIGVARBINARY : TDSType.IMAGE));
// Write maximum length, optional collation, and actual length
if (useVarType) {
@@ -6147,8 +6018,7 @@ void writeRPCInputStream(String sName,
if (jdbcType.isTextual())
collation.writeCollation(this);
writeShort((short) streamLength);
- }
- else {
+ } else {
writeInt(DataTypes.IMAGE_TEXT_MAX_BYTES);
if (jdbcType.isTextual())
collation.writeCollation(this);
@@ -6164,19 +6034,16 @@ void writeRPCInputStream(String sName,
* Append the XML data in a stream in RPC transmission format.
*
* @param sName
- * the optional parameter name
+ * the optional parameter name
* @param stream
- * is the stream
+ * is the stream
* @param streamLength
- * length of the stream (may be unknown)
+ * length of the stream (may be unknown)
* @param bOut
- * boolean true if the data value is being registered as an ouput parameter
+ * boolean true if the data value is being registered as an ouput parameter
* @throws SQLServerException
*/
- void writeRPCXML(String sName,
- InputStream stream,
- long streamLength,
- boolean bOut) throws SQLServerException {
+ void writeRPCXML(String sName, InputStream stream, long streamLength, boolean bOut) throws SQLServerException {
assert DataTypes.UNKNOWN_STREAM_LENGTH == streamLength || streamLength >= 0;
assert DataTypes.UNKNOWN_STREAM_LENGTH == streamLength || streamLength <= DataTypes.MAX_VARTYPE_MAX_BYTES;
@@ -6186,15 +6053,13 @@ void writeRPCXML(String sName,
if (null == stream) {
// Null header for v*max types is 0xFFFFFFFFFFFFFFFF.
writeLong(0xFFFFFFFFFFFFFFFFL);
- }
- else if (DataTypes.UNKNOWN_STREAM_LENGTH == streamLength) {
+ } else if (DataTypes.UNKNOWN_STREAM_LENGTH == streamLength) {
// Append v*max length.
// UNKNOWN_PLP_LEN is 0xFFFFFFFFFFFFFFFE
writeLong(0xFFFFFFFFFFFFFFFEL);
// NOTE: Don't send the first chunk length, this will be calculated by caller.
- }
- else {
+ } else {
// For v*max types with known length, length is
// We're sending same total length as chunk length (as we're sending 1 chunk).
writeLong(streamLength);
@@ -6208,21 +6073,18 @@ else if (DataTypes.UNKNOWN_STREAM_LENGTH == streamLength) {
* Append the data in a character reader in RPC transmission format.
*
* @param sName
- * the optional parameter name
+ * the optional parameter name
* @param re
- * the reader
+ * the reader
* @param reLength
- * the reader data length (in characters)
+ * the reader data length (in characters)
* @param bOut
- * boolean true if the data value is being registered as an ouput parameter
+ * boolean true if the data value is being registered as an ouput parameter
* @param collation
- * The SQL collation associated with the value. Null for non-textual SQL Server types.
+ * The SQL collation associated with the value. Null for non-textual SQL Server types.
* @throws SQLServerException
*/
- void writeRPCReaderUnicode(String sName,
- Reader re,
- long reLength,
- boolean bOut,
+ void writeRPCReaderUnicode(String sName, Reader re, long reLength, boolean bOut,
SQLCollation collation) throws SQLServerException {
assert null != re;
assert DataTypes.UNKNOWN_STREAM_LENGTH == reLength || reLength >= 0;
@@ -6241,7 +6103,10 @@ void writeRPCReaderUnicode(String sName,
writeRPCNameValType(sName, bOut, TDSType.NVARCHAR);
// Handle Yukon v*max type header here.
- writeVMaxHeader((DataTypes.UNKNOWN_STREAM_LENGTH == reLength) ? DataTypes.UNKNOWN_STREAM_LENGTH : 2 * reLength, // Length (in bytes)
+ writeVMaxHeader(
+ (DataTypes.UNKNOWN_STREAM_LENGTH == reLength) ? DataTypes.UNKNOWN_STREAM_LENGTH : 2 * reLength, // Length
+ // (in
+ // bytes)
false, collation);
}
@@ -6264,8 +6129,7 @@ void writeRPCReaderUnicode(String sName,
writeShort((short) DataTypes.SHORT_VARTYPE_MAX_BYTES);
collation.writeCollation(this);
writeShort((short) (2 * reLength));
- }
- else {
+ } else {
writeInt(DataTypes.NTEXT_MAX_CHARS);
collation.writeCollation(this);
writeInt((int) (2 * reLength));
@@ -6277,12 +6141,14 @@ void writeRPCReaderUnicode(String sName,
}
}
+
/**
* TDSPacket provides a mechanism for chaining TDS response packets together in a singly-linked list.
*
- * Having both the link and the data in the same class allows TDSReader marks (see below) to automatically hold onto exactly as much response data as
- * they need, and no more. Java reference semantics ensure that a mark holds onto its referenced packet and subsequent packets (through next
- * references). When all marked references to a packet go away, the packet, and any linked unmarked packets, can be reclaimed by GC.
+ * Having both the link and the data in the same class allows TDSReader marks (see below) to automatically hold onto
+ * exactly as much response data as they need, and no more. Java reference semantics ensure that a mark holds onto its
+ * referenced packet and subsequent packets (through next references). When all marked references to a packet go away,
+ * the packet, and any linked unmarked packets, can be reclaimed by GC.
*/
final class TDSPacket {
final byte[] header = new byte[TDS.PACKET_HEADER_SIZE];
@@ -6291,8 +6157,8 @@ final class TDSPacket {
volatile TDSPacket next;
final public String toString() {
- return "TDSPacket(SPID:" + Util.readUnsignedShortBigEndian(header, TDS.PACKET_HEADER_SPID) + " Seq:" + header[TDS.PACKET_HEADER_SEQUENCE_NUM]
- + ")";
+ return "TDSPacket(SPID:" + Util.readUnsignedShortBigEndian(header, TDS.PACKET_HEADER_SPID) + " Seq:"
+ + header[TDS.PACKET_HEADER_SEQUENCE_NUM] + ")";
}
TDSPacket(int size) {
@@ -6306,23 +6172,25 @@ final boolean isEOM() {
}
};
+
/**
* TDSReaderMark encapsulates a fixed position in the response data stream.
*
- * Response data is quantized into a linked chain of packets. A mark refers to a specific location in a specific packet and relies on Java's reference
- * semantics to automatically keep all subsequent packets accessible until the mark is destroyed.
+ * Response data is quantized into a linked chain of packets. A mark refers to a specific location in a specific packet
+ * and relies on Java's reference semantics to automatically keep all subsequent packets accessible until the mark is
+ * destroyed.
*/
final class TDSReaderMark {
final TDSPacket packet;
final int payloadOffset;
- TDSReaderMark(TDSPacket packet,
- int payloadOffset) {
+ TDSReaderMark(TDSPacket packet, int payloadOffset) {
this.packet = packet;
this.payloadOffset = payloadOffset;
}
}
+
/**
* TDSReader encapsulates the TDS response data stream.
*
@@ -6332,7 +6200,7 @@ final class TDSReader {
private final static Logger logger = Logger.getLogger("com.microsoft.sqlserver.jdbc.internals.TDS.Reader");
final private String traceID;
private TimeoutTimer tcpKeepAliveTimeoutTimer;
-
+
final public String toString() {
return traceID;
}
@@ -6350,7 +6218,7 @@ final TDSCommand getCommand() {
final SQLServerConnection getConnection() {
return con;
}
-
+
private TDSPacket currentPacket = new TDSPacket(0);
private TDSPacket lastPacket = currentPacket;
private int payloadOffset = 0;
@@ -6362,7 +6230,7 @@ final SQLServerConnection getConnection() {
private boolean serverSupportsDataClassification = false;
private final byte valueBytes[] = new byte[256];
-
+
protected SensitivityClassification sensitivityClassification;
private static final AtomicInteger lastReaderID = new AtomicInteger(0);
@@ -6371,16 +6239,20 @@ private static int nextReaderID() {
return lastReaderID.incrementAndGet();
}
- TDSReader(TDSChannel tdsChannel,
- SQLServerConnection con,
- TDSCommand command) {
+ TDSReader(TDSChannel tdsChannel, SQLServerConnection con, TDSCommand command) {
this.tdsChannel = tdsChannel;
this.con = con;
this.command = command; // may be null
- if(null != command) {
- //if cancelQueryTimeout is set, we should wait for the total amount of queryTimeout + cancelQueryTimeout to terminate the connection.
- this.tcpKeepAliveTimeoutTimer = (command.getCancelQueryTimeoutSeconds() > 0 && command.getQueryTimeoutSeconds() > 0 ) ?
- (new TimeoutTimer(command.getCancelQueryTimeoutSeconds() + command.getQueryTimeoutSeconds(), null, con)) : null;
+ if (null != command) {
+ // if cancelQueryTimeout is set, we should wait for the total amount of queryTimeout + cancelQueryTimeout to
+ // terminate the connection.
+ this.tcpKeepAliveTimeoutTimer = (command.getCancelQueryTimeoutSeconds() > 0
+ && command.getQueryTimeoutSeconds() > 0)
+ ? (new TimeoutTimer(
+ command.getCancelQueryTimeoutSeconds()
+ + command.getQueryTimeoutSeconds(),
+ null, con))
+ : null;
}
// if the logging level is not detailed than fine or more we will not have proper reader IDs.
if (logger.isLoggable(Level.FINE))
@@ -6405,7 +6277,7 @@ final boolean getServerSupportsColumnEncryption() {
final boolean getServerSupportsDataClassification() {
return serverSupportsDataClassification;
}
-
+
final void throwInvalidTDS() throws SQLServerException {
if (logger.isLoggable(Level.SEVERE))
logger.severe(toString() + " got unexpected value in TDS response at offset:" + payloadOffset);
@@ -6419,7 +6291,8 @@ final void throwInvalidTDSToken(String tokenName) throws SQLServerException {
}
/**
- * Ensures that payload data is available to be read, automatically advancing to (and possibly reading) the next packet.
+ * Ensures that payload data is available to be read, automatically advancing to (and possibly reading) the next
+ * packet.
*
* @return true if additional data is available to be read false if no more data is available
*/
@@ -6471,8 +6344,8 @@ private boolean nextPacket() throws SQLServerException {
/**
* Reads the next packet of the TDS channel.
*
- * This method is synchronized to guard against simultaneously reading packets from one thread that is processing the response and another thread
- * that is trying to buffer it with TDSCommand.detach().
+ * This method is synchronized to guard against simultaneously reading packets from one thread that is processing
+ * the response and another thread that is trying to buffer it with TDSCommand.detach().
*/
synchronized final boolean readPacket() throws SQLServerException {
if (null != command && !command.readingResponse())
@@ -6481,8 +6354,8 @@ synchronized final boolean readPacket() throws SQLServerException {
// Number of packets in should always be less than number of packets out.
// If the server has been notified for an interrupt, it may be less by
// more than one packet.
- assert tdsChannel.numMsgsRcvd < tdsChannel.numMsgsSent : "numMsgsRcvd:" + tdsChannel.numMsgsRcvd + " should be less than numMsgsSent:"
- + tdsChannel.numMsgsSent;
+ assert tdsChannel.numMsgsRcvd < tdsChannel.numMsgsSent : "numMsgsRcvd:" + tdsChannel.numMsgsRcvd
+ + " should be less than numMsgsSent:" + tdsChannel.numMsgsSent;
TDSPacket newPacket = new TDSPacket(con.getTDSPacketSize());
if (null != tcpKeepAliveTimeoutTimer) {
@@ -6493,18 +6366,21 @@ synchronized final boolean readPacket() throws SQLServerException {
}
// First, read the packet header.
for (int headerBytesRead = 0; headerBytesRead < TDS.PACKET_HEADER_SIZE;) {
- int bytesRead = tdsChannel.read(newPacket.header, headerBytesRead, TDS.PACKET_HEADER_SIZE - headerBytesRead);
+ int bytesRead = tdsChannel.read(newPacket.header, headerBytesRead,
+ TDS.PACKET_HEADER_SIZE - headerBytesRead);
if (bytesRead < 0) {
if (logger.isLoggable(Level.FINER))
- logger.finer(toString() + " Premature EOS in response. packetNum:" + packetNum + " headerBytesRead:" + headerBytesRead);
+ logger.finer(toString() + " Premature EOS in response. packetNum:" + packetNum + " headerBytesRead:"
+ + headerBytesRead);
- con.terminate(SQLServerException.DRIVER_ERROR_IO_FAILED, ((0 == packetNum && 0 == headerBytesRead)
- ? SQLServerException.getErrString("R_noServerResponse") : SQLServerException.getErrString("R_truncatedServerResponse")));
+ con.terminate(SQLServerException.DRIVER_ERROR_IO_FAILED,
+ ((0 == packetNum && 0 == headerBytesRead) ? SQLServerException.getErrString(
+ "R_noServerResponse") : SQLServerException.getErrString("R_truncatedServerResponse")));
}
headerBytesRead += bytesRead;
}
-
+
// if execution was subject to timeout then stop timing
if (null != tcpKeepAliveTimeoutTimer) {
if (logger.isLoggable(Level.FINEST)) {
@@ -6518,8 +6394,8 @@ synchronized final boolean readPacket() throws SQLServerException {
// Make header size is properly bounded and compute length of the packet payload.
if (packetLength < TDS.PACKET_HEADER_SIZE || packetLength > con.getTDSPacketSize()) {
if (logger.isLoggable(Level.WARNING)) {
- logger.warning(
- toString() + " TDS header contained invalid packet length:" + packetLength + "; packet size:" + con.getTDSPacketSize());
+ logger.warning(toString() + " TDS header contained invalid packet length:" + packetLength
+ + "; packet size:" + con.getTDSPacketSize());
}
throwInvalidTDS();
}
@@ -6539,9 +6415,11 @@ synchronized final boolean readPacket() throws SQLServerException {
// Now for the payload...
for (int payloadBytesRead = 0; payloadBytesRead < newPacket.payloadLength;) {
- int bytesRead = tdsChannel.read(newPacket.payload, payloadBytesRead, newPacket.payloadLength - payloadBytesRead);
+ int bytesRead = tdsChannel.read(newPacket.payload, payloadBytesRead,
+ newPacket.payloadLength - payloadBytesRead);
if (bytesRead < 0)
- con.terminate(SQLServerException.DRIVER_ERROR_IO_FAILED, SQLServerException.getErrString("R_truncatedServerResponse"));
+ con.terminate(SQLServerException.DRIVER_ERROR_IO_FAILED,
+ SQLServerException.getErrString("R_truncatedServerResponse"));
payloadBytesRead += bytesRead;
}
@@ -6595,8 +6473,8 @@ final void stream() {
}
/**
- * Returns the number of bytes that can be read (or skipped over) from this TDSReader without blocking by the next caller of a method for this
- * TDSReader.
+ * Returns the number of bytes that can be read (or skipped over) from this TDSReader without blocking by the next
+ * caller of a method for this TDSReader.
*
* @return the actual number of bytes available.
*/
@@ -6616,8 +6494,8 @@ final int available() {
*/
final int availableCurrentPacket() {
/*
- * The number of bytes that can be read from the current chunk, without including the next chunk that is buffered. This is so the driver can
- * confirm if the next chunk sent is new packet or just continuation
+ * The number of bytes that can be read from the current chunk, without including the next chunk that is
+ * buffered. This is so the driver can confirm if the next chunk sent is new packet or just continuation
*/
int available = currentPacket.payloadLength - payloadOffset;
return available;
@@ -6716,9 +6594,7 @@ final long readLong() throws SQLServerException {
return Util.readLong(readWrappedBytes(8), 0);
}
- final void readBytes(byte[] value,
- int valueOffset,
- int valueLength) throws SQLServerException {
+ final void readBytes(byte[] value, int valueOffset, int valueLength) throws SQLServerException {
for (int bytesRead = 0; bytesRead < valueLength;) {
// Ensure that we have a packet to read from.
if (!ensurePayload())
@@ -6746,9 +6622,7 @@ final byte[] readWrappedBytes(int valueLength) throws SQLServerException {
return valueBytes;
}
- final Object readDecimal(int valueLength,
- TypeInfo typeInfo,
- JDBCType jdbcType,
+ final Object readDecimal(int valueLength, TypeInfo typeInfo, JDBCType jdbcType,
StreamType streamType) throws SQLServerException {
if (valueLength > valueBytes.length) {
if (logger.isLoggable(Level.WARNING)) {
@@ -6758,12 +6632,11 @@ final Object readDecimal(int valueLength,
}
readBytes(valueBytes, 0, valueLength);
- return DDC.convertBigDecimalToObject(Util.readBigDecimal(valueBytes, valueLength, typeInfo.getScale()), jdbcType, streamType);
+ return DDC.convertBigDecimalToObject(Util.readBigDecimal(valueBytes, valueLength, typeInfo.getScale()),
+ jdbcType, streamType);
}
- final Object readMoney(int valueLength,
- JDBCType jdbcType,
- StreamType streamType) throws SQLServerException {
+ final Object readMoney(int valueLength, JDBCType jdbcType, StreamType streamType) throws SQLServerException {
BigInteger bi;
switch (valueLength) {
case 8: // money
@@ -6800,27 +6673,21 @@ final Object readMoney(int valueLength,
return DDC.convertBigDecimalToObject(new BigDecimal(bi, 4), jdbcType, streamType);
}
- final Object readReal(int valueLength,
- JDBCType jdbcType,
- StreamType streamType) throws SQLServerException {
+ final Object readReal(int valueLength, JDBCType jdbcType, StreamType streamType) throws SQLServerException {
if (4 != valueLength)
throwInvalidTDS();
return DDC.convertFloatToObject(Float.intBitsToFloat(readInt()), jdbcType, streamType);
}
- final Object readFloat(int valueLength,
- JDBCType jdbcType,
- StreamType streamType) throws SQLServerException {
+ final Object readFloat(int valueLength, JDBCType jdbcType, StreamType streamType) throws SQLServerException {
if (8 != valueLength)
throwInvalidTDS();
return DDC.convertDoubleToObject(Double.longBitsToDouble(readLong()), jdbcType, streamType);
}
- final Object readDateTime(int valueLength,
- Calendar appTimeZoneCalendar,
- JDBCType jdbcType,
+ final Object readDateTime(int valueLength, Calendar appTimeZoneCalendar, JDBCType jdbcType,
StreamType streamType) throws SQLServerException {
// Build and return the right kind of temporal object.
int daysSinceSQLBaseDate;
@@ -6843,7 +6710,8 @@ final Object readDateTime(int valueLength,
return value;
}
- msecSinceMidnight = (ticksSinceMidnight * 10 + 1) / 3; // Convert to msec (1 tick = 1 300th of a sec = 3 msec)
+ msecSinceMidnight = (ticksSinceMidnight * 10 + 1) / 3; // Convert to msec (1 tick = 1 300th of a sec = 3
+ // msec)
break;
case 4:
@@ -6869,17 +6737,16 @@ final Object readDateTime(int valueLength,
}
// Convert the DATETIME/SMALLDATETIME value to the desired Java type.
- return DDC.convertTemporalToObject(jdbcType, SSType.DATETIME, appTimeZoneCalendar, daysSinceSQLBaseDate, msecSinceMidnight, 0); // scale
- // (ignored
- // for
- // fixed-scale
- // DATETIME/SMALLDATETIME
- // types)
+ return DDC.convertTemporalToObject(jdbcType, SSType.DATETIME, appTimeZoneCalendar, daysSinceSQLBaseDate,
+ msecSinceMidnight, 0); // scale
+ // (ignored
+ // for
+ // fixed-scale
+ // DATETIME/SMALLDATETIME
+ // types)
}
- final Object readDate(int valueLength,
- Calendar appTimeZoneCalendar,
- JDBCType jdbcType) throws SQLServerException {
+ final Object readDate(int valueLength, Calendar appTimeZoneCalendar, JDBCType jdbcType) throws SQLServerException {
if (TDS.DAYS_INTO_CE_LENGTH != valueLength)
throwInvalidTDS();
@@ -6887,13 +6754,14 @@ final Object readDate(int valueLength,
int localDaysIntoCE = readDaysIntoCE();
// Convert the DATE value to the desired Java type.
- return DDC.convertTemporalToObject(jdbcType, SSType.DATE, appTimeZoneCalendar, localDaysIntoCE, 0, // midnight local to app time zone
+ return DDC.convertTemporalToObject(jdbcType, SSType.DATE, appTimeZoneCalendar, localDaysIntoCE, 0, // midnight
+ // local to
+ // app time
+ // zone
0); // scale (ignored for DATE)
}
- final Object readTime(int valueLength,
- TypeInfo typeInfo,
- Calendar appTimeZoneCalendar,
+ final Object readTime(int valueLength, TypeInfo typeInfo, Calendar appTimeZoneCalendar,
JDBCType jdbcType) throws SQLServerException {
if (TDS.timeValueLength(typeInfo.getScale()) != valueLength)
throwInvalidTDS();
@@ -6902,12 +6770,11 @@ final Object readTime(int valueLength,
long localNanosSinceMidnight = readNanosSinceMidnight(typeInfo.getScale());
// Convert the TIME value to the desired Java type.
- return DDC.convertTemporalToObject(jdbcType, SSType.TIME, appTimeZoneCalendar, 0, localNanosSinceMidnight, typeInfo.getScale());
+ return DDC.convertTemporalToObject(jdbcType, SSType.TIME, appTimeZoneCalendar, 0, localNanosSinceMidnight,
+ typeInfo.getScale());
}
- final Object readDateTime2(int valueLength,
- TypeInfo typeInfo,
- Calendar appTimeZoneCalendar,
+ final Object readDateTime2(int valueLength, TypeInfo typeInfo, Calendar appTimeZoneCalendar,
JDBCType jdbcType) throws SQLServerException {
if (TDS.datetime2ValueLength(typeInfo.getScale()) != valueLength)
throwInvalidTDS();
@@ -6917,13 +6784,11 @@ final Object readDateTime2(int valueLength,
int localDaysIntoCE = readDaysIntoCE();
// Convert the DATETIME2 value to the desired Java type.
- return DDC.convertTemporalToObject(jdbcType, SSType.DATETIME2, appTimeZoneCalendar, localDaysIntoCE, localNanosSinceMidnight,
- typeInfo.getScale());
+ return DDC.convertTemporalToObject(jdbcType, SSType.DATETIME2, appTimeZoneCalendar, localDaysIntoCE,
+ localNanosSinceMidnight, typeInfo.getScale());
}
- final Object readDateTimeOffset(int valueLength,
- TypeInfo typeInfo,
- JDBCType jdbcType) throws SQLServerException {
+ final Object readDateTimeOffset(int valueLength, TypeInfo typeInfo, JDBCType jdbcType) throws SQLServerException {
if (TDS.datetimeoffsetValueLength(typeInfo.getScale()) != valueLength)
throwInvalidTDS();
@@ -6935,8 +6800,8 @@ final Object readDateTimeOffset(int valueLength,
// Convert the DATETIMEOFFSET value to the desired Java type.
return DDC.convertTemporalToObject(jdbcType, SSType.DATETIMEOFFSET,
- new GregorianCalendar(new SimpleTimeZone(localMinutesOffset * 60 * 1000, ""), Locale.US), utcDaysIntoCE, utcNanosSinceMidnight,
- typeInfo.getScale());
+ new GregorianCalendar(new SimpleTimeZone(localMinutesOffset * 60 * 1000, ""), Locale.US), utcDaysIntoCE,
+ utcNanosSinceMidnight, typeInfo.getScale());
}
private int readDaysIntoCE() throws SQLServerException {
@@ -6979,9 +6844,7 @@ private long readNanosSinceMidnight(int scale) throws SQLServerException {
final static String guidTemplate = "NNNNNNNN-NNNN-NNNN-NNNN-NNNNNNNNNNNN";
- final Object readGUID(int valueLength,
- JDBCType jdbcType,
- StreamType streamType) throws SQLServerException {
+ final Object readGUID(int valueLength, JDBCType jdbcType, StreamType streamType) throws SQLServerException {
// GUIDs must be exactly 16 bytes
if (16 != valueLength)
throwInvalidTDS();
@@ -7023,8 +6886,7 @@ final Object readGUID(int valueLength,
try {
return DDC.convertStringToObject(sb.toString(), Encoding.UNICODE.charset(), jdbcType, streamType);
- }
- catch (UnsupportedEncodingException e) {
+ } catch (UnsupportedEncodingException e) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_errorConvertingValue"));
throw new SQLServerException(form.format(new Object[] {"UNIQUEIDENTIFIER", jdbcType}), null, 0, e);
}
@@ -7071,8 +6933,7 @@ final SQLCollation readCollation() throws SQLServerException {
try {
collation = new SQLCollation(this);
- }
- catch (UnsupportedEncodingException e) {
+ } catch (UnsupportedEncodingException e) {
con.terminate(SQLServerException.DRIVER_ERROR_INVALID_TDS, e.getMessage(), e);
// not reached
}
@@ -7104,7 +6965,8 @@ final void tryProcessFeatureExtAck(boolean featureExtAckReceived) throws SQLServ
}
if (isColumnEncryptionSettingEnabled() && !featureExtAckReceived)
- throw new SQLServerException(this, SQLServerException.getErrString("R_AE_NotSupportedByServer"), null, 0, false);
+ throw new SQLServerException(this, SQLServerException.getErrString("R_AE_NotSupportedByServer"), null, 0,
+ false);
}
final void trySetSensitivityClassification(SensitivityClassification sensitivityClassification) {
@@ -7112,11 +6974,12 @@ final void trySetSensitivityClassification(SensitivityClassification sensitivity
}
}
+
/**
* Timer for use with Commands that support a timeout.
*
- * Once started, the timer runs for the prescribed number of seconds unless stopped. If the timer runs out, it interrupts its associated Command with
- * a reason like "timed out".
+ * Once started, the timer runs for the prescribed number of seconds unless stopped. If the timer runs out, it
+ * interrupts its associated Command with a reason like "timed out".
*/
final class TimeoutTimer implements Runnable {
private static final String threadGroupName = "mssql-jdbc-TimeoutTimer";
@@ -7124,18 +6987,16 @@ final class TimeoutTimer implements Runnable {
private final TDSCommand command;
private volatile Future> task;
private final SQLServerConnection con;
-
+
private static final ExecutorService executor = Executors.newCachedThreadPool(new ThreadFactory() {
private final AtomicReference tgr = new AtomicReference<>();
private final AtomicInteger threadNumber = new AtomicInteger(0);
@Override
- public Thread newThread(Runnable r)
- {
+ public Thread newThread(Runnable r) {
ThreadGroup tg = tgr.get();
- if (tg == null || tg.isDestroyed())
- {
+ if (tg == null || tg.isDestroyed()) {
tg = new ThreadGroup(threadGroupName);
tgr.set(tg);
}
@@ -7148,9 +7009,7 @@ public Thread newThread(Runnable r)
private volatile boolean canceled = false;
- TimeoutTimer(int timeoutSeconds,
- TDSCommand command,
- SQLServerConnection con) {
+ TimeoutTimer(int timeoutSeconds, TDSCommand command, SQLServerConnection con) {
assert timeoutSeconds > 0;
this.timeoutSeconds = timeoutSeconds;
@@ -7177,10 +7036,8 @@ public void run() {
return;
Thread.sleep(1000);
- }
- while (--secondsRemaining > 0);
- }
- catch (InterruptedException e) {
+ } while (--secondsRemaining > 0);
+ } catch (InterruptedException e) {
// re-interrupt the current thread, in order to restore the thread's interrupt status.
Thread.currentThread().interrupt();
return;
@@ -7189,18 +7046,19 @@ public void run() {
// If the timer wasn't canceled before it ran out of
// time then interrupt the registered command.
try {
- // If TCP Connection to server is silently dropped, exceeding the query timeout on the same connection does not throw SQLTimeoutException
- // The application stops responding instead until SocketTimeoutException is thrown. In this case, we must manually terminate the connection.
+ // If TCP Connection to server is silently dropped, exceeding the query timeout on the same connection does
+ // not throw SQLTimeoutException
+ // The application stops responding instead until SocketTimeoutException is thrown. In this case, we must
+ // manually terminate the connection.
if (null == command && null != con) {
- con.terminate(SQLServerException.DRIVER_ERROR_IO_FAILED, SQLServerException.getErrString("R_connectionIsClosed"));
- }
- else {
+ con.terminate(SQLServerException.DRIVER_ERROR_IO_FAILED,
+ SQLServerException.getErrString("R_connectionIsClosed"));
+ } else {
// If the timer wasn't canceled before it ran out of
// time then interrupt the registered command.
command.interrupt(SQLServerException.getErrString("R_queryTimedOut"));
}
- }
- catch (SQLServerException e) {
+ } catch (SQLServerException e) {
// Unfortunately, there's nothing we can do if we
// fail to time out the request. There is no way
// to report back what happened.
@@ -7210,14 +7068,17 @@ public void run() {
}
}
+
/**
* TDSCommand encapsulates an interruptable TDS conversation.
*
- * A conversation may consist of one or more TDS request and response messages. A command may be interrupted at any point, from any thread, and for
- * any reason. Acknowledgement and handling of an interrupt is fully encapsulated by this class.
+ * A conversation may consist of one or more TDS request and response messages. A command may be interrupted at any
+ * point, from any thread, and for any reason. Acknowledgement and handling of an interrupt is fully encapsulated by
+ * this class.
*
- * Commands may be created with an optional timeout (in seconds). Timeouts are implemented as a form of interrupt, where the interrupt event occurs
- * when the timeout period expires. Currently, only the time to receive the response from the channel counts against the timeout period.
+ * Commands may be created with an optional timeout (in seconds). Timeouts are implemented as a form of interrupt, where
+ * the interrupt event occurs when the timeout period expires. Currently, only the time to receive the response from the
+ * channel counts against the timeout period.
*/
abstract class TDSCommand {
abstract boolean doExecute() throws SQLServerException;
@@ -7237,8 +7098,7 @@ final public String toString() {
return traceID;
}
- final void log(Level level,
- String message) {
+ final void log(Level level, String message) {
logger.log(level, toString() + ": " + message);
}
@@ -7251,8 +7111,8 @@ final void log(Level level,
// Volatile ensures visibility to execution thread and interrupt thread
private volatile TDSWriter tdsWriter;
private volatile TDSReader tdsReader;
-
- protected TDSWriter getTDSWriter(){
+
+ protected TDSWriter getTDSWriter() {
return tdsWriter;
}
@@ -7332,17 +7192,17 @@ protected void setProcessedResponse(boolean processedResponse) {
// any attention ack. The command's response is read either on demand as it is processed,
// or by detaching.
private volatile boolean readingResponse;
- private int queryTimeoutSeconds;
- private int cancelQueryTimeoutSeconds;
+ private int queryTimeoutSeconds;
+ private int cancelQueryTimeoutSeconds;
protected int getQueryTimeoutSeconds() {
- return this.queryTimeoutSeconds;
+ return this.queryTimeoutSeconds;
}
protected int getCancelQueryTimeoutSeconds() {
- return this.cancelQueryTimeoutSeconds;
+ return this.cancelQueryTimeoutSeconds;
}
-
+
final boolean readingResponse() {
return readingResponse;
}
@@ -7351,12 +7211,12 @@ final boolean readingResponse() {
* Creates this command with an optional timeout.
*
* @param logContext
- * the string describing the context for this command.
+ * the string describing the context for this command.
* @param timeoutSeconds
- * (optional) the time before which the command must complete before it is interrupted. A value of 0 means no timeout.
+ * (optional) the time before which the command must complete before it is interrupted. A value of 0 means no
+ * timeout.
*/
- TDSCommand(String logContext,
- int queryTimeoutSeconds, int cancelQueryTimeoutSeconds) {
+ TDSCommand(String logContext, int queryTimeoutSeconds, int cancelQueryTimeoutSeconds) {
this.logContext = logContext;
this.queryTimeoutSeconds = queryTimeoutSeconds;
this.cancelQueryTimeoutSeconds = cancelQueryTimeoutSeconds;
@@ -7369,18 +7229,16 @@ final boolean readingResponse() {
* @param tdsWriter
* @param tdsReader
* @throws SQLServerException
- * on any error executing the command, including cancel or timeout.
+ * on any error executing the command, including cancel or timeout.
*/
- boolean execute(TDSWriter tdsWriter,
- TDSReader tdsReader) throws SQLServerException {
+ boolean execute(TDSWriter tdsWriter, TDSReader tdsReader) throws SQLServerException {
this.tdsWriter = tdsWriter;
this.tdsReader = tdsReader;
assert null != tdsReader;
try {
return doExecute(); // Derived classes implement the execution details
- }
- catch (SQLServerException e) {
+ } catch (SQLServerException e) {
try {
// If command execution threw an exception for any reason before the request
// was complete then interrupt the command (it may already be interrupted)
@@ -7392,10 +7250,10 @@ boolean execute(TDSWriter tdsWriter,
onRequestComplete();
close();
}
- }
- catch (SQLServerException interruptException) {
+ } catch (SQLServerException interruptException) {
if (logger.isLoggable(Level.FINE))
- logger.fine(this.toString() + ": Ignoring error in sending attention: " + interruptException.getMessage());
+ logger.fine(this.toString() + ": Ignoring error in sending attention: "
+ + interruptException.getMessage());
}
// throw the original exception even if trying to interrupt fails even in the case
// of trying to send a cancel to the server.
@@ -7413,8 +7271,7 @@ void processResponse(TDSReader tdsReader) throws SQLServerException {
logger.finest(this.toString() + ": Processing response");
try {
TDSParser.parse(tdsReader, getLogContext());
- }
- catch (SQLServerException e) {
+ } catch (SQLServerException e) {
if (SQLServerException.DRIVER_ERROR_FROM_DATABASE != e.getDriverErrorCode())
throw e;
@@ -7426,7 +7283,8 @@ void processResponse(TDSReader tdsReader) throws SQLServerException {
/**
* Clears this command from the TDS channel so that another command can execute.
*
- * This method does not process the response. It just buffers it in memory, including any attention ack that may be present.
+ * This method does not process the response. It just buffers it in memory, including any attention ack that may be
+ * present.
*/
final void detach() throws SQLServerException {
if (logger.isLoggable(Level.FINEST))
@@ -7434,8 +7292,7 @@ final void detach() throws SQLServerException {
// Read any remaining response packets from the server.
// This operation may be timed out or cancelled from another thread.
- while (tdsReader.readPacket())
- ;
+ while (tdsReader.readPacket());
// Postcondition: the entire response has been read
assert !readingResponse;
@@ -7451,8 +7308,7 @@ final void close() {
while (!processedResponse) {
try {
processResponse(tdsReader);
- }
- catch (SQLServerException e) {
+ } catch (SQLServerException e) {
if (logger.isLoggable(Level.FINEST))
logger.finest(this + ": close ignoring error processing response: " + e.getMessage());
@@ -7469,14 +7325,12 @@ final void close() {
try {
TDSParser.parse(tdsReader, "attention ack");
- }
- catch (SQLServerException e) {
+ } catch (SQLServerException e) {
if (tdsReader.getConnection().isSessionUnAvailable()) {
if (logger.isLoggable(Level.FINEST))
logger.finest(this + ": giving up on attention ack after connection closed by exception: " + e);
attentionPending = false;
- }
- else {
+ } else {
if (logger.isLoggable(Level.FINEST))
logger.finest(this + ": ignored exception: " + e);
}
@@ -7487,13 +7341,13 @@ final void close() {
// terminate the connection to prevent any other command from executing.
if (attentionPending) {
if (logger.isLoggable(Level.SEVERE)) {
- logger.severe(this.toString() + ": expected attn ack missing or not processed; terminating connection...");
+ logger.severe(this.toString()
+ + ": expected attn ack missing or not processed; terminating connection...");
}
try {
tdsReader.throwInvalidTDS();
- }
- catch (SQLServerException e) {
+ } catch (SQLServerException e) {
if (logger.isLoggable(Level.FINEST))
logger.finest(this + ": ignored expected invalid TDS exception: " + e);
@@ -7512,16 +7366,17 @@ final void close() {
/**
* Interrupts execution of this command, typically from another thread.
*
- * Only the first interrupt has any effect. Subsequent interrupts are ignored. Interrupts are also ignored until enabled. If interrupting the
- * command requires an attention signal to be sent to the server, then this method sends that signal if the command's request is already complete.
+ * Only the first interrupt has any effect. Subsequent interrupts are ignored. Interrupts are also ignored until
+ * enabled. If interrupting the command requires an attention signal to be sent to the server, then this method
+ * sends that signal if the command's request is already complete.
*
- * Signalling mechanism is "fire and forget". It is up to either the execution thread or, possibly, a detaching thread, to ensure that any pending
- * attention ack later will be received and processed.
+ * Signalling mechanism is "fire and forget". It is up to either the execution thread or, possibly, a detaching
+ * thread, to ensure that any pending attention ack later will be received and processed.
*
* @param reason
- * the reason for the interrupt, typically cancel or timeout.
+ * the reason for the interrupt, typically cancel or timeout.
* @throws SQLServerException
- * if interrupting fails for some reason. This call does not throw the reason for the interrupt.
+ * if interrupting fails for some reason. This call does not throw the reason for the interrupt.
*/
void interrupt(String reason) throws SQLServerException {
// Multiple, possibly simultaneous, interrupts may occur.
@@ -7545,17 +7400,18 @@ void interrupt(String reason) throws SQLServerException {
/**
* Checks once whether an interrupt has occurred, and, if it has, throws an exception indicating that fact.
*
- * Any calls after the first to check for interrupts are no-ops. This method is called periodically from this command's execution thread to notify
- * the app when an interrupt has happened.
+ * Any calls after the first to check for interrupts are no-ops. This method is called periodically from this
+ * command's execution thread to notify the app when an interrupt has happened.
*
- * It should only be called from places where consistent behavior can be ensured after the exception is thrown. For example, it should not be
- * called at arbitrary times while processing the response, as doing so could leave the response token stream in an inconsistent state. Currently,
- * response processing only checks for interrupts after every result or OUT parameter.
+ * It should only be called from places where consistent behavior can be ensured after the exception is thrown. For
+ * example, it should not be called at arbitrary times while processing the response, as doing so could leave the
+ * response token stream in an inconsistent state. Currently, response processing only checks for interrupts after
+ * every result or OUT parameter.
*
* Request processing checks for interrupts before writing each packet.
*
* @throws SQLServerException
- * if this command was interrupted, throws the reason for the interrupt.
+ * if this command was interrupted, throws the reason for the interrupt.
*/
final void checkForInterrupt() throws SQLServerException {
// Throw an exception with the interrupt reason if this command was interrupted.
@@ -7576,17 +7432,18 @@ final void checkForInterrupt() throws SQLServerException {
/**
* Notifies this command when no more request packets are to be sent to the server.
*
- * After the last packet has been sent, the only way to interrupt the request is to send an attention signal from the interrupt() method.
+ * After the last packet has been sent, the only way to interrupt the request is to send an attention signal from
+ * the interrupt() method.
*
- * Note that this method is called when the request completes normally (last packet sent with EOM bit) or when it completes after being
- * interrupted (0 or more packets sent with no EOM bit).
+ * Note that this method is called when the request completes normally (last packet sent with EOM bit) or when it
+ * completes after being interrupted (0 or more packets sent with no EOM bit).
*/
final void onRequestComplete() throws SQLServerException {
synchronized (interruptLock) {
- assert !requestComplete;
-
- if (logger.isLoggable(Level.FINEST))
- logger.finest(this + ": request complete");
+ assert !requestComplete;
+
+ if (logger.isLoggable(Level.FINEST))
+ logger.finest(this + ": request complete");
requestComplete = true;
@@ -7600,21 +7457,18 @@ final void onRequestComplete() throws SQLServerException {
assert !processedResponse;
assert !readingResponse;
processedResponse = true;
- }
- else if (wasInterrupted()) {
+ } else if (wasInterrupted()) {
if (tdsWriter.isEOMSent()) {
attentionPending = tdsWriter.sendAttention();
readingResponse = attentionPending;
- }
- else {
+ } else {
assert !attentionPending;
readingResponse = tdsWriter.ignoreMessage();
}
processedResponse = !readingResponse;
- }
- else {
+ } else {
assert !attentionPending;
assert !processedResponse;
readingResponse = true;
@@ -7625,13 +7479,13 @@ else if (wasInterrupted()) {
/**
* Notifies this command when the last packet of the response has been read.
*
- * When the last packet is read, interrupts are disabled. If an interrupt occurred prior to disabling that caused an attention signal to be sent
- * to the server, then an extra packet containing the attention ack is read.
+ * When the last packet is read, interrupts are disabled. If an interrupt occurred prior to disabling that caused an
+ * attention signal to be sent to the server, then an extra packet containing the attention ack is read.
*
* This ensures that on return from this method, the TDS channel is clear of all response packets for this command.
*
- * Note that this method is called for the attention ack message itself as well, so we need to be sure not to expect more than one attention
- * ack...
+ * Note that this method is called for the attention ack message itself as well, so we need to be sure not to expect
+ * more than one attention ack...
*/
final void onResponseEOM() throws SQLServerException {
boolean readAttentionAck = false;
@@ -7690,10 +7544,10 @@ final void onAttentionAck() {
* Starts sending this command's TDS request to the server.
*
* @param tdsMessageType
- * the type of the TDS message (RPC, QUERY, etc.)
+ * the type of the TDS message (RPC, QUERY, etc.)
* @return the TDS writer used to write the request.
* @throws SQLServerException
- * on any error, including acknowledgement of an interrupt.
+ * on any error, including acknowledgement of an interrupt.
*/
final TDSWriter startRequest(byte tdsMessageType) throws SQLServerException {
if (logger.isLoggable(Level.FINEST))
@@ -7702,8 +7556,7 @@ final TDSWriter startRequest(byte tdsMessageType) throws SQLServerException {
// Start this command's request message
try {
tdsWriter.startMessage(this, tdsMessageType);
- }
- catch (SQLServerException e) {
+ } catch (SQLServerException e) {
if (logger.isLoggable(Level.FINEST))
logger.finest(this + ": starting request: exception: " + e.getMessage());
@@ -7731,7 +7584,7 @@ final TDSWriter startRequest(byte tdsMessageType) throws SQLServerException {
*
* @return the TDS reader used to read the response.
* @throws SQLServerException
- * if there is any kind of error.
+ * if there is any kind of error.
*/
final TDSReader startResponse() throws SQLServerException {
return startResponse(false);
@@ -7747,8 +7600,7 @@ final TDSReader startResponse(boolean isAdaptive) throws SQLServerException {
try {
tdsWriter.endMessage();
- }
- catch (SQLServerException e) {
+ } catch (SQLServerException e) {
if (logger.isLoggable(Level.FINEST))
logger.finest(this + ": finishing request: endMessage threw exception: " + e.getMessage());
@@ -7773,19 +7625,15 @@ final TDSReader startResponse(boolean isAdaptive) throws SQLServerException {
// of the response.
if (isAdaptive) {
tdsReader.readPacket();
+ } else {
+ while (tdsReader.readPacket());
}
- else {
- while (tdsReader.readPacket())
- ;
- }
- }
- catch (SQLServerException e) {
+ } catch (SQLServerException e) {
if (logger.isLoggable(Level.FINEST))
logger.finest(this.toString() + ": Exception reading response: " + e.getMessage());
throw e;
- }
- finally {
+ } finally {
// If command execution was subject to timeout then stop timing as soon
// as the server returns the first response packet or errors out.
if (null != timeoutTimer) {
@@ -7800,11 +7648,13 @@ final TDSReader startResponse(boolean isAdaptive) throws SQLServerException {
}
}
+
/**
* UninterruptableTDSCommand encapsulates an uninterruptable TDS conversation.
*
- * TDSCommands have interruptability built in. However, some TDSCommands such as DTC commands, connection commands, cursor close and prepared
- * statement handle close shouldn't be interruptable. This class provides a base implementation for such commands.
+ * TDSCommands have interruptability built in. However, some TDSCommands such as DTC commands, connection commands,
+ * cursor close and prepared statement handle close shouldn't be interruptable. This class provides a base
+ * implementation for such commands.
*/
abstract class UninterruptableTDSCommand extends TDSCommand {
UninterruptableTDSCommand(String logContext) {
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerBulkRecord.java b/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerBulkRecord.java
index 0bf41d944..1f347cac9 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerBulkRecord.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerBulkRecord.java
@@ -1,84 +1,82 @@
/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc;
import java.time.format.DateTimeFormatter;
+
/**
- * The ISQLServerBulkRecord interface can be used to create classes that read in data from any source (such as a file) and allow a SQLServerBulkCopy
- * class to write the data to SQL Server tables.
+ * Provides an interface used to create classes that read in data from any source (such as a file) and allows a
+ * SQLServerBulkCopy class to write the data to SQL Server tables.
*
* This interface is implemented by {@link SQLServerBulkCommon} Class
*/
public interface ISQLServerBulkRecord {
/**
- * Get the ordinals for each of the columns represented in this data record.
+ * Returns the ordinals for each of the columns represented in this data record.
*
* @return Set of ordinals for the columns.
*/
public java.util.Set getColumnOrdinals();
/**
- * Get the name of the given column.
+ * Returns the name of the given column.
*
* @param column
- * Column ordinal
+ * Column ordinal
* @return Name of the column
*/
public String getColumnName(int column);
/**
- * Get the JDBC data type of the given column.
+ * Returns the JDBC data type of the given column.
*
* @param column
- * Column ordinal
+ * Column ordinal
* @return JDBC data type of the column
*/
public int getColumnType(int column);
/**
- * Get the precision for the given column.
+ * Returns the precision for the given column.
*
* @param column
- * Column ordinal
+ * Column ordinal
* @return Precision of the column
*/
public int getPrecision(int column);
/**
- * Get the scale for the given column.
+ * Returns the scale for the given column.
*
* @param column
- * Column ordinal
+ * Column ordinal
* @return Scale of the column
*/
public int getScale(int column);
/**
- * Indicates whether the column represents an identity column.
+ * Returns whether the column represents an identity column.
*
* @param column
- * Column ordinal
+ * Column ordinal
* @return True if the column is an identity column; false otherwise.
*/
public boolean isAutoIncrement(int column);
/**
- * Gets the data for the current row as an array of Objects.
+ * Returns the data for the current row as an array of Objects.
*
- * Each Object must match the Java language Type that is used to represent the indicated JDBC data type for the given column. For more
- * information, see 'Understanding the JDBC Driver Data Types' for the appropriate mappings.
+ * Each Object must match the Java language Type that is used to represent the indicated JDBC data type for the
+ * given column. For more information, see 'Understanding the JDBC Driver Data Types' for the appropriate mappings.
*
* @return The data for the row.
* @throws SQLServerException
- * If there are any errors in obtaining the data.
+ * If there are any errors in obtaining the data.
*/
public Object[] getRowData() throws SQLServerException;
@@ -87,7 +85,7 @@ public interface ISQLServerBulkRecord {
*
* @return True if rows are available; false if there are no more rows
* @throws SQLServerException
- * If there are any errors in advancing to the next row.
+ * If there are any errors in advancing to the next row.
*/
public boolean next() throws SQLServerException;
@@ -95,86 +93,79 @@ public interface ISQLServerBulkRecord {
* Adds metadata for the given column in the file.
*
* @param positionInFile
- * Indicates which column the metadata is for. Columns start at 1.
+ * Indicates which column the metadata is for. Columns start at 1.
* @param name
- * Name for the column (optional if only using column ordinal in a mapping for SQLServerBulkCopy operation)
+ * Name for the column (optional if only using column ordinal in a mapping for SQLServerBulkCopy operation)
* @param jdbcType
- * JDBC data type of the column
+ * JDBC data type of the column
* @param precision
- * Precision for the column (ignored for the appropriate data types)
+ * Precision for the column (ignored for the appropriate data types)
* @param scale
- * Scale for the column (ignored for the appropriate data types)
+ * Scale for the column (ignored for the appropriate data types)
* @param dateTimeFormatter
- * format to parse data that is sent
+ * format to parse data that is sent
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void addColumnMetadata(int positionInFile,
- String name,
- int jdbcType,
- int precision,
- int scale,
+ public void addColumnMetadata(int positionInFile, String name, int jdbcType, int precision, int scale,
DateTimeFormatter dateTimeFormatter) throws SQLServerException;
/**
* Adds metadata for the given column in the file.
*
* @param positionInFile
- * Indicates which column the metadata is for. Columns start at 1.
+ * Indicates which column the metadata is for. Columns start at 1.
* @param name
- * Name for the column (optional if only using column ordinal in a mapping for SQLServerBulkCopy operation)
+ * Name for the column (optional if only using column ordinal in a mapping for SQLServerBulkCopy operation)
* @param jdbcType
- * JDBC data type of the column
+ * JDBC data type of the column
* @param precision
- * Precision for the column (ignored for the appropriate data types)
+ * Precision for the column (ignored for the appropriate data types)
* @param scale
- * Scale for the column (ignored for the appropriate data types)
+ * Scale for the column (ignored for the appropriate data types)
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void addColumnMetadata(int positionInFile,
- String name,
- int jdbcType,
- int precision,
+ public void addColumnMetadata(int positionInFile, String name, int jdbcType, int precision,
int scale) throws SQLServerException;
/**
- * Set the format for reading in dates from the file.
+ * Sets the format for reading in dates from the file.
*
* @param dateTimeFormat
- * format to parse data sent as java.sql.Types.TIMESTAMP_WITH_TIMEZONE
+ * format to parse data sent as java.sql.Types.TIMESTAMP_WITH_TIMEZONE
*/
public void setTimestampWithTimezoneFormat(String dateTimeFormat);
/**
- * Set the format for reading in dates from the file.
+ * Sets the format for reading in dates from the file.
*
* @param dateTimeFormatter
- * format to parse data sent as java.sql.Types.TIMESTAMP_WITH_TIMEZONE
+ * format to parse data sent as java.sql.Types.TIMESTAMP_WITH_TIMEZONE
*/
public void setTimestampWithTimezoneFormat(DateTimeFormatter dateTimeFormatter);
/**
- * Set the format for reading in dates from the file.
+ * Sets the format for reading in dates from the file.
*
* @param timeFormat
- * format to parse data sent as java.sql.Types.TIME_WITH_TIMEZONE
+ * format to parse data sent as java.sql.Types.TIME_WITH_TIMEZONE
*/
public void setTimeWithTimezoneFormat(String timeFormat);
/**
- * Set the format for reading in dates from the file.
+ * Sets the format for reading in dates from the file.
*
* @param dateTimeFormatter
- * format to parse data sent as java.sql.Types.TIME_WITH_TIMEZONE
+ * format to parse data sent as java.sql.Types.TIME_WITH_TIMEZONE
*/
public void setTimeWithTimezoneFormat(DateTimeFormatter dateTimeFormatter);
/**
- * Retreives dateTimeFormatter
for the given column
+ * Returns the dateTimeFormatter
for the given column.
*
* @param column
- * Column ordinal
+ * Column ordinal
* @return dateTimeFormatter
*/
public DateTimeFormatter getColumnDateTimeFormatter(int column);
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerCallableStatement.java b/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerCallableStatement.java
index 7be9957b3..da7d75fde 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerCallableStatement.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerCallableStatement.java
@@ -1,9 +1,6 @@
/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc;
@@ -13,365 +10,362 @@
import java.sql.Timestamp;
import java.util.Calendar;
+
/**
- * This interface is implemented by {@link SQLServerCallableStatement} Class.
+ * Provides an interface to the {@link SQLServerCallableStatement} class.
*/
public interface ISQLServerCallableStatement extends java.sql.CallableStatement, ISQLServerPreparedStatement {
@Deprecated
- public BigDecimal getBigDecimal(String parameterName,
- int scale) throws SQLServerException;
+ public BigDecimal getBigDecimal(String parameterName, int scale) throws SQLServerException;
/**
- * Retrieves the value of the designated column in the current row of this ResultSet object as a java.sql.Timestamp object in the Java programming
- * language.
+ * Returns the value of the designated column in the current row of this ResultSet object as a java.sql.Timestamp
+ * object in the Java programming language.
*
* @param index
- * the first column is 1, the second is 2, ...
+ * the first column is 1, the second is 2, ...
* @return the column value; if the value is SQL NULL, the value returned is null
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
public Timestamp getDateTime(int index) throws SQLServerException;
/**
- * Retrieves the value of the designated column in the current row of this ResultSet object as a java.sql.Timestamp object in the Java programming
- * language.
+ * Returns the value of the designated column in the current row of this ResultSet object as a java.sql.Timestamp
+ * object in the Java programming language.
*
* @param parameterName
- * the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the
- * column
+ * the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then
+ * the label is the name of the column
* @return the column value; if the value is SQL NULL, the value returned is null
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
public Timestamp getDateTime(String parameterName) throws SQLServerException;
/**
- * Retrieves the value of the designated column in the current row of this ResultSet object as a java.sql.Timestamp object in the Java programming
- * language. This method uses the given calendar to construct an appropriate millisecond value for the timestamp if the underlying database does
- * not store timezone information.
+ * Returns the value of the designated column in the current row of this ResultSet object as a java.sql.Timestamp
+ * object in the Java programming language. This method uses the given calendar to construct an appropriate
+ * millisecond value for the timestamp if the underlying database does not store timezone information.
*
* @param index
- * the first column is 1, the second is 2, ...
+ * the first column is 1, the second is 2, ...
* @param cal
- * the java.util.Calendar object to use in constructing the dateTime
+ * the java.util.Calendar object to use in constructing the dateTime
* @return the column value; if the value is SQL NULL, the value returned is null
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public Timestamp getDateTime(int index,
- Calendar cal) throws SQLServerException;
+ public Timestamp getDateTime(int index, Calendar cal) throws SQLServerException;
/**
- * Retrieves the value of the designated column in the current row of this ResultSet object as a java.sql.Timestamp object in the Java programming
- * language. This method uses the given calendar to construct an appropriate millisecond value for the timestamp if the underlying database does
- * not store timezone information.
+ * Returns the value of the designated column in the current row of this ResultSet object as a java.sql.Timestamp
+ * object in the Java programming language. This method uses the given calendar to construct an appropriate
+ * millisecond value for the timestamp if the underlying database does not store timezone information.
*
* @param name
- * the name of the column
+ * the name of the column
* @param cal
- * the java.util.Calendar object to use in constructing the dateTime
+ * the java.util.Calendar object to use in constructing the dateTime
* @return the column value; if the value is SQL NULL, the value returned is null
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public Timestamp getDateTime(String name,
- Calendar cal) throws SQLServerException;
+ public Timestamp getDateTime(String name, Calendar cal) throws SQLServerException;
/**
- * Retrieves the value of the designated column in the current row of this ResultSet object as a java.sql.Timestamp object in the Java programming
- * language.
+ * Returns the value of the designated column in the current row of this ResultSet object as a java.sql.Timestamp
+ * object in the Java programming language.
*
* @param index
- * the first column is 1, the second is 2, ...
+ * the first column is 1, the second is 2, ...
* @return the column value; if the value is SQL NULL, the value returned is null
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
public Timestamp getSmallDateTime(int index) throws SQLServerException;
/**
- * Retrieves the value of the designated column in the current row of this ResultSet object as a java.sql.Timestamp object in the Java programming
- * language.
+ * Returns the value of the designated column in the current row of this ResultSet object as a java.sql.Timestamp
+ * object in the Java programming language.
*
* @param parameterName
- * The name of a column.
+ * The name of a column.
* @return the column value; if the value is SQL NULL, the value returned is null
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
public Timestamp getSmallDateTime(String parameterName) throws SQLServerException;
/**
- * Retrieves the value of the designated column in the current row of this ResultSet object as a java.sql.Timestamp object in the Java programming
- * language.
+ * Returns the value of the designated column in the current row of this ResultSet object as a java.sql.Timestamp
+ * object in the Java programming language.
*
* @param index
- * the first column is 1, the second is 2, ...
+ * the first column is 1, the second is 2, ...
* @param cal
- * the java.util.Calendar object to use in constructing the smalldateTime
+ * the java.util.Calendar object to use in constructing the smalldateTime
* @return the column value; if the value is SQL NULL, the value returned is null
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public Timestamp getSmallDateTime(int index,
- Calendar cal) throws SQLServerException;
+ public Timestamp getSmallDateTime(int index, Calendar cal) throws SQLServerException;
/**
- * Retrieves the value of the designated column in the current row of this ResultSet object as a java.sql.Timestamp object in the Java programming
- * language.
+ * Returns the value of the designated column in the current row of this ResultSet object as a java.sql.Timestamp
+ * object in the Java programming language.
*
* @param name
- * The name of a column
+ * The name of a column
* @param cal
- * the java.util.Calendar object to use in constructing the smalldateTime
+ * the java.util.Calendar object to use in constructing the smalldateTime
* @return the column value; if the value is SQL NULL, the value returned is null
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public Timestamp getSmallDateTime(String name,
- Calendar cal) throws SQLServerException;
+ public Timestamp getSmallDateTime(String name, Calendar cal) throws SQLServerException;
/**
- * Gets the DateTimeOffset value of parameter with index parameterIndex
+ * Returns the DateTimeOffset value of parameter with index parameterIndex.
*
* @param parameterIndex
- * the first parameter is 1, the second is 2, and so on
+ * the first parameter is 1, the second is 2, and so on
* @return DateTimeOffset value if the value is SQL NULL, the value returned is null
* @throws SQLServerException
- * if parameterIndex is out of range; if a database access error occurs or this method is called on a closed
- * CallableStatement
+ * if parameterIndex is out of range; if a database access error occurs or this method is called on a closed
+ * CallableStatement
*/
public microsoft.sql.DateTimeOffset getDateTimeOffset(int parameterIndex) throws SQLServerException;
/**
- * Gets the DateTimeOffset value of parameter with name parameterName
+ * Returns the DateTimeOffset value of parameter with name parameterName.
*
* @param parameterName
- * the name of the parameter
+ * the name of the parameter
* @return DateTimeOffset value if the value is SQL NULL, the value returned is null
* @throws SQLServerException
- * if parameterName does not correspond to a named parameter; if a database access error occurs or this method is called on a closed
- * CallableStatement
+ * if parameterName does not correspond to a named parameter; if a database access error occurs or this
+ * method is called on a closed CallableStatement
*/
public microsoft.sql.DateTimeOffset getDateTimeOffset(String parameterName) throws SQLServerException;
/**
- * Retrieves the value of the designated column in the current row of this ResultSet
object as a stream of ASCII characters. The
- * value can then be read in chunks from the stream. This method is particularly suitable for retrieving large LONGVARCHAR
values.
- * The JDBC driver will do any necessary conversion from the database format into ASCII.
+ * Returns the value of the designated column in the current row of this ResultSet
object as a stream
+ * of ASCII characters. The value can then be read in chunks from the stream. This method is particularly suitable
+ * for retrieving large LONGVARCHAR
values. The JDBC driver will do any necessary conversion from the
+ * database format into ASCII.
*
*
- * Note: All the data in the returned stream must be read prior to getting the value of any other column. The next call to a getter method
- * implicitly closes the stream. Also, a stream may return 0
when the method InputStream.available
is called whether
- * there is data available or not.
+ * Note: All the data in the returned stream must be read prior to getting the value of any other column. The
+ * next call to a getter method implicitly closes the stream. Also, a stream may return 0
when the
+ * method InputStream.available
is called whether there is data available or not.
*
* @param parameterIndex
- * the first column is 1, the second is 2, ...
- * @return a Java input stream that delivers the database column value as a stream of one-byte ASCII characters; if the value is SQL
- * NULL
, the value returned is null
+ * the first column is 1, the second is 2, ...
+ * @return a Java input stream that delivers the database column value as a stream of one-byte ASCII characters; if
+ * the value is SQL NULL
, the value returned is null
* @throws SQLServerException
- * if the columnIndex is not valid; if a database access error occurs or this method is called on a closed result set
+ * if the columnIndex is not valid; if a database access error occurs or this method is called on a closed
+ * result set
*/
public java.io.InputStream getAsciiStream(int parameterIndex) throws SQLServerException;
/**
- * Retrieves the value of the designated column in the current row of this ResultSet
object as a stream of ASCII characters. The
- * value can then be read in chunks from the stream. This method is particularly suitable for retrieving large LONGVARCHAR
values.
- * The JDBC driver will do any necessary conversion from the database format into ASCII.
+ * Returns the value of the designated column in the current row of this ResultSet
object as a stream
+ * of ASCII characters. The value can then be read in chunks from the stream. This method is particularly suitable
+ * for retrieving large LONGVARCHAR
values. The JDBC driver will do any necessary conversion from the
+ * database format into ASCII.
*
*
- * Note: All the data in the returned stream must be read prior to getting the value of any other column. The next call to a getter method
- * implicitly closes the stream. Also, a stream may return 0
when the method available
is called whether there is data
- * available or not.
+ * Note: All the data in the returned stream must be read prior to getting the value of any other column. The
+ * next call to a getter method implicitly closes the stream. Also, a stream may return 0
when the
+ * method available
is called whether there is data available or not.
*
* @param parameterName
- * the name of the parameter
- * @return a Java input stream that delivers the database column value as a stream of one-byte ASCII characters. If the value is SQL
- * NULL
, the value returned is null
.
+ * the name of the parameter
+ * @return a Java input stream that delivers the database column value as a stream of one-byte ASCII characters. If
+ * the value is SQL NULL
, the value returned is null
.
* @throws SQLServerException
- * if the columnLabel is not valid; if a database access error occurs or this method is called on a closed result set
+ * if the columnLabel is not valid; if a database access error occurs or this method is called on a closed
+ * result set
*/
public java.io.InputStream getAsciiStream(String parameterName) throws SQLServerException;
/**
- * Retrieves the value of the column specified as a java.math.BigDecimal object.
+ * Returns the value of the column specified as a java.math.BigDecimal object.
*
* @param parameterIndex
- * The zero-based ordinal of a column.
+ * The zero-based ordinal of a column.
* @return the column value; if the value is SQL NULL, the value returned is null
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
public BigDecimal getMoney(int parameterIndex) throws SQLServerException;
/**
- * Retrieves the value of the column specified as a java.math.BigDecimal object.
+ * Returns the value of the column specified as a java.math.BigDecimal object.
*
* @param parameterName
- * The name of a column.
+ * The name of a column.
* @return the column value; if the value is SQL NULL, the value returned is null.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
public BigDecimal getMoney(String parameterName) throws SQLServerException;
/**
- * Retrieves the value of the column specified as a java.math.BigDecimal object.
+ * Returns the value of the column specified as a java.math.BigDecimal object.
*
* @param parameterIndex
- * The zero-based ordinal of a column.
+ * The zero-based ordinal of a column.
* @return the column value; if the value is SQL NULL, the value returned is null
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
public BigDecimal getSmallMoney(int parameterIndex) throws SQLServerException;
/**
- * Retrieves the value of the column specified as a java.math.BigDecimal object.
+ * Returns the value of the column specified as a java.math.BigDecimal object.
*
* @param parameterName
- * The name of a column.
+ * The name of a column.
* @return the column value; if the value is SQL NULL, the value returned is null.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
public BigDecimal getSmallMoney(String parameterName) throws SQLServerException;
/**
- * Retrieves the value of the designated column in the current row of this ResultSet
object as a stream of uninterpreted bytes. The
- * value can then be read in chunks from the stream. This method is particularly suitable for retrieving large LONGVARBINARY
values.
+ * Returns the value of the designated column in the current row of this ResultSet
object as a stream
+ * of uninterpreted bytes. The value can then be read in chunks from the stream. This method is particularly
+ * suitable for retrieving large LONGVARBINARY
values.
*
*
- * Note: All the data in the returned stream must be read prior to getting the value of any other column. The next call to a getter method
- * implicitly closes the stream. Also, a stream may return 0
when the method InputStream.available
is called whether
- * there is data available or not.
+ * Note: All the data in the returned stream must be read prior to getting the value of any other column. The
+ * next call to a getter method implicitly closes the stream. Also, a stream may return 0
when the
+ * method InputStream.available
is called whether there is data available or not.
*
* @param parameterIndex
- * the first column is 1, the second is 2, ...
- * @return a Java input stream that delivers the database column value as a stream of uninterpreted bytes; if the value is SQL NULL
,
- * the value returned is null
+ * the first column is 1, the second is 2, ...
+ * @return a Java input stream that delivers the database column value as a stream of uninterpreted bytes; if the
+ * value is SQL NULL
, the value returned is null
* @throws SQLServerException
- * if the columnIndex is not valid; if a database access error occurs or this method is called on a closed result set
+ * if the columnIndex is not valid; if a database access error occurs or this method is called on a closed
+ * result set
*/
public java.io.InputStream getBinaryStream(int parameterIndex) throws SQLServerException;
/**
- * Retrieves the value of the designated column in the current row of this ResultSet
object as a stream of uninterpreted
- * byte
s. The value can then be read in chunks from the stream. This method is particularly suitable for retrieving large
- * LONGVARBINARY
values.
+ * Returns the value of the designated column in the current row of this ResultSet
object as a stream
+ * of uninterpreted byte
s. The value can then be read in chunks from the stream. This method is
+ * particularly suitable for retrieving large LONGVARBINARY
values.
*
*
- * Note: All the data in the returned stream must be read prior to getting the value of any other column. The next call to a getter method
- * implicitly closes the stream. Also, a stream may return 0
when the method available
is called whether there is data
- * available or not.
+ * Note: All the data in the returned stream must be read prior to getting the value of any other column. The
+ * next call to a getter method implicitly closes the stream. Also, a stream may return 0
when the
+ * method available
is called whether there is data available or not.
*
* @param parameterName
- * the name of the parameter
- * @return a Java input stream that delivers the database column value as a stream of uninterpreted bytes; if the value is SQL NULL
,
- * the result is null
+ * the name of the parameter
+ * @return a Java input stream that delivers the database column value as a stream of uninterpreted bytes; if the
+ * value is SQL NULL
, the result is null
* @throws SQLServerException
- * if the columnLabel is not valid; if a database access error occurs or this method is called on a closed result set
+ * if the columnLabel is not valid; if a database access error occurs or this method is called on a closed
+ * result set
*/
public java.io.InputStream getBinaryStream(String parameterName) throws SQLServerException;
/**
- * Sets the designated parameter to the given java.sql.Timestamp
value. The driver converts this to an SQL TIMESTAMP
- * value when it sends it to the database.
+ * Sets the designated parameter to the given java.sql.Timestamp
value. The driver converts this to an
+ * SQL TIMESTAMP
value when it sends it to the database.
*
* @param parameterName
- * the name of the parameter
+ * the name of the parameter
* @param value
- * the parameter value
+ * the parameter value
* @param calendar
- * a java.util.Calendar
+ * a java.util.Calendar
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * if parameterName does not correspond to a named parameter; if a database access error occurs or this method is called on a closed
- * CallableStatement
+ * if parameterName does not correspond to a named parameter; if a database access error occurs or this
+ * method is called on a closed CallableStatement
* @see #getTimestamp
*/
- public void setTimestamp(String parameterName,
- java.sql.Timestamp value,
- Calendar calendar,
+ public void setTimestamp(String parameterName, java.sql.Timestamp value, Calendar calendar,
boolean forceEncrypt) throws SQLServerException;
/**
- * Sets the designated parameter to the given java.sql.Time
value, using the given Calendar
object. The driver uses the
- * Calendar
object to construct an SQL TIME
value, which the driver then sends to the database. With a a
- * Calendar
object, the driver can calculate the time taking into account a custom timezone. If no Calendar
object is
+ * Sets the designated parameter to the given java.sql.Time
value, using the given
+ * Calendar
object. The driver uses the Calendar
object to construct an SQL
+ * TIME
value, which the driver then sends to the database. With a a Calendar
object, the
+ * driver can calculate the time taking into account a custom timezone. If no Calendar
object is
* specified, the driver uses the default timezone, which is that of the virtual machine running the application.
*
* @param parameterName
- * the name of the parameter
+ * the name of the parameter
* @param value
- * the parameter value
+ * the parameter value
* @param calendar
- * the Calendar
object the driver will use to construct the time
+ * the Calendar
object the driver will use to construct the time
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * if parameterName does not correspond to a named parameter; if a database access error occurs or this method is called on a closed
- * CallableStatement
+ * if parameterName does not correspond to a named parameter; if a database access error occurs or this
+ * method is called on a closed CallableStatement
* @see #getTime
*/
- public void setTime(String parameterName,
- java.sql.Time value,
- Calendar calendar,
+ public void setTime(String parameterName, java.sql.Time value, Calendar calendar,
boolean forceEncrypt) throws SQLServerException;
/**
- * Sets the designated parameter to the given java.sql.Date
value, using the given Calendar
object. The driver uses the
- * Calendar
object to construct an SQL DATE
value, which the driver then sends to the database. With a a
- * Calendar
object, the driver can calculate the date taking into account a custom timezone. If no Calendar
object is
+ * Sets the designated parameter to the given java.sql.Date
value, using the given
+ * Calendar
object. The driver uses the Calendar
object to construct an SQL
+ * DATE
value, which the driver then sends to the database. With a a Calendar
object, the
+ * driver can calculate the date taking into account a custom timezone. If no Calendar
object is
* specified, the driver uses the default timezone, which is that of the virtual machine running the application.
*
* @param parameterName
- * the name of the parameter
+ * the name of the parameter
* @param value
- * the parameter value
+ * the parameter value
* @param calendar
- * the Calendar
object the driver will use to construct the date
+ * the Calendar
object the driver will use to construct the date
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * if parameterName does not correspond to a named parameter; if a database access error occurs or this method is called on a closed
- * CallableStatement
+ * if parameterName does not correspond to a named parameter; if a database access error occurs or this
+ * method is called on a closed CallableStatement
* @see #getDate
*/
- public void setDate(String parameterName,
- java.sql.Date value,
- Calendar calendar,
+ public void setDate(String parameterName, java.sql.Date value, Calendar calendar,
boolean forceEncrypt) throws SQLServerException;
/**
- * Sets the designated parameter to the given String
object. The driver converts this to a SQL NCHAR
or
- * NVARCHAR
or LONGNVARCHAR
+ * Sets the designated parameter to the given String
object. The driver converts this to a SQL
+ * NCHAR
or NVARCHAR
or LONGNVARCHAR
*
* @param parameterName
- * the name of the parameter to be set
+ * the name of the parameter to be set
* @param value
- * the parameter value
+ * the parameter value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * if parameterName does not correspond to a named parameter; if the driver does not support national character sets; if the driver
- * can detect that a data conversion error could occur; if a database access error occurs or this method is called on a closed
- * CallableStatement
+ * if parameterName does not correspond to a named parameter; if the driver does not support national
+ * character sets; if the driver can detect that a data conversion error could occur; if a database access
+ * error occurs or this method is called on a closed CallableStatement
*/
- public void setNString(String parameterName,
- String value,
- boolean forceEncrypt) throws SQLServerException;
+ public void setNString(String parameterName, String value, boolean forceEncrypt) throws SQLServerException;
/**
* Sets the value of the designated parameter with the given object.
@@ -379,36 +373,35 @@ public void setNString(String parameterName,
*
* The given Java object will be converted to the given targetSqlType before being sent to the database.
*
- * If the object has a custom mapping (is of a class implementing the interface SQLData
), the JDBC driver should call the method
- * SQLData.writeSQL
to write it to the SQL data stream. If, on the other hand, the object is of a class implementing
- * Ref
, Blob
, Clob
, NClob
, Struct
, java.net.URL
, or
- * Array
, the driver should pass it to the database as a value of the corresponding SQL type.
+ * If the object has a custom mapping (is of a class implementing the interface SQLData
), the JDBC
+ * driver should call the method SQLData.writeSQL
to write it to the SQL data stream. If, on the other
+ * hand, the object is of a class implementing Ref
, Blob
, Clob
,
+ * NClob
, Struct
, java.net.URL
, or Array
, the driver should pass
+ * it to the database as a value of the corresponding SQL type.
*
* Note that this method may be used to pass database- specific abstract data types.
*
* @param parameterName
- * the name of the parameter
+ * the name of the parameter
* @param value
- * the object containing the input parameter value
+ * the object containing the input parameter value
* @param sqlType
- * the SQL type (as defined in java.sql.Types) to be sent to the database. The scale argument may further qualify this type.
+ * the SQL type (as defined in java.sql.Types) to be sent to the database. The scale argument may further
+ * qualify this type.
* @param decimals
- * for java.sql.Types.DECIMAL or java.sql.Types.NUMERIC types, this is the number of digits after the decimal point. For all other
- * types, this value will be ignored.
+ * for java.sql.Types.DECIMAL or java.sql.Types.NUMERIC types, this is the number of digits after the decimal
+ * point. For all other types, this value will be ignored.
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * if parameterName does not correspond to a named parameter; if a database access error occurs or this method is called on a closed
- * CallableStatement
+ * if parameterName does not correspond to a named parameter; if a database access error occurs or this
+ * method is called on a closed CallableStatement
* @see java.sql.Types
* @see #getObject
*/
- public void setObject(String parameterName,
- Object value,
- int sqlType,
- int decimals,
+ public void setObject(String parameterName, Object value, int sqlType, int decimals,
boolean forceEncrypt) throws SQLServerException;
/**
@@ -417,714 +410,658 @@ public void setObject(String parameterName,
*
* The given Java object will be converted to the given targetSqlType before being sent to the database.
*
- * If the object has a custom mapping (is of a class implementing the interface SQLData
), the JDBC driver should call the method
- * SQLData.writeSQL
to write it to the SQL data stream. If, on the other hand, the object is of a class implementing
- * Ref
, Blob
, Clob
, NClob
, Struct
, java.net.URL
, or
- * Array
, the driver should pass it to the database as a value of the corresponding SQL type.
+ * If the object has a custom mapping (is of a class implementing the interface SQLData
), the JDBC
+ * driver should call the method SQLData.writeSQL
to write it to the SQL data stream. If, on the other
+ * hand, the object is of a class implementing Ref
, Blob
, Clob
,
+ * NClob
, Struct
, java.net.URL
, or Array
, the driver should pass
+ * it to the database as a value of the corresponding SQL type.
*
* Note that this method may be used to pass datatabase- specific abstract data types.
*
* @param parameterName
- * the name of the parameter
+ * the name of the parameter
* @param value
- * the object containing the input parameter value
+ * the object containing the input parameter value
* @param targetSqlType
- * the SQL type (as defined in java.sql.Types) to be sent to the database. The scale argument may further qualify this type.
+ * the SQL type (as defined in java.sql.Types) to be sent to the database. The scale argument may further
+ * qualify this type.
* @param precision
- * the precision of the column.
+ * the precision of the column.
* @param scale
- * the scale of the column.
+ * the scale of the column.
* @throws SQLServerException
- * if parameterName does not correspond to a named parameter; if a database access error occurs or this method is called on a closed
- * CallableStatement
+ * if parameterName does not correspond to a named parameter; if a database access error occurs or this
+ * method is called on a closed CallableStatement
* @see java.sql.Types
* @see #getObject
*/
- public void setObject(String parameterName,
- Object value,
- int targetSqlType,
- Integer precision,
+ public void setObject(String parameterName, Object value, int targetSqlType, Integer precision,
int scale) throws SQLServerException;
/**
- * Sets the designated parameter to the given java.sql.Timestamp
value. The driver converts this to an SQL TIMESTAMP
- * value when it sends it to the database.
+ * Sets the designated parameter to the given java.sql.Timestamp
value. The driver converts this to an
+ * SQL TIMESTAMP
value when it sends it to the database.
*
* @param parameterName
- * the name of the parameter
+ * the name of the parameter
* @param value
- * the parameter value
+ * the parameter value
* @param scale
- * the scale of the parameter
+ * the scale of the parameter
* @throws SQLServerException
- * if parameterName does not correspond to a named parameter; if a database access error occurs or this method is called on a closed
- * CallableStatement
+ * if parameterName does not correspond to a named parameter; if a database access error occurs or this
+ * method is called on a closed CallableStatement
* @see #getTimestamp
*/
- public void setTimestamp(String parameterName,
- java.sql.Timestamp value,
- int scale) throws SQLServerException;
+ public void setTimestamp(String parameterName, java.sql.Timestamp value, int scale) throws SQLServerException;
/**
- * Sets the designated parameter to the given java.sql.Timestamp
value. The driver converts this to an SQL TIMESTAMP
- * value when it sends it to the database.
+ * Sets the designated parameter to the given java.sql.Timestamp
value. The driver converts this to an
+ * SQL TIMESTAMP
value when it sends it to the database.
*
* @param parameterName
- * the name of the parameter
+ * the name of the parameter
* @param value
- * the parameter value
+ * the parameter value
* @param scale
- * the scale of the parameter
+ * the scale of the parameter
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * if parameterName does not correspond to a named parameter; if a database access error occurs or this method is called on a closed
- * CallableStatement
+ * if parameterName does not correspond to a named parameter; if a database access error occurs or this
+ * method is called on a closed CallableStatement
* @see #getTimestamp
*/
- public void setTimestamp(String parameterName,
- java.sql.Timestamp value,
- int scale,
+ public void setTimestamp(String parameterName, java.sql.Timestamp value, int scale,
boolean forceEncrypt) throws SQLServerException;
/**
- * Sets parameter parameterName to DateTimeOffset x
+ * Sets parameter parameterName to DateTimeOffset value.
*
* @param parameterName
- * the name of the parameter
+ * the name of the parameter
* @param value
- * DateTimeOffset value
+ * DateTimeOffset value
* @throws SQLServerException
- * if an error occurs
+ * if an error occurs
*/
- public void setDateTimeOffset(String parameterName,
- microsoft.sql.DateTimeOffset value) throws SQLServerException;
+ public void setDateTimeOffset(String parameterName, microsoft.sql.DateTimeOffset value) throws SQLServerException;
/**
- * Sets parameter parameterName to DateTimeOffset x
+ * Sets parameter parameterName to DateTimeOffset value.
*
* @param parameterName
- * the name of the parameter
+ * the name of the parameter
* @param value
- * DateTimeOffset value
+ * DateTimeOffset value
* @param scale
- * the scale of the parameter
+ * the scale of the parameter
* @throws SQLServerException
- * if an error occurs
+ * if an error occurs
*/
- public void setDateTimeOffset(String parameterName,
- microsoft.sql.DateTimeOffset value,
+ public void setDateTimeOffset(String parameterName, microsoft.sql.DateTimeOffset value,
int scale) throws SQLServerException;
/**
- * Sets parameter parameterName to DateTimeOffset x
+ * Sets parameter parameterName to DateTimeOffset value.
*
* @param parameterName
- * the name of the parameter
+ * the name of the parameter
* @param value
- * DateTimeOffset value
+ * DateTimeOffset value
* @param scale
- * the scale of the parameter
+ * the scale of the parameter
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * if an error occurs
+ * if an error occurs
*/
- public void setDateTimeOffset(String parameterName,
- microsoft.sql.DateTimeOffset value,
- int scale,
+ public void setDateTimeOffset(String parameterName, microsoft.sql.DateTimeOffset value, int scale,
boolean forceEncrypt) throws SQLServerException;
/**
- * Sets the designated parameter to the given java.sql.Time
value. The driver converts this to an SQL TIME
value when it
- * sends it to the database.
+ * Sets the designated parameter to the given java.sql.Time
value. The driver converts this to an SQL
+ * TIME
value when it sends it to the database.
*
* @param parameterName
- * the name of the parameter
+ * the name of the parameter
* @param value
- * the parameter value
+ * the parameter value
* @param scale
- * the scale of the column
+ * the scale of the column
* @throws SQLServerException
- * if parameterName does not correspond to a named parameter; if a database access error occurs or this method is called on a closed
- * CallableStatement
+ * if parameterName does not correspond to a named parameter; if a database access error occurs or this
+ * method is called on a closed CallableStatement
* @see #getTime
*/
- public void setTime(String parameterName,
- java.sql.Time value,
- int scale) throws SQLServerException;
+ public void setTime(String parameterName, java.sql.Time value, int scale) throws SQLServerException;
/**
- * Sets the designated parameter to the given java.sql.Time
value. The driver converts this to an SQL TIME
value when it
- * sends it to the database.
+ * Sets the designated parameter to the given java.sql.Time
value. The driver converts this to an SQL
+ * TIME
value when it sends it to the database.
*
* @param parameterName
- * the name of the parameter
+ * the name of the parameter
* @param value
- * the parameter value
+ * the parameter value
* @param scale
- * the scale of the column
+ * the scale of the column
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * if parameterName does not correspond to a named parameter; if a database access error occurs or this method is called on a closed
- * CallableStatement
+ * if parameterName does not correspond to a named parameter; if a database access error occurs or this
+ * method is called on a closed CallableStatement
* @see #getTime
*/
- public void setTime(String parameterName,
- java.sql.Time value,
- int scale,
+ public void setTime(String parameterName, java.sql.Time value, int scale,
boolean forceEncrypt) throws SQLServerException;
/**
- * Sets the designated parameter to the given java.sql.Timestamp
value. The driver converts this to an SQL DATETIME
- * value when it sends it to the database.
+ * Sets the designated parameter to the given java.sql.Timestamp
value. The driver converts this to an
+ * SQL DATETIME
value when it sends it to the database.
*
* @param parameterName
- * the name of the parameter
+ * the name of the parameter
* @param value
- * the parameter value
+ * the parameter value
* @throws SQLServerException
- * if parameterName does not correspond to a named parameter; if a database access error occurs or this method is called on a closed
- * CallableStatement
+ * if parameterName does not correspond to a named parameter; if a database access error occurs or this
+ * method is called on a closed CallableStatement
*/
- public void setDateTime(String parameterName,
- java.sql.Timestamp value) throws SQLServerException;
+ public void setDateTime(String parameterName, java.sql.Timestamp value) throws SQLServerException;
/**
- * Sets the designated parameter to the given java.sql.Timestamp
value. The driver converts this to an SQL DATETIME
- * value when it sends it to the database.
+ * Sets the designated parameter to the given java.sql.Timestamp
value. The driver converts this to an
+ * SQL DATETIME
value when it sends it to the database.
*
* @param parameterName
- * the name of the parameter
+ * the name of the parameter
* @param value
- * the parameter value
+ * the parameter value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * if parameterName does not correspond to a named parameter; if a database access error occurs or this method is called on a closed
- * CallableStatement
+ * if parameterName does not correspond to a named parameter; if a database access error occurs or this
+ * method is called on a closed CallableStatement
*/
- public void setDateTime(String parameterName,
- java.sql.Timestamp value,
+ public void setDateTime(String parameterName, java.sql.Timestamp value,
boolean forceEncrypt) throws SQLServerException;
/**
- * Sets the designated parameter to the given java.sql.Timestamp
value. The driver converts this to an SQL SMALLDATETIME
- * value when it sends it to the database.
+ * Sets the designated parameter to the given java.sql.Timestamp
value. The driver converts this to an
+ * SQL SMALLDATETIME
value when it sends it to the database.
*
* @param parameterName
- * the name of the parameter
+ * the name of the parameter
* @param value
- * the parameter value
+ * the parameter value
* @throws SQLServerException
- * if parameterName does not correspond to a named parameter; if a database access error occurs or this method is called on a closed
- * CallableStatement
+ * if parameterName does not correspond to a named parameter; if a database access error occurs or this
+ * method is called on a closed CallableStatement
*/
- public void setSmallDateTime(String parameterName,
- java.sql.Timestamp value) throws SQLServerException;
+ public void setSmallDateTime(String parameterName, java.sql.Timestamp value) throws SQLServerException;
/**
- * Sets the designated parameter to the given java.sql.Timestamp
value. The driver converts this to an SQL SMALLDATETIME
- * value when it sends it to the database.
+ * Sets the designated parameter to the given java.sql.Timestamp
value. The driver converts this to an
+ * SQL SMALLDATETIME
value when it sends it to the database.
*
* @param parameterName
- * the name of the parameter
+ * the name of the parameter
* @param value
- * the parameter value
+ * the parameter value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * if parameterName does not correspond to a named parameter; if a database access error occurs or this method is called on a closed
- * CallableStatement
+ * if parameterName does not correspond to a named parameter; if a database access error occurs or this
+ * method is called on a closed CallableStatement
*/
- public void setSmallDateTime(String parameterName,
- java.sql.Timestamp value,
+ public void setSmallDateTime(String parameterName, java.sql.Timestamp value,
boolean forceEncrypt) throws SQLServerException;
/**
- * Sets the designated parameter to the given String
value. The driver converts this to an SQL uniqueIdentifier
value
- * when it sends it to the database.
+ * Sets the designated parameter to the given String
value. The driver converts this to an SQL
+ * uniqueIdentifier
value when it sends it to the database.
*
* @param parameterName
- * the name of the parameter
+ * the name of the parameter
* @param guid
- * the parameter value
+ * the parameter value
* @throws SQLServerException
- * if parameterName does not correspond to a named parameter; if a database access error occurs or this method is called on a closed
- * CallableStatement
+ * if parameterName does not correspond to a named parameter; if a database access error occurs or this
+ * method is called on a closed CallableStatement
*/
- public void setUniqueIdentifier(String parameterName,
- String guid) throws SQLServerException;
+ public void setUniqueIdentifier(String parameterName, String guid) throws SQLServerException;
/**
- * Sets the designated parameter to the given String
value. The driver converts this to an SQL uniqueIdentifier
value
- * when it sends it to the database.
+ * Sets the designated parameter to the given String
value. The driver converts this to an SQL
+ * uniqueIdentifier
value when it sends it to the database.
*
* @param parameterName
- * the name of the parameter
+ * the name of the parameter
* @param guid
- * the parameter value
+ * the parameter value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * if parameterName does not correspond to a named parameter; if a database access error occurs or this method is called on a closed
- * CallableStatement
+ * if parameterName does not correspond to a named parameter; if a database access error occurs or this
+ * method is called on a closed CallableStatement
*/
- public void setUniqueIdentifier(String parameterName,
- String guid,
- boolean forceEncrypt) throws SQLServerException;
+ public void setUniqueIdentifier(String parameterName, String guid, boolean forceEncrypt) throws SQLServerException;
/**
- * Sets the designated parameter to the given Java array of bytes. The driver converts this to an SQL VARBINARY
or
- * LONGVARBINARY
(depending on the argument's size relative to the driver's limits on VARBINARY
values) when it sends it
- * to the database.
+ * Sets the designated parameter to the given Java array of bytes. The driver converts this to an SQL
+ * VARBINARY
or LONGVARBINARY
(depending on the argument's size relative to the driver's
+ * limits on VARBINARY
values) when it sends it to the database.
*
* @param parameterName
- * the name of the parameter
+ * the name of the parameter
* @param value
- * the parameter value
+ * the parameter value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * if parameterName does not correspond to a named parameter; if a database access error occurs or this method is called on a closed
- * CallableStatement
+ * if parameterName does not correspond to a named parameter; if a database access error occurs or this
+ * method is called on a closed CallableStatement
*/
- public void setBytes(String parameterName,
- byte[] value,
- boolean forceEncrypt) throws SQLServerException;
+ public void setBytes(String parameterName, byte[] value, boolean forceEncrypt) throws SQLServerException;
/**
- * Sets the designated parameter to the given Java byte
value. The driver converts this to an SQL TINYINT
value when it
- * sends it to the database.
+ * Sets the designated parameter to the given Java byte
value. The driver converts this to an SQL
+ * TINYINT
value when it sends it to the database.
*
* @param parameterName
- * the name of the parameter
+ * the name of the parameter
* @param value
- * the parameter value
+ * the parameter value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * if parameterName does not correspond to a named parameter; if a database access error occurs or this method is called on a closed
- * CallableStatement
+ * if parameterName does not correspond to a named parameter; if a database access error occurs or this
+ * method is called on a closed CallableStatement
*/
- public void setByte(String parameterName,
- byte value,
- boolean forceEncrypt) throws SQLServerException;
+ public void setByte(String parameterName, byte value, boolean forceEncrypt) throws SQLServerException;
/**
- * Sets the designated parameter to the given Java String
value. The driver converts this to an SQL VARCHAR
or
- * LONGVARCHAR
value (depending on the argument's size relative to the driver's limits on VARCHAR
values) when it sends
- * it to the database.
+ * Sets the designated parameter to the given Java String
value. The driver converts this to an SQL
+ * VARCHAR
or LONGVARCHAR
value (depending on the argument's size relative to the driver's
+ * limits on VARCHAR
values) when it sends it to the database.
*
* @param parameterName
- * the name of the parameter
+ * the name of the parameter
* @param value
- * the parameter value
+ * the parameter value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * if parameterName does not correspond to a named parameter; if a database access error occurs or this method is called on a closed
- * CallableStatement
+ * if parameterName does not correspond to a named parameter; if a database access error occurs or this
+ * method is called on a closed CallableStatement
*/
- public void setString(String parameterName,
- String value,
- boolean forceEncrypt) throws SQLServerException;
+ public void setString(String parameterName, String value, boolean forceEncrypt) throws SQLServerException;
/**
- * Sets the designated parameter to the given Java java.math.BigDecimal
value. The driver converts this to an SQL Money
- * value.
+ * Sets the designated parameter to the given Java java.math.BigDecimal
value. The driver converts this
+ * to an SQL Money
value.
*
* @param parameterName
- * the name of the parameter
+ * the name of the parameter
* @param value
- * the parameter value
+ * the parameter value
* @throws SQLServerException
- * if parameterName does not correspond to a named parameter; if a database access error occurs or this method is called on a closed
- * CallableStatement
+ * if parameterName does not correspond to a named parameter; if a database access error occurs or this
+ * method is called on a closed CallableStatement
*/
- public void setMoney(String parameterName,
- BigDecimal value) throws SQLServerException;
+ public void setMoney(String parameterName, BigDecimal value) throws SQLServerException;
/**
- * Sets the designated parameter to the given Java java.math.BigDecimal
value. The driver converts this to an SQL Money
- * value.
+ * Sets the designated parameter to the given Java java.math.BigDecimal
value. The driver converts this
+ * to an SQL Money
value.
*
* @param parameterName
- * the name of the parameter
+ * the name of the parameter
* @param value
- * the parameter value
+ * the parameter value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * if parameterName does not correspond to a named parameter; if a database access error occurs or this method is called on a closed
- * CallableStatement
+ * if parameterName does not correspond to a named parameter; if a database access error occurs or this
+ * method is called on a closed CallableStatement
*/
- public void setMoney(String parameterName,
- BigDecimal value,
- boolean forceEncrypt) throws SQLServerException;
+ public void setMoney(String parameterName, BigDecimal value, boolean forceEncrypt) throws SQLServerException;
/**
- * Sets the designated parameter to the given Java java.math.BigDecimal
value. The driver converts this to an SQL
- * smallMoney
value.
+ * Sets the designated parameter to the given Java java.math.BigDecimal
value. The driver converts this
+ * to an SQL smallMoney
value.
*
* @param parameterName
- * the name of the parameter
+ * the name of the parameter
* @param value
- * the parameter value
+ * the parameter value
* @throws SQLServerException
- * if parameterName does not correspond to a named parameter; if a database access error occurs or this method is called on a closed
- * CallableStatement
+ * if parameterName does not correspond to a named parameter; if a database access error occurs or this
+ * method is called on a closed CallableStatement
*/
- public void setSmallMoney(String parameterName,
- BigDecimal value) throws SQLServerException;
+ public void setSmallMoney(String parameterName, BigDecimal value) throws SQLServerException;
/**
- * Sets the designated parameter to the given Java java.math.BigDecimal
value. The driver converts this to an SQL
- * smallMoney
value.
+ * Sets the designated parameter to the given Java java.math.BigDecimal
value. The driver converts this
+ * to an SQL smallMoney
value.
*
* @param parameterName
- * the name of the parameter
+ * the name of the parameter
* @param value
- * the parameter value
+ * the parameter value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * if parameterName does not correspond to a named parameter; if a database access error occurs or this method is called on a closed
- * CallableStatement
+ * if parameterName does not correspond to a named parameter; if a database access error occurs or this
+ * method is called on a closed CallableStatement
*/
- public void setSmallMoney(String parameterName,
- BigDecimal value,
- boolean forceEncrypt) throws SQLServerException;
+ public void setSmallMoney(String parameterName, BigDecimal value, boolean forceEncrypt) throws SQLServerException;
/**
- * Sets the designated parameter to the given java.math.BigDecimal
value. The driver converts this to an SQL NUMERIC
- * value when it sends it to the database.
+ * Sets the designated parameter to the given java.math.BigDecimal
value. The driver converts this to
+ * an SQL NUMERIC
value when it sends it to the database.
*
* @param parameterName
- * the name of the parameter
+ * the name of the parameter
* @param value
- * the parameter value
+ * the parameter value
* @param precision
- * the precision of the column
+ * the precision of the column
* @param scale
- * the scale of the column
+ * the scale of the column
* @throws SQLServerException
- * if parameterName does not correspond to a named parameter; if a database access error occurs or this method is called on a closed
- * CallableStatement
+ * if parameterName does not correspond to a named parameter; if a database access error occurs or this
+ * method is called on a closed CallableStatement
*/
- public void setBigDecimal(String parameterName,
- BigDecimal value,
- int precision,
+ public void setBigDecimal(String parameterName, BigDecimal value, int precision,
int scale) throws SQLServerException;
/**
- * Sets the designated parameter to the given java.math.BigDecimal
value. The driver converts this to an SQL NUMERIC
- * value when it sends it to the database.
+ * Sets the designated parameter to the given java.math.BigDecimal
value. The driver converts this to
+ * an SQL NUMERIC
value when it sends it to the database.
*
* @param parameterName
- * the name of the parameter
+ * the name of the parameter
* @param value
- * the parameter value
+ * the parameter value
* @param precision
- * the precision of the column
+ * the precision of the column
* @param scale
- * the scale of the column
+ * the scale of the column
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * if parameterName does not correspond to a named parameter; if a database access error occurs or this method is called on a closed
- * CallableStatement
+ * if parameterName does not correspond to a named parameter; if a database access error occurs or this
+ * method is called on a closed CallableStatement
*/
- public void setBigDecimal(String parameterName,
- BigDecimal value,
- int precision,
- int scale,
+ public void setBigDecimal(String parameterName, BigDecimal value, int precision, int scale,
boolean forceEncrypt) throws SQLServerException;
/**
- * Sets the designated parameter to the given Java double
value. The driver converts this to an SQL DOUBLE
value when it
- * sends it to the database.
+ * Sets the designated parameter to the given Java double
value. The driver converts this to an SQL
+ * DOUBLE
value when it sends it to the database.
*
* @param parameterName
- * the name of the parameter
+ * the name of the parameter
* @param value
- * the parameter value
+ * the parameter value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * if parameterName does not correspond to a named parameter; if a database access error occurs or this method is called on a closed
- * CallableStatement
+ * if parameterName does not correspond to a named parameter; if a database access error occurs or this
+ * method is called on a closed CallableStatement
*/
- public void setDouble(String parameterName,
- double value,
- boolean forceEncrypt) throws SQLServerException;
+ public void setDouble(String parameterName, double value, boolean forceEncrypt) throws SQLServerException;
/**
- * Sets the designated parameter to the given Java float
value. The driver converts this to an SQL FLOAT
value when it
- * sends it to the database.
+ * Sets the designated parameter to the given Java float
value. The driver converts this to an SQL
+ * FLOAT
value when it sends it to the database.
*
* @param parameterName
- * the name of the parameter
+ * the name of the parameter
* @param value
- * the parameter value
+ * the parameter value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * if parameterName does not correspond to a named parameter; if a database access error occurs or this method is called on a closed
- * CallableStatement
+ * if parameterName does not correspond to a named parameter; if a database access error occurs or this
+ * method is called on a closed CallableStatement
*/
- public void setFloat(String parameterName,
- float value,
- boolean forceEncrypt) throws SQLServerException;
+ public void setFloat(String parameterName, float value, boolean forceEncrypt) throws SQLServerException;
/**
- * Sets the designated parameter to the given Java int
value. The driver converts this to an SQL INTEGER
value when it
- * sends it to the database.
+ * Sets the designated parameter to the given Java int
value. The driver converts this to an SQL
+ * INTEGER
value when it sends it to the database.
*
* @param parameterName
- * the name of the parameter
+ * the name of the parameter
* @param value
- * the parameter value
+ * the parameter value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * if parameterName does not correspond to a named parameter; if a database access error occurs or this method is called on a closed
- * CallableStatement
+ * if parameterName does not correspond to a named parameter; if a database access error occurs or this
+ * method is called on a closed CallableStatement
*/
- public void setInt(String parameterName,
- int value,
- boolean forceEncrypt) throws SQLServerException;
+ public void setInt(String parameterName, int value, boolean forceEncrypt) throws SQLServerException;
/**
- * Sets the designated parameter to the given Java long
value. The driver converts this to an SQL BIGINT
value when it
- * sends it to the database.
+ * Sets the designated parameter to the given Java long
value. The driver converts this to an SQL
+ * BIGINT
value when it sends it to the database.
*
* @param parameterName
- * the name of the parameter
+ * the name of the parameter
* @param value
- * the parameter value
+ * the parameter value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * if parameterName does not correspond to a named parameter; if a database access error occurs or this method is called on a closed
- * CallableStatement
+ * if parameterName does not correspond to a named parameter; if a database access error occurs or this
+ * method is called on a closed CallableStatement
*/
- public void setLong(String parameterName,
- long value,
- boolean forceEncrypt) throws SQLServerException;
+ public void setLong(String parameterName, long value, boolean forceEncrypt) throws SQLServerException;
/**
- * Sets the designated parameter to the given Java short
value. The driver converts this to an SQL SMALLINT
value when
- * it sends it to the database.
+ * Sets the designated parameter to the given Java short
value. The driver converts this to an SQL
+ * SMALLINT
value when it sends it to the database.
*
* @param parameterName
- * the name of the parameter
+ * the name of the parameter
* @param value
- * the parameter value
+ * the parameter value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * if parameterName does not correspond to a named parameter; if a database access error occurs or this method is called on a closed
- * CallableStatement
+ * if parameterName does not correspond to a named parameter; if a database access error occurs or this
+ * method is called on a closed CallableStatement
*/
- public void setShort(String parameterName,
- short value,
- boolean forceEncrypt) throws SQLServerException;
+ public void setShort(String parameterName, short value, boolean forceEncrypt) throws SQLServerException;
/**
- * Sets the designated parameter to the given Java boolean
value. The driver converts this to an SQL BIT
or
- * BOOLEAN
value when it sends it to the database.
+ * Sets the designated parameter to the given Java boolean
value. The driver converts this to an SQL
+ * BIT
or BOOLEAN
value when it sends it to the database.
*
* @param parameterName
- * the name of the parameter
+ * the name of the parameter
* @param value
- * the parameter value
+ * the parameter value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * if parameterName does not correspond to a named parameter; if a database access error occurs or this method is called on a closed
- * CallableStatement
+ * if parameterName does not correspond to a named parameter; if a database access error occurs or this
+ * method is called on a closed CallableStatement
*/
- public void setBoolean(String parameterName,
- boolean value,
- boolean forceEncrypt) throws SQLServerException;
+ public void setBoolean(String parameterName, boolean value, boolean forceEncrypt) throws SQLServerException;
/**
* Populates a table valued parameter passed to a stored procedure with a data table.
*
* @param parameterName
- * the name of the parameter
+ * the name of the parameter
* @param tvpName
- * the name of the type TVP
+ * the name of the type TVP
* @param tvpDataTable
- * the data table object
+ * the data table object
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void setStructured(String parameterName,
- String tvpName,
+ public void setStructured(String parameterName, String tvpName,
SQLServerDataTable tvpDataTable) throws SQLServerException;
/**
* Populates a table valued parameter passed to a stored procedure with a ResultSet retrieved from another table
*
* @param parameterName
- * the name of the parameter
+ * the name of the parameter
* @param tvpName
- * the name of the type TVP
+ * the name of the type TVP
* @param tvpResultSet
- * the source result set object
+ * the source result set object
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void setStructured(String parameterName,
- String tvpName,
+ public void setStructured(String parameterName, String tvpName,
java.sql.ResultSet tvpResultSet) throws SQLServerException;
/**
* Populates a table valued parameter passed to a stored procedure with an ISQLServerDataRecord object.
*
* @param parameterName
- * the name of the parameter
+ * the name of the parameter
* @param tvpName
- * the name of the type TVP
+ * the name of the type TVP
* @param tvpDataRecord
- * ISQLServerDataRecord is used for streaming data and the user decides how to use it. tvpDataRecord is an ISQLServerDataRecord
- * object.the source result set object
+ * ISQLServerDataRecord is used for streaming data and the user decides how to use it. tvpDataRecord is an
+ * ISQLServerDataRecord object.the source result set object
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void setStructured(String parameterName,
- String tvpName,
+ public void setStructured(String parameterName, String tvpName,
ISQLServerDataRecord tvpDataRecord) throws SQLServerException;
/**
- * Registers the parameter in ordinal position index to be of JDBC type sqlType. All OUT parameters must be registered before a stored procedure
- * is executed.
+ * Registers the parameter in ordinal position index to be of JDBC type sqlType. All OUT parameters must be
+ * registered before a stored procedure is executed.
*
- * The JDBC type specified by sqlType for an OUT parameter determines the Java type that must be used in the get method to read the value of that
- * parameter.
+ * The JDBC type specified by sqlType for an OUT parameter determines the Java type that must be used in the get
+ * method to read the value of that parameter.
*
* @param parameterName
- * the name of the parameter
+ * the name of the parameter
* @param sqlType
- * the JDBC type code defined by SQLType to use to register the OUT Parameter.
+ * the JDBC type code defined by SQLType to use to register the OUT Parameter.
* @param precision
- * the sum of the desired number of digits to the left and right of the decimal point. It must be greater than or equal to zero.
+ * the sum of the desired number of digits to the left and right of the decimal point. It must be greater
+ * than or equal to zero.
* @param scale
- * the desired number of digits to the right of the decimal point. It must be greater than or equal to zero.
+ * the desired number of digits to the right of the decimal point. It must be greater than or equal to zero.
* @throws SQLServerException
- * If any errors occur.
+ * If any errors occur.
*/
- public void registerOutParameter(String parameterName,
- SQLType sqlType,
- int precision,
+ public void registerOutParameter(String parameterName, SQLType sqlType, int precision,
int scale) throws SQLServerException;
/**
- * Registers the parameter in ordinal position index to be of JDBC type sqlType. All OUT parameters must be registered before a stored procedure
- * is executed.
+ * Registers the parameter in ordinal position index to be of JDBC type sqlType. All OUT parameters must be
+ * registered before a stored procedure is executed.
*
- * The JDBC type specified by sqlType for an OUT parameter determines the Java type that must be used in the get method to read the value of that
- * parameter.
+ * The JDBC type specified by sqlType for an OUT parameter determines the Java type that must be used in the get
+ * method to read the value of that parameter.
*
* @param parameterIndex
- * the first column is 1, the second is 2, ...
+ * the first column is 1, the second is 2, ...
* @param sqlType
- * the JDBC type code defined by SQLType to use to register the OUT Parameter.
+ * the JDBC type code defined by SQLType to use to register the OUT Parameter.
* @param precision
- * the sum of the desired number of digits to the left and right of the decimal point. It must be greater than or equal to zero.
+ * the sum of the desired number of digits to the left and right of the decimal point. It must be greater
+ * than or equal to zero.
* @param scale
- * the desired number of digits to the right of the decimal point. It must be greater than or equal to zero.
+ * the desired number of digits to the right of the decimal point. It must be greater than or equal to zero.
* @throws SQLServerException
- * If any errors occur.
+ * If any errors occur.
*/
- public void registerOutParameter(int parameterIndex,
- SQLType sqlType,
- int precision,
+ public void registerOutParameter(int parameterIndex, SQLType sqlType, int precision,
int scale) throws SQLServerException;
/**
- * Registers the parameter in ordinal position index to be of JDBC type sqlType. All OUT parameters must be registered before a stored procedure
- * is executed.
+ * Registers the parameter in ordinal position index to be of JDBC type sqlType. All OUT parameters must be
+ * registered before a stored procedure is executed.
*
- * The JDBC type specified by sqlType for an OUT parameter determines the Java type that must be used in the get method to read the value of that
- * parameter.
+ * The JDBC type specified by sqlType for an OUT parameter determines the Java type that must be used in the get
+ * method to read the value of that parameter.
*
* @param parameterIndex
- * the first column is 1, the second is 2, ...
+ * the first column is 1, the second is 2, ...
* @param sqlType
- * the JDBC type code defined by SQLType to use to register the OUT Parameter.
+ * the JDBC type code defined by SQLType to use to register the OUT Parameter.
* @param precision
- * the sum of the desired number of digits to the left and right of the decimal point. It must be greater than or equal to zero.
+ * the sum of the desired number of digits to the left and right of the decimal point. It must be greater
+ * than or equal to zero.
* @param scale
- * the desired number of digits to the right of the decimal point. It must be greater than or equal to zero.
+ * the desired number of digits to the right of the decimal point. It must be greater than or equal to zero.
* @throws SQLServerException
- * If any errors occur.
+ * If any errors occur.
*/
- public void registerOutParameter(int parameterIndex,
- int sqlType,
- int precision,
+ public void registerOutParameter(int parameterIndex, int sqlType, int precision,
int scale) throws SQLServerException;
/**
- * Registers the parameter in ordinal position index to be of JDBC type sqlType. All OUT parameters must be registered before a stored procedure
- * is executed.
+ * Registers the parameter in ordinal position index to be of JDBC type sqlType. All OUT parameters must be
+ * registered before a stored procedure is executed.
*
- * The JDBC type specified by sqlType for an OUT parameter determines the Java type that must be used in the get method to read the value of that
- * parameter.
+ * The JDBC type specified by sqlType for an OUT parameter determines the Java type that must be used in the get
+ * method to read the value of that parameter.
*
* @param parameterName
- * the name of the parameter
+ * the name of the parameter
* @param sqlType
- * the JDBC type code defined by SQLType to use to register the OUT Parameter.
+ * the JDBC type code defined by SQLType to use to register the OUT Parameter.
* @param precision
- * the sum of the desired number of digits to the left and right of the decimal point. It must be greater than or equal to zero.
+ * the sum of the desired number of digits to the left and right of the decimal point. It must be greater
+ * than or equal to zero.
* @param scale
- * the desired number of digits to the right of the decimal point. It must be greater than or equal to zero.
+ * the desired number of digits to the right of the decimal point. It must be greater than or equal to zero.
* @throws SQLServerException
- * If any errors occur.
+ * If any errors occur.
*/
- public void registerOutParameter(String parameterName,
- int sqlType,
- int precision,
+ public void registerOutParameter(String parameterName, int sqlType, int precision,
int scale) throws SQLServerException;
/**
@@ -1133,34 +1070,33 @@ public void registerOutParameter(String parameterName,
*
* The given Java object will be converted to the given targetSqlType before being sent to the database.
*
- * If the object has a custom mapping (is of a class implementing the interface SQLData
), the JDBC driver should call the method
- * SQLData.writeSQL
to write it to the SQL data stream. If, on the other hand, the object is of a class implementing
- * Ref
, Blob
, Clob
, NClob
, Struct
, java.net.URL
, or
- * Array
, the driver should pass it to the database as a value of the corresponding SQL type.
+ * If the object has a custom mapping (is of a class implementing the interface SQLData
), the JDBC
+ * driver should call the method SQLData.writeSQL
to write it to the SQL data stream. If, on the other
+ * hand, the object is of a class implementing Ref
, Blob
, Clob
,
+ * NClob
, Struct
, java.net.URL
, or Array
, the driver should pass
+ * it to the database as a value of the corresponding SQL type.
*
* Note that this method may be used to pass datatabase- specific abstract data types.
*
* @param parameterName
- * the name of the parameter
+ * the name of the parameter
* @param value
- * the object containing the input parameter value
+ * the object containing the input parameter value
* @param jdbcType
- * the SQL type (as defined in java.sql.Types) to be sent to the database. The scale argument may further qualify this type.
+ * the SQL type (as defined in java.sql.Types) to be sent to the database. The scale argument may further
+ * qualify this type.
* @param scale
- * the scale of the column.
+ * the scale of the column.
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * if parameterName does not correspond to a named parameter; if a database access error occurs or this method is called on a closed
- * CallableStatement
+ * if parameterName does not correspond to a named parameter; if a database access error occurs or this
+ * method is called on a closed CallableStatement
* @see java.sql.Types
* @see #getObject
*/
- public void setObject(String parameterName,
- Object value,
- SQLType jdbcType,
- int scale,
+ public void setObject(String parameterName, Object value, SQLType jdbcType, int scale,
boolean forceEncrypt) throws SQLServerException;
}
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerConnection.java b/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerConnection.java
index 7ebf9dcfc..44d991782 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerConnection.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerConnection.java
@@ -1,9 +1,6 @@
/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc;
@@ -13,8 +10,9 @@
import java.sql.Statement;
import java.util.UUID;
+
/**
- * This interface is implemented by {@link SQLServerConnection} and {@link SQLServerConnectionPoolProxy} Classes.
+ * Provides an interface to the {@link SQLServerConnection} and {@link SQLServerConnectionPoolProxy} classes.
*/
public interface ISQLServerConnection extends java.sql.Connection {
@@ -23,223 +21,223 @@ public interface ISQLServerConnection extends java.sql.Connection {
public final static int TRANSACTION_SNAPSHOT = 0x1000;
/**
- * Gets the connection ID of the most recent connection attempt, regardless of whether the attempt succeeded or failed.
+ * Returns the connection ID of the most recent connection attempt, regardless of whether the attempt succeeded or
+ * failed.
*
- * @return 16-byte GUID representing the connection ID of the most recent connection attempt. Or, NULL if there is a failure after the connection
- * request is initiated and the pre-login handshake.
+ * @return 16-byte GUID representing the connection ID of the most recent connection attempt. Or, NULL if there is a
+ * failure after the connection request is initiated and the pre-login handshake.
* @throws SQLServerException
- * If any errors occur.
+ * If any errors occur.
*/
public UUID getClientConnectionId() throws SQLServerException;
/**
- * Creates a Statement
object that will generate ResultSet
objects with the given type, concurrency, and holdability.
- * This method is the same as the createStatement
method above, but it allows the default result set type, concurrency, and
- * holdability to be overridden.
+ * Creates a Statement
object that will generate ResultSet
objects with the given type,
+ * concurrency, and holdability. This method is the same as the createStatement
method above, but it
+ * allows the default result set type, concurrency, and holdability to be overridden.
*
* @param nType
- * one of the following ResultSet
constants: ResultSet.TYPE_FORWARD_ONLY
,
- * ResultSet.TYPE_SCROLL_INSENSITIVE
, or ResultSet.TYPE_SCROLL_SENSITIVE
+ * one of the following ResultSet
constants: ResultSet.TYPE_FORWARD_ONLY
,
+ * ResultSet.TYPE_SCROLL_INSENSITIVE
, or ResultSet.TYPE_SCROLL_SENSITIVE
* @param nConcur
- * one of the following ResultSet
constants: ResultSet.CONCUR_READ_ONLY
or
- * ResultSet.CONCUR_UPDATABLE
+ * one of the following ResultSet
constants: ResultSet.CONCUR_READ_ONLY
or
+ * ResultSet.CONCUR_UPDATABLE
* @param nHold
- * one of the following ResultSet
constants: ResultSet.HOLD_CURSORS_OVER_COMMIT
or
- * ResultSet.CLOSE_CURSORS_AT_COMMIT
+ * one of the following ResultSet
constants: ResultSet.HOLD_CURSORS_OVER_COMMIT
or
+ * ResultSet.CLOSE_CURSORS_AT_COMMIT
* @param stmtColEncSetting
- * Specifies how data will be sent and received when reading and writing encrypted columns.
- * @return a new Statement
object that will generate ResultSet
objects with the given type, concurrency, and holdability
+ * Specifies how data will be sent and received when reading and writing encrypted columns.
+ * @return a new Statement
object that will generate ResultSet
objects with the given
+ * type, concurrency, and holdability
* @throws SQLServerException
- * if a database access error occurs, this method is called on a closed connection or the given parameters are not
- * ResultSet
constants indicating type, concurrency, and holdability
+ * if a database access error occurs, this method is called on a closed connection or the given parameters
+ * are not ResultSet
constants indicating type, concurrency, and holdability
*/
- public Statement createStatement(int nType,
- int nConcur,
- int nHold,
+ public Statement createStatement(int nType, int nConcur, int nHold,
SQLServerStatementColumnEncryptionSetting stmtColEncSetting) throws SQLServerException;
/**
- * Creates a default PreparedStatement
object that has the capability to retrieve auto-generated keys. The given constant tells the
- * driver whether it should make auto-generated keys available for retrieval. This parameter is ignored if the SQL statement is not an
- * INSERT
statement, or an SQL statement able to return auto-generated keys (the list of such statements is vendor-specific).
+ * Creates a default PreparedStatement
object that has the capability to retrieve auto-generated keys.
+ * The given constant tells the driver whether it should make auto-generated keys available for retrieval. This
+ * parameter is ignored if the SQL statement is not an INSERT
statement, or an SQL statement able to
+ * return auto-generated keys (the list of such statements is vendor-specific).
*
- * Note: This method is optimized for handling parametric SQL statements that benefit from precompilation. If the driver supports
- * precompilation, the method prepareStatement
will send the statement to the database for precompilation. Some drivers may not
- * support precompilation. In this case, the statement may not be sent to the database until the PreparedStatement
object is
- * executed. This has no direct effect on users; however, it does affect which methods throw certain SQLExceptions.
+ * Note: This method is optimized for handling parametric SQL statements that benefit from precompilation. If
+ * the driver supports precompilation, the method prepareStatement
will send the statement to the
+ * database for precompilation. Some drivers may not support precompilation. In this case, the statement may not be
+ * sent to the database until the PreparedStatement
object is executed. This has no direct effect on
+ * users; however, it does affect which methods throw certain SQLExceptions.
*
- * Result sets created using the returned PreparedStatement
object will by default be type TYPE_FORWARD_ONLY
and have a
- * concurrency level of CONCUR_READ_ONLY
. The holdability of the created result sets can be determined by calling
- * {@link #getHoldability}.
+ * Result sets created using the returned PreparedStatement
object will by default be type
+ * TYPE_FORWARD_ONLY
and have a concurrency level of CONCUR_READ_ONLY
. The holdability of
+ * the created result sets can be determined by calling {@link #getHoldability}.
*
* @param sql
- * an SQL statement that may contain one or more '?' IN parameter placeholders
+ * an SQL statement that may contain one or more '?' IN parameter placeholders
* @param flag
- * a flag indicating whether auto-generated keys should be returned; one of Statement.RETURN_GENERATED_KEYS
or
- * Statement.NO_GENERATED_KEYS
+ * a flag indicating whether auto-generated keys should be returned; one of
+ * Statement.RETURN_GENERATED_KEYS
or Statement.NO_GENERATED_KEYS
* @param stmtColEncSetting
- * Specifies how data will be sent and received when reading and writing encrypted columns.
- * @return a new PreparedStatement
object, containing the pre-compiled SQL statement, that will have the capability of returning
- * auto-generated keys
+ * Specifies how data will be sent and received when reading and writing encrypted columns.
+ * @return a new PreparedStatement
object, containing the pre-compiled SQL statement, that will have
+ * the capability of returning auto-generated keys
* @throws SQLServerException
- * if a database access error occurs, this method is called on a closed connection or the given parameter is not a
- * Statement
constant indicating whether auto-generated keys should be returned
+ * if a database access error occurs, this method is called on a closed connection or the given parameter is
+ * not a Statement
constant indicating whether auto-generated keys should be returned
*/
- public PreparedStatement prepareStatement(String sql,
- int flag,
+ public PreparedStatement prepareStatement(String sql, int flag,
SQLServerStatementColumnEncryptionSetting stmtColEncSetting) throws SQLServerException;
/**
- * Creates a default PreparedStatement
object capable of returning the auto-generated keys designated by the given array. This array
- * contains the indexes of the columns in the target table that contain the auto-generated keys that should be made available. The driver will
- * ignore the array if the SQL statement is not an INSERT
statement, or an SQL statement able to return auto-generated keys (the list
- * of such statements is vendor-specific).
+ * Creates a default PreparedStatement
object capable of returning the auto-generated keys designated
+ * by the given array. This array contains the indexes of the columns in the target table that contain the
+ * auto-generated keys that should be made available. The driver will ignore the array if the SQL statement is not
+ * an INSERT
statement, or an SQL statement able to return auto-generated keys (the list of such
+ * statements is vendor-specific).
*
- * An SQL statement with or without IN parameters can be pre-compiled and stored in a PreparedStatement
object. This object can then
- * be used to efficiently execute this statement multiple times.
+ * An SQL statement with or without IN parameters can be pre-compiled and stored in a PreparedStatement
+ * object. This object can then be used to efficiently execute this statement multiple times.
*
- * Note: This method is optimized for handling parametric SQL statements that benefit from precompilation. If the driver supports
- * precompilation, the method prepareStatement
will send the statement to the database for precompilation. Some drivers may not
- * support precompilation. In this case, the statement may not be sent to the database until the PreparedStatement
object is
- * executed. This has no direct effect on users; however, it does affect which methods throw certain SQLExceptions.
+ * Note: This method is optimized for handling parametric SQL statements that benefit from precompilation. If
+ * the driver supports precompilation, the method prepareStatement
will send the statement to the
+ * database for precompilation. Some drivers may not support precompilation. In this case, the statement may not be
+ * sent to the database until the PreparedStatement
object is executed. This has no direct effect on
+ * users; however, it does affect which methods throw certain SQLExceptions.
*
- * Result sets created using the returned PreparedStatement
object will by default be type TYPE_FORWARD_ONLY
and have a
- * concurrency level of CONCUR_READ_ONLY
. The holdability of the created result sets can be determined by calling
- * {@link #getHoldability}.
+ * Result sets created using the returned PreparedStatement
object will by default be type
+ * TYPE_FORWARD_ONLY
and have a concurrency level of CONCUR_READ_ONLY
. The holdability of
+ * the created result sets can be determined by calling {@link #getHoldability}.
*
* @param sql
- * an SQL statement that may contain one or more '?' IN parameter placeholders
+ * an SQL statement that may contain one or more '?' IN parameter placeholders
* @param columnIndexes
- * an array of column indexes indicating the columns that should be returned from the inserted row or rows
+ * an array of column indexes indicating the columns that should be returned from the inserted row or rows
* @param stmtColEncSetting
- * Specifies how data will be sent and received when reading and writing encrypted columns.
- * @return a new PreparedStatement
object, containing the pre-compiled statement, that is capable of returning the auto-generated
- * keys designated by the given array of column indexes
+ * Specifies how data will be sent and received when reading and writing encrypted columns.
+ * @return a new PreparedStatement
object, containing the pre-compiled statement, that is capable of
+ * returning the auto-generated keys designated by the given array of column indexes
* @throws SQLServerException
- * if a database access error occurs or this method is called on a closed connection
+ * if a database access error occurs or this method is called on a closed connection
*/
- public PreparedStatement prepareStatement(String sql,
- int[] columnIndexes,
+ public PreparedStatement prepareStatement(String sql, int[] columnIndexes,
SQLServerStatementColumnEncryptionSetting stmtColEncSetting) throws SQLServerException;
/**
- * Creates a default PreparedStatement
object capable of returning the auto-generated keys designated by the given array. This array
- * contains the names of the columns in the target table that contain the auto-generated keys that should be returned. The driver will ignore the
- * array if the SQL statement is not an INSERT
statement, or an SQL statement able to return auto-generated keys (the list of such
+ * Creates a default PreparedStatement
object capable of returning the auto-generated keys designated
+ * by the given array. This array contains the names of the columns in the target table that contain the
+ * auto-generated keys that should be returned. The driver will ignore the array if the SQL statement is not an
+ * INSERT
statement, or an SQL statement able to return auto-generated keys (the list of such
* statements is vendor-specific).
*
- * An SQL statement with or without IN parameters can be pre-compiled and stored in a PreparedStatement
object. This object can then
- * be used to efficiently execute this statement multiple times.
+ * An SQL statement with or without IN parameters can be pre-compiled and stored in a PreparedStatement
+ * object. This object can then be used to efficiently execute this statement multiple times.
*
- * Note: This method is optimized for handling parametric SQL statements that benefit from precompilation. If the driver supports
- * precompilation, the method prepareStatement
will send the statement to the database for precompilation. Some drivers may not
- * support precompilation. In this case, the statement may not be sent to the database until the PreparedStatement
object is
- * executed. This has no direct effect on users; however, it does affect which methods throw certain SQLExceptions.
+ * Note: This method is optimized for handling parametric SQL statements that benefit from precompilation. If
+ * the driver supports precompilation, the method prepareStatement
will send the statement to the
+ * database for precompilation. Some drivers may not support precompilation. In this case, the statement may not be
+ * sent to the database until the PreparedStatement
object is executed. This has no direct effect on
+ * users; however, it does affect which methods throw certain SQLExceptions.
*
- * Result sets created using the returned PreparedStatement
object will by default be type TYPE_FORWARD_ONLY
and have a
- * concurrency level of CONCUR_READ_ONLY
. The holdability of the created result sets can be determined by calling
- * {@link #getHoldability}.
+ * Result sets created using the returned PreparedStatement
object will by default be type
+ * TYPE_FORWARD_ONLY
and have a concurrency level of CONCUR_READ_ONLY
. The holdability of
+ * the created result sets can be determined by calling {@link #getHoldability}.
*
* @param sql
- * an SQL statement that may contain one or more '?' IN parameter placeholders
+ * an SQL statement that may contain one or more '?' IN parameter placeholders
* @param columnNames
- * an array of column names indicating the columns that should be returned from the inserted row or rows
+ * an array of column names indicating the columns that should be returned from the inserted row or rows
* @param stmtColEncSetting
- * Specifies how data will be sent and received when reading and writing encrypted columns.
- * @return a new PreparedStatement
object, containing the pre-compiled statement, that is capable of returning the auto-generated
- * keys designated by the given array of column names
+ * Specifies how data will be sent and received when reading and writing encrypted columns.
+ * @return a new PreparedStatement
object, containing the pre-compiled statement, that is capable of
+ * returning the auto-generated keys designated by the given array of column names
* @throws SQLServerException
- * if a database access error occurs or this method is called on a closed connection
+ * if a database access error occurs or this method is called on a closed connection
*/
- public PreparedStatement prepareStatement(String sql,
- String[] columnNames,
+ public PreparedStatement prepareStatement(String sql, String[] columnNames,
SQLServerStatementColumnEncryptionSetting stmtColEncSetting) throws SQLServerException;
/**
- * Creates a PreparedStatement
object that will generate ResultSet
objects with the given type, concurrency, and
- * holdability.
+ * Creates a PreparedStatement
object that will generate ResultSet
objects with the given
+ * type, concurrency, and holdability.
*
- * This method is the same as the prepareStatement
method above, but it allows the default result set type, concurrency, and
- * holdability to be overridden.
+ * This method is the same as the prepareStatement
method above, but it allows the default result set
+ * type, concurrency, and holdability to be overridden.
*
* @param sql
- * a String
object that is the SQL statement to be sent to the database; may contain one or more '?' IN parameters
+ * a String
object that is the SQL statement to be sent to the database; may contain one or more
+ * '?' IN parameters
* @param nType
- * one of the following ResultSet
constants: ResultSet.TYPE_FORWARD_ONLY
,
- * ResultSet.TYPE_SCROLL_INSENSITIVE
, or ResultSet.TYPE_SCROLL_SENSITIVE
+ * one of the following ResultSet
constants: ResultSet.TYPE_FORWARD_ONLY
,
+ * ResultSet.TYPE_SCROLL_INSENSITIVE
, or ResultSet.TYPE_SCROLL_SENSITIVE
* @param nConcur
- * one of the following ResultSet
constants: ResultSet.CONCUR_READ_ONLY
or
- * ResultSet.CONCUR_UPDATABLE
+ * one of the following ResultSet
constants: ResultSet.CONCUR_READ_ONLY
or
+ * ResultSet.CONCUR_UPDATABLE
* @param resultSetHoldability
- * one of the following ResultSet
constants: ResultSet.HOLD_CURSORS_OVER_COMMIT
or
- * ResultSet.CLOSE_CURSORS_AT_COMMIT
+ * one of the following ResultSet
constants: ResultSet.HOLD_CURSORS_OVER_COMMIT
or
+ * ResultSet.CLOSE_CURSORS_AT_COMMIT
* @param stmtColEncSetting
- * Specifies how data will be sent and received when reading and writing encrypted columns.
- * @return a new PreparedStatement
object, containing the pre-compiled SQL statement, that will generate ResultSet
- * objects with the given type, concurrency, and holdability
+ * Specifies how data will be sent and received when reading and writing encrypted columns.
+ * @return a new PreparedStatement
object, containing the pre-compiled SQL statement, that will
+ * generate ResultSet
objects with the given type, concurrency, and holdability
* @throws SQLServerException
- * if a database access error occurs, this method is called on a closed connection or the given parameters are not
- * ResultSet
constants indicating type, concurrency, and holdability
+ * if a database access error occurs, this method is called on a closed connection or the given parameters
+ * are not ResultSet
constants indicating type, concurrency, and holdability
*/
- public PreparedStatement prepareStatement(java.lang.String sql,
- int nType,
- int nConcur,
- int resultSetHoldability,
+ public PreparedStatement prepareStatement(java.lang.String sql, int nType, int nConcur, int resultSetHoldability,
SQLServerStatementColumnEncryptionSetting stmtColEncSetting) throws SQLServerException;
/**
- * Creates a CallableStatement
object that will generate ResultSet
objects with the given type and concurrency. This
- * method is the same as the prepareCall
method above, but it allows the default result set type, result set concurrency type and
- * holdability to be overridden.
+ * Creates a CallableStatement
object that will generate ResultSet
objects with the given
+ * type and concurrency. This method is the same as the prepareCall
method above, but it allows the
+ * default result set type, result set concurrency type and holdability to be overridden.
*
* @param sql
- * a String
object that is the SQL statement to be sent to the database; may contain on or more '?' parameters
+ * a String
object that is the SQL statement to be sent to the database; may contain on or more
+ * '?' parameters
* @param nType
- * one of the following ResultSet
constants: ResultSet.TYPE_FORWARD_ONLY
,
- * ResultSet.TYPE_SCROLL_INSENSITIVE
, or ResultSet.TYPE_SCROLL_SENSITIVE
+ * one of the following ResultSet
constants: ResultSet.TYPE_FORWARD_ONLY
,
+ * ResultSet.TYPE_SCROLL_INSENSITIVE
, or ResultSet.TYPE_SCROLL_SENSITIVE
* @param nConcur
- * one of the following ResultSet
constants: ResultSet.CONCUR_READ_ONLY
or
- * ResultSet.CONCUR_UPDATABLE
+ * one of the following ResultSet
constants: ResultSet.CONCUR_READ_ONLY
or
+ * ResultSet.CONCUR_UPDATABLE
* @param nHold
- * one of the following ResultSet
constants: ResultSet.HOLD_CURSORS_OVER_COMMIT
or
- * ResultSet.CLOSE_CURSORS_AT_COMMIT
+ * one of the following ResultSet
constants: ResultSet.HOLD_CURSORS_OVER_COMMIT
or
+ * ResultSet.CLOSE_CURSORS_AT_COMMIT
* @param stmtColEncSetting
- * Specifies how data will be sent and received when reading and writing encrypted columns.
- * @return a new CallableStatement
object, containing the pre-compiled SQL statement, that will generate ResultSet
- * objects with the given type, concurrency, and holdability
+ * Specifies how data will be sent and received when reading and writing encrypted columns.
+ * @return a new CallableStatement
object, containing the pre-compiled SQL statement, that will
+ * generate ResultSet
objects with the given type, concurrency, and holdability
* @throws SQLServerException
- * if a database access error occurs, this method is called on a closed connection or the given parameters are not
- * ResultSet
constants indicating type, concurrency, and holdability
+ * if a database access error occurs, this method is called on a closed connection or the given parameters
+ * are not ResultSet
constants indicating type, concurrency, and holdability
*/
- public CallableStatement prepareCall(String sql,
- int nType,
- int nConcur,
- int nHold,
+ public CallableStatement prepareCall(String sql, int nType, int nConcur, int nHold,
SQLServerStatementColumnEncryptionSetting stmtColEncSetting) throws SQLServerException;
/**
- * Modifies the setting of the sendTimeAsDatetime connection property. When true, java.sql.Time values will be sent to the server as SQL
- * Serverdatetime values. When false, java.sql.Time values will be sent to the server as SQL Servertime values. sendTimeAsDatetime can also be
- * modified programmatically with SQLServerDataSource.setSendTimeAsDatetime. The default value for this property may change in a future release.
+ * Sets the value of the sendTimeAsDatetime connection property. When true, java.sql.Time values will be sent to the
+ * server as SQL Serverdatetime values. When false, java.sql.Time values will be sent to the server as SQL
+ * Servertime values. sendTimeAsDatetime can also be modified programmatically with
+ * SQLServerDataSource.setSendTimeAsDatetime. The default value for this property may change in a future release.
*
* @param sendTimeAsDateTimeValue
- * enables/disables setting the sendTimeAsDatetime connection property. For more information about how the Microsoft JDBC Driver for
- * SQL Server configures java.sql.Time values before sending them to the server, see
- * Configuring How java.sql.Time Values are Sent to the
- * Server.
+ * enables/disables setting the sendTimeAsDatetime connection property. For more information about how the
+ * Microsoft JDBC Driver for SQL Server configures java.sql.Time values before sending them to the server,
+ * see Configuring How
+ * java.sql.Time Values are Sent to the Server.
*
* @throws SQLServerException
- * if a database access error occurs
+ * if a database access error occurs
*/
public void setSendTimeAsDatetime(boolean sendTimeAsDateTimeValue) throws SQLServerException;
/**
- * Checks the sendTimeAsDatetime property.
+ * Returns the value of the sendTimeAsDatetime property.
*
* @return boolean value of sendTimeAsDatetime
*
* @throws SQLServerException
- * if a database access error occurs
+ * if a database access error occurs
*/
public boolean getSendTimeAsDatetime() throws SQLServerException;
@@ -256,52 +254,56 @@ public CallableStatement prepareCall(String sql,
public void closeUnreferencedPreparedStatementHandles();
/**
- * Returns the behavior for a specific connection instance. If false the first execution will call sp_executesql and not prepare a statement, once
- * the second execution happens it will call sp_prepexec and actually setup a prepared statement handle. Following executions will call
- * sp_execute. This relieves the need for sp_unprepare on prepared statement close if the statement is only executed once. The default for this
- * option can be changed by calling setDefaultEnablePrepareOnFirstPreparedStatementCall().
+ * Returns the behavior for a specific connection instance. If false the first execution will call sp_executesql and
+ * not prepare a statement, once the second execution happens it will call sp_prepexec and actually setup a prepared
+ * statement handle. Following executions will call sp_execute. This relieves the need for sp_unprepare on prepared
+ * statement close if the statement is only executed once. The default for this option can be changed by calling
+ * setDefaultEnablePrepareOnFirstPreparedStatementCall().
*
* @return Returns the current setting per the description.
*/
public boolean getEnablePrepareOnFirstPreparedStatementCall();
/**
- * Specifies the behavior for a specific connection instance. If value is false the first execution will call sp_executesql and not prepare a
- * statement, once the second execution happens it will call sp_prepexec and actually setup a prepared statement handle. Following executions will
- * call sp_execute. This relieves the need for sp_unprepare on prepared statement close if the statement is only executed once.
+ * Sets the behavior for a specific connection instance. If value is false the first execution will call
+ * sp_executesql and not prepare a statement, once the second execution happens it will call sp_prepexec and
+ * actually setup a prepared statement handle. Following executions will call sp_execute. This relieves the need for
+ * sp_unprepare on prepared statement close if the statement is only executed once.
*
* @param value
- * Changes the setting per the description.
+ * Changes the setting per the description.
*/
public void setEnablePrepareOnFirstPreparedStatementCall(boolean value);
/**
- * Returns the behavior for a specific connection instance. This setting controls how many outstanding prepared statement discard actions
- * (sp_unprepare) can be outstanding per connection before a call to clean-up the outstanding handles on the server is executed. If the setting is
- * {@literal <=} 1, unprepare actions will be executed immedietely on prepared statement close. If it is set to {@literal >} 1, these calls will
- * be batched together to avoid overhead of calling sp_unprepare too often. The default for this option can be changed by calling
- * getDefaultServerPreparedStatementDiscardThreshold().
+ * Returns the behavior for a specific connection instance. This setting controls how many outstanding prepared
+ * statement discard actions (sp_unprepare) can be outstanding per connection before a call to clean-up the
+ * outstanding handles on the server is executed. If the setting is {@literal <=} 1, unprepare actions will be
+ * executed immedietely on prepared statement close. If it is set to {@literal >} 1, these calls will be batched
+ * together to avoid overhead of calling sp_unprepare too often. The default for this option can be changed by
+ * calling getDefaultServerPreparedStatementDiscardThreshold().
*
* @return Returns the current setting per the description.
*/
public int getServerPreparedStatementDiscardThreshold();
/**
- * Specifies the behavior for a specific connection instance. This setting controls how many outstanding prepared statement discard actions
- * (sp_unprepare) can be outstanding per connection before a call to clean-up the outstanding handles on the server is executed. If the setting is
- * {@literal <=} 1 unprepare actions will be executed immedietely on prepared statement close. If it is set to {@literal >} 1 these calls will be
- * batched together to avoid overhead of calling sp_unprepare too often.
+ * Sets the behavior for a specific connection instance. This setting controls how many outstanding prepared
+ * statement discard actions (sp_unprepare) can be outstanding per connection before a call to clean-up the
+ * outstanding handles on the server is executed. If the setting is {@literal <=} 1 unprepare actions will be
+ * executed immedietely on prepared statement close. If it is set to {@literal >} 1 these calls will be batched
+ * together to avoid overhead of calling sp_unprepare too often.
*
* @param value
- * Changes the setting per the description.
+ * Changes the setting per the description.
*/
public void setServerPreparedStatementDiscardThreshold(int value);
/**
- * Specifies the size of the prepared statement cache for this connection. A value less than 1 means no cache.
+ * Sets the size of the prepared statement cache for this connection. A value less than 1 means no cache.
*
* @param value
- * The new cache size.
+ * The new cache size.
*
*/
public void setStatementPoolingCacheSize(int value);
@@ -314,7 +316,7 @@ public CallableStatement prepareCall(String sql,
public int getStatementPoolingCacheSize();
/**
- * Whether statement pooling is enabled or not for this connection.
+ * Returns whether statement pooling is enabled or not for this connection.
*
* @return Returns the current setting per the description.
*/
@@ -328,15 +330,15 @@ public CallableStatement prepareCall(String sql,
public int getStatementHandleCacheEntryCount();
/**
- * Disable/enable statement pooling.
+ * Sets the value to Disable/enable statement pooling.
*
* @param value
- * true to disable statement pooling, false to enable it.
+ * true to disable statement pooling, false to enable it.
*/
public void setDisableStatementPooling(boolean value);
/**
- * Determine whether statement pooling is disabled.
+ * Returns the value whether statement pooling is disabled.
*
* @return true if statement pooling is disabled, false if it is enabled.
*/
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerConnection43.java b/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerConnection43.java
index c7dca8ee1..b17597aa6 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerConnection43.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerConnection43.java
@@ -1,57 +1,61 @@
/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc;
import java.sql.SQLException;
+
/**
- * This interface is implemented by {@link SQLServerConnection43} class.
+ * Provides an interface to the {@link SQLServerConnection43} class.
*/
public interface ISQLServerConnection43 extends ISQLServerConnection {
/**
- * Hints to the driver that a request, an independent unit of work, is beginning on this connection. It backs up the values of the connection
- * properties that are modifiable through public methods. Each request is independent of all other requests with regard to state local to the
- * connection either on the client or the server. Work done between {@code beginRequest}, {@code endRequest} pairs does not depend on any other
- * work done on the connection either as part of another request or outside of any request. A request may include multiple transactions. There may
- * be dependencies on committed database state as that is not local to the connection. {@code beginRequest} marks the beginning of the work unit.
+ * Hints to the driver that a request, an independent unit of work, is beginning on this connection. It backs up the
+ * values of the connection properties that are modifiable through public methods. Each request is independent of
+ * all other requests with regard to state local to the connection either on the client or the server. Work done
+ * between {@code beginRequest}, {@code endRequest} pairs does not depend on any other work done on the connection
+ * either as part of another request or outside of any request. A request may include multiple transactions. There
+ * may be dependencies on committed database state as that is not local to the connection. {@code beginRequest}
+ * marks the beginning of the work unit.
*
- * Local state is defined as any state associated with a Connection that is local to the current Connection either in the client or the database
- * that is not transparently reproducible.
+ * Local state is defined as any state associated with a Connection that is local to the current Connection either
+ * in the client or the database that is not transparently reproducible.
*
- * Calls to {@code beginRequest} and {@code endRequest} are not nested. Multiple calls to {@code beginRequest} without an intervening call to
- * {@code endRequest} is not an error. The first {@code beginRequest} call marks the start of the request and subsequent calls are treated as a
- * no-op It is recommended to enclose each unit of work in {@code beginRequest}, {@code endRequest} pairs such that there is no open transaction
- * at the beginning or end of the request and no dependency on local state that crosses request boundaries. Committed database state is not local.
+ * Calls to {@code beginRequest} and {@code endRequest} are not nested. Multiple calls to {@code beginRequest}
+ * without an intervening call to {@code endRequest} is not an error. The first {@code beginRequest} call marks the
+ * start of the request and subsequent calls are treated as a no-op It is recommended to enclose each unit of work
+ * in {@code beginRequest}, {@code endRequest} pairs such that there is no open transaction at the beginning or end
+ * of the request and no dependency on local state that crosses request boundaries. Committed database state is not
+ * local.
*
* This method is to be used by Connection pooling managers.
*
- * The pooling manager should call {@code beginRequest} on the underlying connection prior to returning a connection to the caller.
+ * The pooling manager should call {@code beginRequest} on the underlying connection prior to returning a connection
+ * to the caller.
*
*
* @throws SQLException
- * if an error occurs
+ * if an error occurs
* @see #endRequest()
*/
@Override
public void beginRequest() throws SQLException;
/**
- * Hints to the driver that a request, an independent unit of work, has completed. It rolls back the open transactions. Resets the connection
- * properties that are modifiable through public methods back to their original values. Calls to {@code beginRequest} and {@code endRequest} are
- * not nested. Multiple calls to {@code endRequest} without an intervening call to {@code beginRequest} is not an error. The first
- * {@code endRequest} call marks the request completed and subsequent calls are treated as a no-op. If {@code endRequest} is called without an
- * initial call to {@code beginRequest} is a no-op. This method is to be used by Connection pooling managers.
+ * Hints to the driver that a request, an independent unit of work, has completed. It rolls back the open
+ * transactions. Resets the connection properties that are modifiable through public methods back to their original
+ * values. Calls to {@code beginRequest} and {@code endRequest} are not nested. Multiple calls to {@code endRequest}
+ * without an intervening call to {@code beginRequest} is not an error. The first {@code endRequest} call marks the
+ * request completed and subsequent calls are treated as a no-op. If {@code endRequest} is called without an initial
+ * call to {@code beginRequest} is a no-op. This method is to be used by Connection pooling managers.
*
*
* @throws SQLException
- * if an error occurs
+ * if an error occurs
* @see #beginRequest()
*/
@Override
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerDataRecord.java b/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerDataRecord.java
index a4ee9f7cd..7c45b8449 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerDataRecord.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerDataRecord.java
@@ -1,51 +1,45 @@
/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc;
/**
- * This interface can be used to create classes that read in data from any
- * source (such as a file) and allow a structured type to be sent to SQL Server
- * tables.
+ * Provides an interface to create classes that read in data from any source (such as a file) and allow a structured
+ * type to be sent to SQL Server tables.
*/
public interface ISQLServerDataRecord {
- /**
- * Get the column meta data
- *
- * @param column
- * the first column is 1, the second is 2, and so on
- * @return SQLServerMetaData of column
- */
- public SQLServerMetaData getColumnMetaData(int column);
+ /**
+ * Returns the column meta data.
+ *
+ * @param column
+ * the first column is 1, the second is 2, and so on
+ * @return SQLServerMetaData of column
+ */
+ public SQLServerMetaData getColumnMetaData(int column);
- /**
- * Get the column count.
- *
- * @return Set of ordinals for the columns.
- */
- public int getColumnCount();
+ /**
+ * Returns the column count.
+ *
+ * @return Set of ordinals for the columns.
+ */
+ public int getColumnCount();
- /**
- * Gets the data for the current row as an array of Objects.
- *
- * Each Object must match the Java language Type that is used to represent
- * the indicated JDBC data type for the given column. For more information,
- * see 'Understanding the JDBC Driver Data Types' for the appropriate
- * mappings.
- *
- * @return The data for the row.
- */
- public Object[] getRowData();
+ /**
+ * Returns the data for the current row as an array of Objects.
+ *
+ * Each Object must match the Java language Type that is used to represent the indicated JDBC data type for the
+ * given column. For more information, see 'Understanding the JDBC Driver Data Types' for the appropriate mappings.
+ *
+ * @return The data for the row.
+ */
+ public Object[] getRowData();
- /**
- * Advances to the next data row.
- *
- * @return True if rows are available; false if there are no more rows
- */
- public boolean next();
+ /**
+ * Advances to the next data row.
+ *
+ * @return True if rows are available; false if there are no more rows
+ */
+ public boolean next();
}
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerDataSource.java b/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerDataSource.java
index 08168cac1..a0aedb4a5 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerDataSource.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerDataSource.java
@@ -1,17 +1,16 @@
/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc;
import org.ietf.jgss.GSSCredential;
+
/**
- * A factory to create connections to the data source represented by this object. This interface was added in SQL Server JDBC Driver 3.0.
+ * Provides a factory to create connections to the data source represented by this object. This interface was added in
+ * SQL Server JDBC Driver 3.0.
*
* This interface is implemented by {@link SQLServerDataSource} Class.
*/
@@ -21,7 +20,7 @@ public interface ISQLServerDataSource extends javax.sql.CommonDataSource {
* Sets the application intent.
*
* @param applicationIntent
- * A String that contains the application intent.
+ * A String that contains the application intent.
*/
public void setApplicationIntent(String applicationIntent);
@@ -36,14 +35,15 @@ public interface ISQLServerDataSource extends javax.sql.CommonDataSource {
* Sets the application name.
*
* @param applicationName
- * A String that contains the name of the application.
+ * A String that contains the name of the application.
*/
public void setApplicationName(String applicationName);
/**
* Returns the application name.
*
- * @return A String that contains the application name, or "Microsoft JDBC Driver for SQL Server" if no value is set.
+ * @return A String that contains the application name, or "Microsoft JDBC Driver for SQL Server" if no value is
+ * set.
*/
public String getApplicationName();
@@ -51,7 +51,7 @@ public interface ISQLServerDataSource extends javax.sql.CommonDataSource {
* Sets the database name to connect to.
*
* @param databaseName
- * A String that contains the database name.
+ * A String that contains the database name.
*/
public void setDatabaseName(String databaseName);
@@ -66,7 +66,7 @@ public interface ISQLServerDataSource extends javax.sql.CommonDataSource {
* Sets the SQL Server instance name.
*
* @param instanceName
- * A String that contains the instance name.
+ * A String that contains the instance name.
*/
public void setInstanceName(String instanceName);
@@ -81,7 +81,7 @@ public interface ISQLServerDataSource extends javax.sql.CommonDataSource {
* Sets a Boolean value that indicates if the integratedSecurity property is enabled.
*
* @param enable
- * true if integratedSecurity is enabled. Otherwise, false.
+ * true if integratedSecurity is enabled. Otherwise, false.
*/
public void setIntegratedSecurity(boolean enable);
@@ -89,7 +89,7 @@ public interface ISQLServerDataSource extends javax.sql.CommonDataSource {
* Sets a Boolean value that indicates if the lastUpdateCount property is enabled.
*
* @param lastUpdateCount
- * true if lastUpdateCount is enabled. Otherwise, false.
+ * true if lastUpdateCount is enabled. Otherwise, false.
*/
public void setLastUpdateCount(boolean lastUpdateCount);
@@ -104,7 +104,8 @@ public interface ISQLServerDataSource extends javax.sql.CommonDataSource {
* Sets a Boolean value that indicates if the encrypt property is enabled.
*
* @param encrypt
- * true if the Secure Sockets Layer (SSL) encryption is enabled between the client and the SQL Server. Otherwise, false.
+ * true if the Secure Sockets Layer (SSL) encryption is enabled between the client and the SQL Server.
+ * Otherwise, false.
*/
public void setEncrypt(boolean encrypt);
@@ -116,11 +117,12 @@ public interface ISQLServerDataSource extends javax.sql.CommonDataSource {
public boolean getEncrypt();
/**
- * Beginning in version 6.0 of the Microsoft JDBC Driver for SQL Server, a new connection property transparentNetworkIPResolution (TNIR) is added
- * for transparent connection to Always On availability groups or to a server which has multiple IP addresses associated. When
- * transparentNetworkIPResolution is true, the driver attempts to connect to the first IP address available. If the first attempt fails, the
- * driver tries to connect to all IP addresses in parallel until the timeout expires, discarding any pending connection attempts when one of them
- * succeeds.
+ * Sets the value to enable/disable Transparent Netowrk IP Resolution (TNIR). Beginning in version 6.0 of the
+ * Microsoft JDBC Driver for SQL Server, a new connection property transparentNetworkIPResolution (TNIR) is added
+ * for transparent connection to Always On availability groups or to a server which has multiple IP addresses
+ * associated. When transparentNetworkIPResolution is true, the driver attempts to connect to the first IP address
+ * available. If the first attempt fails, the driver tries to connect to all IP addresses in parallel until the
+ * timeout expires, discarding any pending connection attempts when one of them succeeds.
*
* transparentNetworkIPResolution is ignored if multiSubnetFailover is true
*
@@ -129,12 +131,12 @@ public interface ISQLServerDataSource extends javax.sql.CommonDataSource {
* transparentNetworkIPResolution is ignored if there are more than 64 IP addresses
*
* @param tnir
- * if set to true, the driver attempts to connect to the first IP address available. It is true by default.
+ * if set to true, the driver attempts to connect to the first IP address available. It is true by default.
*/
public void setTransparentNetworkIPResolution(boolean tnir);
/**
- * Retrieves the TransparentNetworkIPResolution value.
+ * Returns the TransparentNetworkIPResolution value.
*
* @return if enabled, returns true. Otherwise, false.
*/
@@ -144,8 +146,8 @@ public interface ISQLServerDataSource extends javax.sql.CommonDataSource {
* Sets a Boolean value that indicates if the trustServerCertificate property is enabled.
*
* @param e
- * true, if the server Secure Sockets Layer (SSL) certificate should be automatically trusted when the communication layer is encrypted
- * using SSL. Otherwise, false.
+ * true, if the server Secure Sockets Layer (SSL) certificate should be automatically trusted when the
+ * communication layer is encrypted using SSL. Otherwise, false.
*/
public void setTrustServerCertificate(boolean e);
@@ -157,15 +159,15 @@ public interface ISQLServerDataSource extends javax.sql.CommonDataSource {
public boolean getTrustServerCertificate();
/**
- * This parameter defines the keystore type for the trustStore.
+ * Sets the keystore type for the trustStore.
*
* @param trustStoreType
- * A String that contains the trust store type
+ * A String that contains the trust store type
*/
public void setTrustStoreType(String trustStoreType);
/**
- * Returns the keyStore Type for the trustStore
+ * Returns the keyStore Type for the trustStore.
*
* @return trustStoreType A String that contains the trust store type
*/
@@ -175,14 +177,15 @@ public interface ISQLServerDataSource extends javax.sql.CommonDataSource {
* Sets the path (including file name) to the certificate trustStore file.
*
* @param trustStore
- * A String that contains the path (including file name) to the certificate trustStore file.
+ * A String that contains the path (including file name) to the certificate trustStore file.
*/
public void setTrustStore(String trustStore);
/**
* Returns the path (including file name) to the certificate trustStore file.
*
- * @return trustStore A String that contains the path (including file name) to the certificate trustStore file, or null if no value is set.
+ * @return trustStore A String that contains the path (including file name) to the certificate trustStore file, or
+ * null if no value is set.
*/
public String getTrustStore();
@@ -190,7 +193,7 @@ public interface ISQLServerDataSource extends javax.sql.CommonDataSource {
* Sets the password that is used to check the integrity of the trustStore data.
*
* @param trustStorePassword
- * A String that contains the password that is used to check the integrity of the trustStore data.
+ * A String that contains the password that is used to check the integrity of the trustStore data.
*/
public void setTrustStorePassword(String trustStorePassword);
@@ -198,7 +201,7 @@ public interface ISQLServerDataSource extends javax.sql.CommonDataSource {
* Sets the host name to be used in validating the SQL Server Secure Sockets Layer (SSL) certificate.
*
* @param hostName
- * A String that contains the host name.
+ * A String that contains the host name.
*/
public void setHostNameInCertificate(String hostName);
@@ -213,12 +216,13 @@ public interface ISQLServerDataSource extends javax.sql.CommonDataSource {
* Sets an int value that indicates the number of milliseconds to wait before the database reports a lock time out.
*
* @param lockTimeout
- * An int value that contains the number of milliseconds to wait.
+ * An int value that contains the number of milliseconds to wait.
*/
public void setLockTimeout(int lockTimeout);
/**
- * Returns an int value that indicates the number of milliseconds that the database will wait before reporting a lock time out.
+ * Returns an int value that indicates the number of milliseconds that the database will wait before reporting a
+ * lock time out.
*
* @return An int value that contains the number of milliseconds that the database will wait.
*/
@@ -228,7 +232,7 @@ public interface ISQLServerDataSource extends javax.sql.CommonDataSource {
* Sets the password that will be used to connect to SQL Server.
*
* @param password
- * A String that contains the password.
+ * A String that contains the password.
*/
public void setPassword(String password);
@@ -236,7 +240,7 @@ public interface ISQLServerDataSource extends javax.sql.CommonDataSource {
* Sets the port number to be used to communicate with SQL Server.
*
* @param portNumber
- * An int value that contains the port number.
+ * An int value that contains the port number.
*/
public void setPortNumber(int portNumber);
@@ -248,15 +252,17 @@ public interface ISQLServerDataSource extends javax.sql.CommonDataSource {
public int getPortNumber();
/**
- * Sets the default cursor type that is used for all result sets that are created by using this SQLServerDataSource object.
+ * Sets the default cursor type that is used for all result sets that are created by using this SQLServerDataSource
+ * object.
*
* @param selectMethod
- * A String value that contains the default cursor type.
+ * A String value that contains the default cursor type.
*/
public void setSelectMethod(String selectMethod);
/**
- * Returns the default cursor type used for all result sets that are created by using this SQLServerDataSource object.
+ * Returns the default cursor type used for all result sets that are created by using this SQLServerDataSource
+ * object.
*
* @return A String value that contains the default cursor type.
*/
@@ -266,8 +272,8 @@ public interface ISQLServerDataSource extends javax.sql.CommonDataSource {
* Sets the response buffering mode for connections created by using this SQLServerDataSource object.
*
* @param bufferingMode
- * A String that contains the buffering and streaming mode. The valid mode can be one of the following case-insensitive Strings: full
- * or adaptive.
+ * A String that contains the buffering and streaming mode. The valid mode can be one of the following
+ * case-insensitive Strings: full or adaptive.
*/
public void setResponseBuffering(String bufferingMode);
@@ -279,19 +285,20 @@ public interface ISQLServerDataSource extends javax.sql.CommonDataSource {
public String getResponseBuffering();
/**
- * Modifies the setting of the sendTimeAsDatetime connection property.
+ * Sets the value to enable/disable the sendTimeAsDatetime connection property.
*
* @param sendTimeAsDatetime
- * A Boolean value. When true, causes java.sql.Time values to be sent to the server as SQL Server datetime types. When false, causes
- * java.sql.Time values to be sent to the server as SQL Server time types.
+ * A Boolean value. When true, causes java.sql.Time values to be sent to the server as SQL Server datetime
+ * types. When false, causes java.sql.Time values to be sent to the server as SQL Server time types.
*/
public void setSendTimeAsDatetime(boolean sendTimeAsDatetime);
/**
- * This method was added in SQL Server JDBC Driver 3.0. Returns the setting of the sendTimeAsDatetime connection property.
+ * Returns the value of the sendTimeAsDatetime connection property. This method was added in SQL Server JDBC Driver
+ * 3.0. Returns the setting of the sendTimeAsDatetime connection property.
*
- * @return true if java.sql.Time values will be sent to the server as a SQL Server datetime type. false if java.sql.Time values will be sent to
- * the server as a SQL Server time type.
+ * @return true if java.sql.Time values will be sent to the server as a SQL Server datetime type. false if
+ * java.sql.Time values will be sent to the server as a SQL Server time type.
*/
public boolean getSendTimeAsDatetime();
@@ -299,27 +306,27 @@ public interface ISQLServerDataSource extends javax.sql.CommonDataSource {
* Sets a boolean value that indicates if sending string parameters to the server in UNICODE format is enabled.
*
* @param sendStringParametersAsUnicode
- * true if string parameters are sent to the server in UNICODE format. Otherwise, false.
+ * true if string parameters are sent to the server in UNICODE format. Otherwise, false.
*/
public void setSendStringParametersAsUnicode(boolean sendStringParametersAsUnicode);
/**
- * Returns a boolean value that indicates if sending string parameters to the server in UNICODE format is enabled.
+ * Returns whether sending string parameters to the server in UNICODE format is enabled.
*
* @return true if string parameters are sent to the server in UNICODE format. Otherwise, false.
*/
public boolean getSendStringParametersAsUnicode();
/**
- * Translates the serverName from Unicode to ASCII Compatible Encoding (ACE)
+ * Sets whether the serverName will be translated from Unicode to ASCII Compatible Encoding (ACE).
*
* @param serverNameAsACE
- * if enabled the servername will be translated to ASCII Compatible Encoding (ACE)
+ * if enabled the servername will be translated to ASCII Compatible Encoding (ACE)
*/
public void setServerNameAsACE(boolean serverNameAsACE);
/**
- * Retrieves if the serverName should be translated from Unicode to ASCII Compatible Encoding (ACE)
+ * Returns if the serverName should be translated from Unicode to ASCII Compatible Encoding (ACE).
*
* @return if enabled, will return true. Otherwise, false.
*/
@@ -329,7 +336,7 @@ public interface ISQLServerDataSource extends javax.sql.CommonDataSource {
* Sets the name of the computer that is running SQL Server.
*
* @param serverName
- * A String that contains the server name.
+ * A String that contains the server name.
*/
public void setServerName(String serverName);
@@ -344,7 +351,7 @@ public interface ISQLServerDataSource extends javax.sql.CommonDataSource {
* Sets the name of the failover server that is used in a database mirroring configuration.
*
* @param serverName
- * A String that contains the failover server name.
+ * A String that contains the failover server name.
*/
public void setFailoverPartner(String serverName);
@@ -359,7 +366,7 @@ public interface ISQLServerDataSource extends javax.sql.CommonDataSource {
* Sets the value of the multiSubnetFailover connection property.
*
* @param multiSubnetFailover
- * The new value of the multiSubnetFailover connection property.
+ * The new value of the multiSubnetFailover connection property.
*/
public void setMultiSubnetFailover(boolean multiSubnetFailover);
@@ -374,7 +381,7 @@ public interface ISQLServerDataSource extends javax.sql.CommonDataSource {
* Sets the user name that is used to connect the data source.
*
* @param user
- * A String that contains the user name.
+ * A String that contains the user name.
*/
public void setUser(String user);
@@ -389,7 +396,7 @@ public interface ISQLServerDataSource extends javax.sql.CommonDataSource {
* Sets the name of the client computer name that is used to connect to the data source.
*
* @param workstationID
- * A String that contains the client computer name.
+ * A String that contains the client computer name.
*/
public void setWorkstationID(String workstationID);
@@ -401,15 +408,15 @@ public interface ISQLServerDataSource extends javax.sql.CommonDataSource {
public String getWorkstationID();
/**
- * Sets a Boolean value that indicates if converting SQL states to XOPEN compliant states is enabled.
+ * Sets whether converting SQL states to XOPEN compliant states is enabled.
*
* @param xopenStates
- * true if converting SQL states to XOPEN compliant states is enabled. Otherwise, false.
+ * true if converting SQL states to XOPEN compliant states is enabled. Otherwise, false.
*/
public void setXopenStates(boolean xopenStates);
/**
- * Returns a boolean value that indicates if converting SQL states to XOPEN compliant states is enabled.
+ * Returns the value that indicates if converting SQL states to XOPEN compliant states is enabled.
*
* @return true if converting SQL states to XOPEN compliant states is enabled. Otherwise, false.
*/
@@ -419,7 +426,7 @@ public interface ISQLServerDataSource extends javax.sql.CommonDataSource {
* Sets the URL that is used to connect to the data source.
*
* @param url
- * A String that contains the URL.
+ * A String that contains the URL.
*/
public void setURL(String url);
@@ -434,7 +441,7 @@ public interface ISQLServerDataSource extends javax.sql.CommonDataSource {
* Sets the description of the data source.
*
* @param description
- * A String that contains the description.
+ * A String that contains the description.
*/
public void setDescription(String description);
@@ -449,7 +456,7 @@ public interface ISQLServerDataSource extends javax.sql.CommonDataSource {
* Sets the current network packet size used to communicate with SQL Server, specified in bytes.
*
* @param packetSize
- * An int value containing the network packet size.
+ * An int value containing the network packet size.
*/
public void setPacketSize(int packetSize);
@@ -461,53 +468,53 @@ public interface ISQLServerDataSource extends javax.sql.CommonDataSource {
public int getPacketSize();
/**
- * Indicates the kind of integrated security you want your application to use.
+ * Sets the kind of integrated security you want your application to use.
*
* @param authenticationScheme
- * Values are "JavaKerberos" and the default "NativeAuthentication".
+ * Values are "JavaKerberos" and the default "NativeAuthentication".
*/
public void setAuthenticationScheme(String authenticationScheme);
/**
- * sets the authentication mode
+ * Sets the authentication mode.
*
* @param authentication
- * the authentication mode
+ * the authentication mode
*/
public void setAuthentication(String authentication);
/**
- * Retrieves the authentication mode
+ * Returns the authentication mode.
*
* @return the authentication value
*/
public String getAuthentication();
/**
- * Sets the server spn
+ * Sets the server spn.
*
* @param serverSpn
- * A String that contains the server spn
+ * A String that contains the server spn
*/
public void setServerSpn(String serverSpn);
/**
- * Returns the server spn
+ * Returns the server spn.
*
* @return A String that contains the server spn
*/
public String getServerSpn();
/**
- * sets GSSCredential
+ * Sets the GSSCredential.
*
* @param userCredential
- * the credential
+ * the credential
*/
public void setGSSCredentials(GSSCredential userCredential);
/**
- * Retrieves the GSSCredential
+ * Returns the GSSCredential.
*
* @return GSSCredential
*/
@@ -517,147 +524,153 @@ public interface ISQLServerDataSource extends javax.sql.CommonDataSource {
* Sets the access token.
*
* @param accessToken
- * to be set in the string property.
+ * to be set in the string property.
*/
public void setAccessToken(String accessToken);
/**
- * Retrieves the access token.
+ * Returns the access token.
*
* @return the access token.
*/
public String getAccessToken();
/**
- * Enables/disables Always Encrypted functionality for the data source object. The default is Disabled.
+ * Sets the value to enable/disable Always Encrypted functionality for the data source object. The default is
+ * Disabled.
*
* @param columnEncryptionSetting
- * Enables/disables Always Encrypted functionality for the data source object. The default is Disabled.
+ * Enables/disables Always Encrypted functionality for the data source object. The default is Disabled.
*/
public void setColumnEncryptionSetting(String columnEncryptionSetting);
/**
- * Retrieves the Always Encrypted functionality setting for the data source object.
+ * Returns the Always Encrypted functionality setting for the data source object.
*
* @return the Always Encrypted functionality setting for the data source object.
*/
public String getColumnEncryptionSetting();
/**
- * Sets the name that identifies a key store. Only value supported is the "JavaKeyStorePassword" for identifying the Java Key Store. The default
- * is null.
+ * Sets the name that identifies a key store. Only value supported is the "JavaKeyStorePassword" for identifying the
+ * Java Key Store. The default is null.
*
* @param keyStoreAuthentication
- * the name that identifies a key store.
+ * the name that identifies a key store.
*/
public void setKeyStoreAuthentication(String keyStoreAuthentication);
/**
- * Gets the value of the keyStoreAuthentication setting for the data source object.
+ * Returns the value of the keyStoreAuthentication setting for the data source object.
*
* @return the value of the keyStoreAuthentication setting for the data source object.
*/
public String getKeyStoreAuthentication();
/**
- * Sets the password for the Java keystore. Note that, for Java Key Store provider the password for the keystore and the key must be the same.
- * Note that, keyStoreAuthentication must be set with "JavaKeyStorePassword".
+ * Sets the password for the Java keystore. Note that, for Java Key Store provider the password for the keystore and
+ * the key must be the same. Note that, keyStoreAuthentication must be set with "JavaKeyStorePassword".
*
* @param keyStoreSecret
- * the password to use for the keystore as well as for the key
+ * the password to use for the keystore as well as for the key
*/
public void setKeyStoreSecret(String keyStoreSecret);
/**
- * Sets the location including the file name for the Java keystore. Note that, keyStoreAuthentication must be set with "JavaKeyStorePassword".
+ * Sets the location including the file name for the Java keystore. Note that, keyStoreAuthentication must be set
+ * with "JavaKeyStorePassword".
*
* @param keyStoreLocation
- * the location including the file name for the Java keystore.
+ * the location including the file name for the Java keystore.
*/
public void setKeyStoreLocation(String keyStoreLocation);
/**
- * Retrieves the keyStoreLocation for the Java Key Store.
+ * Returns the keyStoreLocation for the Java Key Store.
*
* @return the keyStoreLocation for the Java Key Store.
*/
public String getKeyStoreLocation();
/**
- * Setting the query timeout
+ * Setting the query timeout.
*
* @param queryTimeout
- * The number of seconds to wait before a timeout has occurred on a query. The default value is 0, which means infinite timeout.
+ * The number of seconds to wait before a timeout has occurred on a query. The default value is 0, which
+ * means infinite timeout.
*/
public void setQueryTimeout(int queryTimeout);
/**
- * Getting the query timeout
+ * Returns the query timeout.
*
* @return The number of seconds to wait before a timeout has occurred on a query.
*/
public int getQueryTimeout();
/**
- * Setting the cancel timeout
+ * Sets the cancel timeout.
*
* @param cancelQueryTimeout
- * The number of seconds to wait before we wait for the query timeout to happen.
+ * The number of seconds to wait before we wait for the query timeout to happen.
*/
public void setCancelQueryTimeout(int cancelQueryTimeout);
/**
- * Getting the cancel timeout
+ * Returns the cancel timeout.
*
* @return the number of seconds to wait before we wait for the query timeout to happen.
*/
public int getCancelQueryTimeout();
/**
- * If this configuration is false the first execution of a prepared statement will call sp_executesql and not prepare a statement, once the second
- * execution happens it will call sp_prepexec and actually setup a prepared statement handle. Following executions will call sp_execute. This
- * relieves the need for sp_unprepare on prepared statement close if the statement is only executed once.
+ * Sets the value that enables/disables whether the first execution of a prepared statement will call sp_executesql
+ * and not prepare a statement. If this configuration is false the first execution of a prepared statement will call
+ * sp_executesql and not prepare a statement, once the second execution happens it will call sp_prepexec and
+ * actually setup a prepared statement handle. Following executions will call sp_execute. This relieves the need for
+ * sp_unprepare on prepared statement close if the statement is only executed once.
*
* @param enablePrepareOnFirstPreparedStatementCall
- * Changes the setting per the description.
+ * Changes the setting per the description.
*/
public void setEnablePrepareOnFirstPreparedStatementCall(boolean enablePrepareOnFirstPreparedStatementCall);
/**
- * If this configuration returns false the first execution of a prepared statement will call sp_executesql and not prepare a statement, once the
- * second execution happens it will call sp_prepexec and actually setup a prepared statement handle. Following executions will call sp_execute.
- * This relieves the need for sp_unprepare on prepared statement close if the statement is only executed once.
+ * Returns the value that indicates whether the first execution of a prepared statement will call sp_executesql and
+ * not prepare a statement. If this configuration returns false the first execution of a prepared statement will
+ * call sp_executesql and not prepare a statement, once the second execution happens it will call sp_prepexec and
+ * actually setup a prepared statement handle. Following executions will call sp_execute. This relieves the need for
+ * sp_unprepare on prepared statement close if the statement is only executed once.
*
* @return Returns the current setting per the description.
*/
public boolean getEnablePrepareOnFirstPreparedStatementCall();
/**
- * This setting controls how many outstanding prepared statement discard actions (sp_unprepare) can be outstanding per connection before a call to
- * clean-up the outstanding handles on the server is executed. If the setting is {@literal <=} 1 unprepare actions will be executed immedietely on
- * prepared statement close. If it is set to {@literal >} 1 these calls will be batched together to avoid overhead of calling sp_unprepare too
- * often.
+ * Sets the value that controls how many outstanding prepared statement discard actions (sp_unprepare) can be
+ * outstanding per connection before a call to clean-up the outstanding handles on the server is executed. If the
+ * setting is {@literal <=} 1 unprepare actions will be executed immedietely on prepared statement close. If it is
+ * set to {@literal >} 1 these calls will be batched together to avoid overhead of calling sp_unprepare too often.
*
* @param serverPreparedStatementDiscardThreshold
- * Changes the setting per the description.
+ * Changes the setting per the description.
*/
public void setServerPreparedStatementDiscardThreshold(int serverPreparedStatementDiscardThreshold);
/**
- * This setting controls how many outstanding prepared statement discard actions (sp_unprepare) can be outstanding per connection before a call to
- * clean-up the outstanding handles on the server is executed. If the setting is {@literal <=} 1 unprepare actions will be executed immedietely on
- * prepared statement close. If it is set to {@literal >} 1 these calls will be batched together to avoid overhead of calling sp_unprepare too
- * often.
+ * Returns the value of the setting that controls how many outstanding prepared statement discard actions
+ * (sp_unprepare) can be outstanding per connection before a call to clean-up the outstanding handles on the server
+ * is executed.
*
* @return Returns the current setting per the description.
*/
public int getServerPreparedStatementDiscardThreshold();
/**
- * Specifies the size of the prepared statement cache for this connection. A value less than 1 means no cache.
+ * Sets the size of the prepared statement cache for this connection. A value less than 1 means no cache.
*
* @param statementPoolingCacheSize
- * Changes the setting per the description.
+ * Changes the setting per the description.
*/
public void setStatementPoolingCacheSize(int statementPoolingCacheSize);
@@ -669,61 +682,63 @@ public interface ISQLServerDataSource extends javax.sql.CommonDataSource {
public int getStatementPoolingCacheSize();
/**
- * Disable/enable statement pooling.
+ * Sets the value to disable/enable statement pooling.
*
* @param disableStatementPooling
- * true to disable statement pooling, false to enable it.
+ * true to disable statement pooling, false to enable it.
*/
public void setDisableStatementPooling(boolean disableStatementPooling);
/**
- * Determine whether statement pooling is disabled.
+ * Returns whether statement pooling is disabled.
*
* @return true if statement pooling is disabled, false if it is enabled.
*/
public boolean getDisableStatementPooling();
/**
- * Setting the socket timeout
+ * Sets the socket timeout value.
*
* @param socketTimeout
- * The number of milliseconds to wait before a timeout is occurred on a socket read or accept. The default value is 0, which means
- * infinite timeout.
+ * The number of milliseconds to wait before a timeout is occurred on a socket read or accept. The default
+ * value is 0, which means infinite timeout.
*/
public void setSocketTimeout(int socketTimeout);
/**
- * Getting the socket timeout
+ * Returns the socket timeout value.
*
* @return The number of milliseconds to wait before a timeout is occurred on a socket read or accept.
*/
public int getSocketTimeout();
/**
- * Sets the login configuration file for Kerberos authentication. This overrides the default configuration SQLJDBCDriver
+ * Sets the login configuration file for Kerberos authentication. This overrides the default configuration
+ * SQLJDBCDriver
*
* @param configurationName
- * the configuration name
+ * the configuration name
*/
public void setJASSConfigurationName(String configurationName);
/**
- * Retrieves the login configuration file for Kerberos authentication.
+ * Returns the login configuration file for Kerberos authentication.
*
* @return login configuration file name
*/
public String getJASSConfigurationName();
/**
- * Enables Fips Mode on the connection For FIPS enabled JVM this property should be true.
+ * Sets whether Fips Mode should be enabled/disabled on the connection. For FIPS enabled JVM this property should be
+ * true.
*
* @param fips
- * Boolean property to enable/disable fips
+ * Boolean property to enable/disable fips
*/
public void setFIPS(boolean fips);
/**
- * Retrieves value of connection property "fips" For FIPS enabled JVM this property should be true.
+ * Returns the value of connection property "fips". For FIPS enabled JVM this property should be true.
*
* @return fips boolean value
*/
@@ -735,59 +750,59 @@ public interface ISQLServerDataSource extends javax.sql.CommonDataSource {
* Acceptable values are: TLS, TLSv1, TLSv1.1, and TLSv1.2.
*
* @param sslProtocol
- * Value for SSL Protocol to be set.
+ * Value for SSL Protocol to be set.
*/
public void setSSLProtocol(String sslProtocol);
/**
- * Retrieves value of connection property 'sslProtocol'
+ * Returns the value of connection property 'sslProtocol'.
*
* @return sslProtocol property value
*/
public String getSSLProtocol();
/**
- * Sets the connection property 'trustManagerClass' on the connection
+ * Sets the connection property 'trustManagerClass' on the connection.
*
* @param trustManagerClass
- * The fully qualified class name of a custom javax.net.ssl.TrustManager.
+ * The fully qualified class name of a custom javax.net.ssl.TrustManager.
*/
public void setTrustManagerClass(String trustManagerClass);
/**
- * Retrieves value for the connection property 'trustManagerClass'
+ * Returns the value for the connection property 'trustManagerClass'.
*
* @return trustManagerClass property value
*/
public String getTrustManagerClass();
/**
- * Sets Constructor Arguments to be provided on constructor of 'trustManagerClass'
+ * Sets Constructor Arguments to be provided on constructor of 'trustManagerClass'.
*
* @param trustManagerConstructorArg
- * 'trustManagerClass' constructor arguments
+ * 'trustManagerClass' constructor arguments
*/
public void setTrustManagerConstructorArg(String trustManagerConstructorArg);
/**
- * Retrieves value for the connection property 'trustManagerConstructorArg'
+ * Returns the value for the connection property 'trustManagerConstructorArg'.
*
* @return trustManagerConstructorArg property value
*/
public String getTrustManagerConstructorArg();
/**
- * Getting the use Bulk Copy API for Batch Insert
+ * Returns whether the use Bulk Copy API is used for Batch Insert.
*
* @return whether the driver should use Bulk Copy API for Batch Insert operations.
*/
public boolean getUseBulkCopyForBatchInsert();
/**
- * Setting the use Bulk Copy API for Batch Insert
+ * Sets whether the use Bulk Copy API should be used for Batch Insert.
*
* @param useBulkCopyForBatchInsert
- * indicates whether Bulk Copy API should be used for Batch Insert operations.
+ * indicates whether Bulk Copy API should be used for Batch Insert operations.
*/
public void setUseBulkCopyForBatchInsert(boolean useBulkCopyForBatchInsert);
}
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerPreparedStatement.java b/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerPreparedStatement.java
index 17fc6b558..187d20821 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerPreparedStatement.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerPreparedStatement.java
@@ -1,9 +1,6 @@
/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc;
@@ -13,83 +10,78 @@
import java.sql.ResultSet;
import java.sql.SQLType;
+
/**
- * This interface is implemented by {@link SQLServerPreparedStatement} class.
+ * Provides an interface to the {@link SQLServerPreparedStatement} class.
*/
public interface ISQLServerPreparedStatement extends java.sql.PreparedStatement, ISQLServerStatement {
/**
* Sets the designated parameter to the given microsoft.sql.DateTimeOffset
value.
*
* @param parameterIndex
- * the first parameter is 1, the second is 2, ...
+ * the first parameter is 1, the second is 2, ...
* @param x
- * the parameter value
+ * the parameter value
* @throws SQLServerException
- * if parameterIndex does not correspond to a parameter marker in the SQL statement; if a database access error occurs or this method
- * is called on a closed PreparedStatement
+ * if parameterIndex does not correspond to a parameter marker in the SQL statement; if a database access
+ * error occurs or this method is called on a closed PreparedStatement
*/
- public void setDateTimeOffset(int parameterIndex,
- microsoft.sql.DateTimeOffset x) throws SQLServerException;
+ public void setDateTimeOffset(int parameterIndex, microsoft.sql.DateTimeOffset x) throws SQLServerException;
/**
* Sets the value of the designated parameter with the given object.
*
- * This method is similar to {@link #setObject(int parameterIndex, Object x, SQLType targetSqlType, int scaleOrLength)}, except that it assumes a
- * scale of zero.
+ * This method is similar to
+ * {@link #setObject(int parameterIndex, Object x, SQLType targetSqlType, int scaleOrLength)}, except that it
+ * assumes a scale of zero.
*
* The default implementation will throw {@code SQLFeatureNotSupportedException}
*
* @param parameterIndex
- * the first parameter is 1, the second is 2, ...
+ * the first parameter is 1, the second is 2, ...
* @param x
- * the object containing the input parameter value
+ * the object containing the input parameter value
* @param targetSqlType
- * the SQL type to be sent to the database
+ * the SQL type to be sent to the database
* @param precision
- * the precision of the column
+ * the precision of the column
* @param scale
- * the scale of the column
+ * the scale of the column
* @throws SQLServerException
- * if parameterIndex does not correspond to a parameter marker in the SQL statement; if a database access error occurs or this method
- * is called on a closed {@code PreparedStatement}
+ * if parameterIndex does not correspond to a parameter marker in the SQL statement; if a database access
+ * error occurs or this method is called on a closed {@code PreparedStatement}
*/
- public void setObject(int parameterIndex,
- Object x,
- SQLType targetSqlType,
- Integer precision,
+ public void setObject(int parameterIndex, Object x, SQLType targetSqlType, Integer precision,
Integer scale) throws SQLServerException;
/**
* Sets the value of the designated parameter with the given object.
*
- * This method is similar to {@link #setObject(int parameterIndex, Object x, SQLType targetSqlType, int scaleOrLength)}, except that it assumes a
- * scale of zero.
+ * This method is similar to
+ * {@link #setObject(int parameterIndex, Object x, SQLType targetSqlType, int scaleOrLength)}, except that it
+ * assumes a scale of zero.
*
* The default implementation will throw {@code SQLFeatureNotSupportedException}
*
* @param parameterIndex
- * the first parameter is 1, the second is 2, ...
+ * the first parameter is 1, the second is 2, ...
* @param x
- * the object containing the input parameter value
+ * the object containing the input parameter value
* @param targetSqlType
- * the SQL type to be sent to the database
+ * the SQL type to be sent to the database
* @param precision
- * the precision of the column
+ * the precision of the column
* @param scale
- * the scale of the column
+ * the scale of the column
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
- * @throws SQLServerException
- * if parameterIndex does not correspond to a parameter marker in the SQL statement; if a database access error occurs or this method
- * is called on a closed {@code PreparedStatement}
- */
- public void setObject(int parameterIndex,
- Object x,
- SQLType targetSqlType,
- Integer precision,
- Integer scale,
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
+ * @throws SQLServerException
+ * if parameterIndex does not correspond to a parameter marker in the SQL statement; if a database access
+ * error occurs or this method is called on a closed {@code PreparedStatement}
+ */
+ public void setObject(int parameterIndex, Object x, SQLType targetSqlType, Integer precision, Integer scale,
boolean forceEncrypt) throws SQLServerException;
/**
@@ -97,745 +89,677 @@ public void setObject(int parameterIndex,
*
* @return Per the description.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
public int getPreparedStatementHandle() throws SQLServerException;
/**
- * Sets the designated parameter to the given java.math.BigDecimal
value. The driver converts this to an SQL NUMERIC
- * value when it sends it to the database.
+ * Sets the designated parameter to the given java.math.BigDecimal
value. The driver converts this to
+ * an SQL NUMERIC
value when it sends it to the database.
*
* @param parameterIndex
- * the first parameter is 1, the second is 2, ...
+ * the first parameter is 1, the second is 2, ...
* @param x
- * the parameter value
+ * the parameter value
* @param precision
- * the precision of the column
+ * the precision of the column
* @param scale
- * the scale of the column
+ * the scale of the column
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void setBigDecimal(int parameterIndex,
- BigDecimal x,
- int precision,
- int scale) throws SQLServerException;
+ public void setBigDecimal(int parameterIndex, BigDecimal x, int precision, int scale) throws SQLServerException;
/**
- * Sets the designated parameter to the given java.math.BigDecimal
value. The driver converts this to an SQL NUMERIC
- * value when it sends it to the database.
+ * Sets the designated parameter to the given java.math.BigDecimal
value. The driver converts this to
+ * an SQL NUMERIC
value when it sends it to the database.
*
* @param parameterIndex
- * the first parameter is 1, the second is 2, ...
+ * the first parameter is 1, the second is 2, ...
* @param x
- * the parameter value
+ * the parameter value
* @param precision
- * the precision of the column
+ * the precision of the column
* @param scale
- * the scale of the column
+ * the scale of the column
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void setBigDecimal(int parameterIndex,
- BigDecimal x,
- int precision,
- int scale,
+ public void setBigDecimal(int parameterIndex, BigDecimal x, int precision, int scale,
boolean forceEncrypt) throws SQLServerException;
/**
- * Sets the designated parameter to the given java.math.BigDecimal
value. The driver converts this to an SQL NUMERIC
- * value when it sends it to the database.
+ * Sets the designated parameter to the given java.math.BigDecimal
value. The driver converts this to
+ * an SQL NUMERIC
value when it sends it to the database.
*
* @param parameterIndex
- * the first parameter is 1, the second is 2, ...
+ * the first parameter is 1, the second is 2, ...
* @param x
- * the parameter value
+ * the parameter value
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void setMoney(int parameterIndex,
- BigDecimal x) throws SQLServerException;
+ public void setMoney(int parameterIndex, BigDecimal x) throws SQLServerException;
/**
- * Sets the designated parameter to the given java.math.BigDecimal
value. The driver converts this to an SQL NUMERIC
- * value when it sends it to the database.
+ * Sets the designated parameter to the given java.math.BigDecimal
value. The driver converts this to
+ * an SQL NUMERIC
value when it sends it to the database.
*
* @param parameterIndex
- * the first parameter is 1, the second is 2, ...
+ * the first parameter is 1, the second is 2, ...
* @param x
- * the parameter value
+ * the parameter value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void setMoney(int parameterIndex,
- BigDecimal x,
- boolean forceEncrypt) throws SQLServerException;
+ public void setMoney(int parameterIndex, BigDecimal x, boolean forceEncrypt) throws SQLServerException;
/**
- * Sets the designated parameter to the given java.math.BigDecimal
value. The driver converts this to an SQL NUMERIC
- * value when it sends it to the database.
+ * Sets the designated parameter to the given java.math.BigDecimal
value. The driver converts this to
+ * an SQL NUMERIC
value when it sends it to the database.
*
* @param parameterIndex
- * the first parameter is 1, the second is 2, ...
+ * the first parameter is 1, the second is 2, ...
* @param x
- * the parameter value
+ * the parameter value
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void setSmallMoney(int parameterIndex,
- BigDecimal x) throws SQLServerException;
+ public void setSmallMoney(int parameterIndex, BigDecimal x) throws SQLServerException;
/**
- * Sets the designated parameter to the given java.math.BigDecimal
value. The driver converts this to an SQL NUMERIC
- * value when it sends it to the database.
+ * Sets the designated parameter to the given java.math.BigDecimal
value. The driver converts this to
+ * an SQL NUMERIC
value when it sends it to the database.
*
* @param parameterIndex
- * the first parameter is 1, the second is 2, ...
+ * the first parameter is 1, the second is 2, ...
* @param x
- * the parameter value
+ * the parameter value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void setSmallMoney(int parameterIndex,
- BigDecimal x,
- boolean forceEncrypt) throws SQLServerException;
+ public void setSmallMoney(int parameterIndex, BigDecimal x, boolean forceEncrypt) throws SQLServerException;
/**
- * Sets the designated parameter to the given Java boolean
value. The driver converts this to an SQL BIT
or
- * BOOLEAN
value when it sends it to the database.
+ * Sets the designated parameter to the given Java boolean
value. The driver converts this to an SQL
+ * BIT
or BOOLEAN
value when it sends it to the database.
*
* @param parameterIndex
- * the first parameter is 1, the second is 2, ...
+ * the first parameter is 1, the second is 2, ...
* @param x
- * the parameter value
+ * the parameter value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void setBoolean(int parameterIndex,
- boolean x,
- boolean forceEncrypt) throws SQLServerException;
+ public void setBoolean(int parameterIndex, boolean x, boolean forceEncrypt) throws SQLServerException;
/**
- * Sets the designated parameter to the given Java byte
value. The driver converts this to an SQL TINYINT
value when it
- * sends it to the database.
+ * Sets the designated parameter to the given Java byte
value. The driver converts this to an SQL
+ * TINYINT
value when it sends it to the database.
*
* @param parameterIndex
- * the first parameter is 1, the second is 2, ...
+ * the first parameter is 1, the second is 2, ...
* @param x
- * the parameter value
+ * the parameter value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void setByte(int parameterIndex,
- byte x,
- boolean forceEncrypt) throws SQLServerException;
+ public void setByte(int parameterIndex, byte x, boolean forceEncrypt) throws SQLServerException;
/**
- * Sets the designated parameter to the given Java array of bytes. The driver converts this to an SQL VARBINARY
or
- * LONGVARBINARY
(depending on the argument's size relative to the driver's limits on VARBINARY
values) when it sends it
- * to the database.
+ * Sets the designated parameter to the given Java array of bytes. The driver converts this to an SQL
+ * VARBINARY
or LONGVARBINARY
(depending on the argument's size relative to the driver's
+ * limits on VARBINARY
values) when it sends it to the database.
*
* @param parameterIndex
- * the first parameter is 1, the second is 2, ...
+ * the first parameter is 1, the second is 2, ...
* @param x
- * the parameter value
+ * the parameter value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void setBytes(int parameterIndex,
- byte x[],
- boolean forceEncrypt) throws SQLServerException;
+ public void setBytes(int parameterIndex, byte x[], boolean forceEncrypt) throws SQLServerException;
/**
* Sets the designated parameter to the given String. The driver converts this to an SQL GUID
*
* @param parameterIndex
- * the first parameter is 1, the second is 2, ...
+ * the first parameter is 1, the second is 2, ...
* @param guid
- * string representation of the uniqueIdentifier value
+ * string representation of the uniqueIdentifier value
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void setUniqueIdentifier(int parameterIndex,
- String guid) throws SQLServerException;
+ public void setUniqueIdentifier(int parameterIndex, String guid) throws SQLServerException;
/**
* Sets the designated parameter to the given String. The driver converts this to an SQL GUID
*
* @param parameterIndex
- * the first parameter is 1, the second is 2, ...
+ * the first parameter is 1, the second is 2, ...
* @param guid
- * string representation of the uniqueIdentifier value
+ * string representation of the uniqueIdentifier value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void setUniqueIdentifier(int parameterIndex,
- String guid,
- boolean forceEncrypt) throws SQLServerException;
+ public void setUniqueIdentifier(int parameterIndex, String guid, boolean forceEncrypt) throws SQLServerException;
/**
- * Sets the designated parameter to the given Java double
value. The driver converts this to an SQL DOUBLE
value when it
- * sends it to the database.
+ * Sets the designated parameter to the given Java double
value. The driver converts this to an SQL
+ * DOUBLE
value when it sends it to the database.
*
* @param parameterIndex
- * the first parameter is 1, the second is 2, ...
+ * the first parameter is 1, the second is 2, ...
* @param x
- * the parameter value
+ * the parameter value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void setDouble(int parameterIndex,
- double x,
- boolean forceEncrypt) throws SQLServerException;
+ public void setDouble(int parameterIndex, double x, boolean forceEncrypt) throws SQLServerException;
/**
- * Sets the designated parameter to the given Java float
value. The driver converts this to an SQL REAL
value when it
- * sends it to the database.
+ * Sets the designated parameter to the given Java float
value. The driver converts this to an SQL
+ * REAL
value when it sends it to the database.
*
* @param parameterIndex
- * the first parameter is 1, the second is 2, ...
+ * the first parameter is 1, the second is 2, ...
* @param x
- * the parameter value
+ * the parameter value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void setFloat(int parameterIndex,
- float x,
- boolean forceEncrypt) throws SQLServerException;
+ public void setFloat(int parameterIndex, float x, boolean forceEncrypt) throws SQLServerException;
/**
- * Sets the designated parameter to the given microsoft.sql.Geometry
Class object. The driver converts this to an SQL
- * REAL
value when it sends it to the database.
+ * Sets the designated parameter to the given microsoft.sql.Geometry
Class object. The driver converts
+ * this to an SQL REAL
value when it sends it to the database.
*
* @param parameterIndex
- * the first parameter is 1, the second is 2, ...
+ * the first parameter is 1, the second is 2, ...
* @param x
- * the parameter value
+ * the parameter value
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void setGeometry(int parameterIndex,
- Geometry x) throws SQLServerException;
+ public void setGeometry(int parameterIndex, Geometry x) throws SQLServerException;
/**
- * Sets the designated parameter to the given microsoft.sql.Geography
Class object. The driver converts this to an SQL
- * REAL
value when it sends it to the database.
+ * Sets the designated parameter to the given microsoft.sql.Geography
Class object. The driver converts
+ * this to an SQL REAL
value when it sends it to the database.
*
* @param parameterIndex
- * the first parameter is 1, the second is 2, ...
+ * the first parameter is 1, the second is 2, ...
* @param x
- * the parameter value
+ * the parameter value
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void setGeography(int parameterIndex,
- Geography x) throws SQLServerException;
+ public void setGeography(int parameterIndex, Geography x) throws SQLServerException;
/**
- * Sets the designated parameter to the given Java int
value. The driver converts this to an SQL INTEGER
value when it
- * sends it to the database.
+ * Sets the designated parameter to the given Java int
value. The driver converts this to an SQL
+ * INTEGER
value when it sends it to the database.
*
* @param parameterIndex
- * the first parameter is 1, the second is 2, ...
+ * the first parameter is 1, the second is 2, ...
* @param value
- * the parameter value
+ * the parameter value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void setInt(int parameterIndex,
- int value,
- boolean forceEncrypt) throws SQLServerException;
+ public void setInt(int parameterIndex, int value, boolean forceEncrypt) throws SQLServerException;
/**
- * Sets the designated parameter to the given Java long
value. The driver converts this to an SQL BIGINT
value when it
- * sends it to the database.
+ * Sets the designated parameter to the given Java long
value. The driver converts this to an SQL
+ * BIGINT
value when it sends it to the database.
*
* @param parameterIndex
- * the first parameter is 1, the second is 2, ...
+ * the first parameter is 1, the second is 2, ...
* @param x
- * the parameter value
+ * the parameter value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void setLong(int parameterIndex,
- long x,
- boolean forceEncrypt) throws SQLServerException;
+ public void setLong(int parameterIndex, long x, boolean forceEncrypt) throws SQLServerException;
/**
- *
* Sets the value of the designated parameter with the given object.
*
*
* The given Java object will be converted to the given targetSqlType before being sent to the database.
*
- * If the object has a custom mapping (is of a class implementing the interface SQLData
), the JDBC driver should call the method
- * SQLData.writeSQL
to write it to the SQL data stream. If, on the other hand, the object is of a class implementing
- * Ref
, Blob
, Clob
, NClob
, Struct
, java.net.URL
, or
- * Array
, the driver should pass it to the database as a value of the corresponding SQL type.
+ * If the object has a custom mapping (is of a class implementing the interface SQLData
), the JDBC
+ * driver should call the method SQLData.writeSQL
to write it to the SQL data stream. If, on the other
+ * hand, the object is of a class implementing Ref
, Blob
, Clob
,
+ * NClob
, Struct
, java.net.URL
, or Array
, the driver should pass
+ * it to the database as a value of the corresponding SQL type.
*
*
* Note that this method may be used to pass database-specific abstract data types.
*
* @param parameterIndex
- * the first parameter is 1, the second is 2, ...
+ * the first parameter is 1, the second is 2, ...
* @param x
- * the object containing the input parameter value
+ * the object containing the input parameter value
* @param targetSqlType
- * the SQL type (as defined in java.sql.Types) to be sent to the database. The scale argument may further qualify this type.
+ * the SQL type (as defined in java.sql.Types) to be sent to the database. The scale argument may further
+ * qualify this type.
* @param precision
- * the precision of the column
+ * the precision of the column
* @param scale
- * scale of the column
+ * scale of the column
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void setObject(int parameterIndex,
- Object x,
- int targetSqlType,
- Integer precision,
+ public void setObject(int parameterIndex, Object x, int targetSqlType, Integer precision,
int scale) throws SQLServerException;
/**
- *
* Sets the value of the designated parameter with the given object.
*
*
* The given Java object will be converted to the given targetSqlType before being sent to the database.
*
- * If the object has a custom mapping (is of a class implementing the interface SQLData
), the JDBC driver should call the method
- * SQLData.writeSQL
to write it to the SQL data stream. If, on the other hand, the object is of a class implementing
- * Ref
, Blob
, Clob
, NClob
, Struct
, java.net.URL
, or
- * Array
, the driver should pass it to the database as a value of the corresponding SQL type.
+ * If the object has a custom mapping (is of a class implementing the interface SQLData
), the JDBC
+ * driver should call the method SQLData.writeSQL
to write it to the SQL data stream. If, on the other
+ * hand, the object is of a class implementing Ref
, Blob
, Clob
,
+ * NClob
, Struct
, java.net.URL
, or Array
, the driver should pass
+ * it to the database as a value of the corresponding SQL type.
*
*
* Note that this method may be used to pass database-specific abstract data types.
*
* @param parameterIndex
- * the first parameter is 1, the second is 2, ...
+ * the first parameter is 1, the second is 2, ...
* @param x
- * the object containing the input parameter value
+ * the object containing the input parameter value
* @param targetSqlType
- * the SQL type (as defined in java.sql.Types) to be sent to the database. The scale argument may further qualify this type.
+ * the SQL type (as defined in java.sql.Types) to be sent to the database. The scale argument may further
+ * qualify this type.
* @param precision
- * the precision of the column
+ * the precision of the column
* @param scale
- * scale of the column
+ * scale of the column
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void setObject(int parameterIndex,
- Object x,
- int targetSqlType,
- Integer precision,
- int scale,
+ public void setObject(int parameterIndex, Object x, int targetSqlType, Integer precision, int scale,
boolean forceEncrypt) throws SQLServerException;
/**
- * Sets the designated parameter to the given Java short
value. The driver converts this to an SQL SMALLINT
value when
- * it sends it to the database.
+ * Sets the designated parameter to the given Java short
value. The driver converts this to an SQL
+ * SMALLINT
value when it sends it to the database.
*
* @param parameterIndex
- * the first parameter is 1, the second is 2, ...
+ * the first parameter is 1, the second is 2, ...
* @param x
- * the parameter value
+ * the parameter value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void setShort(int parameterIndex,
- short x,
- boolean forceEncrypt) throws SQLServerException;
+ public void setShort(int parameterIndex, short x, boolean forceEncrypt) throws SQLServerException;
/**
- * Sets the designated parameter to the given Java String
value. The driver converts this to an SQL VARCHAR
or
- * LONGVARCHAR
value (depending on the argument's size relative to the driver's limits on VARCHAR
values) when it sends
- * it to the database.
+ * Sets the designated parameter to the given Java String
value. The driver converts this to an SQL
+ * VARCHAR
or LONGVARCHAR
value (depending on the argument's size relative to the driver's
+ * limits on VARCHAR
values) when it sends it to the database.
*
* @param parameterIndex
- * the first parameter is 1, the second is 2, ...
+ * the first parameter is 1, the second is 2, ...
* @param str
- * the parameter value
+ * the parameter value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void setString(int parameterIndex,
- String str,
- boolean forceEncrypt) throws SQLServerException;
+ public void setString(int parameterIndex, String str, boolean forceEncrypt) throws SQLServerException;
/**
- * Sets the designated parameter to the given String
object. The driver converts this to a SQL NCHAR
or
- * NVARCHAR
or LONGNVARCHAR
value (depending on the argument's size relative to the driver's limits on
- * NVARCHAR
values) when it sends it to the database.
+ * Sets the designated parameter to the given String
object. The driver converts this to a SQL
+ * NCHAR
or NVARCHAR
or LONGNVARCHAR
value (depending on the argument's size
+ * relative to the driver's limits on NVARCHAR
values) when it sends it to the database.
*
* @param parameterIndex
- * of the first parameter is 1, the second is 2, ...
+ * of the first parameter is 1, the second is 2, ...
* @param value
- * the parameter value
+ * the parameter value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void setNString(int parameterIndex,
- String value,
- boolean forceEncrypt) throws SQLServerException;
+ public void setNString(int parameterIndex, String value, boolean forceEncrypt) throws SQLServerException;
/**
- * Sets the designated parameter to the given java.sql.Time
value
+ * Sets the designated parameter to the given java.sql.Time
value.
*
* @param parameterIndex
- * the first parameter is 1, the second is 2, ...
+ * the first parameter is 1, the second is 2, ...
* @param x
- * the parameter value
+ * the parameter value
* @param scale
- * the scale of the column
+ * the scale of the column
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void setTime(int parameterIndex,
- java.sql.Time x,
- int scale) throws SQLServerException;
+ public void setTime(int parameterIndex, java.sql.Time x, int scale) throws SQLServerException;
/**
- * Sets the designated parameter to the given java.sql.Time
value
+ * Sets the designated parameter to the given java.sql.Time
value.
*
* @param parameterIndex
- * the first parameter is 1, the second is 2, ...
+ * the first parameter is 1, the second is 2, ...
* @param x
- * the parameter value
+ * the parameter value
* @param scale
- * the scale of the column
+ * the scale of the column
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void setTime(int parameterIndex,
- java.sql.Time x,
- int scale,
- boolean forceEncrypt) throws SQLServerException;
+ public void setTime(int parameterIndex, java.sql.Time x, int scale, boolean forceEncrypt) throws SQLServerException;
/**
- * Sets the designated parameter to the given java.sql.Timestamp
value
+ * Sets the designated parameter to the given java.sql.Timestamp
value.
*
* @param parameterIndex
- * the first parameter is 1, the second is 2, ...
+ * the first parameter is 1, the second is 2, ...
* @param x
- * the parameter value
+ * the parameter value
* @param scale
- * the scale of the column
+ * the scale of the column
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void setTimestamp(int parameterIndex,
- java.sql.Timestamp x,
- int scale) throws SQLServerException;
+ public void setTimestamp(int parameterIndex, java.sql.Timestamp x, int scale) throws SQLServerException;
/**
- * Sets the designated parameter to the given java.sql.Timestamp
value
+ * Sets the designated parameter to the given java.sql.Timestamp
value.
*
* @param parameterIndex
- * the first parameter is 1, the second is 2, ...
+ * the first parameter is 1, the second is 2, ...
* @param x
- * the parameter value
+ * the parameter value
* @param scale
- * the scale of the column
+ * the scale of the column
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void setTimestamp(int parameterIndex,
- java.sql.Timestamp x,
- int scale,
+ public void setTimestamp(int parameterIndex, java.sql.Timestamp x, int scale,
boolean forceEncrypt) throws SQLServerException;
/**
- * Sets the designated parameter to the given microsoft.sql.DatetimeOffset
value
+ * Sets the designated parameter to the given microsoft.sql.DatetimeOffset
value.
*
* @param parameterIndex
- * the first parameter is 1, the second is 2, ...
+ * the first parameter is 1, the second is 2, ...
* @param x
- * the parameter value
+ * the parameter value
* @param scale
- * the scale of the column
+ * the scale of the column
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void setDateTimeOffset(int parameterIndex,
- microsoft.sql.DateTimeOffset x,
+ public void setDateTimeOffset(int parameterIndex, microsoft.sql.DateTimeOffset x,
int scale) throws SQLServerException;
/**
- * Sets the designated parameter to the given microsoft.sql.DatetimeOffset
value
+ * Sets the designated parameter to the given microsoft.sql.DatetimeOffset
value.
*
* @param parameterIndex
- * the first parameter is 1, the second is 2, ...
+ * the first parameter is 1, the second is 2, ...
* @param x
- * the parameter value
+ * the parameter value
* @param scale
- * the scale of the column
+ * the scale of the column
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void setDateTimeOffset(int parameterIndex,
- microsoft.sql.DateTimeOffset x,
- int scale,
+ public void setDateTimeOffset(int parameterIndex, microsoft.sql.DateTimeOffset x, int scale,
boolean forceEncrypt) throws SQLServerException;
/**
- * Sets the designated parameter to the given java.sql.Timestamp
value
+ * Sets the designated parameter to the given java.sql.Timestamp
value.
*
* @param parameterIndex
- * the first parameter is 1, the second is 2, ...
+ * the first parameter is 1, the second is 2, ...
* @param x
- * the parameter value
+ * the parameter value
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void setDateTime(int parameterIndex,
- java.sql.Timestamp x) throws SQLServerException;
+ public void setDateTime(int parameterIndex, java.sql.Timestamp x) throws SQLServerException;
/**
- * Sets the designated parameter to the given java.sql.Timestamp
value
+ * Sets the designated parameter to the given java.sql.Timestamp
value.
*
* @param parameterIndex
- * the first parameter is 1, the second is 2, ...
+ * the first parameter is 1, the second is 2, ...
* @param x
- * the parameter value
+ * the parameter value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void setDateTime(int parameterIndex,
- java.sql.Timestamp x,
- boolean forceEncrypt) throws SQLServerException;
+ public void setDateTime(int parameterIndex, java.sql.Timestamp x, boolean forceEncrypt) throws SQLServerException;
/**
- * Sets the designated parameter to the given java.sql.Timestamp
value
+ * Sets the designated parameter to the given java.sql.Timestamp
value.
*
* @param parameterIndex
- * the first parameter is 1, the second is 2, ...
+ * the first parameter is 1, the second is 2, ...
* @param x
- * the parameter value
+ * the parameter value
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void setSmallDateTime(int parameterIndex,
- java.sql.Timestamp x) throws SQLServerException;
+ public void setSmallDateTime(int parameterIndex, java.sql.Timestamp x) throws SQLServerException;
/**
- * Sets the designated parameter to the given java.sql.Timestamp
value
+ * Sets the designated parameter to the given java.sql.Timestamp
value.
*
* @param parameterIndex
- * the first parameter is 1, the second is 2, ...
+ * the first parameter is 1, the second is 2, ...
* @param x
- * the parameter value
+ * the parameter value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void setSmallDateTime(int parameterIndex,
- java.sql.Timestamp x,
+ public void setSmallDateTime(int parameterIndex, java.sql.Timestamp x,
boolean forceEncrypt) throws SQLServerException;
/**
- * Populates a table valued parameter with a data table
+ * Sets the data table to populates a table valued parameter.
*
* @param parameterIndex
- * the first parameter is 1, the second is 2, ...
+ * the first parameter is 1, the second is 2, ...
* @param tvpName
- * the name of the table valued parameter
+ * the name of the table valued parameter
* @param tvpDataTable
- * the source datatable object
+ * the source datatable object
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void setStructured(int parameterIndex,
- String tvpName,
+ public void setStructured(int parameterIndex, String tvpName,
SQLServerDataTable tvpDataTable) throws SQLServerException;
/**
- * Populates a table valued parameter with a data table
+ * Sets the result set to populate a table-valued parameter.
*
* @param parameterIndex
- * the first parameter is 1, the second is 2, ...
+ * the first parameter is 1, the second is 2, ...
* @param tvpName
- * the name of the table valued parameter
+ * the name of the table valued parameter
* @param tvpResultSet
- * the source resultset object
+ * the source resultset object
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void setStructured(int parameterIndex,
- String tvpName,
- ResultSet tvpResultSet) throws SQLServerException;
+ public void setStructured(int parameterIndex, String tvpName, ResultSet tvpResultSet) throws SQLServerException;
/**
- * Populates a table valued parameter with a data table
+ * Sets the server bulk record to populate a table valued parameter.
*
* @param parameterIndex
- * the first parameter is 1, the second is 2, ...
+ * the first parameter is 1, the second is 2, ...
* @param tvpName
- * the name of the table valued parameter
+ * the name of the table valued parameter
* @param tvpBulkRecord
- * an ISQLServerDataRecord object
+ * an ISQLServerDataRecord object
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void setStructured(int parameterIndex,
- String tvpName,
+ public void setStructured(int parameterIndex, String tvpName,
ISQLServerDataRecord tvpBulkRecord) throws SQLServerException;
/**
- * Sets the designated parameter to the given java.sql.Date
value, using the given Calendar
object. The driver uses the
- * Calendar
object to construct an SQL DATE
value, which the driver then sends to the database. With a
- * Calendar
object, the driver can calculate the date taking into account a custom timezone. If no Calendar
object is
+ * Sets the designated parameter to the given java.sql.Date
value, using the given
+ * Calendar
object. The driver uses the Calendar
object to construct an SQL
+ * DATE
value, which the driver then sends to the database. With a Calendar
object, the
+ * driver can calculate the date taking into account a custom timezone. If no Calendar
object is
* specified, the driver uses the default timezone, which is that of the virtual machine running the application.
*
* @param parameterIndex
- * the first parameter is 1, the second is 2, ...
+ * the first parameter is 1, the second is 2, ...
* @param x
- * the parameter value
+ * the parameter value
* @param cal
- * the Calendar
object the driver will use to construct the date
+ * the Calendar
object the driver will use to construct the date
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void setDate(int parameterIndex,
- java.sql.Date x,
- java.util.Calendar cal,
+ public void setDate(int parameterIndex, java.sql.Date x, java.util.Calendar cal,
boolean forceEncrypt) throws SQLServerException;
/**
- * Sets the designated parameter to the given java.sql.Time
value. The driver converts this to an SQL TIME
value when it
- * sends it to the database.
+ * Sets the designated parameter to the given java.sql.Time
value. The driver converts this to an SQL
+ * TIME
value when it sends it to the database.
*
* @param parameterIndex
- * the first parameter is 1, the second is 2, ...
+ * the first parameter is 1, the second is 2, ...
* @param x
- * the parameter value
+ * the parameter value
* @param cal
- * the Calendar
object the driver will use to construct the date
+ * the Calendar
object the driver will use to construct the date
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void setTime(int parameterIndex,
- java.sql.Time x,
- java.util.Calendar cal,
+ public void setTime(int parameterIndex, java.sql.Time x, java.util.Calendar cal,
boolean forceEncrypt) throws SQLServerException;
/**
- * Sets the designated parameter to the given java.sql.Timestamp
value. The driver converts this to an SQL TIMESTAMP
- * value when it sends it to the database.
+ * Sets the designated parameter to the given java.sql.Timestamp
value. The driver converts this to an
+ * SQL TIMESTAMP
value when it sends it to the database.
*
* @param parameterIndex
- * the first parameter is 1, the second is 2, ...
+ * the first parameter is 1, the second is 2, ...
* @param x
- * the parameter value
+ * the parameter value
* @param cal
- * the Calendar
object the driver will use to construct the date
+ * the Calendar
object the driver will use to construct the date
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void setTimestamp(int parameterIndex,
- java.sql.Timestamp x,
- java.util.Calendar cal,
+ public void setTimestamp(int parameterIndex, java.sql.Timestamp x, java.util.Calendar cal,
boolean forceEncrypt) throws SQLServerException;
/**
* Returns parameter metadata for the prepared statement.
*
* @param forceRefresh:
- * If true the cache will not be used to retrieve the metadata.
+ * If true the cache will not be used to retrieve the metadata.
*
* @return Per the description.
*
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
public ParameterMetaData getParameterMetaData(boolean forceRefresh) throws SQLServerException;
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerResultSet.java b/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerResultSet.java
index e9fa6ccb6..2ac7bc1b5 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerResultSet.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerResultSet.java
@@ -1,9 +1,6 @@
/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc;
@@ -14,8 +11,9 @@
import com.microsoft.sqlserver.jdbc.dataclassification.SensitivityClassification;
+
/**
- * This interface is implemented by {@link SQLServerResultSet} class.
+ * Provides an interface to the {@link SQLServerResultSet} class.
*/
public interface ISQLServerResultSet extends java.sql.ResultSet {
@@ -31,247 +29,248 @@ public interface ISQLServerResultSet extends java.sql.ResultSet {
public static final int CONCUR_SS_OPTIMISTIC_CCVAL = 1010; // CONCUR_UPDATABLE + 2
/**
- * Retrieves the value of the designated column in the current row of this ResultSet object as a com.microsoft.sqlserver.jdbc.Geometry object in
- * the Java programming language.
+ * Returns the value of the designated column in the current row of this ResultSet object as a
+ * com.microsoft.sqlserver.jdbc.Geometry object in the Java programming language.
*
* @param columnIndex
- * the first column is 1, the second is 2, ...
+ * the first column is 1, the second is 2, ...
* @return the column value; if the value is SQL NULL, the value returned is null
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
public Geometry getGeometry(int columnIndex) throws SQLServerException;
/**
- * Retrieves the value of the designated column in the current row of this ResultSet object as a com.microsoft.sqlserver.jdbc.Geometry object in
- * the Java programming language.
+ * Returns the value of the designated column in the current row of this ResultSet object as a
+ * com.microsoft.sqlserver.jdbc.Geometry object in the Java programming language.
*
* @param columnName
- * the name of the column
+ * the name of the column
* @return the column value; if the value is SQL NULL, the value returned is null
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
public Geometry getGeometry(String columnName) throws SQLServerException;
/**
- * Retrieves the value of the designated column in the current row of this ResultSet object as a com.microsoft.sqlserver.jdbc.Geography object in
- * the Java programming language.
+ * Returns the value of the designated column in the current row of this ResultSet object as a
+ * com.microsoft.sqlserver.jdbc.Geography object in the Java programming language.
*
* @param columnIndex
- * the first column is 1, the second is 2, ...
+ * the first column is 1, the second is 2, ...
* @return the column value; if the value is SQL NULL, the value returned is null
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
public Geography getGeography(int columnIndex) throws SQLServerException;
/**
- * Retrieves the value of the designated column in the current row of this ResultSet object as a com.microsoft.sqlserver.jdbc.Geography object in
- * the Java programming language.
+ * Returns the value of the designated column in the current row of this ResultSet object as a
+ * com.microsoft.sqlserver.jdbc.Geography object in the Java programming language.
*
* @param columnName
- * the name of the column
+ * the name of the column
* @return the column value; if the value is SQL NULL, the value returned is null
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
public Geography getGeography(String columnName) throws SQLServerException;
/**
- * Retrieves the value of the designated column in the current row of this ResultSet object as a String object in the Java programming language.
+ * Returns the value of the designated column in the current row of this ResultSet object as a String object in the
+ * Java programming language.
*
* @param columnIndex
- * the first column is 1, the second is 2, ...
+ * the first column is 1, the second is 2, ...
* @return the column value; if the value is SQL NULL, the value returned is null
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
public String getUniqueIdentifier(int columnIndex) throws SQLServerException;
/**
- * Retrieves the value of the designated column in the current row of this ResultSet object as a String object in the Java programming language.
+ * Returns the value of the designated column in the current row of this ResultSet object as a String object in the
+ * Java programming language.
*
* @param columnLabel
- * the name of the column
+ * the name of the column
* @return the column value; if the value is SQL NULL, the value returned is null
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
public String getUniqueIdentifier(String columnLabel) throws SQLServerException;
/**
- * Retrieves the value of the designated column in the current row of this ResultSet object as a java.sql.Timestamp object in the Java programming
- * language.
+ * Returns the value of the designated column in the current row of this ResultSet object as a java.sql.Timestamp
+ * object in the Java programming language.
*
* @param columnIndex
- * the first column is 1, the second is 2, ...
+ * the first column is 1, the second is 2, ...
* @return the column value; if the value is SQL NULL, the value returned is null
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
public java.sql.Timestamp getDateTime(int columnIndex) throws SQLServerException;
/**
- * Retrieves the value of the designated column in the current row of this ResultSet object as a java.sql.Timestamp object in the Java programming
- * language.
+ * Returns the value of the designated column in the current row of this ResultSet object as a java.sql.Timestamp
+ * object in the Java programming language.
*
* @param columnName
- * is the name of the column
+ * is the name of the column
* @return the column value; if the value is SQL NULL, the value returned is null
* @throws SQLServerException
- * If any errors occur.
+ * If any errors occur.
*/
public java.sql.Timestamp getDateTime(String columnName) throws SQLServerException;
/**
- * Retrieves the value of the designated column in the current row of this ResultSet object as a java.sql.Timestamp object in the Java programming
- * language. This method uses the given calendar to construct an appropriate millisecond value for the timestamp if the underlying database does
- * not store timezone information.
+ * Returns the value of the designated column in the current row of this ResultSet object as a java.sql.Timestamp
+ * object in the Java programming language. This method uses the given calendar to construct an appropriate
+ * millisecond value for the timestamp if the underlying database does not store timezone information.
*
* @param columnIndex
- * the first column is 1, the second is 2, ...
+ * the first column is 1, the second is 2, ...
* @param cal
- * the java.util.Calendar object to use in constructing the dateTime
+ * the java.util.Calendar object to use in constructing the dateTime
* @return the column value; if the value is SQL NULL, the value returned is null
* @throws SQLServerException
- * If any errors occur.
+ * If any errors occur.
*/
- public java.sql.Timestamp getDateTime(int columnIndex,
- Calendar cal) throws SQLServerException;
+ public java.sql.Timestamp getDateTime(int columnIndex, Calendar cal) throws SQLServerException;
/**
- * Retrieves the value of the designated column in the current row of this ResultSet object as a java.sql.Timestamp object in the Java programming
- * language. This method uses the given calendar to construct an appropriate millisecond value for the timestamp if the underlying database does
- * not store timezone information.
+ * Returns the value of the designated column in the current row of this ResultSet object as a java.sql.Timestamp
+ * object in the Java programming language. This method uses the given calendar to construct an appropriate
+ * millisecond value for the timestamp if the underlying database does not store timezone information.
*
* @param colName
- * the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the
- * column
+ * the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then
+ * the label is the name of the column
* @param cal
- * the java.util.Calendar object to use in constructing the dateTime
+ * the java.util.Calendar object to use in constructing the dateTime
* @return the column value; if the value is SQL NULL, the value returned is null
* @throws SQLServerException
- * If any errors occur.
+ * If any errors occur.
*/
- public java.sql.Timestamp getDateTime(String colName,
- Calendar cal) throws SQLServerException;
+ public java.sql.Timestamp getDateTime(String colName, Calendar cal) throws SQLServerException;
/**
- * Retrieves the value of the designated column in the current row of this ResultSet object as a java.sql.Timestamp object in the Java programming
- * language.
+ * Returns the value of the designated column in the current row of this ResultSet object as a java.sql.Timestamp
+ * object in the Java programming language.
*
* @param columnIndex
- * the first column is 1, the second is 2, ...
+ * the first column is 1, the second is 2, ...
* @return the column value; if the value is SQL NULL, the value returned is null
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
public java.sql.Timestamp getSmallDateTime(int columnIndex) throws SQLServerException;
/**
- * Retrieves the value of the designated column in the current row of this ResultSet object as a java.sql.Timestamp object in the Java programming
- * language.
+ * Returns the value of the designated column in the current row of this ResultSet object as a java.sql.Timestamp
+ * object in the Java programming language.
*
* @param columnName
- * is the name of a column.
+ * is the name of a column.
* @return the column value; if the value is SQL NULL, the value returned is null
* @throws SQLServerException
- * If any errors occur.
+ * If any errors occur.
*/
public java.sql.Timestamp getSmallDateTime(String columnName) throws SQLServerException;
/**
- * Retrieves the value of the designated column in the current row of this ResultSet object as a java.sql.Timestamp object in the Java programming
- * language.
+ * Returns the value of the designated column in the current row of this ResultSet object as a java.sql.Timestamp
+ * object in the Java programming language.
*
* @param columnIndex
- * the first column is 1, the second is 2, ...
+ * the first column is 1, the second is 2, ...
* @param cal
- * the java.util.Calendar object to use in constructing the smalldateTime
+ * the java.util.Calendar object to use in constructing the smalldateTime
* @return the column value; if the value is SQL NULL, the value returned is null
* @throws SQLServerException
- * If any errors occur.
+ * If any errors occur.
*/
- public java.sql.Timestamp getSmallDateTime(int columnIndex,
- Calendar cal) throws SQLServerException;
+ public java.sql.Timestamp getSmallDateTime(int columnIndex, Calendar cal) throws SQLServerException;
/**
+ * Returns the value of the designated column in the current row of this ResultSet object as a java.sql.Timestamp
+ * object in the Java programming language.
*
* @param colName
- * The name of a column
+ * The name of a column
* @param cal
- * the java.util.Calendar object to use in constructing the smalldateTime
+ * the java.util.Calendar object to use in constructing the smalldateTime
* @return the column value; if the value is SQL NULL, the value returned is null
* @throws SQLServerException
- * If any errors occur.
+ * If any errors occur.
*/
- public java.sql.Timestamp getSmallDateTime(String colName,
- Calendar cal) throws SQLServerException;
+ public java.sql.Timestamp getSmallDateTime(String colName, Calendar cal) throws SQLServerException;
/**
- * Retrieves the value of the designated column as a microsoft.sql.DateTimeOffset object, given a zero-based column ordinal.
+ * Returns the value of the designated column as a microsoft.sql.DateTimeOffset object, given a zero-based column
+ * ordinal.
*
* @param columnIndex
- * The zero-based ordinal of a column.
+ * The zero-based ordinal of a column.
* @return A DateTimeOffset Class object.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
public microsoft.sql.DateTimeOffset getDateTimeOffset(int columnIndex) throws SQLServerException;
/**
- * Retrieves the value of the column specified as a microsoft.sql.DateTimeOffset object, given a column name.
+ * Returns the value of the column specified as a microsoft.sql.DateTimeOffset object, given a column name.
*
* @param columnName
- * The name of a column.
+ * The name of a column.
* @return A DateTimeOffset Class object.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
public microsoft.sql.DateTimeOffset getDateTimeOffset(String columnName) throws SQLServerException;
/**
- * Retrieves the value of the column specified as a java.math.BigDecimal object.
+ * Returns the value of the column specified as a java.math.BigDecimal object.
*
* @param columnIndex
- * The zero-based ordinal of a column.
+ * The zero-based ordinal of a column.
* @return the column value; if the value is SQL NULL, the value returned is null
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
public BigDecimal getMoney(int columnIndex) throws SQLServerException;
/**
- * Retrieves the value of the column specified as a java.math.BigDecimal object.
+ * Returns the value of the column specified as a java.math.BigDecimal object.
*
* @param columnName
- * is the name of a column.
+ * is the name of a column.
* @return the column value; if the value is SQL NULL, the value returned is null.
* @throws SQLServerException
- * If any errors occur.
+ * If any errors occur.
*/
public BigDecimal getMoney(String columnName) throws SQLServerException;
/**
- * Retrieves the value of the column specified as a java.math.BigDecimal object.
+ * Returns the value of the column specified as a java.math.BigDecimal object.
*
* @param columnIndex
- * The zero-based ordinal of a column.
+ * The zero-based ordinal of a column.
* @return the column value; if the value is SQL NULL, the value returned is null
* @throws SQLServerException
- * If any errors occur.
+ * If any errors occur.
*/
public BigDecimal getSmallMoney(int columnIndex) throws SQLServerException;
/**
- * Retrieves the value of the column specified as a java.math.BigDecimal object.
+ * Returns the value of the column specified as a java.math.BigDecimal object.
*
* @param columnName
- * is the name of a column.
+ * is the name of a column.
* @return the column value; if the value is SQL NULL, the value returned is null.
* @throws SQLServerException
- * If any errors occur.
+ * If any errors occur.
*/
public BigDecimal getSmallMoney(String columnName) throws SQLServerException;
@@ -279,1422 +278,1295 @@ public java.sql.Timestamp getSmallDateTime(String colName,
* Updates the value of the column specified to the DateTimeOffset Class value, given a zero-based column ordinal.
*
* @param index
- * The zero-based ordinal of a column.
+ * The zero-based ordinal of a column.
* @param x
- * A DateTimeOffset Class object.
+ * A DateTimeOffset Class object.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void updateDateTimeOffset(int index,
- microsoft.sql.DateTimeOffset x) throws SQLServerException;
+ public void updateDateTimeOffset(int index, microsoft.sql.DateTimeOffset x) throws SQLServerException;
/**
* Updates the value of the column specified to the DateTimeOffset Class value, given a column name.
*
* @param columnName
- * The name of a column.
+ * The name of a column.
* @param x
- * A DateTimeOffset Class object.
+ * A DateTimeOffset Class object.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void updateDateTimeOffset(String columnName,
- microsoft.sql.DateTimeOffset x) throws SQLServerException;
+ public void updateDateTimeOffset(String columnName, microsoft.sql.DateTimeOffset x) throws SQLServerException;
/**
* Updates the designated column with an {@code Object} value.
*
- * The updater methods are used to update column values in the current row or the insert row. The updater methods do not update the underlying
- * database; instead the {@code updateRow} or {@code insertRow} methods are called to update the database.
+ * The updater methods are used to update column values in the current row or the insert row. The updater methods do
+ * not update the underlying database; instead the {@code updateRow} or {@code insertRow} methods are called to
+ * update the database.
*
* @param index
- * the first column is 1, the second is 2, ...
+ * the first column is 1, the second is 2, ...
* @param x
- * the new column value
+ * the new column value
* @param precision
- * the precision of the column
+ * the precision of the column
* @param scale
- * the scale of the column
+ * the scale of the column
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void updateObject(int index,
- Object x,
- int precision,
- int scale) throws SQLServerException;
+ public void updateObject(int index, Object x, int precision, int scale) throws SQLServerException;
/**
- * Updates the designated column with an Object value. The updater methods are used to update column values in the current row or the insert row.
- * The updater methods do not update the underlying database; instead the updateRow or insertRow methods are called to update the database. If the
- * second argument is an InputStream then the stream must contain the number of bytes specified by scaleOrLength. If the second argument is a
- * Reader then the reader must contain the number of characters specified by scaleOrLength. If these conditions are not true the driver will
- * generate a SQLServerException when the statement is executed. The default implementation will throw SQLFeatureNotSupportedException
+ * Updates the designated column with an Object value. The updater methods are used to update column values in the
+ * current row or the insert row. The updater methods do not update the underlying database; instead the updateRow
+ * or insertRow methods are called to update the database. If the second argument is an InputStream then the stream
+ * must contain the number of bytes specified by scaleOrLength. If the second argument is a Reader then the reader
+ * must contain the number of characters specified by scaleOrLength. If these conditions are not true the driver
+ * will generate a SQLServerException when the statement is executed. The default implementation will throw
+ * SQLFeatureNotSupportedException
*
* @param index
- * the first column is 1, the second is 2, ...
+ * the first column is 1, the second is 2, ...
* @param obj
- * the new column value
+ * the new column value
* @param targetSqlType
- * the SQL type to be sent to the database
+ * the SQL type to be sent to the database
* @param scale
- * for an object of java.math.BigDecimal , this is the number of digits after the decimal point. For Java Object types InputStream and
- * Reader, this is the length of the data in the stream or reader. For all other types, this value will be ignored.
+ * for an object of java.math.BigDecimal , this is the number of digits after the decimal point. For Java
+ * Object types InputStream and Reader, this is the length of the data in the stream or reader. For all other
+ * types, this value will be ignored.
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement.If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement.If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * If any errors occur.
+ * If any errors occur.
*/
- public void updateObject(int index,
- Object obj,
- SQLType targetSqlType,
- int scale,
+ public void updateObject(int index, Object obj, SQLType targetSqlType, int scale,
boolean forceEncrypt) throws SQLServerException;
/**
*
- * Updates the designated column with an Object value. The updater methods are used to update column values in the current row or the insert row.
- * The updater methods do not update the underlying database; instead the updateRow or insertRow methods are called to update the database. If the
- * second argument is an InputStream then the stream must contain the number of bytes specified by scaleOrLength. If the second argument is a
- * Reader then the reader must contain the number of characters specified by scaleOrLength. If these conditions are not true the driver will
- * generate a SQLServerException when the statement is executed. The default implementation will throw SQLFeatureNotSupportedException
+ * Updates the designated column with an Object value. The updater methods are used to update column values in the
+ * current row or the insert row. The updater methods do not update the underlying database; instead the updateRow
+ * or insertRow methods are called to update the database. If the second argument is an InputStream then the stream
+ * must contain the number of bytes specified by scaleOrLength. If the second argument is a Reader then the reader
+ * must contain the number of characters specified by scaleOrLength. If these conditions are not true the driver
+ * will generate a SQLServerException when the statement is executed. The default implementation will throw
+ * SQLFeatureNotSupportedException.
*
* @param columnName
- * the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the
- * column
+ * the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then
+ * the label is the name of the column
* @param obj
- * the new column value
+ * the new column value
* @param targetSqlType
- * the SQL type to be sent to the database
+ * the SQL type to be sent to the database
* @param scale
- * for an object of java.math.BigDecimal , this is the number of digits after the decimal point. For Java Object types InputStream and
- * Reader, this is the length of the data in the stream or reader. For all other types, this value will be ignored.
+ * for an object of java.math.BigDecimal , this is the number of digits after the decimal point. For Java
+ * Object types InputStream and Reader, this is the length of the data in the stream or reader. For all other
+ * types, this value will be ignored.
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement.If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement.If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * If any errors occur.
+ * If any errors occur.
*/
- public void updateObject(String columnName,
- Object obj,
- SQLType targetSqlType,
- int scale,
+ public void updateObject(String columnName, Object obj, SQLType targetSqlType, int scale,
boolean forceEncrypt) throws SQLServerException;
/**
- * Updates the designated column with a boolean
value. The updater methods are used to update column values in the current row or the
- * insert row. The updater methods do not update the underlying database; instead the updateRow
or insertRow
methods are
- * called to update the database.
+ * Updates the designated column with a boolean
value. The updater methods are used to update column
+ * values in the current row or the insert row. The updater methods do not update the underlying database; instead
+ * the updateRow
or insertRow
methods are called to update the database.
*
* @param index
- * the first column is 1, the second is 2, ...
+ * the first column is 1, the second is 2, ...
* @param x
- * the new column value
+ * the new column value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void updateBoolean(int index,
- boolean x,
- boolean forceEncrypt) throws SQLServerException;
+ public void updateBoolean(int index, boolean x, boolean forceEncrypt) throws SQLServerException;
/**
- * Updates the designated column with a byte
value. The updater methods are used to update column values in the current row or the
- * insert row. The updater methods do not update the underlying database; instead the updateRow
or insertRow
methods are
- * called to update the database.
+ * Updates the designated column with a byte
value. The updater methods are used to update column
+ * values in the current row or the insert row. The updater methods do not update the underlying database; instead
+ * the updateRow
or insertRow
methods are called to update the database.
*
* @param index
- * the first column is 1, the second is 2, ...
+ * the first column is 1, the second is 2, ...
* @param x
- * the new column value
+ * the new column value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void updateByte(int index,
- byte x,
- boolean forceEncrypt) throws SQLServerException;
+ public void updateByte(int index, byte x, boolean forceEncrypt) throws SQLServerException;
/**
- * Updates the designated column with a short
value. The updater methods are used to update column values in the current row or the
- * insert row. The updater methods do not update the underlying database; instead the updateRow
or insertRow
methods are
- * called to update the database.
+ * Updates the designated column with a short
value. The updater methods are used to update column
+ * values in the current row or the insert row. The updater methods do not update the underlying database; instead
+ * the updateRow
or insertRow
methods are called to update the database.
*
* @param index
- * the first column is 1, the second is 2, ...
+ * the first column is 1, the second is 2, ...
* @param x
- * the new column value
+ * the new column value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void updateShort(int index,
- short x,
- boolean forceEncrypt) throws SQLServerException;
+ public void updateShort(int index, short x, boolean forceEncrypt) throws SQLServerException;
/**
- * Updates the designated column with an int
value. The updater methods are used to update column values in the current row or the
- * insert row. The updater methods do not update the underlying database; instead the updateRow
or insertRow
methods are
- * called to update the database.
+ * Updates the designated column with an int
value. The updater methods are used to update column
+ * values in the current row or the insert row. The updater methods do not update the underlying database; instead
+ * the updateRow
or insertRow
methods are called to update the database.
*
* @param index
- * the first column is 1, the second is 2, ...
+ * the first column is 1, the second is 2, ...
* @param x
- * the new column value
+ * the new column value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void updateInt(int index,
- int x,
- boolean forceEncrypt) throws SQLServerException;
+ public void updateInt(int index, int x, boolean forceEncrypt) throws SQLServerException;
/**
- * Updates the designated column with a long
value. The updater methods are used to update column values in the current row or the
- * insert row. The updater methods do not update the underlying database; instead the updateRow
or insertRow
methods are
- * called to update the database.
+ * Updates the designated column with a long
value. The updater methods are used to update column
+ * values in the current row or the insert row. The updater methods do not update the underlying database; instead
+ * the updateRow
or insertRow
methods are called to update the database.
*
* @param index
- * the first column is 1, the second is 2, ...
+ * the first column is 1, the second is 2, ...
* @param x
- * the new column value
+ * the new column value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void updateLong(int index,
- long x,
- boolean forceEncrypt) throws SQLServerException;
+ public void updateLong(int index, long x, boolean forceEncrypt) throws SQLServerException;
/**
- * Updates the designated column with a float
value. The updater methods are used to update column values in the current row or the
- * insert row. The updater methods do not update the underlying database; instead the updateRow
or insertRow
methods are
- * called to update the database.
+ * Updates the designated column with a float
value. The updater methods are used to update column
+ * values in the current row or the insert row. The updater methods do not update the underlying database; instead
+ * the updateRow
or insertRow
methods are called to update the database.
*
* @param index
- * the first column is 1, the second is 2, ...
+ * the first column is 1, the second is 2, ...
* @param x
- * the new column value
+ * the new column value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void updateFloat(int index,
- float x,
- boolean forceEncrypt) throws SQLServerException;
+ public void updateFloat(int index, float x, boolean forceEncrypt) throws SQLServerException;
/**
- * Updates the designated column with a double
value. The updater methods are used to update column values in the current row or the
- * insert row. The updater methods do not update the underlying database; instead the updateRow
or insertRow
methods are
- * called to update the database.
+ * Updates the designated column with a double
value. The updater methods are used to update column
+ * values in the current row or the insert row. The updater methods do not update the underlying database; instead
+ * the updateRow
or insertRow
methods are called to update the database.
*
* @param index
- * the first column is 1, the second is 2, ...
+ * the first column is 1, the second is 2, ...
* @param x
- * the new column value
+ * the new column value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void updateDouble(int index,
- double x,
- boolean forceEncrypt) throws SQLServerException;
+ public void updateDouble(int index, double x, boolean forceEncrypt) throws SQLServerException;
/**
- * Updates the designated column with a money
value. The updater methods are used to update column values in the current row or the
- * insert row. The updater methods do not update the underlying database; instead the updateRow
or insertRow
methods are
- * called to update the database.
+ * Updates the designated column with a money
value. The updater methods are used to update column
+ * values in the current row or the insert row. The updater methods do not update the underlying database; instead
+ * the updateRow
or insertRow
methods are called to update the database.
*
* @param index
- * the first column is 1, the second is 2, ...
+ * the first column is 1, the second is 2, ...
* @param x
- * the new column value
+ * the new column value
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void updateMoney(int index,
- BigDecimal x) throws SQLServerException;
+ public void updateMoney(int index, BigDecimal x) throws SQLServerException;
/**
- * Updates the designated column with a money
value. The updater methods are used to update column values in the current row or the
- * insert row. The updater methods do not update the underlying database; instead the updateRow
or insertRow
methods are
- * called to update the database.
+ * Updates the designated column with a money
value. The updater methods are used to update column
+ * values in the current row or the insert row. The updater methods do not update the underlying database; instead
+ * the updateRow
or insertRow
methods are called to update the database.
*
* @param index
- * the first column is 1, the second is 2, ...
+ * the first column is 1, the second is 2, ...
* @param x
- * the new column value
+ * the new column value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void updateMoney(int index,
- BigDecimal x,
- boolean forceEncrypt) throws SQLServerException;
+ public void updateMoney(int index, BigDecimal x, boolean forceEncrypt) throws SQLServerException;
/**
- * Updates the designated column with a money
value. The updater methods are used to update column values in the current row or the
- * insert row. The updater methods do not update the underlying database; instead the updateRow
or insertRow
methods are
- * called to update the database.
+ * Updates the designated column with a money
value. The updater methods are used to update column
+ * values in the current row or the insert row. The updater methods do not update the underlying database; instead
+ * the updateRow
or insertRow
methods are called to update the database.
*
* @param columnName
- * the column name
+ * the column name
* @param x
- * the new column value
+ * the new column value
* @throws SQLServerException
- * If any errors occur.
+ * If any errors occur.
*/
- public void updateMoney(String columnName,
- BigDecimal x) throws SQLServerException;
+ public void updateMoney(String columnName, BigDecimal x) throws SQLServerException;
/**
- * Updates the designated column with a money
value. The updater methods are used to update column values in the current row or the
- * insert row. The updater methods do not update the underlying database; instead the updateRow
or insertRow
methods are
- * called to update the database.
+ * Updates the designated column with a money
value. The updater methods are used to update column
+ * values in the current row or the insert row. The updater methods do not update the underlying database; instead
+ * the updateRow
or insertRow
methods are called to update the database.
*
* @param columnName
- * the column name
+ * the column name
* @param x
- * the new column value
+ * the new column value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * If any errors occur.
+ * If any errors occur.
*/
- public void updateMoney(String columnName,
- BigDecimal x,
- boolean forceEncrypt) throws SQLServerException;
+ public void updateMoney(String columnName, BigDecimal x, boolean forceEncrypt) throws SQLServerException;
/**
- * Updates the designated column with a smallmoney
value. The updater methods are used to update column values in the current row or
- * the insert row. The updater methods do not update the underlying database; instead the updateRow
or insertRow
methods
- * are called to update the database.
+ * Updates the designated column with a smallmoney
value. The updater methods are used to update column
+ * values in the current row or the insert row. The updater methods do not update the underlying database; instead
+ * the updateRow
or insertRow
methods are called to update the database.
*
* @param index
- * the first column is 1, the second is 2, ...
+ * the first column is 1, the second is 2, ...
* @param x
- * the new column value
+ * the new column value
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void updateSmallMoney(int index,
- BigDecimal x) throws SQLServerException;
+ public void updateSmallMoney(int index, BigDecimal x) throws SQLServerException;
/**
- * Updates the designated column with a smallmoney
value. The updater methods are used to update column values in the current row or
- * the insert row. The updater methods do not update the underlying database; instead the updateRow
or insertRow
methods
- * are called to update the database.
+ * Updates the designated column with a smallmoney
value. The updater methods are used to update column
+ * values in the current row or the insert row. The updater methods do not update the underlying database; instead
+ * the updateRow
or insertRow
methods are called to update the database.
*
* @param index
- * the first column is 1, the second is 2, ...
+ * the first column is 1, the second is 2, ...
* @param x
- * the new column value
+ * the new column value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void updateSmallMoney(int index,
- BigDecimal x,
- boolean forceEncrypt) throws SQLServerException;
+ public void updateSmallMoney(int index, BigDecimal x, boolean forceEncrypt) throws SQLServerException;
/**
- * Updates the designated column with a smallmoney
value. The updater methods are used to update column values in the current row or
- * the insert row. The updater methods do not update the underlying database; instead the updateRow
or insertRow
methods
- * are called to update the database.
+ * Updates the designated column with a smallmoney
value. The updater methods are used to update column
+ * values in the current row or the insert row. The updater methods do not update the underlying database; instead
+ * the updateRow
or insertRow
methods are called to update the database.
*
* @param columnName
- * the column name
+ * the column name
* @param x
- * the new column value
+ * the new column value
* @throws SQLServerException
- * If any errors occur.
+ * If any errors occur.
*/
- public void updateSmallMoney(String columnName,
- BigDecimal x) throws SQLServerException;
+ public void updateSmallMoney(String columnName, BigDecimal x) throws SQLServerException;
/**
- * Updates the designated column with a smallmoney
value. The updater methods are used to update column values in the current row or
- * the insert row. The updater methods do not update the underlying database; instead the updateRow
or insertRow
methods
- * are called to update the database.
+ * Updates the designated column with a smallmoney
value. The updater methods are used to update column
+ * values in the current row or the insert row. The updater methods do not update the underlying database; instead
+ * the updateRow
or insertRow
methods are called to update the database.
*
* @param columnName
- * the column name
+ * the column name
* @param x
- * the new column value
+ * the new column value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * If any errors occur.
+ * If any errors occur.
*/
- public void updateSmallMoney(String columnName,
- BigDecimal x,
- boolean forceEncrypt) throws SQLServerException;
+ public void updateSmallMoney(String columnName, BigDecimal x, boolean forceEncrypt) throws SQLServerException;
/**
- * Updates the designated column with a java.math.BigDecimal
value. The updater methods are used to update column values in the
- * current row or the insert row. The updater methods do not update the underlying database; instead the updateRow
or
- * insertRow
methods are called to update the database.
+ * Updates the designated column with a java.math.BigDecimal
value. The updater methods are used to
+ * update column values in the current row or the insert row. The updater methods do not update the underlying
+ * database; instead the updateRow
or insertRow
methods are called to update the database.
*
* @param index
- * the first column is 1, the second is 2, ...
+ * the first column is 1, the second is 2, ...
* @param x
- * the new column value
+ * the new column value
* @param precision
- * the precision of the column
+ * the precision of the column
* @param scale
- * the scale of the column
+ * the scale of the column
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void updateBigDecimal(int index,
- BigDecimal x,
- Integer precision,
- Integer scale) throws SQLServerException;
+ public void updateBigDecimal(int index, BigDecimal x, Integer precision, Integer scale) throws SQLServerException;
/**
- * Updates the designated column with a java.math.BigDecimal
value. The updater methods are used to update column values in the
- * current row or the insert row. The updater methods do not update the underlying database; instead the updateRow
or
- * insertRow
methods are called to update the database.
+ * Updates the designated column with a java.math.BigDecimal
value. The updater methods are used to
+ * update column values in the current row or the insert row. The updater methods do not update the underlying
+ * database; instead the updateRow
or insertRow
methods are called to update the database.
*
* @param index
- * the first column is 1, the second is 2, ...
+ * the first column is 1, the second is 2, ...
* @param x
- * the new column value
+ * the new column value
* @param precision
- * the precision of the column
+ * the precision of the column
* @param scale
- * the scale of the column
+ * the scale of the column
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void updateBigDecimal(int index,
- BigDecimal x,
- Integer precision,
- Integer scale,
+ public void updateBigDecimal(int index, BigDecimal x, Integer precision, Integer scale,
boolean forceEncrypt) throws SQLServerException;
/**
- * Updates the designated column with a String
value. The updater methods are used to update column values in the current row or the
- * insert row. The updater methods do not update the underlying database; instead the updateRow
or insertRow
methods are
- * called to update the database.
+ * Updates the designated column with a String
value. The updater methods are used to update column
+ * values in the current row or the insert row. The updater methods do not update the underlying database; instead
+ * the updateRow
or insertRow
methods are called to update the database.
*
* @param columnIndex
- * the first column is 1, the second is 2, ...
+ * the first column is 1, the second is 2, ...
* @param stringValue
- * the new column value
+ * the new column value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void updateString(int columnIndex,
- String stringValue,
- boolean forceEncrypt) throws SQLServerException;
+ public void updateString(int columnIndex, String stringValue, boolean forceEncrypt) throws SQLServerException;
/**
- * Updates the designated column with a String
value. It is intended for use when updating NCHAR
,NVARCHAR
- * and LONGNVARCHAR
columns. The updater methods are used to update column values in the current row or the insert row. The updater
- * methods do not update the underlying database; instead the updateRow
or insertRow
methods are called to update the
- * database.
+ * Updates the designated column with a String
value. It is intended for use when updating
+ * NCHAR
,NVARCHAR
and LONGNVARCHAR
columns. The updater methods are used to
+ * update column values in the current row or the insert row. The updater methods do not update the underlying
+ * database; instead the updateRow
or insertRow
methods are called to update the database.
*
* @param columnIndex
- * the first column is 1, the second 2, ...
+ * the first column is 1, the second 2, ...
* @param nString
- * the value for the column to be updated
+ * the value for the column to be updated
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void updateNString(int columnIndex,
- String nString,
- boolean forceEncrypt) throws SQLServerException;
+ public void updateNString(int columnIndex, String nString, boolean forceEncrypt) throws SQLServerException;
/**
- * Updates the designated column with a String
value. It is intended for use when updating NCHAR
,NVARCHAR
- * and LONGNVARCHAR
columns. The updater methods are used to update column values in the current row or the insert row. The updater
- * methods do not update the underlying database; instead the updateRow
or insertRow
methods are called to update the
- * database.
+ * Updates the designated column with a String
value. It is intended for use when updating
+ * NCHAR
,NVARCHAR
and LONGNVARCHAR
columns. The updater methods are used to
+ * update column values in the current row or the insert row. The updater methods do not update the underlying
+ * database; instead the updateRow
or insertRow
methods are called to update the database.
*
* @param columnLabel
- * the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the
- * column
+ * the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then
+ * the label is the name of the column
* @param nString
- * the value for the column to be updated
+ * the value for the column to be updated
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void updateNString(String columnLabel,
- String nString,
- boolean forceEncrypt) throws SQLServerException;
+ public void updateNString(String columnLabel, String nString, boolean forceEncrypt) throws SQLServerException;
/**
- * Updates the designated column with a byte
array value. The updater methods are used to update column values in the current row or
- * the insert row. The updater methods do not update the underlying database; instead the updateRow
or insertRow
methods
- * are called to update the database.
+ * Updates the designated column with a byte
array value. The updater methods are used to update column
+ * values in the current row or the insert row. The updater methods do not update the underlying database; instead
+ * the updateRow
or insertRow
methods are called to update the database.
*
* @param index
- * the first column is 1, the second is 2, ...
+ * the first column is 1, the second is 2, ...
* @param x
- * the new column value
+ * the new column value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void updateBytes(int index,
- byte x[],
- boolean forceEncrypt) throws SQLServerException;
+ public void updateBytes(int index, byte x[], boolean forceEncrypt) throws SQLServerException;
/**
- * Updates the designated column with a java.sql.Date
value. The updater methods are used to update column values in the current row
- * or the insert row. The updater methods do not update the underlying database; instead the updateRow
or insertRow
- * methods are called to update the database.
+ * Updates the designated column with a java.sql.Date
value. The updater methods are used to update
+ * column values in the current row or the insert row. The updater methods do not update the underlying database;
+ * instead the updateRow
or insertRow
methods are called to update the database.
*
* @param index
- * the first column is 1, the second is 2, ...
+ * the first column is 1, the second is 2, ...
* @param x
- * the new column value
+ * the new column value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void updateDate(int index,
- java.sql.Date x,
- boolean forceEncrypt) throws SQLServerException;
+ public void updateDate(int index, java.sql.Date x, boolean forceEncrypt) throws SQLServerException;
/**
- * Updates the designated column with a java.sql.Time
value. The updater methods are used to update column values in the current row
- * or the insert row. The updater methods do not update the underlying database; instead the updateRow
or insertRow
- * methods are called to update the database.
+ * Updates the designated column with a java.sql.Time
value. The updater methods are used to update
+ * column values in the current row or the insert row. The updater methods do not update the underlying database;
+ * instead the updateRow
or insertRow
methods are called to update the database.
*
* @param index
- * the first column is 1, the second is 2, ...
+ * the first column is 1, the second is 2, ...
* @param x
- * the new column value
+ * the new column value
* @param scale
- * the scale of the column
+ * the scale of the column
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void updateTime(int index,
- java.sql.Time x,
- Integer scale) throws SQLServerException;
+ public void updateTime(int index, java.sql.Time x, Integer scale) throws SQLServerException;
/**
- * Updates the designated column with a java.sql.Time
value. The updater methods are used to update column values in the current row
- * or the insert row. The updater methods do not update the underlying database; instead the updateRow
or insertRow
- * methods are called to update the database.
+ * Updates the designated column with a java.sql.Time
value. The updater methods are used to update
+ * column values in the current row or the insert row. The updater methods do not update the underlying database;
+ * instead the updateRow
or insertRow
methods are called to update the database.
*
* @param index
- * the first column is 1, the second is 2, ...
+ * the first column is 1, the second is 2, ...
* @param x
- * the new column value
+ * the new column value
* @param scale
- * the scale of the column
+ * the scale of the column
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void updateTime(int index,
- java.sql.Time x,
- Integer scale,
- boolean forceEncrypt) throws SQLServerException;
+ public void updateTime(int index, java.sql.Time x, Integer scale, boolean forceEncrypt) throws SQLServerException;
/**
- * Updates the designated column with a java.sql.Timestamp
value. The updater methods are used to update column values in the current
- * row or the insert row. The updater methods do not update the underlying database; instead the updateRow
or insertRow
- * methods are called to update the database.
+ * Updates the designated column with a java.sql.Timestamp
value. The updater methods are used to
+ * update column values in the current row or the insert row. The updater methods do not update the underlying
+ * database; instead the updateRow
or insertRow
methods are called to update the database.
*
* @param index
- * the first column is 1, the second is 2, ...
+ * the first column is 1, the second is 2, ...
* @param x
- * the new column value
+ * the new column value
* @param scale
- * the scale of the column
+ * the scale of the column
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void updateTimestamp(int index,
- java.sql.Timestamp x,
- int scale) throws SQLServerException;
+ public void updateTimestamp(int index, java.sql.Timestamp x, int scale) throws SQLServerException;
/**
- * Updates the designated column with a java.sql.Timestamp
value. The updater methods are used to update column values in the current
- * row or the insert row. The updater methods do not update the underlying database; instead the updateRow
or insertRow
- * methods are called to update the database.
+ * Updates the designated column with a java.sql.Timestamp
value. The updater methods are used to
+ * update column values in the current row or the insert row. The updater methods do not update the underlying
+ * database; instead the updateRow
or insertRow
methods are called to update the database.
*
* @param index
- * the first column is 1, the second is 2, ...
+ * the first column is 1, the second is 2, ...
* @param x
- * the new column value
+ * the new column value
* @param scale
- * the scale of the column
+ * the scale of the column
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void updateTimestamp(int index,
- java.sql.Timestamp x,
- int scale,
+ public void updateTimestamp(int index, java.sql.Timestamp x, int scale,
boolean forceEncrypt) throws SQLServerException;
/**
- * Updates the designated column with a java.sql.Timestamp
value. The updater methods are used to update column values in the current
- * row or the insert row. The updater methods do not update the underlying database; instead the updateRow
or insertRow
- * methods are called to update the database.
+ * Updates the designated column with a java.sql.Timestamp
value. The updater methods are used to
+ * update column values in the current row or the insert row. The updater methods do not update the underlying
+ * database; instead the updateRow
or insertRow
methods are called to update the database.
*
* @param index
- * the first column is 1, the second is 2, ...
+ * the first column is 1, the second is 2, ...
* @param x
- * the new column value
+ * the new column value
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void updateDateTime(int index,
- java.sql.Timestamp x) throws SQLServerException;
+ public void updateDateTime(int index, java.sql.Timestamp x) throws SQLServerException;
/**
- * Updates the designated column with a java.sql.Timestamp
value. The updater methods are used to update column values in the current
- * row or the insert row. The updater methods do not update the underlying database; instead the updateRow
or insertRow
- * methods are called to update the database.
+ * Updates the designated column with a java.sql.Timestamp
value. The updater methods are used to
+ * update column values in the current row or the insert row. The updater methods do not update the underlying
+ * database; instead the updateRow
or insertRow
methods are called to update the database.
*
* @param index
- * the first column is 1, the second is 2, ...
+ * the first column is 1, the second is 2, ...
* @param x
- * the new column value
+ * the new column value
* @param scale
- * the scale of the column
+ * the scale of the column
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void updateDateTime(int index,
- java.sql.Timestamp x,
- Integer scale) throws SQLServerException;
+ public void updateDateTime(int index, java.sql.Timestamp x, Integer scale) throws SQLServerException;
/**
- * Updates the designated column with a java.sql.Timestamp
value. The updater methods are used to update column values in the current
- * row or the insert row. The updater methods do not update the underlying database; instead the updateRow
or insertRow
- * methods are called to update the database.
+ * Updates the designated column with a java.sql.Timestamp
value. The updater methods are used to
+ * update column values in the current row or the insert row. The updater methods do not update the underlying
+ * database; instead the updateRow
or insertRow
methods are called to update the database.
*
* @param index
- * the first column is 1, the second is 2, ...
+ * the first column is 1, the second is 2, ...
* @param x
- * the new column value
+ * the new column value
* @param scale
- * the scale of the column
+ * the scale of the column
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void updateDateTime(int index,
- java.sql.Timestamp x,
- Integer scale,
+ public void updateDateTime(int index, java.sql.Timestamp x, Integer scale,
boolean forceEncrypt) throws SQLServerException;
/**
- * Updates the designated column with a java.sql.Timestamp
value. The updater methods are used to update column values in the current
- * row or the insert row. The updater methods do not update the underlying database; instead the updateRow
or insertRow
- * methods are called to update the database.
+ * Updates the designated column with a java.sql.Timestamp
value. The updater methods are used to
+ * update column values in the current row or the insert row. The updater methods do not update the underlying
+ * database; instead the updateRow
or insertRow
methods are called to update the database.
*
* @param index
- * the first column is 1, the second is 2, ...
+ * the first column is 1, the second is 2, ...
* @param x
- * the new column value
+ * the new column value
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void updateSmallDateTime(int index,
- java.sql.Timestamp x) throws SQLServerException;
+ public void updateSmallDateTime(int index, java.sql.Timestamp x) throws SQLServerException;
/**
- * Updates the designated column with a java.sql.Timestamp
value. The updater methods are used to update column values in the current
- * row or the insert row. The updater methods do not update the underlying database; instead the updateRow
or insertRow
- * methods are called to update the database.
+ * Updates the designated column with a java.sql.Timestamp
value. The updater methods are used to
+ * update column values in the current row or the insert row. The updater methods do not update the underlying
+ * database; instead the updateRow
or insertRow
methods are called to update the database.
*
* @param index
- * the first column is 1, the second is 2, ...
+ * the first column is 1, the second is 2, ...
* @param x
- * the new column value
+ * the new column value
* @param scale
- * the scale of the column
+ * the scale of the column
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void updateSmallDateTime(int index,
- java.sql.Timestamp x,
- Integer scale) throws SQLServerException;
+ public void updateSmallDateTime(int index, java.sql.Timestamp x, Integer scale) throws SQLServerException;
/**
- * Updates the designated column with a java.sql.Timestamp
value. The updater methods are used to update column values in the current
- * row or the insert row. The updater methods do not update the underlying database; instead the updateRow
or insertRow
- * methods are called to update the database.
+ * Updates the designated column with a java.sql.Timestamp
value. The updater methods are used to
+ * update column values in the current row or the insert row. The updater methods do not update the underlying
+ * database; instead the updateRow
or insertRow
methods are called to update the database.
*
* @param index
- * the first column is 1, the second is 2, ...
+ * the first column is 1, the second is 2, ...
* @param x
- * the new column value
+ * the new column value
* @param scale
- * the scale of the column
+ * the scale of the column
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void updateSmallDateTime(int index,
- java.sql.Timestamp x,
- Integer scale,
+ public void updateSmallDateTime(int index, java.sql.Timestamp x, Integer scale,
boolean forceEncrypt) throws SQLServerException;
/**
* Updates the value of the column specified to the DateTimeOffset Class value, given a zero-based column ordinal.
*
* @param index
- * The zero-based ordinal of a column.
+ * The zero-based ordinal of a column.
* @param x
- * A DateTimeOffset Class object.
+ * A DateTimeOffset Class object.
* @param scale
- * scale of the column
+ * scale of the column
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void updateDateTimeOffset(int index,
- microsoft.sql.DateTimeOffset x,
+ public void updateDateTimeOffset(int index, microsoft.sql.DateTimeOffset x,
Integer scale) throws SQLServerException;
/**
* Updates the value of the column specified to the DateTimeOffset Class value, given a zero-based column ordinal.
*
* @param index
- * The zero-based ordinal of a column.
+ * The zero-based ordinal of a column.
* @param x
- * A DateTimeOffset Class object.
+ * A DateTimeOffset Class object.
* @param scale
- * scale of the column
+ * scale of the column
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void updateDateTimeOffset(int index,
- microsoft.sql.DateTimeOffset x,
- Integer scale,
+ public void updateDateTimeOffset(int index, microsoft.sql.DateTimeOffset x, Integer scale,
boolean forceEncrypt) throws SQLServerException;
/**
- * Updates the designated column with a String
value. The updater methods are used to update column values in the current row or the
- * insert row. The updater methods do not update the underlying database; instead the updateRow
or insertRow
methods are
- * called to update the database.
+ * Updates the designated column with a String
value. The updater methods are used to update column
+ * values in the current row or the insert row. The updater methods do not update the underlying database; instead
+ * the updateRow
or insertRow
methods are called to update the database.
*
* @param index
- * The zero-based ordinal of a column.
+ * The zero-based ordinal of a column.
* @param x
- * the new column value
+ * the new column value
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void updateUniqueIdentifier(int index,
- String x) throws SQLServerException;
+ public void updateUniqueIdentifier(int index, String x) throws SQLServerException;
/**
- * Updates the designated column with a String
value. The updater methods are used to update column values in the current row or the
- * insert row. The updater methods do not update the underlying database; instead the updateRow
or insertRow
methods are
- * called to update the database.
+ * Updates the designated column with a String
value. The updater methods are used to update column
+ * values in the current row or the insert row. The updater methods do not update the underlying database; instead
+ * the updateRow
or insertRow
methods are called to update the database.
*
* @param index
- * The zero-based ordinal of a column.
+ * The zero-based ordinal of a column.
* @param x
- * the new column value
+ * the new column value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void updateUniqueIdentifier(int index,
- String x,
- boolean forceEncrypt) throws SQLServerException;
+ public void updateUniqueIdentifier(int index, String x, boolean forceEncrypt) throws SQLServerException;
/**
* Updates the designated column with an {@code Object} value.
*
- * The updater methods are used to update column values in the current row or the insert row. The updater methods do not update the underlying
- * database; instead the {@code updateRow} or {@code insertRow} methods are called to update the database.
+ * The updater methods are used to update column values in the current row or the insert row. The updater methods do
+ * not update the underlying database; instead the {@code updateRow} or {@code insertRow} methods are called to
+ * update the database.
*
* @param index
- * the first column is 1, the second is 2, ...
+ * the first column is 1, the second is 2, ...
* @param x
- * the new column value
+ * the new column value
* @param precision
- * the precision of the column
+ * the precision of the column
* @param scale
- * the scale of the column
+ * the scale of the column
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void updateObject(int index,
- Object x,
- int precision,
- int scale,
+ public void updateObject(int index, Object x, int precision, int scale,
boolean forceEncrypt) throws SQLServerException;
/**
- * Updates the designated column with a boolean
value. The updater methods are used to update column values in the current row or the
- * insert row. The updater methods do not update the underlying database; instead the updateRow
or insertRow
methods are
- * called to update the database.
+ * Updates the designated column with a boolean
value. The updater methods are used to update column
+ * values in the current row or the insert row. The updater methods do not update the underlying database; instead
+ * the updateRow
or insertRow
methods are called to update the database.
*
* @param columnName
- * the name of the column
+ * the name of the column
* @param x
- * the new column value
+ * the new column value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public void updateBoolean(String columnName,
- boolean x,
- boolean forceEncrypt) throws SQLServerException;
+ public void updateBoolean(String columnName, boolean x, boolean forceEncrypt) throws SQLServerException;
/**
- * Updates the designated column with a byte
value. The updater methods are used to update column values in the current row or the
- * insert row. The updater methods do not update the underlying database; instead the updateRow
or insertRow
methods are
- * called to update the database.
+ * Updates the designated column with a byte
value. The updater methods are used to update column
+ * values in the current row or the insert row. The updater methods do not update the underlying database; instead
+ * the updateRow
or insertRow
methods are called to update the database.
*
*
* @param columnName
- * the name of the column
+ * the name of the column
* @param x
- * the new column value
+ * the new column value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * If any errors occur.
+ * If any errors occur.
*/
- public void updateByte(String columnName,
- byte x,
- boolean forceEncrypt) throws SQLServerException;
+ public void updateByte(String columnName, byte x, boolean forceEncrypt) throws SQLServerException;
/**
- * Updates the designated column with a short
value. The updater methods are used to update column values in the current row or the
- * insert row. The updater methods do not update the underlying database; instead the updateRow
or insertRow
methods are
- * called to update the database.
+ * Updates the designated column with a short
value. The updater methods are used to update column
+ * values in the current row or the insert row. The updater methods do not update the underlying database; instead
+ * the updateRow
or insertRow
methods are called to update the database.
*
* @param columnName
- * the name of the column
+ * the name of the column
* @param x
- * the new column value
+ * the new column value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * If any errors occur.
+ * If any errors occur.
*/
- public void updateShort(String columnName,
- short x,
- boolean forceEncrypt) throws SQLServerException;
+ public void updateShort(String columnName, short x, boolean forceEncrypt) throws SQLServerException;
/**
- * Updates the designated column with an int
value. The updater methods are used to update column values in the current row or the
- * insert row. The updater methods do not update the underlying database; instead the updateRow
or insertRow
methods are
- * called to update the database.
+ * Updates the designated column with an int
value. The updater methods are used to update column
+ * values in the current row or the insert row. The updater methods do not update the underlying database; instead
+ * the updateRow
or insertRow
methods are called to update the database.
*
* @param columnName
- * is the name of the column
+ * is the name of the column
* @param x
- * the new column value
+ * the new column value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * If any errors occur.
+ * If any errors occur.
*/
- public void updateInt(String columnName,
- int x,
- boolean forceEncrypt) throws SQLServerException;
+ public void updateInt(String columnName, int x, boolean forceEncrypt) throws SQLServerException;
/**
- * Updates the designated column with a long
value. The updater methods are used to update column values in the current row or the
- * insert row. The updater methods do not update the underlying database; instead the updateRow
or insertRow
methods are
- * called to update the database.
+ * Updates the designated column with a long
value. The updater methods are used to update column
+ * values in the current row or the insert row. The updater methods do not update the underlying database; instead
+ * the updateRow
or insertRow
methods are called to update the database.
*
* @param columnName
- * is the name of the column
+ * is the name of the column
* @param x
- * the new column value
+ * the new column value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * If any errors occur.
+ * If any errors occur.
*/
- public void updateLong(String columnName,
- long x,
- boolean forceEncrypt) throws SQLServerException;
+ public void updateLong(String columnName, long x, boolean forceEncrypt) throws SQLServerException;
/**
- * Updates the designated column with a float
value. The updater methods are used to update column values in the current row or the
- * insert row. The updater methods do not update the underlying database; instead the updateRow
or insertRow
methods are
- * called to update the database.
+ * Updates the designated column with a float
value. The updater methods are used to update column
+ * values in the current row or the insert row. The updater methods do not update the underlying database; instead
+ * the updateRow
or insertRow
methods are called to update the database.
*
* @param columnName
- * is the name of the column
+ * is the name of the column
* @param x
- * the new column value
+ * the new column value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * If any errors occur.
+ * If any errors occur.
*/
- public void updateFloat(String columnName,
- float x,
- boolean forceEncrypt) throws SQLServerException;
+ public void updateFloat(String columnName, float x, boolean forceEncrypt) throws SQLServerException;
/**
- * Updates the designated column with a double
value. The updater methods are used to update column values in the current row or the
- * insert row. The updater methods do not update the underlying database; instead the updateRow
or insertRow
methods are
- * called to update the database.
+ * Updates the designated column with a double
value. The updater methods are used to update column
+ * values in the current row or the insert row. The updater methods do not update the underlying database; instead
+ * the updateRow
or insertRow
methods are called to update the database.
*
* @param columnName
- * is the name of the column
+ * is the name of the column
* @param x
- * the new column value
+ * the new column value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * If any errors occur.
+ * If any errors occur.
*/
- public void updateDouble(String columnName,
- double x,
- boolean forceEncrypt) throws SQLServerException;
+ public void updateDouble(String columnName, double x, boolean forceEncrypt) throws SQLServerException;
/**
- * Updates the designated column with a java.sql.BigDecimal
value. The updater methods are used to update column values in the
- * current row or the insert row. The updater methods do not update the underlying database; instead the updateRow
or
- * insertRow
methods are called to update the database.
+ * Updates the designated column with a java.sql.BigDecimal
value. The updater methods are used to
+ * update column values in the current row or the insert row. The updater methods do not update the underlying
+ * database; instead the updateRow
or insertRow
methods are called to update the database.
*
* @param columnName
- * is the name of the column
+ * is the name of the column
* @param x
- * the new column value
+ * the new column value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * If any errors occur.
+ * If any errors occur.
*/
- public void updateBigDecimal(String columnName,
- BigDecimal x,
- boolean forceEncrypt) throws SQLServerException;
+ public void updateBigDecimal(String columnName, BigDecimal x, boolean forceEncrypt) throws SQLServerException;
/**
- * Updates the designated column with a java.sql.BigDecimal
value. The updater methods are used to update column values in the
- * current row or the insert row. The updater methods do not update the underlying database; instead the updateRow
or
- * insertRow
methods are called to update the database.
+ * Updates the designated column with a java.sql.BigDecimal
value. The updater methods are used to
+ * update column values in the current row or the insert row. The updater methods do not update the underlying
+ * database; instead the updateRow
or insertRow
methods are called to update the database.
*
* @param columnName
- * is the name of the column and Always Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set
- * to false, the driver will not force encryption on parameters.
+ * is the name of the column and Always Encrypted is enabled on the connection or on the statement. If the
+ * boolean forceEncrypt is set to false, the driver will not force encryption on parameters.
* @param x
- * BigDecimal value
+ * BigDecimal value
* @param precision
- * the precision of the column
+ * the precision of the column
* @param scale
- * the scale of the column
+ * the scale of the column
* @throws SQLServerException
- * If any errors occur.
+ * If any errors occur.
*/
- public void updateBigDecimal(String columnName,
- BigDecimal x,
- Integer precision,
+ public void updateBigDecimal(String columnName, BigDecimal x, Integer precision,
Integer scale) throws SQLServerException;
/**
- * Updates the designated column with a java.sql.BigDecimal
value. The updater methods are used to update column values in the
- * current row or the insert row. The updater methods do not update the underlying database; instead the updateRow
or
- * insertRow
methods are called to update the database.
+ * Updates the designated column with a java.sql.BigDecimal
value. The updater methods are used to
+ * update column values in the current row or the insert row. The updater methods do not update the underlying
+ * database; instead the updateRow
or insertRow
methods are called to update the database.
*
* @param columnName
- * is the name of the column and Always Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set
- * to false, the driver will not force encryption on parameters.
+ * is the name of the column and Always Encrypted is enabled on the connection or on the statement. If the
+ * boolean forceEncrypt is set to false, the driver will not force encryption on parameters.
* @param x
- * BigDecimal value
+ * BigDecimal value
* @param precision
- * the precision of the column
+ * the precision of the column
* @param scale
- * the scale of the column
+ * the scale of the column
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * If any errors occur.
+ * If any errors occur.
*/
- public void updateBigDecimal(String columnName,
- BigDecimal x,
- Integer precision,
- Integer scale,
+ public void updateBigDecimal(String columnName, BigDecimal x, Integer precision, Integer scale,
boolean forceEncrypt) throws SQLServerException;
/**
- * Updates the designated column with a String
value. The updater methods are used to update column values in the current row or the
- * insert row. The updater methods do not update the underlying database; instead the updateRow
or insertRow
methods are
- * called to update the database.
+ * Updates the designated column with a String
value. The updater methods are used to update column
+ * values in the current row or the insert row. The updater methods do not update the underlying database; instead
+ * the updateRow
or insertRow
methods are called to update the database.
*
* @param columnName
- * is the name of the column
+ * is the name of the column
* @param x
- * the new column value
+ * the new column value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * If any errors occur.
+ * If any errors occur.
*/
- public void updateString(String columnName,
- String x,
- boolean forceEncrypt) throws SQLServerException;
+ public void updateString(String columnName, String x, boolean forceEncrypt) throws SQLServerException;
/**
* Updates the designated column with a byte array value.
*
- * The updater methods are used to update column values in the current row or the insert row. The updater methods do not update the underlying
- * database; instead the updateRow
or insertRow
methods are called to update the database.
+ * The updater methods are used to update column values in the current row or the insert row. The updater methods do
+ * not update the underlying database; instead the updateRow
or insertRow
methods are
+ * called to update the database.
*
* @param columnName
- * is the name of the column
+ * is the name of the column
* @param x
- * the new column value
+ * the new column value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * If any errors occur.
+ * If any errors occur.
*/
- public void updateBytes(String columnName,
- byte x[],
- boolean forceEncrypt) throws SQLServerException;
+ public void updateBytes(String columnName, byte x[], boolean forceEncrypt) throws SQLServerException;
/**
- * Updates the designated column with a java.sql.Date
value. The updater methods are used to update column values in the current row
- * or the insert row. The updater methods do not update the underlying database; instead the updateRow
or insertRow
- * methods are called to update the database.
+ * Updates the designated column with a java.sql.Date
value. The updater methods are used to update
+ * column values in the current row or the insert row. The updater methods do not update the underlying database;
+ * instead the updateRow
or insertRow
methods are called to update the database.
*
* @param columnName
- * is the name of the column
+ * is the name of the column
* @param x
- * the new column value
+ * the new column value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * If any errors occur.
+ * If any errors occur.
*/
- public void updateDate(String columnName,
- java.sql.Date x,
- boolean forceEncrypt) throws SQLServerException;
+ public void updateDate(String columnName, java.sql.Date x, boolean forceEncrypt) throws SQLServerException;
/**
- * Updates the designated column with a java.sql.Time
value. The updater methods are used to update column values in the current row
- * or the insert row. The updater methods do not update the underlying database; instead the updateRow
or insertRow
- * methods are called to update the database.
+ * Updates the designated column with a java.sql.Time
value. The updater methods are used to update
+ * column values in the current row or the insert row. The updater methods do not update the underlying database;
+ * instead the updateRow
or insertRow
methods are called to update the database.
*
* @param columnName
- * is the name of the column
+ * is the name of the column
* @param x
- * the new column value
+ * the new column value
* @param scale
- * the scale of the column
+ * the scale of the column
* @throws SQLServerException
- * If any errors occur.
+ * If any errors occur.
*/
- public void updateTime(String columnName,
- java.sql.Time x,
- int scale) throws SQLServerException;
+ public void updateTime(String columnName, java.sql.Time x, int scale) throws SQLServerException;
/**
- * Updates the designated column with a java.sql.Time
value. The updater methods are used to update column values in the current row
- * or the insert row. The updater methods do not update the underlying database; instead the updateRow
or insertRow
- * methods are called to update the database.
+ * Updates the designated column with a java.sql.Time
value. The updater methods are used to update
+ * column values in the current row or the insert row. The updater methods do not update the underlying database;
+ * instead the updateRow
or insertRow
methods are called to update the database.
*
* @param columnName
- * is the name of the column
+ * is the name of the column
* @param x
- * the new column value
+ * the new column value
* @param scale
- * the scale of the column
+ * the scale of the column
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * If any errors occur.
+ * If any errors occur.
*/
- public void updateTime(String columnName,
- java.sql.Time x,
- int scale,
+ public void updateTime(String columnName, java.sql.Time x, int scale,
boolean forceEncrypt) throws SQLServerException;
/**
- * Updates the designated column with a java.sql.Timestamp
value. The updater methods are used to update column values in the current
- * row or the insert row. The updater methods do not update the underlying database; instead the updateRow
or insertRow
- * methods are called to update the database.
+ * Updates the designated column with a java.sql.Timestamp
value. The updater methods are used to
+ * update column values in the current row or the insert row. The updater methods do not update the underlying
+ * database; instead the updateRow
or insertRow
methods are called to update the database.
*
* @param columnName
- * is the name of the column
+ * is the name of the column
* @param x
- * the new column value
+ * the new column value
* @param scale
- * the scale of the column
+ * the scale of the column
* @throws SQLServerException
- * If any errors occur.
+ * If any errors occur.
*/
- public void updateTimestamp(String columnName,
- java.sql.Timestamp x,
- int scale) throws SQLServerException;
+ public void updateTimestamp(String columnName, java.sql.Timestamp x, int scale) throws SQLServerException;
/**
- * Updates the designated column with a java.sql.Timestamp
value. The updater methods are used to update column values in the current
- * row or the insert row. The updater methods do not update the underlying database; instead the updateRow
or insertRow
- * methods are called to update the database.
+ * Updates the designated column with a java.sql.Timestamp
value. The updater methods are used to
+ * update column values in the current row or the insert row. The updater methods do not update the underlying
+ * database; instead the updateRow
or insertRow
methods are called to update the database.
*
* @param columnName
- * is the name of the column
+ * is the name of the column
* @param x
- * the new column value
+ * the new column value
* @param scale
- * the scale of the column
+ * the scale of the column
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * If any errors occur.
+ * If any errors occur.
*/
- public void updateTimestamp(String columnName,
- java.sql.Timestamp x,
- int scale,
+ public void updateTimestamp(String columnName, java.sql.Timestamp x, int scale,
boolean forceEncrypt) throws SQLServerException;
/**
- * Updates the designated column with a java.sql.Timestamp
value. The updater methods are used to update column values in the current
- * row or the insert row. The updater methods do not update the underlying database; instead the updateRow
or insertRow
- * methods are called to update the database.
+ * Updates the designated column with a java.sql.Timestamp
value. The updater methods are used to
+ * update column values in the current row or the insert row. The updater methods do not update the underlying
+ * database; instead the updateRow
or insertRow
methods are called to update the database.
*
* @param columnName
- * is the name of the column
+ * is the name of the column
* @param x
- * the new column value
+ * the new column value
* @throws SQLServerException
- * If any errors occur.
+ * If any errors occur.
*/
- public void updateDateTime(String columnName,
- java.sql.Timestamp x) throws SQLServerException;
+ public void updateDateTime(String columnName, java.sql.Timestamp x) throws SQLServerException;
/**
- * Updates the designated column with a java.sql.Timestamp
value. The updater methods are used to update column values in the current
- * row or the insert row. The updater methods do not update the underlying database; instead the updateRow
or insertRow
- * methods are called to update the database.
+ * Updates the designated column with a java.sql.Timestamp
value. The updater methods are used to
+ * update column values in the current row or the insert row. The updater methods do not update the underlying
+ * database; instead the updateRow
or insertRow
methods are called to update the database.
*
* @param columnName
- * is the name of the column
+ * is the name of the column
* @param x
- * the new column value
+ * the new column value
* @param scale
- * the scale of the column
+ * the scale of the column
* @throws SQLServerException
- * If any errors occur.
+ * If any errors occur.
*/
- public void updateDateTime(String columnName,
- java.sql.Timestamp x,
- int scale) throws SQLServerException;
+ public void updateDateTime(String columnName, java.sql.Timestamp x, int scale) throws SQLServerException;
/**
- * Updates the designated column with a java.sql.Timestamp
value. The updater methods are used to update column values in the current
- * row or the insert row. The updater methods do not update the underlying database; instead the updateRow
or insertRow
- * methods are called to update the database.
+ * Updates the designated column with a java.sql.Timestamp
value. The updater methods are used to
+ * update column values in the current row or the insert row. The updater methods do not update the underlying
+ * database; instead the updateRow
or insertRow
methods are called to update the database.
*
* @param columnName
- * is the name of the column
+ * is the name of the column
* @param x
- * the new column value
+ * the new column value
* @param scale
- * the scale of the column
+ * the scale of the column
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * If any errors occur.
+ * If any errors occur.
*/
- public void updateDateTime(String columnName,
- java.sql.Timestamp x,
- int scale,
+ public void updateDateTime(String columnName, java.sql.Timestamp x, int scale,
boolean forceEncrypt) throws SQLServerException;
/**
- * Updates the designated column with a java.sql.Timestamp
value. The updater methods are used to update column values in the current
- * row or the insert row. The updater methods do not update the underlying database; instead the updateRow
or insertRow
- * methods are called to update the database.
+ * Updates the designated column with a java.sql.Timestamp
value. The updater methods are used to
+ * update column values in the current row or the insert row. The updater methods do not update the underlying
+ * database; instead the updateRow
or insertRow
methods are called to update the database.
*
* @param columnName
- * is the name of the column
+ * is the name of the column
* @param x
- * the new column value
+ * the new column value
* @throws SQLServerException
- * If any errors occur.
+ * If any errors occur.
*/
- public void updateSmallDateTime(String columnName,
- java.sql.Timestamp x) throws SQLServerException;
+ public void updateSmallDateTime(String columnName, java.sql.Timestamp x) throws SQLServerException;
/**
- * Updates the designated column with a java.sql.Timestamp
value. The updater methods are used to update column values in the current
- * row or the insert row. The updater methods do not update the underlying database; instead the updateRow
or insertRow
- * methods are called to update the database.
+ * Updates the designated column with a java.sql.Timestamp
value. The updater methods are used to
+ * update column values in the current row or the insert row. The updater methods do not update the underlying
+ * database; instead the updateRow
or insertRow
methods are called to update the database.
*
* @param columnName
- * is the name of the column
+ * is the name of the column
* @param x
- * the new column value
+ * the new column value
* @param scale
- * the scale of the column
+ * the scale of the column
* @throws SQLServerException
- * If any errors occur.
+ * If any errors occur.
*/
- public void updateSmallDateTime(String columnName,
- java.sql.Timestamp x,
- int scale) throws SQLServerException;
+ public void updateSmallDateTime(String columnName, java.sql.Timestamp x, int scale) throws SQLServerException;
/**
- * Updates the designated column with a java.sql.Timestamp
value. The updater methods are used to update column values in the current
- * row or the insert row. The updater methods do not update the underlying database; instead the updateRow
or insertRow
- * methods are called to update the database.
+ * Updates the designated column with a java.sql.Timestamp
value. The updater methods are used to
+ * update column values in the current row or the insert row. The updater methods do not update the underlying
+ * database; instead the updateRow
or insertRow
methods are called to update the database.
*
* @param columnName
- * is the name of the column
+ * is the name of the column
* @param x
- * the new column value
+ * the new column value
* @param scale
- * the scale of the column
+ * the scale of the column
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * If any errors occur.
+ * If any errors occur.
*/
- public void updateSmallDateTime(String columnName,
- java.sql.Timestamp x,
- int scale,
+ public void updateSmallDateTime(String columnName, java.sql.Timestamp x, int scale,
boolean forceEncrypt) throws SQLServerException;
/**
* Updates the value of the column specified to the DateTimeOffset Class value, given a column name.
*
* @param columnName
- * The name of a column.
+ * The name of a column.
* @param x
- * A DateTimeOffset Class object.
+ * A DateTimeOffset Class object.
* @param scale
- * the scale of the column
+ * the scale of the column
* @throws SQLServerException
- * If any errors occur.
+ * If any errors occur.
*/
- public void updateDateTimeOffset(String columnName,
- microsoft.sql.DateTimeOffset x,
+ public void updateDateTimeOffset(String columnName, microsoft.sql.DateTimeOffset x,
int scale) throws SQLServerException;
/**
* Updates the value of the column specified to the DateTimeOffset Class value, given a column name.
*
* @param columnName
- * The name of a column.
+ * The name of a column.
* @param x
- * A DateTimeOffset Class object.
+ * A DateTimeOffset Class object.
* @param scale
- * the scale of the column
+ * the scale of the column
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * If any errors occur.
+ * If any errors occur.
*/
- public void updateDateTimeOffset(String columnName,
- microsoft.sql.DateTimeOffset x,
- int scale,
+ public void updateDateTimeOffset(String columnName, microsoft.sql.DateTimeOffset x, int scale,
boolean forceEncrypt) throws SQLServerException;
/**
- * Updates the designated column with a String
value. The updater methods are used to update column values in the current row or the
- * insert row. The updater methods do not update the underlying database; instead the updateRow
or insertRow
methods are
- * called to update the database.
+ * Updates the designated column with a String
value. The updater methods are used to update column
+ * values in the current row or the insert row. The updater methods do not update the underlying database; instead
+ * the updateRow
or insertRow
methods are called to update the database.
*
* @param columnName
- * The name of a column.
+ * The name of a column.
* @param x
- * the new column value
+ * the new column value
* @throws SQLServerException
- * If any errors occur.
+ * If any errors occur.
*/
- public void updateUniqueIdentifier(String columnName,
- String x) throws SQLServerException;
+ public void updateUniqueIdentifier(String columnName, String x) throws SQLServerException;
/**
- * Updates the designated column with a String
value. The updater methods are used to update column values in the current row or the
- * insert row. The updater methods do not update the underlying database; instead the updateRow
or insertRow
methods are
- * called to update the database.
+ * Updates the designated column with a String
value. The updater methods are used to update column
+ * values in the current row or the insert row. The updater methods do not update the underlying database; instead
+ * the updateRow
or insertRow
methods are called to update the database.
*
* @param columnName
- * The name of a column.
+ * The name of a column.
* @param x
- * the new column value
+ * the new column value
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * If any errors occur.
+ * If any errors occur.
*/
- public void updateUniqueIdentifier(String columnName,
- String x,
- boolean forceEncrypt) throws SQLServerException;
+ public void updateUniqueIdentifier(String columnName, String x, boolean forceEncrypt) throws SQLServerException;
/**
* Updates the designated column with an {@code Object} value.
*
- * The updater methods are used to update column values in the current row or the insert row. The updater methods do not update the underlying
- * database; instead the {@code updateRow} or {@code insertRow} methods are called to update the database.
+ * The updater methods are used to update column values in the current row or the insert row. The updater methods do
+ * not update the underlying database; instead the {@code updateRow} or {@code insertRow} methods are called to
+ * update the database.
*
* @param columnName
- * The name of a column.
+ * The name of a column.
* @param x
- * the new column value
+ * the new column value
* @param precision
- * the precision of the column
+ * the precision of the column
* @param scale
- * the scale of the column
+ * the scale of the column
* @throws SQLServerException
- * If any errors occur.
+ * If any errors occur.
*/
- public void updateObject(String columnName,
- Object x,
- int precision,
- int scale) throws SQLServerException;
+ public void updateObject(String columnName, Object x, int precision, int scale) throws SQLServerException;
/**
* Updates the designated column with an {@code Object} value.
*
- * The updater methods are used to update column values in the current row or the insert row. The updater methods do not update the underlying
- * database; instead the {@code updateRow} or {@code insertRow} methods are called to update the database.
+ * The updater methods are used to update column values in the current row or the insert row. The updater methods do
+ * not update the underlying database; instead the {@code updateRow} or {@code insertRow} methods are called to
+ * update the database.
*
* @param columnName
- * The name of a column.
+ * The name of a column.
* @param x
- * the new column value
+ * the new column value
* @param precision
- * the precision of the column
+ * the precision of the column
* @param scale
- * the scale of the column
+ * the scale of the column
* @param forceEncrypt
- * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column is encrypted and Always
- * Encrypted is enabled on the connection or on the statement. If the boolean forceEncrypt is set to false, the driver will not force
- * encryption on parameters.
+ * If the boolean forceEncrypt is set to true, the query parameter will only be set if the designation column
+ * is encrypted and Always Encrypted is enabled on the connection or on the statement. If the boolean
+ * forceEncrypt is set to false, the driver will not force encryption on parameters.
* @throws SQLServerException
- * If any errors occur.
+ * If any errors occur.
*/
- public void updateObject(String columnName,
- Object x,
- int precision,
- int scale,
+ public void updateObject(String columnName, Object x, int precision, int scale,
boolean forceEncrypt) throws SQLServerException;
-
+
/**
- * Exposes Data Classification information for the current ResultSet For SQL Servers that do not support Data Classification or results that do
- * not fetch any classified columns, this data can be null
+ * Returns the Data Classification information for the current ResultSet For SQL Servers that do not support Data
+ * Classification or results that do not fetch any classified columns, this data can be null.
*
* @return SensitivityClassification
*/
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerResultSetMetaData.java b/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerResultSetMetaData.java
index 25f88d733..32788d998 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerResultSetMetaData.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerResultSetMetaData.java
@@ -1,28 +1,26 @@
/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc;
import java.sql.ResultSetMetaData;
+
/**
- * This interface is implemented by {@link SQLServerResultSetMetaData} class.
+ * Provides an interface to the{@link SQLServerResultSetMetaData} class.
*/
public interface ISQLServerResultSetMetaData extends ResultSetMetaData {
/**
- * Returns true if the column is a SQLServer SparseColumnSet
+ * Returns if the column is a SQLServer SparseColumnSet.
*
* @param column
- * The column number
+ * The column number
* @return true if a column in a result set is a sparse column set, otherwise false.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
public boolean isSparseColumnSet(int column) throws SQLServerException;
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerSavepoint.java b/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerSavepoint.java
index 4fd4dbb1a..3f97fe79b 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerSavepoint.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerSavepoint.java
@@ -1,36 +1,34 @@
/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc;
import java.sql.Savepoint;
+
/**
- * This interface is implemented by {@link SQLServerSavepoint} class.
+ * Provides an interface to the {@link SQLServerSavepoint} class.
*/
public interface ISQLServerSavepoint extends Savepoint {
/**
- * Get the savepoint name
+ * Returns the savepoint name
*
* @return the name of savepoint
*/
public String getSavepointName() throws SQLServerException;
/**
- * Get the savepoint label
+ * Returns the savepoint label
*
* @return the label for Savepoint
*/
public String getLabel();
/**
- * Checks if the savepoint label is null
+ * Returns if the savepoint label is null
*
* @return true is the savepoint is named. Otherwise, false.
*/
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerStatement.java b/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerStatement.java
index a1ba642a7..51797677b 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerStatement.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerStatement.java
@@ -1,15 +1,12 @@
/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc;
/**
- * This interface is implemented by {@link SQLServerStatement} class.
+ * Provides an interface to the {@link SQLServerStatement} class.
*/
public interface ISQLServerStatement extends java.sql.Statement {
/**
@@ -24,39 +21,39 @@ public interface ISQLServerStatement extends java.sql.Statement {
* "adaptive" - Data Pipe adaptive buffering
*
* @param value
- * A String that contains the response buffering mode. The valid mode can be one of the following case-insensitive Strings: full or
- * adaptive.
+ * A String that contains the response buffering mode. The valid mode can be one of the following
+ * case-insensitive Strings: full or adaptive.
* @throws SQLServerException
- * If there are any errors in setting the response buffering mode.
+ * If there are any errors in setting the response buffering mode.
*/
public void setResponseBuffering(String value) throws SQLServerException;
/**
- * Retrieves the response buffering mode for this SQLServerStatement object.
+ * Returns the response buffering mode for this SQLServerStatement object.
*
* @return A String that contains a lower-case full or adaptive.
* @throws SQLServerException
- * If there are any errors in retrieving the response buffering mode.
+ * If there are any errors in retrieving the response buffering mode.
*/
public String getResponseBuffering() throws SQLServerException;
/**
- * Retrieves the cancelQueryTimeout
property set on this SQLServerStatement object.
+ * Returns the cancelQueryTimeout
property set on this SQLServerStatement object.
*
* @return cancelQueryTimeout Time duration in seconds.
* @throws SQLServerException
- * if any error occurs
+ * if any error occurs
*/
public int getCancelQueryTimeout() throws SQLServerException;
/**
- * Sets the cancelQueryTimeout property on this SQLServerStatement object to cancel queryTimeout
set on Connection
or
- * Statement
level.
+ * Sets the cancelQueryTimeout
property on this SQLServerStatement object to cancel
+ * queryTimeout
set on Connection
or Statement
level.
*
* @param seconds
- * Time duration in seconds.
+ * Time duration in seconds.
* @throws SQLServerException
- * if any error occurs
+ * if any error occurs
*/
public void setCancelQueryTimeout(int seconds) throws SQLServerException;
}
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/InternalSpatialDatatype.java b/src/main/java/com/microsoft/sqlserver/jdbc/InternalSpatialDatatype.java
index 003e30f5d..dfbf6af68 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/InternalSpatialDatatype.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/InternalSpatialDatatype.java
@@ -1,44 +1,44 @@
/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc;
+/**
+ * Specifies the spatial data types values
+ */
public enum InternalSpatialDatatype {
- POINT((byte)1, "POINT"),
- LINESTRING((byte)2, "LINESTRING"),
- POLYGON((byte)3, "POLYGON"),
- MULTIPOINT((byte)4, "MULTIPOINT"),
- MULTILINESTRING((byte)5, "MULTILINESTRING"),
- MULTIPOLYGON((byte)6, "MULTIPOLYGON"),
- GEOMETRYCOLLECTION((byte)7, "GEOMETRYCOLLECTION"),
- CIRCULARSTRING((byte)8, "CIRCULARSTRING"),
- COMPOUNDCURVE((byte)9, "COMPOUNDCURVE"),
- CURVEPOLYGON((byte)10, "CURVEPOLYGON"),
- FULLGLOBE((byte)11, "FULLGLOBE"),
- INVALID_TYPE((byte)0, null);
-
+ POINT((byte) 1, "POINT"),
+ LINESTRING((byte) 2, "LINESTRING"),
+ POLYGON((byte) 3, "POLYGON"),
+ MULTIPOINT((byte) 4, "MULTIPOINT"),
+ MULTILINESTRING((byte) 5, "MULTILINESTRING"),
+ MULTIPOLYGON((byte) 6, "MULTIPOLYGON"),
+ GEOMETRYCOLLECTION((byte) 7, "GEOMETRYCOLLECTION"),
+ CIRCULARSTRING((byte) 8, "CIRCULARSTRING"),
+ COMPOUNDCURVE((byte) 9, "COMPOUNDCURVE"),
+ CURVEPOLYGON((byte) 10, "CURVEPOLYGON"),
+ FULLGLOBE((byte) 11, "FULLGLOBE"),
+ INVALID_TYPE((byte) 0, null);
+
private byte typeCode;
private String typeName;
-
+
private InternalSpatialDatatype(byte typeCode, String typeName) {
this.typeCode = typeCode;
this.typeName = typeName;
}
-
- public byte getTypeCode() {
+
+ byte getTypeCode() {
return this.typeCode;
}
-
- public String getTypeName() {
+
+ String getTypeName() {
return this.typeName;
}
-
- public static InternalSpatialDatatype valueOf(byte typeCode) {
+
+ static InternalSpatialDatatype valueOf(byte typeCode) {
for (InternalSpatialDatatype internalType : values()) {
if (internalType.typeCode == typeCode) {
return internalType;
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/JaasConfiguration.java b/src/main/java/com/microsoft/sqlserver/jdbc/JaasConfiguration.java
index 6443724fd..2f8dda592 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/JaasConfiguration.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/JaasConfiguration.java
@@ -1,71 +1,72 @@
-/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
- */
-package com.microsoft.sqlserver.jdbc;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.security.auth.login.AppConfigurationEntry;
-import javax.security.auth.login.Configuration;
-
-/**
- * This class overrides JAAS Configuration and always provide a configuration is not defined for default configuration.
- */
-public class JaasConfiguration extends Configuration {
-
- private final Configuration delegate;
- private AppConfigurationEntry[] defaultValue;
-
- private static AppConfigurationEntry[] generateDefaultConfiguration() {
- if (Util.isIBM()) {
- Map confDetailsWithoutPassword = new HashMap<>();
- confDetailsWithoutPassword.put("useDefaultCcache", "true");
- Map confDetailsWithPassword = new HashMap<>();
- // We generated a two configurations fallback that is suitable for password and password-less authentication
- // See https://www.ibm.com/support/knowledgecenter/SSYKE2_8.0.0/com.ibm.java.security.component.80.doc/security-component/jgssDocs/jaas_login_user.html
- final String ibmLoginModule = "com.ibm.security.auth.module.Krb5LoginModule";
- return new AppConfigurationEntry[] {
- new AppConfigurationEntry(ibmLoginModule, AppConfigurationEntry.LoginModuleControlFlag.SUFFICIENT, confDetailsWithoutPassword),
- new AppConfigurationEntry(ibmLoginModule, AppConfigurationEntry.LoginModuleControlFlag.SUFFICIENT, confDetailsWithPassword)};
- }
- else {
- Map confDetails = new HashMap<>();
- confDetails.put("useTicketCache", "true");
- return new AppConfigurationEntry[] {new AppConfigurationEntry("com.sun.security.auth.module.Krb5LoginModule",
- AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, confDetails)};
- }
- }
-
- /**
- * Package protected constructor.
- *
- * @param delegate
- * a possibly null delegate
- */
- JaasConfiguration(Configuration delegate) {
- this.delegate = delegate;
- this.defaultValue = generateDefaultConfiguration();
- }
-
- @Override
- public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
- AppConfigurationEntry[] conf = delegate == null ? null : delegate.getAppConfigurationEntry(name);
- // We return our configuration only if user requested default one
- // In case where user did request another JAAS Configuration name, we expect he knows what he is doing.
- if (conf == null && name.equals(SQLServerDriverStringProperty.JAAS_CONFIG_NAME.getDefaultValue())) {
- return defaultValue;
- }
- return conf;
- }
-
- @Override
- public void refresh() {
- if (null != delegate)
- delegate.refresh();
- }
-}
+/*
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ */
+package com.microsoft.sqlserver.jdbc;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.security.auth.login.AppConfigurationEntry;
+import javax.security.auth.login.Configuration;
+
+
+/**
+ * Overrides JAAS Configuration and always provide a configuration is not defined for default configuration.
+ */
+public class JaasConfiguration extends Configuration {
+
+ private final Configuration delegate;
+ private AppConfigurationEntry[] defaultValue;
+
+ private static AppConfigurationEntry[] generateDefaultConfiguration() {
+ if (Util.isIBM()) {
+ Map confDetailsWithoutPassword = new HashMap<>();
+ confDetailsWithoutPassword.put("useDefaultCcache", "true");
+ Map confDetailsWithPassword = new HashMap<>();
+ // We generated a two configurations fallback that is suitable for password and password-less authentication
+ // See
+ // https://www.ibm.com/support/knowledgecenter/SSYKE2_8.0.0/com.ibm.java.security.component.80.doc/security-component/jgssDocs/jaas_login_user.html
+ final String ibmLoginModule = "com.ibm.security.auth.module.Krb5LoginModule";
+ return new AppConfigurationEntry[] {
+ new AppConfigurationEntry(ibmLoginModule, AppConfigurationEntry.LoginModuleControlFlag.SUFFICIENT,
+ confDetailsWithoutPassword),
+ new AppConfigurationEntry(ibmLoginModule, AppConfigurationEntry.LoginModuleControlFlag.SUFFICIENT,
+ confDetailsWithPassword)};
+ } else {
+ Map confDetails = new HashMap<>();
+ confDetails.put("useTicketCache", "true");
+ return new AppConfigurationEntry[] {
+ new AppConfigurationEntry("com.sun.security.auth.module.Krb5LoginModule",
+ AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, confDetails)};
+ }
+ }
+
+ /**
+ * Package protected constructor.
+ *
+ * @param delegate
+ * a possibly null delegate
+ */
+ JaasConfiguration(Configuration delegate) {
+ this.delegate = delegate;
+ this.defaultValue = generateDefaultConfiguration();
+ }
+
+ @Override
+ public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
+ AppConfigurationEntry[] conf = delegate == null ? null : delegate.getAppConfigurationEntry(name);
+ // We return our configuration only if user requested default one
+ // In case where user did request another JAAS Configuration name, we expect he knows what he is doing.
+ if (conf == null && name.equals(SQLServerDriverStringProperty.JAAS_CONFIG_NAME.getDefaultValue())) {
+ return defaultValue;
+ }
+ return conf;
+ }
+
+ @Override
+ public void refresh() {
+ if (null != delegate)
+ delegate.refresh();
+ }
+}
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/KerbAuthentication.java b/src/main/java/com/microsoft/sqlserver/jdbc/KerbAuthentication.java
index d3707c2fe..47c95e9de 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/KerbAuthentication.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/KerbAuthentication.java
@@ -1,9 +1,6 @@
/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc;
@@ -37,6 +34,7 @@
import com.microsoft.sqlserver.jdbc.dns.DNSKerberosLocator;
+
/**
* KerbAuthentication for int auth.
*/
@@ -70,14 +68,15 @@ private void intAuthInit() throws SQLServerException {
GSSName remotePeerName = manager.createName(spn, null);
if (null != peerCredentials) {
- peerContext = manager.createContext(remotePeerName, kerberos, peerCredentials, GSSContext.DEFAULT_LIFETIME);
+ peerContext = manager.createContext(remotePeerName, kerberos, peerCredentials,
+ GSSContext.DEFAULT_LIFETIME);
peerContext.requestCredDeleg(false);
peerContext.requestMutualAuth(true);
peerContext.requestInteg(true);
- }
- else {
- String configName = con.activeConnectionProperties.getProperty(SQLServerDriverStringProperty.JAAS_CONFIG_NAME.toString(),
- SQLServerDriverStringProperty.JAAS_CONFIG_NAME.getDefaultValue());
+ } else {
+ String configName = con.activeConnectionProperties.getProperty(
+ SQLServerDriverStringProperty.JAAS_CONFIG_NAME.toString(),
+ SQLServerDriverStringProperty.JAAS_CONFIG_NAME.getDefaultValue());
Subject currentSubject;
KerbCallback callback = new KerbCallback(con);
try {
@@ -89,24 +88,27 @@ private void intAuthInit() throws SQLServerException {
// per documentation LoginContext will instantiate a new subject.
currentSubject = lc.getSubject();
}
- }
- catch (LoginException le) {
+ } catch (LoginException le) {
if (authLogger.isLoggable(Level.FINE)) {
- authLogger.fine(toString() + "Failed to login using Kerberos due to " + le.getClass().getName() + ":" + le.getMessage());
+ authLogger.fine(toString() + "Failed to login using Kerberos due to " + le.getClass().getName()
+ + ":" + le.getMessage());
}
try {
// Not very clean since it raises an Exception, but we are sure we are cleaning well everything
- con.terminate(SQLServerException.DRIVER_ERROR_NONE, SQLServerException.getErrString("R_integratedAuthenticationFailed"), le);
+ con.terminate(SQLServerException.DRIVER_ERROR_NONE,
+ SQLServerException.getErrString("R_integratedAuthenticationFailed"), le);
} catch (SQLServerException alwaysTriggered) {
- String message = MessageFormat.format(SQLServerException.getErrString("R_kerberosLoginFailed"),
- alwaysTriggered.getMessage(), le.getClass().getName(), le.getMessage());
+ String message = MessageFormat.format(SQLServerException.getErrString("R_kerberosLoginFailed"),
+ alwaysTriggered.getMessage(), le.getClass().getName(), le.getMessage());
if (callback.getUsernameRequested() != null) {
- message = MessageFormat.format(SQLServerException.getErrString("R_kerberosLoginFailedForUsername"),
- callback.getUsernameRequested(), message);
+ message = MessageFormat.format(
+ SQLServerException.getErrString("R_kerberosLoginFailedForUsername"),
+ callback.getUsernameRequested(), message);
}
// By throwing Exception with LOGON_FAILED -> we avoid looping for connection
// In this case, authentication will never work anyway -> fail fast
- throw new SQLServerException(message, alwaysTriggered.getSQLState(), SQLServerException.LOGON_FAILED, le);
+ throw new SQLServerException(message, alwaysTriggered.getSQLState(),
+ SQLServerException.LOGON_FAILED, le);
}
return;
}
@@ -118,8 +120,9 @@ private void intAuthInit() throws SQLServerException {
if (authLogger.isLoggable(Level.FINER)) {
authLogger.finer(toString() + " creating security context");
}
-
- peerContext = manager.createContext(remotePeerName, kerberos, peerCredentials, GSSContext.DEFAULT_LIFETIME);
+
+ peerContext = manager.createContext(remotePeerName, kerberos, peerCredentials,
+ GSSContext.DEFAULT_LIFETIME);
// The following flags should be inline with our native implementation.
peerContext.requestCredDeleg(true);
peerContext.requestMutualAuth(true);
@@ -129,18 +132,18 @@ private void intAuthInit() throws SQLServerException {
catch (GSSException ge) {
authLogger.finer(toString() + "initAuthInit failed GSSException:-" + ge);
- con.terminate(SQLServerException.DRIVER_ERROR_NONE, SQLServerException.getErrString("R_integratedAuthenticationFailed"), ge);
- }
- catch (PrivilegedActionException ge) {
+ con.terminate(SQLServerException.DRIVER_ERROR_NONE,
+ SQLServerException.getErrString("R_integratedAuthenticationFailed"), ge);
+ } catch (PrivilegedActionException ge) {
authLogger.finer(toString() + "initAuthInit failed privileged exception:-" + ge);
- con.terminate(SQLServerException.DRIVER_ERROR_NONE, SQLServerException.getErrString("R_integratedAuthenticationFailed"), ge);
+ con.terminate(SQLServerException.DRIVER_ERROR_NONE,
+ SQLServerException.getErrString("R_integratedAuthenticationFailed"), ge);
}
}
// We have to do a privileged action to create the credential of the user in the current context
- private static GSSCredential getClientCredential(final Subject subject,
- final GSSManager MANAGER,
+ private static GSSCredential getClientCredential(final Subject subject, final GSSManager MANAGER,
final Oid kerboid) throws PrivilegedActionException {
final PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
public GSSCredential run() throws GSSException {
@@ -149,14 +152,13 @@ public GSSCredential run() throws GSSException {
}
};
// TO support java 5, 6 we have to do this
- // The signature for Java 5 returns an object 6 returns GSSCredential, immediate casting throws
+ // The signature for Java 5 returns an object 6 returns GSSCredential, immediate casting throws
// warning in Java 6.
Object credential = Subject.doAs(subject, action);
return (GSSCredential) credential;
}
- private byte[] intAuthHandShake(byte[] pin,
- boolean[] done) throws SQLServerException {
+ private byte[] intAuthHandShake(byte[] pin, boolean[] done) throws SQLServerException {
try {
if (authLogger.isLoggable(Level.FINER)) {
authLogger.finer(toString() + " Sending token to server over secure context");
@@ -167,26 +169,25 @@ private byte[] intAuthHandShake(byte[] pin,
done[0] = true;
if (authLogger.isLoggable(Level.FINER))
authLogger.finer(toString() + "Authentication done.");
- }
- else if (null == byteToken) {
+ } else if (null == byteToken) {
// The documentation is not clear on when this can happen but it does say this could happen
if (authLogger.isLoggable(Level.INFO)) {
authLogger.info(toString() + "byteToken is null in initSecContext.");
}
- con.terminate(SQLServerException.DRIVER_ERROR_NONE, SQLServerException.getErrString("R_integratedAuthenticationFailed"));
+ con.terminate(SQLServerException.DRIVER_ERROR_NONE,
+ SQLServerException.getErrString("R_integratedAuthenticationFailed"));
}
return byteToken;
- }
- catch (GSSException ge) {
+ } catch (GSSException ge) {
authLogger.finer(toString() + "initSecContext Failed :-" + ge);
- con.terminate(SQLServerException.DRIVER_ERROR_NONE, SQLServerException.getErrString("R_integratedAuthenticationFailed"), ge);
+ con.terminate(SQLServerException.DRIVER_ERROR_NONE,
+ SQLServerException.getErrString("R_integratedAuthenticationFailed"), ge);
}
// keep the compiler happy
return null;
}
- private String makeSpn(String server,
- int port) throws SQLServerException {
+ private String makeSpn(String server, int port) throws SQLServerException {
if (authLogger.isLoggable(Level.FINER)) {
authLogger.finer(toString() + " Server: " + server + " port: " + port);
}
@@ -195,8 +196,7 @@ private String makeSpn(String server,
// FQDN must be provided
if (con.serverNameAsACE()) {
spn.append(IDN.toASCII(server));
- }
- else {
+ } else {
spn.append(server);
}
spn.append(":");
@@ -209,37 +209,35 @@ private String makeSpn(String server,
}
// Package visible members below.
- KerbAuthentication(SQLServerConnection con,
- String address,
- int port) throws SQLServerException {
+ KerbAuthentication(SQLServerConnection con, String address, int port) throws SQLServerException {
this.con = con;
// Get user provided SPN string; if not provided then build the generic one
- String userSuppliedServerSpn = con.activeConnectionProperties.getProperty(SQLServerDriverStringProperty.SERVER_SPN.toString());
+ String userSuppliedServerSpn = con.activeConnectionProperties
+ .getProperty(SQLServerDriverStringProperty.SERVER_SPN.toString());
String spn;
if (null != userSuppliedServerSpn) {
// serverNameAsACE is true, translate the user supplied serverSPN to ASCII
if (con.serverNameAsACE()) {
int slashPos = userSuppliedServerSpn.indexOf("/");
- spn = userSuppliedServerSpn.substring(0, slashPos + 1) + IDN.toASCII(userSuppliedServerSpn.substring(slashPos + 1));
- }
- else {
+ spn = userSuppliedServerSpn.substring(0, slashPos + 1)
+ + IDN.toASCII(userSuppliedServerSpn.substring(slashPos + 1));
+ } else {
spn = userSuppliedServerSpn;
}
- }
- else {
+ } else {
spn = makeSpn(address, port);
}
this.spn = enrichSpnWithRealm(spn, null == userSuppliedServerSpn);
- if (!this.spn.equals(spn) && authLogger.isLoggable(Level.FINER)){
+ if (!this.spn.equals(spn) && authLogger.isLoggable(Level.FINER)) {
authLogger.finer(toString() + "SPN enriched: " + spn + " := " + this.spn);
}
- }
+ }
- private static final Pattern SPN_PATTERN = Pattern.compile("MSSQLSvc/(.*):([^:@]+)(@.+)?", Pattern.CASE_INSENSITIVE);
+ private static final Pattern SPN_PATTERN = Pattern.compile("MSSQLSvc/(.*):([^:@]+)(@.+)?",
+ Pattern.CASE_INSENSITIVE);
- private String enrichSpnWithRealm(String spn,
- boolean allowHostnameCanonicalization) {
+ private String enrichSpnWithRealm(String spn, boolean allowHostnameCanonicalization) {
if (spn == null) {
return spn;
}
@@ -263,15 +261,13 @@ private String enrichSpnWithRealm(String spn,
// Since we have a match, our hostname is the correct one (for instance of server
// name was an IP), so we override dnsName as well
dnsName = canonicalHostName;
- }
- catch (UnknownHostException cannotCanonicalize) {
+ } catch (UnknownHostException cannotCanonicalize) {
// ignored, but we are in a bad shape
}
}
if (realm == null) {
return spn;
- }
- else {
+ } else {
StringBuilder sb = new StringBuilder("MSSQLSvc/");
sb.append(dnsName).append(":").append(portOrInstance).append("@").append(realm.toUpperCase(Locale.ENGLISH));
return sb.toString();
@@ -284,7 +280,7 @@ private String enrichSpnWithRealm(String spn,
* Find a suitable way of validating a REALM for given JVM.
*
* @param hostnameToTest
- * an example hostname we are gonna use to test our realm validator.
+ * an example hostname we are gonna use to test our realm validator.
* @return a not null realm Validator.
*/
static RealmValidator getRealmValidator(String hostnameToTest) {
@@ -304,8 +300,7 @@ public boolean isRealmValid(String realm) {
try {
Object ret = getKDCList.invoke(instance, realm);
return ret != null;
- }
- catch (Exception err) {
+ } catch (Exception err) {
return false;
}
}
@@ -319,9 +314,9 @@ public boolean isRealmValid(String realm) {
authLogger.fine("Kerberos Realm Validator: Using Built-in Oracle Realm Validation method.");
return oracleRealmValidator;
}
- authLogger.fine("Kerberos Realm Validator: Detected buggy Oracle Realm Validator, using DNSKerberosLocator.");
- }
- catch (ReflectiveOperationException notTheRightJVMException) {
+ authLogger
+ .fine("Kerberos Realm Validator: Detected buggy Oracle Realm Validator, using DNSKerberosLocator.");
+ } catch (ReflectiveOperationException notTheRightJVMException) {
// Ignored, we simply are not using the right JVM
authLogger.fine("Kerberos Realm Validator: No Oracle Realm Validator Available, using DNSKerberosLocator.");
}
@@ -331,8 +326,7 @@ public boolean isRealmValid(String realm) {
public boolean isRealmValid(String realm) {
try {
return DNSKerberosLocator.isRealmValid(realm);
- }
- catch (NamingException err) {
+ } catch (NamingException err) {
return false;
}
}
@@ -344,13 +338,12 @@ public boolean isRealmValid(String realm) {
* Try to find a REALM in the different parts of a host name.
*
* @param realmValidator
- * a function that return true if REALM is valid and exists
+ * a function that return true if REALM is valid and exists
* @param hostname
- * the name we are looking a REALM for
+ * the name we are looking a REALM for
* @return the realm if found, null otherwise
*/
- private String findRealmFromHostname(RealmValidator realmValidator,
- String hostname) {
+ private String findRealmFromHostname(RealmValidator realmValidator, String hostname) {
if (hostname == null) {
return null;
}
@@ -386,17 +379,14 @@ interface RealmValidator {
* @param ImpersonatedUserCred
* @throws SQLServerException
*/
- KerbAuthentication(SQLServerConnection con,
- String address,
- int port,
- GSSCredential ImpersonatedUserCred, Boolean isUserCreated) throws SQLServerException {
+ KerbAuthentication(SQLServerConnection con, String address, int port, GSSCredential ImpersonatedUserCred,
+ Boolean isUserCreated) throws SQLServerException {
this(con, address, port);
peerCredentials = ImpersonatedUserCred;
this.isUserCreatedCredential = (isUserCreated == null ? false : isUserCreated);
}
- byte[] GenerateClientContext(byte[] pin,
- boolean[] done) throws SQLServerException {
+ byte[] GenerateClientContext(byte[] pin, boolean[] done) throws SQLServerException {
if (null == peerContext) {
intAuthInit();
}
@@ -414,14 +404,14 @@ int ReleaseClientContext() throws SQLServerException {
peerContext.dispose();
if (null != lc)
lc.logout();
- }
- catch (LoginException e) {
- // yes we are eating exceptions here but this should not fail in the normal circumstances and we do not want to eat previous
+ } catch (LoginException e) {
+ // yes we are eating exceptions here but this should not fail in the normal circumstances and we do not want
+ // to eat previous
// login errors if caused before which is more useful to the user than the cleanup errors.
authLogger.fine(toString() + " Release of the credentials failed LoginException: " + e);
- }
- catch (GSSException e) {
- // yes we are eating exceptions here but this should not fail in the normal circumstances and we do not want to eat previous
+ } catch (GSSException e) {
+ // yes we are eating exceptions here but this should not fail in the normal circumstances and we do not want
+ // to eat previous
// login errors if caused before which is more useful to the user than the cleanup errors.
authLogger.fine(toString() + " Release of the credentials failed GSSException: " + e);
}
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/KerbCallback.java b/src/main/java/com/microsoft/sqlserver/jdbc/KerbCallback.java
index f2e312008..454688591 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/KerbCallback.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/KerbCallback.java
@@ -1,9 +1,6 @@
/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc;
@@ -18,6 +15,10 @@
import javax.security.auth.callback.PasswordCallback;
import javax.security.auth.callback.UnsupportedCallbackException;
+
+/**
+ * Provides implemention of the callback handler for Kerberos.
+ */
public class KerbCallback implements CallbackHandler {
private final SQLServerConnection con;
@@ -27,8 +28,7 @@ public class KerbCallback implements CallbackHandler {
this.con = con;
}
- private static String getAnyOf(Callback callback,
- Properties properties,
+ private static String getAnyOf(Callback callback, Properties properties,
String... names) throws UnsupportedCallbackException {
for (String name : names) {
String val = properties.getProperty(name);
@@ -36,11 +36,12 @@ private static String getAnyOf(Callback callback,
return val;
}
}
- throw new UnsupportedCallbackException(callback, "Cannot get any of properties: " + Arrays.toString(names) + " from con properties");
+ throw new UnsupportedCallbackException(callback,
+ "Cannot get any of properties: " + Arrays.toString(names) + " from con properties");
}
/**
- * If a name was retrieved By Kerberos, return it.
+ * Returns if a name was retrieved By Kerberos.
*
* @return null if callback was not called or username was not provided
*/
@@ -52,10 +53,12 @@ public String getUsernameRequested() {
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
for (Callback callback : callbacks) {
if (callback instanceof NameCallback) {
- usernameRequested = getAnyOf(callback, con.activeConnectionProperties, "user", SQLServerDriverStringProperty.USER.name());
+ usernameRequested = getAnyOf(callback, con.activeConnectionProperties, "user",
+ SQLServerDriverStringProperty.USER.name());
((NameCallback) callback).setName(usernameRequested);
} else if (callback instanceof PasswordCallback) {
- String password = getAnyOf(callback, con.activeConnectionProperties, "password", SQLServerDriverStringProperty.PASSWORD.name());
+ String password = getAnyOf(callback, con.activeConnectionProperties, "password",
+ SQLServerDriverStringProperty.PASSWORD.name());
((PasswordCallback) callback).setPassword(password.toCharArray());
} else {
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/KeyStoreProviderCommon.java b/src/main/java/com/microsoft/sqlserver/jdbc/KeyStoreProviderCommon.java
index 8db7b9a61..1da236fcb 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/KeyStoreProviderCommon.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/KeyStoreProviderCommon.java
@@ -1,181 +1,176 @@
-/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
- */
-
-package com.microsoft.sqlserver.jdbc;
-
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-import java.security.InvalidKeyException;
-import java.security.Key;
-import java.security.NoSuchAlgorithmException;
-import java.security.Signature;
-import java.security.SignatureException;
-import java.security.cert.X509Certificate;
-import java.text.MessageFormat;
-
-import javax.crypto.BadPaddingException;
-import javax.crypto.Cipher;
-import javax.crypto.IllegalBlockSizeException;
-import javax.crypto.NoSuchPaddingException;
-
-/**
- *
- * This class holds information about the certificate
- *
- */
-class CertificateDetails {
- X509Certificate certificate;
- Key privateKey;
-
- CertificateDetails(X509Certificate certificate,
- Key privateKey) {
- this.certificate = certificate;
- this.privateKey = privateKey;
- }
-}
-
-class KeyStoreProviderCommon {
-
- static final String rsaEncryptionAlgorithmWithOAEP = "RSA_OAEP";
- static byte[] version = new byte[] {0x01};
-
- static void validateEncryptionAlgorithm(String encryptionAlgorithm,
- boolean isEncrypt) throws SQLServerException {
- String errString = isEncrypt ? "R_NullKeyEncryptionAlgorithm" : "R_NullKeyEncryptionAlgorithmInternal";
- if (null == encryptionAlgorithm) {
-
- throw new SQLServerException(null, SQLServerException.getErrString(errString), null, 0, false);
-
- }
-
- errString = isEncrypt ? "R_InvalidKeyEncryptionAlgorithm" : "R_InvalidKeyEncryptionAlgorithmInternal";
- if (!rsaEncryptionAlgorithmWithOAEP.equalsIgnoreCase(encryptionAlgorithm.trim())) {
-
- MessageFormat form = new MessageFormat(SQLServerException.getErrString(errString));
- Object[] msgArgs = {encryptionAlgorithm, rsaEncryptionAlgorithmWithOAEP};
- throw new SQLServerException(form.format(msgArgs), null);
-
- }
- }
-
- static void validateNonEmptyMasterKeyPath(String masterKeyPath) throws SQLServerException {
- if (null == masterKeyPath || masterKeyPath.trim().length() == 0) {
- throw new SQLServerException(null, SQLServerException.getErrString("R_InvalidMasterKeyDetails"), null, 0, false);
- }
- }
-
- static byte[] decryptColumnEncryptionKey(String masterKeyPath,
- String encryptionAlgorithm,
- byte[] encryptedColumnEncryptionKey,
- CertificateDetails certificateDetails) throws SQLServerException {
- if (null == encryptedColumnEncryptionKey) {
-
- throw new SQLServerException(null, SQLServerException.getErrString("R_NullEncryptedColumnEncryptionKey"), null, 0, false);
-
- }
- else if (0 == encryptedColumnEncryptionKey.length) {
-
- throw new SQLServerException(null, SQLServerException.getErrString("R_EmptyEncryptedColumnEncryptionKey"), null, 0, false);
-
- }
-
- validateEncryptionAlgorithm(encryptionAlgorithm, false);
-
- int currentIndex = version.length;
- int keyPathLength = convertTwoBytesToShort(encryptedColumnEncryptionKey, currentIndex);
- // We just read 2 bytes
- currentIndex += 2;
-
- // Get ciphertext length
- int cipherTextLength = convertTwoBytesToShort(encryptedColumnEncryptionKey, currentIndex);
- currentIndex += 2;
-
- currentIndex += keyPathLength;
-
- int signatureLength = encryptedColumnEncryptionKey.length - currentIndex - cipherTextLength;
-
- // Get ciphertext
- byte[] cipherText = new byte[cipherTextLength];
- System.arraycopy(encryptedColumnEncryptionKey, currentIndex, cipherText, 0, cipherTextLength);
- currentIndex += cipherTextLength;
-
- byte[] signature = new byte[signatureLength];
- System.arraycopy(encryptedColumnEncryptionKey, currentIndex, signature, 0, signatureLength);
-
- byte[] hash = new byte[encryptedColumnEncryptionKey.length - signature.length];
-
- System.arraycopy(encryptedColumnEncryptionKey, 0, hash, 0, encryptedColumnEncryptionKey.length - signature.length);
-
- if (!verifyRSASignature(hash, signature, certificateDetails.certificate, masterKeyPath)) {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_InvalidCertificateSignature"));
- Object[] msgArgs = {masterKeyPath};
- throw new SQLServerException(form.format(msgArgs), null);
- }
-
- byte[] plainCEK = decryptRSAOAEP(cipherText, certificateDetails);
-
- return plainCEK;
- }
-
- private static byte[] decryptRSAOAEP(byte[] cipherText,
- CertificateDetails certificateDetails) throws SQLServerException {
- byte[] plainCEK = null;
- try {
- Cipher rsa = Cipher.getInstance("RSA/ECB/OAEPWithSHA-1AndMGF1Padding");
- rsa.init(Cipher.DECRYPT_MODE, certificateDetails.privateKey);
- rsa.update(cipherText);
- plainCEK = rsa.doFinal();
- }
- catch (InvalidKeyException | NoSuchAlgorithmException | NoSuchPaddingException | IllegalBlockSizeException | BadPaddingException e) {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_CEKDecryptionFailed"));
- Object[] msgArgs = {e.getMessage()};
- throw new SQLServerException(form.format(msgArgs), e);
- }
-
- return plainCEK;
-
- }
-
- private static boolean verifyRSASignature(byte[] hash,
- byte[] signature,
- X509Certificate certificate,
- String masterKeyPath) throws SQLServerException {
- Signature signVerify;
- boolean verificationSucess = false;
- try {
- signVerify = Signature.getInstance("SHA256withRSA");
- signVerify.initVerify(certificate.getPublicKey());
- signVerify.update(hash);
- verificationSucess = signVerify.verify(signature);
- }
- catch (InvalidKeyException | NoSuchAlgorithmException | SignatureException e) {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_InvalidCertificateSignature"));
- Object[] msgArgs = {masterKeyPath};
- throw new SQLServerException(form.format(msgArgs), e);
- }
-
- return verificationSucess;
-
- }
-
- private static short convertTwoBytesToShort(byte[] input,
- int index) throws SQLServerException {
-
- short shortVal;
- if (index + 1 >= input.length) {
- throw new SQLServerException(null, SQLServerException.getErrString("R_ByteToShortConversion"), null, 0, false);
- }
- ByteBuffer byteBuffer = ByteBuffer.allocate(2);
- byteBuffer.order(ByteOrder.LITTLE_ENDIAN);
- byteBuffer.put(input[index]);
- byteBuffer.put(input[index + 1]);
- shortVal = byteBuffer.getShort(0);
- return shortVal;
-
- }
-}
+/*
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ */
+
+package com.microsoft.sqlserver.jdbc;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.security.InvalidKeyException;
+import java.security.Key;
+import java.security.NoSuchAlgorithmException;
+import java.security.Signature;
+import java.security.SignatureException;
+import java.security.cert.X509Certificate;
+import java.text.MessageFormat;
+
+import javax.crypto.BadPaddingException;
+import javax.crypto.Cipher;
+import javax.crypto.IllegalBlockSizeException;
+import javax.crypto.NoSuchPaddingException;
+
+
+/**
+ *
+ * This class holds information about the certificate
+ *
+ */
+class CertificateDetails {
+ X509Certificate certificate;
+ Key privateKey;
+
+ CertificateDetails(X509Certificate certificate, Key privateKey) {
+ this.certificate = certificate;
+ this.privateKey = privateKey;
+ }
+}
+
+
+class KeyStoreProviderCommon {
+
+ static final String rsaEncryptionAlgorithmWithOAEP = "RSA_OAEP";
+ static byte[] version = new byte[] {0x01};
+
+ static void validateEncryptionAlgorithm(String encryptionAlgorithm, boolean isEncrypt) throws SQLServerException {
+ String errString = isEncrypt ? "R_NullKeyEncryptionAlgorithm" : "R_NullKeyEncryptionAlgorithmInternal";
+ if (null == encryptionAlgorithm) {
+
+ throw new SQLServerException(null, SQLServerException.getErrString(errString), null, 0, false);
+
+ }
+
+ errString = isEncrypt ? "R_InvalidKeyEncryptionAlgorithm" : "R_InvalidKeyEncryptionAlgorithmInternal";
+ if (!rsaEncryptionAlgorithmWithOAEP.equalsIgnoreCase(encryptionAlgorithm.trim())) {
+
+ MessageFormat form = new MessageFormat(SQLServerException.getErrString(errString));
+ Object[] msgArgs = {encryptionAlgorithm, rsaEncryptionAlgorithmWithOAEP};
+ throw new SQLServerException(form.format(msgArgs), null);
+
+ }
+ }
+
+ static void validateNonEmptyMasterKeyPath(String masterKeyPath) throws SQLServerException {
+ if (null == masterKeyPath || masterKeyPath.trim().length() == 0) {
+ throw new SQLServerException(null, SQLServerException.getErrString("R_InvalidMasterKeyDetails"), null, 0,
+ false);
+ }
+ }
+
+ static byte[] decryptColumnEncryptionKey(String masterKeyPath, String encryptionAlgorithm,
+ byte[] encryptedColumnEncryptionKey, CertificateDetails certificateDetails) throws SQLServerException {
+ if (null == encryptedColumnEncryptionKey) {
+
+ throw new SQLServerException(null, SQLServerException.getErrString("R_NullEncryptedColumnEncryptionKey"),
+ null, 0, false);
+
+ } else if (0 == encryptedColumnEncryptionKey.length) {
+
+ throw new SQLServerException(null, SQLServerException.getErrString("R_EmptyEncryptedColumnEncryptionKey"),
+ null, 0, false);
+
+ }
+
+ validateEncryptionAlgorithm(encryptionAlgorithm, false);
+
+ int currentIndex = version.length;
+ int keyPathLength = convertTwoBytesToShort(encryptedColumnEncryptionKey, currentIndex);
+ // We just read 2 bytes
+ currentIndex += 2;
+
+ // Get ciphertext length
+ int cipherTextLength = convertTwoBytesToShort(encryptedColumnEncryptionKey, currentIndex);
+ currentIndex += 2;
+
+ currentIndex += keyPathLength;
+
+ int signatureLength = encryptedColumnEncryptionKey.length - currentIndex - cipherTextLength;
+
+ // Get ciphertext
+ byte[] cipherText = new byte[cipherTextLength];
+ System.arraycopy(encryptedColumnEncryptionKey, currentIndex, cipherText, 0, cipherTextLength);
+ currentIndex += cipherTextLength;
+
+ byte[] signature = new byte[signatureLength];
+ System.arraycopy(encryptedColumnEncryptionKey, currentIndex, signature, 0, signatureLength);
+
+ byte[] hash = new byte[encryptedColumnEncryptionKey.length - signature.length];
+
+ System.arraycopy(encryptedColumnEncryptionKey, 0, hash, 0,
+ encryptedColumnEncryptionKey.length - signature.length);
+
+ if (!verifyRSASignature(hash, signature, certificateDetails.certificate, masterKeyPath)) {
+ MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_InvalidCertificateSignature"));
+ Object[] msgArgs = {masterKeyPath};
+ throw new SQLServerException(form.format(msgArgs), null);
+ }
+
+ byte[] plainCEK = decryptRSAOAEP(cipherText, certificateDetails);
+
+ return plainCEK;
+ }
+
+ private static byte[] decryptRSAOAEP(byte[] cipherText,
+ CertificateDetails certificateDetails) throws SQLServerException {
+ byte[] plainCEK = null;
+ try {
+ Cipher rsa = Cipher.getInstance("RSA/ECB/OAEPWithSHA-1AndMGF1Padding");
+ rsa.init(Cipher.DECRYPT_MODE, certificateDetails.privateKey);
+ rsa.update(cipherText);
+ plainCEK = rsa.doFinal();
+ } catch (InvalidKeyException | NoSuchAlgorithmException | NoSuchPaddingException | IllegalBlockSizeException
+ | BadPaddingException e) {
+ MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_CEKDecryptionFailed"));
+ Object[] msgArgs = {e.getMessage()};
+ throw new SQLServerException(form.format(msgArgs), e);
+ }
+
+ return plainCEK;
+
+ }
+
+ private static boolean verifyRSASignature(byte[] hash, byte[] signature, X509Certificate certificate,
+ String masterKeyPath) throws SQLServerException {
+ Signature signVerify;
+ boolean verificationSucess = false;
+ try {
+ signVerify = Signature.getInstance("SHA256withRSA");
+ signVerify.initVerify(certificate.getPublicKey());
+ signVerify.update(hash);
+ verificationSucess = signVerify.verify(signature);
+ } catch (InvalidKeyException | NoSuchAlgorithmException | SignatureException e) {
+ MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_InvalidCertificateSignature"));
+ Object[] msgArgs = {masterKeyPath};
+ throw new SQLServerException(form.format(msgArgs), e);
+ }
+
+ return verificationSucess;
+
+ }
+
+ private static short convertTwoBytesToShort(byte[] input, int index) throws SQLServerException {
+
+ short shortVal;
+ if (index + 1 >= input.length) {
+ throw new SQLServerException(null, SQLServerException.getErrString("R_ByteToShortConversion"), null, 0,
+ false);
+ }
+ ByteBuffer byteBuffer = ByteBuffer.allocate(2);
+ byteBuffer.order(ByteOrder.LITTLE_ENDIAN);
+ byteBuffer.put(input[index]);
+ byteBuffer.put(input[index + 1]);
+ shortVal = byteBuffer.getShort(0);
+ return shortVal;
+
+ }
+}
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/KeyVaultCredential.java b/src/main/java/com/microsoft/sqlserver/jdbc/KeyVaultCredential.java
index 470078242..0c75fae75 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/KeyVaultCredential.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/KeyVaultCredential.java
@@ -1,9 +1,6 @@
/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc;
@@ -17,6 +14,7 @@
import com.microsoft.aad.adal4j.ClientCredential;
import com.microsoft.azure.keyvault.authentication.KeyVaultCredentials;
+
/**
*
* An implementation of ServiceClientCredentials that supports automatic bearer token refresh.
@@ -29,8 +27,7 @@ class KeyVaultCredential extends KeyVaultCredentials {
String clientKey = null;
String accessToken = null;
- KeyVaultCredential(String clientId,
- String clientKey) {
+ KeyVaultCredential(String clientId, String clientKey) {
this.clientId = clientId;
this.clientKey = clientKey;
}
@@ -39,24 +36,20 @@ class KeyVaultCredential extends KeyVaultCredentials {
this.authenticationCallback = authenticationCallback;
}
- public String doAuthenticate(String authorization,
- String resource,
- String scope) {
+ public String doAuthenticate(String authorization, String resource, String scope) {
String accessToken;
if (null == authenticationCallback) {
- AuthenticationResult token = getAccessTokenFromClientCredentials(authorization, resource, clientId, clientKey);
+ AuthenticationResult token = getAccessTokenFromClientCredentials(authorization, resource, clientId,
+ clientKey);
accessToken = token.getAccessToken();
- }
- else {
+ } else {
accessToken = authenticationCallback.getAccessToken(authorization, resource, scope);
}
return accessToken;
}
- private static AuthenticationResult getAccessTokenFromClientCredentials(String authorization,
- String resource,
- String clientId,
- String clientKey) {
+ private static AuthenticationResult getAccessTokenFromClientCredentials(String authorization, String resource,
+ String clientId, String clientKey) {
AuthenticationContext context = null;
AuthenticationResult result = null;
ExecutorService service = null;
@@ -66,11 +59,9 @@ private static AuthenticationResult getAccessTokenFromClientCredentials(String a
ClientCredential credentials = new ClientCredential(clientId, clientKey);
Future future = context.acquireToken(resource, credentials, null);
result = future.get();
- }
- catch (Exception e) {
+ } catch (Exception e) {
throw new RuntimeException(e);
- }
- finally {
+ } finally {
service.shutdown();
}
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/PLPInputStream.java b/src/main/java/com/microsoft/sqlserver/jdbc/PLPInputStream.java
index 43818afd8..0b4563e0b 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/PLPInputStream.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/PLPInputStream.java
@@ -1,526 +1,502 @@
-/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
- */
-
-package com.microsoft.sqlserver.jdbc;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-
-/**
- * PLPInputStream is an InputStream implementation that reads from a TDS PLP stream.
- *
- * Note PLP stands for Partially Length-prefixed Bytes. TDS 7.2 introduced this new streaming format for streaming of large types such as
- * varchar(max), nvarchar(max), varbinary(max) and XML.
- *
- * See TDS specification, 6.3.3 Datatype Dependant Data Streams: Partially Length-prefixed Bytes for more details on the PLP format.
- */
-
-class PLPInputStream extends BaseInputStream {
- static final long PLP_NULL = 0xFFFFFFFFFFFFFFFFL;
- static final long UNKNOWN_PLP_LEN = 0xFFFFFFFFFFFFFFFEL;
- static final int PLP_TERMINATOR = 0x00000000;
- private final static byte[] EMPTY_PLP_BYTES = new byte[0];
-
- // Stated length of the PLP stream payload; -1 if unknown length.
- int payloadLength;
-
- private static final int PLP_EOS = -1;
- private int currentChunkRemain;
-
- private int markedChunkRemain;
- private int leftOverReadLimit = 0;
-
- private byte[] oneByteArray = new byte[1];
-
- /**
- * Non-destructive method for checking whether a PLP value at the current TDSReader location is null.
- */
- final static boolean isNull(TDSReader tdsReader) throws SQLServerException {
- TDSReaderMark mark = tdsReader.mark();
- //Temporary stream cannot get closes, since it closes the main stream.
- try {
- return null == PLPInputStream.makeTempStream(tdsReader, false, null);
- }
- finally {
- tdsReader.reset(mark);
- }
- }
-
- /**
- * Create a new input stream.
- *
- * @param tdsReader
- * TDS reader pointing at the start of the PLP data
- * @param discardValue
- * boolean to represent if base input stream is adaptive and is streaming
- * @param dtv
- * DTV implementation for values set from the TDS response stream.
- * @return PLPInputStream that is created
- * @throws SQLServerException
- * when an error occurs
- */
- final static PLPInputStream makeTempStream(TDSReader tdsReader,
- boolean discardValue,
- ServerDTVImpl dtv) throws SQLServerException {
- return makeStream(tdsReader, discardValue, discardValue, dtv);
- }
-
- final static PLPInputStream makeStream(TDSReader tdsReader,
- InputStreamGetterArgs getterArgs,
- ServerDTVImpl dtv) throws SQLServerException {
- PLPInputStream is = makeStream(tdsReader, getterArgs.isAdaptive, getterArgs.isStreaming, dtv);
- if (null != is)
- is.setLoggingInfo(getterArgs.logContext);
- return is;
- }
-
- private static PLPInputStream makeStream(TDSReader tdsReader,
- boolean isAdaptive,
- boolean isStreaming,
- ServerDTVImpl dtv) throws SQLServerException {
- // Read total length of PLP stream.
- long payloadLength = tdsReader.readLong();
-
- // If length is PLP_NULL, then return a null PLP value.
- if (PLP_NULL == payloadLength)
- return null;
-
- return new PLPInputStream(tdsReader, payloadLength, isAdaptive, isStreaming, dtv);
- }
-
- /**
- * Initializes the input stream.
- */
- PLPInputStream(TDSReader tdsReader,
- long statedPayloadLength,
- boolean isAdaptive,
- boolean isStreaming,
- ServerDTVImpl dtv) throws SQLServerException {
- super(tdsReader, isAdaptive, isStreaming, dtv);
- this.payloadLength = (UNKNOWN_PLP_LEN != statedPayloadLength) ? ((int) statedPayloadLength) : -1;
- this.currentChunkRemain = this.markedChunkRemain = 0;
- }
-
- /**
- * Helper function to convert the entire PLP stream into a contiguous byte array. This call is inefficient (in terms of memory usage and run time)
- * for very large PLPs. Use it only if a contiguous byte array is required.
- */
- byte[] getBytes() throws SQLServerException {
- byte[] value;
-
- // The following 0-byte read just ensures that the number of bytes
- // remaining in the current chunk is known.
- readBytesInternal(null, 0, 0);
-
- if (PLP_EOS == currentChunkRemain) {
- value = EMPTY_PLP_BYTES;
- }
- else {
- // If the PLP payload length is known, allocate the final byte array now.
- // Otherwise, start with the size of the first chunk. Additional chunks
- // will cause the array to be reallocated & copied.
- value = new byte[(-1 != payloadLength) ? payloadLength : currentChunkRemain];
-
- int bytesRead = 0;
- while (PLP_EOS != currentChunkRemain) {
- // If the current byte array isn't large enough to hold
- // the contents of the current chunk, then make it larger.
- if (value.length == bytesRead) {
- byte[] newValue = new byte[bytesRead + currentChunkRemain];
- System.arraycopy(value, 0, newValue, 0, bytesRead);
- value = newValue;
- }
-
- bytesRead += readBytesInternal(value, bytesRead, currentChunkRemain);
- }
- }
-
- // Always close the stream after retrieving it
- try {
- close();
- }
- catch (IOException e) {
- SQLServerException.makeFromDriverError(null, null, e.getMessage(), null, true);
- }
-
- return value;
- }
-
- /**
- * Skips over and discards n bytes of data from this input stream.
- *
- * @param n
- * the number of bytes to be skipped.
- * @return the actual number of bytes skipped.
- * @exception IOException
- * if an I/O error occurs.
- */
- public long skip(long n) throws IOException {
- checkClosed();
- if (n < 0)
- return 0L;
- if (n > Integer.MAX_VALUE)
- n = Integer.MAX_VALUE;
-
- long bytesread = readBytes(null, 0, (int) n);
-
- if (-1 == bytesread)
- return 0;
- else
- return bytesread;
- }
-
- /**
- * Returns the number of bytes that can be read (or skipped over) from this input stream without blocking by the next caller of a method for this
- * input stream.
- *
- * @return the actual number of bytes available.
- * @exception IOException
- * if an I/O error occurs.
- */
- public int available() throws IOException {
- checkClosed();
- try {
-
- // The following 0-byte read just ensures that the number of bytes
- // remaining in the current chunk is known.
- if (0 == currentChunkRemain)
- readBytesInternal(null, 0, 0);
-
- if (PLP_EOS == currentChunkRemain)
- return 0;
-
- // Return the lesser of the number of bytes available for reading
- // from the underlying TDSReader and the number of bytes left in
- // the current chunk.
- int available = tdsReader.available();
- if (available > currentChunkRemain)
- available = currentChunkRemain;
-
- return available;
- }
- catch (SQLServerException e) {
- throw new IOException(e.getMessage());
- }
-
- }
-
- /**
- * Reads the next byte of data from the input stream.
- *
- * @return the byte read or -1 meaning no more bytes.
- * @exception IOException
- * if an I/O error occurs.
- */
- public int read() throws IOException {
- checkClosed();
-
- if (-1 != readBytes(oneByteArray, 0, 1))
- return oneByteArray[0] & 0xFF;
- return -1;
- }
-
- /**
- * Reads available data into supplied byte array.
- *
- * @param b
- * array of bytes to fill.
- * @return the number of bytes read or 0 meaning no bytes read.
- * @exception IOException
- * if an I/O error occurs.
- */
- public int read(byte[] b) throws IOException {
- // If b is null, a NullPointerException is thrown.
- if (null == b)
- throw new NullPointerException();
-
- checkClosed();
-
- return readBytes(b, 0, b.length);
- }
-
- /**
- * Reads available data into supplied byte array.
- *
- * @param b
- * array of bytes to fill.
- * @param offset
- * the offset into array b where to start writing.
- * @param maxBytes
- * the max number of bytes to write into b.
- * @return the number of bytes read or 0 meaning no bytes read.
- * @exception IOException
- * if an I/O error occurs.
- */
- public int read(byte b[],
- int offset,
- int maxBytes) throws IOException {
- // If b is null, a NullPointerException is thrown.
- if (null == b)
- throw new NullPointerException();
-
- // Verify offset and maxBytes against target buffer if we're reading (as opposed to skipping).
- // If offset is negative, or maxBytes is negative, or offset+maxBytes
- // is greater than the length of the array b, then an IndexOutOfBoundsException is thrown.
- if (offset < 0 || maxBytes < 0 || offset + maxBytes > b.length)
- throw new IndexOutOfBoundsException();
-
- checkClosed();
-
- return readBytes(b, offset, maxBytes);
- }
-
- /**
- * Reads available data into supplied byte array b.
- *
- * @param b
- * array of bytes to fill. If b is null, method will skip over data.
- * @param offset
- * the offset into array b where to start writing.
- * @param maxBytes
- * the max number of bytes to write into b.
- * @return the number of bytes read or 0 meaning no bytes read or -1 meaning EOS.
- * @exception IOException
- * if an I/O error occurs.
- */
- int readBytes(byte[] b,
- int offset,
- int maxBytes) throws IOException {
- // If maxBytes is zero, then no bytes are read and 0 is returned
- // This must be done here rather than in readBytesInternal since a 0-byte read
- // there may return -1 at EOS.
- if (0 == maxBytes)
- return 0;
-
- try {
- return readBytesInternal(b, offset, maxBytes);
- }
- catch (SQLServerException e) {
- throw new IOException(e.getMessage());
- }
- }
-
- private int readBytesInternal(byte b[],
- int offset,
- int maxBytes) throws SQLServerException {
- // If we're at EOS, say so.
- // Note: For back compat, this special case needs to always be handled
- // before checking user-supplied arguments below.
- if (PLP_EOS == currentChunkRemain)
- return -1;
-
- // Save off the current TDSReader position, wherever it is, and start reading
- // from where we left off last time.
-
- int bytesRead = 0;
- for (;;) {
- // Check that we have bytes left to read from the current chunk.
- // If not then figure out the size of the next chunk or
- // determine that we have reached the end of the stream.
- if (0 == currentChunkRemain) {
- currentChunkRemain = (int) tdsReader.readUnsignedInt();
- assert currentChunkRemain >= 0;
- if (0 == currentChunkRemain) {
- currentChunkRemain = PLP_EOS;
- break;
- }
- }
-
- if (bytesRead == maxBytes)
- break;
-
- // Now we know there are bytes to be read in the current chunk.
- // Further limit the max number of bytes we can read to whatever
- // remains in the current chunk.
- int bytesToRead = maxBytes - bytesRead;
- if (bytesToRead > currentChunkRemain)
- bytesToRead = currentChunkRemain;
-
- // Skip/Read as many bytes as we can, given the constraints.
- if (null == b)
- tdsReader.skip(bytesToRead);
- else
- tdsReader.readBytes(b, offset + bytesRead, bytesToRead);
-
- bytesRead += bytesToRead;
- currentChunkRemain -= bytesToRead;
- }
-
- if (bytesRead > 0) {
- if (isReadLimitSet && leftOverReadLimit > 0) {
- leftOverReadLimit = leftOverReadLimit - bytesRead;
- if (leftOverReadLimit < 0)
- clearCurrentMark();
- }
- return bytesRead;
- }
-
- if (PLP_EOS == currentChunkRemain)
- return -1;
-
- return 0;
- }
-
- /**
- * Marks the current position in this input stream.
- *
- * @param readlimit
- * the number of bytes to hold (this implementation ignores this).
- */
- public void mark(int readLimit) {
- // Save off current position and how much of the current chunk remains
- // cant throw if the tdsreader is null
- if (null != tdsReader && readLimit > 0) {
- currentMark = tdsReader.mark();
- markedChunkRemain = currentChunkRemain;
- leftOverReadLimit = readLimit;
- setReadLimit(readLimit);
- }
- }
-
- /**
- * Closes the stream releasing all resources held.
- *
- * @exception IOException
- * if an I/O error occurs.
- */
- public void close() throws IOException {
- if (null == tdsReader)
- return;
-
- while (skip(tdsReader.getConnection().getTDSPacketSize()) != 0)
- ;
- // Release ref to tdsReader and parentRS here, shut down stream state.
- closeHelper();
- }
-
- /**
- * Resets stream to saved mark position.
- *
- * @exception IOException
- * if an I/O error occurs.
- */
- public void reset() throws IOException {
- resetHelper();
- leftOverReadLimit = readLimit;
- currentChunkRemain = markedChunkRemain;
- }
-}
-
-/**
- * Implements an XML binary stream with BOM header.
- *
- * Class extends a normal PLPInputStream class and prepends the XML BOM (0xFFFE) token then steps out of the way and forwards the rest of the
- * InputStream calls to the super class PLPInputStream.
- */
-final class PLPXMLInputStream extends PLPInputStream {
- // XML BOM header (the first two header bytes sent to caller).
- private final static byte[] xmlBOM = {(byte) 0xFF, (byte) 0xFE};
- private final ByteArrayInputStream bomStream = new ByteArrayInputStream(xmlBOM);
-
- final static PLPXMLInputStream makeXMLStream(TDSReader tdsReader,
- InputStreamGetterArgs getterArgs,
- ServerDTVImpl dtv) throws SQLServerException {
- // Read total length of PLP stream.
- long payloadLength = tdsReader.readLong();
-
- // If length is PLP_NULL, then return a null PLP value.
- if (PLP_NULL == payloadLength)
- return null;
-
- PLPXMLInputStream is = new PLPXMLInputStream(tdsReader, payloadLength, getterArgs, dtv);
- is.setLoggingInfo(getterArgs.logContext);
-
- return is;
- }
-
- PLPXMLInputStream(TDSReader tdsReader,
- long statedPayloadLength,
- InputStreamGetterArgs getterArgs,
- ServerDTVImpl dtv) throws SQLServerException {
- super(tdsReader, statedPayloadLength, getterArgs.isAdaptive, getterArgs.isStreaming, dtv);
- }
-
- public void close() throws IOException {
- super.close();
- }
-
- int readBytes(byte[] b,
- int offset,
- int maxBytes) throws IOException {
- assert offset >= 0;
- assert maxBytes >= 0;
- // If maxBytes is zero, then no bytes are read and 0 is returned.
- if (0 == maxBytes)
- return 0;
-
- int bytesRead = 0;
- int xmlBytesRead = 0;
-
- // Read/Skip BOM bytes first. When all BOM bytes have been consumed ...
- if (null == b) {
- for (int bomBytesSkipped; bytesRead < maxBytes
- && 0 != (bomBytesSkipped = (int) bomStream.skip(((long) maxBytes) - ((long) bytesRead))); bytesRead += bomBytesSkipped)
- ;
- }
- else {
- for (int bomBytesRead; bytesRead < maxBytes
- && -1 != (bomBytesRead = bomStream.read(b, offset + bytesRead, maxBytes - bytesRead)); bytesRead += bomBytesRead)
- ;
- }
-
- // ... then read/skip bytes from the underlying PLPInputStream
- for (; bytesRead < maxBytes && -1 != (xmlBytesRead = super.readBytes(b, offset + bytesRead, maxBytes - bytesRead)); bytesRead += xmlBytesRead)
- ;
-
- if (bytesRead > 0)
- return bytesRead;
-
- // No bytes read - should have been EOF since 0-byte reads are handled above
- assert -1 == xmlBytesRead;
- return -1;
- }
-
- public void mark(int readLimit) {
- bomStream.mark(xmlBOM.length);
- super.mark(readLimit);
- }
-
- public void reset() throws IOException {
- bomStream.reset();
- super.reset();
- }
-
- /**
- * Helper function to convert the entire PLP stream into a contiguous byte array. This call is inefficient (in terms of memory usage and run time)
- * for very large PLPs. Use it only if a contiguous byte array is required.
- */
- byte[] getBytes() throws SQLServerException {
- // Look to see if the BOM has been read
- byte[] bom = new byte[2];
- try {
- int bytesread = bomStream.read(bom);
- byte[] valueWithoutBOM = super.getBytes();
-
- if (bytesread > 0) {
- assert 2 == bytesread;
- byte[] valueWithBOM = new byte[valueWithoutBOM.length + bytesread];
- System.arraycopy(bom, 0, valueWithBOM, 0, bytesread);
- System.arraycopy(valueWithoutBOM, 0, valueWithBOM, bytesread, valueWithoutBOM.length);
- return valueWithBOM;
- }
- else
- return valueWithoutBOM;
- }
- catch (IOException e) {
- SQLServerException.makeFromDriverError(null, null, e.getMessage(), null, true);
- }
-
- return null;
- }
-}
+/*
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ */
+
+package com.microsoft.sqlserver.jdbc;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+
+
+/**
+ * PLPInputStream is an InputStream implementation that reads from a TDS PLP stream.
+ *
+ * Note PLP stands for Partially Length-prefixed Bytes. TDS 7.2 introduced this new streaming format for streaming of
+ * large types such as varchar(max), nvarchar(max), varbinary(max) and XML.
+ *
+ * See TDS specification, 6.3.3 Datatype Dependant Data Streams: Partially Length-prefixed Bytes for more details on the
+ * PLP format.
+ */
+
+class PLPInputStream extends BaseInputStream {
+ static final long PLP_NULL = 0xFFFFFFFFFFFFFFFFL;
+ static final long UNKNOWN_PLP_LEN = 0xFFFFFFFFFFFFFFFEL;
+ static final int PLP_TERMINATOR = 0x00000000;
+ private final static byte[] EMPTY_PLP_BYTES = new byte[0];
+
+ // Stated length of the PLP stream payload; -1 if unknown length.
+ int payloadLength;
+
+ private static final int PLP_EOS = -1;
+ private int currentChunkRemain;
+
+ private int markedChunkRemain;
+ private int leftOverReadLimit = 0;
+
+ private byte[] oneByteArray = new byte[1];
+
+ /**
+ * Non-destructive method for checking whether a PLP value at the current TDSReader location is null.
+ */
+ final static boolean isNull(TDSReader tdsReader) throws SQLServerException {
+ TDSReaderMark mark = tdsReader.mark();
+ // Temporary stream cannot get closes, since it closes the main stream.
+ try {
+ return null == PLPInputStream.makeTempStream(tdsReader, false, null);
+ } finally {
+ tdsReader.reset(mark);
+ }
+ }
+
+ /**
+ * Create a new input stream.
+ *
+ * @param tdsReader
+ * TDS reader pointing at the start of the PLP data
+ * @param discardValue
+ * boolean to represent if base input stream is adaptive and is streaming
+ * @param dtv
+ * DTV implementation for values set from the TDS response stream.
+ * @return PLPInputStream that is created
+ * @throws SQLServerException
+ * when an error occurs
+ */
+ final static PLPInputStream makeTempStream(TDSReader tdsReader, boolean discardValue,
+ ServerDTVImpl dtv) throws SQLServerException {
+ return makeStream(tdsReader, discardValue, discardValue, dtv);
+ }
+
+ final static PLPInputStream makeStream(TDSReader tdsReader, InputStreamGetterArgs getterArgs,
+ ServerDTVImpl dtv) throws SQLServerException {
+ PLPInputStream is = makeStream(tdsReader, getterArgs.isAdaptive, getterArgs.isStreaming, dtv);
+ if (null != is)
+ is.setLoggingInfo(getterArgs.logContext);
+ return is;
+ }
+
+ private static PLPInputStream makeStream(TDSReader tdsReader, boolean isAdaptive, boolean isStreaming,
+ ServerDTVImpl dtv) throws SQLServerException {
+ // Read total length of PLP stream.
+ long payloadLength = tdsReader.readLong();
+
+ // If length is PLP_NULL, then return a null PLP value.
+ if (PLP_NULL == payloadLength)
+ return null;
+
+ return new PLPInputStream(tdsReader, payloadLength, isAdaptive, isStreaming, dtv);
+ }
+
+ /**
+ * Initializes the input stream.
+ */
+ PLPInputStream(TDSReader tdsReader, long statedPayloadLength, boolean isAdaptive, boolean isStreaming,
+ ServerDTVImpl dtv) throws SQLServerException {
+ super(tdsReader, isAdaptive, isStreaming, dtv);
+ this.payloadLength = (UNKNOWN_PLP_LEN != statedPayloadLength) ? ((int) statedPayloadLength) : -1;
+ this.currentChunkRemain = this.markedChunkRemain = 0;
+ }
+
+ /**
+ * Helper function to convert the entire PLP stream into a contiguous byte array. This call is inefficient (in terms
+ * of memory usage and run time) for very large PLPs. Use it only if a contiguous byte array is required.
+ */
+ byte[] getBytes() throws SQLServerException {
+ byte[] value;
+
+ // The following 0-byte read just ensures that the number of bytes
+ // remaining in the current chunk is known.
+ readBytesInternal(null, 0, 0);
+
+ if (PLP_EOS == currentChunkRemain) {
+ value = EMPTY_PLP_BYTES;
+ } else {
+ // If the PLP payload length is known, allocate the final byte array now.
+ // Otherwise, start with the size of the first chunk. Additional chunks
+ // will cause the array to be reallocated & copied.
+ value = new byte[(-1 != payloadLength) ? payloadLength : currentChunkRemain];
+
+ int bytesRead = 0;
+ while (PLP_EOS != currentChunkRemain) {
+ // If the current byte array isn't large enough to hold
+ // the contents of the current chunk, then make it larger.
+ if (value.length == bytesRead) {
+ byte[] newValue = new byte[bytesRead + currentChunkRemain];
+ System.arraycopy(value, 0, newValue, 0, bytesRead);
+ value = newValue;
+ }
+
+ bytesRead += readBytesInternal(value, bytesRead, currentChunkRemain);
+ }
+ }
+
+ // Always close the stream after retrieving it
+ try {
+ close();
+ } catch (IOException e) {
+ SQLServerException.makeFromDriverError(null, null, e.getMessage(), null, true);
+ }
+
+ return value;
+ }
+
+ /**
+ * Skips over and discards n bytes of data from this input stream.
+ *
+ * @param n
+ * the number of bytes to be skipped.
+ * @return the actual number of bytes skipped.
+ * @exception IOException
+ * if an I/O error occurs.
+ */
+ public long skip(long n) throws IOException {
+ checkClosed();
+ if (n < 0)
+ return 0L;
+ if (n > Integer.MAX_VALUE)
+ n = Integer.MAX_VALUE;
+
+ long bytesread = readBytes(null, 0, (int) n);
+
+ if (-1 == bytesread)
+ return 0;
+ else
+ return bytesread;
+ }
+
+ /**
+ * Returns the number of bytes that can be read (or skipped over) from this input stream without blocking by the
+ * next caller of a method for this input stream.
+ *
+ * @return the actual number of bytes available.
+ * @exception IOException
+ * if an I/O error occurs.
+ */
+ public int available() throws IOException {
+ checkClosed();
+ try {
+
+ // The following 0-byte read just ensures that the number of bytes
+ // remaining in the current chunk is known.
+ if (0 == currentChunkRemain)
+ readBytesInternal(null, 0, 0);
+
+ if (PLP_EOS == currentChunkRemain)
+ return 0;
+
+ // Return the lesser of the number of bytes available for reading
+ // from the underlying TDSReader and the number of bytes left in
+ // the current chunk.
+ int available = tdsReader.available();
+ if (available > currentChunkRemain)
+ available = currentChunkRemain;
+
+ return available;
+ } catch (SQLServerException e) {
+ throw new IOException(e.getMessage());
+ }
+
+ }
+
+ /**
+ * Reads the next byte of data from the input stream.
+ *
+ * @return the byte read or -1 meaning no more bytes.
+ * @exception IOException
+ * if an I/O error occurs.
+ */
+ public int read() throws IOException {
+ checkClosed();
+
+ if (-1 != readBytes(oneByteArray, 0, 1))
+ return oneByteArray[0] & 0xFF;
+ return -1;
+ }
+
+ /**
+ * Reads available data into supplied byte array.
+ *
+ * @param b
+ * array of bytes to fill.
+ * @return the number of bytes read or 0 meaning no bytes read.
+ * @exception IOException
+ * if an I/O error occurs.
+ */
+ public int read(byte[] b) throws IOException {
+ // If b is null, a NullPointerException is thrown.
+ if (null == b)
+ throw new NullPointerException();
+
+ checkClosed();
+
+ return readBytes(b, 0, b.length);
+ }
+
+ /**
+ * Reads available data into supplied byte array.
+ *
+ * @param b
+ * array of bytes to fill.
+ * @param offset
+ * the offset into array b where to start writing.
+ * @param maxBytes
+ * the max number of bytes to write into b.
+ * @return the number of bytes read or 0 meaning no bytes read.
+ * @exception IOException
+ * if an I/O error occurs.
+ */
+ public int read(byte b[], int offset, int maxBytes) throws IOException {
+ // If b is null, a NullPointerException is thrown.
+ if (null == b)
+ throw new NullPointerException();
+
+ // Verify offset and maxBytes against target buffer if we're reading (as opposed to skipping).
+ // If offset is negative, or maxBytes is negative, or offset+maxBytes
+ // is greater than the length of the array b, then an IndexOutOfBoundsException is thrown.
+ if (offset < 0 || maxBytes < 0 || offset + maxBytes > b.length)
+ throw new IndexOutOfBoundsException();
+
+ checkClosed();
+
+ return readBytes(b, offset, maxBytes);
+ }
+
+ /**
+ * Reads available data into supplied byte array b.
+ *
+ * @param b
+ * array of bytes to fill. If b is null, method will skip over data.
+ * @param offset
+ * the offset into array b where to start writing.
+ * @param maxBytes
+ * the max number of bytes to write into b.
+ * @return the number of bytes read or 0 meaning no bytes read or -1 meaning EOS.
+ * @exception IOException
+ * if an I/O error occurs.
+ */
+ int readBytes(byte[] b, int offset, int maxBytes) throws IOException {
+ // If maxBytes is zero, then no bytes are read and 0 is returned
+ // This must be done here rather than in readBytesInternal since a 0-byte read
+ // there may return -1 at EOS.
+ if (0 == maxBytes)
+ return 0;
+
+ try {
+ return readBytesInternal(b, offset, maxBytes);
+ } catch (SQLServerException e) {
+ throw new IOException(e.getMessage());
+ }
+ }
+
+ private int readBytesInternal(byte b[], int offset, int maxBytes) throws SQLServerException {
+ // If we're at EOS, say so.
+ // Note: For back compat, this special case needs to always be handled
+ // before checking user-supplied arguments below.
+ if (PLP_EOS == currentChunkRemain)
+ return -1;
+
+ // Save off the current TDSReader position, wherever it is, and start reading
+ // from where we left off last time.
+
+ int bytesRead = 0;
+ for (;;) {
+ // Check that we have bytes left to read from the current chunk.
+ // If not then figure out the size of the next chunk or
+ // determine that we have reached the end of the stream.
+ if (0 == currentChunkRemain) {
+ currentChunkRemain = (int) tdsReader.readUnsignedInt();
+ assert currentChunkRemain >= 0;
+ if (0 == currentChunkRemain) {
+ currentChunkRemain = PLP_EOS;
+ break;
+ }
+ }
+
+ if (bytesRead == maxBytes)
+ break;
+
+ // Now we know there are bytes to be read in the current chunk.
+ // Further limit the max number of bytes we can read to whatever
+ // remains in the current chunk.
+ int bytesToRead = maxBytes - bytesRead;
+ if (bytesToRead > currentChunkRemain)
+ bytesToRead = currentChunkRemain;
+
+ // Skip/Read as many bytes as we can, given the constraints.
+ if (null == b)
+ tdsReader.skip(bytesToRead);
+ else
+ tdsReader.readBytes(b, offset + bytesRead, bytesToRead);
+
+ bytesRead += bytesToRead;
+ currentChunkRemain -= bytesToRead;
+ }
+
+ if (bytesRead > 0) {
+ if (isReadLimitSet && leftOverReadLimit > 0) {
+ leftOverReadLimit = leftOverReadLimit - bytesRead;
+ if (leftOverReadLimit < 0)
+ clearCurrentMark();
+ }
+ return bytesRead;
+ }
+
+ if (PLP_EOS == currentChunkRemain)
+ return -1;
+
+ return 0;
+ }
+
+ /**
+ * Marks the current position in this input stream.
+ *
+ * @param readlimit
+ * the number of bytes to hold (this implementation ignores this).
+ */
+ public void mark(int readLimit) {
+ // Save off current position and how much of the current chunk remains
+ // cant throw if the tdsreader is null
+ if (null != tdsReader && readLimit > 0) {
+ currentMark = tdsReader.mark();
+ markedChunkRemain = currentChunkRemain;
+ leftOverReadLimit = readLimit;
+ setReadLimit(readLimit);
+ }
+ }
+
+ /**
+ * Closes the stream releasing all resources held.
+ *
+ * @exception IOException
+ * if an I/O error occurs.
+ */
+ public void close() throws IOException {
+ if (null == tdsReader)
+ return;
+
+ while (skip(tdsReader.getConnection().getTDSPacketSize()) != 0);
+ // Release ref to tdsReader and parentRS here, shut down stream state.
+ closeHelper();
+ }
+
+ /**
+ * Resets stream to saved mark position.
+ *
+ * @exception IOException
+ * if an I/O error occurs.
+ */
+ public void reset() throws IOException {
+ resetHelper();
+ leftOverReadLimit = readLimit;
+ currentChunkRemain = markedChunkRemain;
+ }
+}
+
+
+/**
+ * Implements an XML binary stream with BOM header.
+ *
+ * Class extends a normal PLPInputStream class and prepends the XML BOM (0xFFFE) token then steps out of the way and
+ * forwards the rest of the InputStream calls to the super class PLPInputStream.
+ */
+final class PLPXMLInputStream extends PLPInputStream {
+ // XML BOM header (the first two header bytes sent to caller).
+ private final static byte[] xmlBOM = {(byte) 0xFF, (byte) 0xFE};
+ private final ByteArrayInputStream bomStream = new ByteArrayInputStream(xmlBOM);
+
+ final static PLPXMLInputStream makeXMLStream(TDSReader tdsReader, InputStreamGetterArgs getterArgs,
+ ServerDTVImpl dtv) throws SQLServerException {
+ // Read total length of PLP stream.
+ long payloadLength = tdsReader.readLong();
+
+ // If length is PLP_NULL, then return a null PLP value.
+ if (PLP_NULL == payloadLength)
+ return null;
+
+ PLPXMLInputStream is = new PLPXMLInputStream(tdsReader, payloadLength, getterArgs, dtv);
+ is.setLoggingInfo(getterArgs.logContext);
+
+ return is;
+ }
+
+ PLPXMLInputStream(TDSReader tdsReader, long statedPayloadLength, InputStreamGetterArgs getterArgs,
+ ServerDTVImpl dtv) throws SQLServerException {
+ super(tdsReader, statedPayloadLength, getterArgs.isAdaptive, getterArgs.isStreaming, dtv);
+ }
+
+ public void close() throws IOException {
+ super.close();
+ }
+
+ int readBytes(byte[] b, int offset, int maxBytes) throws IOException {
+ assert offset >= 0;
+ assert maxBytes >= 0;
+ // If maxBytes is zero, then no bytes are read and 0 is returned.
+ if (0 == maxBytes)
+ return 0;
+
+ int bytesRead = 0;
+ int xmlBytesRead = 0;
+
+ // Read/Skip BOM bytes first. When all BOM bytes have been consumed ...
+ if (null == b) {
+ for (int bomBytesSkipped;
+ bytesRead < maxBytes
+ && 0 != (bomBytesSkipped = (int) bomStream.skip(((long) maxBytes) - ((long) bytesRead)));
+ bytesRead += bomBytesSkipped);
+ } else {
+ for (int bomBytesRead;
+ bytesRead < maxBytes
+ && -1 != (bomBytesRead = bomStream.read(b, offset + bytesRead, maxBytes - bytesRead));
+ bytesRead += bomBytesRead);
+ }
+
+ // ... then read/skip bytes from the underlying PLPInputStream
+ for (; bytesRead < maxBytes
+ && -1 != (xmlBytesRead = super.readBytes(b, offset + bytesRead, maxBytes - bytesRead));
+ bytesRead += xmlBytesRead);
+
+ if (bytesRead > 0)
+ return bytesRead;
+
+ // No bytes read - should have been EOF since 0-byte reads are handled above
+ assert -1 == xmlBytesRead;
+ return -1;
+ }
+
+ public void mark(int readLimit) {
+ bomStream.mark(xmlBOM.length);
+ super.mark(readLimit);
+ }
+
+ public void reset() throws IOException {
+ bomStream.reset();
+ super.reset();
+ }
+
+ /**
+ * Helper function to convert the entire PLP stream into a contiguous byte array. This call is inefficient (in terms
+ * of memory usage and run time) for very large PLPs. Use it only if a contiguous byte array is required.
+ */
+ byte[] getBytes() throws SQLServerException {
+ // Look to see if the BOM has been read
+ byte[] bom = new byte[2];
+ try {
+ int bytesread = bomStream.read(bom);
+ byte[] valueWithoutBOM = super.getBytes();
+
+ if (bytesread > 0) {
+ assert 2 == bytesread;
+ byte[] valueWithBOM = new byte[valueWithoutBOM.length + bytesread];
+ System.arraycopy(bom, 0, valueWithBOM, 0, bytesread);
+ System.arraycopy(valueWithoutBOM, 0, valueWithBOM, bytesread, valueWithoutBOM.length);
+ return valueWithBOM;
+ } else
+ return valueWithoutBOM;
+ } catch (IOException e) {
+ SQLServerException.makeFromDriverError(null, null, e.getMessage(), null, true);
+ }
+
+ return null;
+ }
+}
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/Parameter.java b/src/main/java/com/microsoft/sqlserver/jdbc/Parameter.java
index 2a9c757d0..93758a09c 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/Parameter.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/Parameter.java
@@ -1,9 +1,6 @@
/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc;
@@ -28,8 +25,9 @@
/**
- * Parameter represents a JDBC parameter value that is supplied with a prepared or callable statement or an updatable result set. Parameter is JDBC
- * type specific and is capable of representing any Java native type as well as a number of Java object types including binary and character streams.
+ * Parameter represents a JDBC parameter value that is supplied with a prepared or callable statement or an updatable
+ * result set. Parameter is JDBC type specific and is capable of representing any Java native type as well as a number
+ * of Java object types including binary and character streams.
*/
final class Parameter {
@@ -80,8 +78,8 @@ JDBCType getJdbcType() throws SQLServerException {
}
/**
- * Used when sendStringParametersAsUnicode=true to derive the appropriate National Character Set JDBC type corresponding to the specified JDBC
- * type.
+ * Used when sendStringParametersAsUnicode=true to derive the appropriate National Character Set JDBC type
+ * corresponding to the specified JDBC type.
*/
private static JDBCType getSSPAUJDBCType(JDBCType jdbcType) {
switch (jdbcType) {
@@ -101,12 +99,11 @@ private static JDBCType getSSPAUJDBCType(JDBCType jdbcType) {
// For parameters whose underlying type is not represented by a JDBC type
// the transport type reflects how the value is sent to the
// server (e.g. JDBCType.CHAR for GUID parameters).
- void registerForOutput(JDBCType jdbcType,
- SQLServerConnection con) throws SQLServerException {
+ void registerForOutput(JDBCType jdbcType, SQLServerConnection con) throws SQLServerException {
// DateTimeOffset is not supported with SQL Server versions earlier than Katmai
if (JDBCType.DATETIMEOFFSET == jdbcType && !con.isKatmaiOrLater()) {
- throw new SQLServerException(SQLServerException.getErrString("R_notSupported"), SQLState.DATA_EXCEPTION_NOT_SPECIFIC, DriverError.NOT_SET,
- null);
+ throw new SQLServerException(SQLServerException.getErrString("R_notSupported"),
+ SQLState.DATA_EXCEPTION_NOT_SPECIFIC, DriverError.NOT_SET, null);
}
// sendStringParametersAsUnicode
@@ -152,22 +149,18 @@ void setOutScale(int outScale) {
private String schemaName;
/*
- * The different DTVs representing the parameter's value:
- *
- * getterDTV - The OUT value, if set, of the parameter after execution. This is the value retrieved by CallableStatement getter methods.
- *
- * registeredOutDTV - The "IN" value corresponding to a SQL NULL with a JDBC type that was passed to the CallableStatement.registerOutParameter
- * method. Since SQL Server does not directly support OUT-only parameters (just IN and IN/OUT), the driver sends a null IN value for an OUT
- * parameter, unless the application set an input value (setterDTV) as well.
- *
- * setterDTV - The IN value, if set, of the parameter. This is the value set by PreparedStatement and CallableStatement setter methods.
- *
- * inputDTV - If set, refers to either setterDTV or registeredOutDTV depending on whether the parameter is IN, IN/OUT, or OUT-only. If cleared
- * (i.e. set to null), it means that no value is set for the parameter and that execution of the PreparedStatement or CallableStatement should
- * throw a "parameter not set" exception.
- *
- * Note that if the parameter value is a stream, the driver consumes its contents it at execution and clears inputDTV and setterDTV so that the
- * application must reset the parameter prior to the next execution to avoid getting a "parameter not set" exception.
+ * The different DTVs representing the parameter's value: getterDTV - The OUT value, if set, of the parameter after
+ * execution. This is the value retrieved by CallableStatement getter methods. registeredOutDTV - The "IN" value
+ * corresponding to a SQL NULL with a JDBC type that was passed to the CallableStatement.registerOutParameter
+ * method. Since SQL Server does not directly support OUT-only parameters (just IN and IN/OUT), the driver sends a
+ * null IN value for an OUT parameter, unless the application set an input value (setterDTV) as well. setterDTV -
+ * The IN value, if set, of the parameter. This is the value set by PreparedStatement and CallableStatement setter
+ * methods. inputDTV - If set, refers to either setterDTV or registeredOutDTV depending on whether the parameter is
+ * IN, IN/OUT, or OUT-only. If cleared (i.e. set to null), it means that no value is set for the parameter and that
+ * execution of the PreparedStatement or CallableStatement should throw a "parameter not set" exception. Note that
+ * if the parameter value is a stream, the driver consumes its contents it at execution and clears inputDTV and
+ * setterDTV so that the application must reset the parameter prior to the next execution to avoid getting a
+ * "parameter not set" exception.
*/
private DTV getterDTV;
private DTV registeredOutDTV = null;
@@ -177,10 +170,11 @@ void setOutScale(int outScale) {
/**
* Clones this Parameter object for use in a batch.
*
- * The clone method creates a shallow clone of the Parameter object. That is, the cloned instance references all of the same internal objects and
- * state as the original.
+ * The clone method creates a shallow clone of the Parameter object. That is, the cloned instance references all of
+ * the same internal objects and state as the original.
*
- * Note: this method is purposely NOT the Object.clone() method, as that method has specific requirements and semantics that we don't need here.
+ * Note: this method is purposely NOT the Object.clone() method, as that method has specific requirements and
+ * semantics that we don't need here.
*/
final Parameter cloneForBatch() {
Parameter clonedParam = new Parameter(shouldHonorAEForParameter);
@@ -203,8 +197,7 @@ final Parameter cloneForBatch() {
/**
* Skip value.
*/
- final void skipValue(TDSReader tdsReader,
- boolean isDiscard) throws SQLServerException {
+ final void skipValue(TDSReader tdsReader, boolean isDiscard) throws SQLServerException {
if (null == getterDTV)
getterDTV = new DTV();
@@ -249,26 +242,17 @@ void deriveTypeInfo(TDSReader tdsReader) throws SQLServerException {
}
}
- void setFromReturnStatus(int returnStatus,
- SQLServerConnection con) throws SQLServerException {
+ void setFromReturnStatus(int returnStatus, SQLServerConnection con) throws SQLServerException {
if (null == getterDTV)
getterDTV = new DTV();
- getterDTV.setValue(null, JDBCType.INTEGER, returnStatus, JavaType.INTEGER, null, null, null, con, getForceEncryption());
+ getterDTV.setValue(null, JDBCType.INTEGER, returnStatus, JavaType.INTEGER, null, null, null, con,
+ getForceEncryption());
}
- void setValue(JDBCType jdbcType,
- Object value,
- JavaType javaType,
- StreamSetterArgs streamSetterArgs,
- Calendar calendar,
- Integer precision,
- Integer scale,
- SQLServerConnection con,
- boolean forceEncrypt,
- SQLServerStatementColumnEncryptionSetting stmtColumnEncriptionSetting,
- int parameterIndex,
- String userSQL,
+ void setValue(JDBCType jdbcType, Object value, JavaType javaType, StreamSetterArgs streamSetterArgs,
+ Calendar calendar, Integer precision, Integer scale, SQLServerConnection con, boolean forceEncrypt,
+ SQLServerStatementColumnEncryptionSetting stmtColumnEncriptionSetting, int parameterIndex, String userSQL,
String tvpName) throws SQLServerException {
if (shouldHonorAEForParameter) {
@@ -288,7 +272,8 @@ void setValue(JDBCType jdbcType,
// Also, for setters, we are able to send tinyint to smallint
// However, for output parameter, it might cause error.
if (!isOutput()) {
- if ((JavaType.SHORT == javaType) && ((JDBCType.TINYINT == jdbcType) || (JDBCType.SMALLINT == jdbcType))) {
+ if ((JavaType.SHORT == javaType)
+ && ((JDBCType.TINYINT == jdbcType) || (JDBCType.SMALLINT == jdbcType))) {
// value falls in the TINYINT range
if (((Short) value) >= 0 && ((Short) value) <= 255) {
value = ((Short) value).byteValue();
@@ -299,8 +284,10 @@ void setValue(JDBCType jdbcType,
else {
// This is for cases like setObject(1, Short.valueOf("-1"), java.sql.Types.TINYINT);
if (JDBCType.TINYINT == jdbcType) {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_InvalidDataForAE"));
- Object[] msgArgs = {javaType.toString().toLowerCase(Locale.ENGLISH), jdbcType.toString().toLowerCase(Locale.ENGLISH)};
+ MessageFormat form = new MessageFormat(
+ SQLServerException.getErrString("R_InvalidDataForAE"));
+ Object[] msgArgs = {javaType.toString().toLowerCase(Locale.ENGLISH),
+ jdbcType.toString().toLowerCase(Locale.ENGLISH)};
throw new SQLServerException(form.format(msgArgs), null);
}
}
@@ -311,7 +298,8 @@ void setValue(JDBCType jdbcType,
// forceEncryption is true, shouldhonorae is false
if ((true == forceEncrypt) && (false == Util.shouldHonorAEForParameters(stmtColumnEncriptionSetting, con))) {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_ForceEncryptionTrue_HonorAEFalse"));
+ MessageFormat form = new MessageFormat(
+ SQLServerException.getErrString("R_ForceEncryptionTrue_HonorAEFalse"));
Object[] msgArgs = {parameterIndex, userSQL};
SQLServerException.makeFromDriverError(con, this, form.format(msgArgs), null, true);
@@ -319,25 +307,21 @@ void setValue(JDBCType jdbcType,
// DateTimeOffset is not supported with SQL Server versions earlier than Katmai
if ((JDBCType.DATETIMEOFFSET == jdbcType || JavaType.DATETIMEOFFSET == javaType) && !con.isKatmaiOrLater()) {
- throw new SQLServerException(SQLServerException.getErrString("R_notSupported"), SQLState.DATA_EXCEPTION_NOT_SPECIFIC, DriverError.NOT_SET,
- null);
+ throw new SQLServerException(SQLServerException.getErrString("R_notSupported"),
+ SQLState.DATA_EXCEPTION_NOT_SPECIFIC, DriverError.NOT_SET, null);
}
if (JavaType.TVP == javaType) {
TVP tvpValue;
if (null == value) {
tvpValue = new TVP(tvpName);
- }
- else if (value instanceof SQLServerDataTable) {
+ } else if (value instanceof SQLServerDataTable) {
tvpValue = new TVP(tvpName, (SQLServerDataTable) value);
- }
- else if (value instanceof ResultSet) {
+ } else if (value instanceof ResultSet) {
tvpValue = new TVP(tvpName, (ResultSet) value);
- }
- else if (value instanceof ISQLServerDataRecord) {
+ } else if (value instanceof ISQLServerDataRecord) {
tvpValue = new TVP(tvpName, (ISQLServerDataRecord) value);
- }
- else {
+ } else {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_TVPInvalidValue"));
Object[] msgArgs = {parameterIndex};
throw new SQLServerException(form.format(msgArgs), null);
@@ -376,13 +360,14 @@ else if (value instanceof ISQLServerDataRecord) {
// to the server as Unicode rather than MBCS. This is accomplished here by re-tagging
// the value with the appropriate corresponding Unicode type.
// JavaType.OBJECT == javaType when calling setNull()
- if (con.sendStringParametersAsUnicode()
- && (JavaType.STRING == javaType || JavaType.READER == javaType || JavaType.CLOB == javaType || JavaType.OBJECT == javaType)) {
+ if (con.sendStringParametersAsUnicode() && (JavaType.STRING == javaType || JavaType.READER == javaType
+ || JavaType.CLOB == javaType || JavaType.OBJECT == javaType)) {
jdbcType = getSSPAUJDBCType(jdbcType);
}
DTV newDTV = new DTV();
- newDTV.setValue(con.getDatabaseCollation(), jdbcType, value, javaType, streamSetterArgs, calendar, scale, con, forceEncrypt);
+ newDTV.setValue(con.getDatabaseCollation(), jdbcType, value, javaType, streamSetterArgs, calendar, scale, con,
+ forceEncrypt);
if (!con.sendStringParametersAsUnicode()) {
newDTV.sendStringParametersAsUnicode = false;
@@ -403,9 +388,7 @@ boolean isValueGotten() {
}
- Object getValue(JDBCType jdbcType,
- InputStreamGetterArgs getterArgs,
- Calendar cal,
+ Object getValue(JDBCType jdbcType, InputStreamGetterArgs getterArgs, Calendar cal,
TDSReader tdsReader) throws SQLServerException {
if (null == getterDTV)
getterDTV = new DTV();
@@ -415,7 +398,7 @@ Object getValue(JDBCType jdbcType,
// statement level), cryptoMeta would be null.
return getterDTV.getValue(jdbcType, outScale, getterArgs, cal, typeInfo, cryptoMeta, tdsReader);
}
-
+
Object getSetterValue() {
return setterDTV.getSetterValue();
}
@@ -444,8 +427,7 @@ final class GetTypeDefinitionOp extends DTVExecuteOp {
private final Parameter param;
private final SQLServerConnection con;
- GetTypeDefinitionOp(Parameter param,
- SQLServerConnection con) {
+ GetTypeDefinitionOp(Parameter param, SQLServerConnection con) {
this.param = param;
this.con = con;
}
@@ -473,18 +455,18 @@ private void setTypeDefinition(DTV dtv) {
if (param.shouldHonorAEForParameter && (null != jdbcTypeSetByUser)
&& !(null == param.getCryptoMetadata() && param.renewDefinition)) {
/*
- * This means AE is ON in the connection, and (1) this is either the first round to SQL Server to get encryption meta data, or
- * (2) this is the second round of renewing meta data and parameter is encrypted In both of these cases we need to send
- * specific type info, otherwise generic type info can be used as before.
+ * This means AE is ON in the connection, and (1) this is either the first round to SQL Server
+ * to get encryption meta data, or (2) this is the second round of renewing meta data and
+ * parameter is encrypted In both of these cases we need to send specific type info, otherwise
+ * generic type info can be used as before.
*/
param.typeDefinition = SSType.REAL.toString();
- }
- else {
+ } else {
// use FLOAT if column is not encrypted
param.typeDefinition = SSType.FLOAT.toString();
}
break;
-
+
case FLOAT:
case DOUBLE:
param.typeDefinition = SSType.FLOAT.toString();
@@ -510,42 +492,46 @@ private void setTypeDefinition(DTV dtv) {
if (param.shouldHonorAEForParameter && (null != jdbcTypeSetByUser)
&& !(null == param.getCryptoMetadata() && param.renewDefinition)) {
/*
- * This means AE is ON in the connection, and (1) this is either the first round to SQL Server to get encryption meta data, or
- * (2) this is the second round of renewing meta data and parameter is encrypted In both of these cases we need to send
- * specific type info, otherwise generic type info can be used as before.
+ * This means AE is ON in the connection, and (1) this is either the first round to SQL Server
+ * to get encryption meta data, or (2) this is the second round of renewing meta data and
+ * parameter is encrypted In both of these cases we need to send specific type info, otherwise
+ * generic type info can be used as before.
*/
if (0 == valueLength) {
- // for prepared statement and callable statement, There are only two cases where valueLength is 0:
+ // for prepared statement and callable statement, There are only two cases where valueLength
+ // is 0:
// 1. when the parameter is output parameter
// 2. for input parameter, the value is null
// so, here, if the decimal parameter is encrypted and it is null and it is not outparameter
// then we set precision as the default precision instead of max precision
if (!isOutput()) {
- param.typeDefinition = "decimal(" + SQLServerConnection.defaultDecimalPrecision + ", " + scale + ")";
+ param.typeDefinition = "decimal(" + SQLServerConnection.defaultDecimalPrecision + ", "
+ + scale + ")";
}
- }
- else {
+ } else {
if (SQLServerConnection.defaultDecimalPrecision >= valueLength) {
- param.typeDefinition = "decimal(" + SQLServerConnection.defaultDecimalPrecision + "," + scale + ")";
+ param.typeDefinition = "decimal(" + SQLServerConnection.defaultDecimalPrecision + ","
+ + scale + ")";
if (SQLServerConnection.defaultDecimalPrecision < (valueLength + scale)) {
- param.typeDefinition = "decimal(" + (SQLServerConnection.defaultDecimalPrecision + scale) + "," + scale + ")";
+ param.typeDefinition = "decimal("
+ + (SQLServerConnection.defaultDecimalPrecision + scale) + "," + scale + ")";
}
- }
- else {
- param.typeDefinition = "decimal(" + SQLServerConnection.maxDecimalPrecision + "," + scale + ")";
+ } else {
+ param.typeDefinition = "decimal(" + SQLServerConnection.maxDecimalPrecision + ","
+ + scale + ")";
}
}
if (isOutput()) {
- param.typeDefinition = "decimal(" + SQLServerConnection.maxDecimalPrecision + ", " + scale + ")";
+ param.typeDefinition = "decimal(" + SQLServerConnection.maxDecimalPrecision + ", " + scale
+ + ")";
}
if (userProvidesPrecision) {
param.typeDefinition = "decimal(" + valueLength + "," + scale + ")";
}
- }
- else
+ } else
param.typeDefinition = "decimal(" + SQLServerConnection.maxDecimalPrecision + "," + scale + ")";
break;
@@ -556,7 +542,8 @@ private void setTypeDefinition(DTV dtv) {
case SMALLMONEY:
param.typeDefinition = SSType.MONEY.toString();
- if (param.shouldHonorAEForParameter && !(null == param.getCryptoMetadata() && param.renewDefinition)) {
+ if (param.shouldHonorAEForParameter
+ && !(null == param.getCryptoMetadata() && param.renewDefinition)) {
param.typeDefinition = SSType.SMALLMONEY.toString();
}
@@ -579,24 +566,23 @@ private void setTypeDefinition(DTV dtv) {
if (param.shouldHonorAEForParameter && (null != jdbcTypeSetByUser)
&& !(null == param.getCryptoMetadata() && param.renewDefinition)) {
/*
- * This means AE is ON in the connection, and (1) this is either the first round to SQL Server to get encryption meta data, or
- * (2) this is the second round of renewing meta data and parameter is encrypted In both of these cases we need to send
- * specific type info, otherwise generic type info can be used as before.
+ * This means AE is ON in the connection, and (1) this is either the first round to SQL Server
+ * to get encryption meta data, or (2) this is the second round of renewing meta data and
+ * parameter is encrypted In both of these cases we need to send specific type info, otherwise
+ * generic type info can be used as before.
*/
if (0 == valueLength) {
// Workaround for the issue when inserting empty string and null into encrypted columns
param.typeDefinition = "varbinary(1)";
valueLength++;
- }
- else {
+ } else {
param.typeDefinition = "varbinary(" + valueLength + ")";
}
if (JDBCType.LONGVARBINARY == jdbcTypeSetByUser) {
param.typeDefinition = VARBINARY_MAX;
}
- }
- else
+ } else
param.typeDefinition = VARBINARY_8K;
break;
@@ -606,46 +592,52 @@ private void setTypeDefinition(DTV dtv) {
break;
case TIME:
- if (param.shouldHonorAEForParameter && !(null == param.getCryptoMetadata() && param.renewDefinition)) {
+ if (param.shouldHonorAEForParameter
+ && !(null == param.getCryptoMetadata() && param.renewDefinition)) {
/*
- * This means AE is ON in the connection, and (1) this is either the first round to SQL Server to get encryption meta data, or
- * (2) this is the second round of renewing meta data and parameter is encrypted In both of these cases we need to send
- * specific type info, otherwise generic type info can be used as before.
+ * This means AE is ON in the connection, and (1) this is either the first round to SQL Server
+ * to get encryption meta data, or (2) this is the second round of renewing meta data and
+ * parameter is encrypted In both of these cases we need to send specific type info, otherwise
+ * generic type info can be used as before.
*/
if (userProvidesScale) {
param.typeDefinition = (SSType.TIME.toString() + "(" + outScale + ")");
+ } else {
+ param.typeDefinition = param.typeDefinition = SSType.TIME.toString() + "(" + valueLength
+ + ")";
}
- else {
- param.typeDefinition = param.typeDefinition = SSType.TIME.toString() + "(" + valueLength + ")";
- }
- }
- else {
- param.typeDefinition = con.getSendTimeAsDatetime() ? SSType.DATETIME.toString() : SSType.TIME.toString();
+ } else {
+ param.typeDefinition = con.getSendTimeAsDatetime() ? SSType.DATETIME.toString()
+ : SSType.TIME.toString();
}
break;
case TIMESTAMP:
// Bind TIMESTAMP values to pre-Katmai servers as DATETIME. Bind TIMESTAMP values to
// Katmai and later servers as DATETIME2 to take advantage of increased precision.
- if (param.shouldHonorAEForParameter && !(null == param.getCryptoMetadata() && param.renewDefinition)) {
+ if (param.shouldHonorAEForParameter
+ && !(null == param.getCryptoMetadata() && param.renewDefinition)) {
/*
- * This means AE is ON in the connection, and (1) this is either the first round to SQL Server to get encryption meta data, or
- * (2) this is the second round of renewing meta data and parameter is encrypted In both of these cases we need to send
- * specific type info, otherwise generic type info can be used as before.
+ * This means AE is ON in the connection, and (1) this is either the first round to SQL Server
+ * to get encryption meta data, or (2) this is the second round of renewing meta data and
+ * parameter is encrypted In both of these cases we need to send specific type info, otherwise
+ * generic type info can be used as before.
*/
if (userProvidesScale) {
- param.typeDefinition = con.isKatmaiOrLater() ? (SSType.DATETIME2.toString() + "(" + outScale + ")")
- : (SSType.DATETIME.toString());
+ param.typeDefinition = con
+ .isKatmaiOrLater() ? (SSType.DATETIME2.toString() + "(" + outScale + ")")
+ : (SSType.DATETIME.toString());
+ } else {
+ param.typeDefinition = con.isKatmaiOrLater()
+ ? (SSType.DATETIME2.toString() + "("
+ + valueLength + ")")
+ : SSType.DATETIME.toString();
}
- else {
- param.typeDefinition = con.isKatmaiOrLater() ? (SSType.DATETIME2.toString() + "(" + valueLength + ")")
- : SSType.DATETIME.toString();
- }
- }
- else {
- param.typeDefinition = con.isKatmaiOrLater() ? SSType.DATETIME2.toString() : SSType.DATETIME.toString();
+ } else {
+ param.typeDefinition = con.isKatmaiOrLater() ? SSType.DATETIME2.toString()
+ : SSType.DATETIME.toString();
}
break;
@@ -653,7 +645,8 @@ private void setTypeDefinition(DTV dtv) {
// send as Datetime by default
param.typeDefinition = SSType.DATETIME2.toString();
- if (param.shouldHonorAEForParameter && !(null == param.getCryptoMetadata() && param.renewDefinition)) {
+ if (param.shouldHonorAEForParameter
+ && !(null == param.getCryptoMetadata() && param.renewDefinition)) {
param.typeDefinition = SSType.DATETIME.toString();
}
@@ -663,8 +656,7 @@ private void setTypeDefinition(DTV dtv) {
if (param.isOutput()) {
param.typeDefinition = SSType.DATETIME2.toString() + "(" + outScale + ")";
}
- }
- else {
+ } else {
// when AE is on, set it to Datetime by default,
// However, if column is not encrypted and it is output parameter of stored procedure,
// renew it to datetime2(3)
@@ -680,7 +672,8 @@ private void setTypeDefinition(DTV dtv) {
case SMALLDATETIME:
param.typeDefinition = SSType.DATETIME2.toString();
- if (param.shouldHonorAEForParameter && !(null == param.getCryptoMetadata() && param.renewDefinition)) {
+ if (param.shouldHonorAEForParameter
+ && !(null == param.getCryptoMetadata() && param.renewDefinition)) {
param.typeDefinition = SSType.SMALLDATETIME.toString();
}
@@ -689,20 +682,20 @@ private void setTypeDefinition(DTV dtv) {
case TIME_WITH_TIMEZONE:
case TIMESTAMP_WITH_TIMEZONE:
case DATETIMEOFFSET:
- if (param.shouldHonorAEForParameter && !(null == param.getCryptoMetadata() && param.renewDefinition)) {
+ if (param.shouldHonorAEForParameter
+ && !(null == param.getCryptoMetadata() && param.renewDefinition)) {
/*
- * This means AE is ON in the connection, and (1) this is either the first round to SQL Server to get encryption meta data, or
- * (2) this is the second round of renewing meta data and parameter is encrypted In both of these cases we need to send
- * specific type info, otherwise generic type info can be used as before.
+ * This means AE is ON in the connection, and (1) this is either the first round to SQL Server
+ * to get encryption meta data, or (2) this is the second round of renewing meta data and
+ * parameter is encrypted In both of these cases we need to send specific type info, otherwise
+ * generic type info can be used as before.
*/
if (userProvidesScale) {
param.typeDefinition = SSType.DATETIMEOFFSET.toString() + "(" + outScale + ")";
- }
- else {
+ } else {
param.typeDefinition = SSType.DATETIMEOFFSET.toString() + "(" + valueLength + ")";
}
- }
- else {
+ } else {
param.typeDefinition = SSType.DATETIMEOFFSET.toString();
}
break;
@@ -722,77 +715,72 @@ private void setTypeDefinition(DTV dtv) {
if (param.shouldHonorAEForParameter && (null != jdbcTypeSetByUser)
&& !(null == param.getCryptoMetadata() && param.renewDefinition)) {
/*
- * This means AE is ON in the connection, and (1) this is either the first round to SQL Server to get encryption meta data, or
- * (2) this is the second round of renewing meta data and parameter is encrypted In both of these cases we need to send
- * specific type info, otherwise generic type info can be used as before.
+ * This means AE is ON in the connection, and (1) this is either the first round to SQL Server
+ * to get encryption meta data, or (2) this is the second round of renewing meta data and
+ * parameter is encrypted In both of these cases we need to send specific type info, otherwise
+ * generic type info can be used as before.
*/
if (0 == valueLength) {
// Workaround for the issue when inserting empty string and null into encrypted columns
param.typeDefinition = "varchar(1)";
valueLength++;
- }
- else {
+ } else {
param.typeDefinition = "varchar(" + valueLength + ")";
if (DataTypes.SHORT_VARTYPE_MAX_BYTES <= valueLength) {
param.typeDefinition = VARCHAR_MAX;
}
}
- }
- else
+ } else
param.typeDefinition = VARCHAR_8K;
break;
case LONGNVARCHAR:
- if (param.shouldHonorAEForParameter && !(null == param.getCryptoMetadata() && param.renewDefinition)) {
+ if (param.shouldHonorAEForParameter
+ && !(null == param.getCryptoMetadata() && param.renewDefinition)) {
/*
- * This means AE is ON in the connection, and (1) this is either the first round to SQL Server to get encryption meta data, or
- * (2) this is the second round of renewing meta data and parameter is encrypted In both of these cases we need to send
- * specific type info, otherwise generic type info can be used as before.
+ * This means AE is ON in the connection, and (1) this is either the first round to SQL Server
+ * to get encryption meta data, or (2) this is the second round of renewing meta data and
+ * parameter is encrypted In both of these cases we need to send specific type info, otherwise
+ * generic type info can be used as before.
*/
- if ((null != jdbcTypeSetByUser) && ((jdbcTypeSetByUser == JDBCType.VARCHAR) || (jdbcTypeSetByUser == JDBCType.CHAR)
- || (jdbcTypeSetByUser == JDBCType.LONGVARCHAR))) {
+ if ((null != jdbcTypeSetByUser)
+ && ((jdbcTypeSetByUser == JDBCType.VARCHAR) || (jdbcTypeSetByUser == JDBCType.CHAR)
+ || (jdbcTypeSetByUser == JDBCType.LONGVARCHAR))) {
if (0 == valueLength) {
// Workaround for the issue when inserting empty string and null into encrypted columns
param.typeDefinition = "varchar(1)";
valueLength++;
- }
- else if (DataTypes.SHORT_VARTYPE_MAX_BYTES < valueLength) {
+ } else if (DataTypes.SHORT_VARTYPE_MAX_BYTES < valueLength) {
param.typeDefinition = VARCHAR_MAX;
- }
- else {
+ } else {
param.typeDefinition = "varchar(" + valueLength + ")";
}
if (jdbcTypeSetByUser == JDBCType.LONGVARCHAR) {
param.typeDefinition = VARCHAR_MAX;
}
- }
- else if ((null != jdbcTypeSetByUser)
- && (jdbcTypeSetByUser == JDBCType.NVARCHAR || jdbcTypeSetByUser == JDBCType.LONGNVARCHAR)) {
+ } else if ((null != jdbcTypeSetByUser) && (jdbcTypeSetByUser == JDBCType.NVARCHAR
+ || jdbcTypeSetByUser == JDBCType.LONGNVARCHAR)) {
if (0 == valueLength) {
// Workaround for the issue when inserting empty string and null into encrypted columns
param.typeDefinition = "nvarchar(1)";
valueLength++;
- }
- else if (DataTypes.SHORT_VARTYPE_MAX_CHARS < valueLength) {
+ } else if (DataTypes.SHORT_VARTYPE_MAX_CHARS < valueLength) {
param.typeDefinition = NVARCHAR_MAX;
- }
- else {
+ } else {
param.typeDefinition = "nvarchar(" + valueLength + ")";
}
if (jdbcTypeSetByUser == JDBCType.LONGNVARCHAR) {
param.typeDefinition = NVARCHAR_MAX;
}
- }
- else { // used if setNull() is called with java.sql.Types.NCHAR
+ } else { // used if setNull() is called with java.sql.Types.NCHAR
if (0 == valueLength) {
// Workaround for the issue when inserting empty string and null into encrypted columns
param.typeDefinition = "nvarchar(1)";
valueLength++;
- }
- else {
+ } else {
param.typeDefinition = "nvarchar(" + valueLength + ")";
if (DataTypes.SHORT_VARTYPE_MAX_BYTES <= valueLength) {
@@ -801,8 +789,7 @@ else if (DataTypes.SHORT_VARTYPE_MAX_CHARS < valueLength) {
}
}
break;
- }
- else
+ } else
param.typeDefinition = NVARCHAR_MAX;
break;
@@ -818,20 +805,22 @@ else if (DataTypes.SHORT_VARTYPE_MAX_CHARS < valueLength) {
if (NVARCHAR_MAX.equals(param.typeDefinition) || NTEXT.equals(param.typeDefinition))
break;
- if (param.shouldHonorAEForParameter && !(null == param.getCryptoMetadata() && param.renewDefinition)) {
+ if (param.shouldHonorAEForParameter
+ && !(null == param.getCryptoMetadata() && param.renewDefinition)) {
/*
- * This means AE is ON in the connection, and (1) this is either the first round to SQL Server to get encryption meta data, or
- * (2) this is the second round of renewing meta data and parameter is encrypted In both of these cases we need to send
- * specific type info, otherwise generic type info can be used as before.
+ * This means AE is ON in the connection, and (1) this is either the first round to SQL Server
+ * to get encryption meta data, or (2) this is the second round of renewing meta data and
+ * parameter is encrypted In both of these cases we need to send specific type info, otherwise
+ * generic type info can be used as before.
*/
- if ((null != jdbcTypeSetByUser) && ((jdbcTypeSetByUser == JDBCType.VARCHAR) || (jdbcTypeSetByUser == JDBCType.CHAR)
- || (JDBCType.LONGVARCHAR == jdbcTypeSetByUser))) {
+ if ((null != jdbcTypeSetByUser)
+ && ((jdbcTypeSetByUser == JDBCType.VARCHAR) || (jdbcTypeSetByUser == JDBCType.CHAR)
+ || (JDBCType.LONGVARCHAR == jdbcTypeSetByUser))) {
if (0 == valueLength) {
// Workaround for the issue when inserting empty string and null into encrypted columns
param.typeDefinition = "varchar(1)";
valueLength++;
- }
- else {
+ } else {
param.typeDefinition = "varchar(" + valueLength + ")";
if (DataTypes.SHORT_VARTYPE_MAX_BYTES < valueLength) {
@@ -842,15 +831,14 @@ else if (DataTypes.SHORT_VARTYPE_MAX_CHARS < valueLength) {
if (JDBCType.LONGVARCHAR == jdbcTypeSetByUser) {
param.typeDefinition = VARCHAR_MAX;
}
- }
- else if ((null != jdbcTypeSetByUser) && ((jdbcTypeSetByUser == JDBCType.NVARCHAR) || (jdbcTypeSetByUser == JDBCType.NCHAR)
- || (JDBCType.LONGNVARCHAR == jdbcTypeSetByUser))) {
+ } else if ((null != jdbcTypeSetByUser)
+ && ((jdbcTypeSetByUser == JDBCType.NVARCHAR) || (jdbcTypeSetByUser == JDBCType.NCHAR)
+ || (JDBCType.LONGNVARCHAR == jdbcTypeSetByUser))) {
if (0 == valueLength) {
// Workaround for the issue when inserting empty string and null into encrypted columns
param.typeDefinition = "nvarchar(1)";
valueLength++;
- }
- else {
+ } else {
param.typeDefinition = "nvarchar(" + valueLength + ")";
if (DataTypes.SHORT_VARTYPE_MAX_BYTES <= valueLength) {
@@ -861,14 +849,12 @@ else if ((null != jdbcTypeSetByUser) && ((jdbcTypeSetByUser == JDBCType.NVARCHAR
if (JDBCType.LONGNVARCHAR == jdbcTypeSetByUser) {
param.typeDefinition = NVARCHAR_MAX;
}
- }
- else { // used if setNull() is called with java.sql.Types.NCHAR
+ } else { // used if setNull() is called with java.sql.Types.NCHAR
if (0 == valueLength) {
// Workaround for the issue when inserting empty string and null into encrypted columns
param.typeDefinition = "nvarchar(1)";
valueLength++;
- }
- else {
+ } else {
param.typeDefinition = "nvarchar(" + valueLength + ")";
if (DataTypes.SHORT_VARTYPE_MAX_BYTES <= valueLength) {
@@ -877,8 +863,7 @@ else if ((null != jdbcTypeSetByUser) && ((jdbcTypeSetByUser == JDBCType.NVARCHAR
}
}
break;
- }
- else
+ } else
param.typeDefinition = NVARCHAR_4K;
break;
case SQLXML:
@@ -891,8 +876,7 @@ else if ((null != jdbcTypeSetByUser) && ((jdbcTypeSetByUser == JDBCType.NVARCHAR
if (null != schema) {
param.typeDefinition = "[" + schema + "].[" + param.name + "] READONLY";
- }
- else {
+ } else {
param.typeDefinition = "[" + param.name + "] READONLY";
}
@@ -901,15 +885,15 @@ else if ((null != jdbcTypeSetByUser) && ((jdbcTypeSetByUser == JDBCType.NVARCHAR
case GUID:
param.typeDefinition = SSType.GUID.toString();
break;
-
+
case SQL_VARIANT:
param.typeDefinition = SSType.SQL_VARIANT.toString();
break;
-
+
case GEOMETRY:
param.typeDefinition = SSType.GEOMETRY.toString();
break;
-
+
case GEOGRAPHY:
param.typeDefinition = SSType.GEOGRAPHY.toString();
break;
@@ -919,98 +903,80 @@ else if ((null != jdbcTypeSetByUser) && ((jdbcTypeSetByUser == JDBCType.NVARCHAR
}
}
- void execute(DTV dtv,
- String strValue) throws SQLServerException {
+ void execute(DTV dtv, String strValue) throws SQLServerException {
if (null != strValue && strValue.length() > DataTypes.SHORT_VARTYPE_MAX_CHARS)
dtv.setJdbcType(JDBCType.LONGNVARCHAR);
setTypeDefinition(dtv);
}
- void execute(DTV dtv,
- Clob clobValue) throws SQLServerException {
+ void execute(DTV dtv, Clob clobValue) throws SQLServerException {
setTypeDefinition(dtv);
}
- void execute(DTV dtv,
- Byte byteValue) throws SQLServerException {
+ void execute(DTV dtv, Byte byteValue) throws SQLServerException {
setTypeDefinition(dtv);
}
- void execute(DTV dtv,
- Integer intValue) throws SQLServerException {
+ void execute(DTV dtv, Integer intValue) throws SQLServerException {
setTypeDefinition(dtv);
}
- void execute(DTV dtv,
- java.sql.Time timeValue) throws SQLServerException {
+ void execute(DTV dtv, java.sql.Time timeValue) throws SQLServerException {
setTypeDefinition(dtv);
}
- void execute(DTV dtv,
- java.sql.Date dateValue) throws SQLServerException {
+ void execute(DTV dtv, java.sql.Date dateValue) throws SQLServerException {
setTypeDefinition(dtv);
}
- void execute(DTV dtv,
- java.sql.Timestamp timestampValue) throws SQLServerException {
+ void execute(DTV dtv, java.sql.Timestamp timestampValue) throws SQLServerException {
setTypeDefinition(dtv);
}
- void execute(DTV dtv,
- java.util.Date utildateValue) throws SQLServerException {
+ void execute(DTV dtv, java.util.Date utildateValue) throws SQLServerException {
setTypeDefinition(dtv);
}
- void execute(DTV dtv,
- java.util.Calendar calendarValue) throws SQLServerException {
+ void execute(DTV dtv, java.util.Calendar calendarValue) throws SQLServerException {
setTypeDefinition(dtv);
}
- void execute(DTV dtv,
- LocalDate localDateValue) throws SQLServerException {
+ void execute(DTV dtv, LocalDate localDateValue) throws SQLServerException {
setTypeDefinition(dtv);
}
- void execute(DTV dtv,
- LocalTime localTimeValue) throws SQLServerException {
+ void execute(DTV dtv, LocalTime localTimeValue) throws SQLServerException {
setTypeDefinition(dtv);
}
- void execute(DTV dtv,
- LocalDateTime localDateTimeValue) throws SQLServerException {
+ void execute(DTV dtv, LocalDateTime localDateTimeValue) throws SQLServerException {
setTypeDefinition(dtv);
}
- void execute(DTV dtv,
- OffsetTime offsetTimeValue) throws SQLServerException {
+ void execute(DTV dtv, OffsetTime offsetTimeValue) throws SQLServerException {
setTypeDefinition(dtv);
}
- void execute(DTV dtv,
- OffsetDateTime OffsetDateTimeValue) throws SQLServerException {
+ void execute(DTV dtv, OffsetDateTime OffsetDateTimeValue) throws SQLServerException {
setTypeDefinition(dtv);
}
- void execute(DTV dtv,
- microsoft.sql.DateTimeOffset dtoValue) throws SQLServerException {
+ void execute(DTV dtv, microsoft.sql.DateTimeOffset dtoValue) throws SQLServerException {
setTypeDefinition(dtv);
}
- void execute(DTV dtv,
- Float floatValue) throws SQLServerException {
+ void execute(DTV dtv, Float floatValue) throws SQLServerException {
scale = 4;
setTypeDefinition(dtv);
}
- void execute(DTV dtv,
- Double doubleValue) throws SQLServerException {
+ void execute(DTV dtv, Double doubleValue) throws SQLServerException {
scale = 4;
setTypeDefinition(dtv);
}
- void execute(DTV dtv,
- BigDecimal bigDecimalValue) throws SQLServerException {
+ void execute(DTV dtv, BigDecimal bigDecimalValue) throws SQLServerException {
if (null != bigDecimalValue) {
scale = bigDecimalValue.scale();
@@ -1026,47 +992,41 @@ void execute(DTV dtv,
setTypeDefinition(dtv);
}
- void execute(DTV dtv,
- Long longValue) throws SQLServerException {
+ void execute(DTV dtv, Long longValue) throws SQLServerException {
setTypeDefinition(dtv);
}
- void execute(DTV dtv,
- java.math.BigInteger bigIntegerValue) throws SQLServerException {
+ void execute(DTV dtv, java.math.BigInteger bigIntegerValue) throws SQLServerException {
setTypeDefinition(dtv);
}
- void execute(DTV dtv,
- Short shortValue) throws SQLServerException {
+ void execute(DTV dtv, Short shortValue) throws SQLServerException {
setTypeDefinition(dtv);
}
- void execute(DTV dtv,
- Boolean booleanValue) throws SQLServerException {
+ void execute(DTV dtv, Boolean booleanValue) throws SQLServerException {
setTypeDefinition(dtv);
}
- void execute(DTV dtv,
- byte[] byteArrayValue) throws SQLServerException {
+ void execute(DTV dtv, byte[] byteArrayValue) throws SQLServerException {
if (null != byteArrayValue && byteArrayValue.length > DataTypes.SHORT_VARTYPE_MAX_BYTES)
dtv.setJdbcType(dtv.getJdbcType().isBinary() ? JDBCType.LONGVARBINARY : JDBCType.LONGVARCHAR);
setTypeDefinition(dtv);
}
- void execute(DTV dtv,
- Blob blobValue) throws SQLServerException {
+ void execute(DTV dtv, Blob blobValue) throws SQLServerException {
setTypeDefinition(dtv);
}
- void execute(DTV dtv,
- InputStream inputStreamValue) throws SQLServerException {
+ void execute(DTV dtv, InputStream inputStreamValue) throws SQLServerException {
StreamSetterArgs streamSetterArgs = dtv.getStreamSetterArgs();
JDBCType jdbcType = dtv.getJdbcType();
// If the JDBC type is currently a "short" type, then figure out if needs to be bumped up to a "long" type
- if (JDBCType.CHAR == jdbcType || JDBCType.VARCHAR == jdbcType || JDBCType.BINARY == jdbcType || JDBCType.VARBINARY == jdbcType) {
+ if (JDBCType.CHAR == jdbcType || JDBCType.VARCHAR == jdbcType || JDBCType.BINARY == jdbcType
+ || JDBCType.VARBINARY == jdbcType) {
// If we know the length is too long for a "short" type, then convert to a "long" type.
if (streamSetterArgs.getLength() > DataTypes.SHORT_VARTYPE_MAX_BYTES)
dtv.setJdbcType(jdbcType.isBinary() ? JDBCType.LONGVARBINARY : JDBCType.LONGVARCHAR);
@@ -1088,8 +1048,7 @@ else if (DataTypes.UNKNOWN_STREAM_LENGTH == streamSetterArgs.getLength()) {
bytesRead = 0;
bufferedStream.reset();
- }
- catch (IOException e) {
+ } catch (IOException e) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_errorReadingStream"));
Object[] msgArgs = {e.toString()};
SQLServerException.makeFromDriverError(null, null, form.format(msgArgs), "", true);
@@ -1097,8 +1056,10 @@ else if (DataTypes.UNKNOWN_STREAM_LENGTH == streamSetterArgs.getLength()) {
dtv.setValue(bufferedStream, JavaType.INPUTSTREAM);
- // If the stream is longer than what can fit into the "short" type, then use the "long" type instead.
- // Otherwise, we know the exact stream length since we reached end of stream before reading SHORT_VARTYPE_MAX_BYTES + 1
+ // If the stream is longer than what can fit into the "short" type, then use the "long" type
+ // instead.
+ // Otherwise, we know the exact stream length since we reached end of stream before reading
+ // SHORT_VARTYPE_MAX_BYTES + 1
// bytes. So adjust the setter args to reflect the known length to avoid unnecessarily copying the
// stream again in SendByRPCOp.
if (bytesRead > DataTypes.SHORT_VARTYPE_MAX_BYTES)
@@ -1111,8 +1072,7 @@ else if (DataTypes.UNKNOWN_STREAM_LENGTH == streamSetterArgs.getLength()) {
setTypeDefinition(dtv);
}
- void execute(DTV dtv,
- Reader readerValue) throws SQLServerException {
+ void execute(DTV dtv, Reader readerValue) throws SQLServerException {
// If the JDBC type is currently a "short" type, then figure out if needs to be bumped up to a "long" type
if (JDBCType.NCHAR == dtv.getJdbcType() || JDBCType.NVARCHAR == dtv.getJdbcType()) {
StreamSetterArgs streamSetterArgs = dtv.getStreamSetterArgs();
@@ -1138,8 +1098,7 @@ else if (DataTypes.UNKNOWN_STREAM_LENGTH == streamSetterArgs.getLength()) {
charsRead = 0;
bufferedReader.reset();
- }
- catch (IOException e) {
+ } catch (IOException e) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_errorReadingStream"));
Object[] msgArgs = {e.toString()};
SQLServerException.makeFromDriverError(null, null, form.format(msgArgs), "", true);
@@ -1157,34 +1116,31 @@ else if (DataTypes.UNKNOWN_STREAM_LENGTH == streamSetterArgs.getLength()) {
setTypeDefinition(dtv);
}
- void execute(DTV dtv,
- SQLServerSQLXML xmlValue) throws SQLServerException {
+ void execute(DTV dtv, SQLServerSQLXML xmlValue) throws SQLServerException {
setTypeDefinition(dtv);
}
- void execute(DTV dtv,
- com.microsoft.sqlserver.jdbc.TVP tvpValue) throws SQLServerException {
+ void execute(DTV dtv, com.microsoft.sqlserver.jdbc.TVP tvpValue) throws SQLServerException {
setTypeDefinition(dtv);
}
/*
* (non-Javadoc)
- *
- * @see com.microsoft.sqlserver.jdbc.DTVExecuteOp#execute(com.microsoft.sqlserver.jdbc.DTV, microsoft.sql.SqlVariant)
+ * @see com.microsoft.sqlserver.jdbc.DTVExecuteOp#execute(com.microsoft.sqlserver.jdbc.DTV,
+ * microsoft.sql.SqlVariant)
*/
@Override
- void execute(DTV dtv,
- SqlVariant SqlVariantValue) throws SQLServerException {
+ void execute(DTV dtv, SqlVariant SqlVariantValue) throws SQLServerException {
setTypeDefinition(dtv);
}
}
/**
- * Returns a string used to define the parameter type for the server; null if no value for the parameter has been set or registered.
+ * Returns a string used to define the parameter type for the server; null if no value for the parameter has been
+ * set or registered.
*/
- String getTypeDefinition(SQLServerConnection con,
- TDSReader tdsReader) throws SQLServerException {
+ String getTypeDefinition(SQLServerConnection con, TDSReader tdsReader) throws SQLServerException {
if (null == inputDTV)
return null;
@@ -1192,16 +1148,15 @@ String getTypeDefinition(SQLServerConnection con,
return typeDefinition;
}
- void sendByRPC(TDSWriter tdsWriter,
- SQLServerConnection conn) throws SQLServerException {
+ void sendByRPC(TDSWriter tdsWriter, SQLServerConnection conn) throws SQLServerException {
assert null != inputDTV : "Parameter was neither set nor registered";
try {
inputDTV.sendCryptoMetaData(this.cryptoMeta, tdsWriter);
inputDTV.jdbcTypeSetByUser(getJdbcTypeSetByUser(), getValueLength());
- inputDTV.sendByRPC(name, null, conn.getDatabaseCollation(), valueLength, isOutput() ? outScale : scale, isOutput(), tdsWriter, conn);
- }
- finally {
+ inputDTV.sendByRPC(name, null, conn.getDatabaseCollation(), valueLength, isOutput() ? outScale : scale,
+ isOutput(), tdsWriter, conn);
+ } finally {
// reset the cryptoMeta in IOBuffer
inputDTV.sendCryptoMetaData(null, tdsWriter);
}
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/ParameterUtils.java b/src/main/java/com/microsoft/sqlserver/jdbc/ParameterUtils.java
index 4cd7f2b84..0dcc60691 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/ParameterUtils.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/ParameterUtils.java
@@ -1,129 +1,126 @@
-/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
- */
-
-package com.microsoft.sqlserver.jdbc;
-
-/**
- * ParameterUtils provides utility a set of methods to manipulate parameter values.
- */
-
-final class ParameterUtils {
- static byte[] HexToBin(String hexV) throws SQLServerException {
- int len = hexV.length();
- char orig[] = hexV.toCharArray();
- if ((len % 2) != 0)
- SQLServerException.makeFromDriverError(null, null, SQLServerException.getErrString("R_stringNotInHex"), null, false);
- byte[] bin = new byte[len / 2];
- for (int i = 0; i < len / 2; i++) {
- bin[i] = (byte) ((CharToHex(orig[2 * i]) << 4) + CharToHex(orig[2 * i + 1]));
- }
- return bin;
- }
-
- // conversion routine valid values 0-9 a-f A-F
- // throws exception when failed to convert
- //
- static byte CharToHex(char CTX) throws SQLServerException {
- byte ret = 0;
- if (CTX >= 'A' && CTX <= 'F') {
- ret = (byte) (CTX - 'A' + 10);
- }
- else if (CTX >= 'a' && CTX <= 'f') {
- ret = (byte) (CTX - 'a' + 10);
- }
- else if (CTX >= '0' && CTX <= '9') {
- ret = (byte) (CTX - '0');
- }
- else {
- SQLServerException.makeFromDriverError(null, null, SQLServerException.getErrString("R_stringNotInHex"), null, false);
- }
- return ret;
- }
-
- /**
- * Locates the first occurrence of [c] in [sql] starting at [offset], where [sql] is a SQL statement string, which may contain any combination of:
- *
- * - Literals, enclosed in single quotes (') - Literals, enclosed in double quotes (") - Escape sequences, enclosed in square brackets ([]) -
- * Escaped escapes or literal delimiters (i.e. '', "", or ]]) in the above - Single-line comments, beginning in -- and continuing to EOL -
- * Multi-line comments, enclosed in C-style comment delimiters
- *
- * and [c] is not contained any of the above.
- *
- * @param c
- * the character to search for
- * @param sql
- * the SQL string to search in
- * @param offset
- * the offset into [sql] to start searching from
- * @return Offset into [sql] where [c] occurs, or sql.length if [c] is not found.
- * @throws SQLServerException
- * when [sql] does not follow
- */
- @SuppressWarnings({"fallthrough"})
- static int scanSQLForChar(char ch,
- String sql,
- int offset) {
- char chQuote;
- char chTmp;
- final int len = sql.length();
-
- while (offset < len) {
- switch (chTmp = sql.charAt(offset++)) {
- case '/':
- if (offset == len)
- break;
-
- if (sql.charAt(offset) == '*') { // If '/* ... */' comment
- while (++offset < len) { // Go thru comment.
- if (sql.charAt(offset) == '*' && offset + 1 < len && sql.charAt(offset + 1) == '/') { // If end of comment
- offset += 2;
- break;
- }
- }
- break;
- }
- else if (sql.charAt(offset) == '-')
- break;
-
- // Fall through - will fail next if and end up in default case
- case '-':
- if (sql.charAt(offset) == '-') { // If '-- ... \n' comment
- while (++offset < len) { // Go thru comment.
- if (sql.charAt(offset) == '\n' || sql.charAt(offset) == '\r') { // If end of comment
- offset++;
- break;
- }
- }
- break;
- }
- // Fall through to test character
- default:
- if (ch == chTmp)
- return offset - 1;
- break;
-
- case '[':
- chTmp = ']';
- case '\'':
- case '"':
- chQuote = chTmp;
- while (offset < len) {
- if (sql.charAt(offset++) == chQuote) {
- if (len == offset || sql.charAt(offset) != chQuote)
- break;
-
- ++offset;
- }
- }
- break;
- }
- }
-
- return len;
- }
-}
+/*
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ */
+
+package com.microsoft.sqlserver.jdbc;
+
+/**
+ * ParameterUtils provides utility a set of methods to manipulate parameter values.
+ */
+
+final class ParameterUtils {
+ static byte[] HexToBin(String hexV) throws SQLServerException {
+ int len = hexV.length();
+ char orig[] = hexV.toCharArray();
+ if ((len % 2) != 0)
+ SQLServerException.makeFromDriverError(null, null, SQLServerException.getErrString("R_stringNotInHex"),
+ null, false);
+ byte[] bin = new byte[len / 2];
+ for (int i = 0; i < len / 2; i++) {
+ bin[i] = (byte) ((CharToHex(orig[2 * i]) << 4) + CharToHex(orig[2 * i + 1]));
+ }
+ return bin;
+ }
+
+ // conversion routine valid values 0-9 a-f A-F
+ // throws exception when failed to convert
+ //
+ static byte CharToHex(char CTX) throws SQLServerException {
+ byte ret = 0;
+ if (CTX >= 'A' && CTX <= 'F') {
+ ret = (byte) (CTX - 'A' + 10);
+ } else if (CTX >= 'a' && CTX <= 'f') {
+ ret = (byte) (CTX - 'a' + 10);
+ } else if (CTX >= '0' && CTX <= '9') {
+ ret = (byte) (CTX - '0');
+ } else {
+ SQLServerException.makeFromDriverError(null, null, SQLServerException.getErrString("R_stringNotInHex"),
+ null, false);
+ }
+ return ret;
+ }
+
+ /**
+ * Locates the first occurrence of [c] in [sql] starting at [offset], where [sql] is a SQL statement string, which
+ * may contain any combination of:
+ *
+ * - Literals, enclosed in single quotes (') - Literals, enclosed in double quotes (") - Escape sequences, enclosed
+ * in square brackets ([]) - Escaped escapes or literal delimiters (i.e. '', "", or ]]) in the above - Single-line
+ * comments, beginning in -- and continuing to EOL - Multi-line comments, enclosed in C-style comment delimiters
+ *
+ * and [c] is not contained any of the above.
+ *
+ * @param c
+ * the character to search for
+ * @param sql
+ * the SQL string to search in
+ * @param offset
+ * the offset into [sql] to start searching from
+ * @return Offset into [sql] where [c] occurs, or sql.length if [c] is not found.
+ * @throws SQLServerException
+ * when [sql] does not follow
+ */
+ @SuppressWarnings({"fallthrough"})
+ static int scanSQLForChar(char ch, String sql, int offset) {
+ char chQuote;
+ char chTmp;
+ final int len = sql.length();
+
+ while (offset < len) {
+ switch (chTmp = sql.charAt(offset++)) {
+ case '/':
+ if (offset == len)
+ break;
+
+ if (sql.charAt(offset) == '*') { // If '/* ... */' comment
+ while (++offset < len) { // Go thru comment.
+ if (sql.charAt(offset) == '*' && offset + 1 < len && sql.charAt(offset + 1) == '/') { // If
+ // end
+ // of
+ // comment
+ offset += 2;
+ break;
+ }
+ }
+ break;
+ } else if (sql.charAt(offset) == '-')
+ break;
+
+ // Fall through - will fail next if and end up in default case
+ case '-':
+ if (sql.charAt(offset) == '-') { // If '-- ... \n' comment
+ while (++offset < len) { // Go thru comment.
+ if (sql.charAt(offset) == '\n' || sql.charAt(offset) == '\r') { // If end of comment
+ offset++;
+ break;
+ }
+ }
+ break;
+ }
+ // Fall through to test character
+ default:
+ if (ch == chTmp)
+ return offset - 1;
+ break;
+
+ case '[':
+ chTmp = ']';
+ case '\'':
+ case '"':
+ chQuote = chTmp;
+ while (offset < len) {
+ if (sql.charAt(offset++) == chQuote) {
+ if (len == offset || sql.charAt(offset) != chQuote)
+ break;
+
+ ++offset;
+ }
+ }
+ break;
+ }
+ }
+
+ return len;
+ }
+}
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/ParsedSQLMetadata.java b/src/main/java/com/microsoft/sqlserver/jdbc/ParsedSQLMetadata.java
index 19c34ebec..b41bbf09f 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/ParsedSQLMetadata.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/ParsedSQLMetadata.java
@@ -1,9 +1,6 @@
/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc;
@@ -14,15 +11,15 @@
final class ParsedSQLCacheItem {
/** The SQL text AFTER processing. */
String processedSQL;
- int parameterCount;
+ int[] parameterPositions;
String procedureName;
- boolean bReturnValueSyntax;
-
- ParsedSQLCacheItem(String processedSQL, int parameterCount, String procedureName, boolean bReturnValueSyntax) {
+ boolean bReturnValueSyntax;
+
+ ParsedSQLCacheItem(String processedSQL, int[] parameterPositions, String procedureName,
+ boolean bReturnValueSyntax) {
this.processedSQL = processedSQL;
- this.parameterCount = parameterCount;
+ this.parameterPositions = parameterPositions;
this.procedureName = procedureName;
this.bReturnValueSyntax = bReturnValueSyntax;
}
}
-
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/ReaderInputStream.java b/src/main/java/com/microsoft/sqlserver/jdbc/ReaderInputStream.java
index 1a2513816..54df7d76b 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/ReaderInputStream.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/ReaderInputStream.java
@@ -1,272 +1,266 @@
-/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
- */
-
-package com.microsoft.sqlserver.jdbc;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Reader;
-import java.nio.Buffer;
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.Charset;
-import java.text.MessageFormat;
-
-/**
- * InputStream adapter for Readers.
- *
- * This class implements an InputStream whose bytes are encoded character values that are read on demand from a wrapped Reader using the suplied
- * Charset.
- *
- * Character values pass through through the following in their transformation to bytes: Reader .. CharBuffer .. Charset (CharsetEncoder) ..
- * ByteBuffer .. InputStream
- *
- * To minimize memory usage, the CharBuffer and ByteBuffer instances used by this class are created on demand when InputStream read methods are
- * called.
- */
-class ReaderInputStream extends InputStream {
- // The Reader that this ReaderInputStream adapts.
- private final Reader reader;
-
- // The character set used to encode character values as
- // they are read from the stream.
- private final Charset charset;
-
- // Length of the Reader, if known, in characters
- private final long readerLength;
-
- // Count of characters read from the reader across all calls to encodeChars()
- private long readerCharsRead = 0;
-
- // Flag indicating whether the stream has reached the end of its data
- private boolean atEndOfStream = false;
-
- // Internal character buffer used to transfer character values
- // between the Reader and the Charset encoder.
- private CharBuffer rawChars = null;
- private static final int MAX_CHAR_BUFFER_SIZE = DataTypes.SHORT_VARTYPE_MAX_CHARS;
-
- // Most recent set of bytes that were encoded from rawChars.
- // This value is null initially and when the end of stream is reached.
- private static final ByteBuffer EMPTY_BUFFER = ByteBuffer.allocate(0);
- private ByteBuffer encodedChars = EMPTY_BUFFER;
-
- ReaderInputStream(Reader reader,
- Charset charset,
- long readerLength) {
- assert reader != null;
- assert charset != null;
- assert DataTypes.UNKNOWN_STREAM_LENGTH == readerLength || readerLength >= 0;
-
- this.reader = reader;
- this.charset = charset;
- this.readerLength = readerLength;
- }
-
- /**
- * Returns the number of bytes that can be read (or skipped over) from this input stream without blocking by the next caller of a method for this
- * input stream.
- *
- * @return - the number of bytes that can be read from this input stream without blocking
- * @throws IOException
- * - if an I/O error occurs
- */
- public int available() throws IOException {
- assert null != reader;
- assert null != encodedChars;
-
- // If we know the reader to be empty, then take the short cut
- if (0 == readerLength)
- return 0;
-
- // If there are encoded characters remaining in the buffer then that's our best guess.
- if (encodedChars.remaining() > 0)
- return encodedChars.remaining();
-
- // If there are no encoded characters left in the buffer (or the buffer hasn't yet been populated)
- // then ask the Reader whether a call to its read() method would block. If reading wouldn't block,
- // then there's at least 1 byte that can be encoded, possibly more.
- if (reader.ready())
- return 1;
-
- // If there are no encoded characters, and reading characters from the underlying Reader object
- // would block, then nothing (more) can be read from this stream without blocking.
- return 0;
- }
-
- private final byte[] oneByte = new byte[1];
-
- public int read() throws IOException {
- return (-1 == readInternal(oneByte, 0, oneByte.length)) ? -1 : oneByte[0];
- }
-
- public int read(byte[] b) throws IOException {
- return readInternal(b, 0, b.length);
- }
-
- public int read(byte[] b,
- int off,
- int len) throws IOException {
- return readInternal(b, off, len);
- }
-
- private int readInternal(byte[] b,
- int off,
- int len) throws IOException {
- assert null != b;
- assert 0 <= off && off <= b.length;
- assert 0 <= len && len <= b.length;
- assert off <= b.length - len;
-
- if (0 == len)
- return 0;
-
- int bytesRead = 0;
- while (bytesRead < len && encodeChars()) {
- // Read the lesser of the number of bytes remaining
- // in the encoded character buffer and the number
- // of bytes remaining for this read request.
- int bytesToRead = encodedChars.remaining();
- if (bytesToRead > len - bytesRead)
- bytesToRead = len - bytesRead;
-
- // We should actually be attempting to read something here,
- // or we'll be in an infinite loop...
- assert bytesToRead > 0;
-
- encodedChars.get(b, off + bytesRead, bytesToRead);
- bytesRead += bytesToRead;
- }
-
- // Return number of bytes read, which may be less than
- // the number of bytes requested, or -1 at end of stream.
- return (0 == bytesRead && atEndOfStream) ? -1 : bytesRead;
- }
-
- /**
- * Determines whether encoded characters are available, encoding them on demand by reading them from the reader as necessary.
- *
- * @return true when encoded characters are available
- * @return false when no more encoded characters are available (i.e. end of stream)
- * @exception IOException
- * if an I/O error occurs reading from the reader or encoding the characters
- */
- private boolean encodeChars() throws IOException {
- // Once at the end of the stream, no more characters can be encoded.
- if (atEndOfStream)
- return false;
-
- // Not at end of stream; check whether there are any encoded characters
- // remaining in the byte buffer. If there are, don't encode any more
- // characters this time.
- if (encodedChars.hasRemaining())
- return true;
-
- // Encoded byte buffer is either exhausted or has never been filled
- // (i.e. first time through). In that case, we need to repopulate
- // the encoded character buffer by encoding raw characters.
- //
- // To do that, there needs to be raw characters available to encode.
- // If there are no raw characters available (because the raw character
- // buffer has been exhausted or never filled), then try to read in
- // raw characters from the reader.
- if (null == rawChars || !rawChars.hasRemaining()) {
- if (null == rawChars) {
- assert MAX_CHAR_BUFFER_SIZE <= Integer.MAX_VALUE;
- rawChars = CharBuffer.allocate((DataTypes.UNKNOWN_STREAM_LENGTH == readerLength || readerLength > MAX_CHAR_BUFFER_SIZE)
- ? MAX_CHAR_BUFFER_SIZE : Math.max((int) readerLength, 1));
- }
- else {
- // Flip the buffer to be ready for put (reader read) operations.
- ((Buffer)rawChars).clear();
- }
-
- // Try to fill up the raw character buffer by reading available characters
- // from the reader into it.
- //
- // This loop continues until one of the following conditions is satisfied:
- // - the raw character buffer has been filled,
- // - the reader reaches end-of-stream
- // - the reader throws any kind of Exception (driver throws an IOException)
- // - the reader violates its interface contract (driver throws an IOException)
- while (rawChars.hasRemaining()) {
- int lastPosition = ((Buffer)rawChars).position();
- int charsRead = 0;
-
- // Try reading from the app-supplied Reader
- try {
- charsRead = reader.read(rawChars);
- }
-
- // Catch any kind of exception and translate it to an IOException.
- // The app-supplied reader cannot be trusted just to throw IOExceptions...
- catch (Exception e) {
- String detailMessage = e.getMessage();
- if (null == detailMessage)
- detailMessage = SQLServerException.getErrString("R_streamReadReturnedInvalidValue");
- IOException ioException = new IOException(detailMessage);
- ioException.initCause(e);
- throw ioException;
- }
-
- if (charsRead < -1 || 0 == charsRead)
- throw new IOException(SQLServerException.getErrString("R_streamReadReturnedInvalidValue"));
-
- if (-1 == charsRead) {
- // If the reader violates its interface contract then throw an exception.
- if (((Buffer)rawChars).position() != lastPosition)
- throw new IOException(SQLServerException.getErrString("R_streamReadReturnedInvalidValue"));
-
- // Check that the reader has returned exactly the amount of data we expect
- if (DataTypes.UNKNOWN_STREAM_LENGTH != readerLength && 0 != readerLength - readerCharsRead) {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_mismatchedStreamLength"));
- throw new IOException(form.format(new Object[] {readerLength, readerCharsRead}));
- }
-
- // If there are no characters left to encode then we're done.
- if (0 == ((Buffer)rawChars).position()) {
- rawChars = null;
- atEndOfStream = true;
- return false;
- }
-
- // Otherwise, we've filled the buffer as much as we can.
- break;
- }
-
- assert charsRead > 0;
-
- // If the reader violates its interface contract then throw an exception.
- if (charsRead != ((Buffer)rawChars).position() - lastPosition)
- throw new IOException(SQLServerException.getErrString("R_streamReadReturnedInvalidValue"));
-
- // Check that the reader isn't trying to return more data than we expect
- if (DataTypes.UNKNOWN_STREAM_LENGTH != readerLength && charsRead > readerLength - readerCharsRead) {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_mismatchedStreamLength"));
- throw new IOException(form.format(new Object[] {readerLength, readerCharsRead}));
- }
-
- readerCharsRead += charsRead;
- }
-
- // The raw character buffer may now have characters available for encoding.
- // Flip the buffer back to be ready for get (charset encode) operations.
- ((Buffer)rawChars).flip();
- }
-
- // If the raw character buffer remains empty, despite our efforts to (re)populate it,
- // then no characters can be encoded at this time. This can happen if the reader reports
- // that no characters were ready to be read.
- if (!rawChars.hasRemaining())
- return false;
-
- // Raw characters are now available to be encoded, so encode them.
- encodedChars = charset.encode(rawChars);
- return true;
- }
-}
+/*
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ */
+
+package com.microsoft.sqlserver.jdbc;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.nio.Buffer;
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.charset.Charset;
+import java.text.MessageFormat;
+
+
+/**
+ * InputStream adapter for Readers.
+ *
+ * This class implements an InputStream whose bytes are encoded character values that are read on demand from a wrapped
+ * Reader using the suplied Charset.
+ *
+ * Character values pass through through the following in their transformation to bytes: Reader .. CharBuffer .. Charset
+ * (CharsetEncoder) .. ByteBuffer .. InputStream
+ *
+ * To minimize memory usage, the CharBuffer and ByteBuffer instances used by this class are created on demand when
+ * InputStream read methods are called.
+ */
+class ReaderInputStream extends InputStream {
+ // The Reader that this ReaderInputStream adapts.
+ private final Reader reader;
+
+ // The character set used to encode character values as
+ // they are read from the stream.
+ private final Charset charset;
+
+ // Length of the Reader, if known, in characters
+ private final long readerLength;
+
+ // Count of characters read from the reader across all calls to encodeChars()
+ private long readerCharsRead = 0;
+
+ // Flag indicating whether the stream has reached the end of its data
+ private boolean atEndOfStream = false;
+
+ // Internal character buffer used to transfer character values
+ // between the Reader and the Charset encoder.
+ private CharBuffer rawChars = null;
+ private static final int MAX_CHAR_BUFFER_SIZE = DataTypes.SHORT_VARTYPE_MAX_CHARS;
+
+ // Most recent set of bytes that were encoded from rawChars.
+ // This value is null initially and when the end of stream is reached.
+ private static final ByteBuffer EMPTY_BUFFER = ByteBuffer.allocate(0);
+ private ByteBuffer encodedChars = EMPTY_BUFFER;
+
+ ReaderInputStream(Reader reader, Charset charset, long readerLength) {
+ assert reader != null;
+ assert charset != null;
+ assert DataTypes.UNKNOWN_STREAM_LENGTH == readerLength || readerLength >= 0;
+
+ this.reader = reader;
+ this.charset = charset;
+ this.readerLength = readerLength;
+ }
+
+ /**
+ * Returns the number of bytes that can be read (or skipped over) from this input stream without blocking by the
+ * next caller of a method for this input stream.
+ *
+ * @return - the number of bytes that can be read from this input stream without blocking
+ * @throws IOException
+ * - if an I/O error occurs
+ */
+ public int available() throws IOException {
+ assert null != reader;
+ assert null != encodedChars;
+
+ // If we know the reader to be empty, then take the short cut
+ if (0 == readerLength)
+ return 0;
+
+ // If there are encoded characters remaining in the buffer then that's our best guess.
+ if (encodedChars.remaining() > 0)
+ return encodedChars.remaining();
+
+ // If there are no encoded characters left in the buffer (or the buffer hasn't yet been populated)
+ // then ask the Reader whether a call to its read() method would block. If reading wouldn't block,
+ // then there's at least 1 byte that can be encoded, possibly more.
+ if (reader.ready())
+ return 1;
+
+ // If there are no encoded characters, and reading characters from the underlying Reader object
+ // would block, then nothing (more) can be read from this stream without blocking.
+ return 0;
+ }
+
+ private final byte[] oneByte = new byte[1];
+
+ public int read() throws IOException {
+ return (-1 == readInternal(oneByte, 0, oneByte.length)) ? -1 : oneByte[0];
+ }
+
+ public int read(byte[] b) throws IOException {
+ return readInternal(b, 0, b.length);
+ }
+
+ public int read(byte[] b, int off, int len) throws IOException {
+ return readInternal(b, off, len);
+ }
+
+ private int readInternal(byte[] b, int off, int len) throws IOException {
+ assert null != b;
+ assert 0 <= off && off <= b.length;
+ assert 0 <= len && len <= b.length;
+ assert off <= b.length - len;
+
+ if (0 == len)
+ return 0;
+
+ int bytesRead = 0;
+ while (bytesRead < len && encodeChars()) {
+ // Read the lesser of the number of bytes remaining
+ // in the encoded character buffer and the number
+ // of bytes remaining for this read request.
+ int bytesToRead = encodedChars.remaining();
+ if (bytesToRead > len - bytesRead)
+ bytesToRead = len - bytesRead;
+
+ // We should actually be attempting to read something here,
+ // or we'll be in an infinite loop...
+ assert bytesToRead > 0;
+
+ encodedChars.get(b, off + bytesRead, bytesToRead);
+ bytesRead += bytesToRead;
+ }
+
+ // Return number of bytes read, which may be less than
+ // the number of bytes requested, or -1 at end of stream.
+ return (0 == bytesRead && atEndOfStream) ? -1 : bytesRead;
+ }
+
+ /**
+ * Determines whether encoded characters are available, encoding them on demand by reading them from the reader as
+ * necessary.
+ *
+ * @return true when encoded characters are available
+ * @return false when no more encoded characters are available (i.e. end of stream)
+ * @exception IOException
+ * if an I/O error occurs reading from the reader or encoding the characters
+ */
+ private boolean encodeChars() throws IOException {
+ // Once at the end of the stream, no more characters can be encoded.
+ if (atEndOfStream)
+ return false;
+
+ // Not at end of stream; check whether there are any encoded characters
+ // remaining in the byte buffer. If there are, don't encode any more
+ // characters this time.
+ if (encodedChars.hasRemaining())
+ return true;
+
+ // Encoded byte buffer is either exhausted or has never been filled
+ // (i.e. first time through). In that case, we need to repopulate
+ // the encoded character buffer by encoding raw characters.
+ //
+ // To do that, there needs to be raw characters available to encode.
+ // If there are no raw characters available (because the raw character
+ // buffer has been exhausted or never filled), then try to read in
+ // raw characters from the reader.
+ if (null == rawChars || !rawChars.hasRemaining()) {
+ if (null == rawChars) {
+ assert MAX_CHAR_BUFFER_SIZE <= Integer.MAX_VALUE;
+ rawChars = CharBuffer.allocate((DataTypes.UNKNOWN_STREAM_LENGTH == readerLength
+ || readerLength > MAX_CHAR_BUFFER_SIZE) ? MAX_CHAR_BUFFER_SIZE
+ : Math.max((int) readerLength, 1));
+ } else {
+ // Flip the buffer to be ready for put (reader read) operations.
+ ((Buffer) rawChars).clear();
+ }
+
+ // Try to fill up the raw character buffer by reading available characters
+ // from the reader into it.
+ //
+ // This loop continues until one of the following conditions is satisfied:
+ // - the raw character buffer has been filled,
+ // - the reader reaches end-of-stream
+ // - the reader throws any kind of Exception (driver throws an IOException)
+ // - the reader violates its interface contract (driver throws an IOException)
+ while (rawChars.hasRemaining()) {
+ int lastPosition = ((Buffer) rawChars).position();
+ int charsRead = 0;
+
+ // Try reading from the app-supplied Reader
+ try {
+ charsRead = reader.read(rawChars);
+ }
+
+ // Catch any kind of exception and translate it to an IOException.
+ // The app-supplied reader cannot be trusted just to throw IOExceptions...
+ catch (Exception e) {
+ String detailMessage = e.getMessage();
+ if (null == detailMessage)
+ detailMessage = SQLServerException.getErrString("R_streamReadReturnedInvalidValue");
+ IOException ioException = new IOException(detailMessage);
+ ioException.initCause(e);
+ throw ioException;
+ }
+
+ if (charsRead < -1 || 0 == charsRead)
+ throw new IOException(SQLServerException.getErrString("R_streamReadReturnedInvalidValue"));
+
+ if (-1 == charsRead) {
+ // If the reader violates its interface contract then throw an exception.
+ if (((Buffer) rawChars).position() != lastPosition)
+ throw new IOException(SQLServerException.getErrString("R_streamReadReturnedInvalidValue"));
+
+ // Check that the reader has returned exactly the amount of data we expect
+ if (DataTypes.UNKNOWN_STREAM_LENGTH != readerLength && 0 != readerLength - readerCharsRead) {
+ MessageFormat form = new MessageFormat(
+ SQLServerException.getErrString("R_mismatchedStreamLength"));
+ throw new IOException(form.format(new Object[] {readerLength, readerCharsRead}));
+ }
+
+ // If there are no characters left to encode then we're done.
+ if (0 == ((Buffer) rawChars).position()) {
+ rawChars = null;
+ atEndOfStream = true;
+ return false;
+ }
+
+ // Otherwise, we've filled the buffer as much as we can.
+ break;
+ }
+
+ assert charsRead > 0;
+
+ // If the reader violates its interface contract then throw an exception.
+ if (charsRead != ((Buffer) rawChars).position() - lastPosition)
+ throw new IOException(SQLServerException.getErrString("R_streamReadReturnedInvalidValue"));
+
+ // Check that the reader isn't trying to return more data than we expect
+ if (DataTypes.UNKNOWN_STREAM_LENGTH != readerLength && charsRead > readerLength - readerCharsRead) {
+ MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_mismatchedStreamLength"));
+ throw new IOException(form.format(new Object[] {readerLength, readerCharsRead}));
+ }
+
+ readerCharsRead += charsRead;
+ }
+
+ // The raw character buffer may now have characters available for encoding.
+ // Flip the buffer back to be ready for get (charset encode) operations.
+ ((Buffer) rawChars).flip();
+ }
+
+ // If the raw character buffer remains empty, despite our efforts to (re)populate it,
+ // then no characters can be encoded at this time. This can happen if the reader reports
+ // that no characters were ready to be read.
+ if (!rawChars.hasRemaining())
+ return false;
+
+ // Raw characters are now available to be encoded, so encode them.
+ encodedChars = charset.encode(rawChars);
+ return true;
+ }
+}
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLCollation.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLCollation.java
index 6dcf58cf6..75a1aed72 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLCollation.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLCollation.java
@@ -1,9 +1,6 @@
/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc;
@@ -17,41 +14,48 @@
/**
- * SQLCollation is helper class used to read TDS collation from a TDS stream.
- * Collation is in the following BNF format (see TDS spec for full details):
+ * SQLCollation is helper class used to read TDS collation from a TDS stream. Collation is in the following BNF format
+ * (see TDS spec for full details):
*
- * LCID := 20 * BIT;
- * fIgnoreCase := BIT;
- * fIgnoreAccent := BIT;
- * fIgnoreWidth := BIT;
- * fIgnoreKana := BIT;
- * fBinary := BIT;
- * ColFlags := fIgnoreCase, fIgnoreAccent, fIgnoreWidth, fIgnoreKana, fBinary, FRESERVEDBIT, FRESERVEDBIT, FRESERVEDBIT;
- * Version := 4 * BIT;
- * SortId := BYTE;
+ * LCID := 20 * BIT; fIgnoreCase := BIT; fIgnoreAccent := BIT; fIgnoreWidth := BIT; fIgnoreKana := BIT; fBinary := BIT;
+ * ColFlags := fIgnoreCase, fIgnoreAccent, fIgnoreWidth, fIgnoreKana, fBinary, FRESERVEDBIT, FRESERVEDBIT, FRESERVEDBIT;
+ * Version := 4 * BIT; SortId := BYTE;
*
- * COLLATION := LCID, ColFlags, Version, SortId;
+ * COLLATION := LCID, ColFlags, Version, SortId;
*
*/
-final class SQLCollation implements java.io.Serializable
-{
- /**
- *
- */
- private static final long serialVersionUID = 6748833280721312349L;
-
- private final int info; // First 4 bytes of TDS collation.
- private int langID() { return info & 0x0000FFFF; }
- private final int sortId; // 5th byte of TDS collation.
+final class SQLCollation implements java.io.Serializable {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 6748833280721312349L;
+
+ private final int info; // First 4 bytes of TDS collation.
+
+ private int langID() {
+ return info & 0x0000FFFF;
+ }
+
+ private final int sortId; // 5th byte of TDS collation.
private final Encoding encoding;
private static final int UTF8_IN_TDSCOLLATION = 0x4000000;
// Utility methods for getting details of this collation's encoding
- final Charset getCharset() throws SQLServerException { return encoding.charset(); }
- final boolean supportsAsciiConversion() { return encoding.supportsAsciiConversion(); }
- final boolean hasAsciiCompatibleSBCS() { return encoding.hasAsciiCompatibleSBCS(); }
+ final Charset getCharset() throws SQLServerException {
+ return encoding.charset();
+ }
- static final int tdsLength() { return 5; } // Length of collation in TDS (in bytes)
+ final boolean supportsAsciiConversion() {
+ return encoding.supportsAsciiConversion();
+ }
+
+ final boolean hasAsciiCompatibleSBCS() {
+ return encoding.hasAsciiCompatibleSBCS();
+ }
+
+ static final int tdsLength() {
+ return 5;
+ } // Length of collation in TDS (in bytes)
/**
* Returns the collation info
@@ -61,7 +65,7 @@ final class SQLCollation implements java.io.Serializable
int getCollationInfo() {
return this.info;
}
-
+
/**
* return sort ID
*
@@ -70,23 +74,21 @@ int getCollationInfo() {
int getCollationSortID() {
return this.sortId;
}
-
+
/**
* Reads TDS collation from TDS buffer into SQLCollation class.
+ *
* @param tdsReader
*/
- SQLCollation(TDSReader tdsReader) throws UnsupportedEncodingException, SQLServerException
- {
- /*
- * TDS rule for collation:
- * COLLATION = LCID ColFlags Version SortId
- */
- info = tdsReader.readInt(); // 4 bytes, contains: LCID ColFlags Version
+ SQLCollation(TDSReader tdsReader) throws UnsupportedEncodingException, SQLServerException {
+ /*
+ * TDS rule for collation: COLLATION = LCID ColFlags Version SortId
+ */
+ info = tdsReader.readInt(); // 4 bytes, contains: LCID ColFlags Version
sortId = tdsReader.readUnsignedByte(); // 1 byte, contains: SortId
if (UTF8_IN_TDSCOLLATION == (info & UTF8_IN_TDSCOLLATION)) {
encoding = Encoding.UTF8;
- }
- else {
+ } else {
// For a SortId==0 collation, the LCID bits correspond to a LocaleId
encoding = (0 == sortId) ? encodingFromLCID() : encodingFromSortId();
}
@@ -94,12 +96,13 @@ int getCollationSortID() {
/**
* Writes TDS collation from SQLCollation class into TDS buffer at offset.
- * @param tdsWriter TDS writer to write collation to.
+ *
+ * @param tdsWriter
+ * TDS writer to write collation to.
*/
- void writeCollation(TDSWriter tdsWriter) throws SQLServerException
- {
- tdsWriter.writeInt(info);
- tdsWriter.writeByte((byte) (sortId & 0xFF));
+ void writeCollation(TDSWriter tdsWriter) throws SQLServerException {
+ tdsWriter.writeInt(info);
+ tdsWriter.writeByte((byte) (sortId & 0xFF));
}
/**
@@ -109,229 +112,227 @@ void writeCollation(TDSWriter tdsWriter) throws SQLServerException
*
* The set of locales is derived from the following resources:
*
- * http://download.microsoft.com/download/9/5/e/95ef66af-9026-4bb0-a41d-a4f81802d92c/[MS-LCID].pdf
- * Lists LCID values and their corresponding meanings (in RFC 3066 format). Used to derive the names
- * for the various enumeration constants.
+ * http://download.microsoft.com/download/9/5/e/95ef66af-9026-4bb0-a41d-a4f81802d92c/[MS-LCID].pdf Lists LCID values
+ * and their corresponding meanings (in RFC 3066 format). Used to derive the names for the various enumeration
+ * constants.
*
- * x_rgLocaleMap and x_rgLcidOrdMap in sql\common\include\localemap.h in Katmai source tree
- * Collectively, these two tables provide a mapping of collation-version specific encodings
- * for every locale supported by SQL Server. Lang IDs are derived from locales' LCIDs.
+ * x_rgLocaleMap and x_rgLcidOrdMap in sql\common\include\localemap.h in Katmai source tree Collectively, these two
+ * tables provide a mapping of collation-version specific encodings for every locale supported by SQL Server. Lang
+ * IDs are derived from locales' LCIDs.
*/
- enum WindowsLocale
- {
- ar_SA (0x0401, Encoding.CP1256),
- bg_BG (0x0402, Encoding.CP1251),
- ca_ES (0x0403, Encoding.CP1252),
- zh_TW (0x0404, Encoding.CP950),
- cs_CZ (0x0405, Encoding.CP1250),
- da_DK (0x0406, Encoding.CP1252),
- de_DE (0x0407, Encoding.CP1252),
- el_GR (0x0408, Encoding.CP1253),
- en_US (0x0409, Encoding.CP1252),
- es_ES_tradnl (0x040a, Encoding.CP1252),
- fi_FI (0x040b, Encoding.CP1252),
- fr_FR (0x040c, Encoding.CP1252),
- he_IL (0x040d, Encoding.CP1255),
- hu_HU (0x040e, Encoding.CP1250),
- is_IS (0x040f, Encoding.CP1252),
- it_IT (0x0410, Encoding.CP1252),
- ja_JP (0x0411, Encoding.CP932),
- ko_KR (0x0412, Encoding.CP949),
- nl_NL (0x0413, Encoding.CP1252),
- nb_NO (0x0414, Encoding.CP1252),
- pl_PL (0x0415, Encoding.CP1250),
- pt_BR (0x0416, Encoding.CP1252),
- rm_CH (0x0417, Encoding.CP1252),
- ro_RO (0x0418, Encoding.CP1250),
- ru_RU (0x0419, Encoding.CP1251),
- hr_HR (0x041a, Encoding.CP1250),
- sk_SK (0x041b, Encoding.CP1250),
- sq_AL (0x041c, Encoding.CP1250),
- sv_SE (0x041d, Encoding.CP1252),
- th_TH (0x041e, Encoding.CP874),
- tr_TR (0x041f, Encoding.CP1254),
- ur_PK (0x0420, Encoding.CP1256),
- id_ID (0x0421, Encoding.CP1252),
- uk_UA (0x0422, Encoding.CP1251),
- be_BY (0x0423, Encoding.CP1251),
- sl_SI (0x0424, Encoding.CP1250),
- et_EE (0x0425, Encoding.CP1257),
- lv_LV (0x0426, Encoding.CP1257),
- lt_LT (0x0427, Encoding.CP1257),
- tg_Cyrl_TJ (0x0428, Encoding.CP1251),
- fa_IR (0x0429, Encoding.CP1256),
- vi_VN (0x042a, Encoding.CP1258),
- hy_AM (0x042b, Encoding.CP1252),
- az_Latn_AZ (0x042c, Encoding.CP1254),
- eu_ES (0x042d, Encoding.CP1252),
- wen_DE (0x042e, Encoding.CP1252),
- mk_MK (0x042f, Encoding.CP1251),
- tn_ZA (0x0432, Encoding.CP1252),
- xh_ZA (0x0434, Encoding.CP1252),
- zu_ZA (0x0435, Encoding.CP1252),
- Af_ZA (0x0436, Encoding.CP1252),
- ka_GE (0x0437, Encoding.CP1252),
- fo_FO (0x0438, Encoding.CP1252),
- hi_IN (0x0439, Encoding.UNICODE),
- mt_MT (0x043a, Encoding.UNICODE),
- se_NO (0x043b, Encoding.CP1252),
- ms_MY (0x043e, Encoding.CP1252),
- kk_KZ (0x043f, Encoding.CP1251),
- ky_KG (0x0440, Encoding.CP1251),
- sw_KE (0x0441, Encoding.CP1252),
- tk_TM (0x0442, Encoding.CP1250),
- uz_Latn_UZ (0x0443, Encoding.CP1254),
- tt_RU (0x0444, Encoding.CP1251),
- bn_IN (0x0445, Encoding.UNICODE),
- pa_IN (0x0446, Encoding.UNICODE),
- gu_IN (0x0447, Encoding.UNICODE),
- or_IN (0x0448, Encoding.UNICODE),
- ta_IN (0x0449, Encoding.UNICODE),
- te_IN (0x044a, Encoding.UNICODE),
- kn_IN (0x044b, Encoding.UNICODE),
- ml_IN (0x044c, Encoding.UNICODE),
- as_IN (0x044d, Encoding.UNICODE),
- mr_IN (0x044e, Encoding.UNICODE),
- sa_IN (0x044f, Encoding.UNICODE),
- mn_MN (0x0450, Encoding.CP1251),
- bo_CN (0x0451, Encoding.UNICODE),
- cy_GB (0x0452, Encoding.CP1252),
- km_KH (0x0453, Encoding.UNICODE),
- lo_LA (0x0454, Encoding.UNICODE),
- gl_ES (0x0456, Encoding.CP1252),
- kok_IN (0x0457, Encoding.UNICODE),
- syr_SY (0x045a, Encoding.UNICODE),
- si_LK (0x045b, Encoding.UNICODE),
- iu_Cans_CA (0x045d, Encoding.CP1252),
- am_ET (0x045e, Encoding.CP1252),
- ne_NP (0x0461, Encoding.UNICODE),
- fy_NL (0x0462, Encoding.CP1252),
- ps_AF (0x0463, Encoding.UNICODE),
- fil_PH (0x0464, Encoding.CP1252),
- dv_MV (0x0465, Encoding.UNICODE),
- ha_Latn_NG (0x0468, Encoding.CP1252),
- yo_NG (0x046a, Encoding.CP1252),
- quz_BO (0x046b, Encoding.CP1252),
- nso_ZA (0x046c, Encoding.CP1252),
- ba_RU (0x046d, Encoding.CP1251),
- lb_LU (0x046e, Encoding.CP1252),
- kl_GL (0x046f, Encoding.CP1252),
- ig_NG (0x0470, Encoding.CP1252),
- ii_CN (0x0478, Encoding.CP1252),
- arn_CL (0x047a, Encoding.CP1252),
- moh_CA (0x047c, Encoding.CP1252),
- br_FR (0x047e, Encoding.CP1252),
- ug_CN (0x0480, Encoding.CP1256),
- mi_NZ (0x0481, Encoding.UNICODE),
- oc_FR (0x0482, Encoding.CP1252),
- co_FR (0x0483, Encoding.CP1252),
- gsw_FR (0x0484, Encoding.CP1252),
- sah_RU (0x0485, Encoding.CP1251),
- qut_GT (0x0486, Encoding.CP1252),
- rw_RW (0x0487, Encoding.CP1252),
- wo_SN (0x0488, Encoding.CP1252),
- prs_AF (0x048c, Encoding.CP1256),
- ar_IQ (0x0801, Encoding.CP1256),
- zh_CN (0x0804, Encoding.CP936),
- de_CH (0x0807, Encoding.CP1252),
- en_GB (0x0809, Encoding.CP1252),
- es_MX (0x080a, Encoding.CP1252),
- fr_BE (0x080c, Encoding.CP1252),
- it_CH (0x0810, Encoding.CP1252),
- nl_BE (0x0813, Encoding.CP1252),
- nn_NO (0x0814, Encoding.CP1252),
- pt_PT (0x0816, Encoding.CP1252),
- sr_Latn_CS (0x081a, Encoding.CP1250),
- sv_FI (0x081d, Encoding.CP1252),
- Lithuanian_Classic (0x0827, Encoding.CP1257),
- az_Cyrl_AZ (0x082c, Encoding.CP1251),
- dsb_DE (0x082e, Encoding.CP1252),
- se_SE (0x083b, Encoding.CP1252),
- ga_IE (0x083c, Encoding.CP1252),
- ms_BN (0x083e, Encoding.CP1252),
- uz_Cyrl_UZ (0x0843, Encoding.CP1251),
- bn_BD (0x0845, Encoding.UNICODE),
- mn_Mong_CN (0x0850, Encoding.CP1251),
- iu_Latn_CA (0x085d, Encoding.CP1252),
- tzm_Latn_DZ (0x085f, Encoding.CP1252),
- quz_EC (0x086b, Encoding.CP1252),
- ar_EG (0x0c01, Encoding.CP1256),
- zh_HK (0x0c04, Encoding.CP950),
- de_AT (0x0c07, Encoding.CP1252),
- en_AU (0x0c09, Encoding.CP1252),
- es_ES (0x0c0a, Encoding.CP1252),
- fr_CA (0x0c0c, Encoding.CP1252),
- sr_Cyrl_CS (0x0c1a, Encoding.CP1251),
- se_FI (0x0c3b, Encoding.CP1252),
- quz_PE (0x0c6b, Encoding.CP1252),
- ar_LY (0x1001, Encoding.CP1256),
- zh_SG (0x1004, Encoding.CP936),
- de_LU (0x1007, Encoding.CP1252),
- en_CA (0x1009, Encoding.CP1252),
- es_GT (0x100a, Encoding.CP1252),
- fr_CH (0x100c, Encoding.CP1252),
- hr_BA (0x101a, Encoding.CP1250),
- smj_NO (0x103b, Encoding.CP1252),
- ar_DZ (0x1401, Encoding.CP1256),
- zh_MO (0x1404, Encoding.CP950),
- de_LI (0x1407, Encoding.CP1252),
- en_NZ (0x1409, Encoding.CP1252),
- es_CR (0x140a, Encoding.CP1252),
- fr_LU (0x140c, Encoding.CP1252),
- bs_Latn_BA (0x141a, Encoding.CP1250),
- smj_SE (0x143b, Encoding.CP1252),
- ar_MA (0x1801, Encoding.CP1256),
- en_IE (0x1809, Encoding.CP1252),
- es_PA (0x180a, Encoding.CP1252),
- fr_MC (0x180c, Encoding.CP1252),
- sr_Latn_BA (0x181a, Encoding.CP1250),
- sma_NO (0x183b, Encoding.CP1252),
- ar_TN (0x1c01, Encoding.CP1256),
- en_ZA (0x1c09, Encoding.CP1252),
- es_DO (0x1c0a, Encoding.CP1252),
- sr_Cyrl_BA (0x1c1a, Encoding.CP1251),
- sma_SB (0x1c3b, Encoding.CP1252),
- ar_OM (0x2001, Encoding.CP1256),
- en_JM (0x2009, Encoding.CP1252),
- es_VE (0x200a, Encoding.CP1252),
- bs_Cyrl_BA (0x201a, Encoding.CP1251),
- sms_FI (0x203b, Encoding.CP1252),
- ar_YE (0x2401, Encoding.CP1256),
- en_CB (0x2409, Encoding.CP1252),
- es_CO (0x240a, Encoding.CP1252),
- smn_FI (0x243b, Encoding.CP1252),
- ar_SY (0x2801, Encoding.CP1256),
- en_BZ (0x2809, Encoding.CP1252),
- es_PE (0x280a, Encoding.CP1252),
- ar_JO (0x2c01, Encoding.CP1256),
- en_TT (0x2c09, Encoding.CP1252),
- es_AR (0x2c0a, Encoding.CP1252),
- ar_LB (0x3001, Encoding.CP1256),
- en_ZW (0x3009, Encoding.CP1252),
- es_EC (0x300a, Encoding.CP1252),
- ar_KW (0x3401, Encoding.CP1256),
- en_PH (0x3409, Encoding.CP1252),
- es_CL (0x340a, Encoding.CP1252),
- ar_AE (0x3801, Encoding.CP1256),
- es_UY (0x380a, Encoding.CP1252),
- ar_BH (0x3c01, Encoding.CP1256),
- es_PY (0x3c0a, Encoding.CP1252),
- ar_QA (0x4001, Encoding.CP1256),
- en_IN (0x4009, Encoding.CP1252),
- es_BO (0x400a, Encoding.CP1252),
- en_MY (0x4409, Encoding.CP1252),
- es_SV (0x440a, Encoding.CP1252),
- en_SG (0x4809, Encoding.CP1252),
- es_HN (0x480a, Encoding.CP1252),
- es_NI (0x4c0a, Encoding.CP1252),
- es_PR (0x500a, Encoding.CP1252),
- es_US (0x540a, Encoding.CP1252);
+ enum WindowsLocale {
+ ar_SA(0x0401, Encoding.CP1256),
+ bg_BG(0x0402, Encoding.CP1251),
+ ca_ES(0x0403, Encoding.CP1252),
+ zh_TW(0x0404, Encoding.CP950),
+ cs_CZ(0x0405, Encoding.CP1250),
+ da_DK(0x0406, Encoding.CP1252),
+ de_DE(0x0407, Encoding.CP1252),
+ el_GR(0x0408, Encoding.CP1253),
+ en_US(0x0409, Encoding.CP1252),
+ es_ES_tradnl(0x040a, Encoding.CP1252),
+ fi_FI(0x040b, Encoding.CP1252),
+ fr_FR(0x040c, Encoding.CP1252),
+ he_IL(0x040d, Encoding.CP1255),
+ hu_HU(0x040e, Encoding.CP1250),
+ is_IS(0x040f, Encoding.CP1252),
+ it_IT(0x0410, Encoding.CP1252),
+ ja_JP(0x0411, Encoding.CP932),
+ ko_KR(0x0412, Encoding.CP949),
+ nl_NL(0x0413, Encoding.CP1252),
+ nb_NO(0x0414, Encoding.CP1252),
+ pl_PL(0x0415, Encoding.CP1250),
+ pt_BR(0x0416, Encoding.CP1252),
+ rm_CH(0x0417, Encoding.CP1252),
+ ro_RO(0x0418, Encoding.CP1250),
+ ru_RU(0x0419, Encoding.CP1251),
+ hr_HR(0x041a, Encoding.CP1250),
+ sk_SK(0x041b, Encoding.CP1250),
+ sq_AL(0x041c, Encoding.CP1250),
+ sv_SE(0x041d, Encoding.CP1252),
+ th_TH(0x041e, Encoding.CP874),
+ tr_TR(0x041f, Encoding.CP1254),
+ ur_PK(0x0420, Encoding.CP1256),
+ id_ID(0x0421, Encoding.CP1252),
+ uk_UA(0x0422, Encoding.CP1251),
+ be_BY(0x0423, Encoding.CP1251),
+ sl_SI(0x0424, Encoding.CP1250),
+ et_EE(0x0425, Encoding.CP1257),
+ lv_LV(0x0426, Encoding.CP1257),
+ lt_LT(0x0427, Encoding.CP1257),
+ tg_Cyrl_TJ(0x0428, Encoding.CP1251),
+ fa_IR(0x0429, Encoding.CP1256),
+ vi_VN(0x042a, Encoding.CP1258),
+ hy_AM(0x042b, Encoding.CP1252),
+ az_Latn_AZ(0x042c, Encoding.CP1254),
+ eu_ES(0x042d, Encoding.CP1252),
+ wen_DE(0x042e, Encoding.CP1252),
+ mk_MK(0x042f, Encoding.CP1251),
+ tn_ZA(0x0432, Encoding.CP1252),
+ xh_ZA(0x0434, Encoding.CP1252),
+ zu_ZA(0x0435, Encoding.CP1252),
+ Af_ZA(0x0436, Encoding.CP1252),
+ ka_GE(0x0437, Encoding.CP1252),
+ fo_FO(0x0438, Encoding.CP1252),
+ hi_IN(0x0439, Encoding.UNICODE),
+ mt_MT(0x043a, Encoding.UNICODE),
+ se_NO(0x043b, Encoding.CP1252),
+ ms_MY(0x043e, Encoding.CP1252),
+ kk_KZ(0x043f, Encoding.CP1251),
+ ky_KG(0x0440, Encoding.CP1251),
+ sw_KE(0x0441, Encoding.CP1252),
+ tk_TM(0x0442, Encoding.CP1250),
+ uz_Latn_UZ(0x0443, Encoding.CP1254),
+ tt_RU(0x0444, Encoding.CP1251),
+ bn_IN(0x0445, Encoding.UNICODE),
+ pa_IN(0x0446, Encoding.UNICODE),
+ gu_IN(0x0447, Encoding.UNICODE),
+ or_IN(0x0448, Encoding.UNICODE),
+ ta_IN(0x0449, Encoding.UNICODE),
+ te_IN(0x044a, Encoding.UNICODE),
+ kn_IN(0x044b, Encoding.UNICODE),
+ ml_IN(0x044c, Encoding.UNICODE),
+ as_IN(0x044d, Encoding.UNICODE),
+ mr_IN(0x044e, Encoding.UNICODE),
+ sa_IN(0x044f, Encoding.UNICODE),
+ mn_MN(0x0450, Encoding.CP1251),
+ bo_CN(0x0451, Encoding.UNICODE),
+ cy_GB(0x0452, Encoding.CP1252),
+ km_KH(0x0453, Encoding.UNICODE),
+ lo_LA(0x0454, Encoding.UNICODE),
+ gl_ES(0x0456, Encoding.CP1252),
+ kok_IN(0x0457, Encoding.UNICODE),
+ syr_SY(0x045a, Encoding.UNICODE),
+ si_LK(0x045b, Encoding.UNICODE),
+ iu_Cans_CA(0x045d, Encoding.CP1252),
+ am_ET(0x045e, Encoding.CP1252),
+ ne_NP(0x0461, Encoding.UNICODE),
+ fy_NL(0x0462, Encoding.CP1252),
+ ps_AF(0x0463, Encoding.UNICODE),
+ fil_PH(0x0464, Encoding.CP1252),
+ dv_MV(0x0465, Encoding.UNICODE),
+ ha_Latn_NG(0x0468, Encoding.CP1252),
+ yo_NG(0x046a, Encoding.CP1252),
+ quz_BO(0x046b, Encoding.CP1252),
+ nso_ZA(0x046c, Encoding.CP1252),
+ ba_RU(0x046d, Encoding.CP1251),
+ lb_LU(0x046e, Encoding.CP1252),
+ kl_GL(0x046f, Encoding.CP1252),
+ ig_NG(0x0470, Encoding.CP1252),
+ ii_CN(0x0478, Encoding.CP1252),
+ arn_CL(0x047a, Encoding.CP1252),
+ moh_CA(0x047c, Encoding.CP1252),
+ br_FR(0x047e, Encoding.CP1252),
+ ug_CN(0x0480, Encoding.CP1256),
+ mi_NZ(0x0481, Encoding.UNICODE),
+ oc_FR(0x0482, Encoding.CP1252),
+ co_FR(0x0483, Encoding.CP1252),
+ gsw_FR(0x0484, Encoding.CP1252),
+ sah_RU(0x0485, Encoding.CP1251),
+ qut_GT(0x0486, Encoding.CP1252),
+ rw_RW(0x0487, Encoding.CP1252),
+ wo_SN(0x0488, Encoding.CP1252),
+ prs_AF(0x048c, Encoding.CP1256),
+ ar_IQ(0x0801, Encoding.CP1256),
+ zh_CN(0x0804, Encoding.CP936),
+ de_CH(0x0807, Encoding.CP1252),
+ en_GB(0x0809, Encoding.CP1252),
+ es_MX(0x080a, Encoding.CP1252),
+ fr_BE(0x080c, Encoding.CP1252),
+ it_CH(0x0810, Encoding.CP1252),
+ nl_BE(0x0813, Encoding.CP1252),
+ nn_NO(0x0814, Encoding.CP1252),
+ pt_PT(0x0816, Encoding.CP1252),
+ sr_Latn_CS(0x081a, Encoding.CP1250),
+ sv_FI(0x081d, Encoding.CP1252),
+ Lithuanian_Classic(0x0827, Encoding.CP1257),
+ az_Cyrl_AZ(0x082c, Encoding.CP1251),
+ dsb_DE(0x082e, Encoding.CP1252),
+ se_SE(0x083b, Encoding.CP1252),
+ ga_IE(0x083c, Encoding.CP1252),
+ ms_BN(0x083e, Encoding.CP1252),
+ uz_Cyrl_UZ(0x0843, Encoding.CP1251),
+ bn_BD(0x0845, Encoding.UNICODE),
+ mn_Mong_CN(0x0850, Encoding.CP1251),
+ iu_Latn_CA(0x085d, Encoding.CP1252),
+ tzm_Latn_DZ(0x085f, Encoding.CP1252),
+ quz_EC(0x086b, Encoding.CP1252),
+ ar_EG(0x0c01, Encoding.CP1256),
+ zh_HK(0x0c04, Encoding.CP950),
+ de_AT(0x0c07, Encoding.CP1252),
+ en_AU(0x0c09, Encoding.CP1252),
+ es_ES(0x0c0a, Encoding.CP1252),
+ fr_CA(0x0c0c, Encoding.CP1252),
+ sr_Cyrl_CS(0x0c1a, Encoding.CP1251),
+ se_FI(0x0c3b, Encoding.CP1252),
+ quz_PE(0x0c6b, Encoding.CP1252),
+ ar_LY(0x1001, Encoding.CP1256),
+ zh_SG(0x1004, Encoding.CP936),
+ de_LU(0x1007, Encoding.CP1252),
+ en_CA(0x1009, Encoding.CP1252),
+ es_GT(0x100a, Encoding.CP1252),
+ fr_CH(0x100c, Encoding.CP1252),
+ hr_BA(0x101a, Encoding.CP1250),
+ smj_NO(0x103b, Encoding.CP1252),
+ ar_DZ(0x1401, Encoding.CP1256),
+ zh_MO(0x1404, Encoding.CP950),
+ de_LI(0x1407, Encoding.CP1252),
+ en_NZ(0x1409, Encoding.CP1252),
+ es_CR(0x140a, Encoding.CP1252),
+ fr_LU(0x140c, Encoding.CP1252),
+ bs_Latn_BA(0x141a, Encoding.CP1250),
+ smj_SE(0x143b, Encoding.CP1252),
+ ar_MA(0x1801, Encoding.CP1256),
+ en_IE(0x1809, Encoding.CP1252),
+ es_PA(0x180a, Encoding.CP1252),
+ fr_MC(0x180c, Encoding.CP1252),
+ sr_Latn_BA(0x181a, Encoding.CP1250),
+ sma_NO(0x183b, Encoding.CP1252),
+ ar_TN(0x1c01, Encoding.CP1256),
+ en_ZA(0x1c09, Encoding.CP1252),
+ es_DO(0x1c0a, Encoding.CP1252),
+ sr_Cyrl_BA(0x1c1a, Encoding.CP1251),
+ sma_SB(0x1c3b, Encoding.CP1252),
+ ar_OM(0x2001, Encoding.CP1256),
+ en_JM(0x2009, Encoding.CP1252),
+ es_VE(0x200a, Encoding.CP1252),
+ bs_Cyrl_BA(0x201a, Encoding.CP1251),
+ sms_FI(0x203b, Encoding.CP1252),
+ ar_YE(0x2401, Encoding.CP1256),
+ en_CB(0x2409, Encoding.CP1252),
+ es_CO(0x240a, Encoding.CP1252),
+ smn_FI(0x243b, Encoding.CP1252),
+ ar_SY(0x2801, Encoding.CP1256),
+ en_BZ(0x2809, Encoding.CP1252),
+ es_PE(0x280a, Encoding.CP1252),
+ ar_JO(0x2c01, Encoding.CP1256),
+ en_TT(0x2c09, Encoding.CP1252),
+ es_AR(0x2c0a, Encoding.CP1252),
+ ar_LB(0x3001, Encoding.CP1256),
+ en_ZW(0x3009, Encoding.CP1252),
+ es_EC(0x300a, Encoding.CP1252),
+ ar_KW(0x3401, Encoding.CP1256),
+ en_PH(0x3409, Encoding.CP1252),
+ es_CL(0x340a, Encoding.CP1252),
+ ar_AE(0x3801, Encoding.CP1256),
+ es_UY(0x380a, Encoding.CP1252),
+ ar_BH(0x3c01, Encoding.CP1256),
+ es_PY(0x3c0a, Encoding.CP1252),
+ ar_QA(0x4001, Encoding.CP1256),
+ en_IN(0x4009, Encoding.CP1252),
+ es_BO(0x400a, Encoding.CP1252),
+ en_MY(0x4409, Encoding.CP1252),
+ es_SV(0x440a, Encoding.CP1252),
+ en_SG(0x4809, Encoding.CP1252),
+ es_HN(0x480a, Encoding.CP1252),
+ es_NI(0x4c0a, Encoding.CP1252),
+ es_PR(0x500a, Encoding.CP1252),
+ es_US(0x540a, Encoding.CP1252);
private final int langID;
private final Encoding encoding;
- WindowsLocale(int langID,
- Encoding encoding) {
+ WindowsLocale(int langID, Encoding encoding) {
this.langID = langID;
this.encoding = encoding;
}
@@ -356,8 +357,7 @@ private Encoding encodingFromLCID() throws UnsupportedEncodingException {
try {
return locale.getEncoding();
- }
- catch (UnsupportedEncodingException inner) {
+ } catch (UnsupportedEncodingException inner) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_unknownLCID"));
Object[] msgArgs = {locale};
UnsupportedEncodingException e = new UnsupportedEncodingException(form.format(msgArgs));
@@ -369,130 +369,129 @@ private Encoding encodingFromLCID() throws UnsupportedEncodingException {
/**
* Enumeration of original SQL Server sort orders recognized by SQL Server.
*
- * If SQL collation has a non-zero sortId, then use this enum to determine the encoding. From sql_main\sql\common\src\sqlscol.cpp (SQLServer code
- * base).
+ * If SQL collation has a non-zero sortId, then use this enum to determine the encoding. From
+ * sql_main\sql\common\src\sqlscol.cpp (SQLServer code base).
*/
- enum SortOrder
- {
- BIN_CP437 (30, "SQL_Latin1_General_CP437_BIN", Encoding.CP437),
- DICTIONARY_437 (31, "SQL_Latin1_General_CP437_CS_AS", Encoding.CP437),
- NOCASE_437 (32, "SQL_Latin1_General_CP437_CI_AS", Encoding.CP437),
- NOCASEPREF_437 (33, "SQL_Latin1_General_Pref_CP437_CI_AS", Encoding.CP437),
- NOACCENTS_437 (34, "SQL_Latin1_General_CP437_CI_AI", Encoding.CP437),
- BIN2_CP437 (35, "SQL_Latin1_General_CP437_BIN2", Encoding.CP437),
-
- BIN_CP850 (40, "SQL_Latin1_General_CP850_BIN", Encoding.CP850),
- DICTIONARY_850 (41, "SQL_Latin1_General_CP850_CS_AS", Encoding.CP850),
- NOCASE_850 (42, "SQL_Latin1_General_CP850_CI_AS", Encoding.CP850),
- NOCASEPREF_850 (43, "SQL_Latin1_General_Pref_CP850_CI_AS", Encoding.CP850),
- NOACCENTS_850 (44, "SQL_Latin1_General_CP850_CI_AI", Encoding.CP850),
- BIN2_CP850 (45, "SQL_Latin1_General_CP850_BIN2", Encoding.CP850),
-
- CASELESS_34 (49, "SQL_1xCompat_CP850_CI_AS", Encoding.CP850),
- BIN_ISO_1 (50, "bin_iso_1", Encoding.CP1252),
- DICTIONARY_ISO (51, "SQL_Latin1_General_CP1_CS_AS", Encoding.CP1252),
- NOCASE_ISO (52, "SQL_Latin1_General_CP1_CI_AS", Encoding.CP1252),
- NOCASEPREF_ISO (53, "SQL_Latin1_General_Pref_CP1_CI_AS", Encoding.CP1252),
- NOACCENTS_ISO (54, "SQL_Latin1_General_CP1_CI_AI", Encoding.CP1252),
- ALT_DICTIONARY (55, "SQL_AltDiction_CP850_CS_AS", Encoding.CP850),
- ALT_NOCASEPREF (56, "SQL_AltDiction_Pref_CP850_CI_AS", Encoding.CP850),
- ALT_NOACCENTS (57, "SQL_AltDiction_CP850_CI_AI", Encoding.CP850),
- SCAND_NOCASEPREF (58, "SQL_Scandinavian_Pref_CP850_CI_AS", Encoding.CP850),
- SCAND_DICTIONARY (59, "SQL_Scandinavian_CP850_CS_AS", Encoding.CP850),
- SCAND_NOCASE (60, "SQL_Scandinavian_CP850_CI_AS", Encoding.CP850),
- ALT_NOCASE (61, "SQL_AltDiction_CP850_CI_AS", Encoding.CP850),
-
- DICTIONARY_1252 (71, "dictionary_1252", Encoding.CP1252),
- NOCASE_1252 (72, "nocase_1252", Encoding.CP1252),
- DNK_NOR_DICTIONARY (73, "dnk_nor_dictionary", Encoding.CP1252),
- FIN_SWE_DICTIONARY (74, "fin_swe_dictionary", Encoding.CP1252),
- ISL_DICTIONARY (75, "isl_dictionary", Encoding.CP1252),
-
- BIN_CP1250 (80, "bin_cp1250", Encoding.CP1250),
- DICTIONARY_1250 (81, "SQL_Latin1_General_CP1250_CS_AS", Encoding.CP1250),
- NOCASE_1250 (82, "SQL_Latin1_General_CP1250_CI_AS", Encoding.CP1250),
- CSYDIC (83, "SQL_Czech_CP1250_CS_AS", Encoding.CP1250),
- CSYNC (84, "SQL_Czech_CP1250_CI_AS", Encoding.CP1250),
- HUNDIC (85, "SQL_Hungarian_CP1250_CS_AS", Encoding.CP1250),
- HUNNC (86, "SQL_Hungarian_CP1250_CI_AS", Encoding.CP1250),
- PLKDIC (87, "SQL_Polish_CP1250_CS_AS", Encoding.CP1250),
- PLKNC (88, "SQL_Polish_CP1250_CI_AS", Encoding.CP1250),
- ROMDIC (89, "SQL_Romanian_CP1250_CS_AS", Encoding.CP1250),
- ROMNC (90, "SQL_Romanian_CP1250_CI_AS", Encoding.CP1250),
- SHLDIC (91, "SQL_Croatian_CP1250_CS_AS", Encoding.CP1250),
- SHLNC (92, "SQL_Croatian_CP1250_CI_AS", Encoding.CP1250),
- SKYDIC (93, "SQL_Slovak_CP1250_CS_AS", Encoding.CP1250),
- SKYNC (94, "SQL_Slovak_CP1250_CI_AS", Encoding.CP1250),
- SLVDIC (95, "SQL_Slovenian_CP1250_CS_AS", Encoding.CP1250),
- SLVNC (96, "SQL_Slovenian_CP1250_CI_AS", Encoding.CP1250),
- POLISH_CS (97, "polish_cs", Encoding.CP1250),
- POLISH_CI (98, "polish_ci", Encoding.CP1250),
-
- BIN_CP1251 (104, "bin_cp1251", Encoding.CP1251),
- DICTIONARY_1251 (105, "SQL_Latin1_General_CP1251_CS_AS", Encoding.CP1251),
- NOCASE_1251 (106, "SQL_Latin1_General_CP1251_CI_AS", Encoding.CP1251),
- UKRDIC (107, "SQL_Ukrainian_CP1251_CS_AS", Encoding.CP1251),
- UKRNC (108, "SQL_Ukrainian_CP1251_CI_AS", Encoding.CP1251),
-
- BIN_CP1253 (112, "bin_cp1253", Encoding.CP1253),
- DICTIONARY_1253 (113, "SQL_Latin1_General_CP1253_CS_AS", Encoding.CP1253),
- NOCASE_1253 (114, "SQL_Latin1_General_CP1253_CI_AS", Encoding.CP1253),
-
- GREEK_MIXEDDICTIONARY (120, "SQL_MixDiction_CP1253_CS_AS", Encoding.CP1253),
- GREEK_ALTDICTIONARY (121, "SQL_AltDiction_CP1253_CS_AS", Encoding.CP1253),
- GREEK_ALTDICTIONARY2 (122, "SQL_AltDiction2_CP1253_CS_AS", Encoding.CP1253),
- GREEK_NOCASEDICT (124, "SQL_Latin1_General_CP1253_CI_AI", Encoding.CP1253),
- BIN_CP1254 (128, "bin_cp1254", Encoding.CP1254),
- DICTIONARY_1254 (129, "SQL_Latin1_General_CP1254_CS_AS", Encoding.CP1254),
- NOCASE_1254 (130, "SQL_Latin1_General_CP1254_CI_AS", Encoding.CP1254),
-
- BIN_CP1255 (136, "bin_cp1255", Encoding.CP1255),
- DICTIONARY_1255 (137, "SQL_Latin1_General_CP1255_CS_AS", Encoding.CP1255),
- NOCASE_1255 (138, "SQL_Latin1_General_CP1255_CI_AS", Encoding.CP1255),
-
- BIN_CP1256 (144, "bin_cp1256", Encoding.CP1256),
- DICTIONARY_1256 (145, "SQL_Latin1_General_CP1256_CS_AS", Encoding.CP1256),
- NOCASE_1256 (146, "SQL_Latin1_General_CP1256_CI_AS", Encoding.CP1256),
-
- BIN_CP1257 (152, "bin_cp1257", Encoding.CP1257),
- DICTIONARY_1257 (153, "SQL_Latin1_General_CP1257_CS_AS", Encoding.CP1257),
- NOCASE_1257 (154, "SQL_Latin1_General_CP1257_CI_AS", Encoding.CP1257),
- ETIDIC (155, "SQL_Estonian_CP1257_CS_AS", Encoding.CP1257),
- ETINC (156, "SQL_Estonian_CP1257_CI_AS", Encoding.CP1257),
- LVIDIC (157, "SQL_Latvian_CP1257_CS_AS", Encoding.CP1257),
- LVINC (158, "SQL_Latvian_CP1257_CI_AS", Encoding.CP1257),
- LTHDIC (159, "SQL_Lithuanian_CP1257_CS_AS", Encoding.CP1257),
- LTHNC (160, "SQL_Lithuanian_CP1257_CI_AS", Encoding.CP1257),
-
- DANNO_NOCASEPREF (183, "SQL_Danish_Pref_CP1_CI_AS", Encoding.CP1252),
- SVFI1_NOCASEPREF (184, "SQL_SwedishPhone_Pref_CP1_CI_AS", Encoding.CP1252),
- SVFI2_NOCASEPREF (185, "SQL_SwedishStd_Pref_CP1_CI_AS", Encoding.CP1252),
- ISLAN_NOCASEPREF (186, "SQL_Icelandic_Pref_CP1_CI_AS", Encoding.CP1252),
-
- BIN_CP932 (192, "bin_cp932", Encoding.CP932),
- NLS_CP932 (193, "nls_cp932", Encoding.CP932),
- BIN_CP949 (194, "bin_cp949", Encoding.CP949),
- NLS_CP949 (195, "nls_cp949", Encoding.CP949),
- BIN_CP950 (196, "bin_cp950", Encoding.CP950),
- NLS_CP950 (197, "nls_cp950", Encoding.CP950),
- BIN_CP936 (198, "bin_cp936", Encoding.CP936),
- NLS_CP936 (199, "nls_cp936", Encoding.CP936),
- NLS_CP932_CS (200, "nls_cp932_cs", Encoding.CP932),
- NLS_CP949_CS (201, "nls_cp949_cs", Encoding.CP949),
- NLS_CP950_CS (202, "nls_cp950_cs", Encoding.CP950),
- NLS_CP936_CS (203, "nls_cp936_cs", Encoding.CP936),
- BIN_CP874 (204, "bin_cp874", Encoding.CP874),
- NLS_CP874 (205, "nls_cp874", Encoding.CP874),
- NLS_CP874_CS (206, "nls_cp874_cs", Encoding.CP874),
-
- EBCDIC_037 (210, "SQL_EBCDIC037_CP1_CS_AS", Encoding.CP1252),
- EBCDIC_273 (211, "SQL_EBCDIC273_CP1_CS_AS", Encoding.CP1252),
- EBCDIC_277 (212, "SQL_EBCDIC277_CP1_CS_AS", Encoding.CP1252),
- EBCDIC_278 (213, "SQL_EBCDIC278_CP1_CS_AS", Encoding.CP1252),
- EBCDIC_280 (214, "SQL_EBCDIC280_CP1_CS_AS", Encoding.CP1252),
- EBCDIC_284 (215, "SQL_EBCDIC284_CP1_CS_AS", Encoding.CP1252),
- EBCDIC_285 (216, "SQL_EBCDIC285_CP1_CS_AS", Encoding.CP1252),
- EBCDIC_297 (217, "SQL_EBCDIC297_CP1_CS_AS", Encoding.CP1252);
+ enum SortOrder {
+ BIN_CP437(30, "SQL_Latin1_General_CP437_BIN", Encoding.CP437),
+ DICTIONARY_437(31, "SQL_Latin1_General_CP437_CS_AS", Encoding.CP437),
+ NOCASE_437(32, "SQL_Latin1_General_CP437_CI_AS", Encoding.CP437),
+ NOCASEPREF_437(33, "SQL_Latin1_General_Pref_CP437_CI_AS", Encoding.CP437),
+ NOACCENTS_437(34, "SQL_Latin1_General_CP437_CI_AI", Encoding.CP437),
+ BIN2_CP437(35, "SQL_Latin1_General_CP437_BIN2", Encoding.CP437),
+
+ BIN_CP850(40, "SQL_Latin1_General_CP850_BIN", Encoding.CP850),
+ DICTIONARY_850(41, "SQL_Latin1_General_CP850_CS_AS", Encoding.CP850),
+ NOCASE_850(42, "SQL_Latin1_General_CP850_CI_AS", Encoding.CP850),
+ NOCASEPREF_850(43, "SQL_Latin1_General_Pref_CP850_CI_AS", Encoding.CP850),
+ NOACCENTS_850(44, "SQL_Latin1_General_CP850_CI_AI", Encoding.CP850),
+ BIN2_CP850(45, "SQL_Latin1_General_CP850_BIN2", Encoding.CP850),
+
+ CASELESS_34(49, "SQL_1xCompat_CP850_CI_AS", Encoding.CP850),
+ BIN_ISO_1(50, "bin_iso_1", Encoding.CP1252),
+ DICTIONARY_ISO(51, "SQL_Latin1_General_CP1_CS_AS", Encoding.CP1252),
+ NOCASE_ISO(52, "SQL_Latin1_General_CP1_CI_AS", Encoding.CP1252),
+ NOCASEPREF_ISO(53, "SQL_Latin1_General_Pref_CP1_CI_AS", Encoding.CP1252),
+ NOACCENTS_ISO(54, "SQL_Latin1_General_CP1_CI_AI", Encoding.CP1252),
+ ALT_DICTIONARY(55, "SQL_AltDiction_CP850_CS_AS", Encoding.CP850),
+ ALT_NOCASEPREF(56, "SQL_AltDiction_Pref_CP850_CI_AS", Encoding.CP850),
+ ALT_NOACCENTS(57, "SQL_AltDiction_CP850_CI_AI", Encoding.CP850),
+ SCAND_NOCASEPREF(58, "SQL_Scandinavian_Pref_CP850_CI_AS", Encoding.CP850),
+ SCAND_DICTIONARY(59, "SQL_Scandinavian_CP850_CS_AS", Encoding.CP850),
+ SCAND_NOCASE(60, "SQL_Scandinavian_CP850_CI_AS", Encoding.CP850),
+ ALT_NOCASE(61, "SQL_AltDiction_CP850_CI_AS", Encoding.CP850),
+
+ DICTIONARY_1252(71, "dictionary_1252", Encoding.CP1252),
+ NOCASE_1252(72, "nocase_1252", Encoding.CP1252),
+ DNK_NOR_DICTIONARY(73, "dnk_nor_dictionary", Encoding.CP1252),
+ FIN_SWE_DICTIONARY(74, "fin_swe_dictionary", Encoding.CP1252),
+ ISL_DICTIONARY(75, "isl_dictionary", Encoding.CP1252),
+
+ BIN_CP1250(80, "bin_cp1250", Encoding.CP1250),
+ DICTIONARY_1250(81, "SQL_Latin1_General_CP1250_CS_AS", Encoding.CP1250),
+ NOCASE_1250(82, "SQL_Latin1_General_CP1250_CI_AS", Encoding.CP1250),
+ CSYDIC(83, "SQL_Czech_CP1250_CS_AS", Encoding.CP1250),
+ CSYNC(84, "SQL_Czech_CP1250_CI_AS", Encoding.CP1250),
+ HUNDIC(85, "SQL_Hungarian_CP1250_CS_AS", Encoding.CP1250),
+ HUNNC(86, "SQL_Hungarian_CP1250_CI_AS", Encoding.CP1250),
+ PLKDIC(87, "SQL_Polish_CP1250_CS_AS", Encoding.CP1250),
+ PLKNC(88, "SQL_Polish_CP1250_CI_AS", Encoding.CP1250),
+ ROMDIC(89, "SQL_Romanian_CP1250_CS_AS", Encoding.CP1250),
+ ROMNC(90, "SQL_Romanian_CP1250_CI_AS", Encoding.CP1250),
+ SHLDIC(91, "SQL_Croatian_CP1250_CS_AS", Encoding.CP1250),
+ SHLNC(92, "SQL_Croatian_CP1250_CI_AS", Encoding.CP1250),
+ SKYDIC(93, "SQL_Slovak_CP1250_CS_AS", Encoding.CP1250),
+ SKYNC(94, "SQL_Slovak_CP1250_CI_AS", Encoding.CP1250),
+ SLVDIC(95, "SQL_Slovenian_CP1250_CS_AS", Encoding.CP1250),
+ SLVNC(96, "SQL_Slovenian_CP1250_CI_AS", Encoding.CP1250),
+ POLISH_CS(97, "polish_cs", Encoding.CP1250),
+ POLISH_CI(98, "polish_ci", Encoding.CP1250),
+
+ BIN_CP1251(104, "bin_cp1251", Encoding.CP1251),
+ DICTIONARY_1251(105, "SQL_Latin1_General_CP1251_CS_AS", Encoding.CP1251),
+ NOCASE_1251(106, "SQL_Latin1_General_CP1251_CI_AS", Encoding.CP1251),
+ UKRDIC(107, "SQL_Ukrainian_CP1251_CS_AS", Encoding.CP1251),
+ UKRNC(108, "SQL_Ukrainian_CP1251_CI_AS", Encoding.CP1251),
+
+ BIN_CP1253(112, "bin_cp1253", Encoding.CP1253),
+ DICTIONARY_1253(113, "SQL_Latin1_General_CP1253_CS_AS", Encoding.CP1253),
+ NOCASE_1253(114, "SQL_Latin1_General_CP1253_CI_AS", Encoding.CP1253),
+
+ GREEK_MIXEDDICTIONARY(120, "SQL_MixDiction_CP1253_CS_AS", Encoding.CP1253),
+ GREEK_ALTDICTIONARY(121, "SQL_AltDiction_CP1253_CS_AS", Encoding.CP1253),
+ GREEK_ALTDICTIONARY2(122, "SQL_AltDiction2_CP1253_CS_AS", Encoding.CP1253),
+ GREEK_NOCASEDICT(124, "SQL_Latin1_General_CP1253_CI_AI", Encoding.CP1253),
+ BIN_CP1254(128, "bin_cp1254", Encoding.CP1254),
+ DICTIONARY_1254(129, "SQL_Latin1_General_CP1254_CS_AS", Encoding.CP1254),
+ NOCASE_1254(130, "SQL_Latin1_General_CP1254_CI_AS", Encoding.CP1254),
+
+ BIN_CP1255(136, "bin_cp1255", Encoding.CP1255),
+ DICTIONARY_1255(137, "SQL_Latin1_General_CP1255_CS_AS", Encoding.CP1255),
+ NOCASE_1255(138, "SQL_Latin1_General_CP1255_CI_AS", Encoding.CP1255),
+
+ BIN_CP1256(144, "bin_cp1256", Encoding.CP1256),
+ DICTIONARY_1256(145, "SQL_Latin1_General_CP1256_CS_AS", Encoding.CP1256),
+ NOCASE_1256(146, "SQL_Latin1_General_CP1256_CI_AS", Encoding.CP1256),
+
+ BIN_CP1257(152, "bin_cp1257", Encoding.CP1257),
+ DICTIONARY_1257(153, "SQL_Latin1_General_CP1257_CS_AS", Encoding.CP1257),
+ NOCASE_1257(154, "SQL_Latin1_General_CP1257_CI_AS", Encoding.CP1257),
+ ETIDIC(155, "SQL_Estonian_CP1257_CS_AS", Encoding.CP1257),
+ ETINC(156, "SQL_Estonian_CP1257_CI_AS", Encoding.CP1257),
+ LVIDIC(157, "SQL_Latvian_CP1257_CS_AS", Encoding.CP1257),
+ LVINC(158, "SQL_Latvian_CP1257_CI_AS", Encoding.CP1257),
+ LTHDIC(159, "SQL_Lithuanian_CP1257_CS_AS", Encoding.CP1257),
+ LTHNC(160, "SQL_Lithuanian_CP1257_CI_AS", Encoding.CP1257),
+
+ DANNO_NOCASEPREF(183, "SQL_Danish_Pref_CP1_CI_AS", Encoding.CP1252),
+ SVFI1_NOCASEPREF(184, "SQL_SwedishPhone_Pref_CP1_CI_AS", Encoding.CP1252),
+ SVFI2_NOCASEPREF(185, "SQL_SwedishStd_Pref_CP1_CI_AS", Encoding.CP1252),
+ ISLAN_NOCASEPREF(186, "SQL_Icelandic_Pref_CP1_CI_AS", Encoding.CP1252),
+
+ BIN_CP932(192, "bin_cp932", Encoding.CP932),
+ NLS_CP932(193, "nls_cp932", Encoding.CP932),
+ BIN_CP949(194, "bin_cp949", Encoding.CP949),
+ NLS_CP949(195, "nls_cp949", Encoding.CP949),
+ BIN_CP950(196, "bin_cp950", Encoding.CP950),
+ NLS_CP950(197, "nls_cp950", Encoding.CP950),
+ BIN_CP936(198, "bin_cp936", Encoding.CP936),
+ NLS_CP936(199, "nls_cp936", Encoding.CP936),
+ NLS_CP932_CS(200, "nls_cp932_cs", Encoding.CP932),
+ NLS_CP949_CS(201, "nls_cp949_cs", Encoding.CP949),
+ NLS_CP950_CS(202, "nls_cp950_cs", Encoding.CP950),
+ NLS_CP936_CS(203, "nls_cp936_cs", Encoding.CP936),
+ BIN_CP874(204, "bin_cp874", Encoding.CP874),
+ NLS_CP874(205, "nls_cp874", Encoding.CP874),
+ NLS_CP874_CS(206, "nls_cp874_cs", Encoding.CP874),
+
+ EBCDIC_037(210, "SQL_EBCDIC037_CP1_CS_AS", Encoding.CP1252),
+ EBCDIC_273(211, "SQL_EBCDIC273_CP1_CS_AS", Encoding.CP1252),
+ EBCDIC_277(212, "SQL_EBCDIC277_CP1_CS_AS", Encoding.CP1252),
+ EBCDIC_278(213, "SQL_EBCDIC278_CP1_CS_AS", Encoding.CP1252),
+ EBCDIC_280(214, "SQL_EBCDIC280_CP1_CS_AS", Encoding.CP1252),
+ EBCDIC_284(215, "SQL_EBCDIC284_CP1_CS_AS", Encoding.CP1252),
+ EBCDIC_285(216, "SQL_EBCDIC285_CP1_CS_AS", Encoding.CP1252),
+ EBCDIC_297(217, "SQL_EBCDIC297_CP1_CS_AS", Encoding.CP1252);
private final int sortId;
private final String name;
@@ -502,9 +501,7 @@ final Encoding getEncoding() throws UnsupportedEncodingException {
return encoding.checkSupported();
}
- SortOrder(int sortId,
- String name,
- Encoding encoding) {
+ SortOrder(int sortId, String name, Encoding encoding) {
this.sortId = sortId;
this.name = name;
this.encoding = encoding;
@@ -528,8 +525,7 @@ private Encoding encodingFromSortId() throws UnsupportedEncodingException {
try {
return sortOrder.getEncoding();
- }
- catch (UnsupportedEncodingException inner) {
+ } catch (UnsupportedEncodingException inner) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_unknownSortId"));
Object[] msgArgs = {sortOrder};
UnsupportedEncodingException e = new UnsupportedEncodingException(form.format(msgArgs));
@@ -551,32 +547,32 @@ private Encoding encodingFromSortId() throws UnsupportedEncodingException {
}
}
+
/**
* Enumeration of encodings that are supported by SQL Server (and hopefully the JVM).
*
- * See, for example, https://docs.oracle.com/javase/8/docs/technotes/guides/intl/encoding.doc.html for a complete list of supported encodings with
- * their canonical names.
+ * See, for example, https://docs.oracle.com/javase/8/docs/technotes/guides/intl/encoding.doc.html for a complete list
+ * of supported encodings with their canonical names.
*/
-enum Encoding
-{
- UNICODE ("UTF-16LE", true, false),
- UTF8 ("UTF-8", true, false),
- CP437 ("Cp437", false, false),
- CP850 ("Cp850", false, false),
- CP874 ("MS874", true, true),
- CP932 ("MS932", true, false),
- CP936 ("MS936", true, false),
- CP949 ("MS949", true, false),
- CP950 ("MS950", true, false),
- CP1250 ("Cp1250", true, true),
- CP1251 ("Cp1251", true, true),
- CP1252 ("Cp1252", true, true),
- CP1253 ("Cp1253", true, true),
- CP1254 ("Cp1254", true, true),
- CP1255 ("Cp1255", true, true),
- CP1256 ("Cp1256", true, true),
- CP1257 ("Cp1257", true, true),
- CP1258 ("Cp1258", true, true);
+enum Encoding {
+ UNICODE("UTF-16LE", true, false),
+ UTF8("UTF-8", true, false),
+ CP437("Cp437", false, false),
+ CP850("Cp850", false, false),
+ CP874("MS874", true, true),
+ CP932("MS932", true, false),
+ CP936("MS936", true, false),
+ CP949("MS949", true, false),
+ CP950("MS950", true, false),
+ CP1250("Cp1250", true, true),
+ CP1251("Cp1251", true, true),
+ CP1252("Cp1252", true, true),
+ CP1253("Cp1253", true, true),
+ CP1254("Cp1254", true, true),
+ CP1255("Cp1255", true, true),
+ CP1256("Cp1256", true, true),
+ CP1257("Cp1257", true, true),
+ CP1258("Cp1258", true, true);
private final String charsetName;
private final boolean supportsAsciiConversion;
@@ -584,9 +580,7 @@ enum Encoding
private boolean jvmSupportConfirmed = false;
private Charset charset;
- private Encoding(String charsetName,
- boolean supportsAsciiConversion,
- boolean hasAsciiCompatibleSBCS) {
+ private Encoding(String charsetName, boolean supportsAsciiConversion, boolean hasAsciiCompatibleSBCS) {
this.charsetName = charsetName;
this.supportsAsciiConversion = supportsAsciiConversion;
this.hasAsciiCompatibleSBCS = hasAsciiCompatibleSBCS;
@@ -614,8 +608,7 @@ final Charset charset() throws SQLServerException {
if (charset == null) {
charset = Charset.forName(charsetName);
}
- }
- catch (UnsupportedEncodingException e) {
+ } catch (UnsupportedEncodingException e) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_codePageNotSupported"));
Object[] msgArgs = {charsetName};
throw new SQLServerException(form.format(msgArgs), e);
@@ -626,8 +619,9 @@ final Charset charset() throws SQLServerException {
/**
* Returns true if the collation supports conversion to ascii.
*
- * Per discussions with richards and michkap on UNICODE alias -> ASCII range is 0x00 to 0x7F. The range of 0x00 to 0x7F of 1250-1258, 874, 932,
- * 936, 949, and 950 are identical to ASCII. See also -> http://blogs.msdn.com/michkap/archive/2005/11/23/495193.aspx
+ * Per discussions with richards and michkap on UNICODE alias -> ASCII range is 0x00 to 0x7F. The range of 0x00 to
+ * 0x7F of 1250-1258, 874, 932, 936, 949, and 950 are identical to ASCII. See also ->
+ * http://blogs.msdn.com/michkap/archive/2005/11/23/495193.aspx
*/
boolean supportsAsciiConversion() {
return supportsAsciiConversion;
@@ -636,8 +630,9 @@ boolean supportsAsciiConversion() {
/**
* Returns true if the collation supports conversion to ascii AND it uses a single-byte character set.
*
- * Per discussions with richards and michkap on UNICODE alias -> ASCII range is 0x00 to 0x7F. The range of 0x00 to 0x7F of 1250-1258 and 874 are
- * identical to ASCII for these SBCS character sets. See also -> http://blogs.msdn.com/michkap/archive/2005/11/23/495193.aspx
+ * Per discussions with richards and michkap on UNICODE alias -> ASCII range is 0x00 to 0x7F. The range of 0x00 to
+ * 0x7F of 1250-1258 and 874 are identical to ASCII for these SBCS character sets. See also ->
+ * http://blogs.msdn.com/michkap/archive/2005/11/23/495193.aspx
*/
boolean hasAsciiCompatibleSBCS() {
return hasAsciiCompatibleSBCS;
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLJdbcVersion.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLJdbcVersion.java
index 41028eb8e..824dfdf8f 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLJdbcVersion.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLJdbcVersion.java
@@ -1,16 +1,13 @@
/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc;
final class SQLJdbcVersion {
- static final int major = 6;
- static final int minor = 5;
- static final int patch = 4;
+ static final int major = 7;
+ static final int minor = 0;
+ static final int patch = 0;
static final int build = 0;
}
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerADAL4JUtils.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerADAL4JUtils.java
index a04b98296..f0418a60c 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerADAL4JUtils.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerADAL4JUtils.java
@@ -1,9 +1,6 @@
/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc;
@@ -25,37 +22,36 @@
import com.microsoft.sqlserver.jdbc.SQLServerConnection.ActiveDirectoryAuthentication;
import com.microsoft.sqlserver.jdbc.SQLServerConnection.SqlFedAuthInfo;
+
class SQLServerADAL4JUtils {
static final private java.util.logging.Logger adal4jLogger = java.util.logging.Logger
.getLogger("com.microsoft.sqlserver.jdbc.internals.SQLServerADAL4JUtils");
- static SqlFedAuthToken getSqlFedAuthToken(SqlFedAuthInfo fedAuthInfo,
- String user,
- String password,
+ static SqlFedAuthToken getSqlFedAuthToken(SqlFedAuthInfo fedAuthInfo, String user, String password,
String authenticationString) throws SQLServerException {
ExecutorService executorService = Executors.newFixedThreadPool(1);
try {
AuthenticationContext context = new AuthenticationContext(fedAuthInfo.stsurl, false, executorService);
- Future future = context.acquireToken(fedAuthInfo.spn, ActiveDirectoryAuthentication.JDBC_FEDAUTH_CLIENT_ID, user,
- password, null);
+ Future future = context.acquireToken(fedAuthInfo.spn,
+ ActiveDirectoryAuthentication.JDBC_FEDAUTH_CLIENT_ID, user, password, null);
AuthenticationResult authenticationResult = future.get();
- SqlFedAuthToken fedAuthToken = new SqlFedAuthToken(authenticationResult.getAccessToken(), authenticationResult.getExpiresOnDate());
+ SqlFedAuthToken fedAuthToken = new SqlFedAuthToken(authenticationResult.getAccessToken(),
+ authenticationResult.getExpiresOnDate());
return fedAuthToken;
- }
- catch (MalformedURLException | InterruptedException e) {
+ } catch (MalformedURLException | InterruptedException e) {
throw new SQLServerException(e.getMessage(), e);
- }
- catch (ExecutionException e) {
+ } catch (ExecutionException e) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_ADALExecution"));
Object[] msgArgs = {user, authenticationString};
// the cause error message uses \\n\\r which does not give correct format
// change it to \r\n to provide correct format
String correctedErrorMessage = e.getCause().getMessage().replaceAll("\\\\r\\\\n", "\r\n");
- AuthenticationException correctedAuthenticationException = new AuthenticationException(correctedErrorMessage);
+ AuthenticationException correctedAuthenticationException = new AuthenticationException(
+ correctedErrorMessage);
// SQLServerException is caused by ExecutionException, which is caused by
// AuthenticationException
@@ -63,8 +59,7 @@ static SqlFedAuthToken getSqlFedAuthToken(SqlFedAuthInfo fedAuthInfo,
ExecutionException correctedExecutionException = new ExecutionException(correctedAuthenticationException);
throw new SQLServerException(form.format(msgArgs), null, 0, correctedExecutionException);
- }
- finally {
+ } finally {
executorService.shutdown();
}
}
@@ -84,40 +79,39 @@ static SqlFedAuthToken getSqlFedAuthTokenIntegrated(SqlFedAuthInfo fedAuthInfo,
}
AuthenticationContext context = new AuthenticationContext(fedAuthInfo.stsurl, false, executorService);
- Future future = context.acquireToken(fedAuthInfo.spn, ActiveDirectoryAuthentication.JDBC_FEDAUTH_CLIENT_ID,
- username, null, null);
+ Future future = context.acquireToken(fedAuthInfo.spn,
+ ActiveDirectoryAuthentication.JDBC_FEDAUTH_CLIENT_ID, username, null, null);
AuthenticationResult authenticationResult = future.get();
- SqlFedAuthToken fedAuthToken = new SqlFedAuthToken(authenticationResult.getAccessToken(), authenticationResult.getExpiresOnDate());
+ SqlFedAuthToken fedAuthToken = new SqlFedAuthToken(authenticationResult.getAccessToken(),
+ authenticationResult.getExpiresOnDate());
return fedAuthToken;
- }
- catch (InterruptedException | IOException e) {
+ } catch (InterruptedException | IOException e) {
throw new SQLServerException(e.getMessage(), e);
- }
- catch (ExecutionException e) {
+ } catch (ExecutionException e) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_ADALExecution"));
Object[] msgArgs = {"", authenticationString};
if (null == e.getCause() || null == e.getCause().getMessage()) {
// the case when Future's outcome has no AuthenticationResult but exception
throw new SQLServerException(form.format(msgArgs), null);
- }
- else {
+ } else {
// the cause error message uses \\n\\r which does not give correct format
// change it to \r\n to provide correct format
String correctedErrorMessage = e.getCause().getMessage().replaceAll("\\\\r\\\\n", "\r\n");
- AuthenticationException correctedAuthenticationException = new AuthenticationException(correctedErrorMessage);
+ AuthenticationException correctedAuthenticationException = new AuthenticationException(
+ correctedErrorMessage);
// SQLServerException is caused by ExecutionException, which is caused by
// AuthenticationException
// to match the exception tree before error message correction
- ExecutionException correctedExecutionException = new ExecutionException(correctedAuthenticationException);
+ ExecutionException correctedExecutionException = new ExecutionException(
+ correctedAuthenticationException);
throw new SQLServerException(form.format(msgArgs), null, 0, correctedExecutionException);
}
- }
- finally {
+ } finally {
executorService.shutdown();
}
}
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerAeadAes256CbcHmac256Algorithm.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerAeadAes256CbcHmac256Algorithm.java
index 0f45edbec..d32d3806f 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerAeadAes256CbcHmac256Algorithm.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerAeadAes256CbcHmac256Algorithm.java
@@ -1,359 +1,353 @@
-/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
- */
-
-package com.microsoft.sqlserver.jdbc;
-
-import java.security.InvalidAlgorithmParameterException;
-import java.security.InvalidKeyException;
-import java.security.NoSuchAlgorithmException;
-import java.security.SecureRandom;
-import java.text.MessageFormat;
-
-import javax.crypto.BadPaddingException;
-import javax.crypto.Cipher;
-import javax.crypto.IllegalBlockSizeException;
-import javax.crypto.Mac;
-import javax.crypto.NoSuchPaddingException;
-import javax.crypto.ShortBufferException;
-import javax.crypto.spec.IvParameterSpec;
-import javax.crypto.spec.SecretKeySpec;
-
-/**
- *
- * This class implements authenticated encryption with associated data (AEAD_AES_256_CBC_HMAC_SHA256) algorithm specified at
- * http://tools.ietf.org/html/draft-mcgrew-aead-aes-cbc-hmac-sha2-05
- *
- */
-class SQLServerAeadAes256CbcHmac256Algorithm extends SQLServerEncryptionAlgorithm {
-
- static final private java.util.logging.Logger aeLogger = java.util.logging.Logger
- .getLogger("com.microsoft.sqlserver.jdbc.SQLServerAeadAes256CbcHmac256Algorithm");
-
- final static String algorithmName = "AEAD_AES_256_CBC_HMAC_SHA256";
- // Stores column encryption key which includes root key and derived keys
- private SQLServerAeadAes256CbcHmac256EncryptionKey columnEncryptionkey;
- private byte algorithmVersion;
- // This variable indicate whether encryption type is deterministic (if true)
- // or random (if false)
- private boolean isDeterministic = false;
- // Each block in the AES is 128 bits
- private int blockSizeInBytes = 16;
- private int keySizeInBytes = SQLServerAeadAes256CbcHmac256EncryptionKey.keySize / 8;
- private byte[] version = new byte[] {0x01};
- // Added so that java hashing algorithm is similar to c#
- private byte[] versionSize = new byte[] {1};
-
- /*
- * Minimum Length of cipherText without authentication tag. This value is 1 (version byte) + 16 (IV) + 16 (minimum of 1 block of cipher Text)
- */
- private int minimumCipherTextLengthInBytesNoAuthenticationTag = 1 + blockSizeInBytes + blockSizeInBytes;
-
- /*
- * Minimum Length of cipherText. This value is 1 (version byte) + 32 (authentication tag) + 16 (IV) + 16 (minimum of 1 block of cipher Text)
- */
- private int minimumCipherTextLengthInBytesWithAuthenticationTag = minimumCipherTextLengthInBytesNoAuthenticationTag + keySizeInBytes;
-
- /**
- * Initializes a new instance of SQLServerAeadAes256CbcHmac256Algorithm with a given key, encryption type and algorithm version
- *
- * @param columnEncryptionkey
- * Root encryption key from which three other keys will be derived
- * @param encryptionType
- * Encryption Type, accepted values are Deterministic and Randomized.
- * @param algorithmVersion
- * Algorithm version
- */
- SQLServerAeadAes256CbcHmac256Algorithm(SQLServerAeadAes256CbcHmac256EncryptionKey columnEncryptionkey,
- SQLServerEncryptionType encryptionType,
- byte algorithmVersion) {
- this.columnEncryptionkey = columnEncryptionkey;
-
- if (encryptionType == SQLServerEncryptionType.Deterministic) {
- this.isDeterministic = true;
- }
- this.algorithmVersion = algorithmVersion;
- version[0] = algorithmVersion;
- }
-
- @Override
- byte[] encryptData(byte[] plainText) throws SQLServerException {
- // hasAuthenticationTag is true for this algorithm
- return encryptData(plainText, true);
- }
-
- /**
- * Performs encryption of plain text
- *
- * @param plainText
- * text to be encrypted
- * @param hasAuthenticationTag
- * specify if encryption needs authentication
- * @return cipher text
- * @throws SQLServerException
- */
- protected byte[] encryptData(byte[] plainText,
- boolean hasAuthenticationTag) throws SQLServerException {
- aeLogger.entering(SQLServerAeadAes256CbcHmac256Algorithm.class.getName(), Thread.currentThread().getStackTrace()[1].getMethodName(),
- "Encrypting data.");
- // we will generate this initialization vector based whether
- // this encryption type is deterministic
- assert (plainText != null);
- byte[] iv = new byte[blockSizeInBytes];
- // Secret/private key to be used in AES encryption
- SecretKeySpec skeySpec = new SecretKeySpec(columnEncryptionkey.getEncryptionKey(), "AES");
-
- if (isDeterministic) {
- // this method makes sure this is 16 bytes key
- try {
- iv = SQLServerSecurityUtility.getHMACWithSHA256(plainText, columnEncryptionkey.getIVKey(), blockSizeInBytes);
- }
- catch (InvalidKeyException | NoSuchAlgorithmException e) {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_EncryptionFailed"));
- Object[] msgArgs = {e.getMessage()};
- throw new SQLServerException(this, form.format(msgArgs), null, 0, false);
- }
- }
- else {
- SecureRandom random = new SecureRandom();
- random.nextBytes(iv);
- }
-
- int numBlocks = plainText.length / blockSizeInBytes + 1;
-
- int hmacStartIndex = 1;
- int authenticationTagLen = hasAuthenticationTag ? keySizeInBytes : 0;
- int ivStartIndex = hmacStartIndex + authenticationTagLen;
- int cipherStartIndex = ivStartIndex + blockSizeInBytes;
-
- // Output buffer size = size of VersionByte + Authentication Tag + IV + cipher Text blocks.
- int outputBufSize = 1 + authenticationTagLen + iv.length + (numBlocks * blockSizeInBytes);
- byte[] outBuffer = new byte[outputBufSize];
-
- // Copying the version to output buffer
- outBuffer[0] = algorithmVersion;
- // Coping IV to the output buffer
- System.arraycopy(iv, 0, outBuffer, ivStartIndex, iv.length);
-
- // Start the AES encryption
-
- try {
- // initialization vector
- IvParameterSpec ivector = new IvParameterSpec(iv);
- Cipher encryptCipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
- encryptCipher.init(Cipher.ENCRYPT_MODE, skeySpec, ivector);
-
- int count = 0;
- int cipherIndex = cipherStartIndex; // this is where cipherText starts
-
- if (numBlocks > 1) {
- count = (numBlocks - 1) * blockSizeInBytes;
- cipherIndex += encryptCipher.update(plainText, 0, count, outBuffer, cipherIndex);
- }
- // doFinal will complete the encryption
- byte[] buffTmp = encryptCipher.doFinal(plainText, count, plainText.length - count);
- // Encryption completed
- System.arraycopy(buffTmp, 0, outBuffer, cipherIndex, buffTmp.length);
-
- if (hasAuthenticationTag) {
-
- Mac hmac = Mac.getInstance("HmacSHA256");
- SecretKeySpec initkey = new SecretKeySpec(columnEncryptionkey.getMacKey(), "HmacSHA256");
- hmac.init(initkey);
- hmac.update(version, 0, version.length);
- hmac.update(iv, 0, iv.length);
- hmac.update(outBuffer, cipherStartIndex, numBlocks * blockSizeInBytes);
- hmac.update(versionSize, 0, version.length);
- byte[] hash = hmac.doFinal();
- // coping the authentication tag in the output buffer which holds cipher text
- System.arraycopy(hash, 0, outBuffer, hmacStartIndex, authenticationTagLen);
-
- }
- }
- catch (NoSuchAlgorithmException | InvalidAlgorithmParameterException | InvalidKeyException | NoSuchPaddingException
- | IllegalBlockSizeException | BadPaddingException | ShortBufferException e) {
-
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_EncryptionFailed"));
- Object[] msgArgs = {e.getMessage()};
- throw new SQLServerException(this, form.format(msgArgs), null, 0, false);
- }
-
- aeLogger.exiting(SQLServerAeadAes256CbcHmac256Algorithm.class.getName(), Thread.currentThread().getStackTrace()[1].getMethodName(),
- "Data encrypted.");
- return outBuffer;
-
- }
-
- @Override
- byte[] decryptData(byte[] cipherText) throws SQLServerException {
- return decryptData(cipherText, true);
-
- }
-
- /**
- * Decrypt the cipher text and return plain text
- *
- * @param cipherText
- * data to be decrypted
- * @param hasAuthenticationTag
- * tells whether cipher text contain authentication tag
- * @return plain text
- * @throws SQLServerException
- */
- private byte[] decryptData(byte[] cipherText,
- boolean hasAuthenticationTag) throws SQLServerException {
- assert (cipherText != null);
-
- byte[] iv = new byte[blockSizeInBytes];
-
- int minimumCipherTextLength = hasAuthenticationTag ? minimumCipherTextLengthInBytesWithAuthenticationTag
- : minimumCipherTextLengthInBytesNoAuthenticationTag;
-
- // Here we check if length of cipher text is more than minimum value,
- // if not exception is thrown
- if (cipherText.length < minimumCipherTextLength) {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_InvalidCipherTextSize"));
- Object[] msgArgs = {cipherText.length, minimumCipherTextLength};
- throw new SQLServerException(this, form.format(msgArgs), null, 0, false);
-
- }
-
- // Validate the version byte
- int startIndex = 0;
- if (cipherText[startIndex] != algorithmVersion) {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_InvalidAlgorithmVersion"));
- // converting byte to Hexa Decimal
- Object[] msgArgs = {String.format("%02X ", cipherText[startIndex]), String.format("%02X ", algorithmVersion)};
- throw new SQLServerException(this, form.format(msgArgs), null, 0, false);
-
- }
-
- startIndex += 1;
- int authenticationTagOffset = 0;
-
- // Read authentication tag
- if (hasAuthenticationTag) {
- authenticationTagOffset = startIndex;
- // authentication tag size is keySizeInBytes
- startIndex += keySizeInBytes;
- }
-
- // Read IV from cipher text
- System.arraycopy(cipherText, startIndex, iv, 0, iv.length);
- startIndex += iv.length;
-
- // To read encrypted text from cipher
- int cipherTextOffset = startIndex;
- // All data after IV is encrypted data
- int cipherTextCount = cipherText.length - startIndex;
-
- if (hasAuthenticationTag) {
- byte[] authenticationTag;
- try {
- authenticationTag = prepareAuthenticationTag(iv, cipherText, cipherTextOffset, cipherTextCount);
- }
- catch (InvalidKeyException | NoSuchAlgorithmException e) {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_DecryptionFailed"));
- Object[] msgArgs = {e.getMessage()};
- throw new SQLServerException(this, form.format(msgArgs), null, 0, false);
-
- }
- if (!(SQLServerSecurityUtility.compareBytes(authenticationTag, cipherText, authenticationTagOffset, cipherTextCount))) {
-
- throw new SQLServerException(this, SQLServerException.getErrString("R_InvalidAuthenticationTag"), null, 0, false);
-
- }
-
- }
-
- // Decrypt the text and return
- return decryptData(iv, cipherText, cipherTextOffset, cipherTextCount);
- }
-
- /**
- * Decrypt data with specified IV
- *
- * @param iv
- * initialization vector
- * @param cipherText
- * text to be decrypted
- * @param offset
- * of cipher text
- * @param count
- * length of cipher text
- * @return plain text
- * @throws SQLServerException
- */
- private byte[] decryptData(byte[] iv,
- byte[] cipherText,
- int offset,
- int count) throws SQLServerException {
- aeLogger.entering(SQLServerAeadAes256CbcHmac256Algorithm.class.getName(), Thread.currentThread().getStackTrace()[1].getMethodName(),
- "Decrypting data.");
- assert (cipherText != null);
- assert (iv != null);
- byte[] plainText = null;
- // key to be used for decryption
- SecretKeySpec skeySpec = new SecretKeySpec(columnEncryptionkey.getEncryptionKey(), "AES");
- IvParameterSpec ivector = new IvParameterSpec(iv);
- Cipher decryptCipher;
- try {
- // AES encryption CBC mode and PKCS5 padding
- decryptCipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
- decryptCipher.init(Cipher.DECRYPT_MODE, skeySpec, ivector);
- plainText = decryptCipher.doFinal(cipherText, offset, count);
- }
- catch (NoSuchAlgorithmException | InvalidAlgorithmParameterException | InvalidKeyException | NoSuchPaddingException
- | IllegalBlockSizeException | BadPaddingException e) {
-
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_DecryptionFailed"));
- Object[] msgArgs = {e.getMessage()};
- throw new SQLServerException(this, form.format(msgArgs), null, 0, false);
- }
-
- aeLogger.exiting(SQLServerAeadAes256CbcHmac256Algorithm.class.getName(), Thread.currentThread().getStackTrace()[1].getMethodName(),
- "Data decrypted.");
- return plainText;
-
- }
-
- /**
- * Prepare the authentication tag
- *
- * @param iv
- * initialization vector
- * @param cipherText
- * @param offset
- * @param length
- * length of cipher text
- * @return authentication tag
- * @throws NoSuchAlgorithmException
- * @throws InvalidKeyException
- */
- private byte[] prepareAuthenticationTag(byte[] iv,
- byte[] cipherText,
- int offset,
- int length) throws NoSuchAlgorithmException, InvalidKeyException {
- assert (cipherText != null);
- byte[] computedHash;
- byte[] authenticationTag = new byte[keySizeInBytes];
-
- Mac hmac = Mac.getInstance("HmacSHA256");
- SecretKeySpec key = new SecretKeySpec(columnEncryptionkey.getMacKey(), "HmacSHA256");
- hmac.init(key);
- hmac.update(version, 0, version.length);
- hmac.update(iv, 0, iv.length);
- hmac.update(cipherText, offset, length);
- hmac.update(versionSize, 0, version.length);
- computedHash = hmac.doFinal();
- System.arraycopy(computedHash, 0, authenticationTag, 0, authenticationTag.length);
-
- return authenticationTag;
-
- }
-
-}
+/*
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ */
+
+package com.microsoft.sqlserver.jdbc;
+
+import java.security.InvalidAlgorithmParameterException;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.security.SecureRandom;
+import java.text.MessageFormat;
+
+import javax.crypto.BadPaddingException;
+import javax.crypto.Cipher;
+import javax.crypto.IllegalBlockSizeException;
+import javax.crypto.Mac;
+import javax.crypto.NoSuchPaddingException;
+import javax.crypto.ShortBufferException;
+import javax.crypto.spec.IvParameterSpec;
+import javax.crypto.spec.SecretKeySpec;
+
+
+/**
+ *
+ * This class implements authenticated encryption with associated data (AEAD_AES_256_CBC_HMAC_SHA256) algorithm
+ * specified at
+ * http://tools.ietf.org/html/draft-mcgrew-aead-aes-cbc-hmac-sha2-05
+ *
+ */
+class SQLServerAeadAes256CbcHmac256Algorithm extends SQLServerEncryptionAlgorithm {
+
+ static final private java.util.logging.Logger aeLogger = java.util.logging.Logger
+ .getLogger("com.microsoft.sqlserver.jdbc.SQLServerAeadAes256CbcHmac256Algorithm");
+
+ final static String algorithmName = "AEAD_AES_256_CBC_HMAC_SHA256";
+ // Stores column encryption key which includes root key and derived keys
+ private SQLServerAeadAes256CbcHmac256EncryptionKey columnEncryptionkey;
+ private byte algorithmVersion;
+ // This variable indicate whether encryption type is deterministic (if true)
+ // or random (if false)
+ private boolean isDeterministic = false;
+ // Each block in the AES is 128 bits
+ private int blockSizeInBytes = 16;
+ private int keySizeInBytes = SQLServerAeadAes256CbcHmac256EncryptionKey.keySize / 8;
+ private byte[] version = new byte[] {0x01};
+ // Added so that java hashing algorithm is similar to c#
+ private byte[] versionSize = new byte[] {1};
+
+ /*
+ * Minimum Length of cipherText without authentication tag. This value is 1 (version byte) + 16 (IV) + 16 (minimum
+ * of 1 block of cipher Text)
+ */
+ private int minimumCipherTextLengthInBytesNoAuthenticationTag = 1 + blockSizeInBytes + blockSizeInBytes;
+
+ /*
+ * Minimum Length of cipherText. This value is 1 (version byte) + 32 (authentication tag) + 16 (IV) + 16 (minimum of
+ * 1 block of cipher Text)
+ */
+ private int minimumCipherTextLengthInBytesWithAuthenticationTag = minimumCipherTextLengthInBytesNoAuthenticationTag
+ + keySizeInBytes;
+
+ /**
+ * Initializes a new instance of SQLServerAeadAes256CbcHmac256Algorithm with a given key, encryption type and
+ * algorithm version
+ *
+ * @param columnEncryptionkey
+ * Root encryption key from which three other keys will be derived
+ * @param encryptionType
+ * Encryption Type, accepted values are Deterministic and Randomized.
+ * @param algorithmVersion
+ * Algorithm version
+ */
+ SQLServerAeadAes256CbcHmac256Algorithm(SQLServerAeadAes256CbcHmac256EncryptionKey columnEncryptionkey,
+ SQLServerEncryptionType encryptionType, byte algorithmVersion) {
+ this.columnEncryptionkey = columnEncryptionkey;
+
+ if (encryptionType == SQLServerEncryptionType.Deterministic) {
+ this.isDeterministic = true;
+ }
+ this.algorithmVersion = algorithmVersion;
+ version[0] = algorithmVersion;
+ }
+
+ @Override
+ byte[] encryptData(byte[] plainText) throws SQLServerException {
+ // hasAuthenticationTag is true for this algorithm
+ return encryptData(plainText, true);
+ }
+
+ /**
+ * Performs encryption of plain text
+ *
+ * @param plainText
+ * text to be encrypted
+ * @param hasAuthenticationTag
+ * specify if encryption needs authentication
+ * @return cipher text
+ * @throws SQLServerException
+ */
+ protected byte[] encryptData(byte[] plainText, boolean hasAuthenticationTag) throws SQLServerException {
+ aeLogger.entering(SQLServerAeadAes256CbcHmac256Algorithm.class.getName(),
+ Thread.currentThread().getStackTrace()[1].getMethodName(), "Encrypting data.");
+ // we will generate this initialization vector based whether
+ // this encryption type is deterministic
+ assert (plainText != null);
+ byte[] iv = new byte[blockSizeInBytes];
+ // Secret/private key to be used in AES encryption
+ SecretKeySpec skeySpec = new SecretKeySpec(columnEncryptionkey.getEncryptionKey(), "AES");
+
+ if (isDeterministic) {
+ // this method makes sure this is 16 bytes key
+ try {
+ iv = SQLServerSecurityUtility.getHMACWithSHA256(plainText, columnEncryptionkey.getIVKey(),
+ blockSizeInBytes);
+ } catch (InvalidKeyException | NoSuchAlgorithmException e) {
+ MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_EncryptionFailed"));
+ Object[] msgArgs = {e.getMessage()};
+ throw new SQLServerException(this, form.format(msgArgs), null, 0, false);
+ }
+ } else {
+ SecureRandom random = new SecureRandom();
+ random.nextBytes(iv);
+ }
+
+ int numBlocks = plainText.length / blockSizeInBytes + 1;
+
+ int hmacStartIndex = 1;
+ int authenticationTagLen = hasAuthenticationTag ? keySizeInBytes : 0;
+ int ivStartIndex = hmacStartIndex + authenticationTagLen;
+ int cipherStartIndex = ivStartIndex + blockSizeInBytes;
+
+ // Output buffer size = size of VersionByte + Authentication Tag + IV + cipher Text blocks.
+ int outputBufSize = 1 + authenticationTagLen + iv.length + (numBlocks * blockSizeInBytes);
+ byte[] outBuffer = new byte[outputBufSize];
+
+ // Copying the version to output buffer
+ outBuffer[0] = algorithmVersion;
+ // Coping IV to the output buffer
+ System.arraycopy(iv, 0, outBuffer, ivStartIndex, iv.length);
+
+ // Start the AES encryption
+
+ try {
+ // initialization vector
+ IvParameterSpec ivector = new IvParameterSpec(iv);
+ Cipher encryptCipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
+ encryptCipher.init(Cipher.ENCRYPT_MODE, skeySpec, ivector);
+
+ int count = 0;
+ int cipherIndex = cipherStartIndex; // this is where cipherText starts
+
+ if (numBlocks > 1) {
+ count = (numBlocks - 1) * blockSizeInBytes;
+ cipherIndex += encryptCipher.update(plainText, 0, count, outBuffer, cipherIndex);
+ }
+ // doFinal will complete the encryption
+ byte[] buffTmp = encryptCipher.doFinal(plainText, count, plainText.length - count);
+ // Encryption completed
+ System.arraycopy(buffTmp, 0, outBuffer, cipherIndex, buffTmp.length);
+
+ if (hasAuthenticationTag) {
+
+ Mac hmac = Mac.getInstance("HmacSHA256");
+ SecretKeySpec initkey = new SecretKeySpec(columnEncryptionkey.getMacKey(), "HmacSHA256");
+ hmac.init(initkey);
+ hmac.update(version, 0, version.length);
+ hmac.update(iv, 0, iv.length);
+ hmac.update(outBuffer, cipherStartIndex, numBlocks * blockSizeInBytes);
+ hmac.update(versionSize, 0, version.length);
+ byte[] hash = hmac.doFinal();
+ // coping the authentication tag in the output buffer which holds cipher text
+ System.arraycopy(hash, 0, outBuffer, hmacStartIndex, authenticationTagLen);
+
+ }
+ } catch (NoSuchAlgorithmException | InvalidAlgorithmParameterException | InvalidKeyException
+ | NoSuchPaddingException | IllegalBlockSizeException | BadPaddingException | ShortBufferException e) {
+
+ MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_EncryptionFailed"));
+ Object[] msgArgs = {e.getMessage()};
+ throw new SQLServerException(this, form.format(msgArgs), null, 0, false);
+ }
+
+ aeLogger.exiting(SQLServerAeadAes256CbcHmac256Algorithm.class.getName(),
+ Thread.currentThread().getStackTrace()[1].getMethodName(), "Data encrypted.");
+ return outBuffer;
+
+ }
+
+ @Override
+ byte[] decryptData(byte[] cipherText) throws SQLServerException {
+ return decryptData(cipherText, true);
+
+ }
+
+ /**
+ * Decrypt the cipher text and return plain text
+ *
+ * @param cipherText
+ * data to be decrypted
+ * @param hasAuthenticationTag
+ * tells whether cipher text contain authentication tag
+ * @return plain text
+ * @throws SQLServerException
+ */
+ private byte[] decryptData(byte[] cipherText, boolean hasAuthenticationTag) throws SQLServerException {
+ assert (cipherText != null);
+
+ byte[] iv = new byte[blockSizeInBytes];
+
+ int minimumCipherTextLength = hasAuthenticationTag ? minimumCipherTextLengthInBytesWithAuthenticationTag
+ : minimumCipherTextLengthInBytesNoAuthenticationTag;
+
+ // Here we check if length of cipher text is more than minimum value,
+ // if not exception is thrown
+ if (cipherText.length < minimumCipherTextLength) {
+ MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_InvalidCipherTextSize"));
+ Object[] msgArgs = {cipherText.length, minimumCipherTextLength};
+ throw new SQLServerException(this, form.format(msgArgs), null, 0, false);
+
+ }
+
+ // Validate the version byte
+ int startIndex = 0;
+ if (cipherText[startIndex] != algorithmVersion) {
+ MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_InvalidAlgorithmVersion"));
+ // converting byte to Hexa Decimal
+ Object[] msgArgs = {String.format("%02X ", cipherText[startIndex]),
+ String.format("%02X ", algorithmVersion)};
+ throw new SQLServerException(this, form.format(msgArgs), null, 0, false);
+
+ }
+
+ startIndex += 1;
+ int authenticationTagOffset = 0;
+
+ // Read authentication tag
+ if (hasAuthenticationTag) {
+ authenticationTagOffset = startIndex;
+ // authentication tag size is keySizeInBytes
+ startIndex += keySizeInBytes;
+ }
+
+ // Read IV from cipher text
+ System.arraycopy(cipherText, startIndex, iv, 0, iv.length);
+ startIndex += iv.length;
+
+ // To read encrypted text from cipher
+ int cipherTextOffset = startIndex;
+ // All data after IV is encrypted data
+ int cipherTextCount = cipherText.length - startIndex;
+
+ if (hasAuthenticationTag) {
+ byte[] authenticationTag;
+ try {
+ authenticationTag = prepareAuthenticationTag(iv, cipherText, cipherTextOffset, cipherTextCount);
+ } catch (InvalidKeyException | NoSuchAlgorithmException e) {
+ MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_DecryptionFailed"));
+ Object[] msgArgs = {e.getMessage()};
+ throw new SQLServerException(this, form.format(msgArgs), null, 0, false);
+
+ }
+ if (!(SQLServerSecurityUtility.compareBytes(authenticationTag, cipherText, authenticationTagOffset,
+ cipherTextCount))) {
+
+ throw new SQLServerException(this, SQLServerException.getErrString("R_InvalidAuthenticationTag"), null,
+ 0, false);
+
+ }
+
+ }
+
+ // Decrypt the text and return
+ return decryptData(iv, cipherText, cipherTextOffset, cipherTextCount);
+ }
+
+ /**
+ * Decrypt data with specified IV
+ *
+ * @param iv
+ * initialization vector
+ * @param cipherText
+ * text to be decrypted
+ * @param offset
+ * of cipher text
+ * @param count
+ * length of cipher text
+ * @return plain text
+ * @throws SQLServerException
+ */
+ private byte[] decryptData(byte[] iv, byte[] cipherText, int offset, int count) throws SQLServerException {
+ aeLogger.entering(SQLServerAeadAes256CbcHmac256Algorithm.class.getName(),
+ Thread.currentThread().getStackTrace()[1].getMethodName(), "Decrypting data.");
+ assert (cipherText != null);
+ assert (iv != null);
+ byte[] plainText = null;
+ // key to be used for decryption
+ SecretKeySpec skeySpec = new SecretKeySpec(columnEncryptionkey.getEncryptionKey(), "AES");
+ IvParameterSpec ivector = new IvParameterSpec(iv);
+ Cipher decryptCipher;
+ try {
+ // AES encryption CBC mode and PKCS5 padding
+ decryptCipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
+ decryptCipher.init(Cipher.DECRYPT_MODE, skeySpec, ivector);
+ plainText = decryptCipher.doFinal(cipherText, offset, count);
+ } catch (NoSuchAlgorithmException | InvalidAlgorithmParameterException | InvalidKeyException
+ | NoSuchPaddingException | IllegalBlockSizeException | BadPaddingException e) {
+
+ MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_DecryptionFailed"));
+ Object[] msgArgs = {e.getMessage()};
+ throw new SQLServerException(this, form.format(msgArgs), null, 0, false);
+ }
+
+ aeLogger.exiting(SQLServerAeadAes256CbcHmac256Algorithm.class.getName(),
+ Thread.currentThread().getStackTrace()[1].getMethodName(), "Data decrypted.");
+ return plainText;
+
+ }
+
+ /**
+ * Prepare the authentication tag
+ *
+ * @param iv
+ * initialization vector
+ * @param cipherText
+ * @param offset
+ * @param length
+ * length of cipher text
+ * @return authentication tag
+ * @throws NoSuchAlgorithmException
+ * @throws InvalidKeyException
+ */
+ private byte[] prepareAuthenticationTag(byte[] iv, byte[] cipherText, int offset,
+ int length) throws NoSuchAlgorithmException, InvalidKeyException {
+ assert (cipherText != null);
+ byte[] computedHash;
+ byte[] authenticationTag = new byte[keySizeInBytes];
+
+ Mac hmac = Mac.getInstance("HmacSHA256");
+ SecretKeySpec key = new SecretKeySpec(columnEncryptionkey.getMacKey(), "HmacSHA256");
+ hmac.init(key);
+ hmac.update(version, 0, version.length);
+ hmac.update(iv, 0, iv.length);
+ hmac.update(cipherText, offset, length);
+ hmac.update(versionSize, 0, version.length);
+ computedHash = hmac.doFinal();
+ System.arraycopy(computedHash, 0, authenticationTag, 0, authenticationTag.length);
+
+ return authenticationTag;
+
+ }
+
+}
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerAeadAes256CbcHmac256EncryptionKey.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerAeadAes256CbcHmac256EncryptionKey.java
index b2e6826ab..b1a8c5853 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerAeadAes256CbcHmac256EncryptionKey.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerAeadAes256CbcHmac256EncryptionKey.java
@@ -1,116 +1,118 @@
-/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
- */
-
-package com.microsoft.sqlserver.jdbc;
-
-import static java.nio.charset.StandardCharsets.UTF_16LE;
-
-import java.security.InvalidKeyException;
-import java.security.NoSuchAlgorithmException;
-import java.text.MessageFormat;
-
-/**
- * Encryption key class which consist of following 4 keys : 1) root key - Main key which is used to derive following keys 2) encryption key - A
- * derived key that is used to encrypt the plain text and generate cipher text 3) mac_key - A derived key that is used to compute HMAC of the cipher
- * text 4) iv_key - A derived key that is used to generate a synthetic IV from plain text data.
- */
-class SQLServerAeadAes256CbcHmac256EncryptionKey extends SQLServerSymmetricKey {
-
- // This is the key size in the bits, since we are using AES256, it will 256
- static final int keySize = 256;
- // Name of algorithm associated with this key
- private final String algorithmName;
- // Salt used to derive encryption key
- private String encryptionKeySaltFormat;
- // Salt used to derive mac key
- private String macKeySaltFormat;
- // Salt used to derive iv key
- private String ivKeySaltFormat;
- private SQLServerSymmetricKey encryptionKey;
- private SQLServerSymmetricKey macKey;
- private SQLServerSymmetricKey ivKey;
-
- /**
- * Derive all the keys from the root key
- *
- * @param rootKey
- * key used to derive other keys
- * @param algorithmName
- * name of the algorithm associated with keys
- * @throws SQLServerException
- */
- SQLServerAeadAes256CbcHmac256EncryptionKey(byte[] rootKey,
- String algorithmName) throws SQLServerException {
- super(rootKey);
- this.algorithmName = algorithmName;
- encryptionKeySaltFormat = "Microsoft SQL Server cell encryption key with encryption algorithm:" + this.algorithmName + " and key length:"
- + keySize;
- macKeySaltFormat = "Microsoft SQL Server cell MAC key with encryption algorithm:" + this.algorithmName + " and key length:" + keySize;
- ivKeySaltFormat = "Microsoft SQL Server cell IV key with encryption algorithm:" + this.algorithmName + " and key length:" + keySize;
- int keySizeInBytes = (keySize / 8);
- if (rootKey.length != keySizeInBytes) {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_InvalidKeySize"));
- Object[] msgArgs = {rootKey.length, keySizeInBytes, this.algorithmName};
- throw new SQLServerException(this, form.format(msgArgs), null, 0, false);
-
- }
-
- // Derive encryption key
-
- byte[] encKeyBuff = new byte[keySizeInBytes];
- try {
- // By default Java is big endian, we are getting bytes in little endian(LE in UTF-16LE)
- // to make it compatible with C# driver which is little endian
- encKeyBuff = SQLServerSecurityUtility.getHMACWithSHA256(encryptionKeySaltFormat.getBytes(UTF_16LE), rootKey, encKeyBuff.length);
-
- encryptionKey = new SQLServerSymmetricKey(encKeyBuff);
-
- // Derive mac key from root key
- byte[] macKeyBuff = new byte[keySizeInBytes];
- macKeyBuff = SQLServerSecurityUtility.getHMACWithSHA256(macKeySaltFormat.getBytes(UTF_16LE), rootKey, macKeyBuff.length);
-
- macKey = new SQLServerSymmetricKey(macKeyBuff);
-
- // Derive the initialization vector from root key
- byte[] ivKeyBuff = new byte[keySizeInBytes];
- ivKeyBuff = SQLServerSecurityUtility.getHMACWithSHA256(ivKeySaltFormat.getBytes(UTF_16LE), rootKey, ivKeyBuff.length);
- ivKey = new SQLServerSymmetricKey(ivKeyBuff);
- }
- catch (InvalidKeyException | NoSuchAlgorithmException e) {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_KeyExtractionFailed"));
- Object[] msgArgs = {e.getMessage()};
- throw new SQLServerException(this, form.format(msgArgs), null, 0, false);
- }
-
- }
-
- /**
- *
- * @return encryption key
- */
- byte[] getEncryptionKey() {
- return encryptionKey.getRootKey();
- }
-
- /**
- *
- * @return mac key
- */
- byte[] getMacKey() {
- return macKey.getRootKey();
- }
-
- /**
- *
- * @return iv key
- */
- byte[] getIVKey() {
- return ivKey.getRootKey();
- }
-
-}
+/*
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ */
+
+package com.microsoft.sqlserver.jdbc;
+
+import static java.nio.charset.StandardCharsets.UTF_16LE;
+
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.text.MessageFormat;
+
+
+/**
+ * Encryption key class which consist of following 4 keys : 1) root key - Main key which is used to derive following
+ * keys 2) encryption key - A derived key that is used to encrypt the plain text and generate cipher text 3) mac_key - A
+ * derived key that is used to compute HMAC of the cipher text 4) iv_key - A derived key that is used to generate a
+ * synthetic IV from plain text data.
+ */
+class SQLServerAeadAes256CbcHmac256EncryptionKey extends SQLServerSymmetricKey {
+
+ // This is the key size in the bits, since we are using AES256, it will 256
+ static final int keySize = 256;
+ // Name of algorithm associated with this key
+ private final String algorithmName;
+ // Salt used to derive encryption key
+ private String encryptionKeySaltFormat;
+ // Salt used to derive mac key
+ private String macKeySaltFormat;
+ // Salt used to derive iv key
+ private String ivKeySaltFormat;
+ private SQLServerSymmetricKey encryptionKey;
+ private SQLServerSymmetricKey macKey;
+ private SQLServerSymmetricKey ivKey;
+
+ /**
+ * Derive all the keys from the root key
+ *
+ * @param rootKey
+ * key used to derive other keys
+ * @param algorithmName
+ * name of the algorithm associated with keys
+ * @throws SQLServerException
+ */
+ SQLServerAeadAes256CbcHmac256EncryptionKey(byte[] rootKey, String algorithmName) throws SQLServerException {
+ super(rootKey);
+ this.algorithmName = algorithmName;
+ encryptionKeySaltFormat = "Microsoft SQL Server cell encryption key with encryption algorithm:"
+ + this.algorithmName + " and key length:" + keySize;
+ macKeySaltFormat = "Microsoft SQL Server cell MAC key with encryption algorithm:" + this.algorithmName
+ + " and key length:" + keySize;
+ ivKeySaltFormat = "Microsoft SQL Server cell IV key with encryption algorithm:" + this.algorithmName
+ + " and key length:" + keySize;
+ int keySizeInBytes = (keySize / 8);
+ if (rootKey.length != keySizeInBytes) {
+ MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_InvalidKeySize"));
+ Object[] msgArgs = {rootKey.length, keySizeInBytes, this.algorithmName};
+ throw new SQLServerException(this, form.format(msgArgs), null, 0, false);
+
+ }
+
+ // Derive encryption key
+
+ byte[] encKeyBuff = new byte[keySizeInBytes];
+ try {
+ // By default Java is big endian, we are getting bytes in little endian(LE in UTF-16LE)
+ // to make it compatible with C# driver which is little endian
+ encKeyBuff = SQLServerSecurityUtility.getHMACWithSHA256(encryptionKeySaltFormat.getBytes(UTF_16LE), rootKey,
+ encKeyBuff.length);
+
+ encryptionKey = new SQLServerSymmetricKey(encKeyBuff);
+
+ // Derive mac key from root key
+ byte[] macKeyBuff = new byte[keySizeInBytes];
+ macKeyBuff = SQLServerSecurityUtility.getHMACWithSHA256(macKeySaltFormat.getBytes(UTF_16LE), rootKey,
+ macKeyBuff.length);
+
+ macKey = new SQLServerSymmetricKey(macKeyBuff);
+
+ // Derive the initialization vector from root key
+ byte[] ivKeyBuff = new byte[keySizeInBytes];
+ ivKeyBuff = SQLServerSecurityUtility.getHMACWithSHA256(ivKeySaltFormat.getBytes(UTF_16LE), rootKey,
+ ivKeyBuff.length);
+ ivKey = new SQLServerSymmetricKey(ivKeyBuff);
+ } catch (InvalidKeyException | NoSuchAlgorithmException e) {
+ MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_KeyExtractionFailed"));
+ Object[] msgArgs = {e.getMessage()};
+ throw new SQLServerException(this, form.format(msgArgs), null, 0, false);
+ }
+
+ }
+
+ /**
+ *
+ * @return encryption key
+ */
+ byte[] getEncryptionKey() {
+ return encryptionKey.getRootKey();
+ }
+
+ /**
+ *
+ * @return mac key
+ */
+ byte[] getMacKey() {
+ return macKey.getRootKey();
+ }
+
+ /**
+ *
+ * @return iv key
+ */
+ byte[] getIVKey() {
+ return ivKey.getRootKey();
+ }
+
+}
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerAeadAes256CbcHmac256Factory.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerAeadAes256CbcHmac256Factory.java
index 3a170da2d..58f5af235 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerAeadAes256CbcHmac256Factory.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerAeadAes256CbcHmac256Factory.java
@@ -1,61 +1,60 @@
-/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
- */
-
-package com.microsoft.sqlserver.jdbc;
-
-import static java.nio.charset.StandardCharsets.UTF_8;
-
-import java.text.MessageFormat;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.Base64;
-
-/**
- * Factory for SQLServerAeadAes256CbcHmac256Algorithm
- */
-class SQLServerAeadAes256CbcHmac256Factory extends SQLServerEncryptionAlgorithmFactory {
- // In future we can have more
- private byte algorithmVersion = 0x1;
- private ConcurrentHashMap encryptionAlgorithms = new ConcurrentHashMap<>();
-
- @Override
- SQLServerEncryptionAlgorithm create(SQLServerSymmetricKey columnEncryptionKey,
- SQLServerEncryptionType encryptionType,
- String encryptionAlgorithm) throws SQLServerException {
-
- assert (columnEncryptionKey != null);
- if (encryptionType != SQLServerEncryptionType.Deterministic && encryptionType != SQLServerEncryptionType.Randomized) {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_InvalidEncryptionType"));
- Object[] msgArgs = {encryptionType, encryptionAlgorithm,
- "'" + SQLServerEncryptionType.Deterministic + "," + SQLServerEncryptionType.Randomized + "'"};
- throw new SQLServerException(this, form.format(msgArgs), null, 0, false);
-
- }
-
- StringBuilder factoryKeyBuilder = new StringBuilder();
- factoryKeyBuilder.append(Base64.getEncoder().encodeToString(new String(columnEncryptionKey.getRootKey(), UTF_8).getBytes()));
-
- factoryKeyBuilder.append(":");
- factoryKeyBuilder.append(encryptionType);
- factoryKeyBuilder.append(":");
- factoryKeyBuilder.append(algorithmVersion);
-
- String factoryKey = factoryKeyBuilder.toString();
-
- SQLServerAeadAes256CbcHmac256Algorithm aesAlgorithm;
-
- if (!encryptionAlgorithms.containsKey(factoryKey)) {
- SQLServerAeadAes256CbcHmac256EncryptionKey encryptedKey = new SQLServerAeadAes256CbcHmac256EncryptionKey(columnEncryptionKey.getRootKey(),
- SQLServerAeadAes256CbcHmac256Algorithm.algorithmName);
- aesAlgorithm = new SQLServerAeadAes256CbcHmac256Algorithm(encryptedKey, encryptionType, algorithmVersion);
- encryptionAlgorithms.putIfAbsent(factoryKey, aesAlgorithm);
- }
-
- return encryptionAlgorithms.get(factoryKey);
- }
-
-}
+/*
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ */
+
+package com.microsoft.sqlserver.jdbc;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+
+import java.text.MessageFormat;
+import java.util.Base64;
+import java.util.concurrent.ConcurrentHashMap;
+
+
+/**
+ * Factory for SQLServerAeadAes256CbcHmac256Algorithm
+ */
+class SQLServerAeadAes256CbcHmac256Factory extends SQLServerEncryptionAlgorithmFactory {
+ // In future we can have more
+ private byte algorithmVersion = 0x1;
+ private ConcurrentHashMap encryptionAlgorithms = new ConcurrentHashMap<>();
+
+ @Override
+ SQLServerEncryptionAlgorithm create(SQLServerSymmetricKey columnEncryptionKey,
+ SQLServerEncryptionType encryptionType, String encryptionAlgorithm) throws SQLServerException {
+
+ assert (columnEncryptionKey != null);
+ if (encryptionType != SQLServerEncryptionType.Deterministic
+ && encryptionType != SQLServerEncryptionType.Randomized) {
+ MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_InvalidEncryptionType"));
+ Object[] msgArgs = {encryptionType, encryptionAlgorithm,
+ "'" + SQLServerEncryptionType.Deterministic + "," + SQLServerEncryptionType.Randomized + "'"};
+ throw new SQLServerException(this, form.format(msgArgs), null, 0, false);
+
+ }
+
+ StringBuilder factoryKeyBuilder = new StringBuilder();
+ factoryKeyBuilder.append(
+ Base64.getEncoder().encodeToString(new String(columnEncryptionKey.getRootKey(), UTF_8).getBytes()));
+
+ factoryKeyBuilder.append(":");
+ factoryKeyBuilder.append(encryptionType);
+ factoryKeyBuilder.append(":");
+ factoryKeyBuilder.append(algorithmVersion);
+
+ String factoryKey = factoryKeyBuilder.toString();
+
+ SQLServerAeadAes256CbcHmac256Algorithm aesAlgorithm;
+
+ if (!encryptionAlgorithms.containsKey(factoryKey)) {
+ SQLServerAeadAes256CbcHmac256EncryptionKey encryptedKey = new SQLServerAeadAes256CbcHmac256EncryptionKey(
+ columnEncryptionKey.getRootKey(), SQLServerAeadAes256CbcHmac256Algorithm.algorithmName);
+ aesAlgorithm = new SQLServerAeadAes256CbcHmac256Algorithm(encryptedKey, encryptionType, algorithmVersion);
+ encryptionAlgorithms.putIfAbsent(factoryKey, aesAlgorithm);
+ }
+
+ return encryptionAlgorithms.get(factoryKey);
+ }
+
+}
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBlob.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBlob.java
index 3631e2374..b1e785817 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBlob.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBlob.java
@@ -1,9 +1,6 @@
/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc;
@@ -19,10 +16,10 @@
import java.util.logging.Level;
import java.util.logging.Logger;
+
/**
- * SQLServerBlob represents a binary LOB object and implements a java.sql.Blob.
+ * Represents a binary LOB object and implements a java.sql.Blob.
*/
-
public final class SQLServerBlob extends SQLServerLob implements java.sql.Blob, java.io.Serializable {
/**
* Always refresh SerialVersionUID when prompted
@@ -63,14 +60,13 @@ private static int nextInstanceID() {
* Create a new BLOB
*
* @param connection
- * the database connection this blob is implemented on
+ * the database connection this blob is implemented on
* @param data
- * the BLOB's data
+ * the BLOB's data
* @deprecated Use {@link SQLServerConnection#createBlob()} instead.
*/
@Deprecated
- public SQLServerBlob(SQLServerConnection connection,
- byte data[]) {
+ public SQLServerBlob(SQLServerConnection connection, byte data[]) {
traceID = " SQLServerBlob:" + nextInstanceID();
con = connection;
@@ -114,9 +110,9 @@ public void free() throws SQLException {
for (Closeable stream : activeStreams) {
try {
stream.close();
- }
- catch (IOException ioException) {
- logger.fine(toString() + " ignored IOException closing stream " + stream + ": " + ioException.getMessage());
+ } catch (IOException ioException) {
+ logger.fine(toString() + " ignored IOException closing stream " + stream + ": "
+ + ioException.getMessage());
}
}
activeStreams = null;
@@ -145,29 +141,26 @@ public InputStream getBinaryStream() throws SQLException {
InputStream stream = (InputStream) activeStreams.get(0);
try {
stream.reset();
- }
- catch (IOException e) {
+ } catch (IOException e) {
throw new SQLServerException(e.getMessage(), null, 0, e);
}
return (InputStream) activeStreams.get(0);
- }
- else {
+ } else {
if (value == null) {
- throw new SQLServerException("Unexpected Error: blob value is null while all streams are closed.", null);
+ throw new SQLServerException("Unexpected Error: blob value is null while all streams are closed.",
+ null);
}
return getBinaryStreamInternal(0, value.length);
}
}
@Override
- public InputStream getBinaryStream(long pos,
- long length) throws SQLException {
+ public InputStream getBinaryStream(long pos, long length) throws SQLException {
SQLServerException.throwFeatureNotSupportedException();
return null;
}
- private InputStream getBinaryStreamInternal(int pos,
- int length) {
+ private InputStream getBinaryStreamInternal(int pos, int length) {
assert null != value;
assert pos >= 0;
assert 0 <= length && length <= value.length - pos;
@@ -179,8 +172,7 @@ private InputStream getBinaryStreamInternal(int pos,
}
@Override
- public byte[] getBytes(long pos,
- int length) throws SQLException {
+ public byte[] getBytes(long pos, int length) throws SQLException {
checkClosed();
getBytesFromStream();
@@ -239,8 +231,7 @@ private void getBytesFromStream() throws SQLServerException {
BaseInputStream stream = (BaseInputStream) activeStreams.get(0);
try {
stream.reset();
- }
- catch (IOException e) {
+ } catch (IOException e) {
throw new SQLServerException(e.getMessage(), null, 0, e);
}
value = stream.getBytes();
@@ -248,8 +239,7 @@ private void getBytesFromStream() throws SQLServerException {
}
@Override
- public long position(java.sql.Blob pattern,
- long start) throws SQLException {
+ public long position(java.sql.Blob pattern, long start) throws SQLException {
checkClosed();
getBytesFromStream();
@@ -266,8 +256,7 @@ public long position(java.sql.Blob pattern,
}
@Override
- public long position(byte[] bPattern,
- long start) throws SQLException {
+ public long position(byte[] bPattern, long start) throws SQLException {
checkClosed();
getBytesFromStream();
if (start < 1) {
@@ -334,27 +323,25 @@ public java.io.OutputStream setBinaryStream(long pos) throws SQLException {
}
@Override
- public int setBytes(long pos,
- byte[] bytes) throws SQLException {
+ public int setBytes(long pos, byte[] bytes) throws SQLException {
checkClosed();
getBytesFromStream();
if (null == bytes)
- SQLServerException.makeFromDriverError(con, null, SQLServerException.getErrString("R_cantSetNull"), null, true);
+ SQLServerException.makeFromDriverError(con, null, SQLServerException.getErrString("R_cantSetNull"), null,
+ true);
return setBytes(pos, bytes, 0, bytes.length);
}
@Override
- public int setBytes(long pos,
- byte[] bytes,
- int offset,
- int len) throws SQLException {
+ public int setBytes(long pos, byte[] bytes, int offset, int len) throws SQLException {
checkClosed();
getBytesFromStream();
if (null == bytes)
- SQLServerException.makeFromDriverError(con, null, SQLServerException.getErrString("R_cantSetNull"), null, true);
+ SQLServerException.makeFromDriverError(con, null, SQLServerException.getErrString("R_cantSetNull"), null,
+ true);
// Offset must be within incoming bytes boundary.
if (offset < 0 || offset > bytes.length) {
@@ -396,8 +383,7 @@ public int setBytes(long pos,
// Copy rest of data.
System.arraycopy(bytes, offset, combinedValue, (int) pos, len);
value = combinedValue;
- }
- else {
+ } else {
// Overwrite internal to value case.
System.arraycopy(bytes, offset, value, (int) pos, len);
}
@@ -406,18 +392,19 @@ public int setBytes(long pos,
}
}
+
/**
- * SQLServerBlobOutputStream is a simple java.io.OutputStream interface implementing class that forwards all calls to SQLServerBlob.setBytes. This
- * class is returned to caller by SQLServerBlob class when setBinaryStream is called.
+ * SQLServerBlobOutputStream is a simple java.io.OutputStream interface implementing class that forwards all calls to
+ * SQLServerBlob.setBytes. This class is returned to caller by SQLServerBlob class when setBinaryStream is called.
*
- * SQLServerBlobOutputStream starts writing at postion startPos and continues to write in a forward only manner. Reset/mark are not supported.
+ * SQLServerBlobOutputStream starts writing at postion startPos and continues to write in a forward only manner.
+ * Reset/mark are not supported.
*/
final class SQLServerBlobOutputStream extends java.io.OutputStream {
private SQLServerBlob parentBlob = null;
private long currentPos;
- SQLServerBlobOutputStream(SQLServerBlob parentBlob,
- long startPos) {
+ SQLServerBlobOutputStream(SQLServerBlob parentBlob, long startPos) {
this.parentBlob = parentBlob;
this.currentPos = startPos;
}
@@ -430,17 +417,14 @@ public void write(byte[] b) throws IOException {
}
@Override
- public void write(byte[] b,
- int off,
- int len) throws IOException {
+ public void write(byte[] b, int off, int len) throws IOException {
try {
// Call parent's setBytes and update position.
// setBytes can throw a SQLServerException, we translate
// this to an IOException here.
int bytesWritten = parentBlob.setBytes(currentPos, b, off, len);
currentPos += bytesWritten;
- }
- catch (SQLException ex) {
+ } catch (SQLException ex) {
throw new IOException(ex.getMessage());
}
}
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkBatchInsertRecord.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkBatchInsertRecord.java
index 8ded138ac..3203f07f1 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkBatchInsertRecord.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkBatchInsertRecord.java
@@ -1,9 +1,6 @@
/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc;
@@ -20,463 +17,417 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
-
import java.util.Set;
+
/**
- * A simple implementation of the ISQLServerBulkRecord interface that can be
- * used to read in the basic Java data types from an ArrayList of Parameters
- * that were provided by pstmt/cstmt.
+ * Provides a simple implementation of the ISQLServerBulkRecord interface that can be used to read in the basic Java
+ * data types from an ArrayList of Parameters that were provided by pstmt/cstmt.
*/
public class SQLServerBulkBatchInsertRecord extends SQLServerBulkCommon {
- private List batchParam;
- private int batchParamIndex = -1;
- private List columnList;
- private List valueList;
-
- /*
- * Class name for logging.
- */
- private static final String loggerClassName = "com.microsoft.sqlserver.jdbc.SQLServerBulkBatchInsertRecord";
-
- /*
- * Logger
- */
- private static final java.util.logging.Logger loggerExternal = java.util.logging.Logger
- .getLogger(loggerClassName);
-
- public SQLServerBulkBatchInsertRecord(ArrayList batchParam,
- ArrayList columnList, ArrayList valueList,
- String encoding) throws SQLServerException {
- loggerExternal.entering(loggerClassName,
- "SQLServerBulkBatchInsertRecord",
- new Object[]{batchParam, encoding});
-
- if (null == batchParam) {
- throwInvalidArgument("batchParam");
- }
-
- if (null == valueList) {
- throwInvalidArgument("valueList");
- }
-
- this.batchParam = batchParam;
- this.columnList = columnList;
- this.valueList = valueList;
- columnMetadata = new HashMap<>();
-
- loggerExternal.exiting(loggerClassName,
- "SQLServerBulkBatchInsertRecord");
- }
-
- @Override
- public DateTimeFormatter getColumnDateTimeFormatter(int column) {
- return columnMetadata.get(column).dateTimeFormatter;
- }
-
- @Override
- public Set getColumnOrdinals() {
- return columnMetadata.keySet();
- }
-
- @Override
- public String getColumnName(int column) {
- return columnMetadata.get(column).columnName;
- }
-
- @Override
- public int getColumnType(int column) {
- return columnMetadata.get(column).columnType;
- }
-
- @Override
- public int getPrecision(int column) {
- return columnMetadata.get(column).precision;
- }
-
- @Override
- public int getScale(int column) {
- return columnMetadata.get(column).scale;
- }
-
- @Override
- public boolean isAutoIncrement(int column) {
- return false;
- }
-
- private Object convertValue(ColumnMetadata cm, Object data)
- throws SQLServerException {
- switch (cm.columnType) {
- case Types.INTEGER : {
- // Formatter to remove the decimal part as SQL Server floors the
- // decimal in integer types
- DecimalFormat decimalFormatter = new DecimalFormat("#");
- decimalFormatter.setRoundingMode(RoundingMode.DOWN);
- String formatedfInput = decimalFormatter
- .format(Double.parseDouble(data.toString()));
- return Integer.valueOf(formatedfInput);
- }
-
- case Types.TINYINT :
- case Types.SMALLINT : {
- // Formatter to remove the decimal part as SQL Server floors the
- // decimal in integer types
- DecimalFormat decimalFormatter = new DecimalFormat("#");
- decimalFormatter.setRoundingMode(RoundingMode.DOWN);
- String formatedfInput = decimalFormatter
- .format(Double.parseDouble(data.toString()));
- return Short.valueOf(formatedfInput);
- }
-
- case Types.BIGINT : {
- BigDecimal bd = new BigDecimal(data.toString().trim());
- try {
- return bd.setScale(0, RoundingMode.DOWN).longValueExact();
- } catch (ArithmeticException ex) {
- String value = "'" + data + "'";
- MessageFormat form = new MessageFormat(SQLServerException
- .getErrString("R_errorConvertingValue"));
- throw new SQLServerException(form.format(
- new Object[]{value, JDBCType.of(cm.columnType)}),
- null, 0, ex);
- }
- }
-
- case Types.DECIMAL :
- case Types.NUMERIC : {
- BigDecimal bd = new BigDecimal(data.toString().trim());
- return bd.setScale(cm.scale, RoundingMode.HALF_UP);
- }
-
- case Types.BIT : {
- // "true" => 1, "false" => 0
- // Any non-zero value (integer/double) => 1, 0/0.0 => 0
- try {
- return (0 == Double.parseDouble(data.toString()))
- ? Boolean.FALSE
- : Boolean.TRUE;
- } catch (NumberFormatException e) {
- return Boolean.parseBoolean(data.toString());
- }
- }
-
- case Types.REAL : {
- return Float.parseFloat(data.toString());
- }
-
- case Types.DOUBLE : {
- return Double.parseDouble(data.toString());
- }
-
- case Types.BINARY :
- case Types.VARBINARY :
- case Types.LONGVARBINARY :
- case Types.BLOB : {
- // Strip off 0x if present.
- String binData = data.toString().trim();
- if (binData.startsWith("0x") || binData.startsWith("0X")) {
- return binData.substring(2);
- } else {
- return binData;
- }
- }
-
- case java.sql.Types.TIME_WITH_TIMEZONE : {
- OffsetTime offsetTimeValue;
-
- // The per-column DateTimeFormatter gets priority.
- if (null != cm.dateTimeFormatter)
- offsetTimeValue = OffsetTime.parse(data.toString(),
- cm.dateTimeFormatter);
- else if (timeFormatter != null)
- offsetTimeValue = OffsetTime.parse(data.toString(),
- timeFormatter);
- else
- offsetTimeValue = OffsetTime.parse(data.toString());
-
- return offsetTimeValue;
- }
-
- case java.sql.Types.TIMESTAMP_WITH_TIMEZONE : {
- OffsetDateTime offsetDateTimeValue;
-
- // The per-column DateTimeFormatter gets priority.
- if (null != cm.dateTimeFormatter)
- offsetDateTimeValue = OffsetDateTime.parse(data.toString(),
- cm.dateTimeFormatter);
- else if (dateTimeFormatter != null)
- offsetDateTimeValue = OffsetDateTime.parse(data.toString(),
- dateTimeFormatter);
- else
- offsetDateTimeValue = OffsetDateTime.parse(data.toString());
-
- return offsetDateTimeValue;
- }
-
- case Types.NULL : {
- return null;
- }
-
- case Types.DATE :
- case Types.CHAR :
- case Types.NCHAR :
- case Types.VARCHAR :
- case Types.NVARCHAR :
- case Types.LONGVARCHAR :
- case Types.LONGNVARCHAR :
- case Types.CLOB :
- default : {
- // The string is copied as is.
- return data;
- }
- }
- }
-
- private String removeSingleQuote(String s) {
- int len = s.length();
- return (s.charAt(0) == '\'' && s.charAt(len - 1) == '\'')
- ? s.substring(1, len - 1)
- : s;
- }
-
- @Override
- public Object[] getRowData() throws SQLServerException {
- Object[] data = new Object[columnMetadata.size()];
- int valueIndex = 0;
- String valueData;
- Object rowData;
- int columnListIndex = 0;
-
- // check if the size of the list of values = size of the list of columns
- // (which is optional)
- if (null != columnList && columnList.size() != valueList.size()) {
- MessageFormat form = new MessageFormat(
- SQLServerException.getErrString("R_DataSchemaMismatch"));
- Object[] msgArgs = {};
- throw new SQLServerException(form.format(msgArgs),
- SQLState.COL_NOT_FOUND, DriverError.NOT_SET, null);
- }
-
- for (Entry pair : columnMetadata.entrySet()) {
- int index = pair.getKey() - 1;
-
- // To explain what each variable represents:
- // columnMetadata = map containing the ENTIRE list of columns in the
- // table.
- // columnList = the *optional* list of columns the user can provide.
- // For example, the (c1, c3) part of this query: INSERT into t1 (c1,
- // c3) values (?, ?)
- // valueList = the *mandatory* list of columns the user needs
- // provide. This is the (?, ?) part of the previous query. The size
- // of this valueList will always equal the number of
- // the entire columns in the table IF columnList has NOT been
- // provided. If columnList HAS been provided, then this valueList
- // may be smaller than the list of all columns (which is
- // columnMetadata).
-
- // case when the user has not provided the optional list of column
- // names.
- if (null == columnList || columnList.size() == 0) {
- valueData = valueList.get(index);
- // if the user has provided a wildcard for this column, fetch
- // the set value from the batchParam.
- if (valueData.equalsIgnoreCase("?")) {
- rowData = batchParam.get(batchParamIndex)[valueIndex++]
- .getSetterValue();
- } else if (valueData.equalsIgnoreCase("null")) {
- rowData = null;
- }
- // if the user has provided a hardcoded value for this column,
- // rowData is simply set to the hardcoded value.
- else {
- rowData = removeSingleQuote(valueData);
- }
- }
- // case when the user has provided the optional list of column
- // names.
- else {
- // columnListIndex is a separate counter we need to keep track
- // of for each time we've processed a column
- // that the user provided.
- // for example, if the user provided an optional columnList of
- // (c1, c3, c5, c7) in a table that has 8 columns (c1~c8),
- // then the columnListIndex would increment only when we're
- // dealing with the four columns inside columnMetadata.
- // compare the list of the optional list of column names to the
- // table's metadata, and match each other, so we assign the
- // correct value to each column.
- if (columnList.size() > columnListIndex
- && columnList.get(columnListIndex).equalsIgnoreCase(
- columnMetadata.get(index + 1).columnName)) {
- valueData = valueList.get(columnListIndex);
- if (valueData.equalsIgnoreCase("?")) {
- rowData = batchParam.get(batchParamIndex)[valueIndex++]
- .getSetterValue();
- } else if (valueData.equalsIgnoreCase("null")) {
- rowData = null;
- } else {
- rowData = removeSingleQuote(valueData);
- }
- columnListIndex++;
- } else {
- rowData = null;
- }
- }
-
- try {
- if (null == rowData) {
- data[index] = null;
- continue;
- } else if (0 == rowData.toString().length()) {
- data[index] = "";
- continue;
- }
- data[index] = convertValue(pair.getValue(), rowData);
- } catch (IllegalArgumentException e) {
- String value = "'" + rowData + "'";
- MessageFormat form = new MessageFormat(SQLServerException
- .getErrString("R_errorConvertingValue"));
- throw new SQLServerException(
- form.format(new Object[]{value,
- JDBCType.of(pair.getValue().columnType)}),
- null, 0, e);
- } catch (ArrayIndexOutOfBoundsException e) {
- throw new SQLServerException(
- SQLServerException.getErrString("R_DataSchemaMismatch"),
- e);
- }
- }
- return data;
- }
-
- @Override
- void addColumnMetadataInternal(int positionInSource, String name,
- int jdbcType, int precision, int scale,
- DateTimeFormatter dateTimeFormatter) throws SQLServerException {
- loggerExternal.entering(loggerClassName, "addColumnMetadata",
- new Object[]{positionInSource, name, jdbcType, precision,
- scale});
-
- String colName = "";
-
- if (0 >= positionInSource) {
- MessageFormat form = new MessageFormat(
- SQLServerException.getErrString("R_invalidColumnOrdinal"));
- Object[] msgArgs = {positionInSource};
- throw new SQLServerException(form.format(msgArgs),
- SQLState.COL_NOT_FOUND, DriverError.NOT_SET, null);
- }
-
- if (null != name)
- colName = name.trim();
- else if ((null != columnNames)
- && (columnNames.length >= positionInSource))
- colName = columnNames[positionInSource - 1];
-
- if ((null != columnNames) && (positionInSource > columnNames.length)) {
- MessageFormat form = new MessageFormat(
- SQLServerException.getErrString("R_invalidColumn"));
- Object[] msgArgs = {positionInSource};
- throw new SQLServerException(form.format(msgArgs),
- SQLState.COL_NOT_FOUND, DriverError.NOT_SET, null);
- }
-
- checkDuplicateColumnName(positionInSource, name);
- switch (jdbcType) {
- /*
- * SQL Server supports numerous string literal formats for temporal
- * types, hence sending them as varchar with approximate
- * precision(length) needed to send supported string literals.
- * string literal formats supported by temporal types are available
- * in MSDN page on data types.
- */
- case java.sql.Types.DATE :
- case java.sql.Types.TIME :
- case java.sql.Types.TIMESTAMP :
- case microsoft.sql.Types.DATETIMEOFFSET :
- columnMetadata.put(positionInSource, new ColumnMetadata(colName,
- jdbcType, precision, scale, dateTimeFormatter));
- break;
-
- // Redirect SQLXML as LONGNVARCHAR
- // SQLXML is not valid type in TDS
- case java.sql.Types.SQLXML :
- columnMetadata.put(positionInSource,
- new ColumnMetadata(colName, java.sql.Types.LONGNVARCHAR,
- precision, scale, dateTimeFormatter));
- break;
-
- // Redirecting Float as Double based on data type mapping
- // https://msdn.microsoft.com/en-us/library/ms378878%28v=sql.110%29.aspx
- case java.sql.Types.FLOAT :
- columnMetadata.put(positionInSource,
- new ColumnMetadata(colName, java.sql.Types.DOUBLE,
- precision, scale, dateTimeFormatter));
- break;
-
- // redirecting BOOLEAN as BIT
- case java.sql.Types.BOOLEAN :
- columnMetadata.put(positionInSource,
- new ColumnMetadata(colName, java.sql.Types.BIT,
- precision, scale, dateTimeFormatter));
- break;
-
- default :
- columnMetadata.put(positionInSource, new ColumnMetadata(colName,
- jdbcType, precision, scale, dateTimeFormatter));
- }
-
- loggerExternal.exiting(loggerClassName, "addColumnMetadata");
- }
-
- @Override
- public void setTimestampWithTimezoneFormat(String dateTimeFormat) {
- loggerExternal.entering(loggerClassName,
- "setTimestampWithTimezoneFormat", dateTimeFormat);
-
- super.setTimestampWithTimezoneFormat(dateTimeFormat);
-
- loggerExternal.exiting(loggerClassName,
- "setTimestampWithTimezoneFormat");
- }
-
- @Override
- public void setTimestampWithTimezoneFormat(
- DateTimeFormatter dateTimeFormatter) {
- loggerExternal.entering(loggerClassName,
- "setTimestampWithTimezoneFormat",
- new Object[]{dateTimeFormatter});
-
- super.setTimestampWithTimezoneFormat(dateTimeFormatter);
-
- loggerExternal.exiting(loggerClassName,
- "setTimestampWithTimezoneFormat");
- }
-
- @Override
- public void setTimeWithTimezoneFormat(String timeFormat) {
- loggerExternal.entering(loggerClassName, "setTimeWithTimezoneFormat",
- timeFormat);
-
- super.setTimeWithTimezoneFormat(timeFormat);
-
- loggerExternal.exiting(loggerClassName, "setTimeWithTimezoneFormat");
- }
-
- @Override
- public void setTimeWithTimezoneFormat(DateTimeFormatter dateTimeFormatter) {
- loggerExternal.entering(loggerClassName, "setTimeWithTimezoneFormat",
- new Object[]{dateTimeFormatter});
-
- super.setTimeWithTimezoneFormat(dateTimeFormatter);
-
- loggerExternal.exiting(loggerClassName, "setTimeWithTimezoneFormat");
- }
-
- @Override
- public boolean next() throws SQLServerException {
- batchParamIndex++;
- return batchParamIndex < batchParam.size();
- }
+ private List batchParam;
+ private int batchParamIndex = -1;
+ private List columnList;
+ private List valueList;
+
+ /*
+ * Class name for logging.
+ */
+ private static final String loggerClassName = "com.microsoft.sqlserver.jdbc.SQLServerBulkBatchInsertRecord";
+
+ /*
+ * Logger
+ */
+ private static final java.util.logging.Logger loggerExternal = java.util.logging.Logger.getLogger(loggerClassName);
+
+ /*
+ * Constructs a SQLServerBulkBatchInsertRecord with the batch parameter, column list, value list, and encoding
+ */
+ public SQLServerBulkBatchInsertRecord(ArrayList batchParam, ArrayList columnList,
+ ArrayList valueList, String encoding) throws SQLServerException {
+ loggerExternal.entering(loggerClassName, "SQLServerBulkBatchInsertRecord", new Object[] {batchParam, encoding});
+
+ if (null == batchParam) {
+ throwInvalidArgument("batchParam");
+ }
+
+ if (null == valueList) {
+ throwInvalidArgument("valueList");
+ }
+
+ this.batchParam = batchParam;
+ this.columnList = columnList;
+ this.valueList = valueList;
+ columnMetadata = new HashMap<>();
+
+ loggerExternal.exiting(loggerClassName, "SQLServerBulkBatchInsertRecord");
+ }
+
+ @Override
+ public DateTimeFormatter getColumnDateTimeFormatter(int column) {
+ return columnMetadata.get(column).dateTimeFormatter;
+ }
+
+ @Override
+ public Set getColumnOrdinals() {
+ return columnMetadata.keySet();
+ }
+
+ @Override
+ public String getColumnName(int column) {
+ return columnMetadata.get(column).columnName;
+ }
+
+ @Override
+ public int getColumnType(int column) {
+ return columnMetadata.get(column).columnType;
+ }
+
+ @Override
+ public int getPrecision(int column) {
+ return columnMetadata.get(column).precision;
+ }
+
+ @Override
+ public int getScale(int column) {
+ return columnMetadata.get(column).scale;
+ }
+
+ @Override
+ public boolean isAutoIncrement(int column) {
+ return false;
+ }
+
+ private Object convertValue(ColumnMetadata cm, Object data) throws SQLServerException {
+ switch (cm.columnType) {
+ case Types.INTEGER: {
+ // Formatter to remove the decimal part as SQL Server floors the
+ // decimal in integer types
+ DecimalFormat decimalFormatter = new DecimalFormat("#");
+ decimalFormatter.setRoundingMode(RoundingMode.DOWN);
+ String formatedfInput = decimalFormatter.format(Double.parseDouble(data.toString()));
+ return Integer.valueOf(formatedfInput);
+ }
+
+ case Types.TINYINT:
+ case Types.SMALLINT: {
+ // Formatter to remove the decimal part as SQL Server floors the
+ // decimal in integer types
+ DecimalFormat decimalFormatter = new DecimalFormat("#");
+ decimalFormatter.setRoundingMode(RoundingMode.DOWN);
+ String formatedfInput = decimalFormatter.format(Double.parseDouble(data.toString()));
+ return Short.valueOf(formatedfInput);
+ }
+
+ case Types.BIGINT: {
+ BigDecimal bd = new BigDecimal(data.toString().trim());
+ try {
+ return bd.setScale(0, RoundingMode.DOWN).longValueExact();
+ } catch (ArithmeticException ex) {
+ String value = "'" + data + "'";
+ MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_errorConvertingValue"));
+ throw new SQLServerException(form.format(new Object[] {value, JDBCType.of(cm.columnType)}), null, 0,
+ ex);
+ }
+ }
+
+ case Types.DECIMAL:
+ case Types.NUMERIC: {
+ BigDecimal bd = new BigDecimal(data.toString().trim());
+ return bd.setScale(cm.scale, RoundingMode.HALF_UP);
+ }
+
+ case Types.BIT: {
+ // "true" => 1, "false" => 0
+ // Any non-zero value (integer/double) => 1, 0/0.0 => 0
+ try {
+ return (0 == Double.parseDouble(data.toString())) ? Boolean.FALSE : Boolean.TRUE;
+ } catch (NumberFormatException e) {
+ return Boolean.parseBoolean(data.toString());
+ }
+ }
+
+ case Types.REAL: {
+ return Float.parseFloat(data.toString());
+ }
+
+ case Types.DOUBLE: {
+ return Double.parseDouble(data.toString());
+ }
+
+ case Types.BINARY:
+ case Types.VARBINARY:
+ case Types.LONGVARBINARY:
+ case Types.BLOB: {
+ // Strip off 0x if present.
+ String binData = data.toString().trim();
+ if (binData.startsWith("0x") || binData.startsWith("0X")) {
+ return binData.substring(2);
+ } else {
+ return binData;
+ }
+ }
+
+ case java.sql.Types.TIME_WITH_TIMEZONE: {
+ OffsetTime offsetTimeValue;
+
+ // The per-column DateTimeFormatter gets priority.
+ if (null != cm.dateTimeFormatter)
+ offsetTimeValue = OffsetTime.parse(data.toString(), cm.dateTimeFormatter);
+ else if (timeFormatter != null)
+ offsetTimeValue = OffsetTime.parse(data.toString(), timeFormatter);
+ else
+ offsetTimeValue = OffsetTime.parse(data.toString());
+
+ return offsetTimeValue;
+ }
+
+ case java.sql.Types.TIMESTAMP_WITH_TIMEZONE: {
+ OffsetDateTime offsetDateTimeValue;
+
+ // The per-column DateTimeFormatter gets priority.
+ if (null != cm.dateTimeFormatter)
+ offsetDateTimeValue = OffsetDateTime.parse(data.toString(), cm.dateTimeFormatter);
+ else if (dateTimeFormatter != null)
+ offsetDateTimeValue = OffsetDateTime.parse(data.toString(), dateTimeFormatter);
+ else
+ offsetDateTimeValue = OffsetDateTime.parse(data.toString());
+
+ return offsetDateTimeValue;
+ }
+
+ case Types.NULL: {
+ return null;
+ }
+
+ case Types.DATE:
+ case Types.CHAR:
+ case Types.NCHAR:
+ case Types.VARCHAR:
+ case Types.NVARCHAR:
+ case Types.LONGVARCHAR:
+ case Types.LONGNVARCHAR:
+ case Types.CLOB:
+ default: {
+ // The string is copied as is.
+ return data;
+ }
+ }
+ }
+
+ private String removeSingleQuote(String s) {
+ int len = s.length();
+ return (s.charAt(0) == '\'' && s.charAt(len - 1) == '\'') ? s.substring(1, len - 1) : s;
+ }
+
+ @Override
+ public Object[] getRowData() throws SQLServerException {
+ Object[] data = new Object[columnMetadata.size()];
+ int valueIndex = 0;
+ String valueData;
+ Object rowData;
+ int columnListIndex = 0;
+
+ // check if the size of the list of values = size of the list of columns
+ // (which is optional)
+ if (null != columnList && columnList.size() != valueList.size()) {
+ MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_DataSchemaMismatch"));
+ Object[] msgArgs = {};
+ throw new SQLServerException(form.format(msgArgs), SQLState.COL_NOT_FOUND, DriverError.NOT_SET, null);
+ }
+
+ for (Entry pair : columnMetadata.entrySet()) {
+ int index = pair.getKey() - 1;
+
+ // To explain what each variable represents:
+ // columnMetadata = map containing the ENTIRE list of columns in the
+ // table.
+ // columnList = the *optional* list of columns the user can provide.
+ // For example, the (c1, c3) part of this query: INSERT into t1 (c1,
+ // c3) values (?, ?)
+ // valueList = the *mandatory* list of columns the user needs
+ // provide. This is the (?, ?) part of the previous query. The size
+ // of this valueList will always equal the number of
+ // the entire columns in the table IF columnList has NOT been
+ // provided. If columnList HAS been provided, then this valueList
+ // may be smaller than the list of all columns (which is
+ // columnMetadata).
+
+ // case when the user has not provided the optional list of column
+ // names.
+ if (null == columnList || columnList.size() == 0) {
+ valueData = valueList.get(index);
+ // if the user has provided a wildcard for this column, fetch
+ // the set value from the batchParam.
+ if (valueData.equalsIgnoreCase("?")) {
+ rowData = batchParam.get(batchParamIndex)[valueIndex++].getSetterValue();
+ } else if (valueData.equalsIgnoreCase("null")) {
+ rowData = null;
+ }
+ // if the user has provided a hardcoded value for this column,
+ // rowData is simply set to the hardcoded value.
+ else {
+ rowData = removeSingleQuote(valueData);
+ }
+ }
+ // case when the user has provided the optional list of column
+ // names.
+ else {
+ // columnListIndex is a separate counter we need to keep track
+ // of for each time we've processed a column
+ // that the user provided.
+ // for example, if the user provided an optional columnList of
+ // (c1, c3, c5, c7) in a table that has 8 columns (c1~c8),
+ // then the columnListIndex would increment only when we're
+ // dealing with the four columns inside columnMetadata.
+ // compare the list of the optional list of column names to the
+ // table's metadata, and match each other, so we assign the
+ // correct value to each column.
+ if (columnList.size() > columnListIndex
+ && columnList.get(columnListIndex).equalsIgnoreCase(columnMetadata.get(index + 1).columnName)) {
+ valueData = valueList.get(columnListIndex);
+ if (valueData.equalsIgnoreCase("?")) {
+ rowData = batchParam.get(batchParamIndex)[valueIndex++].getSetterValue();
+ } else if (valueData.equalsIgnoreCase("null")) {
+ rowData = null;
+ } else {
+ rowData = removeSingleQuote(valueData);
+ }
+ columnListIndex++;
+ } else {
+ rowData = null;
+ }
+ }
+
+ try {
+ if (null == rowData) {
+ data[index] = null;
+ continue;
+ } else if (0 == rowData.toString().length()) {
+ data[index] = "";
+ continue;
+ }
+ data[index] = convertValue(pair.getValue(), rowData);
+ } catch (IllegalArgumentException e) {
+ String value = "'" + rowData + "'";
+ MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_errorConvertingValue"));
+ throw new SQLServerException(form.format(new Object[] {value, JDBCType.of(pair.getValue().columnType)}),
+ null, 0, e);
+ } catch (ArrayIndexOutOfBoundsException e) {
+ throw new SQLServerException(SQLServerException.getErrString("R_DataSchemaMismatch"), e);
+ }
+ }
+ return data;
+ }
+
+ @Override
+ void addColumnMetadataInternal(int positionInSource, String name, int jdbcType, int precision, int scale,
+ DateTimeFormatter dateTimeFormatter) throws SQLServerException {
+ loggerExternal.entering(loggerClassName, "addColumnMetadata",
+ new Object[] {positionInSource, name, jdbcType, precision, scale});
+
+ String colName = "";
+
+ if (0 >= positionInSource) {
+ MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidColumnOrdinal"));
+ Object[] msgArgs = {positionInSource};
+ throw new SQLServerException(form.format(msgArgs), SQLState.COL_NOT_FOUND, DriverError.NOT_SET, null);
+ }
+
+ if (null != name)
+ colName = name.trim();
+ else if ((null != columnNames) && (columnNames.length >= positionInSource))
+ colName = columnNames[positionInSource - 1];
+
+ if ((null != columnNames) && (positionInSource > columnNames.length)) {
+ MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidColumn"));
+ Object[] msgArgs = {positionInSource};
+ throw new SQLServerException(form.format(msgArgs), SQLState.COL_NOT_FOUND, DriverError.NOT_SET, null);
+ }
+
+ checkDuplicateColumnName(positionInSource, name);
+ switch (jdbcType) {
+ /*
+ * SQL Server supports numerous string literal formats for temporal types, hence sending them as varchar
+ * with approximate precision(length) needed to send supported string literals. string literal formats
+ * supported by temporal types are available in MSDN page on data types.
+ */
+ case java.sql.Types.DATE:
+ case java.sql.Types.TIME:
+ case java.sql.Types.TIMESTAMP:
+ case microsoft.sql.Types.DATETIMEOFFSET:
+ columnMetadata.put(positionInSource,
+ new ColumnMetadata(colName, jdbcType, precision, scale, dateTimeFormatter));
+ break;
+
+ // Redirect SQLXML as LONGNVARCHAR
+ // SQLXML is not valid type in TDS
+ case java.sql.Types.SQLXML:
+ columnMetadata.put(positionInSource,
+ new ColumnMetadata(colName, java.sql.Types.LONGNVARCHAR, precision, scale, dateTimeFormatter));
+ break;
+
+ // Redirecting Float as Double based on data type mapping
+ // https://msdn.microsoft.com/en-us/library/ms378878%28v=sql.110%29.aspx
+ case java.sql.Types.FLOAT:
+ columnMetadata.put(positionInSource,
+ new ColumnMetadata(colName, java.sql.Types.DOUBLE, precision, scale, dateTimeFormatter));
+ break;
+
+ // redirecting BOOLEAN as BIT
+ case java.sql.Types.BOOLEAN:
+ columnMetadata.put(positionInSource,
+ new ColumnMetadata(colName, java.sql.Types.BIT, precision, scale, dateTimeFormatter));
+ break;
+
+ default:
+ columnMetadata.put(positionInSource,
+ new ColumnMetadata(colName, jdbcType, precision, scale, dateTimeFormatter));
+ }
+
+ loggerExternal.exiting(loggerClassName, "addColumnMetadata");
+ }
+
+ @Override
+ public void setTimestampWithTimezoneFormat(String dateTimeFormat) {
+ loggerExternal.entering(loggerClassName, "setTimestampWithTimezoneFormat", dateTimeFormat);
+
+ super.setTimestampWithTimezoneFormat(dateTimeFormat);
+
+ loggerExternal.exiting(loggerClassName, "setTimestampWithTimezoneFormat");
+ }
+
+ @Override
+ public void setTimestampWithTimezoneFormat(DateTimeFormatter dateTimeFormatter) {
+ loggerExternal.entering(loggerClassName, "setTimestampWithTimezoneFormat", new Object[] {dateTimeFormatter});
+
+ super.setTimestampWithTimezoneFormat(dateTimeFormatter);
+
+ loggerExternal.exiting(loggerClassName, "setTimestampWithTimezoneFormat");
+ }
+
+ @Override
+ public void setTimeWithTimezoneFormat(String timeFormat) {
+ loggerExternal.entering(loggerClassName, "setTimeWithTimezoneFormat", timeFormat);
+
+ super.setTimeWithTimezoneFormat(timeFormat);
+
+ loggerExternal.exiting(loggerClassName, "setTimeWithTimezoneFormat");
+ }
+
+ @Override
+ public void setTimeWithTimezoneFormat(DateTimeFormatter dateTimeFormatter) {
+ loggerExternal.entering(loggerClassName, "setTimeWithTimezoneFormat", new Object[] {dateTimeFormatter});
+
+ super.setTimeWithTimezoneFormat(dateTimeFormatter);
+
+ loggerExternal.exiting(loggerClassName, "setTimeWithTimezoneFormat");
+ }
+
+ @Override
+ public boolean next() throws SQLServerException {
+ batchParamIndex++;
+ return batchParamIndex < batchParam.size();
+ }
}
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkCSVFileRecord.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkCSVFileRecord.java
index 31e101463..ac84bc58d 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkCSVFileRecord.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkCSVFileRecord.java
@@ -1,9 +1,6 @@
/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc;
@@ -24,12 +21,12 @@
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map.Entry;
-
import java.util.Set;
+
/**
- * A simple implementation of the ISQLServerBulkRecord interface that can be used to read in the basic Java data types from a delimited file where
- * each line represents a row of data.
+ * Provides a simple implementation of the ISQLServerBulkRecord interface that can be used to read in the basic Java
+ * data types from a delimited file where each line represents a row of data.
*/
public class SQLServerBulkCSVFileRecord extends SQLServerBulkCommon implements java.lang.AutoCloseable {
/*
@@ -60,30 +57,27 @@ public class SQLServerBulkCSVFileRecord extends SQLServerBulkCommon implements j
private static final java.util.logging.Logger loggerExternal = java.util.logging.Logger.getLogger(loggerClassName);
/**
- * Creates a simple reader to parse data from a delimited file with the given encoding.
+ * Constructs a simple reader to parse data from a delimited file with the given encoding.
*
* @param fileToParse
- * File to parse data from
+ * File to parse data from
* @param encoding
- * Charset encoding to use for reading the file, or NULL for the default encoding.
+ * Charset encoding to use for reading the file, or NULL for the default encoding.
* @param delimiter
- * Delimiter to used to separate each column
+ * Delimiter to used to separate each column
* @param firstLineIsColumnNames
- * True if the first line of the file should be parsed as column names; false otherwise
+ * True if the first line of the file should be parsed as column names; false otherwise
* @throws SQLServerException
- * If the arguments are invalid, there are any errors in reading the file, or the file is empty
+ * If the arguments are invalid, there are any errors in reading the file, or the file is empty
*/
- public SQLServerBulkCSVFileRecord(String fileToParse,
- String encoding,
- String delimiter,
+ public SQLServerBulkCSVFileRecord(String fileToParse, String encoding, String delimiter,
boolean firstLineIsColumnNames) throws SQLServerException {
loggerExternal.entering(loggerClassName, "SQLServerBulkCSVFileRecord",
new Object[] {fileToParse, encoding, delimiter, firstLineIsColumnNames});
if (null == fileToParse) {
throwInvalidArgument("fileToParse");
- }
- else if (null == delimiter) {
+ } else if (null == delimiter) {
throwInvalidArgument("delimiter");
}
@@ -93,8 +87,7 @@ else if (null == delimiter) {
fis = new FileInputStream(fileToParse);
if (null == encoding || 0 == encoding.length()) {
sr = new InputStreamReader(fis);
- }
- else {
+ } else {
sr = new InputStreamReader(fis, encoding);
}
@@ -106,12 +99,10 @@ else if (null == delimiter) {
columnNames = currentLine.split(delimiter, -1);
}
}
- }
- catch (UnsupportedEncodingException unsupportedEncoding) {
+ } catch (UnsupportedEncodingException unsupportedEncoding) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_unsupportedEncoding"));
throw new SQLServerException(form.format(new Object[] {encoding}), null, 0, unsupportedEncoding);
- }
- catch (Exception e) {
+ } catch (Exception e) {
throw new SQLServerException(null, e.getMessage(), null, 0, false);
}
columnMetadata = new HashMap<>();
@@ -120,30 +111,27 @@ else if (null == delimiter) {
}
/**
- * Creates a simple reader to parse data from a delimited file with the given encoding.
+ * Constructs a SQLServerBulkCSVFileRecord to parse data from a delimited file with the given encoding.
*
* @param fileToParse
- * InputStream to parse data from
+ * InputStream to parse data from
* @param encoding
- * Charset encoding to use for reading the file, or NULL for the default encoding.
+ * Charset encoding to use for reading the file, or NULL for the default encoding.
* @param delimiter
- * Delimiter to used to separate each column
+ * Delimiter to used to separate each column
* @param firstLineIsColumnNames
- * True if the first line of the file should be parsed as column names; false otherwise
+ * True if the first line of the file should be parsed as column names; false otherwise
* @throws SQLServerException
- * If the arguments are invalid, there are any errors in reading the file, or the file is empty
+ * If the arguments are invalid, there are any errors in reading the file, or the file is empty
*/
- public SQLServerBulkCSVFileRecord(InputStream fileToParse,
- String encoding,
- String delimiter,
+ public SQLServerBulkCSVFileRecord(InputStream fileToParse, String encoding, String delimiter,
boolean firstLineIsColumnNames) throws SQLServerException {
loggerExternal.entering(loggerClassName, "SQLServerBulkCSVFileRecord",
new Object[] {fileToParse, encoding, delimiter, firstLineIsColumnNames});
if (null == fileToParse) {
throwInvalidArgument("fileToParse");
- }
- else if (null == delimiter) {
+ } else if (null == delimiter) {
throwInvalidArgument("delimiter");
}
@@ -151,8 +139,7 @@ else if (null == delimiter) {
try {
if (null == encoding || 0 == encoding.length()) {
sr = new InputStreamReader(fileToParse);
- }
- else {
+ } else {
sr = new InputStreamReader(fileToParse, encoding);
}
fileReader = new BufferedReader(sr);
@@ -163,12 +150,10 @@ else if (null == delimiter) {
columnNames = currentLine.split(delimiter, -1);
}
}
- }
- catch (UnsupportedEncodingException unsupportedEncoding) {
+ } catch (UnsupportedEncodingException unsupportedEncoding) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_unsupportedEncoding"));
throw new SQLServerException(form.format(new Object[] {encoding}), null, 0, unsupportedEncoding);
- }
- catch (Exception e) {
+ } catch (Exception e) {
throw new SQLServerException(null, e.getMessage(), null, 0, false);
}
columnMetadata = new HashMap<>();
@@ -177,35 +162,33 @@ else if (null == delimiter) {
}
/**
- * Creates a simple reader to parse data from a CSV file with the given encoding.
+ * Constructs a SQLServerBulkCSVFileRecord to parse data from a CSV file with the given encoding.
*
* @param fileToParse
- * File to parse data from
+ * File to parse data from
* @param encoding
- * Charset encoding to use for reading the file.
+ * Charset encoding to use for reading the file.
* @param firstLineIsColumnNames
- * True if the first line of the file should be parsed as column names; false otherwise
+ * True if the first line of the file should be parsed as column names; false otherwise
* @throws SQLServerException
- * If the arguments are invalid, there are any errors in reading the file, or the file is empty
+ * If the arguments are invalid, there are any errors in reading the file, or the file is empty
*/
- public SQLServerBulkCSVFileRecord(String fileToParse,
- String encoding,
+ public SQLServerBulkCSVFileRecord(String fileToParse, String encoding,
boolean firstLineIsColumnNames) throws SQLServerException {
this(fileToParse, encoding, ",", firstLineIsColumnNames);
}
/**
- * Creates a simple reader to parse data from a CSV file with the default encoding.
+ * Constructs a SQLServerBulkCSVFileRecord to parse data from a CSV file with the default encoding.
*
* @param fileToParse
- * File to parse data from
+ * File to parse data from
* @param firstLineIsColumnNames
- * True if the first line of the file should be parsed as column names; false otherwise
+ * True if the first line of the file should be parsed as column names; false otherwise
* @throws SQLServerException
- * If the arguments are invalid, there are any errors in reading the file, or the file is empty
+ * If the arguments are invalid, there are any errors in reading the file, or the file is empty
*/
- public SQLServerBulkCSVFileRecord(String fileToParse,
- boolean firstLineIsColumnNames) throws SQLServerException {
+ public SQLServerBulkCSVFileRecord(String fileToParse, boolean firstLineIsColumnNames) throws SQLServerException {
this(fileToParse, null, ",", firstLineIsColumnNames);
}
@@ -213,7 +196,7 @@ public SQLServerBulkCSVFileRecord(String fileToParse,
* Releases any resources associated with the file reader.
*
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
public void close() throws SQLServerException {
loggerExternal.entering(loggerClassName, "close");
@@ -222,21 +205,15 @@ public void close() throws SQLServerException {
if (fileReader != null)
try {
fileReader.close();
- }
- catch (Exception e) {
- }
+ } catch (Exception e) {}
if (sr != null)
try {
sr.close();
- }
- catch (Exception e) {
- }
+ } catch (Exception e) {}
if (fis != null)
try {
fis.close();
- }
- catch (Exception e) {
- }
+ } catch (Exception e) {}
loggerExternal.exiting(loggerClassName, "close");
}
@@ -299,14 +276,16 @@ public Object[] getRowData() throws SQLServerException {
if (data.length < pair.getKey() - 1) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidColumn"));
Object[] msgArgs = {pair.getKey()};
- throw new SQLServerException(form.format(msgArgs), SQLState.COL_NOT_FOUND, DriverError.NOT_SET, null);
+ throw new SQLServerException(form.format(msgArgs), SQLState.COL_NOT_FOUND, DriverError.NOT_SET,
+ null);
}
// Source header has more columns than current line read
if (columnNames != null && (columnNames.length > data.length)) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_DataSchemaMismatch"));
Object[] msgArgs = {};
- throw new SQLServerException(form.format(msgArgs), SQLState.COL_NOT_FOUND, DriverError.NOT_SET, null);
+ throw new SQLServerException(form.format(msgArgs), SQLState.COL_NOT_FOUND, DriverError.NOT_SET,
+ null);
}
try {
@@ -317,15 +296,16 @@ public Object[] getRowData() throws SQLServerException {
switch (cm.columnType) {
/*
- * Both BCP and BULK INSERT considers double quotes as part of the data and throws error if any data (say "10") is to be
- * inserted into an numeric column. Our implementation does the same.
+ * Both BCP and BULK INSERT considers double quotes as part of the data and throws error if any
+ * data (say "10") is to be inserted into an numeric column. Our implementation does the same.
*/
case Types.INTEGER: {
// Formatter to remove the decimal part as SQL
// Server floors the decimal in integer types
DecimalFormat decimalFormatter = new DecimalFormat("#");
decimalFormatter.setRoundingMode(RoundingMode.DOWN);
- String formatedfInput = decimalFormatter.format(Double.parseDouble(data[pair.getKey() - 1]));
+ String formatedfInput = decimalFormatter
+ .format(Double.parseDouble(data[pair.getKey() - 1]));
dataRow[pair.getKey() - 1] = Integer.valueOf(formatedfInput);
break;
}
@@ -336,7 +316,8 @@ public Object[] getRowData() throws SQLServerException {
// Server floors the decimal in integer types
DecimalFormat decimalFormatter = new DecimalFormat("#");
decimalFormatter.setRoundingMode(RoundingMode.DOWN);
- String formatedfInput = decimalFormatter.format(Double.parseDouble(data[pair.getKey() - 1]));
+ String formatedfInput = decimalFormatter
+ .format(Double.parseDouble(data[pair.getKey() - 1]));
dataRow[pair.getKey() - 1] = Short.valueOf(formatedfInput);
break;
}
@@ -345,11 +326,12 @@ public Object[] getRowData() throws SQLServerException {
BigDecimal bd = new BigDecimal(data[pair.getKey() - 1].trim());
try {
dataRow[pair.getKey() - 1] = bd.setScale(0, RoundingMode.DOWN).longValueExact();
- }
- catch (ArithmeticException ex) {
+ } catch (ArithmeticException ex) {
String value = "'" + data[pair.getKey() - 1] + "'";
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_errorConvertingValue"));
- throw new SQLServerException(form.format(new Object[] {value, JDBCType.of(cm.columnType)}), null, 0, ex);
+ MessageFormat form = new MessageFormat(
+ SQLServerException.getErrString("R_errorConvertingValue"));
+ throw new SQLServerException(
+ form.format(new Object[] {value, JDBCType.of(cm.columnType)}), null, 0, ex);
}
break;
}
@@ -366,9 +348,10 @@ public Object[] getRowData() throws SQLServerException {
// Any non-zero value (integer/double) => 1, 0/0.0
// => 0
try {
- dataRow[pair.getKey() - 1] = (0 == Double.parseDouble(data[pair.getKey() - 1])) ? Boolean.FALSE : Boolean.TRUE;
- }
- catch (NumberFormatException e) {
+ dataRow[pair.getKey()
+ - 1] = (0 == Double.parseDouble(data[pair.getKey() - 1])) ? Boolean.FALSE
+ : Boolean.TRUE;
+ } catch (NumberFormatException e) {
dataRow[pair.getKey() - 1] = Boolean.parseBoolean(data[pair.getKey() - 1]);
}
break;
@@ -389,18 +372,19 @@ public Object[] getRowData() throws SQLServerException {
case Types.LONGVARBINARY:
case Types.BLOB: {
/*
- * For binary data, the value in file may or may not have the '0x' prefix. We will try to match our implementation with
- * 'BULK INSERT' except that we will allow 0x prefix whereas 'BULK INSERT' command does not allow 0x prefix. A BULK INSERT
- * example: A sample csv file containing data for 2 binary columns and 1 row: 61,62 Table definition: create table t1(c1
- * varbinary(10), c2 varbinary(10)) BULK INSERT command: bulk insert t1 from 'C:\in.csv'
- * with(DATAFILETYPE='char',firstrow=1, FIELDTERMINATOR=',') select * from t1 shows 1 row with columns: 0x61, 0x62
+ * For binary data, the value in file may or may not have the '0x' prefix. We will try to
+ * match our implementation with 'BULK INSERT' except that we will allow 0x prefix whereas
+ * 'BULK INSERT' command does not allow 0x prefix. A BULK INSERT example: A sample csv file
+ * containing data for 2 binary columns and 1 row: 61,62 Table definition: create table
+ * t1(c1 varbinary(10), c2 varbinary(10)) BULK INSERT command: bulk insert t1 from
+ * 'C:\in.csv' with(DATAFILETYPE='char',firstrow=1, FIELDTERMINATOR=',') select * from t1
+ * shows 1 row with columns: 0x61, 0x62
*/
// Strip off 0x if present.
String binData = data[pair.getKey() - 1].trim();
if (binData.startsWith("0x") || binData.startsWith("0X")) {
dataRow[pair.getKey() - 1] = binData.substring(2);
- }
- else {
+ } else {
dataRow[pair.getKey() - 1] = binData;
}
break;
@@ -426,7 +410,8 @@ else if (timeFormatter != null)
// The per-column DateTimeFormatter gets priority.
if (null != cm.dateTimeFormatter)
- offsetDateTimeValue = OffsetDateTime.parse(data[pair.getKey() - 1], cm.dateTimeFormatter);
+ offsetDateTimeValue = OffsetDateTime.parse(data[pair.getKey() - 1],
+ cm.dateTimeFormatter);
else if (dateTimeFormatter != null)
offsetDateTimeValue = OffsetDateTime.parse(data[pair.getKey() - 1], dateTimeFormatter);
else
@@ -452,28 +437,29 @@ else if (dateTimeFormatter != null)
default: {
// The string is copied as is.
/*
- * Handling double quotes: Both BCP (without a format file) and BULK INSERT behaves the same way for double quotes. They
- * treat double quotes as part of the data. For a CSV file as follows, data is inserted as is: ""abc"" "abc" abc a"b"c
- * a""b""c Excel on the other hand, shows data as follows. It strips off beginning and ending quotes, and sometimes quotes
- * get messed up. When the same CSV is saved from Excel again, Excel adds additional quotes. abc"" abc abc a"b"c a""b""c
- * In our implementation we will match the behavior with BCP and BULK INSERT. BCP command: bcp table1 in in.csv -c -t , -r
- * 0x0A -S localhost -U sa -P BULK INSERT command: bulk insert table1 from 'in.csv' with (FIELDTERMINATOR=',')
- *
- * Handling delimiters in data: Excel allows comma in data when data is surrounded with quotes. For example,
- * "Hello, world" is treated as one cell. BCP and BULK INSERT deos not allow field terminators in data:
- * https://technet.microsoft.com/en-us/library/ aa196735%28v=sql.80%29.aspx?f=255&MSPPError=- 2147217396
+ * Handling double quotes: Both BCP (without a format file) and BULK INSERT behaves the same
+ * way for double quotes. They treat double quotes as part of the data. For a CSV file as
+ * follows, data is inserted as is: ""abc"" "abc" abc a"b"c a""b""c Excel on the other hand,
+ * shows data as follows. It strips off beginning and ending quotes, and sometimes quotes
+ * get messed up. When the same CSV is saved from Excel again, Excel adds additional quotes.
+ * abc"" abc abc a"b"c a""b""c In our implementation we will match the behavior with BCP and
+ * BULK INSERT. BCP command: bcp table1 in in.csv -c -t , -r 0x0A -S localhost -U sa -P
+ * BULK INSERT command: bulk insert table1 from 'in.csv' with (FIELDTERMINATOR=',')
+ * Handling delimiters in data: Excel allows comma in data when data is surrounded with
+ * quotes. For example, "Hello, world" is treated as one cell. BCP and BULK INSERT deos not
+ * allow field terminators in data: https://technet.microsoft.com/en-us/library/
+ * aa196735%28v=sql.80%29.aspx?f=255&MSPPError=- 2147217396
*/
dataRow[pair.getKey() - 1] = data[pair.getKey() - 1];
break;
}
}
- }
- catch (IllegalArgumentException e) {
+ } catch (IllegalArgumentException e) {
String value = "'" + data[pair.getKey() - 1] + "'";
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_errorConvertingValue"));
- throw new SQLServerException(form.format(new Object[] {value, JDBCType.of(cm.columnType)}), null, 0, e);
- }
- catch (ArrayIndexOutOfBoundsException e) {
+ throw new SQLServerException(form.format(new Object[] {value, JDBCType.of(cm.columnType)}), null, 0,
+ e);
+ } catch (ArrayIndexOutOfBoundsException e) {
throw new SQLServerException(SQLServerException.getErrString("R_DataSchemaMismatch"), e);
}
@@ -483,13 +469,10 @@ else if (dateTimeFormatter != null)
}
@Override
- void addColumnMetadataInternal(int positionInSource,
- String name,
- int jdbcType,
- int precision,
- int scale,
+ void addColumnMetadataInternal(int positionInSource, String name, int jdbcType, int precision, int scale,
DateTimeFormatter dateTimeFormatter) throws SQLServerException {
- loggerExternal.entering(loggerClassName, "addColumnMetadata", new Object[] {positionInSource, name, jdbcType, precision, scale});
+ loggerExternal.entering(loggerClassName, "addColumnMetadata",
+ new Object[] {positionInSource, name, jdbcType, precision, scale});
String colName = "";
@@ -513,36 +496,41 @@ else if ((null != columnNames) && (columnNames.length >= positionInSource))
checkDuplicateColumnName(positionInSource, name);
switch (jdbcType) {
/*
- * SQL Server supports numerous string literal formats for temporal types, hence sending them as varchar with approximate
- * precision(length) needed to send supported string literals. string literal formats supported by temporal types are available in MSDN
- * page on data types.
+ * SQL Server supports numerous string literal formats for temporal types, hence sending them as varchar
+ * with approximate precision(length) needed to send supported string literals. string literal formats
+ * supported by temporal types are available in MSDN page on data types.
*/
case java.sql.Types.DATE:
case java.sql.Types.TIME:
case java.sql.Types.TIMESTAMP:
case microsoft.sql.Types.DATETIMEOFFSET:
- columnMetadata.put(positionInSource, new ColumnMetadata(colName, jdbcType, 50, scale, dateTimeFormatter));
+ columnMetadata.put(positionInSource,
+ new ColumnMetadata(colName, jdbcType, 50, scale, dateTimeFormatter));
break;
// Redirect SQLXML as LONGNVARCHAR
// SQLXML is not valid type in TDS
case java.sql.Types.SQLXML:
- columnMetadata.put(positionInSource, new ColumnMetadata(colName, java.sql.Types.LONGNVARCHAR, precision, scale, dateTimeFormatter));
+ columnMetadata.put(positionInSource,
+ new ColumnMetadata(colName, java.sql.Types.LONGNVARCHAR, precision, scale, dateTimeFormatter));
break;
// Redirecting Float as Double based on data type mapping
// https://msdn.microsoft.com/en-us/library/ms378878%28v=sql.110%29.aspx
case java.sql.Types.FLOAT:
- columnMetadata.put(positionInSource, new ColumnMetadata(colName, java.sql.Types.DOUBLE, precision, scale, dateTimeFormatter));
+ columnMetadata.put(positionInSource,
+ new ColumnMetadata(colName, java.sql.Types.DOUBLE, precision, scale, dateTimeFormatter));
break;
// redirecting BOOLEAN as BIT
case java.sql.Types.BOOLEAN:
- columnMetadata.put(positionInSource, new ColumnMetadata(colName, java.sql.Types.BIT, precision, scale, dateTimeFormatter));
+ columnMetadata.put(positionInSource,
+ new ColumnMetadata(colName, java.sql.Types.BIT, precision, scale, dateTimeFormatter));
break;
default:
- columnMetadata.put(positionInSource, new ColumnMetadata(colName, jdbcType, precision, scale, dateTimeFormatter));
+ columnMetadata.put(positionInSource,
+ new ColumnMetadata(colName, jdbcType, precision, scale, dateTimeFormatter));
}
loggerExternal.exiting(loggerClassName, "addColumnMetadata");
@@ -588,8 +576,7 @@ public void setTimeWithTimezoneFormat(DateTimeFormatter dateTimeFormatter) {
public boolean next() throws SQLServerException {
try {
currentLine = fileReader.readLine();
- }
- catch (IOException e) {
+ } catch (IOException e) {
throw new SQLServerException(e.getMessage(), null, 0, e);
}
return (null != currentLine);
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkCommon.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkCommon.java
index dee5350cc..4fdae1249 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkCommon.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkCommon.java
@@ -1,9 +1,6 @@
/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc;
@@ -13,147 +10,127 @@
import java.util.Map;
import java.util.Map.Entry;
+
abstract class SQLServerBulkCommon implements ISQLServerBulkRecord {
- /*
- * Class to represent the column metadata
- */
- protected class ColumnMetadata {
- String columnName;
- int columnType;
- int precision;
- int scale;
- DateTimeFormatter dateTimeFormatter = null;
-
- ColumnMetadata(String name, int type, int precision, int scale,
- DateTimeFormatter dateTimeFormatter) {
- columnName = name;
- columnType = type;
- this.precision = precision;
- this.scale = scale;
- this.dateTimeFormatter = dateTimeFormatter;
- }
- }
-
- /*
- * Contains all the column names if firstLineIsColumnNames is true
- */
- protected String[] columnNames = null;
-
- /*
- * Metadata to represent the columns in the batch/file. Each column should
- * be mapped to its corresponding position within the parameter (from
- * position 1 and onwards)
- */
- protected Map columnMetadata;
-
- /*
- * Contains the format that java.sql.Types.TIMESTAMP_WITH_TIMEZONE data
- * should be read in as.
- */
- protected DateTimeFormatter dateTimeFormatter = null;
-
- /*
- * Contains the format that java.sql.Types.TIME_WITH_TIMEZONE data should be
- * read in as.
- */
- protected DateTimeFormatter timeFormatter = null;
-
- @Override
- public void addColumnMetadata(int positionInSource, String name,
- int jdbcType, int precision, int scale,
- DateTimeFormatter dateTimeFormatter) throws SQLServerException {
- addColumnMetadataInternal(positionInSource, name, jdbcType, precision,
- scale, dateTimeFormatter);
- }
-
- @Override
- public void addColumnMetadata(int positionInSource, String name,
- int jdbcType, int precision, int scale) throws SQLServerException {
- addColumnMetadataInternal(positionInSource, name, jdbcType, precision,
- scale, null);
- }
-
- /**
- * Adds metadata for the given column in the batch/file.
- *
- * @param positionInSource
- * Indicates which column the metadata is for. Columns start at
- * 1.
- * @param name
- * Name for the column (optional if only using column ordinal in
- * a mapping for SQLServerBulkCopy operation)
- * @param jdbcType
- * JDBC data type of the column
- * @param precision
- * Precision for the column (ignored for the appropriate data
- * types)
- * @param scale
- * Scale for the column (ignored for the appropriate data types)
- * @param dateTimeFormatter
- * format to parse data that is sent
- * @throws SQLServerException
- * when an error occurs
- */
- void addColumnMetadataInternal(int positionInSource, String name,
- int jdbcType, int precision, int scale,
- DateTimeFormatter dateTimeFormatter) throws SQLServerException {
- }
-
- @Override
- public void setTimestampWithTimezoneFormat(String dateTimeFormat) {
- this.dateTimeFormatter = DateTimeFormatter.ofPattern(dateTimeFormat);
- }
-
- @Override
- public void setTimestampWithTimezoneFormat(
- DateTimeFormatter dateTimeFormatter) {
- this.dateTimeFormatter = dateTimeFormatter;
- }
-
- @Override
- public void setTimeWithTimezoneFormat(String timeFormat) {
- this.timeFormatter = DateTimeFormatter.ofPattern(timeFormat);
- }
-
- @Override
- public void setTimeWithTimezoneFormat(DateTimeFormatter dateTimeFormatter) {
- this.timeFormatter = dateTimeFormatter;
- }
-
- /*
- * Helper method to throw a SQLServerExeption with the invalidArgument
- * message and given argument.
- */
- protected void throwInvalidArgument(String argument)
- throws SQLServerException {
- MessageFormat form = new MessageFormat(
- SQLServerException.getErrString("R_invalidArgument"));
- Object[] msgArgs = {argument};
- SQLServerException.makeFromDriverError(null, null, form.format(msgArgs),
- null, false);
- }
-
- /*
- * Method to throw a SQLServerExeption for duplicate column names
- */
- protected void checkDuplicateColumnName(int positionInTable, String colName)
- throws SQLServerException {
-
- if (null != colName && colName.trim().length() != 0) {
- for (Entry entry : columnMetadata
- .entrySet()) {
- // duplicate check is not performed in case of same
- // positionInTable value
- if (null != entry && entry.getKey() != positionInTable) {
- if (null != entry.getValue() && colName.trim()
- .equalsIgnoreCase(entry.getValue().columnName)) {
- throw new SQLServerException(SQLServerException
- .getErrString("R_BulkDataDuplicateColumn"),
- null);
- }
- }
- }
- }
- }
+ /*
+ * Class to represent the column metadata
+ */
+ protected class ColumnMetadata {
+ String columnName;
+ int columnType;
+ int precision;
+ int scale;
+ DateTimeFormatter dateTimeFormatter = null;
+
+ ColumnMetadata(String name, int type, int precision, int scale, DateTimeFormatter dateTimeFormatter) {
+ columnName = name;
+ columnType = type;
+ this.precision = precision;
+ this.scale = scale;
+ this.dateTimeFormatter = dateTimeFormatter;
+ }
+ }
+
+ /*
+ * Contains all the column names if firstLineIsColumnNames is true
+ */
+ protected String[] columnNames = null;
+
+ /*
+ * Metadata to represent the columns in the batch/file. Each column should be mapped to its corresponding position
+ * within the parameter (from position 1 and onwards)
+ */
+ protected Map columnMetadata;
+
+ /*
+ * Contains the format that java.sql.Types.TIMESTAMP_WITH_TIMEZONE data should be read in as.
+ */
+ protected DateTimeFormatter dateTimeFormatter = null;
+
+ /*
+ * Contains the format that java.sql.Types.TIME_WITH_TIMEZONE data should be read in as.
+ */
+ protected DateTimeFormatter timeFormatter = null;
+
+ @Override
+ public void addColumnMetadata(int positionInSource, String name, int jdbcType, int precision, int scale,
+ DateTimeFormatter dateTimeFormatter) throws SQLServerException {
+ addColumnMetadataInternal(positionInSource, name, jdbcType, precision, scale, dateTimeFormatter);
+ }
+
+ @Override
+ public void addColumnMetadata(int positionInSource, String name, int jdbcType, int precision,
+ int scale) throws SQLServerException {
+ addColumnMetadataInternal(positionInSource, name, jdbcType, precision, scale, null);
+ }
+
+ /**
+ * Adds metadata for the given column in the batch/file.
+ *
+ * @param positionInSource
+ * Indicates which column the metadata is for. Columns start at 1.
+ * @param name
+ * Name for the column (optional if only using column ordinal in a mapping for SQLServerBulkCopy operation)
+ * @param jdbcType
+ * JDBC data type of the column
+ * @param precision
+ * Precision for the column (ignored for the appropriate data types)
+ * @param scale
+ * Scale for the column (ignored for the appropriate data types)
+ * @param dateTimeFormatter
+ * format to parse data that is sent
+ * @throws SQLServerException
+ * when an error occurs
+ */
+ void addColumnMetadataInternal(int positionInSource, String name, int jdbcType, int precision, int scale,
+ DateTimeFormatter dateTimeFormatter) throws SQLServerException {}
+
+ @Override
+ public void setTimestampWithTimezoneFormat(String dateTimeFormat) {
+ this.dateTimeFormatter = DateTimeFormatter.ofPattern(dateTimeFormat);
+ }
+
+ @Override
+ public void setTimestampWithTimezoneFormat(DateTimeFormatter dateTimeFormatter) {
+ this.dateTimeFormatter = dateTimeFormatter;
+ }
+
+ @Override
+ public void setTimeWithTimezoneFormat(String timeFormat) {
+ this.timeFormatter = DateTimeFormatter.ofPattern(timeFormat);
+ }
+
+ @Override
+ public void setTimeWithTimezoneFormat(DateTimeFormatter dateTimeFormatter) {
+ this.timeFormatter = dateTimeFormatter;
+ }
+
+ /*
+ * Helper method to throw a SQLServerExeption with the invalidArgument message and given argument.
+ */
+ protected void throwInvalidArgument(String argument) throws SQLServerException {
+ MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidArgument"));
+ Object[] msgArgs = {argument};
+ SQLServerException.makeFromDriverError(null, null, form.format(msgArgs), null, false);
+ }
+
+ /*
+ * Method to throw a SQLServerExeption for duplicate column names
+ */
+ protected void checkDuplicateColumnName(int positionInTable, String colName) throws SQLServerException {
+
+ if (null != colName && colName.trim().length() != 0) {
+ for (Entry entry : columnMetadata.entrySet()) {
+ // duplicate check is not performed in case of same
+ // positionInTable value
+ if (null != entry && entry.getKey() != positionInTable) {
+ if (null != entry.getValue() && colName.trim().equalsIgnoreCase(entry.getValue().columnName)) {
+ throw new SQLServerException(SQLServerException.getErrString("R_BulkDataDuplicateColumn"),
+ null);
+ }
+ }
+ }
+ }
+ }
}
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkCopy.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkCopy.java
index 9122c44fa..90ea08396 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkCopy.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkCopy.java
@@ -1,9 +1,6 @@
/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc;
@@ -51,23 +48,26 @@
import microsoft.sql.DateTimeOffset;
+
/**
- * Lets you efficiently bulk load a SQL Server table with data from another source.
+ * Provides functionality to efficiently bulk load a SQL Server table with data from another source.
*
- * Microsoft SQL Server includes a popular command-prompt utility named bcp for moving data from one table to another, whether on a single server or
- * between servers. The SQLServerBulkCopy class lets you write code solutions in Java that provide similar functionality. There are other ways to load
- * data into a SQL Server table (INSERT statements, for example), but SQLServerBulkCopy offers a significant performance advantage over them.
- * The SQLServerBulkCopy class can be used to write data only to SQL Server tables. However, the data source is not limited to SQL Server; any data
- * source can be used, as long as the data can be read with a ResultSet or ISQLServerBulkRecord instance.
+ * Microsoft SQL Server includes a popular command-prompt utility named bcp for moving data from one table to another,
+ * whether on a single server or between servers. The SQLServerBulkCopy class lets you write code solutions in Java that
+ * provide similar functionality. There are other ways to load data into a SQL Server table (INSERT statements, for
+ * example), but SQLServerBulkCopy offers a significant performance advantage over them.
+ * The SQLServerBulkCopy class can be used to write data only to SQL Server tables. However, the data source is not
+ * limited to SQL Server; any data source can be used, as long as the data can be read with a ResultSet or
+ * ISQLServerBulkRecord instance.
*/
public class SQLServerBulkCopy implements java.lang.AutoCloseable, java.io.Serializable {
/**
- *
- */
- private static final long serialVersionUID = 1989903904654306244L;
+ * Update serialVersionUID when making changes to this file
+ */
+ private static final long serialVersionUID = 1989903904654306244L;
- /*
- * Class to represent the column mappings between the source and destination table
+ /**
+ * Represents the column mappings between the source and destination table
*/
private class ColumnMapping {
String sourceColumnName = null;
@@ -75,100 +75,97 @@ private class ColumnMapping {
String destinationColumnName = null;
int destinationColumnOrdinal = -1;
- ColumnMapping(String source,
- String dest) {
+ ColumnMapping(String source, String dest) {
this.sourceColumnName = source;
this.destinationColumnName = dest;
}
- ColumnMapping(String source,
- int dest) {
+ ColumnMapping(String source, int dest) {
this.sourceColumnName = source;
this.destinationColumnOrdinal = dest;
}
- ColumnMapping(int source,
- String dest) {
+ ColumnMapping(int source, String dest) {
this.sourceColumnOrdinal = source;
this.destinationColumnName = dest;
}
- ColumnMapping(int source,
- int dest) {
+ ColumnMapping(int source, int dest) {
this.sourceColumnOrdinal = source;
this.destinationColumnOrdinal = dest;
}
}
- /*
+ /**
* Class name for logging.
*/
private static final String loggerClassName = "com.microsoft.sqlserver.jdbc.SQLServerBulkCopy";
private static final int SQL_SERVER_2016_VERSION = 13;
- /*
+ /**
* Logger
*/
private static final java.util.logging.Logger loggerExternal = java.util.logging.Logger.getLogger(loggerClassName);
- /*
+ /**
* Destination server connection.
*/
private SQLServerConnection connection;
- /*
+ /**
* Options to control how the WriteToServer methods behave.
*/
private SQLServerBulkCopyOptions copyOptions;
- /*
+ /**
* Mappings between columns in the data source and columns in the destination
*/
private List columnMappings;
- /*
+ /**
* Flag if SQLServerBulkCopy owns the connection and should close it when Close is called
*/
private boolean ownsConnection;
- /*
- * Name of destination table on server.
- *
- * If destinationTable has not been set when WriteToServer is called, an Exception is thrown.
- *
- * destinationTable is a three-part name (..). You can qualify the table name with its database and owning schema if
- * you choose. However, if the table name uses an underscore ("_") or any other special characters, you must escape the name using surrounding
- * brackets. For more information, see "Identifiers" in SQL Server Books Online.
- *
- * You can bulk-copy data to a temporary table by using a value such as tempdb..#table or tempdb..#table for the destinationTable property.
+ /**
+ * Name of destination table on server. If destinationTable has not been set when WriteToServer is called, an
+ * Exception is thrown. destinationTable is a three-part name {@code (..)}. You can
+ * qualify the table name with its database and owning schema if you choose. However, if the table name uses an
+ * underscore ("_") or any other special characters, you must escape the name using surrounding brackets. For more
+ * information, see "Identifiers" in SQL Server Books Online. You can bulk-copy data to a temporary table by using a
+ * value such as {@code tempdb..#table or tempdb..#table} for the destinationTable property.
*/
private String destinationTableName;
- /*
+ /**
* Source data (from a Record). Is null unless the corresponding version of writeToServer is called.
*/
private ISQLServerBulkRecord sourceBulkRecord;
- /*
+ /**
* Source data (from ResultSet). Is null unless the corresponding version of writeToServer is called.
*/
private ResultSet sourceResultSet;
- /*
+ /**
* Metadata for the source table columns
*/
private ResultSetMetaData sourceResultSetMetaData;
- /* The CekTable for the destination table. */
+ /**
+ * The CekTable for the destination table.
+ */
private CekTable destCekTable = null;
- /* Statement level encryption setting needed for querying against encrypted columns. */
+ /**
+ * Statement level encryption setting needed for querying against encrypted columns.
+ */
private SQLServerStatementColumnEncryptionSetting stmtColumnEncriptionSetting = SQLServerStatementColumnEncryptionSetting.UseConnectionSetting;
-
+
private ResultSet destinationTableMetadata;
-
- /*
+
+ /**
* Metadata for the destination table columns
*/
class BulkColumnMetaData {
@@ -202,11 +199,7 @@ class BulkColumnMetaData {
}
// This constructor is needed for the source meta data.
- BulkColumnMetaData(String colName,
- boolean isNullable,
- int precision,
- int scale,
- int jdbcType,
+ BulkColumnMetaData(String colName, boolean isNullable, int precision, int scale, int jdbcType,
DateTimeFormatter dateTimeFormatter) throws SQLServerException {
this.columnName = colName;
this.isNullable = isNullable;
@@ -216,17 +209,14 @@ class BulkColumnMetaData {
this.dateTimeFormatter = dateTimeFormatter;
}
- BulkColumnMetaData(Column column,
- String collationName,
- String encryptionType) throws SQLServerException {
+ BulkColumnMetaData(Column column, String collationName, String encryptionType) throws SQLServerException {
this(column);
this.collationName = collationName;
this.encryptionType = encryptionType;
}
// update the cryptoMeta of source when reading from forward only resultset
- BulkColumnMetaData(BulkColumnMetaData bulkColumnMetaData,
- CryptoMetadata cryptoMeta) {
+ BulkColumnMetaData(BulkColumnMetaData bulkColumnMetaData, CryptoMetadata cryptoMeta) {
this.columnName = bulkColumnMetaData.columnName;
this.isNullable = bulkColumnMetaData.isNullable;
this.precision = bulkColumnMetaData.precision;
@@ -236,28 +226,29 @@ class BulkColumnMetaData {
}
};
- /*
+ /**
* A map to store the metadata information for the destination table.
*/
private Map destColumnMetadata;
- /*
+ /**
* A map to store the metadata information for the source table.
*/
private Map srcColumnMetadata;
- /*
+ /**
* Variable to store destination column count.
*/
private int destColumnCount;
- /*
+ /**
* Variable to store source column count.
*/
private int srcColumnCount;
- /*
- * Timer for the bulk copy operation. The other timeout timers in the TDS layer only measure the response of the first packet from SQL Server.
+ /**
+ * Timer for the bulk copy operation. The other timeout timers in the TDS layer only measure the response of the
+ * first packet from SQL Server.
*/
private final class BulkTimeoutTimer implements Runnable {
private final int timeoutSeconds;
@@ -266,8 +257,7 @@ private final class BulkTimeoutTimer implements Runnable {
private Thread timerThread;
private volatile boolean canceled = false;
- BulkTimeoutTimer(int timeoutSeconds,
- TDSCommand command) {
+ BulkTimeoutTimer(int timeoutSeconds, TDSCommand command) {
assert timeoutSeconds > 0;
assert null != command;
@@ -300,10 +290,8 @@ public void run() {
return;
Thread.sleep(1000);
- }
- while (--secondsRemaining > 0);
- }
- catch (InterruptedException e) {
+ } while (--secondsRemaining > 0);
+ } catch (InterruptedException e) {
// re-interrupt the current thread, in order to restore the thread's interrupt status.
Thread.currentThread().interrupt();
return;
@@ -313,8 +301,7 @@ public void run() {
// time then interrupt the registered command.
try {
command.interrupt(SQLServerException.getErrString("R_queryTimedOut"));
- }
- catch (SQLServerException e) {
+ } catch (SQLServerException e) {
// Unfortunately, there's nothing we can do if we
// fail to time out the request. There is no way
// to report back what happened.
@@ -324,33 +311,34 @@ public void run() {
}
private BulkTimeoutTimer timeoutTimer = null;
-
+
/**
- * The maximum temporal precision we can send when using varchar(precision) in bulkcommand, to send a smalldatetime/datetime
- * value.
+ * The maximum temporal precision we can send when using varchar(precision) in bulkcommand, to send a
+ * smalldatetime/datetime value.
*/
private static final int sourceBulkRecordTemporalMaxPrecision = 50;
/**
- * Initializes a new instance of the SQLServerBulkCopy class using the specified open instance of SQLServerConnection.
+ * Constructs a SQLServerBulkCopy using the specified open instance of SQLServerConnection.
*
* @param connection
- * Open instance of Connection to destination server. Must be from the Microsoft JDBC driver for SQL Server.
+ * Open instance of Connection to destination server. Must be from the Microsoft JDBC driver for SQL Server.
* @throws SQLServerException
- * If the supplied type is not a connection from the Microsoft JDBC driver for SQL Server.
+ * If the supplied type is not a connection from the Microsoft JDBC driver for SQL Server.
*/
public SQLServerBulkCopy(Connection connection) throws SQLServerException {
loggerExternal.entering(loggerClassName, "SQLServerBulkCopy", connection);
if (null == connection || !(connection instanceof SQLServerConnection)) {
- SQLServerException.makeFromDriverError(null, null, SQLServerException.getErrString("R_invalidDestConnection"), null, false);
+ SQLServerException.makeFromDriverError(null, null,
+ SQLServerException.getErrString("R_invalidDestConnection"), null, false);
}
if (connection instanceof SQLServerConnection) {
this.connection = (SQLServerConnection) connection;
- }
- else {
- SQLServerException.makeFromDriverError(null, null, SQLServerException.getErrString("R_invalidDestConnection"), null, false);
+ } else {
+ SQLServerException.makeFromDriverError(null, null,
+ SQLServerException.getErrString("R_invalidDestConnection"), null, false);
}
ownsConnection = false;
@@ -364,12 +352,12 @@ public SQLServerBulkCopy(Connection connection) throws SQLServerException {
}
/**
- * Initializes and opens a new instance of SQLServerConnection based on the supplied connectionString.
+ * Constructs a SQLServerBulkCopy based on the supplied connectionString.
*
* @param connectionUrl
- * Connection string for the destination server.
+ * Connection string for the destination server.
* @throws SQLServerException
- * If a connection cannot be established.
+ * If a connection cannot be established.
*/
public SQLServerBulkCopy(String connectionUrl) throws SQLServerException {
loggerExternal.entering(loggerClassName, "SQLServerBulkCopy", "connectionUrl not traced.");
@@ -395,20 +383,18 @@ public SQLServerBulkCopy(String connectionUrl) throws SQLServerException {
* Adds a new column mapping, using ordinals to specify both the source and destination columns.
*
* @param sourceColumn
- * Source column ordinal.
+ * Source column ordinal.
* @param destinationColumn
- * Destination column ordinal.
+ * Destination column ordinal.
* @throws SQLServerException
- * If the column mapping is invalid
+ * If the column mapping is invalid
*/
- public void addColumnMapping(int sourceColumn,
- int destinationColumn) throws SQLServerException {
+ public void addColumnMapping(int sourceColumn, int destinationColumn) throws SQLServerException {
loggerExternal.entering(loggerClassName, "addColumnMapping", new Object[] {sourceColumn, destinationColumn});
if (0 >= sourceColumn) {
throwInvalidArgument("sourceColumn");
- }
- else if (0 >= destinationColumn) {
+ } else if (0 >= destinationColumn) {
throwInvalidArgument("destinationColumn");
}
columnMappings.add(new ColumnMapping(sourceColumn, destinationColumn));
@@ -420,20 +406,18 @@ else if (0 >= destinationColumn) {
* Adds a new column mapping, using an ordinal for the source column and a string for the destination column.
*
* @param sourceColumn
- * Source column ordinal.
+ * Source column ordinal.
* @param destinationColumn
- * Destination column name.
+ * Destination column name.
* @throws SQLServerException
- * If the column mapping is invalid
+ * If the column mapping is invalid
*/
- public void addColumnMapping(int sourceColumn,
- String destinationColumn) throws SQLServerException {
+ public void addColumnMapping(int sourceColumn, String destinationColumn) throws SQLServerException {
loggerExternal.entering(loggerClassName, "addColumnMapping", new Object[] {sourceColumn, destinationColumn});
if (0 >= sourceColumn) {
throwInvalidArgument("sourceColumn");
- }
- else if (null == destinationColumn || destinationColumn.isEmpty()) {
+ } else if (null == destinationColumn || destinationColumn.isEmpty()) {
throwInvalidArgument("destinationColumn");
}
columnMappings.add(new ColumnMapping(sourceColumn, destinationColumn.trim()));
@@ -442,23 +426,22 @@ else if (null == destinationColumn || destinationColumn.isEmpty()) {
}
/**
- * Adds a new column mapping, using a column name to describe the source column and an ordinal to specify the destination column.
+ * Adds a new column mapping, using a column name to describe the source column and an ordinal to specify the
+ * destination column.
*
* @param sourceColumn
- * Source column name.
+ * Source column name.
* @param destinationColumn
- * Destination column ordinal.
+ * Destination column ordinal.
* @throws SQLServerException
- * If the column mapping is invalid
+ * If the column mapping is invalid
*/
- public void addColumnMapping(String sourceColumn,
- int destinationColumn) throws SQLServerException {
+ public void addColumnMapping(String sourceColumn, int destinationColumn) throws SQLServerException {
loggerExternal.entering(loggerClassName, "addColumnMapping", new Object[] {sourceColumn, destinationColumn});
if (0 >= destinationColumn) {
throwInvalidArgument("destinationColumn");
- }
- else if (null == sourceColumn || sourceColumn.isEmpty()) {
+ } else if (null == sourceColumn || sourceColumn.isEmpty()) {
throwInvalidArgument("sourceColumn");
}
columnMappings.add(new ColumnMapping(sourceColumn.trim(), destinationColumn));
@@ -470,20 +453,18 @@ else if (null == sourceColumn || sourceColumn.isEmpty()) {
* Adds a new column mapping, using column names to specify both source and destination columns.
*
* @param sourceColumn
- * Source column name.
+ * Source column name.
* @param destinationColumn
- * Destination column name.
+ * Destination column name.
* @throws SQLServerException
- * If the column mapping is invalid
+ * If the column mapping is invalid
*/
- public void addColumnMapping(String sourceColumn,
- String destinationColumn) throws SQLServerException {
+ public void addColumnMapping(String sourceColumn, String destinationColumn) throws SQLServerException {
loggerExternal.entering(loggerClassName, "addColumnMapping", new Object[] {sourceColumn, destinationColumn});
if (null == sourceColumn || sourceColumn.isEmpty()) {
throwInvalidArgument("sourceColumn");
- }
- else if (null == destinationColumn || destinationColumn.isEmpty()) {
+ } else if (null == destinationColumn || destinationColumn.isEmpty()) {
throwInvalidArgument("destinationColumn");
}
columnMappings.add(new ColumnMapping(sourceColumn.trim(), destinationColumn.trim()));
@@ -511,8 +492,7 @@ public void close() {
if (ownsConnection) {
try {
connection.close();
- }
- catch (SQLException e) {
+ } catch (SQLException e) {
// Ignore this exception
}
}
@@ -521,7 +501,7 @@ public void close() {
}
/**
- * Gets the name of the destination table on the server.
+ * Returns the name of the destination table on the server.
*
* @return Destination table name.
*/
@@ -533,9 +513,9 @@ public String getDestinationTableName() {
* Sets the name of the destination table on the server.
*
* @param tableName
- * Destination table name.
+ * Destination table name.
* @throws SQLServerException
- * If the table name is null
+ * If the table name is null
*/
public void setDestinationTableName(String tableName) throws SQLServerException {
loggerExternal.entering(loggerClassName, "setDestinationTableName", tableName);
@@ -550,7 +530,7 @@ public void setDestinationTableName(String tableName) throws SQLServerException
}
/**
- * Gets the current SQLServerBulkCopyOptions.
+ * Returns the current SQLServerBulkCopyOptions.
*
* @return Current SQLServerBulkCopyOptions settings.
*/
@@ -559,13 +539,14 @@ public SQLServerBulkCopyOptions getBulkCopyOptions() {
}
/**
- * Update the behavior of the SQLServerBulkCopy instance according to the options supplied, if supplied SQLServerBulkCopyOption is not null.
+ * Update the behavior of the SQLServerBulkCopy instance according to the options supplied, if supplied
+ * SQLServerBulkCopyOption is not null.
*
* @param copyOptions
- * Settings to change how the WriteToServer methods behave.
+ * Settings to change how the WriteToServer methods behave.
* @throws SQLServerException
- * If the SQLServerBulkCopyOption class was constructed using an existing Connection and the UseInternalTransaction option is
- * specified.
+ * If the SQLServerBulkCopyOption class was constructed using an existing Connection and the
+ * UseInternalTransaction option is specified.
*/
public void setBulkCopyOptions(SQLServerBulkCopyOptions copyOptions) throws SQLServerException {
loggerExternal.entering(loggerClassName, "updateBulkCopyOptions", copyOptions);
@@ -576,7 +557,8 @@ public void setBulkCopyOptions(SQLServerBulkCopyOptions copyOptions) throws SQLS
// Setting it with an external connection object should throw
// exception.
if (!ownsConnection && copyOptions.isUseInternalTransaction()) {
- SQLServerException.makeFromDriverError(null, null, SQLServerException.getErrString("R_invalidTransactionOption"), null, false);
+ SQLServerException.makeFromDriverError(null, null,
+ SQLServerException.getErrString("R_invalidTransactionOption"), null, false);
}
this.copyOptions = copyOptions;
@@ -585,42 +567,42 @@ public void setBulkCopyOptions(SQLServerBulkCopyOptions copyOptions) throws SQLS
}
/**
- * Copies all rows in the supplied ResultSet to a destination table specified by the destinationTableName property of the SQLServerBulkCopy
- * object.
+ * Copies all rows in the supplied ResultSet to a destination table specified by the destinationTableName property
+ * of the SQLServerBulkCopy object.
*
* @param sourceData
- * ResultSet to read data rows from.
+ * ResultSet to read data rows from.
* @throws SQLServerException
- * If there are any issues encountered when performing the bulk copy operation
+ * If there are any issues encountered when performing the bulk copy operation
*/
public void writeToServer(ResultSet sourceData) throws SQLServerException {
writeResultSet(sourceData, false);
}
/**
- * Copies all rows in the supplied RowSet to a destination table specified by the destinationTableName property of the SQLServerBulkCopy object.
+ * Copies all rows in the supplied RowSet to a destination table specified by the destinationTableName property of
+ * the SQLServerBulkCopy object.
*
* @param sourceData
- * RowSet to read data rows from.
+ * RowSet to read data rows from.
* @throws SQLServerException
- * If there are any issues encountered when performing the bulk copy operation
+ * If there are any issues encountered when performing the bulk copy operation
*/
public void writeToServer(RowSet sourceData) throws SQLServerException {
writeResultSet(sourceData, true);
}
/**
- * Copies all rows in the supplied ResultSet to a destination table specified by the destinationTableName property of the SQLServerBulkCopy
- * object.
+ * Copies all rows in the supplied ResultSet to a destination table specified by the destinationTableName property
+ * of the SQLServerBulkCopy object.
*
* @param sourceData
- * ResultSet to read data rows from.
+ * ResultSet to read data rows from.
* @param isRowSet
* @throws SQLServerException
- * If there are any issues encountered when performing the bulk copy operation
+ * If there are any issues encountered when performing the bulk copy operation
*/
- private void writeResultSet(ResultSet sourceData,
- boolean isRowSet) throws SQLServerException {
+ private void writeResultSet(ResultSet sourceData, boolean isRowSet) throws SQLServerException {
loggerExternal.entering(loggerClassName, "writeToServer");
if (null == sourceData) {
@@ -628,19 +610,19 @@ private void writeResultSet(ResultSet sourceData,
}
try {
- if (isRowSet) // Default RowSet implementation in Java doesn't have isClosed() implemented so need to do an alternate check instead.
+ if (isRowSet) // Default RowSet implementation in Java doesn't have isClosed() implemented so need to do an
+ // alternate check instead.
{
if (!sourceData.isBeforeFirst()) {
sourceData.beforeFirst();
}
- }
- else {
+ } else {
if (sourceData.isClosed()) {
- SQLServerException.makeFromDriverError(null, null, SQLServerException.getErrString("R_resultsetClosed"), null, false);
+ SQLServerException.makeFromDriverError(null, null,
+ SQLServerException.getErrString("R_resultsetClosed"), null, false);
}
}
- }
- catch (SQLException e) {
+ } catch (SQLException e) {
throw new SQLServerException(null, e.getMessage(), null, 0, false);
}
@@ -652,8 +634,7 @@ private void writeResultSet(ResultSet sourceData,
// Save the resultset metadata as it is used in many places.
try {
sourceResultSetMetaData = sourceResultSet.getMetaData();
- }
- catch (SQLException e) {
+ } catch (SQLException e) {
throw new SQLServerException(SQLServerException.getErrString("R_unableRetrieveColMeta"), e);
}
@@ -663,13 +644,13 @@ private void writeResultSet(ResultSet sourceData,
}
/**
- * Copies all rows from the supplied ISQLServerBulkRecord to a destination table specified by the destinationTableName property of the
- * SQLServerBulkCopy object.
+ * Copies all rows from the supplied ISQLServerBulkRecord to a destination table specified by the
+ * destinationTableName property of the SQLServerBulkCopy object.
*
* @param sourceData
- * SQLServerBulkReader to read data rows from.
+ * SQLServerBulkReader to read data rows from.
* @throws SQLServerException
- * If there are any issues encountered when performing the bulk copy operation
+ * If there are any issues encountered when performing the bulk copy operation
*/
public void writeToServer(ISQLServerBulkRecord sourceData) throws SQLServerException {
loggerExternal.entering(loggerClassName, "writeToServer");
@@ -686,7 +667,7 @@ public void writeToServer(ISQLServerBulkRecord sourceData) throws SQLServerExcep
loggerExternal.exiting(loggerClassName, "writeToServer");
}
- /*
+ /**
* Initializes the defaults for member variables that require it.
*/
private void initializeDefaults() {
@@ -721,10 +702,8 @@ final boolean doExecute() throws SQLServerException {
// the resultset, false otherwise. We keep sending rows, one batch at a time until the
// resultset is done.
try {
- while (doInsertBulk(this))
- ;
- }
- catch (SQLServerException topLevelException) {
+ while (doInsertBulk(this));
+ } catch (SQLServerException topLevelException) {
// Get to the root of this exception.
Throwable rootCause = topLevelException;
while (null != rootCause.getCause()) {
@@ -754,11 +733,10 @@ final boolean doExecute() throws SQLServerException {
connection.executeCommand(new InsertBulk());
}
- /*
+ /**
* write ColumnData token in COLMETADATA header
*/
- private void writeColumnMetaDataColumnData(TDSWriter tdsWriter,
- int idx) throws SQLServerException {
+ private void writeColumnMetaDataColumnData(TDSWriter tdsWriter, int idx) throws SQLServerException {
int srcColumnIndex, destPrecision;
int bulkJdbcType, bulkPrecision, bulkScale;
SQLCollation collation;
@@ -766,8 +744,8 @@ private void writeColumnMetaDataColumnData(TDSWriter tdsWriter,
boolean isStreaming, srcNullable;
// For varchar, precision is the size of the varchar type.
/*
- * UserType USHORT/ULONG; (Changed to ULONG in TDS 7.2) The user type ID of the data type of the column. The value will be 0x0000 with the
- * exceptions of TIMESTAMP (0x0050) and alias types (greater than 0x00FF)
+ * UserType USHORT/ULONG; (Changed to ULONG in TDS 7.2) The user type ID of the data type of the column. The
+ * value will be 0x0000 with the exceptions of TIMESTAMP (0x0050) and alias types (greater than 0x00FF)
*/
byte[] userType = new byte[4];
userType[0] = (byte) 0x00;
@@ -776,13 +754,13 @@ private void writeColumnMetaDataColumnData(TDSWriter tdsWriter,
userType[3] = (byte) 0x00;
tdsWriter.writeBytes(userType);
- /*
- * Flags token - Bit flags in least significant bit order https://msdn.microsoft.com/en-us/library/dd357363.aspx flags[0] = (byte) 0x05;
- * flags[1] = (byte) 0x00;
+ /**
+ * Flags token - Bit flags in least significant bit order https://msdn.microsoft.com/en-us/library/dd357363.aspx
+ * flags[0] = (byte) 0x05; flags[1] = (byte) 0x00;
*/
int destColumnIndex = columnMappings.get(idx).destinationColumnOrdinal;
- /*
+ /**
* TYPE_INFO FIXEDLENTYPE Example INT: tdsWriter.writeByte((byte) 0x38);
*/
srcColumnIndex = columnMappings.get(idx).sourceColumnOrdinal;
@@ -790,7 +768,8 @@ private void writeColumnMetaDataColumnData(TDSWriter tdsWriter,
byte flags[] = destColumnMetadata.get(destColumnIndex).flags;
// If AllowEncryptedValueModification is set to true (and of course AE is off),
// the driver will not sent AE information, so, we need to set Encryption bit flag to 0.
- if (null == srcColumnMetadata.get(srcColumnIndex).cryptoMeta && null == destColumnMetadata.get(destColumnIndex).cryptoMeta
+ if (null == srcColumnMetadata.get(srcColumnIndex).cryptoMeta
+ && null == destColumnMetadata.get(destColumnIndex).cryptoMeta
&& true == copyOptions.isAllowEncryptedValueModifications()) {
// flags[1]>>3 & 0x01 is the encryption bit flag.
@@ -815,55 +794,57 @@ private void writeColumnMetaDataColumnData(TDSWriter tdsWriter,
if (null == collation)
collation = connection.getDatabaseCollation();
- if ((java.sql.Types.NCHAR == bulkJdbcType) || (java.sql.Types.NVARCHAR == bulkJdbcType) || (java.sql.Types.LONGNVARCHAR == bulkJdbcType)) {
- isStreaming = (DataTypes.SHORT_VARTYPE_MAX_CHARS < bulkPrecision) || (DataTypes.SHORT_VARTYPE_MAX_CHARS < destPrecision);
- }
- else {
- isStreaming = (DataTypes.SHORT_VARTYPE_MAX_BYTES < bulkPrecision) || (DataTypes.SHORT_VARTYPE_MAX_BYTES < destPrecision);
+ if ((java.sql.Types.NCHAR == bulkJdbcType) || (java.sql.Types.NVARCHAR == bulkJdbcType)
+ || (java.sql.Types.LONGNVARCHAR == bulkJdbcType)) {
+ isStreaming = (DataTypes.SHORT_VARTYPE_MAX_CHARS < bulkPrecision)
+ || (DataTypes.SHORT_VARTYPE_MAX_CHARS < destPrecision);
+ } else {
+ isStreaming = (DataTypes.SHORT_VARTYPE_MAX_BYTES < bulkPrecision)
+ || (DataTypes.SHORT_VARTYPE_MAX_BYTES < destPrecision);
}
CryptoMetadata destCryptoMeta = destColumnMetadata.get(destColumnIndex).cryptoMeta;
-
+
/*
- * if source is encrypted and destination is unenecrypted, use destination's sql type to send since there is no way of finding if source is
- * encrypted without accessing the resultset.
- *
- * Send destination type if source resultset set is of type SQLServer, encryption is enabled and destination column is not encrypted
+ * if source is encrypted and destination is unenecrypted, use destination's sql type to send since there is no
+ * way of finding if source is encrypted without accessing the resultset. Send destination type if source
+ * resultset set is of type SQLServer, encryption is enabled and destination column is not encrypted
*/
- if ((sourceResultSet instanceof SQLServerResultSet) && (connection.isColumnEncryptionSettingEnabled()) && (null != destCryptoMeta)) {
+ if ((sourceResultSet instanceof SQLServerResultSet) && (connection.isColumnEncryptionSettingEnabled())
+ && (null != destCryptoMeta)) {
bulkJdbcType = destColumnMetadata.get(destColumnIndex).jdbcType;
bulkPrecision = destPrecision;
bulkScale = destColumnMetadata.get(destColumnIndex).scale;
}
// use varbinary to send if destination is encrypted
- if (((null != destColumnMetadata.get(destColumnIndex).encryptionType) && copyOptions.isAllowEncryptedValueModifications())
+ if (((null != destColumnMetadata.get(destColumnIndex).encryptionType)
+ && copyOptions.isAllowEncryptedValueModifications())
|| (null != destColumnMetadata.get(destColumnIndex).cryptoMeta)) {
tdsWriter.writeByte((byte) 0xA5);
if (isStreaming) {
tdsWriter.writeShort((short) 0xFFFF);
- }
- else {
+ } else {
tdsWriter.writeShort((short) (bulkPrecision));
}
}
// In this case we will explicitly send binary value.
- else if (((java.sql.Types.CHAR == bulkJdbcType) || (java.sql.Types.VARCHAR == bulkJdbcType) || (java.sql.Types.LONGVARCHAR == bulkJdbcType))
+ else if (((java.sql.Types.CHAR == bulkJdbcType) || (java.sql.Types.VARCHAR == bulkJdbcType)
+ || (java.sql.Types.LONGVARCHAR == bulkJdbcType))
&& (SSType.BINARY == destSSType || SSType.VARBINARY == destSSType || SSType.VARBINARYMAX == destSSType
|| SSType.IMAGE == destSSType)) {
if (isStreaming) {
// Send as VARBINARY if streaming is enabled
tdsWriter.writeByte((byte) 0xA5);
- }
- else {
+ } else {
tdsWriter.writeByte((byte) ((SSType.BINARY == destSSType) ? 0xAD : 0xA5));
}
tdsWriter.writeShort((short) (bulkPrecision));
- }
- else {
- writeTypeInfo(tdsWriter, bulkJdbcType, bulkScale, bulkPrecision, destSSType, collation, isStreaming, srcNullable, false);
+ } else {
+ writeTypeInfo(tdsWriter, bulkJdbcType, bulkScale, bulkPrecision, destSSType, collation, isStreaming,
+ srcNullable, false);
}
if (null != destCryptoMeta) {
@@ -877,8 +858,8 @@ else if (((java.sql.Types.CHAR == bulkJdbcType) || (java.sql.Types.VARCHAR == bu
isStreaming = (DataTypes.SHORT_VARTYPE_MAX_BYTES < baseDestPrecision);
// Send CryptoMetaData
- tdsWriter.writeShort(destCryptoMeta.getOrdinal()); // Ordinal
- tdsWriter.writeBytes(userType); // usertype
+ tdsWriter.writeShort(destCryptoMeta.getOrdinal()); // Ordinal
+ tdsWriter.writeBytes(userType); // usertype
// BaseTypeInfo
writeTypeInfo(tdsWriter, baseDestJDBCType, destCryptoMeta.baseTypeInfo.getScale(), baseDestPrecision,
destCryptoMeta.baseTypeInfo.getSSType(), collation, isStreaming, srcNullable, true);
@@ -888,7 +869,8 @@ else if (((java.sql.Types.CHAR == bulkJdbcType) || (java.sql.Types.VARCHAR == bu
}
/*
- * ColName token The column name. Contains the column name length and column name. see: SQLServerConnection.java toUCS16(String s)
+ * ColName token The column name. Contains the column name length and column name. see: SQLServerConnection.java
+ * toUCS16(String s)
*/
int destColNameLen = columnMappings.get(idx).destinationColumnName.length();
String destColName = columnMappings.get(idx).destinationColumnName;
@@ -904,21 +886,14 @@ else if (((java.sql.Types.CHAR == bulkJdbcType) || (java.sql.Types.VARCHAR == bu
tdsWriter.writeBytes(colName);
}
- private void writeTypeInfo(TDSWriter tdsWriter,
- int srcJdbcType,
- int srcScale,
- int srcPrecision,
- SSType destSSType,
- SQLCollation collation,
- boolean isStreaming,
- boolean srcNullable,
+ private void writeTypeInfo(TDSWriter tdsWriter, int srcJdbcType, int srcScale, int srcPrecision, SSType destSSType,
+ SQLCollation collation, boolean isStreaming, boolean srcNullable,
boolean isBaseType) throws SQLServerException {
switch (srcJdbcType) {
case java.sql.Types.INTEGER: // 0x38
if (!srcNullable) {
tdsWriter.writeByte(TDSType.INT4.byteValue());
- }
- else {
+ } else {
tdsWriter.writeByte(TDSType.INTN.byteValue());
tdsWriter.writeByte((byte) 0x04);
}
@@ -927,8 +902,7 @@ private void writeTypeInfo(TDSWriter tdsWriter,
case java.sql.Types.BIGINT: // 0x7f
if (!srcNullable) {
tdsWriter.writeByte(TDSType.INT8.byteValue());
- }
- else {
+ } else {
tdsWriter.writeByte(TDSType.INTN.byteValue());
tdsWriter.writeByte((byte) 0x08);
}
@@ -937,8 +911,7 @@ private void writeTypeInfo(TDSWriter tdsWriter,
case java.sql.Types.BIT: // 0x32
if (!srcNullable) {
tdsWriter.writeByte(TDSType.BIT1.byteValue());
- }
- else {
+ } else {
tdsWriter.writeByte(TDSType.BITN.byteValue());
tdsWriter.writeByte((byte) 0x01);
}
@@ -947,8 +920,7 @@ private void writeTypeInfo(TDSWriter tdsWriter,
case java.sql.Types.SMALLINT: // 0x34
if (!srcNullable) {
tdsWriter.writeByte(TDSType.INT2.byteValue());
- }
- else {
+ } else {
tdsWriter.writeByte(TDSType.INTN.byteValue());
tdsWriter.writeByte((byte) 0x02);
}
@@ -957,8 +929,7 @@ private void writeTypeInfo(TDSWriter tdsWriter,
case java.sql.Types.TINYINT: // 0x30
if (!srcNullable) {
tdsWriter.writeByte(TDSType.INT1.byteValue());
- }
- else {
+ } else {
tdsWriter.writeByte(TDSType.INTN.byteValue());
tdsWriter.writeByte((byte) 0x01);
}
@@ -967,8 +938,7 @@ private void writeTypeInfo(TDSWriter tdsWriter,
case java.sql.Types.DOUBLE: // (FLT8TYPE) 0x3E
if (!srcNullable) {
tdsWriter.writeByte(TDSType.FLOAT8.byteValue());
- }
- else {
+ } else {
tdsWriter.writeByte(TDSType.FLOATN.byteValue());
tdsWriter.writeByte((byte) 0x08);
}
@@ -977,8 +947,7 @@ private void writeTypeInfo(TDSWriter tdsWriter,
case java.sql.Types.REAL: // (FLT4TYPE) 0x3B
if (!srcNullable) {
tdsWriter.writeByte(TDSType.FLOAT4.byteValue());
- }
- else {
+ } else {
tdsWriter.writeByte(TDSType.FLOATN.byteValue());
tdsWriter.writeByte((byte) 0x04);
}
@@ -994,8 +963,7 @@ private void writeTypeInfo(TDSWriter tdsWriter,
tdsWriter.writeByte((byte) 8);
else
tdsWriter.writeByte((byte) 4);
- }
- else {
+ } else {
if (java.sql.Types.DECIMAL == srcJdbcType)
tdsWriter.writeByte(TDSType.DECIMALN.byteValue()); // 0x6A
else
@@ -1011,8 +979,7 @@ private void writeTypeInfo(TDSWriter tdsWriter,
if (isBaseType && (SSType.GUID == destSSType)) {
tdsWriter.writeByte(TDSType.GUID.byteValue());
tdsWriter.writeByte((byte) 0x10);
- }
- else {
+ } else {
// BIGCHARTYPE
tdsWriter.writeByte(TDSType.BIGCHAR.byteValue());
@@ -1034,8 +1001,7 @@ private void writeTypeInfo(TDSWriter tdsWriter,
tdsWriter.writeByte(TDSType.BIGVARCHAR.byteValue());
if (isStreaming) {
tdsWriter.writeShort((short) 0xFFFF);
- }
- else {
+ } else {
tdsWriter.writeShort((short) (srcPrecision));
}
collation.writeCollation(tdsWriter);
@@ -1046,8 +1012,7 @@ private void writeTypeInfo(TDSWriter tdsWriter,
tdsWriter.writeByte(TDSType.NVARCHAR.byteValue());
if (isStreaming) {
tdsWriter.writeShort((short) 0xFFFF);
- }
- else {
+ } else {
tdsWriter.writeShort(isBaseType ? (short) (srcPrecision) : (short) (2 * srcPrecision));
}
collation.writeCollation(tdsWriter);
@@ -1064,8 +1029,7 @@ private void writeTypeInfo(TDSWriter tdsWriter,
tdsWriter.writeByte(TDSType.BIGVARBINARY.byteValue());
if (isStreaming) {
tdsWriter.writeShort((short) 0xFFFF);
- }
- else {
+ } else {
tdsWriter.writeShort((short) (srcPrecision));
}
break;
@@ -1077,8 +1041,7 @@ private void writeTypeInfo(TDSWriter tdsWriter,
tdsWriter.writeByte(TDSType.BIGVARCHAR.byteValue());
tdsWriter.writeShort((short) (srcPrecision));
collation.writeCollation(tdsWriter);
- }
- else {
+ } else {
switch (destSSType) {
case SMALLDATETIME:
if (!srcNullable)
@@ -1107,16 +1070,16 @@ private void writeTypeInfo(TDSWriter tdsWriter,
case java.sql.Types.DATE: // 0x28
/*
- * SQL Server supports numerous string literal formats for temporal types, hence sending them as varchar with approximate
- * precision(length) needed to send supported string literals if destination is unencrypted. string literal formats supported by
- * temporal types are available in MSDN page on data types.
+ * SQL Server supports numerous string literal formats for temporal types, hence sending them as varchar
+ * with approximate precision(length) needed to send supported string literals if destination is
+ * unencrypted. string literal formats supported by temporal types are available in MSDN page on data
+ * types.
*/
if ((!isBaseType) && (null != sourceBulkRecord)) {
tdsWriter.writeByte(TDSType.BIGVARCHAR.byteValue());
tdsWriter.writeShort((short) (srcPrecision));
collation.writeCollation(tdsWriter);
- }
- else {
+ } else {
tdsWriter.writeByte(TDSType.DATEN.byteValue());
}
break;
@@ -1126,16 +1089,15 @@ private void writeTypeInfo(TDSWriter tdsWriter,
tdsWriter.writeByte(TDSType.BIGVARCHAR.byteValue());
tdsWriter.writeShort((short) (srcPrecision));
collation.writeCollation(tdsWriter);
- }
- else {
+ } else {
tdsWriter.writeByte(TDSType.TIMEN.byteValue());
tdsWriter.writeByte((byte) srcScale);
}
break;
// Send as DATETIMEOFFSET for TIME_WITH_TIMEZONE and TIMESTAMP_WITH_TIMEZONE
- case 2013: // java.sql.Types.TIME_WITH_TIMEZONE
- case 2014: // java.sql.Types.TIMESTAMP_WITH_TIMEZONE
+ case 2013: // java.sql.Types.TIME_WITH_TIMEZONE
+ case 2014: // java.sql.Types.TIMESTAMP_WITH_TIMEZONE
tdsWriter.writeByte(TDSType.DATETIMEOFFSETN.byteValue());
tdsWriter.writeByte((byte) srcScale);
break;
@@ -1145,15 +1107,14 @@ private void writeTypeInfo(TDSWriter tdsWriter,
tdsWriter.writeByte(TDSType.BIGVARCHAR.byteValue());
tdsWriter.writeShort((short) (srcPrecision));
collation.writeCollation(tdsWriter);
- }
- else {
+ } else {
tdsWriter.writeByte(TDSType.DATETIMEOFFSETN.byteValue());
tdsWriter.writeByte((byte) srcScale);
}
break;
- case microsoft.sql.Types.SQL_VARIANT: //0x62
+ case microsoft.sql.Types.SQL_VARIANT: // 0x62
tdsWriter.writeByte(TDSType.SQL_VARIANT.byteValue());
- tdsWriter.writeInt(TDS.SQL_VARIANT_LENGTH);
+ tdsWriter.writeInt(TDS.SQL_VARIANT_LENGTH);
break;
default:
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_BulkTypeNotSupported"));
@@ -1162,39 +1123,42 @@ private void writeTypeInfo(TDSWriter tdsWriter,
}
}
- /*
- * Writes the CEK table needed for AE. Cek table (with 0 entries) will be present if AE was enabled and server supports it! OR if encryption was
- * disabled in connection options
+ /**
+ * Writes the CEK table needed for AE. Cek table (with 0 entries) will be present if AE was enabled and server
+ * supports it! OR if encryption was disabled in connection options
*/
private void writeCekTable(TDSWriter tdsWriter) throws SQLServerException {
if (connection.getServerSupportsColumnEncryption()) {
if ((null != destCekTable) && (0 < destCekTable.getSize())) {
tdsWriter.writeShort((short) destCekTable.getSize());
for (int cekIndx = 0; cekIndx < destCekTable.getSize(); cekIndx++) {
- tdsWriter.writeInt(destCekTable.getCekTableEntry(cekIndx).getColumnEncryptionKeyValues().get(0).databaseId);
- tdsWriter.writeInt(destCekTable.getCekTableEntry(cekIndx).getColumnEncryptionKeyValues().get(0).cekId);
- tdsWriter.writeInt(destCekTable.getCekTableEntry(cekIndx).getColumnEncryptionKeyValues().get(0).cekVersion);
- tdsWriter.writeBytes(destCekTable.getCekTableEntry(cekIndx).getColumnEncryptionKeyValues().get(0).cekMdVersion);
+ tdsWriter.writeInt(
+ destCekTable.getCekTableEntry(cekIndx).getColumnEncryptionKeyValues().get(0).databaseId);
+ tdsWriter.writeInt(
+ destCekTable.getCekTableEntry(cekIndx).getColumnEncryptionKeyValues().get(0).cekId);
+ tdsWriter.writeInt(
+ destCekTable.getCekTableEntry(cekIndx).getColumnEncryptionKeyValues().get(0).cekVersion);
+ tdsWriter.writeBytes(
+ destCekTable.getCekTableEntry(cekIndx).getColumnEncryptionKeyValues().get(0).cekMdVersion);
// We don't need to send the keys. So count for EncryptionKeyValue is 0 in EK_INFO TDS rule.
tdsWriter.writeByte((byte) 0x00);
}
- }
- else {
+ } else {
// If no encrypted columns, but the connection setting is true write 0 as the size of the CekTable.
tdsWriter.writeShort((short) 0);
}
}
}
- /*
+ /**
* ...
*/
private void writeColumnMetaData(TDSWriter tdsWriter) throws SQLServerException {
/*
- * TDS rules for Always Encrypted metadata COLMETADATA = TokenType Count CekTable NoMetaData / (1 *ColumnData) CekTable = EkValueCount EK_INFO
- * EK_INFO = DatabaseId CekId CekVersion CekMDVersion Count EncryptionKeyValue
+ * TDS rules for Always Encrypted metadata COLMETADATA = TokenType Count CekTable NoMetaData / (1 *ColumnData)
+ * CekTable = EkValueCount EK_INFO EK_INFO = DatabaseId CekId CekVersion CekMDVersion Count EncryptionKeyValue
*/
/*
@@ -1203,9 +1167,8 @@ private void writeColumnMetaData(TDSWriter tdsWriter) throws SQLServerException
tdsWriter.writeByte((byte) TDS.TDS_COLMETADATA);
/*
- * Count token: The count of columns. Should be USHORT. Not Supported in Java.
- *
- * Remedy: tdsWriter.writeShort((short)columnMappings.size());
+ * Count token: The count of columns. Should be USHORT. Not Supported in Java. Remedy:
+ * tdsWriter.writeShort((short)columnMappings.size());
*/
byte[] count = new byte[2];
count[0] = (byte) (columnMappings.size() & 0xFF);
@@ -1222,27 +1185,27 @@ private void writeColumnMetaData(TDSWriter tdsWriter) throws SQLServerException
}
}
- /*
+ /**
* Helper method that throws a timeout exception if the cause of the exception was that the query was cancelled
*/
- private void checkForTimeoutException(SQLException e,
- BulkTimeoutTimer timeoutTimer) throws SQLServerException {
- if ((null != e.getSQLState()) && (e.getSQLState().equals(SQLState.STATEMENT_CANCELED.getSQLStateCode())) && timeoutTimer.expired()) {
+ private void checkForTimeoutException(SQLException e, BulkTimeoutTimer timeoutTimer) throws SQLServerException {
+ if ((null != e.getSQLState()) && (e.getSQLState().equals(SQLState.STATEMENT_CANCELED.getSQLStateCode()))
+ && timeoutTimer.expired()) {
// If SQLServerBulkCopy is managing the transaction, a rollback is needed.
if (copyOptions.isUseInternalTransaction()) {
connection.rollback();
}
- throw new SQLServerException(SQLServerException.getErrString("R_queryTimedOut"), SQLState.STATEMENT_CANCELED, DriverError.NOT_SET, e);
+ throw new SQLServerException(SQLServerException.getErrString("R_queryTimedOut"),
+ SQLState.STATEMENT_CANCELED, DriverError.NOT_SET, e);
}
}
- /*
- * Validates whether the source JDBC types are compatible with the destination table data types. We need to do this only once for the whole bulk
- * copy session.
+ /**
+ * Validates whether the source JDBC types are compatible with the destination table data types. We need to do this
+ * only once for the whole bulk copy session.
*/
- private void validateDataTypeConversions(int srcColOrdinal,
- int destColOrdinal) throws SQLServerException {
+ private void validateDataTypeConversions(int srcColOrdinal, int destColOrdinal) throws SQLServerException {
// Reducing unnecessary assignment to optimize for performance. This reduces code readability, but
// may be worth it for the bulk copy.
@@ -1250,9 +1213,10 @@ private void validateDataTypeConversions(int srcColOrdinal,
CryptoMetadata destCryptoMeta = destColumnMetadata.get(destColOrdinal).cryptoMeta;
JDBCType srcJdbcType = (null != sourceCryptoMeta) ? sourceCryptoMeta.baseTypeInfo.getSSType().getJDBCType()
- : JDBCType.of(srcColumnMetadata.get(srcColOrdinal).jdbcType);
+ : JDBCType.of(srcColumnMetadata.get(srcColOrdinal).jdbcType);
- SSType destSSType = (null != destCryptoMeta) ? destCryptoMeta.baseTypeInfo.getSSType() : destColumnMetadata.get(destColOrdinal).ssType;
+ SSType destSSType = (null != destCryptoMeta) ? destCryptoMeta.baseTypeInfo.getSSType()
+ : destColumnMetadata.get(destColOrdinal).ssType;
// Throw if the source type cannot be converted to the destination type.
if (!srcJdbcType.convertsTo(destSSType)) {
@@ -1260,13 +1224,12 @@ private void validateDataTypeConversions(int srcColOrdinal,
}
}
- private String getDestTypeFromSrcType(int srcColIndx,
- int destColIndx,
+ private String getDestTypeFromSrcType(int srcColIndx, int destColIndx,
TDSWriter tdsWriter) throws SQLServerException {
boolean isStreaming;
- SSType destSSType = (null != destColumnMetadata.get(destColIndx).cryptoMeta)
- ? destColumnMetadata.get(destColIndx).cryptoMeta.baseTypeInfo.getSSType() : destColumnMetadata.get(destColIndx).ssType;
+ SSType destSSType = (null != destColumnMetadata.get(destColIndx).cryptoMeta) ? destColumnMetadata
+ .get(destColIndx).cryptoMeta.baseTypeInfo.getSSType() : destColumnMetadata.get(destColIndx).ssType;
int bulkJdbcType, bulkPrecision, bulkScale;
int srcPrecision;
@@ -1285,8 +1248,7 @@ private String getDestTypeFromSrcType(int srcColIndx,
// if destination is encrypted send metadata from destination and not from source
if (DataTypes.SHORT_VARTYPE_MAX_BYTES < destPrecision) {
return "varbinary(max)";
- }
- else {
+ } else {
return "varbinary(" + destColumnMetadata.get(destColIndx).precision + ")";
}
}
@@ -1299,22 +1261,24 @@ private String getDestTypeFromSrcType(int srcColIndx,
bulkPrecision = validateSourcePrecision(srcPrecision, bulkJdbcType, destPrecision);
/*
- * if source is encrypted and destination is unenecrypted, use destination's sql type to send since there is no way of finding if source is
- * encrypted without accessing the resultset.
- *
- * Send destination type if source resultset set is of type SQLServer, encryption is enabled and destination column is not encrypted
+ * if source is encrypted and destination is unenecrypted, use destination's sql type to send since there is no
+ * way of finding if source is encrypted without accessing the resultset. Send destination type if source
+ * resultset set is of type SQLServer, encryption is enabled and destination column is not encrypted
*/
- if ((sourceResultSet instanceof SQLServerResultSet) && (connection.isColumnEncryptionSettingEnabled()) && (null != destCryptoMeta)) {
+ if ((sourceResultSet instanceof SQLServerResultSet) && (connection.isColumnEncryptionSettingEnabled())
+ && (null != destCryptoMeta)) {
bulkJdbcType = destColumnMetadata.get(destColIndx).jdbcType;
bulkPrecision = destPrecision;
bulkScale = destColumnMetadata.get(destColIndx).scale;
}
- if ((java.sql.Types.NCHAR == bulkJdbcType) || (java.sql.Types.NVARCHAR == bulkJdbcType) || (java.sql.Types.LONGNVARCHAR == bulkJdbcType)) {
- isStreaming = (DataTypes.SHORT_VARTYPE_MAX_CHARS < srcPrecision) || (DataTypes.SHORT_VARTYPE_MAX_CHARS < destPrecision);
- }
- else {
- isStreaming = (DataTypes.SHORT_VARTYPE_MAX_BYTES < srcPrecision) || (DataTypes.SHORT_VARTYPE_MAX_BYTES < destPrecision);
+ if ((java.sql.Types.NCHAR == bulkJdbcType) || (java.sql.Types.NVARCHAR == bulkJdbcType)
+ || (java.sql.Types.LONGNVARCHAR == bulkJdbcType)) {
+ isStreaming = (DataTypes.SHORT_VARTYPE_MAX_CHARS < srcPrecision)
+ || (DataTypes.SHORT_VARTYPE_MAX_CHARS < destPrecision);
+ } else {
+ isStreaming = (DataTypes.SHORT_VARTYPE_MAX_BYTES < srcPrecision)
+ || (DataTypes.SHORT_VARTYPE_MAX_BYTES < destPrecision);
}
// SQL Server does not convert string to binary, we will have to explicitly convert before sending.
@@ -1323,7 +1287,8 @@ private String getDestTypeFromSrcType(int srcColIndx,
return "varbinary(max)";
else
// Return binary(n) or varbinary(n) or varbinary(max) depending on destination type/precision.
- return destSSType.toString() + "(" + ((DataTypes.SHORT_VARTYPE_MAX_BYTES < destPrecision) ? "max" : destPrecision) + ")";
+ return destSSType.toString() + "("
+ + ((DataTypes.SHORT_VARTYPE_MAX_BYTES < destPrecision) ? "max" : destPrecision) + ")";
}
switch (bulkJdbcType) {
@@ -1370,8 +1335,7 @@ private String getDestTypeFromSrcType(int srcColIndx,
// Doesn't need to match with the exact size of data or with the destination column size.
if (isStreaming) {
return "varchar(max)";
- }
- else {
+ } else {
return "varchar(" + bulkPrecision + ")";
}
@@ -1381,8 +1345,7 @@ private String getDestTypeFromSrcType(int srcColIndx,
case java.sql.Types.NVARCHAR:
if (isStreaming) {
return "NVARCHAR(MAX)";
- }
- else {
+ } else {
return "NVARCHAR(" + bulkPrecision + ")";
}
@@ -1403,74 +1366,73 @@ private String getDestTypeFromSrcType(int srcColIndx,
switch (destSSType) {
case SMALLDATETIME:
if (null != sourceBulkRecord) {
- return "varchar(" + ((0 == bulkPrecision) ? sourceBulkRecordTemporalMaxPrecision : bulkPrecision) + ")";
- }
- else {
+ return "varchar("
+ + ((0 == bulkPrecision) ? sourceBulkRecordTemporalMaxPrecision : bulkPrecision)
+ + ")";
+ } else {
return "smalldatetime";
}
case DATETIME:
if (null != sourceBulkRecord) {
- return "varchar(" + ((0 == bulkPrecision) ? sourceBulkRecordTemporalMaxPrecision : bulkPrecision) + ")";
- }
- else {
+ return "varchar("
+ + ((0 == bulkPrecision) ? sourceBulkRecordTemporalMaxPrecision : bulkPrecision)
+ + ")";
+ } else {
return "datetime";
}
default:
// datetime2
/*
- * If encrypted, varbinary will be returned before. The code will come here only if unencrypted. For unencrypted bulk copy if
- * the source is CSV, we send the data as varchar and SQL Server will do the conversion. if the source is ResultSet, we send
- * the data as the corresponding temporal type.
+ * If encrypted, varbinary will be returned before. The code will come here only if unencrypted.
+ * For unencrypted bulk copy if the source is CSV, we send the data as varchar and SQL Server
+ * will do the conversion. if the source is ResultSet, we send the data as the corresponding
+ * temporal type.
*/
if (null != sourceBulkRecord) {
return "varchar(" + ((0 == bulkPrecision) ? destPrecision : bulkPrecision) + ")";
- }
- else {
+ } else {
return "datetime2(" + bulkScale + ")";
}
}
case java.sql.Types.DATE:
/*
- * If encrypted, varbinary will be returned before. The code will come here only if unencrypted. For unencrypted bulk copy if the
- * source is CSV, we send the data as varchar and SQL Server will do the conversion. if the source is ResultSet, we send the data as
- * the corresponding temporal type.
+ * If encrypted, varbinary will be returned before. The code will come here only if unencrypted. For
+ * unencrypted bulk copy if the source is CSV, we send the data as varchar and SQL Server will do the
+ * conversion. if the source is ResultSet, we send the data as the corresponding temporal type.
*/
if (null != sourceBulkRecord) {
return "varchar(" + ((0 == bulkPrecision) ? destPrecision : bulkPrecision) + ")";
- }
- else {
+ } else {
return "date";
}
case java.sql.Types.TIME:
/*
- * If encrypted, varbinary will be returned before. The code will come here only if unencrypted. For unencrypted bulk copy if the
- * source is CSV, we send the data as varchar and SQL Server will do the conversion. if the source is ResultSet, we send the data as
- * the corresponding temporal type.
+ * If encrypted, varbinary will be returned before. The code will come here only if unencrypted. For
+ * unencrypted bulk copy if the source is CSV, we send the data as varchar and SQL Server will do the
+ * conversion. if the source is ResultSet, we send the data as the corresponding temporal type.
*/
if (null != sourceBulkRecord) {
return "varchar(" + ((0 == bulkPrecision) ? destPrecision : bulkPrecision) + ")";
- }
- else {
+ } else {
return "time(" + bulkScale + ")";
}
// Return DATETIMEOFFSET for TIME_WITH_TIMEZONE and TIMESTAMP_WITH_TIMEZONE
- case 2013: // java.sql.Types.TIME_WITH_TIMEZONE
- case 2014: // java.sql.Types.TIMESTAMP_WITH_TIMEZONE
+ case 2013: // java.sql.Types.TIME_WITH_TIMEZONE
+ case 2014: // java.sql.Types.TIMESTAMP_WITH_TIMEZONE
return "datetimeoffset(" + bulkScale + ")";
case microsoft.sql.Types.DATETIMEOFFSET:
/*
- * If encrypted, varbinary will be returned before. The code will come here only if unencrypted. For unencrypted bulk copy if the
- * source is CSV, we send the data as varchar and SQL Server will do the conversion. if the source is ResultSet, we send the data as
- * the corresponding temporal type.
+ * If encrypted, varbinary will be returned before. The code will come here only if unencrypted. For
+ * unencrypted bulk copy if the source is CSV, we send the data as varchar and SQL Server will do the
+ * conversion. if the source is ResultSet, we send the data as the corresponding temporal type.
*/
if (null != sourceBulkRecord) {
return "varchar(" + ((0 == bulkPrecision) ? destPrecision : bulkPrecision) + ")";
- }
- else {
+ } else {
return "datetimeoffset(" + bulkScale + ")";
}
case microsoft.sql.Types.SQL_VARIANT:
@@ -1495,14 +1457,16 @@ private String createInsertBulkCommand(TDSWriter tdsWriter) throws SQLServerExce
endColumn = " ) ";
}
ColumnMapping colMapping = columnMappings.get(i);
- String columnCollation = destColumnMetadata.get(columnMappings.get(i).destinationColumnOrdinal).collationName;
+ String columnCollation = destColumnMetadata
+ .get(columnMappings.get(i).destinationColumnOrdinal).collationName;
String addCollate = "";
- String destType = getDestTypeFromSrcType(colMapping.sourceColumnOrdinal, colMapping.destinationColumnOrdinal, tdsWriter)
- .toUpperCase(Locale.ENGLISH);
+ String destType = getDestTypeFromSrcType(colMapping.sourceColumnOrdinal,
+ colMapping.destinationColumnOrdinal, tdsWriter).toUpperCase(Locale.ENGLISH);
if (null != columnCollation && columnCollation.trim().length() > 0) {
// we are adding collate in command only for char and varchar
- if (null != destType && (destType.toLowerCase(Locale.ENGLISH).trim().startsWith("char") || destType.toLowerCase(Locale.ENGLISH).trim().startsWith("varchar")))
+ if (null != destType && (destType.toLowerCase(Locale.ENGLISH).trim().startsWith("char")
+ || destType.toLowerCase(Locale.ENGLISH).trim().startsWith("varchar")))
addCollate = " COLLATE " + columnCollation;
}
if (colMapping.destinationColumnName.contains("]")) {
@@ -1560,7 +1524,7 @@ private boolean doInsertBulk(TDSCommand command) throws SQLServerException {
// Begin a manual transaction for this batch.
connection.setAutoCommit(false);
}
-
+
boolean insertRowByRow = false;
if (null != sourceResultSet && sourceResultSet instanceof SQLServerResultSet) {
@@ -1570,13 +1534,13 @@ private boolean doInsertBulk(TDSCommand command) throws SQLServerException {
if (connection.equals(src_stmt.getConnection()) && 0 != resultSetServerCursorId) {
insertRowByRow = true;
}
-
+
if (((SQLServerResultSet) sourceResultSet).isForwardOnly()) {
try {
sourceResultSet.setFetchSize(1);
- }
- catch (SQLException e) {
- SQLServerException.makeFromDriverError(connection, sourceResultSet, e.getMessage(), e.getSQLState(), true);
+ } catch (SQLException e) {
+ SQLServerException.makeFromDriverError(connection, sourceResultSet, e.getMessage(), e.getSQLState(),
+ true);
}
}
}
@@ -1592,12 +1556,10 @@ private boolean doInsertBulk(TDSCommand command) throws SQLServerException {
try {
// Write all ROW tokens in the stream.
moreDataAvailable = writeBatchData(tdsWriter, command, insertRowByRow);
- }
- finally {
+ } finally {
tdsWriter = command.getTDSWriter();
}
- }
- catch (SQLServerException ex) {
+ } catch (SQLServerException ex) {
if (null == tdsWriter) {
tdsWriter = command.getTDSWriter();
}
@@ -1613,19 +1575,19 @@ private boolean doInsertBulk(TDSCommand command) throws SQLServerException {
command.onRequestComplete();
throw ex;
- }
- finally {
+ } finally {
if (null == tdsWriter) {
tdsWriter = command.getTDSWriter();
}
-
+
// reset the cryptoMeta in IOBuffer
tdsWriter.setCryptoMetaData(null);
}
-
+
if (!insertRowByRow) {
// Write the DONE token in the stream. We may have to append the DONE token with every packet that is sent.
- // For the current packets the driver does not generate a DONE token, but the BulkLoadBCP stream needs a DONE token
+ // For the current packets the driver does not generate a DONE token, but the BulkLoadBCP stream needs a
+ // DONE token
// after every packet. For now add it manually here for one packet.
// Note: This may break if more than one packet is sent.
// This is an example from https://msdn.microsoft.com/en-us/library/dd340549.aspx
@@ -1666,7 +1628,7 @@ private void writePacketDataDone(TDSWriter tdsWriter) throws SQLServerException
tdsWriter.writeInt(0);
}
- /*
+ /**
* Helper method to throw a SQLServerExeption with the invalidArgument message and given argument.
*/
private void throwInvalidArgument(String argument) throws SQLServerException {
@@ -1675,16 +1637,15 @@ private void throwInvalidArgument(String argument) throws SQLServerException {
SQLServerException.makeFromDriverError(null, null, form.format(msgArgs), null, false);
}
- /*
+ /**
* Helper method to throw a SQLServerExeption with the errorConvertingValue message and given arguments.
*/
- private void throwInvalidJavaToJDBC(String javaClassName,
- int jdbcType) throws SQLServerException {
+ private void throwInvalidJavaToJDBC(String javaClassName, int jdbcType) throws SQLServerException {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_errorConvertingValue"));
throw new SQLServerException(form.format(new Object[] {javaClassName, jdbcType}), null, 0, null);
}
- /*
+ /**
* The bulk copy operation
*/
private void writeToServer() throws SQLServerException {
@@ -1715,28 +1676,24 @@ private void writeToServer() throws SQLServerException {
}
}
- private void validateStringBinaryLengths(Object colValue,
- int srcCol,
- int destCol) throws SQLServerException {
+ private void validateStringBinaryLengths(Object colValue, int srcCol, int destCol) throws SQLServerException {
int sourcePrecision;
int destPrecision = destColumnMetadata.get(destCol).precision;
int srcJdbcType = srcColumnMetadata.get(srcCol).jdbcType;
SSType destSSType = destColumnMetadata.get(destCol).ssType;
- if ((Util.isCharType(srcJdbcType) && Util.isCharType(destSSType)) || (Util.isBinaryType(srcJdbcType) && Util.isBinaryType(destSSType))) {
+ if ((Util.isCharType(srcJdbcType) && Util.isCharType(destSSType))
+ || (Util.isBinaryType(srcJdbcType) && Util.isBinaryType(destSSType))) {
if (colValue instanceof String) {
- if (Util.isBinaryType(destSSType)) {
- // if the dest value is binary and the value is of type string.
- //Repro in test case: ImpISQLServerBulkRecord_IssuesTest#testSendValidValueforBinaryColumnAsString
+ if (Util.isBinaryType(destSSType)) {
+ // if the dest value is binary and the value is of type string.
+ // Repro in test case: ImpISQLServerBulkRecord_IssuesTest#testSendValidValueforBinaryColumnAsString
sourcePrecision = (((String) colValue).getBytes().length) / 2;
- }
- else
+ } else
sourcePrecision = ((String) colValue).length();
- }
- else if (colValue instanceof byte[]) {
+ } else if (colValue instanceof byte[]) {
sourcePrecision = ((byte[]) colValue).length;
- }
- else {
+ } else {
return;
}
@@ -1750,28 +1707,29 @@ else if (colValue instanceof byte[]) {
}
}
- /*
- * Retrieves the column metadata for the destination table (and saves it for later)
+ /**
+ * Returns the column metadata for the destination table (and saves it for later)
*/
private void getDestinationMetadata() throws SQLServerException {
if (null == destinationTableName) {
- SQLServerException.makeFromDriverError(null, null, SQLServerException.getErrString("R_invalidDestinationTable"), null, false);
+ SQLServerException.makeFromDriverError(null, null,
+ SQLServerException.getErrString("R_invalidDestinationTable"), null, false);
}
SQLServerResultSet rs = null;
SQLServerResultSet rsMoreMetaData = null;
SQLServerStatement stmt = null;
-
+
try {
if (null != destinationTableMetadata) {
rs = (SQLServerResultSet) destinationTableMetadata;
- }
- else {
- stmt = (SQLServerStatement) connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY,
- connection.getHoldability(), stmtColumnEncriptionSetting);
+ } else {
+ stmt = (SQLServerStatement) connection.createStatement(ResultSet.TYPE_FORWARD_ONLY,
+ ResultSet.CONCUR_READ_ONLY, connection.getHoldability(), stmtColumnEncriptionSetting);
// Get destination metadata
- rs = stmt.executeQueryInternal("sp_executesql N'SET FMTONLY ON SELECT * FROM " + destinationTableName + " '");
+ rs = stmt.executeQueryInternal(
+ "sp_executesql N'SET FMTONLY ON SELECT * FROM " + destinationTableName + " '");
}
destColumnCount = rs.getMetaData().getColumnCount();
@@ -1781,34 +1739,31 @@ private void getDestinationMetadata() throws SQLServerException {
if (!connection.getServerSupportsColumnEncryption()) {
// SQL server prior to 2016 does not support encryption_type
rsMoreMetaData = ((SQLServerStatement) connection.createStatement())
- .executeQueryInternal("select collation_name from sys.columns where " + "object_id=OBJECT_ID('" + destinationTableName + "') "
- + "order by column_id ASC");
- }
- else {
- rsMoreMetaData = ((SQLServerStatement) connection.createStatement())
- .executeQueryInternal("select collation_name, encryption_type from sys.columns where " + "object_id=OBJECT_ID('"
+ .executeQueryInternal("select collation_name from sys.columns where " + "object_id=OBJECT_ID('"
+ destinationTableName + "') " + "order by column_id ASC");
+ } else {
+ rsMoreMetaData = ((SQLServerStatement) connection.createStatement())
+ .executeQueryInternal("select collation_name, encryption_type from sys.columns where "
+ + "object_id=OBJECT_ID('" + destinationTableName + "') " + "order by column_id ASC");
}
for (int i = 1; i <= destColumnCount; ++i) {
if (rsMoreMetaData.next()) {
if (!connection.getServerSupportsColumnEncryption()) {
- destColumnMetadata.put(i, new BulkColumnMetaData(rs.getColumn(i), rsMoreMetaData.getString("collation_name"), null));
- }
- else {
- destColumnMetadata.put(i, new BulkColumnMetaData(rs.getColumn(i), rsMoreMetaData.getString("collation_name"),
- rsMoreMetaData.getString("encryption_type")));
- }
- }
- else {
+ destColumnMetadata.put(i, new BulkColumnMetaData(rs.getColumn(i),
+ rsMoreMetaData.getString("collation_name"), null));
+ } else {
+ destColumnMetadata.put(i,
+ new BulkColumnMetaData(rs.getColumn(i), rsMoreMetaData.getString("collation_name"),
+ rsMoreMetaData.getString("encryption_type")));
+ }
+ } else {
destColumnMetadata.put(i, new BulkColumnMetaData(rs.getColumn(i)));
}
}
- }
- catch (SQLException e) {
+ } catch (SQLException e) {
// Unable to retrieve metadata for destination
throw new SQLServerException(SQLServerException.getErrString("R_unableRetrieveColMeta"), e);
- }
- finally {
+ } finally {
if (null != rs)
rs.close();
if (null != stmt)
@@ -1818,9 +1773,9 @@ private void getDestinationMetadata() throws SQLServerException {
}
}
- /*
- * Retrieves the column metadata for the source (and saves it for later). Retrieving source metadata in BulkColumnMetaData object helps to access
- * source metadata from the same place for both ResultSet and File.
+ /**
+ * Returns the column metadata for the source (and saves it for later). Retrieving source metadata in
+ * BulkColumnMetaData object helps to access source metadata from the same place for both ResultSet and File.
*/
private void getSourceMetadata() throws SQLServerException {
srcColumnMetadata = new HashMap<>();
@@ -1835,48 +1790,43 @@ private void getSourceMetadata() throws SQLServerException {
sourceResultSetMetaData.getPrecision(i), sourceResultSetMetaData.getScale(i),
sourceResultSetMetaData.getColumnType(i), null));
}
- }
- catch (SQLException e) {
+ } catch (SQLException e) {
// Unable to retrieve meta data for destination
throw new SQLServerException(SQLServerException.getErrString("R_unableRetrieveColMeta"), e);
}
- }
- else if (null != sourceBulkRecord) {
+ } else if (null != sourceBulkRecord) {
Set columnOrdinals = sourceBulkRecord.getColumnOrdinals();
if (null == columnOrdinals || 0 == columnOrdinals.size()) {
throw new SQLServerException(SQLServerException.getErrString("R_unableRetrieveColMeta"), null);
- }
- else {
+ } else {
srcColumnCount = columnOrdinals.size();
for (Integer columnOrdinal : columnOrdinals) {
currentColumn = columnOrdinal;
- srcColumnMetadata.put(currentColumn,
- new BulkColumnMetaData(sourceBulkRecord.getColumnName(currentColumn), true, sourceBulkRecord.getPrecision(currentColumn),
- sourceBulkRecord.getScale(currentColumn), sourceBulkRecord.getColumnType(currentColumn),
- ((sourceBulkRecord instanceof SQLServerBulkCSVFileRecord)
- ? ((SQLServerBulkCSVFileRecord) sourceBulkRecord).getColumnDateTimeFormatter(currentColumn) : null)));
+ srcColumnMetadata.put(currentColumn, new BulkColumnMetaData(
+ sourceBulkRecord.getColumnName(currentColumn), true,
+ sourceBulkRecord.getPrecision(currentColumn), sourceBulkRecord.getScale(currentColumn),
+ sourceBulkRecord.getColumnType(currentColumn),
+ ((sourceBulkRecord instanceof SQLServerBulkCSVFileRecord) ? ((SQLServerBulkCSVFileRecord) sourceBulkRecord)
+ .getColumnDateTimeFormatter(currentColumn) : null)));
}
}
- }
- else {
+ } else {
// Unable to retrieve meta data for source
throw new SQLServerException(SQLServerException.getErrString("R_unableRetrieveColMeta"), null);
}
}
- /*
+ /**
* Oracle 12c database returns precision = 0 for char/varchar data types.
*/
- private int validateSourcePrecision(int srcPrecision,
- int srcJdbcType,
- int destPrecision) {
+ private int validateSourcePrecision(int srcPrecision, int srcJdbcType, int destPrecision) {
if ((1 > srcPrecision) && Util.isCharType(srcJdbcType)) {
srcPrecision = destPrecision;
}
return srcPrecision;
}
- /*
+ /**
* Validates the column mappings
*/
private void validateColumnMappings() throws SQLServerException {
@@ -1885,8 +1835,8 @@ private void validateColumnMappings() throws SQLServerException {
// Check that the source schema matches the destination schema
// If the number of columns are different, there is an obvious mismatch.
if (destColumnCount != srcColumnCount) {
- throw new SQLServerException(SQLServerException.getErrString("R_schemaMismatch"), SQLState.COL_NOT_FOUND, DriverError.NOT_SET,
- null);
+ throw new SQLServerException(SQLServerException.getErrString("R_schemaMismatch"),
+ SQLState.COL_NOT_FOUND, DriverError.NOT_SET, null);
}
// Could validate that the data types can be converted, but easier to leave that check for later
@@ -1912,13 +1862,13 @@ private void validateColumnMappings() throws SQLServerException {
if (j != currentOrdinal) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidColumn"));
Object[] msgArgs = {currentOrdinal};
- throw new SQLServerException(form.format(msgArgs), SQLState.COL_NOT_FOUND, DriverError.NOT_SET, null);
+ throw new SQLServerException(form.format(msgArgs), SQLState.COL_NOT_FOUND,
+ DriverError.NOT_SET, null);
}
j++;
}
}
- }
- else {
+ } else {
int numMappings = columnMappings.size();
ColumnMapping cm;
@@ -1941,15 +1891,15 @@ private void validateColumnMappings() throws SQLServerException {
if (!foundColumn) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidColumn"));
Object[] msgArgs = {cm.destinationColumnName};
- throw new SQLServerException(form.format(msgArgs), SQLState.COL_NOT_FOUND, DriverError.NOT_SET, null);
+ throw new SQLServerException(form.format(msgArgs), SQLState.COL_NOT_FOUND,
+ DriverError.NOT_SET, null);
}
- }
- else if (0 > cm.destinationColumnOrdinal || destColumnCount < cm.destinationColumnOrdinal) {
+ } else if (0 > cm.destinationColumnOrdinal || destColumnCount < cm.destinationColumnOrdinal) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidColumn"));
Object[] msgArgs = {cm.destinationColumnOrdinal};
- throw new SQLServerException(form.format(msgArgs), SQLState.COL_NOT_FOUND, DriverError.NOT_SET, null);
- }
- else {
+ throw new SQLServerException(form.format(msgArgs), SQLState.COL_NOT_FOUND, DriverError.NOT_SET,
+ null);
+ } else {
cm.destinationColumnName = destColumnMetadata.get(cm.destinationColumnOrdinal).columnName;
}
}
@@ -1970,8 +1920,7 @@ else if (0 > cm.destinationColumnOrdinal || destColumnCount < cm.destinationColu
break;
}
}
- }
- else {
+ } else {
Set columnOrdinals = sourceBulkRecord.getColumnOrdinals();
for (Integer currentColumn : columnOrdinals) {
if (sourceBulkRecord.getColumnName(currentColumn).equals(cm.sourceColumnName)) {
@@ -1985,10 +1934,10 @@ else if (0 > cm.destinationColumnOrdinal || destColumnCount < cm.destinationColu
if (!foundColumn) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidColumn"));
Object[] msgArgs = {cm.sourceColumnName};
- throw new SQLServerException(form.format(msgArgs), SQLState.COL_NOT_FOUND, DriverError.NOT_SET, null);
+ throw new SQLServerException(form.format(msgArgs), SQLState.COL_NOT_FOUND,
+ DriverError.NOT_SET, null);
}
- }
- else // Validate that the source column is in range
+ } else // Validate that the source column is in range
{
boolean columnOutOfRange = true;
if (null != sourceResultSet) {
@@ -1996,8 +1945,7 @@ else if (0 > cm.destinationColumnOrdinal || destColumnCount < cm.destinationColu
if (0 < cm.sourceColumnOrdinal && columns >= cm.sourceColumnOrdinal) {
columnOutOfRange = false;
}
- }
- else {
+ } else {
// check if the ordinal is in SQLServerBulkCSVFileRecord.addColumnMetadata()
if (srcColumnMetadata.containsKey(cm.sourceColumnOrdinal)) {
columnOutOfRange = false;
@@ -2007,22 +1955,24 @@ else if (0 > cm.destinationColumnOrdinal || destColumnCount < cm.destinationColu
if (columnOutOfRange) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidColumn"));
Object[] msgArgs = {cm.sourceColumnOrdinal};
- throw new SQLServerException(form.format(msgArgs), SQLState.COL_NOT_FOUND, DriverError.NOT_SET, null);
+ throw new SQLServerException(form.format(msgArgs), SQLState.COL_NOT_FOUND,
+ DriverError.NOT_SET, null);
}
}
// Remove mappings for identity column if KEEP IDENTITY OPTION is FALSE
- if (destColumnMetadata.get(cm.destinationColumnOrdinal).isIdentity && !copyOptions.isKeepIdentity()) {
+ if (destColumnMetadata.get(cm.destinationColumnOrdinal).isIdentity
+ && !copyOptions.isKeepIdentity()) {
columnMappings.remove(i);
numMappings--;
i--;
}
}
}
- }
- catch (SQLException e) {
+ } catch (SQLException e) {
// Let the column mapping validations go straight through as a single exception
- if ((e instanceof SQLServerException) && (null != e.getSQLState()) && e.getSQLState().equals(SQLState.COL_NOT_FOUND.getSQLStateCode())) {
+ if ((e instanceof SQLServerException) && (null != e.getSQLState())
+ && e.getSQLState().equals(SQLState.COL_NOT_FOUND.getSQLStateCode())) {
throw (SQLServerException) e;
}
@@ -2033,12 +1983,12 @@ else if (0 > cm.destinationColumnOrdinal || destColumnCount < cm.destinationColu
// Throw an exception is Column mapping is empty.
// If keep identity option is set to be false and not other mapping is explicitly provided.
if (columnMappings.isEmpty()) {
- throw new SQLServerException(null, SQLServerException.getErrString("R_BulkColumnMappingsIsEmpty"), null, 0, false);
+ throw new SQLServerException(null, SQLServerException.getErrString("R_BulkColumnMappingsIsEmpty"), null, 0,
+ false);
}
}
- private void writeNullToTdsWriter(TDSWriter tdsWriter,
- int srcJdbcType,
+ private void writeNullToTdsWriter(TDSWriter tdsWriter, int srcJdbcType,
boolean isStreaming) throws SQLServerException {
switch (srcJdbcType) {
@@ -2053,8 +2003,7 @@ private void writeNullToTdsWriter(TDSWriter tdsWriter,
case java.sql.Types.LONGVARBINARY:
if (isStreaming) {
tdsWriter.writeLong(PLPInputStream.PLP_NULL);
- }
- else {
+ } else {
tdsWriter.writeByte((byte) 0xFF);
tdsWriter.writeByte((byte) 0xFF);
}
@@ -2071,8 +2020,8 @@ private void writeNullToTdsWriter(TDSWriter tdsWriter,
case java.sql.Types.TIMESTAMP:
case java.sql.Types.DATE:
case java.sql.Types.TIME:
- case 2013: // java.sql.Types.TIME_WITH_TIMEZONE
- case 2014: // java.sql.Types.TIMESTAMP_WITH_TIMEZONE
+ case 2013: // java.sql.Types.TIME_WITH_TIMEZONE
+ case 2014: // java.sql.Types.TIMESTAMP_WITH_TIMEZONE
case microsoft.sql.Types.DATETIMEOFFSET:
tdsWriter.writeByte((byte) 0x00);
return;
@@ -2086,36 +2035,34 @@ private void writeNullToTdsWriter(TDSWriter tdsWriter,
}
}
- private void writeColumnToTdsWriter(TDSWriter tdsWriter,
- int bulkPrecision,
- int bulkScale,
- int bulkJdbcType,
+ private void writeColumnToTdsWriter(TDSWriter tdsWriter, int bulkPrecision, int bulkScale, int bulkJdbcType,
boolean bulkNullable, // should it be destNullable instead?
- int srcColOrdinal,
- int destColOrdinal,
- boolean isStreaming,
- Object colValue) throws SQLServerException {
+ int srcColOrdinal, int destColOrdinal, boolean isStreaming, Object colValue) throws SQLServerException {
SSType destSSType = destColumnMetadata.get(destColOrdinal).ssType;
- bulkPrecision = validateSourcePrecision(bulkPrecision, bulkJdbcType, destColumnMetadata.get(destColOrdinal).precision);
+ bulkPrecision = validateSourcePrecision(bulkPrecision, bulkJdbcType,
+ destColumnMetadata.get(destColOrdinal).precision);
CryptoMetadata sourceCryptoMeta = srcColumnMetadata.get(srcColOrdinal).cryptoMeta;
- if (((null != destColumnMetadata.get(destColOrdinal).encryptionType) && copyOptions.isAllowEncryptedValueModifications())
+ if (((null != destColumnMetadata.get(destColOrdinal).encryptionType)
+ && copyOptions.isAllowEncryptedValueModifications())
// if destination is encrypted send varbinary explicitly(needed for unencrypted source)
|| (null != destColumnMetadata.get(destColOrdinal).cryptoMeta)) {
bulkJdbcType = java.sql.Types.VARBINARY;
}
/*
- * if source is encrypted and destination is unenecrypted, use destination sql type to send since there is no way of finding if source is
- * encrypted without accessing the resultset, send destination type if source resultset set is of type SQLServer and encryption is enabled
+ * if source is encrypted and destination is unenecrypted, use destination sql type to send since there is no
+ * way of finding if source is encrypted without accessing the resultset, send destination type if source
+ * resultset set is of type SQLServer and encryption is enabled
*/
else if (null != sourceCryptoMeta) {
bulkJdbcType = destColumnMetadata.get(destColOrdinal).jdbcType;
bulkScale = destColumnMetadata.get(destColOrdinal).scale;
- }
- else if (null != sourceBulkRecord) {
- // Bulk copy from CSV and destination is not encrypted. In this case, we send the temporal types as varchar and
- // SQL Server does the conversion. If destination is encrypted, then temporal types can not be sent as varchar.
+ } else if (null != sourceBulkRecord) {
+ // Bulk copy from CSV and destination is not encrypted. In this case, we send the temporal types as varchar
+ // and
+ // SQL Server does the conversion. If destination is encrypted, then temporal types can not be sent as
+ // varchar.
switch (bulkJdbcType) {
case java.sql.Types.DATE:
case java.sql.Types.TIME:
@@ -2129,13 +2076,13 @@ else if (null != sourceBulkRecord) {
}
try {
- // We are sending the data using JDBCType and not using SSType as SQL Server will automatically do the conversion.
+ // We are sending the data using JDBCType and not using SSType as SQL Server will automatically do the
+ // conversion.
switch (bulkJdbcType) {
case java.sql.Types.INTEGER:
if (null == colValue) {
writeNullToTdsWriter(tdsWriter, bulkJdbcType, isStreaming);
- }
- else {
+ } else {
if (bulkNullable) {
tdsWriter.writeByte((byte) 0x04);
}
@@ -2146,8 +2093,7 @@ else if (null != sourceBulkRecord) {
case java.sql.Types.SMALLINT:
if (null == colValue) {
writeNullToTdsWriter(tdsWriter, bulkJdbcType, isStreaming);
- }
- else {
+ } else {
if (bulkNullable) {
tdsWriter.writeByte((byte) 0x02);
}
@@ -2158,8 +2104,7 @@ else if (null != sourceBulkRecord) {
case java.sql.Types.BIGINT:
if (null == colValue) {
writeNullToTdsWriter(tdsWriter, bulkJdbcType, isStreaming);
- }
- else {
+ } else {
if (bulkNullable) {
tdsWriter.writeByte((byte) 0x08);
}
@@ -2170,8 +2115,7 @@ else if (null != sourceBulkRecord) {
case java.sql.Types.BIT:
if (null == colValue) {
writeNullToTdsWriter(tdsWriter, bulkJdbcType, isStreaming);
- }
- else {
+ } else {
if (bulkNullable) {
tdsWriter.writeByte((byte) 0x01);
}
@@ -2182,8 +2126,7 @@ else if (null != sourceBulkRecord) {
case java.sql.Types.TINYINT:
if (null == colValue) {
writeNullToTdsWriter(tdsWriter, bulkJdbcType, isStreaming);
- }
- else {
+ } else {
if (bulkNullable) {
tdsWriter.writeByte((byte) 0x01);
}
@@ -2197,8 +2140,7 @@ else if (null != sourceBulkRecord) {
case java.sql.Types.DOUBLE:
if (null == colValue) {
writeNullToTdsWriter(tdsWriter, bulkJdbcType, isStreaming);
- }
- else {
+ } else {
if (bulkNullable) {
tdsWriter.writeByte((byte) 0x08);
}
@@ -2209,8 +2151,7 @@ else if (null != sourceBulkRecord) {
case java.sql.Types.REAL:
if (null == colValue) {
writeNullToTdsWriter(tdsWriter, bulkJdbcType, isStreaming);
- }
- else {
+ } else {
if (bulkNullable) {
tdsWriter.writeByte((byte) 0x04);
}
@@ -2224,17 +2165,19 @@ else if (null != sourceBulkRecord) {
case java.sql.Types.NUMERIC:
if (null == colValue) {
writeNullToTdsWriter(tdsWriter, bulkJdbcType, isStreaming);
- }
- else {
+ } else {
/*
- * if the precision that user provides is smaller than the precision of the actual value, the driver assumes the precision
- * that user provides is the correct precision, and throws exception
+ * if the precision that user provides is smaller than the precision of the actual value, the
+ * driver assumes the precision that user provides is the correct precision, and throws
+ * exception
*/
- if (bulkPrecision < Util.getValueLengthBaseOnJavaType(colValue, JavaType.of(colValue), null, null,
- JDBCType.of(bulkJdbcType))) {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_valueOutOfRange"));
+ if (bulkPrecision < Util.getValueLengthBaseOnJavaType(colValue, JavaType.of(colValue), null,
+ null, JDBCType.of(bulkJdbcType))) {
+ MessageFormat form = new MessageFormat(
+ SQLServerException.getErrString("R_valueOutOfRange"));
Object[] msgArgs = {SSType.DECIMAL};
- throw new SQLServerException(form.format(msgArgs), SQLState.DATA_EXCEPTION_LENGTH_MISMATCH, DriverError.NOT_SET, null);
+ throw new SQLServerException(form.format(msgArgs), SQLState.DATA_EXCEPTION_LENGTH_MISMATCH,
+ DriverError.NOT_SET, null);
}
tdsWriter.writeBigDecimal((BigDecimal) colValue, bulkJdbcType, bulkPrecision, bulkScale);
}
@@ -2242,17 +2185,18 @@ else if (null != sourceBulkRecord) {
case microsoft.sql.Types.GUID:
case java.sql.Types.LONGVARCHAR:
- case java.sql.Types.CHAR: // Fixed-length, non-Unicode string data.
- case java.sql.Types.VARCHAR: // Variable-length, non-Unicode string data.
+ case java.sql.Types.CHAR: // Fixed-length, non-Unicode string data.
+ case java.sql.Types.VARCHAR: // Variable-length, non-Unicode string data.
if (isStreaming) // PLP
{
// PLP_BODY rule in TDS
- // Use ResultSet.getString for non-streaming data and ResultSet.getCharacterStream() for streaming data,
- // so that if the source data source does not have streaming enabled, the smaller size data will still work.
+ // Use ResultSet.getString for non-streaming data and ResultSet.getCharacterStream() for
+ // streaming data,
+ // so that if the source data source does not have streaming enabled, the smaller size data will
+ // still work.
if (null == colValue) {
writeNullToTdsWriter(tdsWriter, bulkJdbcType, isStreaming);
- }
- else {
+ } else {
// Send length as unknown.
tdsWriter.writeLong(PLPInputStream.UNKNOWN_PLP_LEN);
try {
@@ -2261,59 +2205,56 @@ else if (null != sourceBulkRecord) {
Reader reader;
if (colValue instanceof Reader) {
reader = (Reader) colValue;
- }
- else {
+ } else {
reader = new StringReader(colValue.toString());
}
- if ((SSType.BINARY == destSSType) || (SSType.VARBINARY == destSSType) || (SSType.VARBINARYMAX == destSSType)
- || (SSType.IMAGE == destSSType)) {
- tdsWriter.writeNonUnicodeReader(reader, DataTypes.UNKNOWN_STREAM_LENGTH, true, null);
- }
- else {
+ if ((SSType.BINARY == destSSType) || (SSType.VARBINARY == destSSType)
+ || (SSType.VARBINARYMAX == destSSType) || (SSType.IMAGE == destSSType)) {
+ tdsWriter.writeNonUnicodeReader(reader, DataTypes.UNKNOWN_STREAM_LENGTH, true,
+ null);
+ } else {
SQLCollation destCollation = destColumnMetadata.get(destColOrdinal).collation;
if (null != destCollation) {
- tdsWriter.writeNonUnicodeReader(reader, DataTypes.UNKNOWN_STREAM_LENGTH, false, destCollation.getCharset());
- }
- else {
- tdsWriter.writeNonUnicodeReader(reader, DataTypes.UNKNOWN_STREAM_LENGTH, false, null);
+ tdsWriter.writeNonUnicodeReader(reader, DataTypes.UNKNOWN_STREAM_LENGTH, false,
+ destCollation.getCharset());
+ } else {
+ tdsWriter.writeNonUnicodeReader(reader, DataTypes.UNKNOWN_STREAM_LENGTH, false,
+ null);
}
}
reader.close();
- }
- catch (IOException e) {
- throw new SQLServerException(SQLServerException.getErrString("R_unableRetrieveSourceData"), e);
+ } catch (IOException e) {
+ throw new SQLServerException(
+ SQLServerException.getErrString("R_unableRetrieveSourceData"), e);
}
}
- }
- else // Non-PLP
+ } else // Non-PLP
{
if (null == colValue) {
writeNullToTdsWriter(tdsWriter, bulkJdbcType, isStreaming);
- }
- else {
+ } else {
String colValueStr = colValue.toString();
if ((SSType.BINARY == destSSType) || (SSType.VARBINARY == destSSType)) {
byte[] bytes = null;
try {
bytes = ParameterUtils.HexToBin(colValueStr);
- }
- catch (SQLServerException e) {
- throw new SQLServerException(SQLServerException.getErrString("R_unableRetrieveSourceData"), e);
+ } catch (SQLServerException e) {
+ throw new SQLServerException(
+ SQLServerException.getErrString("R_unableRetrieveSourceData"), e);
}
tdsWriter.writeShort((short) bytes.length);
tdsWriter.writeBytes(bytes);
- }
- else {
+ } else {
tdsWriter.writeShort((short) (colValueStr.length()));
// converting string into destination collation using Charset
SQLCollation destCollation = destColumnMetadata.get(destColOrdinal).collation;
if (null != destCollation) {
- tdsWriter.writeBytes(colValueStr.getBytes(destColumnMetadata.get(destColOrdinal).collation.getCharset()));
+ tdsWriter.writeBytes(colValueStr
+ .getBytes(destColumnMetadata.get(destColOrdinal).collation.getCharset()));
- }
- else {
+ } else {
tdsWriter.writeBytes(colValueStr.getBytes());
}
}
@@ -2322,21 +2263,23 @@ else if (null != sourceBulkRecord) {
break;
/*
- * The length value associated with these data types is specified within a USHORT. see MS-TDS.pdf page 38. However, nchar(n)
- * nvarchar(n) supports n = 1 .. 4000 (see MSDN SQL 2014, SQL 2016 Transact-SQL) NVARCHAR/NCHAR/LONGNVARCHAR is not compatible with
- * BINARY/VARBINARY as specified in enum UpdaterConversion of DataTypes.java
+ * The length value associated with these data types is specified within a USHORT. see MS-TDS.pdf page
+ * 38. However, nchar(n) nvarchar(n) supports n = 1 .. 4000 (see MSDN SQL 2014, SQL 2016 Transact-SQL)
+ * NVARCHAR/NCHAR/LONGNVARCHAR is not compatible with BINARY/VARBINARY as specified in enum
+ * UpdaterConversion of DataTypes.java
*/
case java.sql.Types.LONGNVARCHAR:
case java.sql.Types.NCHAR:
case java.sql.Types.NVARCHAR:
if (isStreaming) {
// PLP_BODY rule in TDS
- // Use ResultSet.getString for non-streaming data and ResultSet.getNCharacterStream() for streaming data,
- // so that if the source data source does not have streaming enabled, the smaller size data will still work.
+ // Use ResultSet.getString for non-streaming data and ResultSet.getNCharacterStream() for
+ // streaming data,
+ // so that if the source data source does not have streaming enabled, the smaller size data will
+ // still work.
if (null == colValue) {
writeNullToTdsWriter(tdsWriter, bulkJdbcType, isStreaming);
- }
- else {
+ } else {
// Send length as unknown.
tdsWriter.writeLong(PLPInputStream.UNKNOWN_PLP_LEN);
try {
@@ -2344,25 +2287,22 @@ else if (null != sourceBulkRecord) {
Reader reader;
if (colValue instanceof Reader) {
reader = (Reader) colValue;
- }
- else {
+ } else {
reader = new StringReader(colValue.toString());
}
// writeReader is unicode.
tdsWriter.writeReader(reader, DataTypes.UNKNOWN_STREAM_LENGTH, true);
reader.close();
- }
- catch (IOException e) {
- throw new SQLServerException(SQLServerException.getErrString("R_unableRetrieveSourceData"), e);
+ } catch (IOException e) {
+ throw new SQLServerException(
+ SQLServerException.getErrString("R_unableRetrieveSourceData"), e);
}
}
- }
- else {
+ } else {
if (null == colValue) {
writeNullToTdsWriter(tdsWriter, bulkJdbcType, isStreaming);
- }
- else {
+ } else {
int stringLength = colValue.toString().length();
byte[] typevarlen = new byte[2];
typevarlen[0] = (byte) (2 * stringLength & 0xFF);
@@ -2378,12 +2318,12 @@ else if (null != sourceBulkRecord) {
case java.sql.Types.VARBINARY:
if (isStreaming) // PLP
{
- // Check for null separately for streaming and non-streaming data types, there could be source data sources who
+ // Check for null separately for streaming and non-streaming data types, there could be source
+ // data sources who
// does not support streaming data.
if (null == colValue) {
writeNullToTdsWriter(tdsWriter, bulkJdbcType, isStreaming);
- }
- else {
+ } else {
// Send length as unknown.
tdsWriter.writeLong(PLPInputStream.UNKNOWN_PLP_LEN);
try {
@@ -2391,39 +2331,35 @@ else if (null != sourceBulkRecord) {
InputStream iStream;
if (colValue instanceof InputStream) {
iStream = (InputStream) colValue;
- }
- else {
+ } else {
if (colValue instanceof byte[]) {
iStream = new ByteArrayInputStream((byte[]) colValue);
- }
- else
- iStream = new ByteArrayInputStream(ParameterUtils.HexToBin(colValue.toString()));
+ } else
+ iStream = new ByteArrayInputStream(
+ ParameterUtils.HexToBin(colValue.toString()));
}
// We do not need to check for null values here as it is already checked above.
tdsWriter.writeStream(iStream, DataTypes.UNKNOWN_STREAM_LENGTH, true);
iStream.close();
- }
- catch (IOException e) {
- throw new SQLServerException(SQLServerException.getErrString("R_unableRetrieveSourceData"), e);
+ } catch (IOException e) {
+ throw new SQLServerException(
+ SQLServerException.getErrString("R_unableRetrieveSourceData"), e);
}
}
- }
- else // Non-PLP
+ } else // Non-PLP
{
if (null == colValue) {
writeNullToTdsWriter(tdsWriter, bulkJdbcType, isStreaming);
- }
- else {
+ } else {
byte[] srcBytes;
if (colValue instanceof byte[]) {
srcBytes = (byte[]) colValue;
- }
- else {
+ } else {
try {
srcBytes = ParameterUtils.HexToBin(colValue.toString());
- }
- catch (SQLServerException e) {
- throw new SQLServerException(SQLServerException.getErrString("R_unableRetrieveSourceData"), e);
+ } catch (SQLServerException e) {
+ throw new SQLServerException(
+ SQLServerException.getErrString("R_unableRetrieveSourceData"), e);
}
}
tdsWriter.writeShort((short) srcBytes.length);
@@ -2437,8 +2373,7 @@ else if (null != sourceBulkRecord) {
case java.sql.Types.TIMESTAMP:
if (null == colValue) {
writeNullToTdsWriter(tdsWriter, bulkJdbcType, isStreaming);
- }
- else {
+ } else {
switch (destSSType) {
case SMALLDATETIME:
if (bulkNullable)
@@ -2450,7 +2385,7 @@ else if (null != sourceBulkRecord) {
tdsWriter.writeByte((byte) 0x08);
tdsWriter.writeDatetime(colValue.toString());
break;
- default: // DATETIME2
+ default: // DATETIME2
if (bulkNullable) {
if (2 >= bulkScale)
tdsWriter.writeByte((byte) 0x06);
@@ -2470,8 +2405,7 @@ else if (4 >= bulkScale)
case java.sql.Types.DATE:
if (null == colValue) {
writeNullToTdsWriter(tdsWriter, bulkJdbcType, isStreaming);
- }
- else {
+ } else {
tdsWriter.writeByte((byte) 0x03);
tdsWriter.writeDate(colValue.toString());
}
@@ -2483,8 +2417,7 @@ else if (4 >= bulkScale)
// values are read as java.sql.Types.TIMESTAMP if srcJdbcType is java.sql.Types.TIME
if (null == colValue) {
writeNullToTdsWriter(tdsWriter, bulkJdbcType, isStreaming);
- }
- else {
+ } else {
if (2 >= bulkScale)
tdsWriter.writeByte((byte) 0x03);
else if (4 >= bulkScale)
@@ -2496,11 +2429,10 @@ else if (4 >= bulkScale)
}
break;
- case 2013: // java.sql.Types.TIME_WITH_TIMEZONE
+ case 2013: // java.sql.Types.TIME_WITH_TIMEZONE
if (null == colValue) {
writeNullToTdsWriter(tdsWriter, bulkJdbcType, isStreaming);
- }
- else {
+ } else {
if (2 >= bulkScale)
tdsWriter.writeByte((byte) 0x08);
else if (4 >= bulkScale)
@@ -2512,11 +2444,10 @@ else if (4 >= bulkScale)
}
break;
- case 2014: // java.sql.Types.TIMESTAMP_WITH_TIMEZONE
+ case 2014: // java.sql.Types.TIMESTAMP_WITH_TIMEZONE
if (null == colValue) {
writeNullToTdsWriter(tdsWriter, bulkJdbcType, isStreaming);
- }
- else {
+ } else {
if (2 >= bulkScale)
tdsWriter.writeByte((byte) 0x08);
else if (4 >= bulkScale)
@@ -2529,11 +2460,11 @@ else if (4 >= bulkScale)
break;
case microsoft.sql.Types.DATETIMEOFFSET:
- // We can safely cast the result set to a SQLServerResultSet as the DatetimeOffset type is only available in the JDBC driver.
+ // We can safely cast the result set to a SQLServerResultSet as the DatetimeOffset type is only
+ // available in the JDBC driver.
if (null == colValue) {
writeNullToTdsWriter(tdsWriter, bulkJdbcType, isStreaming);
- }
- else {
+ } else {
if (2 >= bulkScale)
tdsWriter.writeByte((byte) 0x08);
else if (4 >= bulkScale)
@@ -2550,7 +2481,8 @@ else if (4 >= bulkScale)
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_SQLVariantSupport"));
throw new SQLServerException(null, form.format(new Object[] {}), null, 0, false);
}
- writeSqlVariant(tdsWriter, colValue, sourceResultSet, srcColOrdinal, destColOrdinal, bulkJdbcType, bulkScale, isStreaming);
+ writeSqlVariant(tdsWriter, colValue, sourceResultSet, srcColOrdinal, destColOrdinal, bulkJdbcType,
+ bulkScale, isStreaming);
break;
default:
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_BulkTypeNotSupported"));
@@ -2558,8 +2490,7 @@ else if (4 >= bulkScale)
SQLServerException.makeFromDriverError(null, null, form.format(msgArgs), null, true);
break;
} // End of switch
- }
- catch (ClassCastException ex) {
+ } catch (ClassCastException ex) {
if (null == colValue) {
// this should not really happen, since ClassCastException should only happen when colValue is not null.
// just do one more checking here to make sure
@@ -2567,23 +2498,18 @@ else if (4 >= bulkScale)
}
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_errorConvertingValue"));
Object[] msgArgs = {colValue.getClass().getSimpleName(), JDBCType.of(bulkJdbcType)};
- throw new SQLServerException(form.format(msgArgs), SQLState.DATA_EXCEPTION_NOT_SPECIFIC, DriverError.NOT_SET, ex);
+ throw new SQLServerException(form.format(msgArgs), SQLState.DATA_EXCEPTION_NOT_SPECIFIC,
+ DriverError.NOT_SET, ex);
}
}
-
+
/**
* Writes sql_variant data based on the baseType for bulkcopy
*
* @throws SQLServerException
*/
- private void writeSqlVariant(TDSWriter tdsWriter,
- Object colValue,
- ResultSet sourceResultSet,
- int srcColOrdinal,
- int destColOrdinal,
- int bulkJdbcType,
- int bulkScale,
- boolean isStreaming) throws SQLServerException {
+ private void writeSqlVariant(TDSWriter tdsWriter, Object colValue, ResultSet sourceResultSet, int srcColOrdinal,
+ int destColOrdinal, int bulkJdbcType, int bulkScale, boolean isStreaming) throws SQLServerException {
if (null == colValue) {
writeNullToTdsWriter(tdsWriter, bulkJdbcType, isStreaming);
return;
@@ -2603,32 +2529,32 @@ private void writeSqlVariant(TDSWriter tdsWriter,
writeBulkCopySqlVariantHeader(10, TDSType.INT8.byteValue(), (byte) 0, tdsWriter);
tdsWriter.writeLong(Long.valueOf(colValue.toString()));
break;
-
+
case INT4:
writeBulkCopySqlVariantHeader(6, TDSType.INT4.byteValue(), (byte) 0, tdsWriter);
tdsWriter.writeInt(Integer.valueOf(colValue.toString()));
break;
-
+
case INT2:
writeBulkCopySqlVariantHeader(4, TDSType.INT2.byteValue(), (byte) 0, tdsWriter);
tdsWriter.writeShort(Short.valueOf(colValue.toString()));
break;
-
+
case INT1:
writeBulkCopySqlVariantHeader(3, TDSType.INT1.byteValue(), (byte) 0, tdsWriter);
tdsWriter.writeByte(Byte.valueOf(colValue.toString()));
break;
-
+
case FLOAT8:
writeBulkCopySqlVariantHeader(10, TDSType.FLOAT8.byteValue(), (byte) 0, tdsWriter);
tdsWriter.writeDouble(Double.valueOf(colValue.toString()));
break;
-
+
case FLOAT4:
writeBulkCopySqlVariantHeader(6, TDSType.FLOAT4.byteValue(), (byte) 0, tdsWriter);
tdsWriter.writeReal(Float.valueOf(colValue.toString()));
break;
-
+
case MONEY8:
// For decimalN we right TDSWriter.BIGDECIMAL_MAX_LENGTH as maximum length = 17
// 17 + 2 for basetype and probBytes + 2 for precision and length = 21 the length of data in header
@@ -2637,96 +2563,101 @@ private void writeSqlVariant(TDSWriter tdsWriter,
tdsWriter.writeByte((byte) 4);
tdsWriter.writeSqlVariantInternalBigDecimal((BigDecimal) colValue, bulkJdbcType);
break;
-
+
case MONEY4:
writeBulkCopySqlVariantHeader(21, TDSType.DECIMALN.byteValue(), (byte) 2, tdsWriter);
tdsWriter.writeByte((byte) 38);
tdsWriter.writeByte((byte) 4);
tdsWriter.writeSqlVariantInternalBigDecimal((BigDecimal) colValue, bulkJdbcType);
break;
-
+
case BIT1:
writeBulkCopySqlVariantHeader(3, TDSType.BIT1.byteValue(), (byte) 0, tdsWriter);
tdsWriter.writeByte((byte) (((Boolean) colValue).booleanValue() ? 1 : 0));
break;
-
+
case DATEN:
writeBulkCopySqlVariantHeader(5, TDSType.DATEN.byteValue(), (byte) 0, tdsWriter);
tdsWriter.writeDate(colValue.toString());
break;
-
+
case TIMEN:
- bulkScale = variantType.getScale();
+ int timeBulkScale = variantType.getScale();
int timeHeaderLength = 0x08; // default
- if (2 >= bulkScale) {
+ if (2 >= timeBulkScale) {
timeHeaderLength = 0x06;
- }
- else if (4 >= bulkScale) {
+ } else if (4 >= timeBulkScale) {
timeHeaderLength = 0x07;
- }
- else {
+ } else {
timeHeaderLength = 0x08;
}
- writeBulkCopySqlVariantHeader(timeHeaderLength, TDSType.TIMEN.byteValue(), (byte) 1, tdsWriter); // depending on scale, the header
+ writeBulkCopySqlVariantHeader(timeHeaderLength, TDSType.TIMEN.byteValue(), (byte) 1, tdsWriter); // depending
+ // on
+ // scale,
+ // the
+ // header
// length
// defers
- tdsWriter.writeByte((byte) bulkScale);
- tdsWriter.writeTime((java.sql.Timestamp) colValue, bulkScale);
+ tdsWriter.writeByte((byte) timeBulkScale);
+ tdsWriter.writeTime((java.sql.Timestamp) colValue, timeBulkScale);
break;
-
+
case DATETIME8:
writeBulkCopySqlVariantHeader(10, TDSType.DATETIME8.byteValue(), (byte) 0, tdsWriter);
tdsWriter.writeDatetime(colValue.toString());
break;
-
+
case DATETIME4:
// when the type is ambiguous, we write to bigger type
writeBulkCopySqlVariantHeader(10, TDSType.DATETIME8.byteValue(), (byte) 0, tdsWriter);
tdsWriter.writeDatetime(colValue.toString());
break;
-
+
case DATETIME2N:
- writeBulkCopySqlVariantHeader(10, TDSType.DATETIME2N.byteValue(), (byte) 1, tdsWriter); // 1 is probbytes for time
+ writeBulkCopySqlVariantHeader(10, TDSType.DATETIME2N.byteValue(), (byte) 1, tdsWriter); // 1 is
+ // probbytes for
+ // time
tdsWriter.writeByte((byte) 0x03);
String timeStampValue = colValue.toString();
- tdsWriter.writeTime(java.sql.Timestamp.valueOf(timeStampValue), 0x03); // datetime2 in sql_variant has up to scale 3 support
+ tdsWriter.writeTime(java.sql.Timestamp.valueOf(timeStampValue), 0x03); // datetime2 in sql_variant has
+ // up to scale 3 support
// Send only the date part
tdsWriter.writeDate(timeStampValue.substring(0, timeStampValue.lastIndexOf(' ')));
break;
-
+
case BIGCHAR:
int length = colValue.toString().length();
writeBulkCopySqlVariantHeader(9 + length, TDSType.BIGCHAR.byteValue(), (byte) 7, tdsWriter);
- tdsWriter.writeCollationForSqlVariant(variantType); // writes collation info and sortID
+ tdsWriter.writeCollationForSqlVariant(variantType); // writes collation info and sortID
tdsWriter.writeShort((short) (length));
SQLCollation destCollation = destColumnMetadata.get(destColOrdinal).collation;
if (null != destCollation) {
- tdsWriter.writeBytes(colValue.toString().getBytes(destColumnMetadata.get(destColOrdinal).collation.getCharset()));
- }
- else {
+ tdsWriter.writeBytes(colValue.toString()
+ .getBytes(destColumnMetadata.get(destColOrdinal).collation.getCharset()));
+ } else {
tdsWriter.writeBytes(colValue.toString().getBytes());
}
break;
-
+
case BIGVARCHAR:
length = colValue.toString().length();
writeBulkCopySqlVariantHeader(9 + length, TDSType.BIGVARCHAR.byteValue(), (byte) 7, tdsWriter);
- tdsWriter.writeCollationForSqlVariant(variantType); // writes collation info and sortID
+ tdsWriter.writeCollationForSqlVariant(variantType); // writes collation info and sortID
tdsWriter.writeShort((short) (length));
destCollation = destColumnMetadata.get(destColOrdinal).collation;
if (null != destCollation) {
- tdsWriter.writeBytes(colValue.toString().getBytes(destColumnMetadata.get(destColOrdinal).collation.getCharset()));
- }
- else {
+ tdsWriter.writeBytes(colValue.toString()
+ .getBytes(destColumnMetadata.get(destColOrdinal).collation.getCharset()));
+ } else {
tdsWriter.writeBytes(colValue.toString().getBytes());
}
break;
-
+
case NCHAR:
length = colValue.toString().length() * 2;
writeBulkCopySqlVariantHeader(9 + length, TDSType.NCHAR.byteValue(), (byte) 7, tdsWriter);
- tdsWriter.writeCollationForSqlVariant(variantType); // writes collation info and sortID
+ tdsWriter.writeCollationForSqlVariant(variantType); // writes collation info and sortID
int stringLength = colValue.toString().length();
byte[] typevarlen = new byte[2];
typevarlen[0] = (byte) (2 * stringLength & 0xFF);
@@ -2734,11 +2665,11 @@ else if (4 >= bulkScale) {
tdsWriter.writeBytes(typevarlen);
tdsWriter.writeString(colValue.toString());
break;
-
+
case NVARCHAR:
length = colValue.toString().length() * 2;
writeBulkCopySqlVariantHeader(9 + length, TDSType.NVARCHAR.byteValue(), (byte) 7, tdsWriter);
- tdsWriter.writeCollationForSqlVariant(variantType); // writes collation info and sortID
+ tdsWriter.writeCollationForSqlVariant(variantType); // writes collation info and sortID
stringLength = colValue.toString().length();
typevarlen = new byte[2];
typevarlen[0] = (byte) (2 * stringLength & 0xFF);
@@ -2746,27 +2677,28 @@ else if (4 >= bulkScale) {
tdsWriter.writeBytes(typevarlen);
tdsWriter.writeString(colValue.toString());
break;
-
+
case GUID:
length = colValue.toString().length();
writeBulkCopySqlVariantHeader(9 + length, TDSType.BIGCHAR.byteValue(), (byte) 7, tdsWriter);
- // since while reading collation from sourceMetaData in guid we don't read collation, cause we are reading binary
+ // since while reading collation from sourceMetaData in guid we don't read collation, cause we are
+ // reading binary
// but in writing it we are using char, we need to get the collation.
- SQLCollation collation = (null != destColumnMetadata.get(srcColOrdinal).collation) ? destColumnMetadata.get(srcColOrdinal).collation
- : connection.getDatabaseCollation();
+ SQLCollation collation = (null != destColumnMetadata.get(srcColOrdinal).collation) ? destColumnMetadata
+ .get(srcColOrdinal).collation : connection.getDatabaseCollation();
variantType.setCollation(collation);
- tdsWriter.writeCollationForSqlVariant(variantType); // writes collation info and sortID
+ tdsWriter.writeCollationForSqlVariant(variantType); // writes collation info and sortID
tdsWriter.writeShort((short) (length));
// converting string into destination collation using Charset
destCollation = destColumnMetadata.get(destColOrdinal).collation;
if (null != destCollation) {
- tdsWriter.writeBytes(colValue.toString().getBytes(destColumnMetadata.get(destColOrdinal).collation.getCharset()));
- }
- else {
+ tdsWriter.writeBytes(colValue.toString()
+ .getBytes(destColumnMetadata.get(destColOrdinal).collation.getCharset()));
+ } else {
tdsWriter.writeBytes(colValue.toString().getBytes());
}
break;
-
+
case BIGBINARY:
byte[] b = (byte[]) colValue;
length = b.length;
@@ -2774,24 +2706,22 @@ else if (4 >= bulkScale) {
tdsWriter.writeShort((short) (variantType.getMaxLength())); // length
if (null == colValue) {
writeNullToTdsWriter(tdsWriter, bulkJdbcType, isStreaming);
- }
- else {
+ } else {
byte[] srcBytes;
if (colValue instanceof byte[]) {
srcBytes = (byte[]) colValue;
- }
- else {
+ } else {
try {
srcBytes = ParameterUtils.HexToBin(colValue.toString());
- }
- catch (SQLServerException e) {
- throw new SQLServerException(SQLServerException.getErrString("R_unableRetrieveSourceData"), e);
+ } catch (SQLServerException e) {
+ throw new SQLServerException(SQLServerException.getErrString("R_unableRetrieveSourceData"),
+ e);
}
}
tdsWriter.writeBytes(srcBytes);
}
break;
-
+
case BIGVARBINARY:
b = (byte[]) colValue;
length = b.length;
@@ -2799,24 +2729,22 @@ else if (4 >= bulkScale) {
tdsWriter.writeShort((short) (variantType.getMaxLength())); // length
if (null == colValue) {
writeNullToTdsWriter(tdsWriter, bulkJdbcType, isStreaming);
- }
- else {
+ } else {
byte[] srcBytes;
if (colValue instanceof byte[]) {
srcBytes = (byte[]) colValue;
- }
- else {
+ } else {
try {
srcBytes = ParameterUtils.HexToBin(colValue.toString());
- }
- catch (SQLServerException e) {
- throw new SQLServerException(SQLServerException.getErrString("R_unableRetrieveSourceData"), e);
+ } catch (SQLServerException e) {
+ throw new SQLServerException(SQLServerException.getErrString("R_unableRetrieveSourceData"),
+ e);
}
}
tdsWriter.writeBytes(srcBytes);
}
break;
-
+
default:
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_BulkTypeNotSupported"));
Object[] msgArgs = {JDBCType.of(bulkJdbcType).toString().toLowerCase(Locale.ENGLISH)};
@@ -2824,44 +2752,43 @@ else if (4 >= bulkScale) {
break;
}
}
-
+
/**
* Write header for sql_variant
*
* @param length:
- * length of base type + Basetype + probBytes
+ * length of base type + Basetype + probBytes
* @param tdsType
* @param probBytes
* @param tdsWriter
* @throws SQLServerException
*/
- private void writeBulkCopySqlVariantHeader(int length,
- byte tdsType,
- byte probBytes,
+ private void writeBulkCopySqlVariantHeader(int length, byte tdsType, byte probBytes,
TDSWriter tdsWriter) throws SQLServerException {
tdsWriter.writeInt(length);
tdsWriter.writeByte(tdsType);
tdsWriter.writeByte(probBytes);
}
- private Object readColumnFromResultSet(int srcColOrdinal,
- int srcJdbcType,
- boolean isStreaming,
+ private Object readColumnFromResultSet(int srcColOrdinal, int srcJdbcType, boolean isStreaming,
boolean isDestEncrypted) throws SQLServerException {
CryptoMetadata srcCryptoMeta = null;
// if source is encrypted read its baseTypeInfo
if ((sourceResultSet instanceof SQLServerResultSet)
- && (null != (srcCryptoMeta = ((SQLServerResultSet) sourceResultSet).getterGetColumn(srcColOrdinal).getCryptoMetadata()))) {
+ && (null != (srcCryptoMeta = ((SQLServerResultSet) sourceResultSet).getterGetColumn(srcColOrdinal)
+ .getCryptoMetadata()))) {
srcJdbcType = srcCryptoMeta.baseTypeInfo.getSSType().getJDBCType().asJavaSqlType();
BulkColumnMetaData temp = srcColumnMetadata.get(srcColOrdinal);
srcColumnMetadata.put(srcColOrdinal, new BulkColumnMetaData(temp, srcCryptoMeta));
}
try {
- // We are sending the data using JDBCType and not using SSType as SQL Server will automatically do the conversion.
+ // We are sending the data using JDBCType and not using SSType as SQL Server will automatically do the
+ // conversion.
switch (srcJdbcType) {
- // For numeric types (like, int, smallint, bit, ...) use getObject() instead of get* methods as get* methods
+ // For numeric types (like, int, smallint, bit, ...) use getObject() instead of get* methods as get*
+ // methods
// return 0 if the value is null.
// Change getObject to get* as other data sources may not have similar implementation.
case java.sql.Types.INTEGER:
@@ -2881,19 +2808,20 @@ private Object readColumnFromResultSet(int srcColOrdinal,
case microsoft.sql.Types.GUID:
case java.sql.Types.LONGVARCHAR:
- case java.sql.Types.CHAR: // Fixed-length, non-Unicode string data.
- case java.sql.Types.VARCHAR: // Variable-length, non-Unicode string data.
+ case java.sql.Types.CHAR: // Fixed-length, non-Unicode string data.
+ case java.sql.Types.VARCHAR: // Variable-length, non-Unicode string data.
// PLP if stream type and both the source and destination are not encrypted
// This is because AE does not support streaming types.
// Therefore an encrypted source or destination means the data must not actually be streaming data
if (isStreaming && !isDestEncrypted && (null == srcCryptoMeta)) // PLP
{
- // Use ResultSet.getString for non-streaming data and ResultSet.getCharacterStream() for streaming data,
- // so that if the source data source does not have streaming enabled, the smaller size data will still work.
+ // Use ResultSet.getString for non-streaming data and ResultSet.getCharacterStream() for
+ // streaming data,
+ // so that if the source data source does not have streaming enabled, the smaller size data will
+ // still work.
return sourceResultSet.getCharacterStream(srcColOrdinal);
- }
- else // Non-PLP
+ } else // Non-PLP
{
return sourceResultSet.getString(srcColOrdinal);
}
@@ -2906,11 +2834,12 @@ private Object readColumnFromResultSet(int srcColOrdinal,
// Therefore an encrypted source or destination means the data must not actually be streaming data
if (isStreaming && !isDestEncrypted && (null == srcCryptoMeta)) // PLP
{
- // Use ResultSet.getString for non-streaming data and ResultSet.getNCharacterStream() for streaming data,
- // so that if the source data source does not have streaming enabled, the smaller size data will still work.
+ // Use ResultSet.getString for non-streaming data and ResultSet.getNCharacterStream() for
+ // streaming data,
+ // so that if the source data source does not have streaming enabled, the smaller size data will
+ // still work.
return sourceResultSet.getNCharacterStream(srcColOrdinal);
- }
- else {
+ } else {
return sourceResultSet.getObject(srcColOrdinal);
}
@@ -2923,8 +2852,7 @@ private Object readColumnFromResultSet(int srcColOrdinal,
if (isStreaming && !isDestEncrypted && (null == srcCryptoMeta)) // PLP
{
return sourceResultSet.getBinaryStream(srcColOrdinal);
- }
- else // Non-PLP
+ } else // Non-PLP
{
return sourceResultSet.getBytes(srcColOrdinal);
}
@@ -2942,10 +2870,11 @@ private Object readColumnFromResultSet(int srcColOrdinal,
return sourceResultSet.getDate(srcColOrdinal);
case microsoft.sql.Types.DATETIMEOFFSET:
- // We can safely cast the result set to a SQLServerResultSet as the DatetimeOffset type is only available in the JDBC driver.
+ // We can safely cast the result set to a SQLServerResultSet as the DatetimeOffset type is only
+ // available in the JDBC driver.
return ((SQLServerResultSet) sourceResultSet).getDateTimeOffset(srcColOrdinal);
- case microsoft.sql.Types.SQL_VARIANT:
+ case microsoft.sql.Types.SQL_VARIANT:
return sourceResultSet.getObject(srcColOrdinal);
default:
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_BulkTypeNotSupported"));
@@ -2953,19 +2882,16 @@ private Object readColumnFromResultSet(int srcColOrdinal,
SQLServerException.makeFromDriverError(null, null, form.format(msgArgs), null, true);
// This return will never be executed, but it is needed as Eclipse complains otherwise.
return null;
- }
- }
- catch (SQLException e) {
+ }
+ } catch (SQLException e) {
throw new SQLServerException(SQLServerException.getErrString("R_unableRetrieveSourceData"), e);
}
}
- /*
+ /**
* Reads the given column from the result set current row and writes the data to tdsWriter.
*/
- private void writeColumn(TDSWriter tdsWriter,
- int srcColOrdinal,
- int destColOrdinal,
+ private void writeColumn(TDSWriter tdsWriter, int srcColOrdinal, int destColOrdinal,
Object colValue) throws SQLServerException {
int srcPrecision, srcScale, destPrecision, srcJdbcType;
SSType destSSType = null;
@@ -2977,11 +2903,13 @@ private void writeColumn(TDSWriter tdsWriter,
destPrecision = destColumnMetadata.get(destColOrdinal).precision;
- if ((java.sql.Types.NCHAR == srcJdbcType) || (java.sql.Types.NVARCHAR == srcJdbcType) || (java.sql.Types.LONGNVARCHAR == srcJdbcType)) {
- isStreaming = (DataTypes.SHORT_VARTYPE_MAX_CHARS < srcPrecision) || (DataTypes.SHORT_VARTYPE_MAX_CHARS < destPrecision);
- }
- else {
- isStreaming = (DataTypes.SHORT_VARTYPE_MAX_BYTES < srcPrecision) || (DataTypes.SHORT_VARTYPE_MAX_BYTES < destPrecision);
+ if ((java.sql.Types.NCHAR == srcJdbcType) || (java.sql.Types.NVARCHAR == srcJdbcType)
+ || (java.sql.Types.LONGNVARCHAR == srcJdbcType)) {
+ isStreaming = (DataTypes.SHORT_VARTYPE_MAX_CHARS < srcPrecision)
+ || (DataTypes.SHORT_VARTYPE_MAX_CHARS < destPrecision);
+ } else {
+ isStreaming = (DataTypes.SHORT_VARTYPE_MAX_BYTES < srcPrecision)
+ || (DataTypes.SHORT_VARTYPE_MAX_BYTES < destPrecision);
}
CryptoMetadata destCryptoMeta = destColumnMetadata.get(destColOrdinal).cryptoMeta;
@@ -2995,24 +2923,25 @@ private void writeColumn(TDSWriter tdsWriter,
colValue = readColumnFromResultSet(srcColOrdinal, srcJdbcType, isStreaming, (null != destCryptoMeta));
validateStringBinaryLengths(colValue, srcColOrdinal, destColOrdinal);
- // if AllowEncryptedValueModifications is set send varbinary read from source without checking type conversion
+ // if AllowEncryptedValueModifications is set send varbinary read from source without checking type
+ // conversion
if (!((copyOptions.isAllowEncryptedValueModifications())
// normalizationCheck() will be called for encrypted columns so skip this validation
|| ((null != destCryptoMeta) && (null != colValue)))) {
validateDataTypeConversions(srcColOrdinal, destColOrdinal);
}
}
- //If we are using ISQLBulkRecord and the data we are passing is char type, we need to check the source and dest precision
+ // If we are using ISQLBulkRecord and the data we are passing is char type, we need to check the source and dest
+ // precision
else if (null != sourceBulkRecord && (null == destCryptoMeta)) {
validateStringBinaryLengths(colValue, srcColOrdinal, destColOrdinal);
- }
- else if ((null != sourceBulkRecord) && (null != destCryptoMeta)) {
+ } else if ((null != sourceBulkRecord) && (null != destCryptoMeta)) {
// From CSV to encrypted column. Convert to respective object.
- if ((java.sql.Types.DATE == srcJdbcType) || (java.sql.Types.TIME == srcJdbcType) || (java.sql.Types.TIMESTAMP == srcJdbcType)
- || (microsoft.sql.Types.DATETIMEOFFSET == srcJdbcType) || (2013 == srcJdbcType) || (2014 == srcJdbcType)) {
+ if ((java.sql.Types.DATE == srcJdbcType) || (java.sql.Types.TIME == srcJdbcType)
+ || (java.sql.Types.TIMESTAMP == srcJdbcType) || (microsoft.sql.Types.DATETIMEOFFSET == srcJdbcType)
+ || (2013 == srcJdbcType) || (2014 == srcJdbcType)) {
colValue = getTemporalObjectFromCSV(colValue, srcJdbcType, srcColOrdinal);
- }
- else if ((java.sql.Types.NUMERIC == srcJdbcType) || (java.sql.Types.DECIMAL == srcJdbcType)) {
+ } else if ((java.sql.Types.NUMERIC == srcJdbcType) || (java.sql.Types.DECIMAL == srcJdbcType)) {
int baseDestPrecision = destCryptoMeta.baseTypeInfo.getPrecision();
int baseDestScale = destCryptoMeta.baseTypeInfo.getScale();
if ((srcScale != baseDestScale) || (srcPrecision != baseDestPrecision)) {
@@ -3028,14 +2957,13 @@ else if ((java.sql.Types.NUMERIC == srcJdbcType) || (java.sql.Types.DECIMAL == s
CryptoMetadata srcCryptoMeta = srcColumnMetadata.get(srcColOrdinal).cryptoMeta;
// If destination is encrypted column, transparently encrypt the data
if ((null != destCryptoMeta) && (null != colValue)) {
- JDBCType baseSrcJdbcType = (null != srcCryptoMeta)
- ? srcColumnMetadata.get(srcColOrdinal).cryptoMeta.baseTypeInfo.getSSType().getJDBCType() : JDBCType.of(srcJdbcType);
+ JDBCType baseSrcJdbcType = (null != srcCryptoMeta) ? srcColumnMetadata
+ .get(srcColOrdinal).cryptoMeta.baseTypeInfo.getSSType().getJDBCType() : JDBCType.of(srcJdbcType);
if (JDBCType.TIMESTAMP == baseSrcJdbcType) {
if (SSType.DATETIME == destSSType) {
baseSrcJdbcType = JDBCType.DATETIME;
- }
- else if (SSType.SMALLDATETIME == destSSType) {
+ } else if (SSType.SMALLDATETIME == destSSType) {
baseSrcJdbcType = JDBCType.SMALLDATETIME;
}
}
@@ -3044,29 +2972,32 @@ else if (SSType.SMALLDATETIME == destSSType) {
|| (SSType.SMALLMONEY == destSSType && JDBCType.DECIMAL == baseSrcJdbcType)
|| (SSType.GUID == destSSType && JDBCType.CHAR == baseSrcJdbcType))) {
// check for bulkcopy from other than SQLServer, for instance for MYSQL, if anykind of chartype pass
- if (!(Util.isCharType(destSSType) && Util.isCharType(srcJdbcType)) && !(sourceResultSet instanceof SQLServerResultSet))
+ if (!(Util.isCharType(destSSType) && Util.isCharType(srcJdbcType))
+ && !(sourceResultSet instanceof SQLServerResultSet))
// check for normalization of AE data types
if (!baseSrcJdbcType.normalizationCheck(destSSType)) {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_unsupportedConversionAE"));
+ MessageFormat form = new MessageFormat(
+ SQLServerException.getErrString("R_unsupportedConversionAE"));
Object[] msgArgs = {baseSrcJdbcType, destSSType};
throw new SQLServerException(this, form.format(msgArgs), null, 0, false);
}
}
// if source is encrypted and temporal, call IOBuffer functions to encrypt
- if ((baseSrcJdbcType == JDBCType.DATE) || (baseSrcJdbcType == JDBCType.TIMESTAMP) || (baseSrcJdbcType == JDBCType.TIME)
- || (baseSrcJdbcType == JDBCType.DATETIMEOFFSET) || (baseSrcJdbcType == JDBCType.DATETIME)
- || (baseSrcJdbcType == JDBCType.SMALLDATETIME)) {
- colValue = getEncryptedTemporalBytes(tdsWriter, baseSrcJdbcType, colValue, srcColOrdinal, destCryptoMeta.baseTypeInfo.getScale());
- }
- else {
+ if ((baseSrcJdbcType == JDBCType.DATE) || (baseSrcJdbcType == JDBCType.TIMESTAMP)
+ || (baseSrcJdbcType == JDBCType.TIME) || (baseSrcJdbcType == JDBCType.DATETIMEOFFSET)
+ || (baseSrcJdbcType == JDBCType.DATETIME) || (baseSrcJdbcType == JDBCType.SMALLDATETIME)) {
+ colValue = getEncryptedTemporalBytes(tdsWriter, baseSrcJdbcType, colValue, srcColOrdinal,
+ destCryptoMeta.baseTypeInfo.getScale());
+ } else {
TypeInfo destTypeInfo = destCryptoMeta.getBaseTypeInfo();
JDBCType destJdbcType = destTypeInfo.getSSType().getJDBCType();
/*
- * the following if checks that no casting exception would be thrown in the normalizedValue() method below a SQLServerException is
- * then thrown before the ClassCastException could occur an example of how this situation could arise would be if the application
- * creates encrypted source and destination tables the result set used to read the source would have AE disabled (causing colValue to
- * be varbinary) AE would be enabled on the connection used to complete the bulkCopy operation
+ * the following if checks that no casting exception would be thrown in the normalizedValue() method
+ * below a SQLServerException is then thrown before the ClassCastException could occur an example of how
+ * this situation could arise would be if the application creates encrypted source and destination
+ * tables the result set used to read the source would have AE disabled (causing colValue to be
+ * varbinary) AE would be enabled on the connection used to complete the bulkCopy operation
*/
if ((!Util.isBinaryType(destJdbcType.getIntValue())) && (colValue instanceof byte[])) {
@@ -3075,19 +3006,32 @@ else if (SSType.SMALLDATETIME == destSSType) {
throw new SQLServerException(this, form.format(msgArgs), null, 0, false);
}
// normalize the values before encrypting them
- colValue = SQLServerSecurityUtility.encryptWithKey(
- normalizedValue(destJdbcType, colValue, baseSrcJdbcType, destTypeInfo.getPrecision(), destTypeInfo.getScale()),
- destCryptoMeta, connection);
+ colValue = SQLServerSecurityUtility.encryptWithKey(normalizedValue(destJdbcType, colValue,
+ baseSrcJdbcType, destTypeInfo.getPrecision(), destTypeInfo.getScale()), destCryptoMeta,
+ connection);
}
}
- writeColumnToTdsWriter(tdsWriter, srcPrecision, srcScale, srcJdbcType, srcNullable, srcColOrdinal, destColOrdinal, isStreaming, colValue);
+ writeColumnToTdsWriter(tdsWriter, srcPrecision, srcScale, srcJdbcType, srcNullable, srcColOrdinal,
+ destColOrdinal, isStreaming, colValue);
}
- // this method is called against jdbc41, but it require jdbc42 to work
- // therefore, we will throw exception.
- protected Object getTemporalObjectFromCSVWithFormatter(String valueStrUntrimmed,
- int srcJdbcType,
- int srcColOrdinal,
+ /**
+ * Returns the temporal object from CSV This method is called against jdbc41, but it require jdbc42 to work
+ * therefore, we will throw exception.
+ *
+ * @param valueStrUntrimmed
+ * valueStrUntrimmed
+ * @param srcJdbcType
+ * srcJdbcType
+ * @param srcColOrdinal
+ * srcColOrdinal
+ * @param dateTimeFormatter
+ * dateTimeFormatter
+ * @return temporal object
+ * @throws SQLServerException
+ * if parsing error
+ */
+ protected Object getTemporalObjectFromCSVWithFormatter(String valueStrUntrimmed, int srcJdbcType, int srcColOrdinal,
DateTimeFormatter dateTimeFormatter) throws SQLServerException {
try {
TemporalAccessor ta = dateTimeFormatter.parse(valueStrUntrimmed);
@@ -3124,7 +3068,7 @@ protected Object getTemporalObjectFromCSVWithFormatter(String valueStrUntrimmed,
taNano *= 10;
Timestamp ts = new Timestamp(cal.getTimeInMillis());
ts.setNanos(taNano);
-
+
switch (srcJdbcType) {
case java.sql.Types.TIMESTAMP:
return ts;
@@ -3139,8 +3083,7 @@ protected Object getTemporalObjectFromCSVWithFormatter(String valueStrUntrimmed,
case microsoft.sql.Types.DATETIMEOFFSET:
return DateTimeOffset.valueOf(ts, taOffsetSec / 60);
}
- }
- catch (DateTimeException | ArithmeticException e) {
+ } catch (DateTimeException | ArithmeticException e) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_ParsingError"));
Object[] msgArgs = {JDBCType.of(srcJdbcType)};
throw new SQLServerException(this, form.format(msgArgs), null, 0, false);
@@ -3148,16 +3091,14 @@ protected Object getTemporalObjectFromCSVWithFormatter(String valueStrUntrimmed,
return valueStrUntrimmed;
}
- private Object getTemporalObjectFromCSV(Object value,
- int srcJdbcType,
+ private Object getTemporalObjectFromCSV(Object value, int srcJdbcType,
int srcColOrdinal) throws SQLServerException {
// TIME_WITH_TIMEZONE and TIMESTAMP_WITH_TIMEZONE are not supported with encrypted columns.
if (2013 == srcJdbcType) {
MessageFormat form1 = new MessageFormat(SQLServerException.getErrString("R_UnsupportedDataTypeAE"));
Object[] msgArgs1 = {"TIME_WITH_TIMEZONE"};
throw new SQLServerException(this, form1.format(msgArgs1), null, 0, false);
- }
- else if (2014 == srcJdbcType) {
+ } else if (2014 == srcJdbcType) {
MessageFormat form2 = new MessageFormat(SQLServerException.getErrString("R_UnsupportedDataTypeAE"));
Object[] msgArgs2 = {"TIMESTAMP_WITH_TIMEZONE"};
throw new SQLServerException(this, form2.format(msgArgs2), null, 0, false);
@@ -3188,7 +3129,8 @@ else if (2014 == srcJdbcType) {
// Get the temporal values from the formatter
DateTimeFormatter dateTimeFormatter = srcColumnMetadata.get(srcColOrdinal).dateTimeFormatter;
if (null != dateTimeFormatter) {
- return getTemporalObjectFromCSVWithFormatter(valueStrUntrimmed, srcJdbcType, srcColOrdinal, dateTimeFormatter);
+ return getTemporalObjectFromCSVWithFormatter(valueStrUntrimmed, srcJdbcType, srcColOrdinal,
+ dateTimeFormatter);
}
// If we are here that means datetimeformatter is not present. Only default format is supported in this case.
@@ -3243,20 +3185,17 @@ else if (2014 == srcJdbcType) {
fractionalSeconds = Integer.parseInt(valueStr.substring(startIndx, endIndx));
fractionalSecondsLength = endIndx - startIndx;
hasTimeZone = true;
- }
- else // no timezone
+ } else // no timezone
{
fractionalSeconds = Integer.parseInt(valueStr.substring(startIndx));
fractionalSecondsLength = valueStr.length() - startIndx;
}
- }
- else {
+ } else {
endIndx = valueStr.indexOf(' ', startIndx);
if (-1 != endIndx) {
hasTimeZone = true;
seconds = Integer.parseInt(valueStr.substring(startIndx, endIndx));
- }
- else {
+ } else {
seconds = Integer.parseInt(valueStr.substring(startIndx));
++endIndx; // skip the space
}
@@ -3293,18 +3232,15 @@ else if ('-' == valueStr.charAt(startIndx)) {
ts.setNanos(fractionalSeconds);
return microsoft.sql.DateTimeOffset.valueOf(ts, totalOffset);
}
- }
- catch (IndexOutOfBoundsException e) {
+ } catch (IndexOutOfBoundsException e) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_ParsingError"));
Object[] msgArgs = {JDBCType.of(srcJdbcType)};
throw new SQLServerException(this, form.format(msgArgs), null, 0, false);
- }
- catch (NumberFormatException e) {
+ } catch (NumberFormatException e) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_ParsingError"));
Object[] msgArgs = {JDBCType.of(srcJdbcType)};
throw new SQLServerException(this, form.format(msgArgs), null, 0, false);
- }
- catch (IllegalArgumentException e) {
+ } catch (IllegalArgumentException e) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_ParsingError"));
Object[] msgArgs = {JDBCType.of(srcJdbcType)};
throw new SQLServerException(this, form.format(msgArgs), null, 0, false);
@@ -3313,11 +3249,8 @@ else if ('-' == valueStr.charAt(startIndx)) {
return value;
}
- private byte[] getEncryptedTemporalBytes(TDSWriter tdsWriter,
- JDBCType srcTemporalJdbcType,
- Object colValue,
- int srcColOrdinal,
- int scale) throws SQLServerException {
+ private byte[] getEncryptedTemporalBytes(TDSWriter tdsWriter, JDBCType srcTemporalJdbcType, Object colValue,
+ int srcColOrdinal, int scale) throws SQLServerException {
long utcMillis;
GregorianCalendar calendar;
@@ -3340,8 +3273,7 @@ private byte[] getEncryptedTemporalBytes(TDSWriter tdsWriter,
int subSecondNanos;
if (colValue instanceof java.sql.Timestamp) {
subSecondNanos = ((java.sql.Timestamp) colValue).getNanos();
- }
- else {
+ } else {
subSecondNanos = Nanos.PER_MILLISECOND * (int) (utcMillis % 1000);
if (subSecondNanos < 0)
subSecondNanos += Nanos.PER_SECOND;
@@ -3355,7 +3287,8 @@ private byte[] getEncryptedTemporalBytes(TDSWriter tdsWriter,
utcMillis = ((java.sql.Timestamp) colValue).getTime();
calendar.setTimeInMillis(utcMillis);
subSecondNanos = ((java.sql.Timestamp) colValue).getNanos();
- return tdsWriter.writeEncryptedScaledTemporal(calendar, subSecondNanos, scale, SSType.DATETIME2, (short) 0);
+ return tdsWriter.writeEncryptedScaledTemporal(calendar, subSecondNanos, scale, SSType.DATETIME2,
+ (short) 0);
case DATETIME:
case SMALLDATETIME:
@@ -3376,7 +3309,8 @@ private byte[] getEncryptedTemporalBytes(TDSWriter tdsWriter,
calendar.setLenient(true);
calendar.clear();
calendar.setTimeInMillis(utcMillis);
- return tdsWriter.writeEncryptedScaledTemporal(calendar, subSecondNanos, scale, SSType.DATETIMEOFFSET, (short) minutesOffset);
+ return tdsWriter.writeEncryptedScaledTemporal(calendar, subSecondNanos, scale, SSType.DATETIMEOFFSET,
+ (short) minutesOffset);
default:
@@ -3386,10 +3320,7 @@ private byte[] getEncryptedTemporalBytes(TDSWriter tdsWriter,
}
}
- private byte[] normalizedValue(JDBCType destJdbcType,
- Object value,
- JDBCType srcJdbcType,
- int destPrecision,
+ private byte[] normalizedValue(JDBCType destJdbcType, Object value, JDBCType srcJdbcType, int destPrecision,
int destScale) throws SQLServerException {
Long longValue = null;
byte[] byteValue = null;
@@ -3399,7 +3330,8 @@ private byte[] normalizedValue(JDBCType destJdbcType,
switch (destJdbcType) {
case BIT:
longValue = (long) ((Boolean) value ? 1 : 0);
- return ByteBuffer.allocate(Long.SIZE / Byte.SIZE).order(ByteOrder.LITTLE_ENDIAN).putLong(longValue).array();
+ return ByteBuffer.allocate(Long.SIZE / Byte.SIZE).order(ByteOrder.LITTLE_ENDIAN).putLong(longValue)
+ .array();
case TINYINT:
case SMALLINT:
@@ -3412,12 +3344,12 @@ private byte[] normalizedValue(JDBCType destJdbcType,
int intValue = (int) value;
short shortValue = (short) intValue;
longValue = (long) shortValue;
- }
- else
+ } else
longValue = (long) (short) value;
}
- return ByteBuffer.allocate(Long.SIZE / Byte.SIZE).order(ByteOrder.LITTLE_ENDIAN).putLong(longValue).array();
+ return ByteBuffer.allocate(Long.SIZE / Byte.SIZE).order(ByteOrder.LITTLE_ENDIAN).putLong(longValue)
+ .array();
case INTEGER:
switch (srcJdbcType) {
@@ -3431,7 +3363,8 @@ private byte[] normalizedValue(JDBCType destJdbcType,
default:
longValue = Long.valueOf((Integer) value);
}
- return ByteBuffer.allocate(Long.SIZE / Byte.SIZE).order(ByteOrder.LITTLE_ENDIAN).putLong(longValue).array();
+ return ByteBuffer.allocate(Long.SIZE / Byte.SIZE).order(ByteOrder.LITTLE_ENDIAN).putLong(longValue)
+ .array();
case BIGINT:
switch (srcJdbcType) {
@@ -3448,7 +3381,8 @@ private byte[] normalizedValue(JDBCType destJdbcType,
default:
longValue = (long) value;
}
- return ByteBuffer.allocate(Long.SIZE / Byte.SIZE).order(ByteOrder.LITTLE_ENDIAN).putLong(longValue).array();
+ return ByteBuffer.allocate(Long.SIZE / Byte.SIZE).order(ByteOrder.LITTLE_ENDIAN).putLong(longValue)
+ .array();
case BINARY:
case VARBINARY:
@@ -3456,8 +3390,7 @@ private byte[] normalizedValue(JDBCType destJdbcType,
byte[] byteArrayValue;
if (value instanceof String) {
byteArrayValue = ParameterUtils.HexToBin((String) value);
- }
- else {
+ } else {
byteArrayValue = (byte[]) value;
}
if (byteArrayValue.length > destPrecision) {
@@ -3496,11 +3429,14 @@ private byte[] normalizedValue(JDBCType destJdbcType,
case FLOAT:
Float floatValue = (value instanceof String) ? Float.parseFloat((String) value) : (Float) value;
- return ByteBuffer.allocate((Float.SIZE / Byte.SIZE)).order(ByteOrder.LITTLE_ENDIAN).putFloat(floatValue).array();
+ return ByteBuffer.allocate((Float.SIZE / Byte.SIZE)).order(ByteOrder.LITTLE_ENDIAN)
+ .putFloat(floatValue).array();
case DOUBLE:
- Double doubleValue = (value instanceof String) ? Double.parseDouble((String) value) : (Double) value;
- return ByteBuffer.allocate((Double.SIZE / Byte.SIZE)).order(ByteOrder.LITTLE_ENDIAN).putDouble(doubleValue).array();
+ Double doubleValue = (value instanceof String) ? Double.parseDouble((String) value)
+ : (Double) value;
+ return ByteBuffer.allocate((Double.SIZE / Byte.SIZE)).order(ByteOrder.LITTLE_ENDIAN)
+ .putDouble(doubleValue).array();
case NUMERIC:
case DECIMAL:
@@ -3511,8 +3447,7 @@ private byte[] normalizedValue(JDBCType destJdbcType,
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_InvalidDataForAE"));
Object[] msgArgs = {srcJdbcType, destJdbcType};
throw new SQLServerException(this, form.format(msgArgs), null, 0, false);
- }
- else if (srcDataScale < destScale)
+ } else if (srcDataScale < destScale)
// update the scale of source data based on the metadata for scale sent early
bigDataValue = bigDataValue.setScale(destScale);
@@ -3531,11 +3466,12 @@ else if (srcDataScale < destScale)
// Need to validate range in the client side as we are converting BigDecimal to integers.
Util.validateMoneyRange(bdValue, destJdbcType);
- // Get the total number of digits after the multiplication. Scale is hardcoded to 4. This is needed to get the proper rounding.
+ // Get the total number of digits after the multiplication. Scale is hardcoded to 4. This is needed
+ // to get the proper rounding.
int digitCount = (bdValue.precision() - bdValue.scale()) + 4;
- long moneyVal = ((BigDecimal) value)
- .multiply(new BigDecimal(10000), new java.math.MathContext(digitCount, java.math.RoundingMode.HALF_UP)).longValue();
+ long moneyVal = ((BigDecimal) value).multiply(new BigDecimal(10000),
+ new java.math.MathContext(digitCount, java.math.RoundingMode.HALF_UP)).longValue();
ByteBuffer bbuf = ByteBuffer.allocate(8).order(ByteOrder.LITTLE_ENDIAN);
bbuf.putInt((int) (moneyVal >> 32)).array();
bbuf.putInt((int) moneyVal).array();
@@ -3552,13 +3488,11 @@ else if (srcDataScale < destScale)
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_InvalidDataForAE"));
Object[] msgArgs = {srcJdbcType, destJdbcType};
throw new SQLServerException(this, form.format(msgArgs), null, 0, false);
- }
- catch (IllegalArgumentException ex) {
+ } catch (IllegalArgumentException ex) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_InvalidDataForAE"));
Object[] msgArgs = {srcJdbcType, destJdbcType};
throw new SQLServerException(this, form.format(msgArgs), null, 0, false);
- }
- catch (ClassCastException ex) {
+ } catch (ClassCastException ex) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_InvalidDataForAE"));
Object[] msgArgs = {srcJdbcType, destJdbcType};
throw new SQLServerException(this, form.format(msgArgs), null, 0, false);
@@ -3569,35 +3503,33 @@ private boolean goToNextRow() throws SQLServerException {
try {
if (null != sourceResultSet) {
return sourceResultSet.next();
- }
- else {
+ } else {
return sourceBulkRecord.next();
}
- }
- catch (SQLException e) {
+ } catch (SQLException e) {
throw new SQLServerException(SQLServerException.getErrString("R_unableRetrieveSourceData"), e);
}
}
- /*
+ /**
* Writes data for a batch of rows to the TDSWriter object. Writes the following part in the BulkLoadBCP stream
* (https://msdn.microsoft.com/en-us/library/dd340549.aspx) ...
*/
- private boolean writeBatchData(TDSWriter tdsWriter,
- TDSCommand command,
+ private boolean writeBatchData(TDSWriter tdsWriter, TDSCommand command,
boolean insertRowByRow) throws SQLServerException {
int batchsize = copyOptions.getBatchSize();
int row = 0;
while (true) {
// Default batchsize is 0 - means all rows are sent in one batch. In this case we will return
- // when all rows in the resultset are processed. If batchsize is not zero, we will return when one batch of rows are processed.
+ // when all rows in the resultset are processed. If batchsize is not zero, we will return when one batch of
+ // rows are processed.
if (0 != batchsize && row >= batchsize)
return true;
// No more data available, return false so we do not execute any more batches.
if (!goToNextRow())
return false;
-
+
if (insertRowByRow) {
// read response gotten from goToNextRow()
((SQLServerResultSet) sourceResultSet).getTDSReader().readPacket();
@@ -3614,12 +3546,13 @@ private boolean writeBatchData(TDSWriter tdsWriter,
// Loop for each destination column. The mappings is a many to one mapping
// where multiple source columns can be mapped to one destination column.
for (ColumnMapping columnMapping : columnMappings) {
- writeColumn(tdsWriter, columnMapping.sourceColumnOrdinal, columnMapping.destinationColumnOrdinal, null // cell
- // value is
- // retrieved
- // inside
- // writeRowData()
- // method.
+ writeColumn(tdsWriter, columnMapping.sourceColumnOrdinal, columnMapping.destinationColumnOrdinal,
+ null // cell
+ // value is
+ // retrieved
+ // inside
+ // writeRowData()
+ // method.
);
}
}
@@ -3630,14 +3563,14 @@ private boolean writeBatchData(TDSWriter tdsWriter,
try {
rowObjects = sourceBulkRecord.getRowData();
- }
- catch (Exception ex) {
+ } catch (Exception ex) {
// if no more data available to retrive
throw new SQLServerException(SQLServerException.getErrString("R_unableRetrieveSourceData"), ex);
}
for (ColumnMapping columnMapping : columnMappings) {
- // If the SQLServerBulkCSVRecord does not have metadata for columns, it returns strings in the object array.
+ // If the SQLServerBulkCSVRecord does not have metadata for columns, it returns strings in the
+ // object array.
// COnvert the strings using destination table types.
writeColumn(tdsWriter, columnMapping.sourceColumnOrdinal, columnMapping.destinationColumnOrdinal,
rowObjects[columnMapping.sourceColumnOrdinal - 1]);
@@ -3655,7 +3588,8 @@ private boolean writeBatchData(TDSWriter tdsWriter,
}
}
- protected void setStmtColumnEncriptionSetting(SQLServerStatementColumnEncryptionSetting stmtColumnEncriptionSetting) {
+ protected void setStmtColumnEncriptionSetting(
+ SQLServerStatementColumnEncryptionSetting stmtColumnEncriptionSetting) {
this.stmtColumnEncriptionSetting = stmtColumnEncriptionSetting;
}
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkCopyOptions.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkCopyOptions.java
index c247b1c28..67f76277b 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkCopyOptions.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkCopyOptions.java
@@ -1,294 +1,296 @@
-/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
- */
-
-package com.microsoft.sqlserver.jdbc;
-
-import java.text.MessageFormat;
-
-/**
- * A collection of settings that control how an instance of SQLServerBulkCopy behaves. Used when constructing a SQLServerBulkCopy instance to change
- * how the writeToServer methods for that instance behave.
- */
-public class SQLServerBulkCopyOptions {
- /**
- * Number of rows in each batch.
- *
- * A batch is complete when BatchSize rows have been processed or there are no more rows to send to the destination data source. Zero (the
- * default) indicates that each WriteToServer operation is a single batch. If the SqlBulkCopy instance has been declared without the
- * UseInternalTransaction option in effect, rows are sent to the server BatchSize rows at a time, but no transaction-related action is taken. If
- * UseInternalTransaction is in effect, each batch of rows is inserted as a separate transaction.
- *
- * Default: 0
- */
- private int batchSize;
-
- /**
- * Number of seconds for the operation to complete before it times out.
- *
- * A value of 0 indicates no limit; the bulk copy will wait indefinitely. If the operation does time out, the transaction is not committed and all
- * copied rows are removed from the destination table.
- *
- * Default: 60
- */
- private int bulkCopyTimeout;
-
- /**
- * Check constraints while data is being inserted.
- *
- * Default: false - constraints are not checked
- */
- private boolean checkConstraints;
-
- /**
- * When specified, cause the server to fire the insert triggers for the rows being inserted into the database.
- *
- * Default: false - no triggers are fired.
- */
- private boolean fireTriggers;
-
- /**
- * Preserve source identity values.
- *
- * Default: false - identity values are assigned by the destination.
- */
- private boolean keepIdentity;
-
- /**
- * Preserve null values in the destination table regardless of the settings for default values.
- *
- * Default: false - null values are replaced by default values where applicable.
- */
- private boolean keepNulls;
-
- /**
- * Obtain a bulk update lock for the duration of the bulk copy operation.
- *
- * Default: false - row locks are used.
- */
- private boolean tableLock;
-
- /**
- * When specified, each batch of the bulk-copy operation will occur within a transaction.
- *
- * Default: false - no transaction
- */
- private boolean useInternalTransaction;
-
- private boolean allowEncryptedValueModifications;
-
- /**
- * Initializes an instance of the SQLServerBulkCopySettings class using defaults for all of the settings.
- */
- public SQLServerBulkCopyOptions() {
- batchSize = 0;
- bulkCopyTimeout = 60;
- checkConstraints = false;
- fireTriggers = false;
- keepIdentity = false;
- keepNulls = false;
- tableLock = false;
- useInternalTransaction = false;
- allowEncryptedValueModifications = false;
- }
-
- /**
- * Gets the number of rows in each batch. At the end of each batch, the rows in the batch are sent to the server.
- *
- * @return Number of rows in each batch.
- */
- public int getBatchSize() {
- return batchSize;
- }
-
- /**
- * Sets the number of rows in each batch. At the end of each batch, the rows in the batch are sent to the server.
- *
- * @param batchSize
- * Number of rows in each batch.
- * @throws SQLServerException
- * If the batchSize being set is invalid.
- */
- public void setBatchSize(int batchSize) throws SQLServerException {
- if (batchSize >= 0) {
- this.batchSize = batchSize;
- }
- else {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidNegativeArg"));
- Object[] msgArgs = {"batchSize"};
- SQLServerException.makeFromDriverError(null, null, form.format(msgArgs), null, false);
- }
- }
-
- /**
- * Gets the number of seconds for the operation to complete before it times out.
- *
- * @return Number of seconds before operation times out.
- */
- public int getBulkCopyTimeout() {
- return bulkCopyTimeout;
- }
-
- /**
- * Sets the number of seconds for the operation to complete before it times out.
- *
- * @param timeout
- * Number of seconds before operation times out.
- * @throws SQLServerException
- * If the timeout being set is invalid.
- */
- public void setBulkCopyTimeout(int timeout) throws SQLServerException {
- if (timeout >= 0) {
- this.bulkCopyTimeout = timeout;
- }
- else {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidNegativeArg"));
- Object[] msgArgs = {"timeout"};
- SQLServerException.makeFromDriverError(null, null, form.format(msgArgs), null, false);
- }
- }
-
- /**
- * Indicates whether or not to preserve any source identity values.
- *
- * @return True if source identity values are to be preserved; false if they are to be assigned by the destination.
- */
- public boolean isKeepIdentity() {
- return keepIdentity;
- }
-
- /**
- * Sets whether or not to preserve any source identity values.
- *
- * @param keepIdentity
- * True if source identity values are to be preserved; false if they are to be assigned by the destination
- */
- public void setKeepIdentity(boolean keepIdentity) {
- this.keepIdentity = keepIdentity;
- }
-
- /**
- * Indicates whether to preserve null values in the destination table regardless of the settings for default values, or if they should be replaced
- * by default values (where applicable).
- *
- * @return True if null values should be preserved; false if null values should be replaced by default values where applicable.
- */
- public boolean isKeepNulls() {
- return keepNulls;
- }
-
- /**
- * Sets whether to preserve null values in the destination table regardless of the settings for default values, or if they should be replaced by
- * default values (where applicable).
- *
- * @param keepNulls
- * True if null values should be preserved; false if null values should be replaced by default values where applicable.
- */
- public void setKeepNulls(boolean keepNulls) {
- this.keepNulls = keepNulls;
- }
-
- /**
- * Indicates whether SQLServerBulkCopy should obtain a bulk update lock for the duration of the bulk copy operation.
- *
- * @return True to obtain row locks; false otherwise.
- */
- public boolean isTableLock() {
- return tableLock;
- }
-
- /**
- * Sets whether SQLServerBulkCopy should obtain a bulk update lock for the duration of the bulk copy operation.
- *
- * @param tableLock
- * True to obtain row locks; false otherwise.
- */
- public void setTableLock(boolean tableLock) {
- this.tableLock = tableLock;
- }
-
- /**
- * Indicates whether each batch of the bulk-copy operation will occur within a transaction or not.
- *
- * @return True if the batch will occur within a transaction; false otherwise.
- */
- public boolean isUseInternalTransaction() {
- return useInternalTransaction;
- }
-
- /**
- * Sets whether each batch of the bulk-copy operation will occur within a transaction or not.
- *
- * @param useInternalTransaction
- * True if the batch will occur within a transaction; false otherwise.
- */
- public void setUseInternalTransaction(boolean useInternalTransaction) {
- this.useInternalTransaction = useInternalTransaction;
- }
-
- /**
- * Indicates whether constraints are to be checked while data is being inserted or not.
- *
- * @return True if constraints are to be checked; false otherwise.
- */
- public boolean isCheckConstraints() {
- return checkConstraints;
- }
-
- /**
- * Sets whether constraints are to be checked while data is being inserted or not.
- *
- * @param checkConstraints
- * True if constraints are to be checked; false otherwise.
- */
- public void setCheckConstraints(boolean checkConstraints) {
- this.checkConstraints = checkConstraints;
- }
-
- /**
- * Indicates if the server should fire insert triggers for rows being inserted into the database.
- *
- * @return True triggers are enabled; false otherwise.
- */
- public boolean isFireTriggers() {
- return fireTriggers;
- }
-
- /**
- * Sets whether the server should be set to fire insert triggers for rows being inserted into the database.
- *
- * @param fireTriggers
- * True triggers are to be enabled; false otherwise.
- */
- public void setFireTriggers(boolean fireTriggers) {
- this.fireTriggers = fireTriggers;
- }
-
- /**
- * Indicates if allowEncryptedValueModifications option is enabled or not
- *
- * @return True if allowEncryptedValueModification is set to true; false otherwise.
- */
- public boolean isAllowEncryptedValueModifications() {
- return allowEncryptedValueModifications;
- }
-
- /**
- * Sets whether the driver would send data as is or would decrypt the data and encrypt it again before sending to SQL Server
- *
- * Use caution when specifying allowEncryptedValueModifications as this may lead to corrupting the database because the driver does not check if
- * the data is indeed encrypted, or if it is correctly encrypted using the same encryption type, algorithm and key as the target column.
- *
- * @param allowEncryptedValueModifications
- * enables bulk copying of encrypted data between tables or databases, without decrypting the data. Typically, an application would
- * select data from encrypted columns from one table without decrypting the data (the app would connect to the database with the column
- * encryption setting keyword set to disabled) and then would use this option to bulk insert the data, which is still encrypted.
- */
- public void setAllowEncryptedValueModifications(boolean allowEncryptedValueModifications) {
- this.allowEncryptedValueModifications = allowEncryptedValueModifications;
- }
-}
+/*
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ */
+
+package com.microsoft.sqlserver.jdbc;
+
+import java.text.MessageFormat;
+
+
+/**
+ * Provides a collection of settings that control how an instance of SQLServerBulkCopy behaves. Used when constructing a
+ * SQLServerBulkCopy instance to change how the writeToServer methods for that instance behave.
+ */
+public class SQLServerBulkCopyOptions {
+ /**
+ * Number of rows in each batch.
+ *
+ * A batch is complete when BatchSize rows have been processed or there are no more rows to send to the destination
+ * data source. Zero (the default) indicates that each WriteToServer operation is a single batch. If the SqlBulkCopy
+ * instance has been declared without the UseInternalTransaction option in effect, rows are sent to the server
+ * BatchSize rows at a time, but no transaction-related action is taken. If UseInternalTransaction is in effect,
+ * each batch of rows is inserted as a separate transaction.
+ *
+ * Default: 0
+ */
+ private int batchSize;
+
+ /**
+ * Number of seconds for the operation to complete before it times out.
+ *
+ * A value of 0 indicates no limit; the bulk copy will wait indefinitely. If the operation does time out, the
+ * transaction is not committed and all copied rows are removed from the destination table.
+ *
+ * Default: 60
+ */
+ private int bulkCopyTimeout;
+
+ /**
+ * Checks constraints while data is being inserted.
+ *
+ * Default: false - constraints are not checked
+ */
+ private boolean checkConstraints;
+
+ /**
+ * When specified, cause the server to fire the insert triggers for the rows being inserted into the database.
+ *
+ * Default: false - no triggers are fired.
+ */
+ private boolean fireTriggers;
+
+ /**
+ * Preserve source identity values.
+ *
+ * Default: false - identity values are assigned by the destination.
+ */
+ private boolean keepIdentity;
+
+ /**
+ * Preserve null values in the destination table regardless of the settings for default values.
+ *
+ * Default: false - null values are replaced by default values where applicable.
+ */
+ private boolean keepNulls;
+
+ /**
+ * Obtain a bulk update lock for the duration of the bulk copy operation.
+ *
+ * Default: false - row locks are used.
+ */
+ private boolean tableLock;
+
+ /**
+ * When specified, each batch of the bulk-copy operation will occur within a transaction.
+ *
+ * Default: false - no transaction
+ */
+ private boolean useInternalTransaction;
+
+ private boolean allowEncryptedValueModifications;
+
+ /**
+ * Constructs a SQLServerBulkCopySettings class using defaults for all of the settings.
+ */
+ public SQLServerBulkCopyOptions() {
+ batchSize = 0;
+ bulkCopyTimeout = 60;
+ checkConstraints = false;
+ fireTriggers = false;
+ keepIdentity = false;
+ keepNulls = false;
+ tableLock = false;
+ useInternalTransaction = false;
+ allowEncryptedValueModifications = false;
+ }
+
+ /**
+ * Returns the number of rows in each batch. At the end of each batch, the rows in the batch are sent to the server.
+ *
+ * @return Number of rows in each batch.
+ */
+ public int getBatchSize() {
+ return batchSize;
+ }
+
+ /**
+ * Sets the number of rows in each batch. At the end of each batch, the rows in the batch are sent to the server.
+ *
+ * @param batchSize
+ * Number of rows in each batch.
+ * @throws SQLServerException
+ * If the batchSize being set is invalid.
+ */
+ public void setBatchSize(int batchSize) throws SQLServerException {
+ if (batchSize >= 0) {
+ this.batchSize = batchSize;
+ } else {
+ MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidNegativeArg"));
+ Object[] msgArgs = {"batchSize"};
+ SQLServerException.makeFromDriverError(null, null, form.format(msgArgs), null, false);
+ }
+ }
+
+ /**
+ * Returns the number of seconds for the operation to complete before it times out.
+ *
+ * @return Number of seconds before operation times out.
+ */
+ public int getBulkCopyTimeout() {
+ return bulkCopyTimeout;
+ }
+
+ /**
+ * Sets the number of seconds for the operation to complete before it times out.
+ *
+ * @param timeout
+ * Number of seconds before operation times out.
+ * @throws SQLServerException
+ * If the timeout being set is invalid.
+ */
+ public void setBulkCopyTimeout(int timeout) throws SQLServerException {
+ if (timeout >= 0) {
+ this.bulkCopyTimeout = timeout;
+ } else {
+ MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidNegativeArg"));
+ Object[] msgArgs = {"timeout"};
+ SQLServerException.makeFromDriverError(null, null, form.format(msgArgs), null, false);
+ }
+ }
+
+ /**
+ * Returns whether or not to preserve any source identity values.
+ *
+ * @return True if source identity values are to be preserved; false if they are to be assigned by the destination.
+ */
+ public boolean isKeepIdentity() {
+ return keepIdentity;
+ }
+
+ /**
+ * Sets whether or not to preserve any source identity values.
+ *
+ * @param keepIdentity
+ * True if source identity values are to be preserved; false if they are to be assigned by the destination
+ */
+ public void setKeepIdentity(boolean keepIdentity) {
+ this.keepIdentity = keepIdentity;
+ }
+
+ /**
+ * Returns whether to preserve null values in the destination table regardless of the settings for default values,
+ * or if they should be replaced by default values (where applicable).
+ *
+ * @return True if null values should be preserved; false if null values should be replaced by default values where
+ * applicable.
+ */
+ public boolean isKeepNulls() {
+ return keepNulls;
+ }
+
+ /**
+ * Sets whether to preserve null values in the destination table regardless of the settings for default values, or
+ * if they should be replaced by default values (where applicable).
+ *
+ * @param keepNulls
+ * True if null values should be preserved; false if null values should be replaced by default values where
+ * applicable.
+ */
+ public void setKeepNulls(boolean keepNulls) {
+ this.keepNulls = keepNulls;
+ }
+
+ /**
+ * Returns whether SQLServerBulkCopy should obtain a bulk update lock for the duration of the bulk copy operation.
+ *
+ * @return True to obtain row locks; false otherwise.
+ */
+ public boolean isTableLock() {
+ return tableLock;
+ }
+
+ /**
+ * Sets whether SQLServerBulkCopy should obtain a bulk update lock for the duration of the bulk copy operation.
+ *
+ * @param tableLock
+ * True to obtain row locks; false otherwise.
+ */
+ public void setTableLock(boolean tableLock) {
+ this.tableLock = tableLock;
+ }
+
+ /**
+ * Returns whether each batch of the bulk-copy operation will occur within a transaction or not.
+ *
+ * @return True if the batch will occur within a transaction; false otherwise.
+ */
+ public boolean isUseInternalTransaction() {
+ return useInternalTransaction;
+ }
+
+ /**
+ * Sets whether each batch of the bulk-copy operation will occur within a transaction or not.
+ *
+ * @param useInternalTransaction
+ * True if the batch will occur within a transaction; false otherwise.
+ */
+ public void setUseInternalTransaction(boolean useInternalTransaction) {
+ this.useInternalTransaction = useInternalTransaction;
+ }
+
+ /**
+ * Returns whether constraints are to be checked while data is being inserted or not.
+ *
+ * @return True if constraints are to be checked; false otherwise.
+ */
+ public boolean isCheckConstraints() {
+ return checkConstraints;
+ }
+
+ /**
+ * Sets whether constraints are to be checked while data is being inserted or not.
+ *
+ * @param checkConstraints
+ * True if constraints are to be checked; false otherwise.
+ */
+ public void setCheckConstraints(boolean checkConstraints) {
+ this.checkConstraints = checkConstraints;
+ }
+
+ /**
+ * Returns if the server should fire insert triggers for rows being inserted into the database.
+ *
+ * @return True triggers are enabled; false otherwise.
+ */
+ public boolean isFireTriggers() {
+ return fireTriggers;
+ }
+
+ /**
+ * Sets whether the server should be set to fire insert triggers for rows being inserted into the database.
+ *
+ * @param fireTriggers
+ * True triggers are to be enabled; false otherwise.
+ */
+ public void setFireTriggers(boolean fireTriggers) {
+ this.fireTriggers = fireTriggers;
+ }
+
+ /**
+ * Returns if allowEncryptedValueModifications option is enabled or not
+ *
+ * @return True if allowEncryptedValueModification is set to true; false otherwise.
+ */
+ public boolean isAllowEncryptedValueModifications() {
+ return allowEncryptedValueModifications;
+ }
+
+ /**
+ * Sets whether the driver would send data as is or would decrypt the data and encrypt it again before sending to
+ * SQL Server
+ *
+ * Use caution when specifying allowEncryptedValueModifications as this may lead to corrupting the database because
+ * the driver does not check if the data is indeed encrypted, or if it is correctly encrypted using the same
+ * encryption type, algorithm and key as the target column.
+ *
+ * @param allowEncryptedValueModifications
+ * enables bulk copying of encrypted data between tables or databases, without decrypting the data.
+ * Typically, an application would select data from encrypted columns from one table without decrypting the
+ * data (the app would connect to the database with the column encryption setting keyword set to disabled)
+ * and then would use this option to bulk insert the data, which is still encrypted.
+ */
+ public void setAllowEncryptedValueModifications(boolean allowEncryptedValueModifications) {
+ this.allowEncryptedValueModifications = allowEncryptedValueModifications;
+ }
+}
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerCallableStatement.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerCallableStatement.java
index 57da43fff..87054ef95 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerCallableStatement.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerCallableStatement.java
@@ -1,9 +1,6 @@
/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc;
@@ -31,12 +28,14 @@
import java.util.Calendar;
import java.util.UUID;
+
/**
- * CallableStatement implements JDBC callable statements. CallableStatement allows the caller to specify the procedure name to call along with input
- * parameter value and output parameter types. Callable statement also allows the return of a return status with the ? = call( ?, ..) JDBC syntax
+ * Provides implementation of JDBC callable statements. CallableStatement allows the caller to specify the procedure
+ * name to call along with input parameter value and output parameter types. Callable statement also allows the return
+ * of a return status with the ? = call( ?, ..) JDBC syntax
*
- * The API javadoc for JDBC API methods that this class implements are not repeated here. Please see Sun's JDBC API interfaces javadoc for those
- * details.
+ * The API javadoc for JDBC API methods that this class implements are not repeated here. Please see Sun's JDBC API
+ * interfaces javadoc for those details.
*/
public class SQLServerCallableStatement extends SQLServerPreparedStatement implements ISQLServerCallableStatement {
@@ -67,28 +66,24 @@ String getClassNameInternal() {
* Create a new callable statement.
*
* @param connection
- * the connection
+ * the connection
* @param sql
- * the users call syntax
+ * the users call syntax
* @param nRSType
- * the result set type
+ * the result set type
* @param nRSConcur
- * the result set concurrency
+ * the result set concurrency
* @param stmtColEncSetting
- * the statement column encryption setting
+ * the statement column encryption setting
* @throws SQLServerException
*/
- SQLServerCallableStatement(SQLServerConnection connection,
- String sql,
- int nRSType,
- int nRSConcur,
+ SQLServerCallableStatement(SQLServerConnection connection, String sql, int nRSType, int nRSConcur,
SQLServerStatementColumnEncryptionSetting stmtColEncSetting) throws SQLServerException {
super(connection, sql, nRSType, nRSConcur, stmtColEncSetting);
}
@Override
- public void registerOutParameter(int index,
- int sqlType) throws SQLServerException {
+ public void registerOutParameter(int index, int sqlType) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "registerOutParameter", new Object[] {index, sqlType});
checkClosed();
@@ -228,8 +223,8 @@ final void processOutParameters() throws SQLServerException {
}
/**
- * Processes the remainder of the batch up to the final or batch-terminating DONE token that marks the end of a sp_[cursor][prep]exec stored
- * procedure call.
+ * Processes the remainder of the batch up to the final or batch-terminating DONE token that marks the end of a
+ * sp_[cursor][prep]exec stored procedure call.
*/
private void processBatchRemainder() throws SQLServerException {
final class ExecDoneHandler extends TDSTokenHandler {
@@ -260,8 +255,7 @@ boolean onDone(TDSReader tdsReader) throws SQLServerException {
TDSParser.parse(resultsReader(), execDoneHandler);
}
- private void skipOutParameters(int numParamsToSkip,
- boolean discardValues) throws SQLServerException {
+ private void skipOutParameters(int numParamsToSkip, boolean discardValues) throws SQLServerException {
/** TDS token handler for locating OUT parameters (RETURN_VALUE tokens) in the response token stream */
final class OutParamHandler extends TDSTokenHandler {
final StreamRetValue srv = new StreamRetValue();
@@ -335,7 +329,8 @@ boolean onRetValue(TDSReader tdsReader) throws SQLServerException {
// of sp_[cursor][prep]exec params.
outParamIndex -= outParamIndexAdjustment;
if ((outParamIndex < 0 || outParamIndex >= inOutParam.length) || (!inOutParam[outParamIndex].isOutput())) {
- getStatementLogger().info(toString() + " Unexpected outParamIndex: " + outParamIndex + "; adjustment: " + outParamIndexAdjustment);
+ getStatementLogger().info(toString() + " Unexpected outParamIndex: " + outParamIndex + "; adjustment: "
+ + outParamIndexAdjustment);
connection.throwInvalidTDS();
}
@@ -344,11 +339,10 @@ boolean onRetValue(TDSReader tdsReader) throws SQLServerException {
}
@Override
- public void registerOutParameter(int index,
- int sqlType,
- String typeName) throws SQLServerException {
+ public void registerOutParameter(int index, int sqlType, String typeName) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "registerOutParameter", new Object[] {index, sqlType, typeName});
+ loggerExternal.entering(getClassNameLogging(), "registerOutParameter",
+ new Object[] {index, sqlType, typeName});
checkClosed();
@@ -358,11 +352,10 @@ public void registerOutParameter(int index,
}
@Override
- public void registerOutParameter(int index,
- int sqlType,
- int scale) throws SQLServerException {
+ public void registerOutParameter(int index, int sqlType, int scale) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "registerOutParameter", new Object[] {index, sqlType, scale});
+ loggerExternal.entering(getClassNameLogging(), "registerOutParameter",
+ new Object[] {index, sqlType, scale});
checkClosed();
@@ -373,12 +366,10 @@ public void registerOutParameter(int index,
}
@Override
- public void registerOutParameter(int index,
- int sqlType,
- int precision,
- int scale) throws SQLServerException {
+ public void registerOutParameter(int index, int sqlType, int precision, int scale) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "registerOutParameter", new Object[] {index, sqlType, scale, precision});
+ loggerExternal.entering(getClassNameLogging(), "registerOutParameter",
+ new Object[] {index, sqlType, scale, precision});
checkClosed();
@@ -403,14 +394,16 @@ private Parameter getterGetParam(int index) throws SQLServerException {
// Check index refers to a registered OUT parameter
if (!inOutParam[index - 1].isOutput()) {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_outputParameterNotRegisteredForOutput"));
+ MessageFormat form = new MessageFormat(
+ SQLServerException.getErrString("R_outputParameterNotRegisteredForOutput"));
Object[] msgArgs = {index};
SQLServerException.makeFromDriverError(connection, this, form.format(msgArgs), "07009", true);
}
// If we haven't executed the statement yet then throw a nice friendly exception.
if (!wasExecuted())
- SQLServerException.makeFromDriverError(connection, this, SQLServerException.getErrString("R_statementMustBeExecuted"), "07009", false);
+ SQLServerException.makeFromDriverError(connection, this,
+ SQLServerException.getErrString("R_statementMustBeExecuted"), "07009", false);
resultsReader().getCommand().checkForInterrupt();
@@ -423,21 +416,19 @@ private Parameter getterGetParam(int index) throws SQLServerException {
return lastParamAccessed;
}
- private Object getValue(int parameterIndex,
- JDBCType jdbcType) throws SQLServerException {
+ private Object getValue(int parameterIndex, JDBCType jdbcType) throws SQLServerException {
return getterGetParam(parameterIndex).getValue(jdbcType, null, null, resultsReader());
}
- private Object getValue(int parameterIndex,
- JDBCType jdbcType,
- Calendar cal) throws SQLServerException {
+ private Object getValue(int parameterIndex, JDBCType jdbcType, Calendar cal) throws SQLServerException {
return getterGetParam(parameterIndex).getValue(jdbcType, null, cal, resultsReader());
}
- private Object getStream(int parameterIndex,
- StreamType streamType) throws SQLServerException {
+ private Object getStream(int parameterIndex, StreamType streamType) throws SQLServerException {
Object value = getterGetParam(parameterIndex).getValue(streamType.getJDBCType(),
- new InputStreamGetterArgs(streamType, getIsResponseBufferingAdaptive(), getIsResponseBufferingAdaptive(), toString()), null, // calendar
+ new InputStreamGetterArgs(streamType, getIsResponseBufferingAdaptive(),
+ getIsResponseBufferingAdaptive(), toString()),
+ null, // calendar
resultsReader());
activeStream = (Closeable) value;
@@ -446,7 +437,9 @@ private Object getStream(int parameterIndex,
private Object getSQLXMLInternal(int parameterIndex) throws SQLServerException {
SQLServerSQLXML value = (SQLServerSQLXML) getterGetParam(parameterIndex).getValue(JDBCType.SQLXML,
- new InputStreamGetterArgs(StreamType.SQLXML, getIsResponseBufferingAdaptive(), getIsResponseBufferingAdaptive(), toString()), null, // calendar
+ new InputStreamGetterArgs(StreamType.SQLXML, getIsResponseBufferingAdaptive(),
+ getIsResponseBufferingAdaptive(), toString()),
+ null, // calendar
resultsReader());
if (null != value)
@@ -518,8 +511,7 @@ public final String getNString(String parameterName) throws SQLException {
@Deprecated
@Override
- public BigDecimal getBigDecimal(int parameterIndex,
- int scale) throws SQLException {
+ public BigDecimal getBigDecimal(int parameterIndex, int scale) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "getBigDecimal", new Object[] {parameterIndex, scale});
checkClosed();
@@ -532,8 +524,7 @@ public BigDecimal getBigDecimal(int parameterIndex,
@Deprecated
@Override
- public BigDecimal getBigDecimal(String parameterName,
- int scale) throws SQLServerException {
+ public BigDecimal getBigDecimal(String parameterName, int scale) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "getBigDecimal", new Object[] {parameterName, scale});
checkClosed();
@@ -619,8 +610,7 @@ public Date getDate(String parameterName) throws SQLServerException {
}
@Override
- public Date getDate(int index,
- Calendar cal) throws SQLServerException {
+ public Date getDate(int index, Calendar cal) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "getDate", new Object[] {index, cal});
checkClosed();
@@ -630,8 +620,7 @@ public Date getDate(int index,
}
@Override
- public Date getDate(String parameterName,
- Calendar cal) throws SQLServerException {
+ public Date getDate(String parameterName, Calendar cal) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "getDate", new Object[] {parameterName, cal});
checkClosed();
@@ -701,90 +690,72 @@ public Object getObject(int index) throws SQLServerException {
loggerExternal.entering(getClassNameLogging(), "getObject", index);
checkClosed();
- Object value = getValue(index, getterGetParam(index).getJdbcTypeSetByUser() != null ? getterGetParam(index).getJdbcTypeSetByUser()
- : getterGetParam(index).getJdbcType());
+ Object value = getValue(index,
+ getterGetParam(index).getJdbcTypeSetByUser() != null ? getterGetParam(index).getJdbcTypeSetByUser()
+ : getterGetParam(index).getJdbcType());
loggerExternal.exiting(getClassNameLogging(), "getObject", value);
return value;
}
@Override
- public T getObject(int index,
- Class type) throws SQLException {
+ public T getObject(int index, Class type) throws SQLException {
loggerExternal.entering(getClassNameLogging(), "getObject", index);
checkClosed();
Object returnValue;
if (type == String.class) {
returnValue = getString(index);
- }
- else if (type == Byte.class) {
+ } else if (type == Byte.class) {
byte byteValue = getByte(index);
returnValue = wasNull() ? null : byteValue;
- }
- else if (type == Short.class) {
+ } else if (type == Short.class) {
short shortValue = getShort(index);
returnValue = wasNull() ? null : shortValue;
- }
- else if (type == Integer.class) {
+ } else if (type == Integer.class) {
int intValue = getInt(index);
returnValue = wasNull() ? null : intValue;
- }
- else if (type == Long.class) {
+ } else if (type == Long.class) {
long longValue = getLong(index);
returnValue = wasNull() ? null : longValue;
- }
- else if (type == BigDecimal.class) {
+ } else if (type == BigDecimal.class) {
returnValue = getBigDecimal(index);
- }
- else if (type == Boolean.class) {
+ } else if (type == Boolean.class) {
boolean booleanValue = getBoolean(index);
returnValue = wasNull() ? null : booleanValue;
- }
- else if (type == java.sql.Date.class) {
+ } else if (type == java.sql.Date.class) {
returnValue = getDate(index);
- }
- else if (type == java.sql.Time.class) {
+ } else if (type == java.sql.Time.class) {
returnValue = getTime(index);
- }
- else if (type == java.sql.Timestamp.class) {
+ } else if (type == java.sql.Timestamp.class) {
returnValue = getTimestamp(index);
- }
- else if (type == microsoft.sql.DateTimeOffset.class) {
+ } else if (type == microsoft.sql.DateTimeOffset.class) {
returnValue = getDateTimeOffset(index);
- }
- else if (type == UUID.class) {
+ } else if (type == UUID.class) {
// read binary, avoid string allocation and parsing
byte[] guid = getBytes(index);
returnValue = guid != null ? Util.readGUIDtoUUID(guid) : null;
- }
- else if (type == SQLXML.class) {
+ } else if (type == SQLXML.class) {
returnValue = getSQLXML(index);
- }
- else if (type == Blob.class) {
+ } else if (type == Blob.class) {
returnValue = getBlob(index);
- }
- else if (type == Clob.class) {
+ } else if (type == Clob.class) {
returnValue = getClob(index);
- }
- else if (type == NClob.class) {
+ } else if (type == NClob.class) {
returnValue = getNClob(index);
- }
- else if (type == byte[].class) {
+ } else if (type == byte[].class) {
returnValue = getBytes(index);
- }
- else if (type == Float.class) {
+ } else if (type == Float.class) {
float floatValue = getFloat(index);
returnValue = wasNull() ? null : floatValue;
- }
- else if (type == Double.class) {
+ } else if (type == Double.class) {
double doubleValue = getDouble(index);
returnValue = wasNull() ? null : doubleValue;
- }
- else {
+ } else {
// if the type is not supported the specification says the should
// a SQLException instead of SQLFeatureNotSupportedException
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_unsupportedConversionTo"));
Object[] msgArgs = {type};
- throw new SQLServerException(form.format(msgArgs), SQLState.DATA_EXCEPTION_NOT_SPECIFIC, DriverError.NOT_SET, null);
+ throw new SQLServerException(form.format(msgArgs), SQLState.DATA_EXCEPTION_NOT_SPECIFIC,
+ DriverError.NOT_SET, null);
}
loggerExternal.exiting(getClassNameLogging(), "getObject", index);
return type.cast(returnValue);
@@ -796,15 +767,14 @@ public Object getObject(String parameterName) throws SQLServerException {
checkClosed();
int parameterIndex = findColumn(parameterName);
Object value = getValue(parameterIndex,
- getterGetParam(parameterIndex).getJdbcTypeSetByUser() != null ? getterGetParam(parameterIndex).getJdbcTypeSetByUser()
- : getterGetParam(parameterIndex).getJdbcType());
+ getterGetParam(parameterIndex).getJdbcTypeSetByUser() != null ? getterGetParam(parameterIndex)
+ .getJdbcTypeSetByUser() : getterGetParam(parameterIndex).getJdbcType());
loggerExternal.exiting(getClassNameLogging(), "getObject", value);
return value;
}
@Override
- public T getObject(String parameterName,
- Class type) throws SQLException {
+ public T getObject(String parameterName, Class type) throws SQLException {
loggerExternal.entering(getClassNameLogging(), "getObject", parameterName);
checkClosed();
int parameterIndex = findColumn(parameterName);
@@ -852,8 +822,7 @@ public Time getTime(String parameterName) throws SQLServerException {
}
@Override
- public Time getTime(int index,
- Calendar cal) throws SQLServerException {
+ public Time getTime(int index, Calendar cal) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "getTime", new Object[] {index, cal});
checkClosed();
@@ -863,8 +832,7 @@ public Time getTime(int index,
}
@Override
- public Time getTime(String parameterName,
- Calendar cal) throws SQLServerException {
+ public Time getTime(String parameterName, Calendar cal) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "getTime", new Object[] {parameterName, cal});
checkClosed();
@@ -893,8 +861,7 @@ public Timestamp getTimestamp(String parameterName) throws SQLServerException {
}
@Override
- public Timestamp getTimestamp(int index,
- Calendar cal) throws SQLServerException {
+ public Timestamp getTimestamp(int index, Calendar cal) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "getTimestamp", new Object[] {index, cal});
checkClosed();
@@ -904,8 +871,7 @@ public Timestamp getTimestamp(int index,
}
@Override
- public Timestamp getTimestamp(String name,
- Calendar cal) throws SQLServerException {
+ public Timestamp getTimestamp(String name, Calendar cal) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "getTimestamp", new Object[] {name, cal});
checkClosed();
@@ -934,8 +900,7 @@ public Timestamp getDateTime(String parameterName) throws SQLServerException {
}
@Override
- public Timestamp getDateTime(int index,
- Calendar cal) throws SQLServerException {
+ public Timestamp getDateTime(int index, Calendar cal) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "getDateTime", new Object[] {index, cal});
checkClosed();
@@ -945,8 +910,7 @@ public Timestamp getDateTime(int index,
}
@Override
- public Timestamp getDateTime(String name,
- Calendar cal) throws SQLServerException {
+ public Timestamp getDateTime(String name, Calendar cal) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "getDateTime", new Object[] {name, cal});
checkClosed();
@@ -975,8 +939,7 @@ public Timestamp getSmallDateTime(String parameterName) throws SQLServerExceptio
}
@Override
- public Timestamp getSmallDateTime(int index,
- Calendar cal) throws SQLServerException {
+ public Timestamp getSmallDateTime(int index, Calendar cal) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "getSmallDateTime", new Object[] {index, cal});
checkClosed();
@@ -986,8 +949,7 @@ public Timestamp getSmallDateTime(int index,
}
@Override
- public Timestamp getSmallDateTime(String name,
- Calendar cal) throws SQLServerException {
+ public Timestamp getSmallDateTime(String name, Calendar cal) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "getSmallDateTime", new Object[] {name, cal});
checkClosed();
@@ -1004,8 +966,8 @@ public microsoft.sql.DateTimeOffset getDateTimeOffset(int index) throws SQLServe
// DateTimeOffset is not supported with SQL Server versions earlier than Katmai
if (!connection.isKatmaiOrLater())
- throw new SQLServerException(SQLServerException.getErrString("R_notSupported"), SQLState.DATA_EXCEPTION_NOT_SPECIFIC, DriverError.NOT_SET,
- null);
+ throw new SQLServerException(SQLServerException.getErrString("R_notSupported"),
+ SQLState.DATA_EXCEPTION_NOT_SPECIFIC, DriverError.NOT_SET, null);
microsoft.sql.DateTimeOffset value = (microsoft.sql.DateTimeOffset) getValue(index, JDBCType.DATETIMEOFFSET);
loggerExternal.exiting(getClassNameLogging(), "getDateTimeOffset", value);
@@ -1019,10 +981,11 @@ public microsoft.sql.DateTimeOffset getDateTimeOffset(String parameterName) thro
// DateTimeOffset is not supported with SQL Server versions earlier than Katmai
if (!connection.isKatmaiOrLater())
- throw new SQLServerException(SQLServerException.getErrString("R_notSupported"), SQLState.DATA_EXCEPTION_NOT_SPECIFIC, DriverError.NOT_SET,
- null);
+ throw new SQLServerException(SQLServerException.getErrString("R_notSupported"),
+ SQLState.DATA_EXCEPTION_NOT_SPECIFIC, DriverError.NOT_SET, null);
- microsoft.sql.DateTimeOffset value = (microsoft.sql.DateTimeOffset) getValue(findColumn(parameterName), JDBCType.DATETIMEOFFSET);
+ microsoft.sql.DateTimeOffset value = (microsoft.sql.DateTimeOffset) getValue(findColumn(parameterName),
+ JDBCType.DATETIMEOFFSET);
loggerExternal.exiting(getClassNameLogging(), "getDateTimeOffset", value);
return value;
}
@@ -1187,11 +1150,9 @@ void closeActiveStream() throws SQLServerException {
if (null != activeStream) {
try {
activeStream.close();
- }
- catch (IOException e) {
+ } catch (IOException e) {
SQLServerException.makeFromDriverError(null, null, e.getMessage(), null, true);
- }
- finally {
+ } finally {
activeStream = null;
}
}
@@ -1234,15 +1195,13 @@ public NClob getNClob(String parameterName) throws SQLException {
}
@Override
- public Object getObject(int parameterIndex,
- java.util.Map> map) throws SQLException {
+ public Object getObject(int parameterIndex, java.util.Map> map) throws SQLException {
SQLServerException.throwNotSupportedException(connection, this);
return null;
}
@Override
- public Object getObject(String parameterName,
- java.util.Map> m) throws SQLException {
+ public Object getObject(String parameterName, java.util.Map> m) throws SQLException {
checkClosed();
return getObject(findColumn(parameterName), m);
}
@@ -1277,16 +1236,18 @@ public java.sql.Array getArray(String parameterName) throws SQLException {
* Find a column's index given its name.
*
* @param columnName
- * the name
+ * the name
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
* @return the index
*/
private int findColumn(String columnName) throws SQLServerException {
if (parameterNames == null) {
try (SQLServerStatement s = (SQLServerStatement) connection.createStatement()) {
- // Note we are concatenating the information from the passed in sql, not any arguments provided by the user
- // if the user can execute the sql, any fragments of it is potentially executed via the meta data call through injection
+ // Note we are concatenating the information from the passed in sql, not any arguments provided by the
+ // user
+ // if the user can execute the sql, any fragments of it is potentially executed via the meta data call
+ // through injection
// is not a security issue.
ThreePartName threePartName = ThreePartName.parse(procedureName);
@@ -1306,11 +1267,11 @@ private int findColumn(String columnName) throws SQLServerException {
metaQuery.append("@procedure_name=");
metaQuery.append(threePartName.getProcedurePart());
metaQuery.append(" , @ODBCVer=3");
- }
- else {
+ } else {
// This should rarely happen, this will only happen if we can't find the stored procedure name
// invalidly formatted call syntax.
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_parameterNotDefinedForProcedure"));
+ MessageFormat form = new MessageFormat(
+ SQLServerException.getErrString("R_parameterNotDefinedForProcedure"));
Object[] msgArgs = {columnName, ""};
SQLServerException.makeFromDriverError(connection, this, form.format(msgArgs), "07009", false);
}
@@ -1321,8 +1282,7 @@ private int findColumn(String columnName) throws SQLServerException {
String parameterName = rs.getString(4);
parameterNames.add(parameterName.trim());
}
- }
- catch (SQLException e) {
+ } catch (SQLException e) {
SQLServerException.makeFromDriverError(connection, this, e.toString(), null, false);
}
@@ -1339,8 +1299,7 @@ private int findColumn(String columnName) throws SQLServerException {
String columnNameWithoutAtSign = null;
if (columnName.startsWith("@")) {
columnNameWithoutAtSign = columnName.substring(1, columnName.length());
- }
- else {
+ } else {
columnNameWithoutAtSign = columnName;
}
@@ -1378,7 +1337,8 @@ private int findColumn(String columnName) throws SQLServerException {
}
if (-1 == matchPos) {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_parameterNotDefinedForProcedure"));
+ MessageFormat form = new MessageFormat(
+ SQLServerException.getErrString("R_parameterNotDefinedForProcedure"));
Object[] msgArgs = {columnName, procedureName};
SQLServerException.makeFromDriverError(connection, this, form.format(msgArgs), "07009", false);
}
@@ -1392,32 +1352,29 @@ private int findColumn(String columnName) throws SQLServerException {
}
@Override
- public void setTimestamp(String parameterName,
- java.sql.Timestamp value,
+ public void setTimestamp(String parameterName, java.sql.Timestamp value,
Calendar calendar) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "setTimeStamp", new Object[] {parameterName, value, calendar});
+ loggerExternal.entering(getClassNameLogging(), "setTimeStamp",
+ new Object[] {parameterName, value, calendar});
checkClosed();
setValue(findColumn(parameterName), JDBCType.TIMESTAMP, value, JavaType.TIMESTAMP, calendar, false);
loggerExternal.exiting(getClassNameLogging(), "setTimeStamp");
}
@Override
- public void setTimestamp(String parameterName,
- java.sql.Timestamp value,
- Calendar calendar,
+ public void setTimestamp(String parameterName, java.sql.Timestamp value, Calendar calendar,
boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "setTimeStamp", new Object[] {parameterName, value, calendar, forceEncrypt});
+ loggerExternal.entering(getClassNameLogging(), "setTimeStamp",
+ new Object[] {parameterName, value, calendar, forceEncrypt});
checkClosed();
setValue(findColumn(parameterName), JDBCType.TIMESTAMP, value, JavaType.TIMESTAMP, calendar, forceEncrypt);
loggerExternal.exiting(getClassNameLogging(), "setTimeStamp");
}
@Override
- public void setTime(String parameterName,
- java.sql.Time value,
- Calendar calendar) throws SQLServerException {
+ public void setTime(String parameterName, java.sql.Time value, Calendar calendar) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setTime", new Object[] {parameterName, value, calendar});
checkClosed();
@@ -1426,21 +1383,18 @@ public void setTime(String parameterName,
}
@Override
- public void setTime(String parameterName,
- java.sql.Time value,
- Calendar calendar,
+ public void setTime(String parameterName, java.sql.Time value, Calendar calendar,
boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "setTime", new Object[] {parameterName, value, calendar, forceEncrypt});
+ loggerExternal.entering(getClassNameLogging(), "setTime",
+ new Object[] {parameterName, value, calendar, forceEncrypt});
checkClosed();
setValue(findColumn(parameterName), JDBCType.TIME, value, JavaType.TIME, calendar, forceEncrypt);
loggerExternal.exiting(getClassNameLogging(), "setTime");
}
@Override
- public void setDate(String parameterName,
- java.sql.Date value,
- Calendar calendar) throws SQLServerException {
+ public void setDate(String parameterName, java.sql.Date value, Calendar calendar) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setDate", new Object[] {parameterName, value, calendar});
checkClosed();
@@ -1449,74 +1403,69 @@ public void setDate(String parameterName,
}
@Override
- public void setDate(String parameterName,
- java.sql.Date value,
- Calendar calendar,
+ public void setDate(String parameterName, java.sql.Date value, Calendar calendar,
boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "setDate", new Object[] {parameterName, value, calendar, forceEncrypt});
+ loggerExternal.entering(getClassNameLogging(), "setDate",
+ new Object[] {parameterName, value, calendar, forceEncrypt});
checkClosed();
setValue(findColumn(parameterName), JDBCType.DATE, value, JavaType.DATE, calendar, forceEncrypt);
loggerExternal.exiting(getClassNameLogging(), "setDate");
}
@Override
- public final void setCharacterStream(String parameterName,
- Reader reader) throws SQLException {
+ public final void setCharacterStream(String parameterName, Reader reader) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setCharacterStream", new Object[] {parameterName, reader});
checkClosed();
- setStream(findColumn(parameterName), StreamType.CHARACTER, reader, JavaType.READER, DataTypes.UNKNOWN_STREAM_LENGTH);
+ setStream(findColumn(parameterName), StreamType.CHARACTER, reader, JavaType.READER,
+ DataTypes.UNKNOWN_STREAM_LENGTH);
loggerExternal.exiting(getClassNameLogging(), "setCharacterStream");
}
@Override
- public final void setCharacterStream(String parameterName,
- Reader value,
- int length) throws SQLException {
+ public final void setCharacterStream(String parameterName, Reader value, int length) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "setCharacterStream", new Object[] {parameterName, value, length});
+ loggerExternal.entering(getClassNameLogging(), "setCharacterStream",
+ new Object[] {parameterName, value, length});
checkClosed();
setStream(findColumn(parameterName), StreamType.CHARACTER, value, JavaType.READER, length);
loggerExternal.exiting(getClassNameLogging(), "setCharacterStream");
}
@Override
- public final void setCharacterStream(String parameterName,
- Reader reader,
- long length) throws SQLException {
+ public final void setCharacterStream(String parameterName, Reader reader, long length) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "setCharacterStream", new Object[] {parameterName, reader, length});
+ loggerExternal.entering(getClassNameLogging(), "setCharacterStream",
+ new Object[] {parameterName, reader, length});
checkClosed();
setStream(findColumn(parameterName), StreamType.CHARACTER, reader, JavaType.READER, length);
loggerExternal.exiting(getClassNameLogging(), "setCharacterStream");
}
@Override
- public final void setNCharacterStream(String parameterName,
- Reader value) throws SQLException {
+ public final void setNCharacterStream(String parameterName, Reader value) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setNCharacterStream", new Object[] {parameterName, value});
checkClosed();
- setStream(findColumn(parameterName), StreamType.NCHARACTER, value, JavaType.READER, DataTypes.UNKNOWN_STREAM_LENGTH);
+ setStream(findColumn(parameterName), StreamType.NCHARACTER, value, JavaType.READER,
+ DataTypes.UNKNOWN_STREAM_LENGTH);
loggerExternal.exiting(getClassNameLogging(), "setNCharacterStream");
}
@Override
- public final void setNCharacterStream(String parameterName,
- Reader value,
- long length) throws SQLException {
+ public final void setNCharacterStream(String parameterName, Reader value, long length) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "setNCharacterStream", new Object[] {parameterName, value, length});
+ loggerExternal.entering(getClassNameLogging(), "setNCharacterStream",
+ new Object[] {parameterName, value, length});
checkClosed();
setStream(findColumn(parameterName), StreamType.NCHARACTER, value, JavaType.READER, length);
loggerExternal.exiting(getClassNameLogging(), "setNCharacterStream");
}
@Override
- public final void setClob(String parameterName,
- Clob value) throws SQLException {
+ public final void setClob(String parameterName, Clob value) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setClob", new Object[] {parameterName, value});
checkClosed();
@@ -1525,19 +1474,17 @@ public final void setClob(String parameterName,
}
@Override
- public final void setClob(String parameterName,
- Reader reader) throws SQLException {
+ public final void setClob(String parameterName, Reader reader) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setClob", new Object[] {parameterName, reader});
checkClosed();
- setStream(findColumn(parameterName), StreamType.CHARACTER, reader, JavaType.READER, DataTypes.UNKNOWN_STREAM_LENGTH);
+ setStream(findColumn(parameterName), StreamType.CHARACTER, reader, JavaType.READER,
+ DataTypes.UNKNOWN_STREAM_LENGTH);
loggerExternal.exiting(getClassNameLogging(), "setClob");
}
@Override
- public final void setClob(String parameterName,
- Reader value,
- long length) throws SQLException {
+ public final void setClob(String parameterName, Reader value, long length) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setClob", new Object[] {parameterName, value, length});
checkClosed();
@@ -1546,8 +1493,7 @@ public final void setClob(String parameterName,
}
@Override
- public final void setNClob(String parameterName,
- NClob value) throws SQLException {
+ public final void setNClob(String parameterName, NClob value) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setNClob", new Object[] {parameterName, value});
checkClosed();
@@ -1556,19 +1502,17 @@ public final void setNClob(String parameterName,
}
@Override
- public final void setNClob(String parameterName,
- Reader reader) throws SQLException {
+ public final void setNClob(String parameterName, Reader reader) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setNClob", new Object[] {parameterName, reader});
checkClosed();
- setStream(findColumn(parameterName), StreamType.NCHARACTER, reader, JavaType.READER, DataTypes.UNKNOWN_STREAM_LENGTH);
+ setStream(findColumn(parameterName), StreamType.NCHARACTER, reader, JavaType.READER,
+ DataTypes.UNKNOWN_STREAM_LENGTH);
loggerExternal.exiting(getClassNameLogging(), "setNClob");
}
@Override
- public final void setNClob(String parameterName,
- Reader reader,
- long length) throws SQLException {
+ public final void setNClob(String parameterName, Reader reader, long length) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setNClob", new Object[] {parameterName, reader, length});
checkClosed();
@@ -1577,8 +1521,7 @@ public final void setNClob(String parameterName,
}
@Override
- public final void setNString(String parameterName,
- String value) throws SQLException {
+ public final void setNString(String parameterName, String value) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setNString", new Object[] {parameterName, value});
checkClosed();
@@ -1587,19 +1530,17 @@ public final void setNString(String parameterName,
}
@Override
- public final void setNString(String parameterName,
- String value,
- boolean forceEncrypt) throws SQLServerException {
+ public final void setNString(String parameterName, String value, boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "setNString", new Object[] {parameterName, value, forceEncrypt});
+ loggerExternal.entering(getClassNameLogging(), "setNString",
+ new Object[] {parameterName, value, forceEncrypt});
checkClosed();
setValue(findColumn(parameterName), JDBCType.NVARCHAR, value, JavaType.STRING, forceEncrypt);
loggerExternal.exiting(getClassNameLogging(), "setNString");
}
@Override
- public void setObject(String parameterName,
- Object value) throws SQLServerException {
+ public void setObject(String parameterName, Object value) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setObject", new Object[] {parameterName, value});
checkClosed();
@@ -1608,45 +1549,38 @@ public void setObject(String parameterName,
}
@Override
- public void setObject(String parameterName,
- Object value,
- int sqlType) throws SQLServerException {
+ public void setObject(String parameterName, Object value, int sqlType) throws SQLServerException {
String tvpName = null;
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setObject", new Object[] {parameterName, value, sqlType});
checkClosed();
if (microsoft.sql.Types.STRUCTURED == sqlType) {
tvpName = getTVPNameIfNull(findColumn(parameterName), null);
- setObject(setterGetParam(findColumn(parameterName)), value, JavaType.TVP, JDBCType.TVP, null, null, false, findColumn(parameterName),
- tvpName);
- }
- else
- setObject(setterGetParam(findColumn(parameterName)), value, JavaType.of(value), JDBCType.of(sqlType), null, null, false,
+ setObject(setterGetParam(findColumn(parameterName)), value, JavaType.TVP, JDBCType.TVP, null, null, false,
findColumn(parameterName), tvpName);
+ } else
+ setObject(setterGetParam(findColumn(parameterName)), value, JavaType.of(value), JDBCType.of(sqlType), null,
+ null, false, findColumn(parameterName), tvpName);
loggerExternal.exiting(getClassNameLogging(), "setObject");
}
@Override
- public void setObject(String parameterName,
- Object value,
- int sqlType,
- int decimals) throws SQLServerException {
+ public void setObject(String parameterName, Object value, int sqlType, int decimals) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "setObject", new Object[] {parameterName, value, sqlType, decimals});
+ loggerExternal.entering(getClassNameLogging(), "setObject",
+ new Object[] {parameterName, value, sqlType, decimals});
checkClosed();
- setObject(setterGetParam(findColumn(parameterName)), value, JavaType.of(value), JDBCType.of(sqlType), decimals, null, false,
- findColumn(parameterName), null);
+ setObject(setterGetParam(findColumn(parameterName)), value, JavaType.of(value), JDBCType.of(sqlType), decimals,
+ null, false, findColumn(parameterName), null);
loggerExternal.exiting(getClassNameLogging(), "setObject");
}
@Override
- public void setObject(String parameterName,
- Object value,
- int sqlType,
- int decimals,
+ public void setObject(String parameterName, Object value, int sqlType, int decimals,
boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "setObject", new Object[] {parameterName, value, sqlType, decimals, forceEncrypt});
+ loggerExternal.entering(getClassNameLogging(), "setObject",
+ new Object[] {parameterName, value, sqlType, decimals, forceEncrypt});
checkClosed();
// scale - for java.sql.Types.DECIMAL or java.sql.Types.NUMERIC types,
@@ -1654,20 +1588,18 @@ public void setObject(String parameterName,
// For all other types, this value will be ignored.
setObject(setterGetParam(findColumn(parameterName)), value, JavaType.of(value), JDBCType.of(sqlType),
- (java.sql.Types.NUMERIC == sqlType || java.sql.Types.DECIMAL == sqlType) ? decimals : null, null, forceEncrypt,
- findColumn(parameterName), null);
+ (java.sql.Types.NUMERIC == sqlType || java.sql.Types.DECIMAL == sqlType) ? decimals : null, null,
+ forceEncrypt, findColumn(parameterName), null);
loggerExternal.exiting(getClassNameLogging(), "setObject");
}
@Override
- public final void setObject(String parameterName,
- Object value,
- int targetSqlType,
- Integer precision,
+ public final void setObject(String parameterName, Object value, int targetSqlType, Integer precision,
int scale) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "setObject", new Object[] {parameterName, value, targetSqlType, precision, scale});
+ loggerExternal.entering(getClassNameLogging(), "setObject",
+ new Object[] {parameterName, value, targetSqlType, precision, scale});
checkClosed();
// scale - for java.sql.Types.DECIMAL or java.sql.Types.NUMERIC types,
@@ -1676,81 +1608,76 @@ public final void setObject(String parameterName,
// For all other types, this value will be ignored.
setObject(setterGetParam(findColumn(parameterName)), value, JavaType.of(value), JDBCType.of(targetSqlType),
- (java.sql.Types.NUMERIC == targetSqlType || java.sql.Types.DECIMAL == targetSqlType || InputStream.class.isInstance(value)
- || Reader.class.isInstance(value)) ? scale : null,
+ (java.sql.Types.NUMERIC == targetSqlType || java.sql.Types.DECIMAL == targetSqlType
+ || InputStream.class.isInstance(value) || Reader.class.isInstance(value)) ? scale : null,
precision, false, findColumn(parameterName), null);
loggerExternal.exiting(getClassNameLogging(), "setObject");
}
@Override
- public final void setAsciiStream(String parameterName,
- InputStream value) throws SQLException {
+ public final void setAsciiStream(String parameterName, InputStream value) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setAsciiStream", new Object[] {parameterName, value});
checkClosed();
- setStream(findColumn(parameterName), StreamType.ASCII, value, JavaType.INPUTSTREAM, DataTypes.UNKNOWN_STREAM_LENGTH);
+ setStream(findColumn(parameterName), StreamType.ASCII, value, JavaType.INPUTSTREAM,
+ DataTypes.UNKNOWN_STREAM_LENGTH);
loggerExternal.exiting(getClassNameLogging(), "setAsciiStream");
}
@Override
- public final void setAsciiStream(String parameterName,
- InputStream value,
- int length) throws SQLException {
+ public final void setAsciiStream(String parameterName, InputStream value, int length) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "setAsciiStream", new Object[] {parameterName, value, length});
+ loggerExternal.entering(getClassNameLogging(), "setAsciiStream",
+ new Object[] {parameterName, value, length});
checkClosed();
setStream(findColumn(parameterName), StreamType.ASCII, value, JavaType.INPUTSTREAM, length);
loggerExternal.exiting(getClassNameLogging(), "setAsciiStream");
}
@Override
- public final void setAsciiStream(String parameterName,
- InputStream value,
- long length) throws SQLException {
+ public final void setAsciiStream(String parameterName, InputStream value, long length) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "setAsciiStream", new Object[] {parameterName, value, length});
+ loggerExternal.entering(getClassNameLogging(), "setAsciiStream",
+ new Object[] {parameterName, value, length});
checkClosed();
setStream(findColumn(parameterName), StreamType.ASCII, value, JavaType.INPUTSTREAM, length);
loggerExternal.exiting(getClassNameLogging(), "setAsciiStream");
}
@Override
- public final void setBinaryStream(String parameterName,
- InputStream value) throws SQLException {
+ public final void setBinaryStream(String parameterName, InputStream value) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setBinaryStream", new Object[] {parameterName, value});
checkClosed();
- setStream(findColumn(parameterName), StreamType.BINARY, value, JavaType.INPUTSTREAM, DataTypes.UNKNOWN_STREAM_LENGTH);
+ setStream(findColumn(parameterName), StreamType.BINARY, value, JavaType.INPUTSTREAM,
+ DataTypes.UNKNOWN_STREAM_LENGTH);
loggerExternal.exiting(getClassNameLogging(), "setBinaryStream");
}
@Override
- public final void setBinaryStream(String parameterName,
- InputStream value,
- int length) throws SQLException {
+ public final void setBinaryStream(String parameterName, InputStream value, int length) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "setBinaryStream", new Object[] {parameterName, value, length});
+ loggerExternal.entering(getClassNameLogging(), "setBinaryStream",
+ new Object[] {parameterName, value, length});
checkClosed();
setStream(findColumn(parameterName), StreamType.BINARY, value, JavaType.INPUTSTREAM, length);
loggerExternal.exiting(getClassNameLogging(), "setBinaryStream");
}
@Override
- public final void setBinaryStream(String parameterName,
- InputStream value,
- long length) throws SQLException {
+ public final void setBinaryStream(String parameterName, InputStream value, long length) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "setBinaryStream", new Object[] {parameterName, value, length});
+ loggerExternal.entering(getClassNameLogging(), "setBinaryStream",
+ new Object[] {parameterName, value, length});
checkClosed();
setStream(findColumn(parameterName), StreamType.BINARY, value, JavaType.INPUTSTREAM, length);
loggerExternal.exiting(getClassNameLogging(), "setBinaryStream");
}
@Override
- public final void setBlob(String parameterName,
- Blob inputStream) throws SQLException {
+ public final void setBlob(String parameterName, Blob inputStream) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setBlob", new Object[] {parameterName, inputStream});
checkClosed();
@@ -1759,29 +1686,27 @@ public final void setBlob(String parameterName,
}
@Override
- public final void setBlob(String parameterName,
- InputStream value) throws SQLException {
+ public final void setBlob(String parameterName, InputStream value) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setBlob", new Object[] {parameterName, value});
checkClosed();
- setStream(findColumn(parameterName), StreamType.BINARY, value, JavaType.INPUTSTREAM, DataTypes.UNKNOWN_STREAM_LENGTH);
+ setStream(findColumn(parameterName), StreamType.BINARY, value, JavaType.INPUTSTREAM,
+ DataTypes.UNKNOWN_STREAM_LENGTH);
loggerExternal.exiting(getClassNameLogging(), "setBlob");
}
@Override
- public final void setBlob(String parameterName,
- InputStream inputStream,
- long length) throws SQLException {
+ public final void setBlob(String parameterName, InputStream inputStream, long length) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "setBlob", new Object[] {parameterName, inputStream, length});
+ loggerExternal.entering(getClassNameLogging(), "setBlob",
+ new Object[] {parameterName, inputStream, length});
checkClosed();
setStream(findColumn(parameterName), StreamType.BINARY, inputStream, JavaType.INPUTSTREAM, length);
loggerExternal.exiting(getClassNameLogging(), "setBlob");
}
@Override
- public void setTimestamp(String parameterName,
- java.sql.Timestamp value) throws SQLServerException {
+ public void setTimestamp(String parameterName, java.sql.Timestamp value) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setTimestamp", new Object[] {parameterName, value});
checkClosed();
@@ -1790,9 +1715,7 @@ public void setTimestamp(String parameterName,
}
@Override
- public void setTimestamp(String parameterName,
- java.sql.Timestamp value,
- int scale) throws SQLServerException {
+ public void setTimestamp(String parameterName, java.sql.Timestamp value, int scale) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setTimestamp", new Object[] {parameterName, value});
checkClosed();
@@ -1801,20 +1724,18 @@ public void setTimestamp(String parameterName,
}
@Override
- public void setTimestamp(String parameterName,
- java.sql.Timestamp value,
- int scale,
+ public void setTimestamp(String parameterName, java.sql.Timestamp value, int scale,
boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "setTimestamp", new Object[] {parameterName, value, forceEncrypt});
+ loggerExternal.entering(getClassNameLogging(), "setTimestamp",
+ new Object[] {parameterName, value, forceEncrypt});
checkClosed();
setValue(findColumn(parameterName), JDBCType.TIMESTAMP, value, JavaType.TIMESTAMP, null, scale, forceEncrypt);
loggerExternal.exiting(getClassNameLogging(), "setTimestamp");
}
@Override
- public void setDateTimeOffset(String parameterName,
- microsoft.sql.DateTimeOffset value) throws SQLServerException {
+ public void setDateTimeOffset(String parameterName, microsoft.sql.DateTimeOffset value) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setDateTimeOffset", new Object[] {parameterName, value});
checkClosed();
@@ -1823,31 +1744,30 @@ public void setDateTimeOffset(String parameterName,
}
@Override
- public void setDateTimeOffset(String parameterName,
- microsoft.sql.DateTimeOffset value,
+ public void setDateTimeOffset(String parameterName, microsoft.sql.DateTimeOffset value,
int scale) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setDateTimeOffset", new Object[] {parameterName, value});
checkClosed();
- setValue(findColumn(parameterName), JDBCType.DATETIMEOFFSET, value, JavaType.DATETIMEOFFSET, null, scale, false);
+ setValue(findColumn(parameterName), JDBCType.DATETIMEOFFSET, value, JavaType.DATETIMEOFFSET, null, scale,
+ false);
loggerExternal.exiting(getClassNameLogging(), "setDateTimeOffset");
}
@Override
- public void setDateTimeOffset(String parameterName,
- microsoft.sql.DateTimeOffset value,
- int scale,
+ public void setDateTimeOffset(String parameterName, microsoft.sql.DateTimeOffset value, int scale,
boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "setDateTimeOffset", new Object[] {parameterName, value, forceEncrypt});
+ loggerExternal.entering(getClassNameLogging(), "setDateTimeOffset",
+ new Object[] {parameterName, value, forceEncrypt});
checkClosed();
- setValue(findColumn(parameterName), JDBCType.DATETIMEOFFSET, value, JavaType.DATETIMEOFFSET, null, scale, forceEncrypt);
+ setValue(findColumn(parameterName), JDBCType.DATETIMEOFFSET, value, JavaType.DATETIMEOFFSET, null, scale,
+ forceEncrypt);
loggerExternal.exiting(getClassNameLogging(), "setDateTimeOffset");
}
@Override
- public void setDate(String parameterName,
- java.sql.Date value) throws SQLServerException {
+ public void setDate(String parameterName, java.sql.Date value) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setDate", new Object[] {parameterName, value});
checkClosed();
@@ -1856,8 +1776,7 @@ public void setDate(String parameterName,
}
@Override
- public void setTime(String parameterName,
- java.sql.Time value) throws SQLServerException {
+ public void setTime(String parameterName, java.sql.Time value) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setTime", new Object[] {parameterName, value});
checkClosed();
@@ -1866,9 +1785,7 @@ public void setTime(String parameterName,
}
@Override
- public void setTime(String parameterName,
- java.sql.Time value,
- int scale) throws SQLServerException {
+ public void setTime(String parameterName, java.sql.Time value, int scale) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setTime", new Object[] {parameterName, value});
checkClosed();
@@ -1877,20 +1794,18 @@ public void setTime(String parameterName,
}
@Override
- public void setTime(String parameterName,
- java.sql.Time value,
- int scale,
+ public void setTime(String parameterName, java.sql.Time value, int scale,
boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "setTime", new Object[] {parameterName, value, forceEncrypt});
+ loggerExternal.entering(getClassNameLogging(), "setTime",
+ new Object[] {parameterName, value, forceEncrypt});
checkClosed();
setValue(findColumn(parameterName), JDBCType.TIME, value, JavaType.TIME, null, scale, forceEncrypt);
loggerExternal.exiting(getClassNameLogging(), "setTime");
}
@Override
- public void setDateTime(String parameterName,
- java.sql.Timestamp value) throws SQLServerException {
+ public void setDateTime(String parameterName, java.sql.Timestamp value) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setDateTime", new Object[] {parameterName, value});
checkClosed();
@@ -1899,19 +1814,18 @@ public void setDateTime(String parameterName,
}
@Override
- public void setDateTime(String parameterName,
- java.sql.Timestamp value,
+ public void setDateTime(String parameterName, java.sql.Timestamp value,
boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "setDateTime", new Object[] {parameterName, value, forceEncrypt});
+ loggerExternal.entering(getClassNameLogging(), "setDateTime",
+ new Object[] {parameterName, value, forceEncrypt});
checkClosed();
setValue(findColumn(parameterName), JDBCType.DATETIME, value, JavaType.TIMESTAMP, forceEncrypt);
loggerExternal.exiting(getClassNameLogging(), "setDateTime");
}
@Override
- public void setSmallDateTime(String parameterName,
- java.sql.Timestamp value) throws SQLServerException {
+ public void setSmallDateTime(String parameterName, java.sql.Timestamp value) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setSmallDateTime", new Object[] {parameterName, value});
checkClosed();
@@ -1920,19 +1834,18 @@ public void setSmallDateTime(String parameterName,
}
@Override
- public void setSmallDateTime(String parameterName,
- java.sql.Timestamp value,
+ public void setSmallDateTime(String parameterName, java.sql.Timestamp value,
boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "setSmallDateTime", new Object[] {parameterName, value, forceEncrypt});
+ loggerExternal.entering(getClassNameLogging(), "setSmallDateTime",
+ new Object[] {parameterName, value, forceEncrypt});
checkClosed();
setValue(findColumn(parameterName), JDBCType.SMALLDATETIME, value, JavaType.TIMESTAMP, forceEncrypt);
loggerExternal.exiting(getClassNameLogging(), "setSmallDateTime");
}
@Override
- public void setUniqueIdentifier(String parameterName,
- String guid) throws SQLServerException {
+ public void setUniqueIdentifier(String parameterName, String guid) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setUniqueIdentifier", new Object[] {parameterName, guid});
checkClosed();
@@ -1941,19 +1854,17 @@ public void setUniqueIdentifier(String parameterName,
}
@Override
- public void setUniqueIdentifier(String parameterName,
- String guid,
- boolean forceEncrypt) throws SQLServerException {
+ public void setUniqueIdentifier(String parameterName, String guid, boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "setUniqueIdentifier", new Object[] {parameterName, guid, forceEncrypt});
+ loggerExternal.entering(getClassNameLogging(), "setUniqueIdentifier",
+ new Object[] {parameterName, guid, forceEncrypt});
checkClosed();
setValue(findColumn(parameterName), JDBCType.GUID, guid, JavaType.STRING, forceEncrypt);
loggerExternal.exiting(getClassNameLogging(), "setUniqueIdentifier");
}
@Override
- public void setBytes(String parameterName,
- byte[] value) throws SQLServerException {
+ public void setBytes(String parameterName, byte[] value) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setBytes", new Object[] {parameterName, value});
checkClosed();
@@ -1962,19 +1873,17 @@ public void setBytes(String parameterName,
}
@Override
- public void setBytes(String parameterName,
- byte[] value,
- boolean forceEncrypt) throws SQLServerException {
+ public void setBytes(String parameterName, byte[] value, boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "setBytes", new Object[] {parameterName, value, forceEncrypt});
+ loggerExternal.entering(getClassNameLogging(), "setBytes",
+ new Object[] {parameterName, value, forceEncrypt});
checkClosed();
setValue(findColumn(parameterName), JDBCType.BINARY, value, JavaType.BYTEARRAY, forceEncrypt);
loggerExternal.exiting(getClassNameLogging(), "setBytes");
}
@Override
- public void setByte(String parameterName,
- byte value) throws SQLServerException {
+ public void setByte(String parameterName, byte value) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setByte", new Object[] {parameterName, value});
checkClosed();
@@ -1983,19 +1892,17 @@ public void setByte(String parameterName,
}
@Override
- public void setByte(String parameterName,
- byte value,
- boolean forceEncrypt) throws SQLServerException {
+ public void setByte(String parameterName, byte value, boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "setByte", new Object[] {parameterName, value, forceEncrypt});
+ loggerExternal.entering(getClassNameLogging(), "setByte",
+ new Object[] {parameterName, value, forceEncrypt});
checkClosed();
setValue(findColumn(parameterName), JDBCType.TINYINT, value, JavaType.BYTE, forceEncrypt);
loggerExternal.exiting(getClassNameLogging(), "setByte");
}
@Override
- public void setString(String parameterName,
- String value) throws SQLServerException {
+ public void setString(String parameterName, String value) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setString", new Object[] {parameterName, value});
checkClosed();
@@ -2004,19 +1911,17 @@ public void setString(String parameterName,
}
@Override
- public void setString(String parameterName,
- String value,
- boolean forceEncrypt) throws SQLServerException {
+ public void setString(String parameterName, String value, boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "setString", new Object[] {parameterName, value, forceEncrypt});
+ loggerExternal.entering(getClassNameLogging(), "setString",
+ new Object[] {parameterName, value, forceEncrypt});
checkClosed();
setValue(findColumn(parameterName), JDBCType.VARCHAR, value, JavaType.STRING, forceEncrypt);
loggerExternal.exiting(getClassNameLogging(), "setString");
}
@Override
- public void setMoney(String parameterName,
- BigDecimal value) throws SQLServerException {
+ public void setMoney(String parameterName, BigDecimal value) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setMoney", new Object[] {parameterName, value});
checkClosed();
@@ -2025,19 +1930,17 @@ public void setMoney(String parameterName,
}
@Override
- public void setMoney(String parameterName,
- BigDecimal value,
- boolean forceEncrypt) throws SQLServerException {
+ public void setMoney(String parameterName, BigDecimal value, boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "setMoney", new Object[] {parameterName, value, forceEncrypt});
+ loggerExternal.entering(getClassNameLogging(), "setMoney",
+ new Object[] {parameterName, value, forceEncrypt});
checkClosed();
setValue(findColumn(parameterName), JDBCType.MONEY, value, JavaType.BIGDECIMAL, forceEncrypt);
loggerExternal.exiting(getClassNameLogging(), "setMoney");
}
@Override
- public void setSmallMoney(String parameterName,
- BigDecimal value) throws SQLServerException {
+ public void setSmallMoney(String parameterName, BigDecimal value) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setSmallMoney", new Object[] {parameterName, value});
checkClosed();
@@ -2046,19 +1949,17 @@ public void setSmallMoney(String parameterName,
}
@Override
- public void setSmallMoney(String parameterName,
- BigDecimal value,
- boolean forceEncrypt) throws SQLServerException {
+ public void setSmallMoney(String parameterName, BigDecimal value, boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "setSmallMoney", new Object[] {parameterName, value, forceEncrypt});
+ loggerExternal.entering(getClassNameLogging(), "setSmallMoney",
+ new Object[] {parameterName, value, forceEncrypt});
checkClosed();
setValue(findColumn(parameterName), JDBCType.SMALLMONEY, value, JavaType.BIGDECIMAL, forceEncrypt);
loggerExternal.exiting(getClassNameLogging(), "setSmallMoney");
}
@Override
- public void setBigDecimal(String parameterName,
- BigDecimal value) throws SQLServerException {
+ public void setBigDecimal(String parameterName, BigDecimal value) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setBigDecimal", new Object[] {parameterName, value});
checkClosed();
@@ -2067,33 +1968,30 @@ public void setBigDecimal(String parameterName,
}
@Override
- public void setBigDecimal(String parameterName,
- BigDecimal value,
- int precision,
+ public void setBigDecimal(String parameterName, BigDecimal value, int precision,
int scale) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "setBigDecimal", new Object[] {parameterName, value, precision, scale});
+ loggerExternal.entering(getClassNameLogging(), "setBigDecimal",
+ new Object[] {parameterName, value, precision, scale});
checkClosed();
setValue(findColumn(parameterName), JDBCType.DECIMAL, value, JavaType.BIGDECIMAL, precision, scale, false);
loggerExternal.exiting(getClassNameLogging(), "setBigDecimal");
}
@Override
- public void setBigDecimal(String parameterName,
- BigDecimal value,
- int precision,
- int scale,
+ public void setBigDecimal(String parameterName, BigDecimal value, int precision, int scale,
boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "setBigDecimal", new Object[] {parameterName, value, precision, scale, forceEncrypt});
+ loggerExternal.entering(getClassNameLogging(), "setBigDecimal",
+ new Object[] {parameterName, value, precision, scale, forceEncrypt});
checkClosed();
- setValue(findColumn(parameterName), JDBCType.DECIMAL, value, JavaType.BIGDECIMAL, precision, scale, forceEncrypt);
+ setValue(findColumn(parameterName), JDBCType.DECIMAL, value, JavaType.BIGDECIMAL, precision, scale,
+ forceEncrypt);
loggerExternal.exiting(getClassNameLogging(), "setBigDecimal");
}
@Override
- public void setDouble(String parameterName,
- double value) throws SQLServerException {
+ public void setDouble(String parameterName, double value) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setDouble", new Object[] {parameterName, value});
checkClosed();
@@ -2102,19 +2000,17 @@ public void setDouble(String parameterName,
}
@Override
- public void setDouble(String parameterName,
- double value,
- boolean forceEncrypt) throws SQLServerException {
+ public void setDouble(String parameterName, double value, boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "setDouble", new Object[] {parameterName, value, forceEncrypt});
+ loggerExternal.entering(getClassNameLogging(), "setDouble",
+ new Object[] {parameterName, value, forceEncrypt});
checkClosed();
setValue(findColumn(parameterName), JDBCType.DOUBLE, value, JavaType.DOUBLE, forceEncrypt);
loggerExternal.exiting(getClassNameLogging(), "setDouble");
}
@Override
- public void setFloat(String parameterName,
- float value) throws SQLServerException {
+ public void setFloat(String parameterName, float value) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setFloat", new Object[] {parameterName, value});
checkClosed();
@@ -2123,19 +2019,17 @@ public void setFloat(String parameterName,
}
@Override
- public void setFloat(String parameterName,
- float value,
- boolean forceEncrypt) throws SQLServerException {
+ public void setFloat(String parameterName, float value, boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "setFloat", new Object[] {parameterName, value, forceEncrypt});
+ loggerExternal.entering(getClassNameLogging(), "setFloat",
+ new Object[] {parameterName, value, forceEncrypt});
checkClosed();
setValue(findColumn(parameterName), JDBCType.REAL, value, JavaType.FLOAT, forceEncrypt);
loggerExternal.exiting(getClassNameLogging(), "setFloat");
}
@Override
- public void setInt(String parameterName,
- int value) throws SQLServerException {
+ public void setInt(String parameterName, int value) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setInt", new Object[] {parameterName, value});
checkClosed();
@@ -2144,9 +2038,7 @@ public void setInt(String parameterName,
}
@Override
- public void setInt(String parameterName,
- int value,
- boolean forceEncrypt) throws SQLServerException {
+ public void setInt(String parameterName, int value, boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setInt", new Object[] {parameterName, value, forceEncrypt});
checkClosed();
@@ -2155,8 +2047,7 @@ public void setInt(String parameterName,
}
@Override
- public void setLong(String parameterName,
- long value) throws SQLServerException {
+ public void setLong(String parameterName, long value) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setLong", new Object[] {parameterName, value});
checkClosed();
@@ -2165,19 +2056,17 @@ public void setLong(String parameterName,
}
@Override
- public void setLong(String parameterName,
- long value,
- boolean forceEncrypt) throws SQLServerException {
+ public void setLong(String parameterName, long value, boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "setLong", new Object[] {parameterName, value, forceEncrypt});
+ loggerExternal.entering(getClassNameLogging(), "setLong",
+ new Object[] {parameterName, value, forceEncrypt});
checkClosed();
setValue(findColumn(parameterName), JDBCType.BIGINT, value, JavaType.LONG, forceEncrypt);
loggerExternal.exiting(getClassNameLogging(), "setLong");
}
@Override
- public void setShort(String parameterName,
- short value) throws SQLServerException {
+ public void setShort(String parameterName, short value) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setShort", new Object[] {parameterName, value});
checkClosed();
@@ -2186,19 +2075,17 @@ public void setShort(String parameterName,
}
@Override
- public void setShort(String parameterName,
- short value,
- boolean forceEncrypt) throws SQLServerException {
+ public void setShort(String parameterName, short value, boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "setShort", new Object[] {parameterName, value, forceEncrypt});
+ loggerExternal.entering(getClassNameLogging(), "setShort",
+ new Object[] {parameterName, value, forceEncrypt});
checkClosed();
setValue(findColumn(parameterName), JDBCType.SMALLINT, value, JavaType.SHORT, forceEncrypt);
loggerExternal.exiting(getClassNameLogging(), "setShort");
}
@Override
- public void setBoolean(String parameterName,
- boolean value) throws SQLServerException {
+ public void setBoolean(String parameterName, boolean value) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setBoolean", new Object[] {parameterName, value});
checkClosed();
@@ -2207,42 +2094,37 @@ public void setBoolean(String parameterName,
}
@Override
- public void setBoolean(String parameterName,
- boolean value,
- boolean forceEncrypt) throws SQLServerException {
+ public void setBoolean(String parameterName, boolean value, boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "setBoolean", new Object[] {parameterName, value, forceEncrypt});
+ loggerExternal.entering(getClassNameLogging(), "setBoolean",
+ new Object[] {parameterName, value, forceEncrypt});
checkClosed();
setValue(findColumn(parameterName), JDBCType.BIT, value, JavaType.BOOLEAN, forceEncrypt);
loggerExternal.exiting(getClassNameLogging(), "setBoolean");
}
@Override
- public void setNull(String parameterName,
- int nType) throws SQLServerException {
+ public void setNull(String parameterName, int nType) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setNull", new Object[] {parameterName, nType});
checkClosed();
- setObject(setterGetParam(findColumn(parameterName)), null, JavaType.OBJECT, JDBCType.of(nType), null, null, false, findColumn(parameterName),
- null);
+ setObject(setterGetParam(findColumn(parameterName)), null, JavaType.OBJECT, JDBCType.of(nType), null, null,
+ false, findColumn(parameterName), null);
loggerExternal.exiting(getClassNameLogging(), "setNull");
}
@Override
- public void setNull(String parameterName,
- int nType,
- String sTypeName) throws SQLServerException {
+ public void setNull(String parameterName, int nType, String sTypeName) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setNull", new Object[] {parameterName, nType, sTypeName});
checkClosed();
- setObject(setterGetParam(findColumn(parameterName)), null, JavaType.OBJECT, JDBCType.of(nType), null, null, false, findColumn(parameterName),
- sTypeName);
+ setObject(setterGetParam(findColumn(parameterName)), null, JavaType.OBJECT, JDBCType.of(nType), null, null,
+ false, findColumn(parameterName), sTypeName);
loggerExternal.exiting(getClassNameLogging(), "setNull");
}
@Override
- public void setURL(String parameterName,
- URL url) throws SQLException {
+ public void setURL(String parameterName, URL url) throws SQLException {
loggerExternal.entering(getClassNameLogging(), "setURL", parameterName);
checkClosed();
setURL(findColumn(parameterName), url);
@@ -2250,36 +2132,36 @@ public void setURL(String parameterName,
}
@Override
- public final void setStructured(String parameterName,
- String tvpName,
+ public final void setStructured(String parameterName, String tvpName,
SQLServerDataTable tvpDataTable) throws SQLServerException {
tvpName = getTVPNameIfNull(findColumn(parameterName), tvpName);
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "setStructured", new Object[] {parameterName, tvpName, tvpDataTable});
+ loggerExternal.entering(getClassNameLogging(), "setStructured",
+ new Object[] {parameterName, tvpName, tvpDataTable});
checkClosed();
setValue(findColumn(parameterName), JDBCType.TVP, tvpDataTable, JavaType.TVP, tvpName);
loggerExternal.exiting(getClassNameLogging(), "setStructured");
}
@Override
- public final void setStructured(String parameterName,
- String tvpName,
+ public final void setStructured(String parameterName, String tvpName,
ResultSet tvpResultSet) throws SQLServerException {
tvpName = getTVPNameIfNull(findColumn(parameterName), tvpName);
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "setStructured", new Object[] {parameterName, tvpName, tvpResultSet});
+ loggerExternal.entering(getClassNameLogging(), "setStructured",
+ new Object[] {parameterName, tvpName, tvpResultSet});
checkClosed();
setValue(findColumn(parameterName), JDBCType.TVP, tvpResultSet, JavaType.TVP, tvpName);
loggerExternal.exiting(getClassNameLogging(), "setStructured");
}
@Override
- public final void setStructured(String parameterName,
- String tvpName,
+ public final void setStructured(String parameterName, String tvpName,
ISQLServerDataRecord tvpDataRecord) throws SQLServerException {
tvpName = getTVPNameIfNull(findColumn(parameterName), tvpName);
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "setStructured", new Object[] {parameterName, tvpName, tvpDataRecord});
+ loggerExternal.entering(getClassNameLogging(), "setStructured",
+ new Object[] {parameterName, tvpName, tvpDataRecord});
checkClosed();
setValue(findColumn(parameterName), JDBCType.TVP, tvpDataRecord, JavaType.TVP, tvpName);
loggerExternal.exiting(getClassNameLogging(), "setStructured");
@@ -2298,8 +2180,7 @@ public URL getURL(String parameterName) throws SQLException {
}
@Override
- public final void setSQLXML(String parameterName,
- SQLXML xmlObject) throws SQLException {
+ public final void setSQLXML(String parameterName, SQLXML xmlObject) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setSQLXML", new Object[] {parameterName, xmlObject});
checkClosed();
@@ -2326,8 +2207,7 @@ public final SQLXML getSQLXML(String parameterName) throws SQLException {
}
@Override
- public final void setRowId(String parameterName,
- RowId value) throws SQLException {
+ public final void setRowId(String parameterName, RowId value) throws SQLException {
SQLServerException.throwNotSupportedException(connection, this);
}
@@ -2344,55 +2224,52 @@ public final RowId getRowId(String parameterName) throws SQLException {
}
@Override
- public void registerOutParameter(String parameterName,
- int sqlType,
- String typeName) throws SQLServerException {
+ public void registerOutParameter(String parameterName, int sqlType, String typeName) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "registerOutParameter", new Object[] {parameterName, sqlType, typeName});
+ loggerExternal.entering(getClassNameLogging(), "registerOutParameter",
+ new Object[] {parameterName, sqlType, typeName});
checkClosed();
registerOutParameter(findColumn(parameterName), sqlType, typeName);
loggerExternal.exiting(getClassNameLogging(), "registerOutParameter");
}
@Override
- public void registerOutParameter(String parameterName,
- int sqlType,
- int scale) throws SQLServerException {
+ public void registerOutParameter(String parameterName, int sqlType, int scale) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "registerOutParameter", new Object[] {parameterName, sqlType, scale});
+ loggerExternal.entering(getClassNameLogging(), "registerOutParameter",
+ new Object[] {parameterName, sqlType, scale});
checkClosed();
registerOutParameter(findColumn(parameterName), sqlType, scale);
loggerExternal.exiting(getClassNameLogging(), "registerOutParameter");
}
@Override
- public void registerOutParameter(String parameterName,
- int sqlType,
- int precision,
+ public void registerOutParameter(String parameterName, int sqlType, int precision,
int scale) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "registerOutParameter", new Object[] {parameterName, sqlType, scale});
+ loggerExternal.entering(getClassNameLogging(), "registerOutParameter",
+ new Object[] {parameterName, sqlType, scale});
checkClosed();
registerOutParameter(findColumn(parameterName), sqlType, precision, scale);
loggerExternal.exiting(getClassNameLogging(), "registerOutParameter");
}
@Override
- public void registerOutParameter(String parameterName,
- int sqlType) throws SQLServerException {
+ public void registerOutParameter(String parameterName, int sqlType) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "registerOutParameter", new Object[] {parameterName, sqlType});
+ loggerExternal.entering(getClassNameLogging(), "registerOutParameter",
+ new Object[] {parameterName, sqlType});
checkClosed();
registerOutParameter(findColumn(parameterName), sqlType);
loggerExternal.exiting(getClassNameLogging(), "registerOutParameter");
}
@Override
- public void registerOutParameter(int paramterIndex,
- SQLType sqlType) throws SQLServerException {
+ public void registerOutParameter(int paramterIndex, SQLType sqlType) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "registerOutParameter", new Object[] {paramterIndex, sqlType});
+ loggerExternal.entering(getClassNameLogging(), "registerOutParameter",
+ new Object[] {paramterIndex, sqlType});
// getVendorTypeNumber() returns the same constant integer values as in java.sql.Types
registerOutParameter(paramterIndex, sqlType.getVendorTypeNumber());
@@ -2400,12 +2277,11 @@ public void registerOutParameter(int paramterIndex,
}
@Override
- public void registerOutParameter(int paramterIndex,
- SQLType sqlType,
- String typeName) throws SQLServerException {
+ public void registerOutParameter(int paramterIndex, SQLType sqlType, String typeName) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "registerOutParameter", new Object[] {paramterIndex, sqlType, typeName});
+ loggerExternal.entering(getClassNameLogging(), "registerOutParameter",
+ new Object[] {paramterIndex, sqlType, typeName});
// getVendorTypeNumber() returns the same constant integer values as in java.sql.Types
registerOutParameter(paramterIndex, sqlType.getVendorTypeNumber(), typeName);
@@ -2413,12 +2289,11 @@ public void registerOutParameter(int paramterIndex,
}
@Override
- public void registerOutParameter(int paramterIndex,
- SQLType sqlType,
- int scale) throws SQLServerException {
+ public void registerOutParameter(int paramterIndex, SQLType sqlType, int scale) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "registerOutParameter", new Object[] {paramterIndex, sqlType, scale});
+ loggerExternal.entering(getClassNameLogging(), "registerOutParameter",
+ new Object[] {paramterIndex, sqlType, scale});
// getVendorTypeNumber() returns the same constant integer values as in java.sql.Types
registerOutParameter(paramterIndex, sqlType.getVendorTypeNumber(), scale);
@@ -2426,13 +2301,12 @@ public void registerOutParameter(int paramterIndex,
}
@Override
- public void registerOutParameter(int paramterIndex,
- SQLType sqlType,
- int precision,
+ public void registerOutParameter(int paramterIndex, SQLType sqlType, int precision,
int scale) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "registerOutParameter", new Object[] {paramterIndex, sqlType, scale});
+ loggerExternal.entering(getClassNameLogging(), "registerOutParameter",
+ new Object[] {paramterIndex, sqlType, scale});
// getVendorTypeNumber() returns the same constant integer values as in java.sql.Types
registerOutParameter(paramterIndex, sqlType.getVendorTypeNumber(), precision, scale);
@@ -2440,9 +2314,7 @@ public void registerOutParameter(int paramterIndex,
}
@Override
- public void setObject(String parameterName,
- Object value,
- SQLType jdbcType) throws SQLServerException {
+ public void setObject(String parameterName, Object value, SQLType jdbcType) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setObject", new Object[] {parameterName, value, jdbcType});
@@ -2453,13 +2325,11 @@ public void setObject(String parameterName,
}
@Override
- public void setObject(String parameterName,
- Object value,
- SQLType jdbcType,
- int scale) throws SQLServerException {
+ public void setObject(String parameterName, Object value, SQLType jdbcType, int scale) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "setObject", new Object[] {parameterName, value, jdbcType, scale});
+ loggerExternal.entering(getClassNameLogging(), "setObject",
+ new Object[] {parameterName, value, jdbcType, scale});
// getVendorTypeNumber() returns the same constant integer values as in java.sql.Types
setObject(parameterName, value, jdbcType.getVendorTypeNumber(), scale);
@@ -2467,14 +2337,12 @@ public void setObject(String parameterName,
}
@Override
- public void setObject(String parameterName,
- Object value,
- SQLType jdbcType,
- int scale,
+ public void setObject(String parameterName, Object value, SQLType jdbcType, int scale,
boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "setObject", new Object[] {parameterName, value, jdbcType, scale, forceEncrypt});
+ loggerExternal.entering(getClassNameLogging(), "setObject",
+ new Object[] {parameterName, value, jdbcType, scale, forceEncrypt});
// getVendorTypeNumber() returns the same constant integer values as in java.sql.Types
setObject(parameterName, value, jdbcType.getVendorTypeNumber(), scale, forceEncrypt);
@@ -2482,12 +2350,11 @@ public void setObject(String parameterName,
}
@Override
- public void registerOutParameter(String parameterName,
- SQLType sqlType,
- String typeName) throws SQLServerException {
+ public void registerOutParameter(String parameterName, SQLType sqlType, String typeName) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "registerOutParameter", new Object[] {parameterName, sqlType, typeName});
+ loggerExternal.entering(getClassNameLogging(), "registerOutParameter",
+ new Object[] {parameterName, sqlType, typeName});
// getVendorTypeNumber() returns the same constant integer values as in java.sql.Types
registerOutParameter(parameterName, sqlType.getVendorTypeNumber(), typeName);
@@ -2495,12 +2362,11 @@ public void registerOutParameter(String parameterName,
}
@Override
- public void registerOutParameter(String parameterName,
- SQLType sqlType,
- int scale) throws SQLServerException {
+ public void registerOutParameter(String parameterName, SQLType sqlType, int scale) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "registerOutParameter", new Object[] {parameterName, sqlType, scale});
+ loggerExternal.entering(getClassNameLogging(), "registerOutParameter",
+ new Object[] {parameterName, sqlType, scale});
// getVendorTypeNumber() returns the same constant integer values as in java.sql.Types
registerOutParameter(parameterName, sqlType.getVendorTypeNumber(), scale);
@@ -2508,13 +2374,12 @@ public void registerOutParameter(String parameterName,
}
@Override
- public void registerOutParameter(String parameterName,
- SQLType sqlType,
- int precision,
+ public void registerOutParameter(String parameterName, SQLType sqlType, int precision,
int scale) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "registerOutParameter", new Object[] {parameterName, sqlType, scale});
+ loggerExternal.entering(getClassNameLogging(), "registerOutParameter",
+ new Object[] {parameterName, sqlType, scale});
// getVendorTypeNumber() returns the same constant integer values as in java.sql.Types
registerOutParameter(parameterName, sqlType.getVendorTypeNumber(), precision, scale);
@@ -2522,11 +2387,11 @@ public void registerOutParameter(String parameterName,
}
@Override
- public void registerOutParameter(String parameterName,
- SQLType sqlType) throws SQLServerException {
+ public void registerOutParameter(String parameterName, SQLType sqlType) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "registerOutParameter", new Object[] {parameterName, sqlType});
+ loggerExternal.entering(getClassNameLogging(), "registerOutParameter",
+ new Object[] {parameterName, sqlType});
// getVendorTypeNumber() returns the same constant integer values as in java.sql.Types
registerOutParameter(parameterName, sqlType.getVendorTypeNumber());
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerClob.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerClob.java
index 31b8d0837..b59fd9062 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerClob.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerClob.java
@@ -1,15 +1,12 @@
/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc;
-import static java.nio.charset.StandardCharsets.UTF_16LE;
import static java.nio.charset.StandardCharsets.US_ASCII;
+import static java.nio.charset.StandardCharsets.UTF_16LE;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
@@ -25,17 +22,16 @@
import java.io.Writer;
import java.sql.Clob;
import java.sql.SQLException;
-import java.sql.SQLFeatureNotSupportedException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level;
import java.util.logging.Logger;
+
/**
- * SQLServerClob represents a character LOB object and implements java.sql.Clob.
+ * Represents a character LOB object and implements java.sql.Clob.
*/
-
public class SQLServerClob extends SQLServerClobBase implements Clob {
/**
* Always refresh SerialVersionUID when prompted
@@ -47,17 +43,16 @@ public class SQLServerClob extends SQLServerClobBase implements Clob {
private static final Logger logger = Logger.getLogger("com.microsoft.sqlserver.jdbc.internals.SQLServerClob");
/**
- * Create a new CLOB
+ * Constructs a SQLServerClob.
*
* @param connection
- * the database connection this blob is implemented on
+ * the database connection this blob is implemented on
* @param data
- * the CLOB's data
+ * the CLOB's data
* @deprecated Use {@link SQLServerConnection#createClob()} instead.
*/
@Deprecated
- public SQLServerClob(SQLServerConnection connection,
- String data) {
+ public SQLServerClob(SQLServerConnection connection, String data) {
super(connection, data, (null == connection) ? null : connection.getDatabaseCollation(), logger, null);
if (null == data)
@@ -68,8 +63,7 @@ public SQLServerClob(SQLServerConnection connection,
super(connection, "", connection.getDatabaseCollation(), logger, null);
}
- SQLServerClob(BaseInputStream stream,
- TypeInfo typeInfo) throws SQLServerException, UnsupportedEncodingException {
+ SQLServerClob(BaseInputStream stream, TypeInfo typeInfo) throws SQLServerException, UnsupportedEncodingException {
super(null, stream, typeInfo.getSQLCollation(), logger, typeInfo);
}
@@ -89,14 +83,12 @@ public Reader getCharacterStream() throws SQLException {
}
@Override
- public Reader getCharacterStream(long pos,
- long length) throws SQLException {
+ public Reader getCharacterStream(long pos, long length) throws SQLException {
return super.getCharacterStream(pos, length);
}
@Override
- public String getSubString(long pos,
- int length) throws SQLException {
+ public String getSubString(long pos, int length) throws SQLException {
return super.getSubString(pos, length);
}
@@ -111,14 +103,12 @@ void fillFromStream() throws SQLException {
}
@Override
- public long position(Clob searchstr,
- long start) throws SQLException {
+ public long position(Clob searchstr, long start) throws SQLException {
return super.position(searchstr, start);
}
@Override
- public long position(String searchstr,
- long start) throws SQLException {
+ public long position(String searchstr, long start) throws SQLException {
return super.position(searchstr, start);
}
@@ -138,16 +128,12 @@ public Writer setCharacterStream(long pos) throws SQLException {
}
@Override
- public int setString(long pos,
- String s) throws SQLException {
+ public int setString(long pos, String s) throws SQLException {
return super.setString(pos, s);
}
@Override
- public int setString(long pos,
- String str,
- int offset,
- int len) throws SQLException {
+ public int setString(long pos, String str, int offset, int len) throws SQLException {
return super.setString(pos, str, offset, len);
}
@@ -157,6 +143,7 @@ final JDBCType getJdbcType() {
}
}
+
abstract class SQLServerClobBase extends SQLServerLob implements Serializable {
/**
* Always refresh SerialVersionUID when prompted
@@ -173,20 +160,19 @@ abstract class SQLServerClobBase extends SQLServerLob implements Serializable {
private final TypeInfo typeInfo;
- // Active streams which must be closed when the Clob/NClob is closed
- //
- // Initial size of the array is based on an assumption that a Clob/NClob
- // object is
- // typically used either for input or output, and then only once. The array
- // size
- // grows automatically if multiple streams are used.
+ /**
+ * Active streams which must be closed when the Clob/NClob is closed. Initial size of the array is based on an
+ * assumption that a Clob/NClob object is typically used either for input or output, and then only once. The array
+ * size grows automatically if multiple streams are used.
+ */
private ArrayList activeStreams = new ArrayList<>(1);
transient SQLServerConnection con;
private final Logger logger;
- final private String traceID = getClass().getName().substring(1 + getClass().getName().lastIndexOf('.')) + ":" + nextInstanceID();
+ final private String traceID = getClass().getName().substring(1 + getClass().getName().lastIndexOf('.')) + ":"
+ + nextInstanceID();
final public String toString() {
return traceID;
@@ -209,29 +195,25 @@ private String getDisplayClassName() {
}
/**
- * Create a new CLOB from a String
+ * Constructs a new CLOB from a String.
*
* @param connection
- * SQLServerConnection
+ * SQLServerConnection
* @param data
- * the CLOB data
+ * the CLOB data
* @param collation
- * the data collation
+ * the data collation
* @param logger
- * logger information
+ * logger information
* @param typeInfo
- * the column TYPE_INFO
+ * the column TYPE_INFO
*/
- SQLServerClobBase(SQLServerConnection connection,
- Object data,
- SQLCollation collation,
- Logger logger,
+ SQLServerClobBase(SQLServerConnection connection, Object data, SQLCollation collation, Logger logger,
TypeInfo typeInfo) {
this.con = connection;
if (data instanceof BaseInputStream) {
activeStreams.add((Closeable) data);
- }
- else {
+ } else {
this.value = (String) data;
}
this.sqlCollation = collation;
@@ -246,11 +228,11 @@ private String getDisplayClassName() {
/**
* Frees this Clob/NClob object and releases the resources that it holds.
*
- * After free() has been called, any attempt to invoke a method other than free() will result in a SQLException being thrown. If free() is called
- * multiple times, the subsequent calls to free are treated as a no-op.
+ * After free() has been called, any attempt to invoke a method other than free() will result in a SQLException
+ * being thrown. If free() is called multiple times, the subsequent calls to free are treated as a no-op.
*
* @throws SQLException
- * when an error occurs
+ * when an error occurs
*/
public void free() throws SQLException {
if (!isClosed) {
@@ -260,9 +242,9 @@ public void free() throws SQLException {
for (Closeable stream : activeStreams) {
try {
stream.close();
- }
- catch (IOException ioException) {
- logger.fine(toString() + " ignored IOException closing stream " + stream + ": " + ioException.getMessage());
+ } catch (IOException ioException) {
+ logger.fine(toString() + " ignored IOException closing stream " + stream + ": "
+ + ioException.getMessage());
}
}
activeStreams = null;
@@ -281,15 +263,16 @@ public void free() throws SQLException {
private void checkClosed() throws SQLServerException {
if (isClosed) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_isFreed"));
- SQLServerException.makeFromDriverError(con, null, form.format(new Object[] {getDisplayClassName()}), null, true);
+ SQLServerException.makeFromDriverError(con, null, form.format(new Object[] {getDisplayClassName()}), null,
+ true);
}
}
/**
- * Materialize the CLOB as an ASCII stream.
+ * Returns the CLOB as an ASCII stream.
*
* @throws SQLException
- * when an error occurs
+ * when an error occurs
* @return the data as an input stream
*/
public InputStream getAsciiStream() throws SQLException {
@@ -299,16 +282,17 @@ public InputStream getAsciiStream() throws SQLException {
DataTypes.throwConversionError(getDisplayClassName(), "AsciiStream");
getStringFromStream();
- InputStream getterStream = new BufferedInputStream(new ReaderInputStream(new StringReader(value), US_ASCII, value.length()));
+ InputStream getterStream = new BufferedInputStream(
+ new ReaderInputStream(new StringReader(value), US_ASCII, value.length()));
activeStreams.add(getterStream);
return getterStream;
}
/**
- * Retrieves the CLOB value designated by this Clob object as a java.io.Reader object (or as a stream of characters).
+ * Returns the CLOB value designated by this Clob object as a java.io.Reader object (or as a stream of characters).
*
* @throws SQLException
- * if there is an error accessing the CLOB value
+ * if there is an error accessing the CLOB value
* @return a java.io.Reader object containing the CLOB data
*/
public Reader getCharacterStream() throws SQLException {
@@ -318,8 +302,7 @@ public Reader getCharacterStream() throws SQLException {
if (null == value && !activeStreams.isEmpty()) {
InputStream inputStream = (InputStream) activeStreams.get(0);
getterStream = new BufferedReader(new InputStreamReader(inputStream, UTF_16LE));
- }
- else {
+ } else {
getterStream = new StringReader(value);
activeStreams.add(getterStream);
}
@@ -327,36 +310,35 @@ public Reader getCharacterStream() throws SQLException {
}
/**
- * Returns the Clob data as a java.io.Reader object or as a stream of characters with the specified position and length.
+ * Returns the Clob data as a java.io.Reader object or as a stream of characters with the specified position and
+ * length.
*
* @param pos
- * A long that indicates the offset to the first character of the partial value to be retrieved.
+ * A long that indicates the offset to the first character of the partial value to be retrieved.
* @param length
- * A long that indicates the length in characters of the partial value to be retrieved.
+ * A long that indicates the length in characters of the partial value to be retrieved.
* @return A Reader object that contains the Clob data.
* @throws SQLException
- * when an error occurs.
+ * when an error occurs.
*/
- public Reader getCharacterStream(long pos,
- long length) throws SQLException {
+ public Reader getCharacterStream(long pos, long length) throws SQLException {
SQLServerException.throwFeatureNotSupportedException();
return null;
}
/**
- * Retrieves a copy of the specified substring in the CLOB value designated by this Clob object. The substring begins at position pos and has up
- * to length consecutive characters.
+ * Returns a copy of the specified substring in the CLOB value designated by this Clob object. The substring begins
+ * at position pos and has up to length consecutive characters.
*
* @param pos
- * - the first character of the substring to be extracted. The first character is at position 1.
+ * - the first character of the substring to be extracted. The first character is at position 1.
* @param length
- * - the number of consecutive characters to be copied; the value for length must be 0 or greater
+ * - the number of consecutive characters to be copied; the value for length must be 0 or greater
* @return a String that is the specified substring in the CLOB value designated by this Clob object
* @throws SQLException
- * - if there is an error accessing the CLOB value; if pos is less than 1 or length is less than 0
+ * - if there is an error accessing the CLOB value; if pos is less than 1 or length is less than 0
*/
- public String getSubString(long pos,
- int length) throws SQLException {
+ public String getSubString(long pos, int length) throws SQLException {
checkClosed();
getStringFromStream();
@@ -391,10 +373,10 @@ public String getSubString(long pos,
}
/**
- * Retrieves the number of characters in the CLOB value designated by this Clob object.
+ * Returns the number of characters in the CLOB value designated by this Clob object.
*
* @throws SQLException
- * when an error occurs
+ * when an error occurs
* @return length of the CLOB in characters
*/
public long length() throws SQLException {
@@ -407,7 +389,7 @@ public long length() throws SQLException {
}
/**
- * Function for the result set to maintain clobs it has created
+ * Provides functionality for the result set to maintain clobs it has created.
*
* @throws SQLException
*/
@@ -418,7 +400,7 @@ void fillFromStream() throws SQLException {
}
/**
- * Converts the stream to String
+ * Converts the stream to String.
*
* @throws SQLServerException
*/
@@ -427,8 +409,7 @@ private void getStringFromStream() throws SQLServerException {
BaseInputStream stream = (BaseInputStream) activeStreams.get(0);
try {
stream.reset();
- }
- catch (IOException e) {
+ } catch (IOException e) {
throw new SQLServerException(e.getMessage(), null, 0, e);
}
value = new String((stream).getBytes(), typeInfo.getCharset());
@@ -436,18 +417,18 @@ private void getStringFromStream() throws SQLServerException {
}
/**
- * Retrieves the character position at which the specified Clob object searchstr appears in this Clob object. The search begins at position start.
+ * Returns the character position at which the specified Clob object searchstr appears in this Clob object. The
+ * search begins at position start.
*
* @param searchstr
- * - the Clob for which to search
+ * - the Clob for which to search
* @param start
- * - the position at which to begin searching; the first position is 1
+ * - the position at which to begin searching; the first position is 1
* @return the position at which the Clob object appears or -1 if it is not present; the first position is 1
* @throws SQLException
- * - if there is an error accessing the CLOB value or if start is less than 1
+ * - if there is an error accessing the CLOB value or if start is less than 1
*/
- public long position(Clob searchstr,
- long start) throws SQLException {
+ public long position(Clob searchstr, long start) throws SQLException {
checkClosed();
getStringFromStream();
@@ -464,19 +445,18 @@ public long position(Clob searchstr,
}
/**
- * Retrieves the character position at which the specified substring searchstr appears in the SQL CLOB value represented by this Clob object. The
- * search begins at position start.
+ * Returns the character position at which the specified substring searchstr appears in the SQL CLOB value
+ * represented by this Clob object. The search begins at position start.
*
* @param searchstr
- * - the substring for which to search
+ * - the substring for which to search
* @param start
- * - the position at which to begin searching; the first position is 1
+ * - the position at which to begin searching; the first position is 1
* @return the position at which the substring appears or -1 if it is not present; the first position is 1
* @throws SQLException
- * - if there is an error accessing the CLOB value or if start is less than 1
+ * - if there is an error accessing the CLOB value or if start is less than 1
*/
- public long position(String searchstr,
- long start) throws SQLException {
+ public long position(String searchstr, long start) throws SQLException {
checkClosed();
getStringFromStream();
@@ -505,9 +485,9 @@ public long position(String searchstr,
* Truncates the CLOB value that this Clob designates to have a length of len characters.
*
* @param len
- * the length, in characters, to which the CLOB value should be truncated
+ * the length, in characters, to which the CLOB value should be truncated
* @throws SQLException
- * when an error occurs
+ * when an error occurs
*/
public void truncate(long len) throws SQLException {
checkClosed();
@@ -524,12 +504,13 @@ public void truncate(long len) throws SQLException {
}
/**
- * Retrieves a stream to be used to write Ascii characters to the CLOB value that this Clob object represents, starting at position pos.
+ * Returns a stream to be used to write Ascii characters to the CLOB value that this Clob object represents,
+ * starting at position pos.
*
* @param pos
- * the position at which to start writing to this CLOB object
+ * the position at which to start writing to this CLOB object
* @throws SQLException
- * when an error occurs
+ * when an error occurs
* @return the stream to which ASCII encoded characters can be written
*/
public java.io.OutputStream setAsciiStream(long pos) throws SQLException {
@@ -545,12 +526,13 @@ public java.io.OutputStream setAsciiStream(long pos) throws SQLException {
}
/**
- * Retrieves a stream to be used to write a stream of Unicode characters to the CLOB value that this Clob object represents, at position pos.
+ * Returns a stream to be used to write a stream of Unicode characters to the CLOB value that this Clob object
+ * represents, at position pos.
*
* @param pos
- * the position at which to start writing to the CLOB value
+ * the position at which to start writing to the CLOB value
* @throws SQLException
- * when an error occurs
+ * when an error occurs
* @return a stream to which Unicode encoded characters can be written
*/
public java.io.Writer setCharacterStream(long pos) throws SQLException {
@@ -569,51 +551,51 @@ public java.io.Writer setCharacterStream(long pos) throws SQLException {
* Writes the given Java String to the CLOB value that this Clob object designates at the position pos.
*
* @param pos
- * the position at which to start writing to the CLOB
+ * the position at which to start writing to the CLOB
* @param s
- * the string to be written to the CLOB value that this Clob designates
+ * the string to be written to the CLOB value that this Clob designates
* @throws SQLException
- * when an error occurs
+ * when an error occurs
* @return the number of characters written
*/
- public int setString(long pos,
- String s) throws SQLException {
+ public int setString(long pos, String s) throws SQLException {
checkClosed();
if (null == s)
- SQLServerException.makeFromDriverError(con, null, SQLServerException.getErrString("R_cantSetNull"), null, true);
+ SQLServerException.makeFromDriverError(con, null, SQLServerException.getErrString("R_cantSetNull"), null,
+ true);
return setString(pos, s, 0, s.length());
}
/**
- * Writes len characters of str, starting at character offset, to the CLOB value that this Clob represents. The string will overwrite the existing
- * characters in the Clob object starting at the position pos. If the end of the Clob value is reached while writing the given string, then the
- * length of the Clob value will be increased to accomodate the extra characters.
+ * Writes len characters of str, starting at character offset, to the CLOB value that this Clob represents. The
+ * string will overwrite the existing characters in the Clob object starting at the position pos. If the end of the
+ * Clob value is reached while writing the given string, then the length of the Clob value will be increased to
+ * accomodate the extra characters.
*
- * SQL Server behavior: If the value specified for pos is greater than then length+1 of the CLOB value then a SQLException is thrown.
+ * SQL Server behavior: If the value specified for pos is greater than then length+1 of the CLOB value then a
+ * SQLException is thrown.
*
* @param pos
- * - the position at which to start writing to this CLOB object; The first position is 1
+ * - the position at which to start writing to this CLOB object; The first position is 1
* @param str
- * - the string to be written to the CLOB value that this Clob object represents
+ * - the string to be written to the CLOB value that this Clob object represents
* @param offset
- * - the offset (0-based) into str to start reading the characters to be written
+ * - the offset (0-based) into str to start reading the characters to be written
* @param len
- * - the number of characters to be written
+ * - the number of characters to be written
* @return the number of characters written
* @throws SQLException
- * - if there is an error accessing the CLOB value or if pos is less than 1
+ * - if there is an error accessing the CLOB value or if pos is less than 1
*/
- public int setString(long pos,
- String str,
- int offset,
- int len) throws SQLException {
+ public int setString(long pos, String str, int offset, int len) throws SQLException {
checkClosed();
getStringFromStream();
if (null == str)
- SQLServerException.makeFromDriverError(con, null, SQLServerException.getErrString("R_cantSetNull"), null, true);
+ SQLServerException.makeFromDriverError(con, null, SQLServerException.getErrString("R_cantSetNull"), null,
+ true);
// Offset must be within incoming string str boundary.
if (offset < 0 || offset > str.length()) {
@@ -681,22 +663,17 @@ public int setString(long pos,
}
}
-// SQLServerClobWriter is a simple java.io.Writer interface implementing class
-// that
-// forwards all calls to SQLServerClob.setString. This class is returned to
-// caller by
-// SQLServerClob class when setCharacterStream is called.
-//
-// SQLServerClobWriter starts writing at postion streamPos and continues to
-// write
-// in a forward only manner. There is no reset with java.io.Writer.
-//
+
+/**
+ * Provides a simple java.io.Writer interface that forwards all calls to SQLServerClob.setString.\ This class is
+ * returned to caller by SQLServerClob class when setCharacterStream is called. SQLServerClobWriter starts writing at
+ * postion streamPos and continues to write in a forward only manner. There is no reset with java.io.Writer.
+ */
final class SQLServerClobWriter extends java.io.Writer {
private SQLServerClobBase parentClob = null;
private long streamPos;
- SQLServerClobWriter(SQLServerClobBase parentClob,
- long streamPos) {
+ SQLServerClobWriter(SQLServerClobBase parentClob, long streamPos) {
this.parentClob = parentClob;
this.streamPos = streamPos;
}
@@ -707,9 +684,7 @@ public void write(char[] cbuf) throws IOException {
write(new String(cbuf));
}
- public void write(char[] cbuf,
- int off,
- int len) throws IOException {
+ public void write(char[] cbuf, int off, int len) throws IOException {
if (null == cbuf)
return;
write(new String(cbuf, off, len));
@@ -721,9 +696,7 @@ public void write(int b) throws java.io.IOException {
write(new String(c));
}
- public void write(String str,
- int off,
- int len) throws IOException {
+ public void write(String str, int off, int len) throws IOException {
checkClosed();
try {
// Call parent's setString and update position.
@@ -731,8 +704,7 @@ public void write(String str,
// this to an IOException here.
int charsWritten = parentClob.setString(streamPos, str, off, len);
streamPos += charsWritten;
- }
- catch (SQLException ex) {
+ } catch (SQLException ex) {
throw new IOException(ex.getMessage());
}
}
@@ -758,22 +730,17 @@ private void checkClosed() throws IOException {
}
}
-// SQLServerClobAsciiOutputStream is a simple java.io.OutputStream interface
-// implementing class that
-// forwards all calls to SQLServerClob.setString. This class is returned to
-// caller by
-// SQLServerClob class when setAsciiStream is called.
-//
-// SQLServerClobAsciiOutputStream starts writing at character postion streamPos
-// and continues to write
-// in a forward only manner. Reset/mark are not supported.
-//
+
+/**
+ * Provides a simple java.io.OutputStream interface that forwards all calls to SQLServerClob.setString. This class is
+ * returned to caller by SQLServerClob class when setAsciiStream is called. SQLServerClobAsciiOutputStream starts
+ * writing at character postion streamPos and continues to write in a forward only manner. Reset/mark are not supported.
+ */
final class SQLServerClobAsciiOutputStream extends java.io.OutputStream {
private SQLServerClobBase parentClob = null;
private long streamPos;
- SQLServerClobAsciiOutputStream(SQLServerClobBase parentClob,
- long streamPos) {
+ SQLServerClobAsciiOutputStream(SQLServerClobBase parentClob, long streamPos) {
this.parentClob = parentClob;
this.streamPos = streamPos;
}
@@ -784,9 +751,7 @@ public void write(byte[] b) throws IOException {
write(b, 0, b.length);
}
- public void write(byte[] b,
- int off,
- int len) throws IOException {
+ public void write(byte[] b, int off, int len) throws IOException {
if (null == b)
return;
try {
@@ -798,8 +763,7 @@ public void write(byte[] b,
// this to an IOException here.
int charsWritten = parentClob.setString(streamPos, s);
streamPos += charsWritten;
- }
- catch (SQLException ex) {
+ } catch (SQLException ex) {
throw new IOException(ex.getMessage());
}
}
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerColumnEncryptionAzureKeyVaultProvider.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerColumnEncryptionAzureKeyVaultProvider.java
index 201f13c7b..5b3e25eab 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerColumnEncryptionAzureKeyVaultProvider.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerColumnEncryptionAzureKeyVaultProvider.java
@@ -1,9 +1,6 @@
/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc;
@@ -33,14 +30,16 @@
import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
+
/**
- * Provides implementation similar to certificate store provider. A CEK encrypted with certificate store provider should be decryptable by this
- * provider and vice versa.
+ * Provides implementation similar to certificate store provider. A CEK encrypted with certificate store provider should
+ * be decryptable by this provider and vice versa.
*
- * Envelope Format for the encrypted column encryption key version + keyPathLength + ciphertextLength + keyPath + ciphertext + signature version: A
- * single byte indicating the format version. keyPathLength: Length of the keyPath. ciphertextLength: ciphertext length keyPath: keyPath used to
- * encrypt the column encryption key. This is only used for troubleshooting purposes and is not verified during decryption. ciphertext: Encrypted
- * column encryption key signature: Signature of the entire byte array. Signature is validated before decrypting the column encryption key.
+ * Envelope Format for the encrypted column encryption key version + keyPathLength + ciphertextLength + keyPath +
+ * ciphertext + signature version: A single byte indicating the format version. keyPathLength: Length of the keyPath.
+ * ciphertextLength: ciphertext length keyPath: keyPath used to encrypt the column encryption key. This is only used for
+ * troubleshooting purposes and is not verified during decryption. ciphertext: Encrypted column encryption key
+ * signature: Signature of the entire byte array. Signature is validated before decrypting the column encryption key.
*/
public class SQLServerColumnEncryptionAzureKeyVaultProvider extends SQLServerColumnEncryptionKeyStoreProvider {
@@ -73,76 +72,79 @@ public String getName() {
}
/**
- * Constructor that takes a callback function to authenticate to AAD. This is used by KeyVaultClient at runtime to authenticate to Azure Key
- * Vault.
+ * Constructs a SQLServerColumnEncryptionAzureKeyVaultProvider with a callback function to authenticate to AAD and
+ * an executor service.. This is used by KeyVaultClient at runtime to authenticate to Azure Key Vault.
*
- * This constructor is present to maintain backwards compatibility with 6.0 version of the driver. Deprecated for removal in next stable release.
+ * This constructor is present to maintain backwards compatibility with 6.0 version of the driver. Deprecated for
+ * removal in next stable release.
*
* @param authenticationCallback
- * - Callback function used for authenticating to AAD.
+ * - Callback function used for authenticating to AAD.
* @param executorService
- * - The ExecutorService, previously used to create the keyVaultClient, but not in use anymore. - This parameter can be passed as 'null'
+ * - The ExecutorService, previously used to create the keyVaultClient, but not in use anymore. - This
+ * parameter can be passed as 'null'
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
@Deprecated
- public SQLServerColumnEncryptionAzureKeyVaultProvider(SQLServerKeyVaultAuthenticationCallback authenticationCallback,
+ public SQLServerColumnEncryptionAzureKeyVaultProvider(
+ SQLServerKeyVaultAuthenticationCallback authenticationCallback,
ExecutorService executorService) throws SQLServerException {
this(authenticationCallback);
}
/**
- * Constructor that takes a callback function to authenticate to AAD. This is used by KeyVaultClient at runtime to authenticate to Azure Key
- * Vault.
+ * Constructs a SQLServerColumnEncryptionAzureKeyVaultProvider with a callback function to authenticate to AAD. This
+ * is used by KeyVaultClient at runtime to authenticate to Azure Key Vault.
*
* @param authenticationCallback
- * - Callback function used for authenticating to AAD.
+ * - Callback function used for authenticating to AAD.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public SQLServerColumnEncryptionAzureKeyVaultProvider(SQLServerKeyVaultAuthenticationCallback authenticationCallback) throws SQLServerException {
+ public SQLServerColumnEncryptionAzureKeyVaultProvider(
+ SQLServerKeyVaultAuthenticationCallback authenticationCallback) throws SQLServerException {
if (null == authenticationCallback) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_NullValue"));
Object[] msgArgs1 = {"SQLServerKeyVaultAuthenticationCallback"};
throw new SQLServerException(form.format(msgArgs1), null);
}
credentials = new KeyVaultCredential(authenticationCallback);
- RestClient restClient = new RestClient.Builder(new OkHttpClient.Builder(), new Retrofit.Builder()).withBaseUrl(baseUrl)
- .withCredentials(credentials).withSerializerAdapter(new AzureJacksonAdapter())
+ RestClient restClient = new RestClient.Builder(new OkHttpClient.Builder(), new Retrofit.Builder())
+ .withBaseUrl(baseUrl).withCredentials(credentials).withSerializerAdapter(new AzureJacksonAdapter())
.withResponseBuilderFactory(new AzureResponseBuilder.Factory()).build();
keyVaultClient = new KeyVaultClient(restClient);
}
/**
- * Constructor that authenticates to AAD. This is used by KeyVaultClient at runtime to authenticate to Azure Key Vault.
+ * Constructs a SQLServerColumnEncryptionAzureKeyVaultProvider with a client id and client key to authenticate to
+ * AAD. This is used by KeyVaultClient at runtime to authenticate to Azure Key Vault.
*
* @param clientId
- * Identifier of the client requesting the token.
+ * Identifier of the client requesting the token.
* @param clientKey
- * Key of the client requesting the token.
+ * Key of the client requesting the token.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public SQLServerColumnEncryptionAzureKeyVaultProvider(String clientId,
- String clientKey) throws SQLServerException {
+ public SQLServerColumnEncryptionAzureKeyVaultProvider(String clientId, String clientKey) throws SQLServerException {
credentials = new KeyVaultCredential(clientId, clientKey);
keyVaultClient = new KeyVaultClient(credentials);
}
/**
- * This function uses the asymmetric key specified by the key path and decrypts an encrypted CEK with RSA encryption algorithm.
+ * Decryptes an encrypted CEK with RSA encryption algorithm using the asymmetric key specified by the key path
*
* @param masterKeyPath
- * - Complete path of an asymmetric key in AKV
+ * - Complete path of an asymmetric key in AKV
* @param encryptionAlgorithm
- * - Asymmetric Key Encryption Algorithm
+ * - Asymmetric Key Encryption Algorithm
* @param encryptedColumnEncryptionKey
- * - Encrypted Column Encryption Key
+ * - Encrypted Column Encryption Key
* @return Plain text column encryption key
*/
@Override
- public byte[] decryptColumnEncryptionKey(String masterKeyPath,
- String encryptionAlgorithm,
+ public byte[] decryptColumnEncryptionKey(String masterKeyPath, String encryptionAlgorithm,
byte[] encryptedColumnEncryptionKey) throws SQLServerException {
// Validate the input parameters
@@ -166,13 +168,16 @@ public byte[] decryptColumnEncryptionKey(String masterKeyPath,
// Format is
// version + keyPathLength + ciphertextLength + keyPath + ciphertext + signature
//
- // keyPath is present in the encrypted column encryption key for identifying the original source of the asymmetric key pair and
+ // keyPath is present in the encrypted column encryption key for identifying the original source of the
+ // asymmetric key pair and
// we will not validate it against the data contained in the CMK metadata (masterKeyPath).
// Validate the version byte
if (encryptedColumnEncryptionKey[0] != firstVersion[0]) {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_InvalidEcryptionAlgorithmVersion"));
- Object[] msgArgs = {String.format("%02X ", encryptedColumnEncryptionKey[0]), String.format("%02X ", firstVersion[0])};
+ MessageFormat form = new MessageFormat(
+ SQLServerException.getErrString("R_InvalidEcryptionAlgorithmVersion"));
+ Object[] msgArgs = {String.format("%02X ", encryptedColumnEncryptionKey[0]),
+ String.format("%02X ", firstVersion[0])};
throw new SQLServerException(this, form.format(msgArgs), null, 0, false);
}
@@ -218,13 +223,13 @@ public byte[] decryptColumnEncryptionKey(String masterKeyPath,
// Compute the hash to validate the signature
byte[] hash = new byte[encryptedColumnEncryptionKey.length - signature.length];
- System.arraycopy(encryptedColumnEncryptionKey, 0, hash, 0, encryptedColumnEncryptionKey.length - signature.length);
+ System.arraycopy(encryptedColumnEncryptionKey, 0, hash, 0,
+ encryptedColumnEncryptionKey.length - signature.length);
MessageDigest md = null;
try {
md = MessageDigest.getInstance("SHA-256");
- }
- catch (NoSuchAlgorithmException e) {
+ } catch (NoSuchAlgorithmException e) {
throw new SQLServerException(SQLServerException.getErrString("R_NoSHA256Algorithm"), e);
}
md.update(hash);
@@ -247,12 +252,12 @@ public byte[] decryptColumnEncryptionKey(String masterKeyPath,
return decryptedCEK;
}
- private short convertTwoBytesToShort(byte[] input,
- int index) throws SQLServerException {
+ private short convertTwoBytesToShort(byte[] input, int index) throws SQLServerException {
short shortVal;
if (index + 1 >= input.length) {
- throw new SQLServerException(null, SQLServerException.getErrString("R_ByteToShortConversion"), null, 0, false);
+ throw new SQLServerException(null, SQLServerException.getErrString("R_ByteToShortConversion"), null, 0,
+ false);
}
ByteBuffer byteBuffer = ByteBuffer.allocate(2);
byteBuffer.order(ByteOrder.LITTLE_ENDIAN);
@@ -264,19 +269,18 @@ private short convertTwoBytesToShort(byte[] input,
}
/**
- * This function uses the asymmetric key specified by the key path and encrypts CEK with RSA encryption algorithm.
+ * Encrypts CEK with RSA encryption algorithm using the asymmetric key specified by the key path.
*
* @param masterKeyPath
- * - Complete path of an asymmetric key in AKV
+ * - Complete path of an asymmetric key in AKV
* @param encryptionAlgorithm
- * - Asymmetric Key Encryption Algorithm
+ * - Asymmetric Key Encryption Algorithm
* @param columnEncryptionKey
- * - Plain text column encryption key
+ * - Plain text column encryption key
* @return Encrypted column encryption key
*/
@Override
- public byte[] encryptColumnEncryptionKey(String masterKeyPath,
- String encryptionAlgorithm,
+ public byte[] encryptColumnEncryptionKey(String masterKeyPath, String encryptionAlgorithm,
byte[] columnEncryptionKey) throws SQLServerException {
// Validate the input parameters
@@ -323,7 +327,8 @@ public byte[] encryptColumnEncryptionKey(String masterKeyPath,
// Compute hash
// SHA-2-256(version + keyPathLength + ciphertextLength + keyPath + ciphertext)
- byte[] dataToHash = new byte[version.length + keyPathLength.length + cipherTextLength.length + masterKeyPathBytes.length + cipherText.length];
+ byte[] dataToHash = new byte[version.length + keyPathLength.length + cipherTextLength.length
+ + masterKeyPathBytes.length + cipherText.length];
int destinationPosition = version.length;
System.arraycopy(version, 0, dataToHash, 0, version.length);
@@ -341,8 +346,7 @@ public byte[] encryptColumnEncryptionKey(String masterKeyPath,
MessageDigest md = null;
try {
md = MessageDigest.getInstance("SHA-256");
- }
- catch (NoSuchAlgorithmException e) {
+ } catch (NoSuchAlgorithmException e) {
throw new SQLServerException(SQLServerException.getErrString("R_NoSHA256Algorithm"), e);
}
md.update(dataToHash);
@@ -361,8 +365,8 @@ public byte[] encryptColumnEncryptionKey(String masterKeyPath,
// Construct the encrypted column encryption key
// EncryptedColumnEncryptionKey = version + keyPathLength + ciphertextLength + keyPath + ciphertext + signature
- int encryptedColumnEncryptionKeyLength = version.length + cipherTextLength.length + keyPathLength.length + cipherText.length
- + masterKeyPathBytes.length + signedHash.length;
+ int encryptedColumnEncryptionKeyLength = version.length + cipherTextLength.length + keyPathLength.length
+ + cipherText.length + masterKeyPathBytes.length + signedHash.length;
byte[] encryptedColumnEncryptionKey = new byte[encryptedColumnEncryptionKeyLength];
// Copy version byte
@@ -393,17 +397,18 @@ public byte[] encryptColumnEncryptionKey(String masterKeyPath,
}
/**
- * This function validates that the encryption algorithm is RSA_OAEP and if it is not, then throws an exception
+ * Validates that the encryption algorithm is RSA_OAEP and if it is not, then throws an exception.
*
* @param encryptionAlgorithm
- * - Asymmetric key encryptio algorithm
+ * - Asymmetric key encryptio algorithm
* @return The encryption algorithm that is going to be used.
* @throws SQLServerException
*/
private String validateEncryptionAlgorithm(String encryptionAlgorithm) throws SQLServerException {
if (null == encryptionAlgorithm) {
- throw new SQLServerException(null, SQLServerException.getErrString("R_NullKeyEncryptionAlgorithm"), null, 0, false);
+ throw new SQLServerException(null, SQLServerException.getErrString("R_NullKeyEncryptionAlgorithm"), null, 0,
+ false);
}
// Transform to standard format (dash instead of underscore) to support both "RSA_OAEP" and "RSA-OAEP"
@@ -432,13 +437,11 @@ private void ValidateNonEmptyAKVPath(String masterKeyPath) throws SQLServerExcep
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_AKVPathNull"));
Object[] msgArgs = {masterKeyPath};
throw new SQLServerException(null, form.format(msgArgs), null, 0, false);
- }
- else {
+ } else {
URI parsedUri = null;
try {
parsedUri = new URI(masterKeyPath);
- }
- catch (URISyntaxException e) {
+ } catch (URISyntaxException e) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_AKVURLInvalid"));
Object[] msgArgs = {masterKeyPath};
throw new SQLServerException(form.format(msgArgs), null, 0, e);
@@ -456,44 +459,43 @@ private void ValidateNonEmptyAKVPath(String masterKeyPath) throws SQLServerExcep
}
/**
- * Encrypt the text using specified Azure Key Vault key.
+ * Encrypts the text using specified Azure Key Vault key.
*
* @param masterKeyPath
- * - Azure Key Vault key url.
+ * - Azure Key Vault key url.
* @param encryptionAlgorithm
- * - Encryption Algorithm.
+ * - Encryption Algorithm.
* @param columnEncryptionKey
- * - Plain text Column Encryption Key.
+ * - Plain text Column Encryption Key.
* @return Returns an encrypted blob or throws an exception if there are any errors.
* @throws SQLServerException
*/
- private byte[] AzureKeyVaultWrap(String masterKeyPath,
- String encryptionAlgorithm,
+ private byte[] AzureKeyVaultWrap(String masterKeyPath, String encryptionAlgorithm,
byte[] columnEncryptionKey) throws SQLServerException {
if (null == columnEncryptionKey) {
throw new SQLServerException(SQLServerException.getErrString("R_CEKNull"), null);
}
JsonWebKeyEncryptionAlgorithm jsonEncryptionAlgorithm = new JsonWebKeyEncryptionAlgorithm(encryptionAlgorithm);
- KeyOperationResult wrappedKey = keyVaultClient.wrapKey(masterKeyPath, jsonEncryptionAlgorithm, columnEncryptionKey);
+ KeyOperationResult wrappedKey = keyVaultClient.wrapKey(masterKeyPath, jsonEncryptionAlgorithm,
+ columnEncryptionKey);
return wrappedKey.result();
}
/**
- * Encrypt the text using specified Azure Key Vault key.
+ * Encrypts the text using specified Azure Key Vault key.
*
* @param masterKeyPath
- * - Azure Key Vault key url.
+ * - Azure Key Vault key url.
* @param encryptionAlgorithm
- * - Encrypted Column Encryption Key.
+ * - Encrypted Column Encryption Key.
* @param encryptedColumnEncryptionKey
- * - Encrypted Column Encryption Key.
+ * - Encrypted Column Encryption Key.
* @return Returns the decrypted plaintext Column Encryption Key or throws an exception if there are any errors.
* @throws SQLServerException
*/
- private byte[] AzureKeyVaultUnWrap(String masterKeyPath,
- String encryptionAlgorithm,
+ private byte[] AzureKeyVaultUnWrap(String masterKeyPath, String encryptionAlgorithm,
byte[] encryptedColumnEncryptionKey) throws SQLServerException {
if (null == encryptedColumnEncryptionKey) {
throw new SQLServerException(SQLServerException.getErrString("R_EncryptedCEKNull"), null);
@@ -504,7 +506,8 @@ private byte[] AzureKeyVaultUnWrap(String masterKeyPath,
}
JsonWebKeyEncryptionAlgorithm jsonEncryptionAlgorithm = new JsonWebKeyEncryptionAlgorithm(encryptionAlgorithm);
- KeyOperationResult unwrappedKey = keyVaultClient.unwrapKey(masterKeyPath, jsonEncryptionAlgorithm, encryptedColumnEncryptionKey);
+ KeyOperationResult unwrappedKey = keyVaultClient.unwrapKey(masterKeyPath, jsonEncryptionAlgorithm,
+ encryptedColumnEncryptionKey);
return unwrappedKey.result();
}
@@ -513,17 +516,17 @@ private byte[] AzureKeyVaultUnWrap(String masterKeyPath,
* Generates signature based on RSA PKCS#v1.5 scheme using a specified Azure Key Vault Key URL.
*
* @param dataToSign
- * - Text to sign.
+ * - Text to sign.
* @param masterKeyPath
- * - Azure Key Vault key url.
+ * - Azure Key Vault key url.
* @return Signature
* @throws SQLServerException
*/
- private byte[] AzureKeyVaultSignHashedData(byte[] dataToSign,
- String masterKeyPath) throws SQLServerException {
+ private byte[] AzureKeyVaultSignHashedData(byte[] dataToSign, String masterKeyPath) throws SQLServerException {
assert ((null != dataToSign) && (0 != dataToSign.length));
- KeyOperationResult signedData = keyVaultClient.sign(masterKeyPath, JsonWebKeySignatureAlgorithm.RS256, dataToSign);
+ KeyOperationResult signedData = keyVaultClient.sign(masterKeyPath, JsonWebKeySignatureAlgorithm.RS256,
+ dataToSign);
return signedData.result();
}
@@ -534,29 +537,29 @@ private byte[] AzureKeyVaultSignHashedData(byte[] dataToSign,
* @param dataToVerify
* @param signature
* @param masterKeyPath
- * - Azure Key Vault key url.
+ * - Azure Key Vault key url.
* @return true if signature is valid, false if it is not valid
* @throws SQLServerException
*/
- private boolean AzureKeyVaultVerifySignature(byte[] dataToVerify,
- byte[] signature,
+ private boolean AzureKeyVaultVerifySignature(byte[] dataToVerify, byte[] signature,
String masterKeyPath) throws SQLServerException {
assert ((null != dataToVerify) && (0 != dataToVerify.length));
assert ((null != signature) && (0 != signature.length));
- KeyVerifyResult valid = keyVaultClient.verify(masterKeyPath, JsonWebKeySignatureAlgorithm.RS256, dataToVerify, signature);
+ KeyVerifyResult valid = keyVaultClient.verify(masterKeyPath, JsonWebKeySignatureAlgorithm.RS256, dataToVerify,
+ signature);
return valid.value();
}
/**
- * Gets the public Key size in bytes
+ * Returns the public Key size in bytes.
*
* @param masterKeyPath
- * - Azure Key Vault Key path
+ * - Azure Key Vault Key path
* @return Key size in bytes
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
private int getAKVKeySize(String masterKeyPath) throws SQLServerException {
KeyBundle retrievedKey = keyVaultClient.getKey(masterKeyPath);
@@ -569,7 +572,8 @@ private int getAKVKeySize(String masterKeyPath) throws SQLServerException {
throw new SQLServerException(null, form.format(msgArgs), null, 0, false);
}
- if (!"RSA".equalsIgnoreCase(retrievedKey.key().kty().toString()) && !"RSA-HSM".equalsIgnoreCase(retrievedKey.key().kty().toString())) {
+ if (!"RSA".equalsIgnoreCase(retrievedKey.key().kty().toString())
+ && !"RSA-HSM".equalsIgnoreCase(retrievedKey.key().kty().toString())) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_NonRSAKey"));
Object[] msgArgs = {retrievedKey.key().kty().toString()};
throw new SQLServerException(null, form.format(msgArgs), null, 0, false);
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerColumnEncryptionCertificateStoreProvider.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerColumnEncryptionCertificateStoreProvider.java
index 5f8bc8001..1f87ecbe0 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerColumnEncryptionCertificateStoreProvider.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerColumnEncryptionCertificateStoreProvider.java
@@ -1,246 +1,238 @@
-/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
- */
-
-package com.microsoft.sqlserver.jdbc;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.nio.file.Path;
-import java.security.Key;
-import java.security.KeyStore;
-import java.security.KeyStoreException;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-import java.security.UnrecoverableKeyException;
-import java.security.cert.CertificateEncodingException;
-import java.security.cert.CertificateException;
-import java.security.cert.X509Certificate;
-import java.text.MessageFormat;
-import java.util.Base64;
-import java.util.Enumeration;
-import java.util.Locale;
-
-
-/**
- * The implementation of the key store provider for the Windows Certificate Store. This class enables using keys stored in the Windows Certificate
- * Store as column master keys.
- *
- */
-public final class SQLServerColumnEncryptionCertificateStoreProvider extends SQLServerColumnEncryptionKeyStoreProvider {
- static final private java.util.logging.Logger windowsCertificateStoreLogger = java.util.logging.Logger
- .getLogger("com.microsoft.sqlserver.jdbc.SQLServerColumnEncryptionCertificateStoreProvider");
-
- static boolean isWindows;
-
- String name = "MSSQL_CERTIFICATE_STORE";
-
- static final String localMachineDirectory = "LocalMachine";
- static final String currentUserDirectory = "CurrentUser";
- static final String myCertificateStore = "My";
-
- static {
- if (System.getProperty("os.name").toLowerCase(Locale.ENGLISH).startsWith("windows")) {
- isWindows = true;
- }
- else {
- isWindows = false;
- }
- }
- private Path keyStoreDirectoryPath = null;
-
- public SQLServerColumnEncryptionCertificateStoreProvider() {
- windowsCertificateStoreLogger.entering(SQLServerColumnEncryptionCertificateStoreProvider.class.getName(),
- "SQLServerColumnEncryptionCertificateStoreProvider");
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getName() {
- return this.name;
- }
-
- public byte[] encryptColumnEncryptionKey(String masterKeyPath,
- String encryptionAlgorithm,
- byte[] plainTextColumnEncryptionKey) throws SQLServerException {
- throw new SQLServerException(null, SQLServerException.getErrString("R_InvalidWindowsCertificateStoreEncryption"), null, 0, false);
- }
-
- private byte[] decryptColumnEncryptionKeyWindows(String masterKeyPath,
- String encryptionAlgorithm,
- byte[] encryptedColumnEncryptionKey) throws SQLServerException {
- try {
- return AuthenticationJNI.DecryptColumnEncryptionKey(masterKeyPath, encryptionAlgorithm, encryptedColumnEncryptionKey);
- }
- catch (DLLException e) {
- DLLException.buildException(e.GetErrCode(), e.GetParam1(), e.GetParam2(), e.GetParam3());
- return null;
- }
- }
-
- private CertificateDetails getCertificateDetails(String masterKeyPath) throws SQLServerException {
- String storeLocation = null;
-
- String[] certParts = masterKeyPath.split("/");
-
- // Validate certificate path
- // Certificate path should only contain 3 parts (Certificate Location, Certificate Store Name and Thumbprint)
- if (certParts.length > 3) {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_AECertpathBad"));
- Object[] msgArgs = {masterKeyPath};
- throw new SQLServerException(form.format(msgArgs), null);
- }
-
- // Extract the store location where the cert is stored
- if (certParts.length > 2) {
- if (certParts[0].equalsIgnoreCase(localMachineDirectory)) {
- storeLocation = localMachineDirectory;
- }
- else if (certParts[0].equalsIgnoreCase(currentUserDirectory)) {
- storeLocation = currentUserDirectory;
- }
- else {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_AECertLocBad"));
- Object[] msgArgs = {certParts[0], masterKeyPath};
- throw new SQLServerException(form.format(msgArgs), null);
- }
- }
-
- // Parse the certificate store name. Only store name "My" is supported.
- if (certParts.length > 1) {
- if (!certParts[certParts.length - 2].equalsIgnoreCase(myCertificateStore)) {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_AECertStoreBad"));
- Object[] msgArgs = {certParts[certParts.length - 2], masterKeyPath};
- throw new SQLServerException(form.format(msgArgs), null);
- }
- }
-
- // Get thumpbrint
- String thumbprint = certParts[certParts.length - 1];
- if ((null == thumbprint) || (0 == thumbprint.length())) {
- // An empty thumbprint specified
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_AECertHashEmpty"));
- Object[] msgArgs = {masterKeyPath};
- throw new SQLServerException(form.format(msgArgs), null);
- }
-
- // Find the certificate and return
- return getCertificateByThumbprint(storeLocation, thumbprint, masterKeyPath);
- }
-
- private String getThumbPrint(X509Certificate cert) throws NoSuchAlgorithmException, CertificateEncodingException {
- MessageDigest md = MessageDigest.getInstance("SHA-1");
- byte[] der = cert.getEncoded();
- md.update(der);
- byte[] digest = md.digest();
- return Base64.getEncoder().encodeToString(digest);
- }
-
- private CertificateDetails getCertificateByThumbprint(String storeLocation,
- String thumbprint,
- String masterKeyPath) throws SQLServerException {
- FileInputStream fis;
-
- if ((null == keyStoreDirectoryPath)) {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_AEKeyPathEmptyOrReserved"));
- Object[] msgArgs = {keyStoreDirectoryPath};
- throw new SQLServerException(form.format(msgArgs), null);
- }
-
- Path keyStoreFullPath = keyStoreDirectoryPath.resolve(storeLocation);
-
- KeyStore keyStore = null;
- try {
- keyStore = KeyStore.getInstance("PKCS12");
- }
- catch (KeyStoreException e) {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_CertificateError"));
- Object[] msgArgs = {masterKeyPath, name};
- throw new SQLServerException(this, form.format(msgArgs), null, 0, false);
- }
-
- File keyStoreDirectory = keyStoreFullPath.toFile();
- File[] listOfFiles = keyStoreDirectory.listFiles();
-
- if ((null == listOfFiles) || (0 == listOfFiles.length)) {
- throw new SQLServerException(SQLServerException.getErrString("R_KeyStoreNotFound"), null);
- }
-
- for (File f : listOfFiles) {
-
- if (f.isDirectory()) {
- continue;
- }
-
- char[] password = "".toCharArray();
- try {
- fis = new FileInputStream(f);
- keyStore.load(fis, password);
- }
- catch (IOException | CertificateException | NoSuchAlgorithmException e) {
- // Cannot parse the current file, continue to the next.
- continue;
- }
-
- // If we are here, we were able to load a PKCS12 file.
- try {
- for (Enumeration enumeration = keyStore.aliases(); enumeration.hasMoreElements();) {
-
- String alias = enumeration.nextElement();
-
- X509Certificate publicCertificate = (X509Certificate) keyStore.getCertificate(alias);
-
- if (thumbprint.matches(getThumbPrint(publicCertificate))) {
- // Found the right certificate
- Key keyPrivate = null;
- try {
- keyPrivate = keyStore.getKey(alias, "".toCharArray());
- if (null == keyPrivate) {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_UnrecoverableKeyAE"));
- Object[] msgArgs = {masterKeyPath};
- throw new SQLServerException(this, form.format(msgArgs), null, 0, false);
- }
- }
- catch (UnrecoverableKeyException | NoSuchAlgorithmException | KeyStoreException e) {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_UnrecoverableKeyAE"));
- Object[] msgArgs = {masterKeyPath};
- throw new SQLServerException(this, form.format(msgArgs), null, 0, false);
- }
- return new CertificateDetails(publicCertificate, keyPrivate);
- }
- }// end of for for alias
- }
- catch (CertificateException | NoSuchAlgorithmException | KeyStoreException e) {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_CertificateError"));
- Object[] msgArgs = {masterKeyPath, name};
- throw new SQLServerException(form.format(msgArgs), e);
- }
- }
- // Looped over all files, haven't found the certificate
- throw new SQLServerException(SQLServerException.getErrString("R_KeyStoreNotFound"), null);
- }
-
- public byte[] decryptColumnEncryptionKey(String masterKeyPath,
- String encryptionAlgorithm,
- byte[] encryptedColumnEncryptionKey) throws SQLServerException {
- windowsCertificateStoreLogger.entering(SQLServerColumnEncryptionCertificateStoreProvider.class.getName(), "decryptColumnEncryptionKey",
- "Decrypting Column Encryption Key.");
- byte[] plainCek;
- if (isWindows) {
- plainCek = decryptColumnEncryptionKeyWindows(masterKeyPath, encryptionAlgorithm, encryptedColumnEncryptionKey);
- }
- else {
- throw new SQLServerException(SQLServerException.getErrString("R_notSupported"), null);
- }
- windowsCertificateStoreLogger.exiting(SQLServerColumnEncryptionCertificateStoreProvider.class.getName(), "decryptColumnEncryptionKey",
- "Finished decrypting Column Encryption Key.");
- return plainCek;
- }
-}
+/*
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ */
+
+package com.microsoft.sqlserver.jdbc;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.nio.file.Path;
+import java.security.Key;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.security.UnrecoverableKeyException;
+import java.security.cert.CertificateEncodingException;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+import java.text.MessageFormat;
+import java.util.Base64;
+import java.util.Enumeration;
+import java.util.Locale;
+
+
+/**
+ * Provides the implementation of the key store provider for the Windows Certificate Store. This class enables using
+ * keys stored in the Windows Certificate Store as column master keys.
+ *
+ */
+public final class SQLServerColumnEncryptionCertificateStoreProvider extends SQLServerColumnEncryptionKeyStoreProvider {
+ static final private java.util.logging.Logger windowsCertificateStoreLogger = java.util.logging.Logger
+ .getLogger("com.microsoft.sqlserver.jdbc.SQLServerColumnEncryptionCertificateStoreProvider");
+
+ static boolean isWindows;
+
+ String name = "MSSQL_CERTIFICATE_STORE";
+
+ static final String localMachineDirectory = "LocalMachine";
+ static final String currentUserDirectory = "CurrentUser";
+ static final String myCertificateStore = "My";
+
+ static {
+ if (System.getProperty("os.name").toLowerCase(Locale.ENGLISH).startsWith("windows")) {
+ isWindows = true;
+ } else {
+ isWindows = false;
+ }
+ }
+ private Path keyStoreDirectoryPath = null;
+
+ /**
+ * Constructs a SQLServerColumnEncryptionCertificateStoreProvider.
+ */
+ public SQLServerColumnEncryptionCertificateStoreProvider() {
+ windowsCertificateStoreLogger.entering(SQLServerColumnEncryptionCertificateStoreProvider.class.getName(),
+ "SQLServerColumnEncryptionCertificateStoreProvider");
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public byte[] encryptColumnEncryptionKey(String masterKeyPath, String encryptionAlgorithm,
+ byte[] plainTextColumnEncryptionKey) throws SQLServerException {
+ throw new SQLServerException(null,
+ SQLServerException.getErrString("R_InvalidWindowsCertificateStoreEncryption"), null, 0, false);
+ }
+
+ private byte[] decryptColumnEncryptionKeyWindows(String masterKeyPath, String encryptionAlgorithm,
+ byte[] encryptedColumnEncryptionKey) throws SQLServerException {
+ try {
+ return AuthenticationJNI.DecryptColumnEncryptionKey(masterKeyPath, encryptionAlgorithm,
+ encryptedColumnEncryptionKey);
+ } catch (DLLException e) {
+ DLLException.buildException(e.GetErrCode(), e.GetParam1(), e.GetParam2(), e.GetParam3());
+ return null;
+ }
+ }
+
+ private CertificateDetails getCertificateDetails(String masterKeyPath) throws SQLServerException {
+ String storeLocation = null;
+
+ String[] certParts = masterKeyPath.split("/");
+
+ // Validate certificate path
+ // Certificate path should only contain 3 parts (Certificate Location, Certificate Store Name and Thumbprint)
+ if (certParts.length > 3) {
+ MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_AECertpathBad"));
+ Object[] msgArgs = {masterKeyPath};
+ throw new SQLServerException(form.format(msgArgs), null);
+ }
+
+ // Extract the store location where the cert is stored
+ if (certParts.length > 2) {
+ if (certParts[0].equalsIgnoreCase(localMachineDirectory)) {
+ storeLocation = localMachineDirectory;
+ } else if (certParts[0].equalsIgnoreCase(currentUserDirectory)) {
+ storeLocation = currentUserDirectory;
+ } else {
+ MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_AECertLocBad"));
+ Object[] msgArgs = {certParts[0], masterKeyPath};
+ throw new SQLServerException(form.format(msgArgs), null);
+ }
+ }
+
+ // Parse the certificate store name. Only store name "My" is supported.
+ if (certParts.length > 1) {
+ if (!certParts[certParts.length - 2].equalsIgnoreCase(myCertificateStore)) {
+ MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_AECertStoreBad"));
+ Object[] msgArgs = {certParts[certParts.length - 2], masterKeyPath};
+ throw new SQLServerException(form.format(msgArgs), null);
+ }
+ }
+
+ // Get thumpbrint
+ String thumbprint = certParts[certParts.length - 1];
+ if ((null == thumbprint) || (0 == thumbprint.length())) {
+ // An empty thumbprint specified
+ MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_AECertHashEmpty"));
+ Object[] msgArgs = {masterKeyPath};
+ throw new SQLServerException(form.format(msgArgs), null);
+ }
+
+ // Find the certificate and return
+ return getCertificateByThumbprint(storeLocation, thumbprint, masterKeyPath);
+ }
+
+ private String getThumbPrint(X509Certificate cert) throws NoSuchAlgorithmException, CertificateEncodingException {
+ MessageDigest md = MessageDigest.getInstance("SHA-1");
+ byte[] der = cert.getEncoded();
+ md.update(der);
+ byte[] digest = md.digest();
+ return Base64.getEncoder().encodeToString(digest);
+ }
+
+ private CertificateDetails getCertificateByThumbprint(String storeLocation, String thumbprint,
+ String masterKeyPath) throws SQLServerException {
+ FileInputStream fis;
+
+ if ((null == keyStoreDirectoryPath)) {
+ MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_AEKeyPathEmptyOrReserved"));
+ Object[] msgArgs = {keyStoreDirectoryPath};
+ throw new SQLServerException(form.format(msgArgs), null);
+ }
+
+ Path keyStoreFullPath = keyStoreDirectoryPath.resolve(storeLocation);
+
+ KeyStore keyStore = null;
+ try {
+ keyStore = KeyStore.getInstance("PKCS12");
+ } catch (KeyStoreException e) {
+ MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_CertificateError"));
+ Object[] msgArgs = {masterKeyPath, name};
+ throw new SQLServerException(this, form.format(msgArgs), null, 0, false);
+ }
+
+ File keyStoreDirectory = keyStoreFullPath.toFile();
+ File[] listOfFiles = keyStoreDirectory.listFiles();
+
+ if ((null == listOfFiles) || (0 == listOfFiles.length)) {
+ throw new SQLServerException(SQLServerException.getErrString("R_KeyStoreNotFound"), null);
+ }
+
+ for (File f : listOfFiles) {
+
+ if (f.isDirectory()) {
+ continue;
+ }
+
+ char[] password = "".toCharArray();
+ try {
+ fis = new FileInputStream(f);
+ keyStore.load(fis, password);
+ } catch (IOException | CertificateException | NoSuchAlgorithmException e) {
+ // Cannot parse the current file, continue to the next.
+ continue;
+ }
+
+ // If we are here, we were able to load a PKCS12 file.
+ try {
+ for (Enumeration enumeration = keyStore.aliases(); enumeration.hasMoreElements();) {
+
+ String alias = enumeration.nextElement();
+
+ X509Certificate publicCertificate = (X509Certificate) keyStore.getCertificate(alias);
+
+ if (thumbprint.matches(getThumbPrint(publicCertificate))) {
+ // Found the right certificate
+ Key keyPrivate = null;
+ try {
+ keyPrivate = keyStore.getKey(alias, "".toCharArray());
+ if (null == keyPrivate) {
+ MessageFormat form = new MessageFormat(
+ SQLServerException.getErrString("R_UnrecoverableKeyAE"));
+ Object[] msgArgs = {masterKeyPath};
+ throw new SQLServerException(this, form.format(msgArgs), null, 0, false);
+ }
+ } catch (UnrecoverableKeyException | NoSuchAlgorithmException | KeyStoreException e) {
+ MessageFormat form = new MessageFormat(
+ SQLServerException.getErrString("R_UnrecoverableKeyAE"));
+ Object[] msgArgs = {masterKeyPath};
+ throw new SQLServerException(this, form.format(msgArgs), null, 0, false);
+ }
+ return new CertificateDetails(publicCertificate, keyPrivate);
+ }
+ } // end of for for alias
+ } catch (CertificateException | NoSuchAlgorithmException | KeyStoreException e) {
+ MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_CertificateError"));
+ Object[] msgArgs = {masterKeyPath, name};
+ throw new SQLServerException(form.format(msgArgs), e);
+ }
+ }
+ // Looped over all files, haven't found the certificate
+ throw new SQLServerException(SQLServerException.getErrString("R_KeyStoreNotFound"), null);
+ }
+
+ public byte[] decryptColumnEncryptionKey(String masterKeyPath, String encryptionAlgorithm,
+ byte[] encryptedColumnEncryptionKey) throws SQLServerException {
+ windowsCertificateStoreLogger.entering(SQLServerColumnEncryptionCertificateStoreProvider.class.getName(),
+ "decryptColumnEncryptionKey", "Decrypting Column Encryption Key.");
+ byte[] plainCek;
+ if (isWindows) {
+ plainCek = decryptColumnEncryptionKeyWindows(masterKeyPath, encryptionAlgorithm,
+ encryptedColumnEncryptionKey);
+ } else {
+ throw new SQLServerException(SQLServerException.getErrString("R_notSupported"), null);
+ }
+ windowsCertificateStoreLogger.exiting(SQLServerColumnEncryptionCertificateStoreProvider.class.getName(),
+ "decryptColumnEncryptionKey", "Finished decrypting Column Encryption Key.");
+ return plainCek;
+ }
+}
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerColumnEncryptionJavaKeyStoreProvider.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerColumnEncryptionJavaKeyStoreProvider.java
index 4de4f19b1..b4ee6be76 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerColumnEncryptionJavaKeyStoreProvider.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerColumnEncryptionJavaKeyStoreProvider.java
@@ -1,328 +1,321 @@
-/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
- */
-
-package com.microsoft.sqlserver.jdbc;
-
-import static java.nio.charset.StandardCharsets.UTF_16LE;
-
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-import java.security.InvalidKeyException;
-import java.security.Key;
-import java.security.KeyStore;
-import java.security.KeyStoreException;
-import java.security.NoSuchAlgorithmException;
-import java.security.PrivateKey;
-import java.security.Signature;
-import java.security.SignatureException;
-import java.security.UnrecoverableKeyException;
-import java.security.cert.CertificateException;
-import java.security.cert.X509Certificate;
-import java.text.MessageFormat;
-
-import javax.crypto.BadPaddingException;
-import javax.crypto.Cipher;
-import javax.crypto.IllegalBlockSizeException;
-import javax.crypto.NoSuchPaddingException;
-
-/**
- *
- * The implementation of the key store provider for Java Key Store. This class enables using certificates stored in the Java keystore as column master
- * keys.
- *
- */
-public class SQLServerColumnEncryptionJavaKeyStoreProvider extends SQLServerColumnEncryptionKeyStoreProvider {
- String name = "MSSQL_JAVA_KEYSTORE";
- String keyStorePath = null;
- char[] keyStorePwd = null;
-
- static final private java.util.logging.Logger javaKeyStoreLogger = java.util.logging.Logger
- .getLogger("com.microsoft.sqlserver.jdbc.SQLServerColumnEncryptionJavaKeyStoreProvider");
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getName() {
- return this.name;
- }
-
- /**
- * Key store provider for the Java Key Store.
- *
- * @param keyStoreLocation
- * specifies the location of the keystore
- * @param keyStoreSecret
- * specifies the secret used for keystore
- * @throws SQLServerException
- * when an error occurs
- */
- public SQLServerColumnEncryptionJavaKeyStoreProvider(String keyStoreLocation,
- char[] keyStoreSecret) throws SQLServerException {
- javaKeyStoreLogger.entering(SQLServerColumnEncryptionJavaKeyStoreProvider.class.getName(), "SQLServerColumnEncryptionJavaKeyStoreProvider");
-
- if ((null == keyStoreLocation) || (0 == keyStoreLocation.length())) {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_InvalidConnectionSetting"));
- Object[] msgArgs = {"keyStoreLocation", keyStoreLocation};
- throw new SQLServerException(form.format(msgArgs), null);
- }
-
- this.keyStorePath = keyStoreLocation;
-
- if (javaKeyStoreLogger.isLoggable(java.util.logging.Level.FINE)) {
- javaKeyStoreLogger.fine("Path of key store provider is set.");
- }
-
- // Password can be null or empty, PKCS12 type allows that.
- if (null == keyStoreSecret) {
- keyStoreSecret = "".toCharArray();
- }
-
- this.keyStorePwd = new char[keyStoreSecret.length];
- System.arraycopy(keyStoreSecret, 0, this.keyStorePwd, 0, keyStoreSecret.length);
-
- if (javaKeyStoreLogger.isLoggable(java.util.logging.Level.FINE)) {
- javaKeyStoreLogger.fine("Password for key store provider is set.");
- }
-
- javaKeyStoreLogger.exiting(SQLServerColumnEncryptionJavaKeyStoreProvider.class.getName(), "SQLServerColumnEncryptionJavaKeyStoreProvider");
- }
-
- @Override
- public byte[] decryptColumnEncryptionKey(String masterKeyPath,
- String encryptionAlgorithm,
- byte[] encryptedColumnEncryptionKey) throws SQLServerException {
- javaKeyStoreLogger.entering(SQLServerColumnEncryptionJavaKeyStoreProvider.class.getName(), "decryptColumnEncryptionKey",
- "Decrypting Column Encryption Key.");
-
- KeyStoreProviderCommon.validateNonEmptyMasterKeyPath(masterKeyPath);
- CertificateDetails certificateDetails = getCertificateDetails(masterKeyPath);
- byte[] plainCEK = KeyStoreProviderCommon.decryptColumnEncryptionKey(masterKeyPath, encryptionAlgorithm, encryptedColumnEncryptionKey,
- certificateDetails);
-
- javaKeyStoreLogger.exiting(SQLServerColumnEncryptionJavaKeyStoreProvider.class.getName(), "decryptColumnEncryptionKey",
- "Finished decrypting Column Encryption Key.");
- return plainCEK;
- }
-
- private CertificateDetails getCertificateDetails(String masterKeyPath) throws SQLServerException {
- FileInputStream fis = null;
- KeyStore keyStore = null;
- CertificateDetails certificateDetails = null;
-
- try {
- if (null == masterKeyPath || 0 == masterKeyPath.length()) {
- throw new SQLServerException(null, SQLServerException.getErrString("R_InvalidMasterKeyDetails"), null, 0, false);
- }
-
- try {
- // Try to load JKS first, if fails try PKCS12
- keyStore = KeyStore.getInstance("JKS");
- fis = new FileInputStream(keyStorePath);
- keyStore.load(fis, keyStorePwd);
- }
- catch (IOException e) {
- if (null != fis)
- fis.close();
-
- // Loading as JKS failed, try to load as PKCS12
- keyStore = KeyStore.getInstance("PKCS12");
- fis = new FileInputStream(keyStorePath);
- keyStore.load(fis, keyStorePwd);
- }
-
- certificateDetails = getCertificateDetailsByAlias(keyStore, masterKeyPath);
- }
- catch (FileNotFoundException fileNotFound) {
- throw new SQLServerException(this, SQLServerException.getErrString("R_KeyStoreNotFound"), null, 0, false);
- }
- catch (IOException | CertificateException | NoSuchAlgorithmException | KeyStoreException e) {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidKeyStoreFile"));
- Object[] msgArgs = {keyStorePath};
- throw new SQLServerException(form.format(msgArgs), e);
- }
- finally {
- try {
- if (null != fis)
- fis.close();
- }
- // Ignore the exception as we are cleaning up.
- catch (IOException e) {
- }
- }
-
- return certificateDetails;
- }
-
- private CertificateDetails getCertificateDetailsByAlias(KeyStore keyStore,
- String alias) throws SQLServerException {
- try {
- X509Certificate publicCertificate = (X509Certificate) keyStore.getCertificate(alias);
- Key keyPrivate = keyStore.getKey(alias, keyStorePwd);
- if (null == publicCertificate) {
- // Certificate not found. Throw an exception.
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_CertificateNotFoundForAlias"));
- Object[] msgArgs = {alias, "MSSQL_JAVA_KEYSTORE"};
- throw new SQLServerException(this, form.format(msgArgs), null, 0, false);
- }
-
- // found certificate but corresponding private key not found, throw exception
- if (null == keyPrivate) {
- throw new UnrecoverableKeyException();
- }
-
- return new CertificateDetails(publicCertificate, keyPrivate);
- }
- catch (UnrecoverableKeyException unrecoverableKeyException) {
-
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_UnrecoverableKeyAE"));
- Object[] msgArgs = {alias};
- throw new SQLServerException(this, form.format(msgArgs), null, 0, false);
- }
- catch (NoSuchAlgorithmException | KeyStoreException e) {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_CertificateError"));
- Object[] msgArgs = {alias, name};
- throw new SQLServerException(form.format(msgArgs), e);
- }
- }
-
- @Override
- public byte[] encryptColumnEncryptionKey(String masterKeyPath,
- String encryptionAlgorithm,
- byte[] plainTextColumnEncryptionKey) throws SQLServerException {
- javaKeyStoreLogger.entering(SQLServerColumnEncryptionJavaKeyStoreProvider.class.getName(),
- Thread.currentThread().getStackTrace()[1].getMethodName(), "Encrypting Column Encryption Key.");
-
- byte[] version = KeyStoreProviderCommon.version;
- KeyStoreProviderCommon.validateNonEmptyMasterKeyPath(masterKeyPath);
-
- if (null == plainTextColumnEncryptionKey) {
-
- throw new SQLServerException(null, SQLServerException.getErrString("R_NullColumnEncryptionKey"), null, 0, false);
-
- }
- else if (0 == plainTextColumnEncryptionKey.length) {
-
- throw new SQLServerException(null, SQLServerException.getErrString("R_EmptyColumnEncryptionKey"), null, 0, false);
-
- }
-
- KeyStoreProviderCommon.validateEncryptionAlgorithm(encryptionAlgorithm, true);
-
- CertificateDetails certificateDetails = getCertificateDetails(masterKeyPath);
- byte[] cipherText = encryptRSAOAEP(plainTextColumnEncryptionKey, certificateDetails);
- byte[] cipherTextLength = getLittleEndianBytesFromShort((short) cipherText.length);
- byte[] masterKeyPathBytes = masterKeyPath.toLowerCase().getBytes(UTF_16LE);
-
- byte[] keyPathLength = getLittleEndianBytesFromShort((short) masterKeyPathBytes.length);
-
- byte[] dataToSign = new byte[version.length + keyPathLength.length + cipherTextLength.length + masterKeyPathBytes.length + cipherText.length];
- int destinationPosition = version.length;
- System.arraycopy(version, 0, dataToSign, 0, version.length);
-
- System.arraycopy(keyPathLength, 0, dataToSign, destinationPosition, keyPathLength.length);
- destinationPosition += keyPathLength.length;
-
- System.arraycopy(cipherTextLength, 0, dataToSign, destinationPosition, cipherTextLength.length);
- destinationPosition += cipherTextLength.length;
-
- System.arraycopy(masterKeyPathBytes, 0, dataToSign, destinationPosition, masterKeyPathBytes.length);
- destinationPosition += masterKeyPathBytes.length;
-
- System.arraycopy(cipherText, 0, dataToSign, destinationPosition, cipherText.length);
- byte[] signedHash = rsaSignHashedData(dataToSign, certificateDetails);
-
- int encryptedColumnEncryptionKeyLength = version.length + cipherTextLength.length + keyPathLength.length + cipherText.length
- + masterKeyPathBytes.length + signedHash.length;
- byte[] encryptedColumnEncryptionKey = new byte[encryptedColumnEncryptionKeyLength];
-
- int currentIndex = 0;
- System.arraycopy(version, 0, encryptedColumnEncryptionKey, currentIndex, version.length);
- currentIndex += version.length;
-
- System.arraycopy(keyPathLength, 0, encryptedColumnEncryptionKey, currentIndex, keyPathLength.length);
- currentIndex += keyPathLength.length;
-
- System.arraycopy(cipherTextLength, 0, encryptedColumnEncryptionKey, currentIndex, cipherTextLength.length);
- currentIndex += cipherTextLength.length;
-
- System.arraycopy(masterKeyPathBytes, 0, encryptedColumnEncryptionKey, currentIndex, masterKeyPathBytes.length);
- currentIndex += masterKeyPathBytes.length;
-
- System.arraycopy(cipherText, 0, encryptedColumnEncryptionKey, currentIndex, cipherText.length);
- currentIndex += cipherText.length;
-
- System.arraycopy(signedHash, 0, encryptedColumnEncryptionKey, currentIndex, signedHash.length);
-
- javaKeyStoreLogger.exiting(SQLServerColumnEncryptionJavaKeyStoreProvider.class.getName(),
- Thread.currentThread().getStackTrace()[1].getMethodName(), "Finished encrypting Column Encryption Key.");
- return encryptedColumnEncryptionKey;
-
- }
-
- /**
- * Encrypt plainText with the certificate provided
- *
- * @param plainText
- * plain CEK to be encrypted
- * @param certificateDetails
- * @return encrypted CEK
- * @throws SQLServerException
- */
- private byte[] encryptRSAOAEP(byte[] plainText,
- CertificateDetails certificateDetails) throws SQLServerException {
- byte[] cipherText = null;
- try {
- Cipher rsa = Cipher.getInstance("RSA/ECB/OAEPWithSHA-1AndMGF1Padding");
- rsa.init(Cipher.ENCRYPT_MODE, certificateDetails.certificate.getPublicKey());
- rsa.update(plainText);
- cipherText = rsa.doFinal();
- }
- catch (InvalidKeyException | NoSuchAlgorithmException | IllegalBlockSizeException | NoSuchPaddingException | BadPaddingException e) {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_EncryptionFailed"));
- Object[] msgArgs = {e.getMessage()};
- throw new SQLServerException(this, form.format(msgArgs), null, 0, false);
- }
-
- return cipherText;
-
- }
-
- private byte[] rsaSignHashedData(byte[] dataToSign,
- CertificateDetails certificateDetails) throws SQLServerException {
- Signature signature;
- byte[] signedHash = null;
-
- try {
- signature = Signature.getInstance("SHA256withRSA");
- signature.initSign((PrivateKey) certificateDetails.privateKey);
- signature.update(dataToSign);
- signedHash = signature.sign();
- }
- catch (InvalidKeyException | NoSuchAlgorithmException | SignatureException e) {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_EncryptionFailed"));
- Object[] msgArgs = {e.getMessage()};
- throw new SQLServerException(this, form.format(msgArgs), null, 0, false);
-
- }
- return signedHash;
-
- }
-
- private byte[] getLittleEndianBytesFromShort(short value) {
- ByteBuffer byteBuffer = ByteBuffer.allocate(2);
- byteBuffer.order(ByteOrder.LITTLE_ENDIAN);
- byte[] byteValue = byteBuffer.putShort(value).array();
- return byteValue;
-
- }
-
-}
+/*
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ */
+
+package com.microsoft.sqlserver.jdbc;
+
+import static java.nio.charset.StandardCharsets.UTF_16LE;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.security.InvalidKeyException;
+import java.security.Key;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.PrivateKey;
+import java.security.Signature;
+import java.security.SignatureException;
+import java.security.UnrecoverableKeyException;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+import java.text.MessageFormat;
+
+import javax.crypto.BadPaddingException;
+import javax.crypto.Cipher;
+import javax.crypto.IllegalBlockSizeException;
+import javax.crypto.NoSuchPaddingException;
+
+
+/**
+ *
+ * Provides the implementation of the key store provider for Java Key Store. This class enables using certificates
+ * stored in the Java keystore as column master keys.
+ *
+ */
+public class SQLServerColumnEncryptionJavaKeyStoreProvider extends SQLServerColumnEncryptionKeyStoreProvider {
+ String name = "MSSQL_JAVA_KEYSTORE";
+ String keyStorePath = null;
+ char[] keyStorePwd = null;
+
+ static final private java.util.logging.Logger javaKeyStoreLogger = java.util.logging.Logger
+ .getLogger("com.microsoft.sqlserver.jdbc.SQLServerColumnEncryptionJavaKeyStoreProvider");
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ /**
+ * Constructs a SQLServerColumnEncryptionJavaKeyStoreProvider for the Java Key Store.
+ *
+ * @param keyStoreLocation
+ * specifies the location of the keystore
+ * @param keyStoreSecret
+ * specifies the secret used for keystore
+ * @throws SQLServerException
+ * when an error occurs
+ */
+ public SQLServerColumnEncryptionJavaKeyStoreProvider(String keyStoreLocation,
+ char[] keyStoreSecret) throws SQLServerException {
+ javaKeyStoreLogger.entering(SQLServerColumnEncryptionJavaKeyStoreProvider.class.getName(),
+ "SQLServerColumnEncryptionJavaKeyStoreProvider");
+
+ if ((null == keyStoreLocation) || (0 == keyStoreLocation.length())) {
+ MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_InvalidConnectionSetting"));
+ Object[] msgArgs = {"keyStoreLocation", keyStoreLocation};
+ throw new SQLServerException(form.format(msgArgs), null);
+ }
+
+ this.keyStorePath = keyStoreLocation;
+
+ if (javaKeyStoreLogger.isLoggable(java.util.logging.Level.FINE)) {
+ javaKeyStoreLogger.fine("Path of key store provider is set.");
+ }
+
+ // Password can be null or empty, PKCS12 type allows that.
+ if (null == keyStoreSecret) {
+ keyStoreSecret = "".toCharArray();
+ }
+
+ this.keyStorePwd = new char[keyStoreSecret.length];
+ System.arraycopy(keyStoreSecret, 0, this.keyStorePwd, 0, keyStoreSecret.length);
+
+ if (javaKeyStoreLogger.isLoggable(java.util.logging.Level.FINE)) {
+ javaKeyStoreLogger.fine("Password for key store provider is set.");
+ }
+
+ javaKeyStoreLogger.exiting(SQLServerColumnEncryptionJavaKeyStoreProvider.class.getName(),
+ "SQLServerColumnEncryptionJavaKeyStoreProvider");
+ }
+
+ @Override
+ public byte[] decryptColumnEncryptionKey(String masterKeyPath, String encryptionAlgorithm,
+ byte[] encryptedColumnEncryptionKey) throws SQLServerException {
+ javaKeyStoreLogger.entering(SQLServerColumnEncryptionJavaKeyStoreProvider.class.getName(),
+ "decryptColumnEncryptionKey", "Decrypting Column Encryption Key.");
+
+ KeyStoreProviderCommon.validateNonEmptyMasterKeyPath(masterKeyPath);
+ CertificateDetails certificateDetails = getCertificateDetails(masterKeyPath);
+ byte[] plainCEK = KeyStoreProviderCommon.decryptColumnEncryptionKey(masterKeyPath, encryptionAlgorithm,
+ encryptedColumnEncryptionKey, certificateDetails);
+
+ javaKeyStoreLogger.exiting(SQLServerColumnEncryptionJavaKeyStoreProvider.class.getName(),
+ "decryptColumnEncryptionKey", "Finished decrypting Column Encryption Key.");
+ return plainCEK;
+ }
+
+ private CertificateDetails getCertificateDetails(String masterKeyPath) throws SQLServerException {
+ FileInputStream fis = null;
+ KeyStore keyStore = null;
+ CertificateDetails certificateDetails = null;
+
+ try {
+ if (null == masterKeyPath || 0 == masterKeyPath.length()) {
+ throw new SQLServerException(null, SQLServerException.getErrString("R_InvalidMasterKeyDetails"), null,
+ 0, false);
+ }
+
+ try {
+ // Try to load JKS first, if fails try PKCS12
+ keyStore = KeyStore.getInstance("JKS");
+ fis = new FileInputStream(keyStorePath);
+ keyStore.load(fis, keyStorePwd);
+ } catch (IOException e) {
+ if (null != fis)
+ fis.close();
+
+ // Loading as JKS failed, try to load as PKCS12
+ keyStore = KeyStore.getInstance("PKCS12");
+ fis = new FileInputStream(keyStorePath);
+ keyStore.load(fis, keyStorePwd);
+ }
+
+ certificateDetails = getCertificateDetailsByAlias(keyStore, masterKeyPath);
+ } catch (FileNotFoundException fileNotFound) {
+ throw new SQLServerException(this, SQLServerException.getErrString("R_KeyStoreNotFound"), null, 0, false);
+ } catch (IOException | CertificateException | NoSuchAlgorithmException | KeyStoreException e) {
+ MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidKeyStoreFile"));
+ Object[] msgArgs = {keyStorePath};
+ throw new SQLServerException(form.format(msgArgs), e);
+ } finally {
+ try {
+ if (null != fis)
+ fis.close();
+ }
+ // Ignore the exception as we are cleaning up.
+ catch (IOException e) {}
+ }
+
+ return certificateDetails;
+ }
+
+ private CertificateDetails getCertificateDetailsByAlias(KeyStore keyStore, String alias) throws SQLServerException {
+ try {
+ X509Certificate publicCertificate = (X509Certificate) keyStore.getCertificate(alias);
+ Key keyPrivate = keyStore.getKey(alias, keyStorePwd);
+ if (null == publicCertificate) {
+ // Certificate not found. Throw an exception.
+ MessageFormat form = new MessageFormat(
+ SQLServerException.getErrString("R_CertificateNotFoundForAlias"));
+ Object[] msgArgs = {alias, "MSSQL_JAVA_KEYSTORE"};
+ throw new SQLServerException(this, form.format(msgArgs), null, 0, false);
+ }
+
+ // found certificate but corresponding private key not found, throw exception
+ if (null == keyPrivate) {
+ throw new UnrecoverableKeyException();
+ }
+
+ return new CertificateDetails(publicCertificate, keyPrivate);
+ } catch (UnrecoverableKeyException unrecoverableKeyException) {
+
+ MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_UnrecoverableKeyAE"));
+ Object[] msgArgs = {alias};
+ throw new SQLServerException(this, form.format(msgArgs), null, 0, false);
+ } catch (NoSuchAlgorithmException | KeyStoreException e) {
+ MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_CertificateError"));
+ Object[] msgArgs = {alias, name};
+ throw new SQLServerException(form.format(msgArgs), e);
+ }
+ }
+
+ @Override
+ public byte[] encryptColumnEncryptionKey(String masterKeyPath, String encryptionAlgorithm,
+ byte[] plainTextColumnEncryptionKey) throws SQLServerException {
+ javaKeyStoreLogger.entering(SQLServerColumnEncryptionJavaKeyStoreProvider.class.getName(),
+ Thread.currentThread().getStackTrace()[1].getMethodName(), "Encrypting Column Encryption Key.");
+
+ byte[] version = KeyStoreProviderCommon.version;
+ KeyStoreProviderCommon.validateNonEmptyMasterKeyPath(masterKeyPath);
+
+ if (null == plainTextColumnEncryptionKey) {
+
+ throw new SQLServerException(null, SQLServerException.getErrString("R_NullColumnEncryptionKey"), null, 0,
+ false);
+
+ } else if (0 == plainTextColumnEncryptionKey.length) {
+
+ throw new SQLServerException(null, SQLServerException.getErrString("R_EmptyColumnEncryptionKey"), null, 0,
+ false);
+
+ }
+
+ KeyStoreProviderCommon.validateEncryptionAlgorithm(encryptionAlgorithm, true);
+
+ CertificateDetails certificateDetails = getCertificateDetails(masterKeyPath);
+ byte[] cipherText = encryptRSAOAEP(plainTextColumnEncryptionKey, certificateDetails);
+ byte[] cipherTextLength = getLittleEndianBytesFromShort((short) cipherText.length);
+ byte[] masterKeyPathBytes = masterKeyPath.toLowerCase().getBytes(UTF_16LE);
+
+ byte[] keyPathLength = getLittleEndianBytesFromShort((short) masterKeyPathBytes.length);
+
+ byte[] dataToSign = new byte[version.length + keyPathLength.length + cipherTextLength.length
+ + masterKeyPathBytes.length + cipherText.length];
+ int destinationPosition = version.length;
+ System.arraycopy(version, 0, dataToSign, 0, version.length);
+
+ System.arraycopy(keyPathLength, 0, dataToSign, destinationPosition, keyPathLength.length);
+ destinationPosition += keyPathLength.length;
+
+ System.arraycopy(cipherTextLength, 0, dataToSign, destinationPosition, cipherTextLength.length);
+ destinationPosition += cipherTextLength.length;
+
+ System.arraycopy(masterKeyPathBytes, 0, dataToSign, destinationPosition, masterKeyPathBytes.length);
+ destinationPosition += masterKeyPathBytes.length;
+
+ System.arraycopy(cipherText, 0, dataToSign, destinationPosition, cipherText.length);
+ byte[] signedHash = rsaSignHashedData(dataToSign, certificateDetails);
+
+ int encryptedColumnEncryptionKeyLength = version.length + cipherTextLength.length + keyPathLength.length
+ + cipherText.length + masterKeyPathBytes.length + signedHash.length;
+ byte[] encryptedColumnEncryptionKey = new byte[encryptedColumnEncryptionKeyLength];
+
+ int currentIndex = 0;
+ System.arraycopy(version, 0, encryptedColumnEncryptionKey, currentIndex, version.length);
+ currentIndex += version.length;
+
+ System.arraycopy(keyPathLength, 0, encryptedColumnEncryptionKey, currentIndex, keyPathLength.length);
+ currentIndex += keyPathLength.length;
+
+ System.arraycopy(cipherTextLength, 0, encryptedColumnEncryptionKey, currentIndex, cipherTextLength.length);
+ currentIndex += cipherTextLength.length;
+
+ System.arraycopy(masterKeyPathBytes, 0, encryptedColumnEncryptionKey, currentIndex, masterKeyPathBytes.length);
+ currentIndex += masterKeyPathBytes.length;
+
+ System.arraycopy(cipherText, 0, encryptedColumnEncryptionKey, currentIndex, cipherText.length);
+ currentIndex += cipherText.length;
+
+ System.arraycopy(signedHash, 0, encryptedColumnEncryptionKey, currentIndex, signedHash.length);
+
+ javaKeyStoreLogger.exiting(SQLServerColumnEncryptionJavaKeyStoreProvider.class.getName(),
+ Thread.currentThread().getStackTrace()[1].getMethodName(),
+ "Finished encrypting Column Encryption Key.");
+ return encryptedColumnEncryptionKey;
+
+ }
+
+ /**
+ * Encrypt plainText with the certificate provided.
+ *
+ * @param plainText
+ * plain CEK to be encrypted
+ * @param certificateDetails
+ * @return encrypted CEK
+ * @throws SQLServerException
+ */
+ private byte[] encryptRSAOAEP(byte[] plainText, CertificateDetails certificateDetails) throws SQLServerException {
+ byte[] cipherText = null;
+ try {
+ Cipher rsa = Cipher.getInstance("RSA/ECB/OAEPWithSHA-1AndMGF1Padding");
+ rsa.init(Cipher.ENCRYPT_MODE, certificateDetails.certificate.getPublicKey());
+ rsa.update(plainText);
+ cipherText = rsa.doFinal();
+ } catch (InvalidKeyException | NoSuchAlgorithmException | IllegalBlockSizeException | NoSuchPaddingException
+ | BadPaddingException e) {
+ MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_EncryptionFailed"));
+ Object[] msgArgs = {e.getMessage()};
+ throw new SQLServerException(this, form.format(msgArgs), null, 0, false);
+ }
+
+ return cipherText;
+
+ }
+
+ private byte[] rsaSignHashedData(byte[] dataToSign,
+ CertificateDetails certificateDetails) throws SQLServerException {
+ Signature signature;
+ byte[] signedHash = null;
+
+ try {
+ signature = Signature.getInstance("SHA256withRSA");
+ signature.initSign((PrivateKey) certificateDetails.privateKey);
+ signature.update(dataToSign);
+ signedHash = signature.sign();
+ } catch (InvalidKeyException | NoSuchAlgorithmException | SignatureException e) {
+ MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_EncryptionFailed"));
+ Object[] msgArgs = {e.getMessage()};
+ throw new SQLServerException(this, form.format(msgArgs), null, 0, false);
+
+ }
+ return signedHash;
+
+ }
+
+ private byte[] getLittleEndianBytesFromShort(short value) {
+ ByteBuffer byteBuffer = ByteBuffer.allocate(2);
+ byteBuffer.order(ByteOrder.LITTLE_ENDIAN);
+ byte[] byteValue = byteBuffer.putShort(value).array();
+ return byteValue;
+
+ }
+
+}
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerColumnEncryptionKeyStoreProvider.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerColumnEncryptionKeyStoreProvider.java
index 705f9d3bc..6fd8b845f 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerColumnEncryptionKeyStoreProvider.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerColumnEncryptionKeyStoreProvider.java
@@ -1,69 +1,65 @@
-/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
- */
-
-package com.microsoft.sqlserver.jdbc;
-
-/**
- *
- * Extend this class to implement a custom key store provider.
- *
- */
-public abstract class SQLServerColumnEncryptionKeyStoreProvider {
-
- /**
- * Sets the name of this key store provider.
- *
- * @param name
- * value to be set for the key store provider.
- */
- public abstract void setName(String name);
-
- /**
- * Retrieves the name of this key store provider.
- *
- * @return the name of this key store provider.
- */
- public abstract String getName();
-
- /**
- * Base class method for decrypting the specified encrypted value of a column encryption key. The encrypted value is expected to be encrypted
- * using the column master key with the specified key path and using the specified algorithm.
- *
- * @param masterKeyPath
- * The column master key path.
- * @param encryptionAlgorithm
- * the specific encryption algorithm.
- * @param encryptedColumnEncryptionKey
- * the encrypted column encryption key
- * @return the decrypted value of column encryption key.
- * @throws SQLServerException
- * when an error occurs while decrypting the CEK
- */
- public abstract byte[] decryptColumnEncryptionKey(String masterKeyPath,
- String encryptionAlgorithm,
- byte[] encryptedColumnEncryptionKey) throws SQLServerException;
-
- /**
- * Base class method for encrypting a column encryption key using the column master key with the specified key path and using the specified
- * algorithm.
- *
- * @param masterKeyPath
- * The column master key path.
- * @param encryptionAlgorithm
- * the specific encryption algorithm.
- * @param columnEncryptionKey
- * column encryption key to be encrypted.
- * @return the encrypted column encryption key.
- * @throws SQLServerException
- * when an error occurs while encrypting the CEK
- */
- public abstract byte[] encryptColumnEncryptionKey(String masterKeyPath,
- String encryptionAlgorithm,
- byte[] columnEncryptionKey) throws SQLServerException;
-
-}
+/*
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ */
+
+package com.microsoft.sqlserver.jdbc;
+
+/**
+ *
+ * Defines the abtract class for a SQL Server Column Encryption key store provider Extend this class to implement a
+ * custom key store provider.
+ *
+ */
+public abstract class SQLServerColumnEncryptionKeyStoreProvider {
+
+ /**
+ * Sets the name of this key store provider.
+ *
+ * @param name
+ * value to be set for the key store provider.
+ */
+ public abstract void setName(String name);
+
+ /**
+ * Returns the name of this key store provider.
+ *
+ * @return the name of this key store provider.
+ */
+ public abstract String getName();
+
+ /**
+ * Decrypts the specified encrypted value of a column encryption key. The encrypted value is expected to be
+ * encrypted using the column master key with the specified key path and using the specified algorithm.
+ *
+ * @param masterKeyPath
+ * The column master key path.
+ * @param encryptionAlgorithm
+ * the specific encryption algorithm.
+ * @param encryptedColumnEncryptionKey
+ * the encrypted column encryption key
+ * @return the decrypted value of column encryption key.
+ * @throws SQLServerException
+ * when an error occurs while decrypting the CEK
+ */
+ public abstract byte[] decryptColumnEncryptionKey(String masterKeyPath, String encryptionAlgorithm,
+ byte[] encryptedColumnEncryptionKey) throws SQLServerException;
+
+ /**
+ * Encrypts a column encryption key using the column master key with the specified key path and using the specified
+ * algorithm.
+ *
+ * @param masterKeyPath
+ * The column master key path.
+ * @param encryptionAlgorithm
+ * the specific encryption algorithm.
+ * @param columnEncryptionKey
+ * column encryption key to be encrypted.
+ * @return the encrypted column encryption key.
+ * @throws SQLServerException
+ * when an error occurs while encrypting the CEK
+ */
+ public abstract byte[] encryptColumnEncryptionKey(String masterKeyPath, String encryptionAlgorithm,
+ byte[] columnEncryptionKey) throws SQLServerException;
+
+}
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java
index 0c4b2bef9..18142be1d 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java
@@ -1,9 +1,6 @@
/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc;
@@ -47,59 +44,67 @@
import javax.sql.XAConnection;
import org.ietf.jgss.GSSCredential;
+
+import mssql.googlecode.cityhash.CityHash;
import mssql.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap;
import mssql.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap.Builder;
import mssql.googlecode.concurrentlinkedhashmap.EvictionListener;
+
/**
- * SQLServerConnection implements a JDBC connection to SQL Server. SQLServerConnections support JDBC connection pooling and may be either physical
- * JDBC connections or logical JDBC connections.
+ * Provides an implementation java.sql.connection interface that assists creating a JDBC connection to SQL Server.
+ * SQLServerConnections support JDBC connection pooling and may be either physical JDBC connections or logical JDBC
+ * connections.
*
- * SQLServerConnection manages transaction control for all statements that were created from it. SQLServerConnection may participate in XA distributed
- * transactions managed via an XAResource adapter.
+ * SQLServerConnection manages transaction control for all statements that were created from it. SQLServerConnection may
+ * participate in XA distributed transactions managed via an XAResource adapter.
*
- * SQLServerConnection instantiates a new TDSChannel object for use by itself and all statement objects that are created under this connection.
- * SQLServerConnection is thread safe.
+ * SQLServerConnection instantiates a new TDSChannel object for use by itself and all statement objects that are created
+ * under this connection. SQLServerConnection is thread safe.
*
- * SQLServerConnection manages a pool of prepared statement handles. Prepared statements are prepared once and typically executed many times with
- * different data values for their parameters. Prepared statements are also maintained across logical (pooled) connection closes.
+ * SQLServerConnection manages a pool of prepared statement handles. Prepared statements are prepared once and typically
+ * executed many times with different data values for their parameters. Prepared statements are also maintained across
+ * logical (pooled) connection closes.
*
- * SQLServerConnection is not thread safe, however multiple statements created from a single connection can be processing simultaneously in concurrent
- * threads.
+ * SQLServerConnection is not thread safe, however multiple statements created from a single connection can be
+ * processing simultaneously in concurrent threads.
*
* This class's public functions need to be kept identical to the SQLServerConnectionPoolProxy's.
*
- * The API javadoc for JDBC API methods that this class implements are not repeated here. Please see Sun's JDBC API interfaces javadoc for those
- * details.
+ * The API javadoc for JDBC API methods that this class implements are not repeated here. Please see Sun's JDBC API
+ * interfaces javadoc for those details.
+ *
+ * NOTE: All the public functions in this class also need to be defined in SQLServerConnectionPoolProxy Declare all new
+ * custom (non-static) Public APIs in ISQLServerConnection interface such that they can also be implemented by
+ * SQLServerConnectionPoolProxy
*/
-
-// NOTE: All the public functions in this class also need to be defined in SQLServerConnectionPoolProxy
-// Declare all new custom (non-static) Public APIs in ISQLServerConnection interface such that they can also be implemented by
-// SQLServerConnectionPoolProxy
public class SQLServerConnection implements ISQLServerConnection, java.io.Serializable {
/**
- * Always refresh SerialVersionUID when prompted
- */
- private static final long serialVersionUID = 1965647556064751510L;
-
- long timerExpire;
+ * Always refresh SerialVersionUID when prompted
+ */
+ private static final long serialVersionUID = 1965647556064751510L;
+
+ long timerExpire;
boolean attemptRefreshTokenLocked = false;
// Thresholds related to when prepared statement handles are cleaned-up. 1 == immediately.
/**
* The default for the prepared statement clean-up action threshold (i.e. when sp_unprepare is called).
*/
- static final int DEFAULT_SERVER_PREPARED_STATEMENT_DISCARD_THRESHOLD = 10; // Used to set the initial default, can be changed later.
+ static final int DEFAULT_SERVER_PREPARED_STATEMENT_DISCARD_THRESHOLD = 10; // Used to set the initial default, can
+ // be changed later.
private int serverPreparedStatementDiscardThreshold = -1; // Current limit for this particular connection.
/**
- * The default for if prepared statements should execute sp_executesql before following the prepare, unprepare pattern.
+ * The default for if prepared statements should execute sp_executesql before following the prepare, unprepare
+ * pattern.
+ *
+ * Used to set the initial default, can be changed later. false == use sp_executesql -> sp_prepexec -> sp_execute ->
+ * batched -> sp_unprepare pattern, true == skip sp_executesql part of pattern.
*/
- static final boolean DEFAULT_ENABLE_PREPARE_ON_FIRST_PREPARED_STATEMENT_CALL = false; // Used to set the initial default, can be changed later.
- // false == use sp_executesql -> sp_prepexec -> sp_execute
- // -> batched -> sp_unprepare pattern, true == skip
- // sp_executesql part of pattern.
+ static final boolean DEFAULT_ENABLE_PREPARE_ON_FIRST_PREPARED_STATEMENT_CALL = false;
+
private Boolean enablePrepareOnFirstPreparedStatementCall = null; // Current limit for this particular connection.
// Handle the actual queue of discarded prepared statements.
@@ -109,7 +114,9 @@ public class SQLServerConnection implements ISQLServerConnection, java.io.Serial
private boolean fedAuthRequiredByUser = false;
private boolean fedAuthRequiredPreLoginResponse = false;
private boolean federatedAuthenticationRequested = false;
- private boolean federatedAuthenticationInfoRequested = false; // Keep this distinct from _federatedAuthenticationRequested, since some fedauth
+ private boolean federatedAuthenticationInfoRequested = false; // Keep this distinct from
+ // _federatedAuthenticationRequested, since some
+ // fedauth
// library types may not need more info
private FederatedAuthenticationFeatureExtensionData fedAuthFeatureExtensionData = null;
@@ -119,50 +126,50 @@ public class SQLServerConnection implements ISQLServerConnection, java.io.Serial
private SqlFedAuthToken fedAuthToken = null;
private String originalHostNameInCertificate = null;
-
+
private Boolean isAzureDW = null;
- static class Sha1HashKey implements java.io.Serializable {
+ static class CityHash128Key implements java.io.Serializable {
/**
* Always refresh SerialVersionUID when prompted
*/
private static final long serialVersionUID = 166788428640603097L;
- private byte[] bytes;
+ String unhashedString;
+ private long[] segments;
+ private int hashCode;
- Sha1HashKey(String sql,
- String parametersDefinition) {
- this(String.format("%s%s", sql, parametersDefinition));
+ CityHash128Key(String sql, String parametersDefinition) {
+ this(sql + parametersDefinition);
}
- Sha1HashKey(String s) {
- bytes = getSha1Digest().digest(s.getBytes());
+ @SuppressWarnings("deprecation")
+ CityHash128Key(String s) {
+ unhashedString = s;
+ byte[] bytes = new byte[s.length()];
+ s.getBytes(0, s.length(), bytes, 0);
+ segments = CityHash.cityHash128(bytes, 0, bytes.length);
}
public boolean equals(Object obj) {
- if (!(obj instanceof Sha1HashKey))
+ if (!(obj instanceof CityHash128Key))
return false;
- return java.util.Arrays.equals(bytes, ((Sha1HashKey) obj).bytes);
+ return (java.util.Arrays.equals(segments, ((CityHash128Key) obj).segments)// checks if hash is equal,
+ // short-circuitting;
+ && this.unhashedString.equals(((CityHash128Key) obj).unhashedString));// checks if string is equal
}
public int hashCode() {
- return java.util.Arrays.hashCode(bytes);
- }
-
- private java.security.MessageDigest getSha1Digest() {
- try {
- return java.security.MessageDigest.getInstance("SHA-1");
- }
- catch (final java.security.NoSuchAlgorithmException e) {
- // This is not theoretically possible, but we're forced to catch it anyway
- throw new RuntimeException(e);
+ if (0 == hashCode) {
+ hashCode = java.util.Arrays.hashCode(segments);
}
+ return hashCode;
}
}
/**
- * Used to keep track of an individual prepared statement handle.
+ * Keeps track of an individual prepared statement handle.
*/
class PreparedStatementHandle {
private int handle = 0;
@@ -170,12 +177,9 @@ class PreparedStatementHandle {
private boolean isDirectSql;
private volatile boolean evictedFromCache;
private volatile boolean explicitlyDiscarded;
- private Sha1HashKey key;
+ private CityHash128Key key;
- PreparedStatementHandle(Sha1HashKey key,
- int handle,
- boolean isDirectSql,
- boolean isEvictedFromCache) {
+ PreparedStatementHandle(CityHash128Key key, int handle, boolean isDirectSql, boolean isEvictedFromCache) {
this.key = key;
this.handle = handle;
this.isDirectSql = isDirectSql;
@@ -205,13 +209,13 @@ private boolean isExplicitlyDiscarded() {
return explicitlyDiscarded;
}
- /** Get the actual handle. */
+ /** Returns the actual handle. */
int getHandle() {
return handle;
}
- /** Get the cache key. */
- Sha1HashKey getKey() {
+ /** Returns the cache key. */
+ CityHash128Key getKey() {
return key;
}
@@ -220,9 +224,10 @@ boolean isDirectSql() {
}
/**
- * Make sure handle cannot be re-used.
+ * Makes sure handle cannot be re-used.
*
- * @return false: Handle could not be discarded, it is in use. true: Handle was successfully put on path for discarding.
+ * @return false: Handle could not be discarded, it is in use. true: Handle was successfully put on path for
+ * discarding.
*/
private boolean tryDiscardHandle() {
return handleRefCount.compareAndSet(0, -999);
@@ -236,8 +241,8 @@ private boolean isDiscarded() {
/**
* Adds a new reference to this handle, i.e. re-using it.
*
- * @return false: Reference could not be added, statement has been discarded or does not have a handle associated with it. true: Reference was
- * successfully added.
+ * @return false: Reference could not be added, statement has been discarded or does not have a handle
+ * associated with it. true: Reference was successfully added.
*/
boolean tryAddReference() {
if (isDiscarded() || isExplicitlyDiscarded())
@@ -258,28 +263,29 @@ void removeReference() {
static final private int PARSED_SQL_CACHE_SIZE = 100;
/** Cache of parsed SQL meta data */
- static private ConcurrentLinkedHashMap parsedSQLCache;
+ static private ConcurrentLinkedHashMap parsedSQLCache;
static {
- parsedSQLCache = new Builder().maximumWeightedCapacity(PARSED_SQL_CACHE_SIZE).build();
+ parsedSQLCache = new Builder()
+ .maximumWeightedCapacity(PARSED_SQL_CACHE_SIZE).build();
}
- /** Get prepared statement cache entry if exists, if not parse and create a new one */
- static ParsedSQLCacheItem getCachedParsedSQL(Sha1HashKey key) {
+ /** Returns prepared statement cache entry if exists, if not parse and create a new one */
+ static ParsedSQLCacheItem getCachedParsedSQL(CityHash128Key key) {
return parsedSQLCache.get(key);
}
- /** Parse and create a information about parsed SQL text */
- static ParsedSQLCacheItem parseAndCacheSQL(Sha1HashKey key,
- String sql) throws SQLServerException {
+ /** Parses and create a information about parsed SQL text */
+ static ParsedSQLCacheItem parseAndCacheSQL(CityHash128Key key, String sql) throws SQLServerException {
JDBCSyntaxTranslator translator = new JDBCSyntaxTranslator();
String parsedSql = translator.translate(sql);
String procName = translator.getProcedureName(); // may return null
boolean returnValueSyntax = translator.hasReturnValueSyntax();
- int paramCount = countParams(parsedSql);
+ int[] parameterPositions = locateParams(parsedSql);
- ParsedSQLCacheItem cacheItem = new ParsedSQLCacheItem(parsedSql, paramCount, procName, returnValueSyntax);
+ ParsedSQLCacheItem cacheItem = new ParsedSQLCacheItem(parsedSql, parameterPositions, procName,
+ returnValueSyntax);
parsedSQLCache.putIfAbsent(key, cacheItem);
return cacheItem;
}
@@ -291,30 +297,31 @@ static ParsedSQLCacheItem parseAndCacheSQL(Sha1HashKey key,
private int statementPoolingCacheSize = DEFAULT_STATEMENT_POOLING_CACHE_SIZE;
/** Cache of prepared statement handles */
- private ConcurrentLinkedHashMap preparedStatementHandleCache;
+ private ConcurrentLinkedHashMap preparedStatementHandleCache;
/** Cache of prepared statement parameter metadata */
- private ConcurrentLinkedHashMap parameterMetadataCache;
+ private ConcurrentLinkedHashMap parameterMetadataCache;
/**
* Checks whether statement pooling is enabled or disabled. The default is set to true;
*/
private boolean disableStatementPooling = true;
/**
- * Find statement parameters.
+ * Locates statement parameters.
*
* @param sql
- * SQL text to parse for number of parameters to intialize.
+ * SQL text to parse for positions of parameters to intialize.
*/
- private static int countParams(String sql) {
- int nParams = 0;
+ private static int[] locateParams(String sql) {
+ LinkedList parameterPositions = new LinkedList<>();
- // Figure out the expected number of parameters by counting the
- // parameter placeholders in the SQL string.
+ // Locate the parameter placeholders in the SQL string.
int offset = -1;
- while ((offset = ParameterUtils.scanSQLForChar('?', sql, ++offset)) < sql.length())
- ++nParams;
+ while ((offset = ParameterUtils.scanSQLForChar('?', sql, ++offset)) < sql.length()) {
+ parameterPositions.add(offset);
+ }
- return nParams;
+ // return as int[]
+ return parameterPositions.stream().mapToInt(Integer::valueOf).toArray();
}
SqlFedAuthToken getAuthenticationResult() {
@@ -322,7 +329,7 @@ SqlFedAuthToken getAuthenticationResult() {
}
/**
- * Struct encapsulating the data to be sent to the server as part of Federated Authentication Feature Extension.
+ * Encapsulates the data to be sent to the server as part of Federated Authentication Feature Extension.
*/
class FederatedAuthenticationFeatureExtensionData {
boolean fedAuthRequiredPreLoginResponse;
@@ -330,8 +337,7 @@ class FederatedAuthenticationFeatureExtensionData {
byte[] accessToken = null;
SqlAuthentication authentication = null;
- FederatedAuthenticationFeatureExtensionData(int libraryType,
- String authenticationString,
+ FederatedAuthenticationFeatureExtensionData(int libraryType, String authenticationString,
boolean fedAuthRequiredPreLoginResponse) throws SQLServerException {
this.libraryType = libraryType;
this.fedAuthRequiredPreLoginResponse = fedAuthRequiredPreLoginResponse;
@@ -345,14 +351,14 @@ class FederatedAuthenticationFeatureExtensionData {
break;
default:
assert (false);
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_InvalidConnectionSetting"));
+ MessageFormat form = new MessageFormat(
+ SQLServerException.getErrString("R_InvalidConnectionSetting"));
Object[] msgArgs = {"authentication", authenticationString};
throw new SQLServerException(null, form.format(msgArgs), null, 0, false);
}
}
- FederatedAuthenticationFeatureExtensionData(int libraryType,
- boolean fedAuthRequiredPreLoginResponse,
+ FederatedAuthenticationFeatureExtensionData(int libraryType, boolean fedAuthRequiredPreLoginResponse,
byte[] accessToken) {
this.libraryType = libraryType;
this.fedAuthRequiredPreLoginResponse = fedAuthRequiredPreLoginResponse;
@@ -380,22 +386,24 @@ class ActiveDirectoryAuthentication {
}
/**
- * denotes the state of the SqlServerConnection
+ * Denotes the state of the SqlServerConnection.
*/
private enum State {
- Initialized,// default value on calling SQLServerConnection constructor
- Connected, // indicates that the TCP connection has completed
- Opened, // indicates that the prelogin, login have completed, the database session established and the connection is ready for use.
- Closed // indicates that the connection has been closed.
+ Initialized, // default value on calling SQLServerConnection constructor
+ Connected, // indicates that the TCP connection has completed
+ Opened, // indicates that the prelogin, login have completed, the database session established and the
+ // connection is ready for use.
+ Closed // indicates that the connection has been closed.
}
- private final static float TIMEOUTSTEP = 0.08F; // fraction of timeout to use for fast failover connections
+ private final static float TIMEOUTSTEP = 0.08F; // fraction of timeout to use for fast failover connections
private final static float TIMEOUTSTEP_TNIR = 0.125F;
- final static int TnirFirstAttemptTimeoutMs = 500; // fraction of timeout to use for fast failover connections
+ final static int TnirFirstAttemptTimeoutMs = 500; // fraction of timeout to use for fast failover connections
/*
- * Connection state variables. NB If new state is added then logical connections derived from a physical connection must inherit the same state.
- * If state variables are added they must be added also in connection cloning method clone()
+ * Connection state variables. NB If new state is added then logical connections derived from a physical connection
+ * must inherit the same state. If state variables are added they must be added also in connection cloning method
+ * clone()
*/
private final static int INTERMITTENT_TLS_MAX_RETRY = 5;
@@ -415,7 +423,8 @@ ServerPortPlaceHolder getRoutingInfo() {
private static final String SET_NETWORK_TIMEOUT_PERM = "setNetworkTimeout";
// see connection properties doc (default is false).
- private boolean sendStringParametersAsUnicode = SQLServerDriverBooleanProperty.SEND_STRING_PARAMETERS_AS_UNICODE.getDefaultValue();
+ private boolean sendStringParametersAsUnicode = SQLServerDriverBooleanProperty.SEND_STRING_PARAMETERS_AS_UNICODE
+ .getDefaultValue();
private String hostName = null;
@@ -429,7 +438,8 @@ final boolean useLastUpdateCount() {
return lastUpdateCount;
}
- // Translates the serverName from Unicode to ASCII Compatible Encoding (ACE), as defined by the ToASCII operation of RFC 3490
+ // Translates the serverName from Unicode to ASCII Compatible Encoding (ACE), as defined by the ToASCII operation of
+ // RFC 3490
private boolean serverNameAsACE = SQLServerDriverBooleanProperty.SERVER_NAME_AS_ACE.getDefaultValue();
boolean serverNameAsACE() {
@@ -455,8 +465,8 @@ final ApplicationIntent getApplicationIntent() {
return applicationIntent;
}
- private int nLockTimeout; // see connection properties doc
- private String selectMethod; // see connection properties doc 4.0 new property
+ private int nLockTimeout; // see connection properties doc
+ private String selectMethod; // see connection properties doc 4.0 new property
final String getSelectMethod() {
return selectMethod;
@@ -475,12 +485,12 @@ final int getQueryTimeoutSeconds() {
}
/**
- * timeout value for canceling the query timeout
+ * Timeout value for canceling the query timeout.
*/
private int cancelQueryTimeoutSeconds;
/**
- * Retrieves the cancelTimeout in seconds
+ * Returns the cancelTimeout in seconds.
*
* @return
*/
@@ -493,34 +503,37 @@ final int getCancelQueryTimeoutSeconds() {
final int getSocketTimeoutMilliseconds() {
return socketTimeoutMilliseconds;
}
-
+
/**
- * boolean value for deciding if the driver should use bulk copy API for batch inserts
+ * boolean value for deciding if the driver should use bulk copy API for batch inserts.
*/
private boolean useBulkCopyForBatchInsert;
/**
- * Retrieves the useBulkCopyForBatchInsert value.
+ * Returns the useBulkCopyForBatchInsert value.
+ *
* @return flag for using Bulk Copy API for batch insert operations.
*/
public boolean getUseBulkCopyForBatchInsert() {
return useBulkCopyForBatchInsert;
}
-
+
/**
* Specifies the flag for using Bulk Copy API for batch insert operations.
- * @param useBulkCopyForBatchInsert boolean value for useBulkCopyForBatchInsert.
+ *
+ * @param useBulkCopyForBatchInsert
+ * boolean value for useBulkCopyForBatchInsert.
*/
public void setUseBulkCopyForBatchInsert(boolean useBulkCopyForBatchInsert) {
this.useBulkCopyForBatchInsert = useBulkCopyForBatchInsert;
}
-
+
boolean userSetTNIR = true;
private boolean sendTimeAsDatetime = SQLServerDriverBooleanProperty.SEND_TIME_AS_DATETIME.getDefaultValue();
@Override
- public synchronized final boolean getSendTimeAsDatetime() {
+ public final boolean getSendTimeAsDatetime() {
return !isKatmaiOrLater() || sendTimeAsDatetime;
}
@@ -584,7 +597,7 @@ boolean getServerSupportsColumnEncryption() {
boolean getServerSupportsDataClassification() {
return serverSupportsDataClassification;
}
-
+
static boolean isWindows;
static Map globalSystemColumnEncryptionKeyStoreProviders = new HashMap<>();
static {
@@ -592,8 +605,7 @@ boolean getServerSupportsDataClassification() {
isWindows = true;
SQLServerColumnEncryptionCertificateStoreProvider provider = new SQLServerColumnEncryptionCertificateStoreProvider();
globalSystemColumnEncryptionKeyStoreProviders.put(provider.getName(), provider);
- }
- else {
+ } else {
isWindows = false;
}
}
@@ -605,9 +617,9 @@ boolean getServerSupportsDataClassification() {
* Registers key store providers in the globalCustomColumnEncryptionKeyStoreProviders.
*
* @param clientKeyStoreProviders
- * a map containing the store providers information.
+ * a map containing the store providers information.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
public static synchronized void registerColumnEncryptionKeyStoreProviders(
Map clientKeyStoreProviders) throws SQLServerException {
@@ -615,11 +627,13 @@ public static synchronized void registerColumnEncryptionKeyStoreProviders(
"Registering Column Encryption Key Store Providers");
if (null == clientKeyStoreProviders) {
- throw new SQLServerException(null, SQLServerException.getErrString("R_CustomKeyStoreProviderMapNull"), null, 0, false);
+ throw new SQLServerException(null, SQLServerException.getErrString("R_CustomKeyStoreProviderMapNull"), null,
+ 0, false);
}
if (null != globalCustomColumnEncryptionKeyStoreProviders) {
- throw new SQLServerException(null, SQLServerException.getErrString("R_CustomKeyStoreProviderSetOnce"), null, 0, false);
+ throw new SQLServerException(null, SQLServerException.getErrString("R_CustomKeyStoreProviderSetOnce"), null,
+ 0, false);
}
globalCustomColumnEncryptionKeyStoreProviders = new HashMap<>();
@@ -627,15 +641,18 @@ public static synchronized void registerColumnEncryptionKeyStoreProviders(
for (Map.Entry entry : clientKeyStoreProviders.entrySet()) {
String providerName = entry.getKey();
if (null == providerName || 0 == providerName.length()) {
- throw new SQLServerException(null, SQLServerException.getErrString("R_EmptyCustomKeyStoreProviderName"), null, 0, false);
+ throw new SQLServerException(null, SQLServerException.getErrString("R_EmptyCustomKeyStoreProviderName"),
+ null, 0, false);
}
if ((providerName.substring(0, 6).equalsIgnoreCase(RESERVED_PROVIDER_NAME_PREFIX))) {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_InvalidCustomKeyStoreProviderName"));
+ MessageFormat form = new MessageFormat(
+ SQLServerException.getErrString("R_InvalidCustomKeyStoreProviderName"));
Object[] msgArgs = {providerName, RESERVED_PROVIDER_NAME_PREFIX};
throw new SQLServerException(null, form.format(msgArgs), null, 0, false);
}
if (null == entry.getValue()) {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_CustomKeyStoreProviderValueNull"));
+ MessageFormat form = new MessageFormat(
+ SQLServerException.getErrString("R_CustomKeyStoreProviderValueNull"));
Object[] msgArgs = {providerName, RESERVED_PROVIDER_NAME_PREFIX};
throw new SQLServerException(null, form.format(msgArgs), null, 0, false);
}
@@ -643,11 +660,14 @@ public static synchronized void registerColumnEncryptionKeyStoreProviders(
}
loggerExternal.exiting(SQLServerConnection.class.getName(), "registerColumnEncryptionKeyStoreProviders",
- "Number of Key store providers that are registered:" + globalCustomColumnEncryptionKeyStoreProviders.size());
+ "Number of Key store providers that are registered:"
+ + globalCustomColumnEncryptionKeyStoreProviders.size());
}
- static synchronized SQLServerColumnEncryptionKeyStoreProvider getGlobalSystemColumnEncryptionKeyStoreProvider(String providerName) {
- if (null != globalSystemColumnEncryptionKeyStoreProviders && globalSystemColumnEncryptionKeyStoreProviders.containsKey(providerName)) {
+ static synchronized SQLServerColumnEncryptionKeyStoreProvider getGlobalSystemColumnEncryptionKeyStoreProvider(
+ String providerName) {
+ if (null != globalSystemColumnEncryptionKeyStoreProviders
+ && globalSystemColumnEncryptionKeyStoreProviders.containsKey(providerName)) {
return globalSystemColumnEncryptionKeyStoreProviders.get(providerName);
}
return null;
@@ -669,18 +689,21 @@ synchronized String getAllSystemColumnEncryptionKeyStoreProviders() {
return keyStores;
}
- static synchronized SQLServerColumnEncryptionKeyStoreProvider getGlobalCustomColumnEncryptionKeyStoreProvider(String providerName) {
- if (null != globalCustomColumnEncryptionKeyStoreProviders && globalCustomColumnEncryptionKeyStoreProviders.containsKey(providerName)) {
+ static synchronized SQLServerColumnEncryptionKeyStoreProvider getGlobalCustomColumnEncryptionKeyStoreProvider(
+ String providerName) {
+ if (null != globalCustomColumnEncryptionKeyStoreProviders
+ && globalCustomColumnEncryptionKeyStoreProviders.containsKey(providerName)) {
return globalCustomColumnEncryptionKeyStoreProviders.get(providerName);
}
return null;
}
- synchronized SQLServerColumnEncryptionKeyStoreProvider getSystemColumnEncryptionKeyStoreProvider(String providerName) {
- if ((null != systemColumnEncryptionKeyStoreProvider) && (systemColumnEncryptionKeyStoreProvider.containsKey(providerName))) {
+ synchronized SQLServerColumnEncryptionKeyStoreProvider getSystemColumnEncryptionKeyStoreProvider(
+ String providerName) {
+ if ((null != systemColumnEncryptionKeyStoreProvider)
+ && (systemColumnEncryptionKeyStoreProvider.containsKey(providerName))) {
return systemColumnEncryptionKeyStoreProvider.get(providerName);
- }
- else {
+ } else {
return null;
}
}
@@ -692,10 +715,12 @@ synchronized SQLServerColumnEncryptionKeyStoreProvider getSystemColumnEncryption
* Sets Trusted Master Key Paths in the columnEncryptionTrustedMasterKeyPaths.
*
* @param trustedKeyPaths
- * all master key paths that are trusted
+ * all master key paths that are trusted
*/
- public static synchronized void setColumnEncryptionTrustedMasterKeyPaths(Map> trustedKeyPaths) {
- loggerExternal.entering(SQLServerConnection.class.getName(), "setColumnEncryptionTrustedMasterKeyPaths", "Setting Trusted Master Key Paths");
+ public static synchronized void setColumnEncryptionTrustedMasterKeyPaths(
+ Map> trustedKeyPaths) {
+ loggerExternal.entering(SQLServerConnection.class.getName(), "setColumnEncryptionTrustedMasterKeyPaths",
+ "Setting Trusted Master Key Paths");
// Use upper case for server and instance names.
columnEncryptionTrustedMasterKeyPaths.clear();
@@ -711,9 +736,9 @@ public static synchronized void setColumnEncryptionTrustedMasterKeyPaths(Map trustedKeyPaths) {
@@ -731,7 +756,7 @@ public static synchronized void updateColumnEncryptionTrustedMasterKeyPaths(Stri
* Removes the trusted Master key Path from the columnEncryptionTrustedMasterKeyPaths.
*
* @param server
- * String server name
+ * String server name
*/
public static synchronized void removeColumnEncryptionTrustedMasterKeyPaths(String server) {
loggerExternal.entering(SQLServerConnection.class.getName(), "removeColumnEncryptionTrustedMasterKeyPaths",
@@ -745,12 +770,13 @@ public static synchronized void removeColumnEncryptionTrustedMasterKeyPaths(Stri
}
/**
- * Retrieves the Trusted Master Key Paths.
+ * Returns the Trusted Master Key Paths.
*
* @return columnEncryptionTrustedMasterKeyPaths.
*/
public static synchronized Map> getColumnEncryptionTrustedMasterKeyPaths() {
- loggerExternal.entering(SQLServerConnection.class.getName(), "getColumnEncryptionTrustedMasterKeyPaths", "Getting Trusted Master Key Paths");
+ loggerExternal.entering(SQLServerConnection.class.getName(), "getColumnEncryptionTrustedMasterKeyPaths",
+ "Getting Trusted Master Key Paths");
Map> masterKeyPathCopy = new HashMap<>();
@@ -764,13 +790,11 @@ public static synchronized Map> getColumnEncryptionTrustedM
return masterKeyPathCopy;
}
- static synchronized List getColumnEncryptionTrustedMasterKeyPaths(String server,
- Boolean[] hasEntry) {
+ static synchronized List getColumnEncryptionTrustedMasterKeyPaths(String server, Boolean[] hasEntry) {
if (columnEncryptionTrustedMasterKeyPaths.containsKey(server)) {
hasEntry[0] = true;
return columnEncryptionTrustedMasterKeyPaths.get(server);
- }
- else {
+ } else {
hasEntry[0] = false;
return null;
}
@@ -784,8 +808,8 @@ static synchronized List getColumnEncryptionTrustedMasterKeyPaths(String
// This is the current connect place holder this should point one of the primary or failover place holder
ServerPortPlaceHolder currentConnectPlaceHolder = null;
- String sqlServerVersion; // SQL Server version string
- boolean xopenStates; // XOPEN or SQL 92 state codes?
+ String sqlServerVersion; // SQL Server version string
+ boolean xopenStates; // XOPEN or SQL 92 state codes?
private boolean databaseAutoCommitMode;
private boolean inXATransaction = false; // Set to true when in an XA transaction.
private byte[] transactionDescriptor = new byte[8];
@@ -798,7 +822,7 @@ final boolean rolledBackTransaction() {
return rolledBackTransaction;
}
- private State state = State.Initialized; // connection state
+ private State state = State.Initialized; // connection state
private void setState(State state) {
this.state = state;
@@ -811,7 +835,7 @@ final boolean isSessionUnAvailable() {
return !(state.equals(State.Opened));
}
- final static int maxDecimalPrecision = 38; // @@max_precision for SQL 2000 and 2005 is 38.
+ final static int maxDecimalPrecision = 38; // @@max_precision for SQL 2000 and 2005 is 38.
final static int defaultDecimalPrecision = 18;
final String traceID;
@@ -835,7 +859,7 @@ final void setMaxFieldSize(int limit) throws SQLServerException {
final void initResettableValues() {
rolledBackTransaction = false;
transactionIsolationLevel = Connection.TRANSACTION_READ_COMMITTED;// default isolation level
- maxFieldSize = 0; // default: 0 --> no limit
+ maxFieldSize = 0; // default: 0 --> no limit
maxRows = 0; // default: 0 --> no limit
nLockTimeout = -1;
databaseAutoCommitMode = true;// auto commit mode
@@ -859,26 +883,27 @@ final void setMaxRows(int limit) throws SQLServerException {
}
}
- private SQLCollation databaseCollation; // Default database collation read from ENVCHANGE_SQLCOLLATION token.
+ private SQLCollation databaseCollation; // Default database collation read from ENVCHANGE_SQLCOLLATION token.
final SQLCollation getDatabaseCollation() {
return databaseCollation;
}
- static private final AtomicInteger baseConnectionID = new AtomicInteger(0); // connection id dispenser
+ static private final AtomicInteger baseConnectionID = new AtomicInteger(0); // connection id dispenser
// This is the current catalog
- private String sCatalog = "master"; // the database catalog
+ private String sCatalog = "master"; // the database catalog
// This is the catalog immediately after login.
private String originalCatalog = "master";
private int transactionIsolationLevel;
private SQLServerPooledConnection pooledConnectionParent;
private DatabaseMetaData databaseMetaData; // the meta data for this connection
- private int nNextSavePointId = 10000; // first save point id
+ private int nNextSavePointId = 10000; // first save point id
static final private java.util.logging.Logger connectionlogger = java.util.logging.Logger
.getLogger("com.microsoft.sqlserver.jdbc.internals.SQLServerConnection");
- static final private java.util.logging.Logger loggerExternal = java.util.logging.Logger.getLogger("com.microsoft.sqlserver.jdbc.Connection");
+ static final private java.util.logging.Logger loggerExternal = java.util.logging.Logger
+ .getLogger("com.microsoft.sqlserver.jdbc.Connection");
private final String loggingClassName;
// there are three ways to get a failover partner
@@ -948,7 +973,7 @@ final boolean attachConnId() {
@SuppressWarnings("unused")
SQLServerConnection(String parentInfo) throws SQLServerException {
- int connectionID = nextConnectionID(); // sequential connection id
+ int connectionID = nextConnectionID(); // sequential connection id
traceID = "ConnectionID:" + connectionID;
loggingClassName = "com.microsoft.sqlserver.jdbc.SQLServerConnection:" + connectionID;
if (connectionlogger.isLoggable(Level.FINE))
@@ -971,9 +996,9 @@ final void setAssociatedProxy(SQLServerConnectionPoolProxy proxy) {
}
/*
- * This function is used by the functions that return a connection object to outside world. E.g. stmt.getConnection, these functions should return
- * the proxy not the actual physical connection when the physical connection is pooled and the user should be accessing the connection functions
- * via the proxy object.
+ * Provides functionality to return a connection object to outside world. E.g. stmt.getConnection, these functions
+ * should return the proxy not the actual physical connection when the physical connection is pooled and the user
+ * should be accessing the connection functions via the proxy object.
*/
final Connection getConnection() {
if (null != proxy)
@@ -988,7 +1013,7 @@ final void resetPooledConnection() {
}
/**
- * Generate the next unique connection id.
+ * Generates the next unique connection id.
*
* @return the next conn id
*/
@@ -1005,7 +1030,7 @@ String getClassNameLogging() {
}
/**
- * This is a helper function to provide an ID string suitable for tracing.
+ * Provides a helper function to return an ID string suitable for tracing.
*/
@Override
public String toString() {
@@ -1016,13 +1041,15 @@ public String toString() {
}
/**
- * Check if the connection is closed Create a new connection if it's a fedauth connection and the access token is going to expire.
+ * Checks if the connection is closed Create a new connection if it's a fedauth connection and the access token is
+ * going to expire.
*
* @throws SQLServerException
*/
void checkClosed() throws SQLServerException {
if (isSessionUnAvailable()) {
- SQLServerException.makeFromDriverError(null, null, SQLServerException.getErrString("R_connectionIsClosed"), null, false);
+ SQLServerException.makeFromDriverError(null, null, SQLServerException.getErrString("R_connectionIsClosed"),
+ null, false);
}
if (null != fedAuthToken) {
@@ -1033,20 +1060,19 @@ void checkClosed() throws SQLServerException {
}
/**
- * Check if a string property is enabled.
+ * Returns if a string property is enabled.
*
* @param propName
- * the string property name
+ * the string property name
* @param propValue
- * the string property value.
+ * the string property value.
* @return false if p == null (meaning take default).
* @return true if p == "true" (case-insensitive).
* @return false if p == "false" (case-insensitive).
* @exception SQLServerException
- * thrown if value is not recognized.
+ * thrown if value is not recognized.
*/
- private boolean booleanPropertyOn(String propName,
- String propValue) throws SQLServerException {
+ private boolean booleanPropertyOn(String propName, String propValue) throws SQLServerException {
// Null means take the default of false.
if (null == propValue)
return false;
@@ -1068,16 +1094,16 @@ private boolean booleanPropertyOn(String propName,
final static int MAX_SQL_LOGIN_NAME_WCHARS = 128;
/**
- * Validates propName against maximum allowed length MAX_SQL_LOGIN_NAME_WCHARS. Throws exception if name length exceeded.
+ * Validates propName against maximum allowed length MAX_SQL_LOGIN_NAME_WCHARS. Throws exception if name length
+ * exceeded.
*
* @param propName
- * the name of the property.
+ * the name of the property.
* @param propValue
- * the value of the property.
+ * the value of the property.
* @throws SQLServerException
*/
- void ValidateMaxSQLLoginName(String propName,
- String propValue) throws SQLServerException {
+ void ValidateMaxSQLLoginName(String propName, String propValue) throws SQLServerException {
if (propValue != null && propValue.length() > MAX_SQL_LOGIN_NAME_WCHARS) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_propertyMaximumExceedsChars"));
Object[] msgArgs = {propName, Integer.toString(MAX_SQL_LOGIN_NAME_WCHARS)};
@@ -1085,22 +1111,19 @@ void ValidateMaxSQLLoginName(String propName,
}
}
- Connection connect(Properties propsIn,
- SQLServerPooledConnection pooledConnection) throws SQLServerException {
+ Connection connect(Properties propsIn, SQLServerPooledConnection pooledConnection) throws SQLServerException {
int loginTimeoutSeconds = 0; // Will be set during the first retry attempt.
long start = System.currentTimeMillis();
for (int retryAttempt = 0;;) {
try {
return connectInternal(propsIn, pooledConnection);
- }
- catch (SQLServerException e) {
+ } catch (SQLServerException e) {
// Catch only the TLS 1.2 specific intermittent error.
if (SQLServerException.DRIVER_ERROR_INTERMITTENT_TLS_FAILED != e.getDriverErrorCode()) {
// Re-throw all other exceptions.
throw e;
- }
- else {
+ } else {
// Special handling of the retry logic for TLS 1.2 intermittent issue.
// If timeout is not set yet, set it once.
@@ -1108,8 +1131,9 @@ Connection connect(Properties propsIn,
// We do not need to check for exceptions here, as the connection properties are already
// verified during the first try. Also, we would like to do this calculation
// only for the TLS 1.2 exception case.
- loginTimeoutSeconds = SQLServerDriverIntProperty.LOGIN_TIMEOUT.getDefaultValue(); // if the user does not specify a default
- // timeout, default is 15 per spec
+ // if the user does not specify a default timeout, default is 15 per spec
+ loginTimeoutSeconds = SQLServerDriverIntProperty.LOGIN_TIMEOUT.getDefaultValue();
+
String sPropValue = propsIn.getProperty(SQLServerDriverIntProperty.LOGIN_TIMEOUT.toString());
if (null != sPropValue && sPropValue.length() > 0) {
int sPropValueInt = Integer.parseInt(sPropValue);
@@ -1125,19 +1149,18 @@ Connection connect(Properties propsIn,
if (INTERMITTENT_TLS_MAX_RETRY < retryAttempt) {
// Re-throw the exception if we have reached the maximum retry attempts.
if (connectionlogger.isLoggable(Level.FINE)) {
- connectionlogger.fine(
- "Connection failed during SSL handshake. Maximum retry attempt (" + INTERMITTENT_TLS_MAX_RETRY + ") reached. ");
+ connectionlogger.fine("Connection failed during SSL handshake. Maximum retry attempt ("
+ + INTERMITTENT_TLS_MAX_RETRY + ") reached. ");
}
throw e;
- }
- else if (elapsedSeconds >= loginTimeoutSeconds) {
+ } else if (elapsedSeconds >= loginTimeoutSeconds) {
// Re-throw the exception if we do not have any time left to retry.
if (connectionlogger.isLoggable(Level.FINE)) {
- connectionlogger.fine("Connection failed during SSL handshake. Not retrying as timeout expired.");
+ connectionlogger
+ .fine("Connection failed during SSL handshake. Not retrying as timeout expired.");
}
throw e;
- }
- else {
+ } else {
// Retry the connection.
if (connectionlogger.isLoggable(Level.FINE)) {
connectionlogger.fine(
@@ -1150,33 +1173,33 @@ else if (elapsedSeconds >= loginTimeoutSeconds) {
}
}
- private void registerKeyStoreProviderOnConnection(String keyStoreAuth,
- String keyStoreSecret,
+ private void registerKeyStoreProviderOnConnection(String keyStoreAuth, String keyStoreSecret,
String keyStoreLocation) throws SQLServerException {
if (null == keyStoreAuth) {
// secret and location must be null too.
if ((null != keyStoreSecret)) {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_keyStoreAuthenticationNotSet"));
+ MessageFormat form = new MessageFormat(
+ SQLServerException.getErrString("R_keyStoreAuthenticationNotSet"));
Object[] msgArgs = {"keyStoreSecret"};
throw new SQLServerException(form.format(msgArgs), null);
}
if (null != keyStoreLocation) {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_keyStoreAuthenticationNotSet"));
+ MessageFormat form = new MessageFormat(
+ SQLServerException.getErrString("R_keyStoreAuthenticationNotSet"));
Object[] msgArgs = {"keyStoreLocation"};
throw new SQLServerException(form.format(msgArgs), null);
}
- }
- else {
+ } else {
KeyStoreAuthentication keyStoreAuthentication = KeyStoreAuthentication.valueOfString(keyStoreAuth);
switch (keyStoreAuthentication) {
case JavaKeyStorePassword:
// both secret and location must be set for JKS.
if ((null == keyStoreSecret) || (null == keyStoreLocation)) {
- throw new SQLServerException(SQLServerException.getErrString("R_keyStoreSecretOrLocationNotSet"), null);
- }
- else {
- SQLServerColumnEncryptionJavaKeyStoreProvider provider = new SQLServerColumnEncryptionJavaKeyStoreProvider(keyStoreLocation,
- keyStoreSecret.toCharArray());
+ throw new SQLServerException(
+ SQLServerException.getErrString("R_keyStoreSecretOrLocationNotSet"), null);
+ } else {
+ SQLServerColumnEncryptionJavaKeyStoreProvider provider = new SQLServerColumnEncryptionJavaKeyStoreProvider(
+ keyStoreLocation, keyStoreSecret.toCharArray());
systemColumnEncryptionKeyStoreProvider.put(provider.getName(), provider);
}
break;
@@ -1189,12 +1212,13 @@ private void registerKeyStoreProviderOnConnection(String keyStoreAuth,
}
/**
- * Establish a physical database connection based on the user specified connection properties. Logon to the database.
+ * Establish a physical database connection based on the user specified connection properties. Logon to the
+ * database.
*
* @param propsIn
- * the connection properties
+ * the connection properties
* @param pooledConnection
- * a parent pooled connection if this is a logical connection
+ * a parent pooled connection if this is a logical connection
* @throws SQLServerException
* @return the database connection
*/
@@ -1205,11 +1229,13 @@ Connection connectInternal(Properties propsIn,
pooledConnectionParent = pooledConnection;
- String hostNameInCertificate = activeConnectionProperties.getProperty(SQLServerDriverStringProperty.HOSTNAME_IN_CERTIFICATE.toString());
+ String hostNameInCertificate = activeConnectionProperties
+ .getProperty(SQLServerDriverStringProperty.HOSTNAME_IN_CERTIFICATE.toString());
// hostNameInCertificate property can change when redirection is involved, so maintain this value
// for every instance of SQLServerConnection.
- if (null == originalHostNameInCertificate && null != hostNameInCertificate && !hostNameInCertificate.isEmpty()) {
+ if (null == originalHostNameInCertificate && null != hostNameInCertificate
+ && !hostNameInCertificate.isEmpty()) {
originalHostNameInCertificate = activeConnectionProperties
.getProperty(SQLServerDriverStringProperty.HOSTNAME_IN_CERTIFICATE.toString());
}
@@ -1220,7 +1246,7 @@ Connection connectInternal(Properties propsIn,
activeConnectionProperties.setProperty(SQLServerDriverStringProperty.HOSTNAME_IN_CERTIFICATE.toString(),
originalHostNameInCertificate);
}
-
+
String sPropKey;
String sPropValue;
@@ -1244,14 +1270,13 @@ Connection connectInternal(Properties propsIn,
sPropValue = activeConnectionProperties.getProperty(sPropKey);
ValidateMaxSQLLoginName(sPropKey, sPropValue);
- int loginTimeoutSeconds = SQLServerDriverIntProperty.LOGIN_TIMEOUT.getDefaultValue(); // if the user does not specify a default timeout,
- // default is 15 per spec
+ // if the user does not specify a default timeout, default is 15 per spec
+ int loginTimeoutSeconds = SQLServerDriverIntProperty.LOGIN_TIMEOUT.getDefaultValue();
sPropValue = activeConnectionProperties.getProperty(SQLServerDriverIntProperty.LOGIN_TIMEOUT.toString());
if (null != sPropValue && sPropValue.length() > 0) {
try {
loginTimeoutSeconds = Integer.parseInt(sPropValue);
- }
- catch (NumberFormatException e) {
+ } catch (NumberFormatException e) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidTimeOut"));
Object[] msgArgs = {sPropValue};
SQLServerException.makeFromDriverError(this, this, form.format(msgArgs), null, false);
@@ -1264,7 +1289,8 @@ Connection connectInternal(Properties propsIn,
}
}
- // Translates the serverName from Unicode to ASCII Compatible Encoding (ACE), as defined by the ToASCII operation of RFC 3490.
+ // Translates the serverName from Unicode to ASCII Compatible Encoding (ACE), as defined by the ToASCII
+ // operation of RFC 3490.
sPropKey = SQLServerDriverBooleanProperty.SERVER_NAME_AS_ACE.toString();
sPropValue = activeConnectionProperties.getProperty(sPropKey);
if (sPropValue == null) {
@@ -1301,9 +1327,9 @@ Connection connectInternal(Properties propsIn,
if (true == serverNameAsACE) {
try {
sPropValue = java.net.IDN.toASCII(sPropValue);
- }
- catch (IllegalArgumentException ex) {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_InvalidConnectionSetting"));
+ } catch (IllegalArgumentException ex) {
+ MessageFormat form = new MessageFormat(
+ SQLServerException.getErrString("R_InvalidConnectionSetting"));
Object[] msgArgs = {"serverNameAsACE", sPropValue};
throw new SQLServerException(form.format(msgArgs), ex);
}
@@ -1380,7 +1406,8 @@ Connection connectInternal(Properties propsIn,
sPropValue = activeConnectionProperties.getProperty(sPropKey);
if (sPropValue == null) {
userSetTNIR = false;
- sPropValue = Boolean.toString(SQLServerDriverBooleanProperty.TRANSPARENT_NETWORK_IP_RESOLUTION.getDefaultValue());
+ sPropValue = Boolean
+ .toString(SQLServerDriverBooleanProperty.TRANSPARENT_NETWORK_IP_RESOLUTION.getDefaultValue());
activeConnectionProperties.setProperty(sPropKey, sPropValue);
}
transparentNetworkIPResolution = booleanPropertyOn(sPropKey, sPropValue);
@@ -1398,13 +1425,15 @@ Connection connectInternal(Properties propsIn,
sPropKey = SQLServerDriverBooleanProperty.TRUST_SERVER_CERTIFICATE.toString();
sPropValue = activeConnectionProperties.getProperty(sPropKey);
if (sPropValue == null) {
- sPropValue = Boolean.toString(SQLServerDriverBooleanProperty.TRUST_SERVER_CERTIFICATE.getDefaultValue());
+ sPropValue = Boolean
+ .toString(SQLServerDriverBooleanProperty.TRUST_SERVER_CERTIFICATE.getDefaultValue());
activeConnectionProperties.setProperty(sPropKey, sPropValue);
}
trustServerCertificate = booleanPropertyOn(sPropKey, sPropValue);
- trustManagerClass = activeConnectionProperties.getProperty(SQLServerDriverStringProperty.TRUST_MANAGER_CLASS.toString());
+ trustManagerClass = activeConnectionProperties
+ .getProperty(SQLServerDriverStringProperty.TRUST_MANAGER_CLASS.toString());
trustManagerConstructorArg = activeConnectionProperties
.getProperty(SQLServerDriverStringProperty.TRUST_MANAGER_CONSTRUCTOR_ARG.toString());
@@ -1414,8 +1443,7 @@ Connection connectInternal(Properties propsIn,
sPropValue = SQLServerDriverStringProperty.SELECT_METHOD.getDefaultValue();
if ("cursor".equalsIgnoreCase(sPropValue) || "direct".equalsIgnoreCase(sPropValue)) {
activeConnectionProperties.setProperty(sPropKey, sPropValue.toLowerCase(Locale.ENGLISH));
- }
- else {
+ } else {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidselectMethod"));
Object[] msgArgs = {sPropValue};
SQLServerException.makeFromDriverError(this, this, form.format(msgArgs), null, false);
@@ -1427,8 +1455,7 @@ Connection connectInternal(Properties propsIn,
sPropValue = SQLServerDriverStringProperty.RESPONSE_BUFFERING.getDefaultValue();
if ("full".equalsIgnoreCase(sPropValue) || "adaptive".equalsIgnoreCase(sPropValue)) {
activeConnectionProperties.setProperty(sPropKey, sPropValue.toLowerCase(Locale.ENGLISH));
- }
- else {
+ } else {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidresponseBuffering"));
Object[] msgArgs = {sPropValue};
SQLServerException.makeFromDriverError(this, this, form.format(msgArgs), null, false);
@@ -1452,13 +1479,14 @@ Connection connectInternal(Properties propsIn,
// Must be set before DISABLE_STATEMENT_POOLING
sPropKey = SQLServerDriverIntProperty.STATEMENT_POOLING_CACHE_SIZE.toString();
- if (activeConnectionProperties.getProperty(sPropKey) != null && activeConnectionProperties.getProperty(sPropKey).length() > 0) {
+ if (activeConnectionProperties.getProperty(sPropKey) != null
+ && activeConnectionProperties.getProperty(sPropKey).length() > 0) {
try {
int n = Integer.parseInt(activeConnectionProperties.getProperty(sPropKey));
this.setStatementPoolingCacheSize(n);
- }
- catch (NumberFormatException e) {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_statementPoolingCacheSize"));
+ } catch (NumberFormatException e) {
+ MessageFormat form = new MessageFormat(
+ SQLServerException.getErrString("R_statementPoolingCacheSize"));
Object[] msgArgs = {activeConnectionProperties.getProperty(sPropKey)};
SQLServerException.makeFromDriverError(this, this, form.format(msgArgs), null, false);
}
@@ -1501,36 +1529,50 @@ Connection connectInternal(Properties propsIn,
}
authenticationString = SqlAuthentication.valueOfString(sPropValue).toString();
- if ((true == integratedSecurity) && (!authenticationString.equalsIgnoreCase(SqlAuthentication.NotSpecified.toString()))) {
+ if ((true == integratedSecurity)
+ && (!authenticationString.equalsIgnoreCase(SqlAuthentication.NotSpecified.toString()))) {
if (connectionlogger.isLoggable(Level.SEVERE)) {
- connectionlogger.severe(toString() + " " + SQLServerException.getErrString("R_SetAuthenticationWhenIntegratedSecurityTrue"));
+ connectionlogger.severe(toString() + " "
+ + SQLServerException.getErrString("R_SetAuthenticationWhenIntegratedSecurityTrue"));
}
- throw new SQLServerException(SQLServerException.getErrString("R_SetAuthenticationWhenIntegratedSecurityTrue"), null);
+ throw new SQLServerException(
+ SQLServerException.getErrString("R_SetAuthenticationWhenIntegratedSecurityTrue"), null);
}
if (authenticationString.equalsIgnoreCase(SqlAuthentication.ActiveDirectoryIntegrated.toString())
- && ((!activeConnectionProperties.getProperty(SQLServerDriverStringProperty.USER.toString()).isEmpty())
- || (!activeConnectionProperties.getProperty(SQLServerDriverStringProperty.PASSWORD.toString()).isEmpty()))) {
+ && ((!activeConnectionProperties.getProperty(SQLServerDriverStringProperty.USER.toString())
+ .isEmpty())
+ || (!activeConnectionProperties
+ .getProperty(SQLServerDriverStringProperty.PASSWORD.toString()).isEmpty()))) {
if (connectionlogger.isLoggable(Level.SEVERE)) {
- connectionlogger.severe(toString() + " " + SQLServerException.getErrString("R_IntegratedAuthenticationWithUserPassword"));
+ connectionlogger.severe(toString() + " "
+ + SQLServerException.getErrString("R_IntegratedAuthenticationWithUserPassword"));
}
- throw new SQLServerException(SQLServerException.getErrString("R_IntegratedAuthenticationWithUserPassword"), null);
+ throw new SQLServerException(
+ SQLServerException.getErrString("R_IntegratedAuthenticationWithUserPassword"), null);
}
if (authenticationString.equalsIgnoreCase(SqlAuthentication.ActiveDirectoryPassword.toString())
- && ((activeConnectionProperties.getProperty(SQLServerDriverStringProperty.USER.toString()).isEmpty())
- || (activeConnectionProperties.getProperty(SQLServerDriverStringProperty.PASSWORD.toString()).isEmpty()))) {
+ && ((activeConnectionProperties.getProperty(SQLServerDriverStringProperty.USER.toString())
+ .isEmpty())
+ || (activeConnectionProperties
+ .getProperty(SQLServerDriverStringProperty.PASSWORD.toString()).isEmpty()))) {
if (connectionlogger.isLoggable(Level.SEVERE)) {
- connectionlogger.severe(toString() + " " + SQLServerException.getErrString("R_NoUserPasswordForActivePassword"));
+ connectionlogger.severe(
+ toString() + " " + SQLServerException.getErrString("R_NoUserPasswordForActivePassword"));
}
- throw new SQLServerException(SQLServerException.getErrString("R_NoUserPasswordForActivePassword"), null);
+ throw new SQLServerException(SQLServerException.getErrString("R_NoUserPasswordForActivePassword"),
+ null);
}
if (authenticationString.equalsIgnoreCase(SqlAuthentication.SqlPassword.toString())
- && ((activeConnectionProperties.getProperty(SQLServerDriverStringProperty.USER.toString()).isEmpty())
- || (activeConnectionProperties.getProperty(SQLServerDriverStringProperty.PASSWORD.toString()).isEmpty()))) {
+ && ((activeConnectionProperties.getProperty(SQLServerDriverStringProperty.USER.toString())
+ .isEmpty())
+ || (activeConnectionProperties
+ .getProperty(SQLServerDriverStringProperty.PASSWORD.toString()).isEmpty()))) {
if (connectionlogger.isLoggable(Level.SEVERE)) {
- connectionlogger.severe(toString() + " " + SQLServerException.getErrString("R_NoUserPasswordForSqlPassword"));
+ connectionlogger.severe(
+ toString() + " " + SQLServerException.getErrString("R_NoUserPasswordForSqlPassword"));
}
throw new SQLServerException(SQLServerException.getErrString("R_NoUserPasswordForSqlPassword"), null);
}
@@ -1543,36 +1585,46 @@ Connection connectInternal(Properties propsIn,
if ((null != accessTokenInByte) && 0 == accessTokenInByte.length) {
if (connectionlogger.isLoggable(Level.SEVERE)) {
- connectionlogger.severe(toString() + " " + SQLServerException.getErrString("R_AccessTokenCannotBeEmpty"));
+ connectionlogger
+ .severe(toString() + " " + SQLServerException.getErrString("R_AccessTokenCannotBeEmpty"));
}
throw new SQLServerException(SQLServerException.getErrString("R_AccessTokenCannotBeEmpty"), null);
}
if ((true == integratedSecurity) && (null != accessTokenInByte)) {
if (connectionlogger.isLoggable(Level.SEVERE)) {
- connectionlogger.severe(toString() + " " + SQLServerException.getErrString("R_SetAccesstokenWhenIntegratedSecurityTrue"));
+ connectionlogger.severe(toString() + " "
+ + SQLServerException.getErrString("R_SetAccesstokenWhenIntegratedSecurityTrue"));
}
- throw new SQLServerException(SQLServerException.getErrString("R_SetAccesstokenWhenIntegratedSecurityTrue"), null);
+ throw new SQLServerException(
+ SQLServerException.getErrString("R_SetAccesstokenWhenIntegratedSecurityTrue"), null);
}
- if ((!authenticationString.equalsIgnoreCase(SqlAuthentication.NotSpecified.toString())) && (null != accessTokenInByte)) {
+ if ((!authenticationString.equalsIgnoreCase(SqlAuthentication.NotSpecified.toString()))
+ && (null != accessTokenInByte)) {
if (connectionlogger.isLoggable(Level.SEVERE)) {
- connectionlogger.severe(toString() + " " + SQLServerException.getErrString("R_SetBothAuthenticationAndAccessToken"));
+ connectionlogger.severe(toString() + " "
+ + SQLServerException.getErrString("R_SetBothAuthenticationAndAccessToken"));
}
- throw new SQLServerException(SQLServerException.getErrString("R_SetBothAuthenticationAndAccessToken"), null);
+ throw new SQLServerException(SQLServerException.getErrString("R_SetBothAuthenticationAndAccessToken"),
+ null);
}
- if ((null != accessTokenInByte) && ((!activeConnectionProperties.getProperty(SQLServerDriverStringProperty.USER.toString()).isEmpty())
- || (!activeConnectionProperties.getProperty(SQLServerDriverStringProperty.PASSWORD.toString()).isEmpty()))) {
+ if ((null != accessTokenInByte) && ((!activeConnectionProperties
+ .getProperty(SQLServerDriverStringProperty.USER.toString()).isEmpty())
+ || (!activeConnectionProperties.getProperty(SQLServerDriverStringProperty.PASSWORD.toString())
+ .isEmpty()))) {
if (connectionlogger.isLoggable(Level.SEVERE)) {
- connectionlogger.severe(toString() + " " + SQLServerException.getErrString("R_AccessTokenWithUserPassword"));
+ connectionlogger.severe(
+ toString() + " " + SQLServerException.getErrString("R_AccessTokenWithUserPassword"));
}
throw new SQLServerException(SQLServerException.getErrString("R_AccessTokenWithUserPassword"), null);
}
// Turn off TNIR for FedAuth if user does not set TNIR explicitly
if (!userSetTNIR) {
- if ((!authenticationString.equalsIgnoreCase(SqlAuthentication.NotSpecified.toString())) || (null != accessTokenInByte)) {
+ if ((!authenticationString.equalsIgnoreCase(SqlAuthentication.NotSpecified.toString()))
+ || (null != accessTokenInByte)) {
transparentNetworkIPResolution = false;
}
}
@@ -1594,8 +1646,7 @@ Connection connectInternal(Properties propsIn,
SQLServerException.makeFromDriverError(this, this, form.format(msgArgs), null, false);
}
}
- }
- catch (NumberFormatException e) {
+ } catch (NumberFormatException e) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidPortNumber"));
Object[] msgArgs = {activeConnectionProperties.getProperty(sPropKey)};
SQLServerException.makeFromDriverError(this, this, form.format(msgArgs), null, false);
@@ -1615,8 +1666,7 @@ Connection connectInternal(Properties propsIn,
// 0 --> Use maximum size
else if (0 == requestedPacketSize)
requestedPacketSize = TDS.MAX_PACKET_SIZE;
- }
- catch (NumberFormatException e) {
+ } catch (NumberFormatException e) {
// Ensure that an invalid prop value results in an invalid packet size that
// is not acceptable to the server.
requestedPacketSize = TDS.INVALID_PACKET_SIZE;
@@ -1638,10 +1688,11 @@ else if (0 == requestedPacketSize)
// assumes that the null property defaults to false.
sPropKey = SQLServerDriverBooleanProperty.SEND_STRING_PARAMETERS_AS_UNICODE.toString();
if (null == activeConnectionProperties.getProperty(sPropKey)) {
- sendStringParametersAsUnicode = SQLServerDriverBooleanProperty.SEND_STRING_PARAMETERS_AS_UNICODE.getDefaultValue();
- }
- else {
- sendStringParametersAsUnicode = booleanPropertyOn(sPropKey, activeConnectionProperties.getProperty(sPropKey));
+ sendStringParametersAsUnicode = SQLServerDriverBooleanProperty.SEND_STRING_PARAMETERS_AS_UNICODE
+ .getDefaultValue();
+ } else {
+ sendStringParametersAsUnicode = booleanPropertyOn(sPropKey,
+ activeConnectionProperties.getProperty(sPropKey));
}
sPropKey = SQLServerDriverBooleanProperty.LAST_UPDATE_COUNT.toString();
@@ -1651,20 +1702,23 @@ else if (0 == requestedPacketSize)
sPropKey = SQLServerDriverStringProperty.SELECT_METHOD.toString();
selectMethod = null;
- if (activeConnectionProperties.getProperty(sPropKey) != null && activeConnectionProperties.getProperty(sPropKey).length() > 0) {
+ if (activeConnectionProperties.getProperty(sPropKey) != null
+ && activeConnectionProperties.getProperty(sPropKey).length() > 0) {
selectMethod = activeConnectionProperties.getProperty(sPropKey);
}
sPropKey = SQLServerDriverStringProperty.RESPONSE_BUFFERING.toString();
responseBuffering = null;
- if (activeConnectionProperties.getProperty(sPropKey) != null && activeConnectionProperties.getProperty(sPropKey).length() > 0) {
+ if (activeConnectionProperties.getProperty(sPropKey) != null
+ && activeConnectionProperties.getProperty(sPropKey).length() > 0) {
responseBuffering = activeConnectionProperties.getProperty(sPropKey);
}
sPropKey = SQLServerDriverIntProperty.LOCK_TIMEOUT.toString();
int defaultLockTimeOut = SQLServerDriverIntProperty.LOCK_TIMEOUT.getDefaultValue();
nLockTimeout = defaultLockTimeOut; // Wait forever
- if (activeConnectionProperties.getProperty(sPropKey) != null && activeConnectionProperties.getProperty(sPropKey).length() > 0) {
+ if (activeConnectionProperties.getProperty(sPropKey) != null
+ && activeConnectionProperties.getProperty(sPropKey).length() > 0) {
try {
int n = Integer.parseInt(activeConnectionProperties.getProperty(sPropKey));
if (n >= defaultLockTimeOut)
@@ -1674,8 +1728,7 @@ else if (0 == requestedPacketSize)
Object[] msgArgs = {activeConnectionProperties.getProperty(sPropKey)};
SQLServerException.makeFromDriverError(this, this, form.format(msgArgs), null, false);
}
- }
- catch (NumberFormatException e) {
+ } catch (NumberFormatException e) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidLockTimeOut"));
Object[] msgArgs = {activeConnectionProperties.getProperty(sPropKey)};
SQLServerException.makeFromDriverError(this, this, form.format(msgArgs), null, false);
@@ -1685,19 +1738,19 @@ else if (0 == requestedPacketSize)
sPropKey = SQLServerDriverIntProperty.QUERY_TIMEOUT.toString();
int defaultQueryTimeout = SQLServerDriverIntProperty.QUERY_TIMEOUT.getDefaultValue();
queryTimeoutSeconds = defaultQueryTimeout; // Wait forever
- if (activeConnectionProperties.getProperty(sPropKey) != null && activeConnectionProperties.getProperty(sPropKey).length() > 0) {
+ if (activeConnectionProperties.getProperty(sPropKey) != null
+ && activeConnectionProperties.getProperty(sPropKey).length() > 0) {
try {
int n = Integer.parseInt(activeConnectionProperties.getProperty(sPropKey));
if (n >= defaultQueryTimeout) {
queryTimeoutSeconds = n;
- }
- else {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidQueryTimeout"));
+ } else {
+ MessageFormat form = new MessageFormat(
+ SQLServerException.getErrString("R_invalidQueryTimeout"));
Object[] msgArgs = {activeConnectionProperties.getProperty(sPropKey)};
SQLServerException.makeFromDriverError(this, this, form.format(msgArgs), null, false);
}
- }
- catch (NumberFormatException e) {
+ } catch (NumberFormatException e) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidQueryTimeout"));
Object[] msgArgs = {activeConnectionProperties.getProperty(sPropKey)};
SQLServerException.makeFromDriverError(this, this, form.format(msgArgs), null, false);
@@ -1707,19 +1760,19 @@ else if (0 == requestedPacketSize)
sPropKey = SQLServerDriverIntProperty.SOCKET_TIMEOUT.toString();
int defaultSocketTimeout = SQLServerDriverIntProperty.SOCKET_TIMEOUT.getDefaultValue();
socketTimeoutMilliseconds = defaultSocketTimeout; // Wait forever
- if (activeConnectionProperties.getProperty(sPropKey) != null && activeConnectionProperties.getProperty(sPropKey).length() > 0) {
+ if (activeConnectionProperties.getProperty(sPropKey) != null
+ && activeConnectionProperties.getProperty(sPropKey).length() > 0) {
try {
int n = Integer.parseInt(activeConnectionProperties.getProperty(sPropKey));
if (n >= defaultSocketTimeout) {
socketTimeoutMilliseconds = n;
- }
- else {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidSocketTimeout"));
+ } else {
+ MessageFormat form = new MessageFormat(
+ SQLServerException.getErrString("R_invalidSocketTimeout"));
Object[] msgArgs = {activeConnectionProperties.getProperty(sPropKey)};
SQLServerException.makeFromDriverError(this, this, form.format(msgArgs), null, false);
}
- }
- catch (NumberFormatException e) {
+ } catch (NumberFormatException e) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidSocketTimeout"));
Object[] msgArgs = {activeConnectionProperties.getProperty(sPropKey)};
SQLServerException.makeFromDriverError(this, this, form.format(msgArgs), null, false);
@@ -1729,7 +1782,8 @@ else if (0 == requestedPacketSize)
sPropKey = SQLServerDriverIntProperty.CANCEL_QUERY_TIMEOUT.toString();
int cancelQueryTimeout = SQLServerDriverIntProperty.CANCEL_QUERY_TIMEOUT.getDefaultValue();
- if (activeConnectionProperties.getProperty(sPropKey) != null && activeConnectionProperties.getProperty(sPropKey).length() > 0) {
+ if (activeConnectionProperties.getProperty(sPropKey) != null
+ && activeConnectionProperties.getProperty(sPropKey).length() > 0) {
try {
int n = Integer.parseInt(activeConnectionProperties.getProperty(sPropKey));
if (n >= cancelQueryTimeout) {
@@ -1737,28 +1791,29 @@ else if (0 == requestedPacketSize)
if (queryTimeoutSeconds > defaultQueryTimeout) {
cancelQueryTimeoutSeconds = n;
}
- }
- else {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidCancelQueryTimeout"));
+ } else {
+ MessageFormat form = new MessageFormat(
+ SQLServerException.getErrString("R_invalidCancelQueryTimeout"));
Object[] msgArgs = {activeConnectionProperties.getProperty(sPropKey)};
SQLServerException.makeFromDriverError(this, this, form.format(msgArgs), null, false);
}
- }
- catch (NumberFormatException e) {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidCancelQueryTimeout"));
+ } catch (NumberFormatException e) {
+ MessageFormat form = new MessageFormat(
+ SQLServerException.getErrString("R_invalidCancelQueryTimeout"));
Object[] msgArgs = {activeConnectionProperties.getProperty(sPropKey)};
SQLServerException.makeFromDriverError(this, this, form.format(msgArgs), null, false);
}
}
sPropKey = SQLServerDriverIntProperty.SERVER_PREPARED_STATEMENT_DISCARD_THRESHOLD.toString();
- if (activeConnectionProperties.getProperty(sPropKey) != null && activeConnectionProperties.getProperty(sPropKey).length() > 0) {
+ if (activeConnectionProperties.getProperty(sPropKey) != null
+ && activeConnectionProperties.getProperty(sPropKey).length() > 0) {
try {
int n = Integer.parseInt(activeConnectionProperties.getProperty(sPropKey));
setServerPreparedStatementDiscardThreshold(n);
- }
- catch (NumberFormatException e) {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_serverPreparedStatementDiscardThreshold"));
+ } catch (NumberFormatException e) {
+ MessageFormat form = new MessageFormat(
+ SQLServerException.getErrString("R_serverPreparedStatementDiscardThreshold"));
Object[] msgArgs = {activeConnectionProperties.getProperty(sPropKey)};
SQLServerException.makeFromDriverError(this, this, form.format(msgArgs), null, false);
}
@@ -1769,20 +1824,19 @@ else if (0 == requestedPacketSize)
if (null != sPropValue) {
setEnablePrepareOnFirstPreparedStatementCall(booleanPropertyOn(sPropKey, sPropValue));
}
-
+
sPropKey = SQLServerDriverBooleanProperty.USE_BULK_COPY_FOR_BATCH_INSERT.toString();
sPropValue = activeConnectionProperties.getProperty(sPropKey);
if (null != sPropValue) {
useBulkCopyForBatchInsert = booleanPropertyOn(sPropKey, sPropValue);
}
-
+
sPropKey = SQLServerDriverStringProperty.SSL_PROTOCOL.toString();
sPropValue = activeConnectionProperties.getProperty(sPropKey);
if (null == sPropValue) {
sPropValue = SQLServerDriverStringProperty.SSL_PROTOCOL.getDefaultValue();
activeConnectionProperties.setProperty(sPropKey, sPropValue);
- }
- else {
+ } else {
activeConnectionProperties.setProperty(sPropKey, SSLProtocol.valueOfString(sPropValue).toString());
}
@@ -1794,11 +1848,12 @@ else if (0 == requestedPacketSize)
// failoverPartner and multiSubnetFailover=true cannot be used together
if (multiSubnetFailover && failOverPartnerPropertyValue != null) {
- SQLServerException.makeFromDriverError(this, this, SQLServerException.getErrString("R_dbMirroringWithMultiSubnetFailover"), null,
- false);
+ SQLServerException.makeFromDriverError(this, this,
+ SQLServerException.getErrString("R_dbMirroringWithMultiSubnetFailover"), null, false);
}
- // transparentNetworkIPResolution is ignored if multiSubnetFailover or DBMirroring is true and user does not set TNIR explicitly
+ // transparentNetworkIPResolution is ignored if multiSubnetFailover or DBMirroring is true and user does not
+ // set TNIR explicitly
if (multiSubnetFailover || (null != failOverPartnerPropertyValue)) {
if (!userSetTNIR) {
transparentNetworkIPResolution = false;
@@ -1806,20 +1861,24 @@ else if (0 == requestedPacketSize)
}
// failoverPartner and applicationIntent=ReadOnly cannot be used together
- if ((applicationIntent != null) && applicationIntent.equals(ApplicationIntent.READ_ONLY) && failOverPartnerPropertyValue != null) {
- SQLServerException.makeFromDriverError(this, this, SQLServerException.getErrString("R_dbMirroringWithReadOnlyIntent"), null, false);
+ if ((applicationIntent != null) && applicationIntent.equals(ApplicationIntent.READ_ONLY)
+ && failOverPartnerPropertyValue != null) {
+ SQLServerException.makeFromDriverError(this, this,
+ SQLServerException.getErrString("R_dbMirroringWithReadOnlyIntent"), null, false);
}
// check to see failover specified without DB error here if not.
if (null != activeConnectionProperties.getProperty(databaseNameProperty)) {
// look to see if there exists a failover
- fo = FailoverMapSingleton.getFailoverInfo(this, activeConnectionProperties.getProperty(serverNameProperty),
- activeConnectionProperties.getProperty(instanceNameProperty), activeConnectionProperties.getProperty(databaseNameProperty));
- }
- else {
+ fo = FailoverMapSingleton.getFailoverInfo(this,
+ activeConnectionProperties.getProperty(serverNameProperty),
+ activeConnectionProperties.getProperty(instanceNameProperty),
+ activeConnectionProperties.getProperty(databaseNameProperty));
+ } else {
// it is an error to specify failover without db.
if (null != failOverPartnerPropertyValue)
- SQLServerException.makeFromDriverError(this, this, SQLServerException.getErrString("R_failoverPartnerWithoutDB"), null, true);
+ SQLServerException.makeFromDriverError(this, this,
+ SQLServerException.getErrString("R_failoverPartnerWithoutDB"), null, true);
}
String mirror = null;
@@ -1827,7 +1886,8 @@ else if (0 == requestedPacketSize)
mirror = failOverPartnerPropertyValue;
long startTime = System.currentTimeMillis();
- login(activeConnectionProperties.getProperty(serverNameProperty), instanceValue, nPort, mirror, fo, loginTimeoutSeconds, startTime);
+ login(activeConnectionProperties.getProperty(serverNameProperty), instanceValue, nPort, mirror, fo,
+ loginTimeoutSeconds, startTime);
// If SSL is to be used for the duration of the connection, then make sure
// that the final negotiated TDS packet size is no larger than the SSL record size.
@@ -1837,8 +1897,9 @@ else if (0 == requestedPacketSize)
if (tdsPacketSize > sslRecordSize) {
if (connectionlogger.isLoggable(Level.FINER)) {
- connectionlogger.finer(toString() + " Negotiated tdsPacketSize " + tdsPacketSize + " is too large for SSL with JRE "
- + Util.SYSTEM_JRE + " (max size is " + sslRecordSize + ")");
+ connectionlogger.finer(toString() + " Negotiated tdsPacketSize " + tdsPacketSize
+ + " is too large for SSL with JRE " + Util.SYSTEM_JRE + " (max size is " + sslRecordSize
+ + ")");
}
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_packetSizeTooBigForSSL"));
Object[] msgArgs = {Integer.toString(sslRecordSize)};
@@ -1851,8 +1912,7 @@ else if (0 == requestedPacketSize)
if (connectionlogger.isLoggable(Level.FINER)) {
connectionlogger.finer(toString() + " End of connect");
}
- }
- finally {
+ } finally {
// once we exit the connect function, the connection can be only in one of two
// states, Opened or Closed(if an exception occurred)
if (!state.equals(State.Opened)) {
@@ -1866,22 +1926,17 @@ else if (0 == requestedPacketSize)
}
- // This function is used by non failover and failover cases. Even when we make a standard connection the server can provide us with its
- // FO partner.
- // If no FO information is available a standard connection is made.
- // If the server returns a failover upon connection, we shall store the FO in our cache.
- //
- private void login(String primary,
- String primaryInstanceName,
- int primaryPortNumber,
- String mirror,
- FailoverInfo foActual,
- int timeout,
- long timerStart) throws SQLServerException {
+ /**
+ * This function is used by non failover and failover cases. Even when we make a standard connection the server can
+ * provide us with its FO partner. If no FO information is available a standard connection is made. If the server
+ * returns a failover upon connection, we shall store the FO in our cache.
+ */
+ private void login(String primary, String primaryInstanceName, int primaryPortNumber, String mirror,
+ FailoverInfo foActual, int timeout, long timerStart) throws SQLServerException {
// standardLogin would be false only for db mirroring scenarios. It would be true
// for all other cases, including multiSubnetFailover
final boolean isDBMirroring = null != mirror || null != foActual;
- int sleepInterval = 100; // milliseconds to sleep (back off) between attempts.
+ int sleepInterval = 100; // milliseconds to sleep (back off) between attempts.
long timeoutUnitInterval;
boolean useFailoverHost = false;
@@ -1894,8 +1949,7 @@ private void login(String primary,
if (null != foActual) {
tempFailover = foActual;
useFailoverHost = foActual.getUseFailoverPartner();
- }
- else {
+ } else {
if (isDBMirroring)
// Create a temporary class with the mirror info from the user
tempFailover = new FailoverInfo(mirror, this, false);
@@ -1912,17 +1966,16 @@ private void login(String primary,
if (0 == timeout) {
timeout = SQLServerDriverIntProperty.LOGIN_TIMEOUT.getDefaultValue();
}
- long timerTimeout = timeout * 1000L; // ConnectTimeout is in seconds, we need timer millis
+ long timerTimeout = timeout * 1000L; // ConnectTimeout is in seconds, we need timer millis
timerExpire = timerStart + timerTimeout;
- // For non-dbmirroring, non-tnir and non-multisubnetfailover scenarios, full time out would be used as time slice.
+ // For non-dbmirroring, non-tnir and non-multisubnetfailover scenarios, full time out would be used as time
+ // slice.
if (isDBMirroring || useParallel) {
timeoutUnitInterval = (long) (TIMEOUTSTEP * timerTimeout);
- }
- else if (useTnir) {
+ } else if (useTnir) {
timeoutUnitInterval = (long) (TIMEOUTSTEP_TNIR * timerTimeout);
- }
- else {
+ } else {
timeoutUnitInterval = timerTimeout;
}
intervalExpire = timerStart + timeoutUnitInterval;
@@ -1931,8 +1984,8 @@ else if (useTnir) {
long intervalExpireFullTimeout = timerStart + timerTimeout;
if (connectionlogger.isLoggable(Level.FINER)) {
- connectionlogger.finer(
- toString() + " Start time: " + timerStart + " Time out time: " + timerExpire + " Timeout Unit Interval: " + timeoutUnitInterval);
+ connectionlogger.finer(toString() + " Start time: " + timerStart + " Time out time: " + timerExpire
+ + " Timeout Unit Interval: " + timeoutUnitInterval);
}
// Initialize loop variables
@@ -1961,23 +2014,23 @@ else if (useTnir) {
currentFOPlaceHolder = tempFailover.failoverPermissionCheck(this, integratedSecurity);
}
currentConnectPlaceHolder = currentFOPlaceHolder;
- }
- else {
+ } else {
if (routingInfo != null) {
currentPrimaryPlaceHolder = routingInfo;
routingInfo = null;
- }
- else if (null == currentPrimaryPlaceHolder) {
- currentPrimaryPlaceHolder = primaryPermissionCheck(primary, primaryInstanceName, primaryPortNumber);
+ } else if (null == currentPrimaryPlaceHolder) {
+ currentPrimaryPlaceHolder = primaryPermissionCheck(primary, primaryInstanceName,
+ primaryPortNumber);
}
currentConnectPlaceHolder = currentPrimaryPlaceHolder;
}
// logging code
if (connectionlogger.isLoggable(Level.FINE)) {
- connectionlogger.fine(toString() + " This attempt server name: " + currentConnectPlaceHolder.getServerName() + " port: "
- + currentConnectPlaceHolder.getPortNumber() + " InstanceName: " + currentConnectPlaceHolder.getInstanceName()
- + " useParallel: " + useParallel);
+ connectionlogger
+ .fine(toString() + " This attempt server name: " + currentConnectPlaceHolder.getServerName()
+ + " port: " + currentConnectPlaceHolder.getPortNumber() + " InstanceName: "
+ + currentConnectPlaceHolder.getInstanceName() + " useParallel: " + useParallel);
connectionlogger.fine(toString() + " This attempt endtime: " + intervalExpire);
connectionlogger.fine(toString() + " This attempt No: " + attemptNumber);
}
@@ -1986,12 +2039,13 @@ else if (null == currentPrimaryPlaceHolder) {
// Attempt login.
// use Place holder to make sure that the failoverdemand is done.
- connectHelper(currentConnectPlaceHolder, TimerRemaining(intervalExpire), timeout, useParallel, useTnir, (0 == attemptNumber), // Is
- // this
- // the
- // TNIR
- // first
- // attempt
+ connectHelper(currentConnectPlaceHolder, TimerRemaining(intervalExpire), timeout, useParallel, useTnir,
+ (0 == attemptNumber), // Is
+ // this
+ // the
+ // TNIR
+ // first
+ // attempt
TimerRemaining(intervalExpireFullTimeout)); // Only used when host resolves to >64 IPs
if (isRoutedInCurrentAttempt) {
@@ -2032,34 +2086,47 @@ else if (null == currentPrimaryPlaceHolder) {
useParallel = false;
useTnir = false;
- // When connection is routed for read only application, remaining timer duration is used as a one full interval
+ // When connection is routed for read only application, remaining timer duration is used as a one
+ // full interval
intervalExpire = timerExpire;
// if timeout expired, throw.
if (timerHasExpired(timerExpire)) {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_tcpipConnectionFailed"));
- Object[] msgArgs = {currentConnectPlaceHolder.getServerName(), Integer.toString(currentConnectPlaceHolder.getPortNumber()),
+ MessageFormat form = new MessageFormat(
+ SQLServerException.getErrString("R_tcpipConnectionFailed"));
+ Object[] msgArgs = {currentConnectPlaceHolder.getServerName(),
+ Integer.toString(currentConnectPlaceHolder.getPortNumber()),
SQLServerException.getErrString("R_timedOutBeforeRouting")};
String msg = form.format(msgArgs);
terminate(SQLServerException.DRIVER_ERROR_UNSUPPORTED_CONFIG, msg);
- }
- else {
+ } else {
continue;
}
- }
- else
+ } else
break; // leave the while loop -- we've successfully connected
- }
- catch (SQLServerException sqlex) {
+ } catch (SQLServerException sqlex) {
if ((SQLServerException.LOGON_FAILED == sqlex.getErrorCode()) // actual logon failed, i.e. bad password
- || (SQLServerException.PASSWORD_EXPIRED == sqlex.getErrorCode()) // actual logon failed, i.e. password isExpired
- || (SQLServerException.USER_ACCOUNT_LOCKED == sqlex.getErrorCode()) // actual logon failed, i.e. user account locked
- || (SQLServerException.DRIVER_ERROR_INVALID_TDS == sqlex.getDriverErrorCode()) // invalid TDS received from server
- || (SQLServerException.DRIVER_ERROR_SSL_FAILED == sqlex.getDriverErrorCode()) // failure negotiating SSL
- || (SQLServerException.DRIVER_ERROR_INTERMITTENT_TLS_FAILED == sqlex.getDriverErrorCode()) // failure TLS1.2
- || (SQLServerException.DRIVER_ERROR_UNSUPPORTED_CONFIG == sqlex.getDriverErrorCode()) // unsupported configuration (e.g.
- // Sphinx, invalid packet size, etc.)
- || (SQLServerException.ERROR_SOCKET_TIMEOUT == sqlex.getDriverErrorCode()) // socket timeout ocurred
+ || (SQLServerException.PASSWORD_EXPIRED == sqlex.getErrorCode()) // actual logon failed, i.e.
+ // password isExpired
+ || (SQLServerException.USER_ACCOUNT_LOCKED == sqlex.getErrorCode()) // actual logon failed, i.e.
+ // user account locked
+ || (SQLServerException.DRIVER_ERROR_INVALID_TDS == sqlex.getDriverErrorCode()) // invalid TDS
+ // received from
+ // server
+ || (SQLServerException.DRIVER_ERROR_SSL_FAILED == sqlex.getDriverErrorCode()) // failure
+ // negotiating SSL
+ || (SQLServerException.DRIVER_ERROR_INTERMITTENT_TLS_FAILED == sqlex.getDriverErrorCode()) // failure
+ // TLS1.2
+ || (SQLServerException.DRIVER_ERROR_UNSUPPORTED_CONFIG == sqlex.getDriverErrorCode()) // unsupported
+ // configuration
+ // (e.g.
+ // Sphinx,
+ // invalid
+ // packet
+ // size,
+ // etc.)
+ || (SQLServerException.ERROR_SOCKET_TIMEOUT == sqlex.getDriverErrorCode()) // socket timeout
+ // ocurred
|| timerHasExpired(timerExpire)// no more time to try again
|| (state.equals(State.Connected) && !isDBMirroring)
// for non-dbmirroring cases, do not retry after tcp socket connection succeeds
@@ -2068,15 +2135,15 @@ else if (null == currentPrimaryPlaceHolder) {
// close the connection and throw the error back
close();
throw sqlex;
- }
- else {
+ } else {
// Close the TDS channel from the failed connection attempt so that we don't
// hold onto network resources any longer than necessary.
if (null != tdsChannel)
tdsChannel.close();
}
- // For standard connections and MultiSubnetFailover connections, change the sleep interval after every attempt.
+ // For standard connections and MultiSubnetFailover connections, change the sleep interval after every
+ // attempt.
// For DB Mirroring, we only sleep after every other attempt.
if (!isDBMirroring || 1 == attemptNumber % 2) {
// Check sleep interval to make sure we won't exceed the timeout
@@ -2099,8 +2166,7 @@ else if (null == currentPrimaryPlaceHolder) {
}
try {
Thread.sleep(sleepInterval);
- }
- catch (InterruptedException e) {
+ } catch (InterruptedException e) {
// re-interrupt the current thread, in order to restore the thread's interrupt status.
Thread.currentThread().interrupt();
}
@@ -2112,11 +2178,9 @@ else if (null == currentPrimaryPlaceHolder) {
if (useParallel) {
intervalExpire = System.currentTimeMillis() + (timeoutUnitInterval * (attemptNumber + 1));
- }
- else if (isDBMirroring) {
+ } else if (isDBMirroring) {
intervalExpire = System.currentTimeMillis() + (timeoutUnitInterval * ((attemptNumber / 2) + 1));
- }
- else if (useTnir) {
+ } else if (useTnir) {
long timeSlice = timeoutUnitInterval * (1 << attemptNumber);
// In case the timeout for the first slice is less than 500 ms then bump it up to 500 ms
@@ -2125,11 +2189,11 @@ else if (useTnir) {
}
intervalExpire = System.currentTimeMillis() + timeSlice;
- }
- else
+ } else
intervalExpire = timerExpire;
// Due to the below condition and the timerHasExpired check in catch block,
- // the multiSubnetFailover case or any other standardLogin case where timeOutInterval is full timeout would also be handled correctly.
+ // the multiSubnetFailover case or any other standardLogin case where timeOutInterval is full timeout would
+ // also be handled correctly.
if (intervalExpire > timerExpire) {
intervalExpire = timerExpire;
}
@@ -2147,7 +2211,9 @@ else if (useTnir) {
curserverinfo = curserverinfo + currentFOPlaceHolder.getInstanceName();
}
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidPartnerConfiguration"));
- Object[] msgArgs = {activeConnectionProperties.getProperty(SQLServerDriverStringProperty.DATABASE_NAME.toString()), curserverinfo};
+ Object[] msgArgs = {
+ activeConnectionProperties.getProperty(SQLServerDriverStringProperty.DATABASE_NAME.toString()),
+ curserverinfo};
terminate(SQLServerException.DRIVER_ERROR_UNSUPPORTED_CONFIG, form.format(msgArgs));
}
@@ -2166,29 +2232,31 @@ else if (useTnir) {
if (null == tempFailover)
tempFailover = new FailoverInfo(failoverPartnerServerProvided, this, false);
- // if the failover is not from the map already out this in the map, if it is from the map just make sure that we change the
+ // if the failover is not from the map already out this in the map, if it is from the map just make sure
+ // that we change the
if (null != foActual) {
// We must wait for CompleteLogin to finish for to have the
// env change from the server to know its designated failover
// partner; saved in failoverPartnerServerProvided
foActual.failoverAdd(this, useFailoverHost, failoverPartnerServerProvided);
- }
- else {
+ } else {
String databaseNameProperty = SQLServerDriverStringProperty.DATABASE_NAME.toString();
String instanceNameProperty = SQLServerDriverStringProperty.INSTANCE_NAME.toString();
String serverNameProperty = SQLServerDriverStringProperty.SERVER_NAME.toString();
if (connectionlogger.isLoggable(Level.FINE)) {
- connectionlogger
- .fine(toString() + " adding new failover info server: " + activeConnectionProperties.getProperty(serverNameProperty)
- + " instance: " + activeConnectionProperties.getProperty(instanceNameProperty) + " database: "
- + activeConnectionProperties.getProperty(databaseNameProperty) + " server provided failover: "
- + failoverPartnerServerProvided);
+ connectionlogger.fine(toString() + " adding new failover info server: "
+ + activeConnectionProperties.getProperty(serverNameProperty) + " instance: "
+ + activeConnectionProperties.getProperty(instanceNameProperty) + " database: "
+ + activeConnectionProperties.getProperty(databaseNameProperty)
+ + " server provided failover: " + failoverPartnerServerProvided);
}
tempFailover.failoverAdd(this, useFailoverHost, failoverPartnerServerProvided);
- FailoverMapSingleton.putFailoverInfo(this, primary, activeConnectionProperties.getProperty(instanceNameProperty),
- activeConnectionProperties.getProperty(databaseNameProperty), tempFailover, useFailoverHost, failoverPartnerServerProvided);
+ FailoverMapSingleton.putFailoverInfo(this, primary,
+ activeConnectionProperties.getProperty(instanceNameProperty),
+ activeConnectionProperties.getProperty(databaseNameProperty), tempFailover, useFailoverHost,
+ failoverPartnerServerProvided);
}
}
}
@@ -2209,8 +2277,7 @@ void resetNonRoutingEnvchangeValues() {
// This code should be similar to the code in FailOverInfo class's failoverPermissionCheck
// Only difference is that this gets the instance port if the port number is zero where as failover
// does not have port number available.
- ServerPortPlaceHolder primaryPermissionCheck(String primary,
- String primaryInstanceName,
+ ServerPortPlaceHolder primaryPermissionCheck(String primary, String primaryInstanceName,
int primaryPortNumber) throws SQLServerException {
String instancePort;
// look to see primary port number is specified
@@ -2224,12 +2291,12 @@ ServerPortPlaceHolder primaryPermissionCheck(String primary,
primaryPortNumber = Integer.parseInt(instancePort);
if ((primaryPortNumber < 0) || (primaryPortNumber > 65535)) {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidPortNumber"));
+ MessageFormat form = new MessageFormat(
+ SQLServerException.getErrString("R_invalidPortNumber"));
Object[] msgArgs = {Integer.toString(primaryPortNumber)};
SQLServerException.makeFromDriverError(this, this, form.format(msgArgs), null, false);
}
- }
- else
+ } else
primaryPortNumber = DEFAULTPORT;
}
@@ -2238,13 +2305,13 @@ ServerPortPlaceHolder primaryPermissionCheck(String primary,
Object[] msgArgs = {primaryPortNumber};
SQLServerException.makeFromDriverError(this, this, form.format(msgArgs), null, false);
}
- }
- else
+ } else
primaryPortNumber = DEFAULTPORT;
}
// now we have determined the right port set the connection property back
- activeConnectionProperties.setProperty(SQLServerDriverIntProperty.PORT_NUMBER.toString(), String.valueOf(primaryPortNumber));
+ activeConnectionProperties.setProperty(SQLServerDriverIntProperty.PORT_NUMBER.toString(),
+ String.valueOf(primaryPortNumber));
return new ServerPortPlaceHolder(primary, primaryPortNumber, primaryInstanceName, integratedSecurity);
}
@@ -2267,38 +2334,37 @@ static int TimerRemaining(long timerExpire) {
}
/**
- * This is a helper function to connect this gets the port of the server to connect and the server name to connect and the timeout This function
- * achieves one connection attempt Create a prepared statement for internal use by the driver.
+ * This is a helper function to connect this gets the port of the server to connect and the server name to connect
+ * and the timeout This function achieves one connection attempt Create a prepared statement for internal use by the
+ * driver.
*
* @param serverInfo
* @param timeOutSliceInMillis
- * -timeout value in milli seconds for one try
+ * -timeout value in milli seconds for one try
* @param timeOutFullInSeconds
- * - whole timeout value specified by the user in seconds
+ * - whole timeout value specified by the user in seconds
* @param useParallel
- * - It is used to indicate whether a parallel algorithm should be tried or not for resolving a hostName. Note that useParallel is set
- * to false for a routed connection even if multiSubnetFailover is set to true.
+ * - It is used to indicate whether a parallel algorithm should be tried or not for resolving a hostName.
+ * Note that useParallel is set to false for a routed connection even if multiSubnetFailover is set to true.
* @param useTnir
* @param isTnirFirstAttempt
* @param timeOutsliceInMillisForFullTimeout
* @throws SQLServerException
*/
- private void connectHelper(ServerPortPlaceHolder serverInfo,
- int timeOutsliceInMillis,
- int timeOutFullInSeconds,
- boolean useParallel,
- boolean useTnir,
- boolean isTnirFirstAttempt,
+ private void connectHelper(ServerPortPlaceHolder serverInfo, int timeOutsliceInMillis, int timeOutFullInSeconds,
+ boolean useParallel, boolean useTnir, boolean isTnirFirstAttempt,
int timeOutsliceInMillisForFullTimeout) throws SQLServerException {
// Make the initial tcp-ip connection.
if (connectionlogger.isLoggable(Level.FINE)) {
- connectionlogger.fine(toString() + " Connecting with server: " + serverInfo.getServerName() + " port: " + serverInfo.getPortNumber()
- + " Timeout slice: " + timeOutsliceInMillis + " Timeout Full: " + timeOutFullInSeconds);
+ connectionlogger.fine(toString() + " Connecting with server: " + serverInfo.getServerName() + " port: "
+ + serverInfo.getPortNumber() + " Timeout slice: " + timeOutsliceInMillis + " Timeout Full: "
+ + timeOutFullInSeconds);
}
// Before opening the TDSChannel, calculate local hostname
- // as the InetAddress.getLocalHost() takes more than usual time in certain OS and JVM combination, it avoids connection loss
+ // as the InetAddress.getLocalHost() takes more than usual time in certain OS and JVM combination, it avoids
+ // connection loss
hostName = activeConnectionProperties.getProperty(SQLServerDriverStringProperty.WORKSTATION_ID.toString());
if (StringUtils.isEmpty(hostName)) {
hostName = Util.lookupHostName();
@@ -2307,11 +2373,11 @@ private void connectHelper(ServerPortPlaceHolder serverInfo,
// if the timeout is infinite slices are infinite too.
tdsChannel = new TDSChannel(this);
if (0 == timeOutFullInSeconds)
- tdsChannel.open(serverInfo.getServerName(), serverInfo.getPortNumber(), 0, useParallel, useTnir, isTnirFirstAttempt,
- timeOutsliceInMillisForFullTimeout);
+ tdsChannel.open(serverInfo.getServerName(), serverInfo.getPortNumber(), 0, useParallel, useTnir,
+ isTnirFirstAttempt, timeOutsliceInMillisForFullTimeout);
else
- tdsChannel.open(serverInfo.getServerName(), serverInfo.getPortNumber(), timeOutsliceInMillis, useParallel, useTnir, isTnirFirstAttempt,
- timeOutsliceInMillisForFullTimeout);
+ tdsChannel.open(serverInfo.getServerName(), serverInfo.getPortNumber(), timeOutsliceInMillis, useParallel,
+ useTnir, isTnirFirstAttempt, timeOutsliceInMillisForFullTimeout);
setState(State.Connected);
@@ -2330,12 +2396,12 @@ private void connectHelper(ServerPortPlaceHolder serverInfo,
}
/**
- * Negotiates prelogin information with the server
+ * Negotiates prelogin information with the server.
*/
- void Prelogin(String serverName,
- int portNumber) throws SQLServerException {
+ void Prelogin(String serverName, int portNumber) throws SQLServerException {
// Build a TDS Pre-Login packet to send to the server.
- if ((!authenticationString.trim().equalsIgnoreCase(SqlAuthentication.NotSpecified.toString())) || (null != accessTokenInByte)) {
+ if ((!authenticationString.trim().equalsIgnoreCase(SqlAuthentication.NotSpecified.toString()))
+ || (null != accessTokenInByte)) {
fedAuthRequiredByUser = true;
}
@@ -2350,8 +2416,7 @@ void Prelogin(String serverName,
// we also needed to modify the offsets above, by adding 5 to each offset,
// since the data session of each option is push 5 bytes behind.
fedAuthOffset = 5;
- }
- else {
+ } else {
messageLength = TDS.B_PRELOGIN_MESSAGE_LENGTH;
fedAuthOffset = 0;
}
@@ -2363,9 +2428,9 @@ void Prelogin(String serverName,
byte[] bufferHeader = {
// Buffer Header
TDS.PKT_PRELOGIN, // Message Type
- TDS.STATUS_BIT_EOM, 0, messageLength, 0, 0, // SPID (not used)
- 0, // Packet (not used)
- 0, // Window (not used)
+ TDS.STATUS_BIT_EOM, 0, messageLength, 0, 0, // SPID (not used)
+ 0, // Packet (not used)
+ 0, // Window (not used)
};
System.arraycopy(bufferHeader, 0, preloginRequest, preloginRequestOffset, bufferHeader.length);
@@ -2377,7 +2442,8 @@ void Prelogin(String serverName,
TDS.B_PRELOGIN_OPTION_ENCRYPTION, 0, (byte) (22 + fedAuthOffset), 0, 1, // B_FENCRYPTION
TDS.B_PRELOGIN_OPTION_TRACEID, 0, (byte) (23 + fedAuthOffset), 0, 36, // ClientConnectionId + ActivityId
};
- System.arraycopy(preloginOptionsBeforeFedAuth, 0, preloginRequest, preloginRequestOffset, preloginOptionsBeforeFedAuth.length);
+ System.arraycopy(preloginOptionsBeforeFedAuth, 0, preloginRequest, preloginRequestOffset,
+ preloginOptionsBeforeFedAuth.length);
preloginRequestOffset = preloginRequestOffset + preloginOptionsBeforeFedAuth.length;
if (fedAuthRequiredByUser) {
@@ -2399,7 +2465,8 @@ void Prelogin(String serverName,
requestedEncryptionLevel,
// TRACEID Data Session (ClientConnectionId + ActivityId) - Initialize to 0
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,};
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0,};
System.arraycopy(preloginOptionData, 0, preloginRequest, preloginRequestOffset, preloginOptionData.length);
preloginRequestOffset = preloginRequestOffset + preloginOptionData.length;
@@ -2420,9 +2487,9 @@ void Prelogin(String serverName,
int offset;
if (fedAuthRequiredByUser) {
- offset = preloginRequest.length - 36 - 1; // point to the TRACEID Data Session (one more byte for fedauth data session)
- }
- else {
+ offset = preloginRequest.length - 36 - 1; // point to the TRACEID Data Session (one more byte for fedauth
+ // data session)
+ } else {
offset = preloginRequest.length - 36; // point to the TRACEID Data Session
}
@@ -2439,7 +2506,8 @@ void Prelogin(String serverName,
offset += 4;
if (connectionlogger.isLoggable(Level.FINER)) {
- connectionlogger.finer(toString() + " Requesting encryption level:" + TDS.getEncryptionLevel(requestedEncryptionLevel));
+ connectionlogger.finer(
+ toString() + " Requesting encryption level:" + TDS.getEncryptionLevel(requestedEncryptionLevel));
connectionlogger.finer(toString() + " ActivityId " + activityId.toString());
}
@@ -2450,13 +2518,13 @@ void Prelogin(String serverName,
try {
tdsChannel.write(preloginRequest, 0, preloginRequest.length);
tdsChannel.flush();
- }
- catch (SQLServerException e) {
- connectionlogger.warning(toString() + preloginErrorLogString + " Error sending prelogin request: " + e.getMessage());
+ } catch (SQLServerException e) {
+ connectionlogger.warning(
+ toString() + preloginErrorLogString + " Error sending prelogin request: " + e.getMessage());
throw e;
}
- ActivityCorrelator.setCurrentActivityIdSentFlag(); // indicate current ActivityId is sent
+ ActivityCorrelator.setCurrentActivityIdSentFlag(); // indicate current ActivityId is sent
// Read the entire prelogin response
int responseLength = preloginResponse.length;
@@ -2467,9 +2535,9 @@ void Prelogin(String serverName,
try {
bytesRead = tdsChannel.read(preloginResponse, responseBytesRead, responseLength - responseBytesRead);
- }
- catch (SQLServerException e) {
- connectionlogger.warning(toString() + preloginErrorLogString + " Error reading prelogin response: " + e.getMessage());
+ } catch (SQLServerException e) {
+ connectionlogger.warning(
+ toString() + preloginErrorLogString + " Error reading prelogin response: " + e.getMessage());
throw e;
}
@@ -2480,11 +2548,12 @@ void Prelogin(String serverName,
// (and that we don't support with this driver).
if (-1 == bytesRead) {
if (connectionlogger.isLoggable(Level.WARNING)) {
- connectionlogger.warning(
- toString() + preloginErrorLogString + " Unexpected end of prelogin response after " + responseBytesRead + " bytes read");
+ connectionlogger.warning(toString() + preloginErrorLogString
+ + " Unexpected end of prelogin response after " + responseBytesRead + " bytes read");
}
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_tcpipConnectionFailed"));
- Object[] msgArgs = {serverName, Integer.toString(portNumber), SQLServerException.getErrString("R_notSQLServer")};
+ Object[] msgArgs = {serverName, Integer.toString(portNumber),
+ SQLServerException.getErrString("R_notSQLServer")};
terminate(SQLServerException.DRIVER_ERROR_IO_FAILED, form.format(msgArgs));
}
@@ -2503,10 +2572,12 @@ void Prelogin(String serverName,
// Verify that the response is actually a response...
if (TDS.PKT_REPLY != preloginResponse[0]) {
if (connectionlogger.isLoggable(Level.WARNING)) {
- connectionlogger.warning(toString() + preloginErrorLogString + " Unexpected response type:" + preloginResponse[0]);
+ connectionlogger.warning(toString() + preloginErrorLogString + " Unexpected response type:"
+ + preloginResponse[0]);
}
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_tcpipConnectionFailed"));
- Object[] msgArgs = {serverName, Integer.toString(portNumber), SQLServerException.getErrString("R_notSQLServer")};
+ Object[] msgArgs = {serverName, Integer.toString(portNumber),
+ SQLServerException.getErrString("R_notSQLServer")};
terminate(SQLServerException.DRIVER_ERROR_IO_FAILED, form.format(msgArgs));
}
@@ -2515,10 +2586,12 @@ void Prelogin(String serverName,
// prelogin response items easily fit into a single 4K packet.
if (TDS.STATUS_BIT_EOM != (TDS.STATUS_BIT_EOM & preloginResponse[1])) {
if (connectionlogger.isLoggable(Level.WARNING)) {
- connectionlogger.warning(toString() + preloginErrorLogString + " Unexpected response status:" + preloginResponse[1]);
+ connectionlogger.warning(toString() + preloginErrorLogString + " Unexpected response status:"
+ + preloginResponse[1]);
}
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_tcpipConnectionFailed"));
- Object[] msgArgs = {serverName, Integer.toString(portNumber), SQLServerException.getErrString("R_notSQLServer")};
+ Object[] msgArgs = {serverName, Integer.toString(portNumber),
+ SQLServerException.getErrString("R_notSQLServer")};
terminate(SQLServerException.DRIVER_ERROR_IO_FAILED, form.format(msgArgs));
}
@@ -2528,11 +2601,12 @@ void Prelogin(String serverName,
if (responseLength >= preloginResponse.length) {
if (connectionlogger.isLoggable(Level.WARNING)) {
- connectionlogger.warning(toString() + preloginErrorLogString + " Response length:" + responseLength
- + " is greater than allowed length:" + preloginResponse.length);
+ connectionlogger.warning(toString() + preloginErrorLogString + " Response length:"
+ + responseLength + " is greater than allowed length:" + preloginResponse.length);
}
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_tcpipConnectionFailed"));
- Object[] msgArgs = {serverName, Integer.toString(portNumber), SQLServerException.getErrString("R_notSQLServer")};
+ Object[] msgArgs = {serverName, Integer.toString(portNumber),
+ SQLServerException.getErrString("R_notSQLServer")};
terminate(SQLServerException.DRIVER_ERROR_IO_FAILED, form.format(msgArgs));
}
@@ -2568,7 +2642,8 @@ void Prelogin(String serverName,
throwInvalidTDS();
}
- int optionOffset = Util.readUnsignedShortBigEndian(preloginResponse, responseIndex) + TDS.PACKET_HEADER_SIZE;
+ int optionOffset = Util.readUnsignedShortBigEndian(preloginResponse, responseIndex)
+ + TDS.PACKET_HEADER_SIZE;
responseIndex += 2;
assert optionOffset >= 0;
@@ -2578,8 +2653,8 @@ void Prelogin(String serverName,
if (optionOffset + optionLength > responseLength) {
if (connectionlogger.isLoggable(Level.WARNING)) {
- connectionlogger.warning(
- toString() + " Offset:" + optionOffset + " and length:" + optionLength + " exceed response length:" + responseLength);
+ connectionlogger.warning(toString() + " Offset:" + optionOffset + " and length:" + optionLength
+ + " exceed response length:" + responseLength);
}
throwInvalidTDS();
}
@@ -2595,7 +2670,8 @@ void Prelogin(String serverName,
if (6 != optionLength) {
if (connectionlogger.isLoggable(Level.WARNING)) {
- connectionlogger.warning(toString() + " Version option length:" + optionLength + " is incorrect. Correct value is 6.");
+ connectionlogger.warning(toString() + " Version option length:" + optionLength
+ + " is incorrect. Correct value is 6.");
}
throwInvalidTDS();
}
@@ -2603,16 +2679,18 @@ void Prelogin(String serverName,
serverMajorVersion = preloginResponse[optionOffset];
if (serverMajorVersion < 9) {
if (connectionlogger.isLoggable(Level.WARNING)) {
- connectionlogger
- .warning(toString() + " Server major version:" + serverMajorVersion + " is not supported by this driver.");
+ connectionlogger.warning(toString() + " Server major version:" + serverMajorVersion
+ + " is not supported by this driver.");
}
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_unsupportedServerVersion"));
+ MessageFormat form = new MessageFormat(
+ SQLServerException.getErrString("R_unsupportedServerVersion"));
Object[] msgArgs = {Integer.toString(preloginResponse[optionOffset])};
terminate(SQLServerException.DRIVER_ERROR_UNSUPPORTED_CONFIG, form.format(msgArgs));
}
if (connectionlogger.isLoggable(Level.FINE))
- connectionlogger.fine(toString() + " Server returned major version:" + preloginResponse[optionOffset]);
+ connectionlogger
+ .fine(toString() + " Server returned major version:" + preloginResponse[optionOffset]);
receivedVersionOption = true;
break;
@@ -2627,8 +2705,8 @@ void Prelogin(String serverName,
if (1 != optionLength) {
if (connectionlogger.isLoggable(Level.WARNING)) {
- connectionlogger
- .warning(toString() + " Encryption option length:" + optionLength + " is incorrect. Correct value is 1.");
+ connectionlogger.warning(toString() + " Encryption option length:" + optionLength
+ + " is incorrect. Correct value is 1.");
}
throwInvalidTDS();
}
@@ -2637,33 +2715,40 @@ void Prelogin(String serverName,
// If the server did not return a valid encryption level, terminate the connection.
if (TDS.ENCRYPT_OFF != negotiatedEncryptionLevel && TDS.ENCRYPT_ON != negotiatedEncryptionLevel
- && TDS.ENCRYPT_REQ != negotiatedEncryptionLevel && TDS.ENCRYPT_NOT_SUP != negotiatedEncryptionLevel) {
+ && TDS.ENCRYPT_REQ != negotiatedEncryptionLevel
+ && TDS.ENCRYPT_NOT_SUP != negotiatedEncryptionLevel) {
if (connectionlogger.isLoggable(Level.WARNING)) {
- connectionlogger.warning(toString() + " Server returned " + TDS.getEncryptionLevel(negotiatedEncryptionLevel));
+ connectionlogger.warning(toString() + " Server returned "
+ + TDS.getEncryptionLevel(negotiatedEncryptionLevel));
}
throwInvalidTDS();
}
if (connectionlogger.isLoggable(Level.FINER))
- connectionlogger.finer(toString() + " Negotiated encryption level:" + TDS.getEncryptionLevel(negotiatedEncryptionLevel));
+ connectionlogger.finer(toString() + " Negotiated encryption level:"
+ + TDS.getEncryptionLevel(negotiatedEncryptionLevel));
// If we requested SSL encryption and the server does not support it, then terminate the connection.
if (TDS.ENCRYPT_ON == requestedEncryptionLevel && TDS.ENCRYPT_ON != negotiatedEncryptionLevel
&& TDS.ENCRYPT_REQ != negotiatedEncryptionLevel) {
- terminate(SQLServerException.DRIVER_ERROR_SSL_FAILED, SQLServerException.getErrString("R_sslRequiredNoServerSupport"));
+ terminate(SQLServerException.DRIVER_ERROR_SSL_FAILED,
+ SQLServerException.getErrString("R_sslRequiredNoServerSupport"));
}
// If we say we don't support SSL and the server doesn't accept unencrypted connections,
// then terminate the connection.
- if (TDS.ENCRYPT_NOT_SUP == requestedEncryptionLevel && TDS.ENCRYPT_NOT_SUP != negotiatedEncryptionLevel) {
+ if (TDS.ENCRYPT_NOT_SUP == requestedEncryptionLevel
+ && TDS.ENCRYPT_NOT_SUP != negotiatedEncryptionLevel) {
// If the server required an encrypted connection then terminate with an appropriate error.
if (TDS.ENCRYPT_REQ == negotiatedEncryptionLevel)
- terminate(SQLServerException.DRIVER_ERROR_SSL_FAILED, SQLServerException.getErrString("R_sslRequiredByServer"));
+ terminate(SQLServerException.DRIVER_ERROR_SSL_FAILED,
+ SQLServerException.getErrString("R_sslRequiredByServer"));
if (connectionlogger.isLoggable(Level.WARNING)) {
- connectionlogger
- .warning(toString() + " Client requested encryption level: " + TDS.getEncryptionLevel(requestedEncryptionLevel)
- + " Server returned unexpected encryption level: " + TDS.getEncryptionLevel(negotiatedEncryptionLevel));
+ connectionlogger.warning(toString() + " Client requested encryption level: "
+ + TDS.getEncryptionLevel(requestedEncryptionLevel)
+ + " Server returned unexpected encryption level: "
+ + TDS.getEncryptionLevel(negotiatedEncryptionLevel));
}
throwInvalidTDS();
}
@@ -2673,17 +2758,21 @@ void Prelogin(String serverName,
// Only 0x00 and 0x01 are accepted values from the server.
if (0 != preloginResponse[optionOffset] && 1 != preloginResponse[optionOffset]) {
if (connectionlogger.isLoggable(Level.SEVERE)) {
- connectionlogger.severe(toString() + " Server sent an unexpected value for FedAuthRequired PreLogin Option. Value was "
+ connectionlogger.severe(toString()
+ + " Server sent an unexpected value for FedAuthRequired PreLogin Option. Value was "
+ preloginResponse[optionOffset]);
}
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_FedAuthRequiredPreLoginResponseInvalidValue"));
+ MessageFormat form = new MessageFormat(
+ SQLServerException.getErrString("R_FedAuthRequiredPreLoginResponseInvalidValue"));
throw new SQLServerException(form.format(new Object[] {preloginResponse[optionOffset]}), null);
}
- // We must NOT use the response for the FEDAUTHREQUIRED PreLogin option, if the connection string option
+ // We must NOT use the response for the FEDAUTHREQUIRED PreLogin option, if the connection string
+ // option
// was not using the new Authentication keyword or in other words, if Authentication=NotSpecified
// Or AccessToken is not null, mean token based authentication is used.
- if (((null != authenticationString) && (!authenticationString.equalsIgnoreCase(SqlAuthentication.NotSpecified.toString())))
+ if (((null != authenticationString)
+ && (!authenticationString.equalsIgnoreCase(SqlAuthentication.NotSpecified.toString())))
|| (null != accessTokenInByte)) {
fedAuthRequiredPreLoginResponse = (preloginResponse[optionOffset] == 1);
}
@@ -2698,7 +2787,8 @@ void Prelogin(String serverName,
if (!receivedVersionOption || TDS.ENCRYPT_INVALID == negotiatedEncryptionLevel) {
if (connectionlogger.isLoggable(Level.WARNING)) {
- connectionlogger.warning(toString() + " Prelogin response is missing version and/or encryption option.");
+ connectionlogger
+ .warning(toString() + " Prelogin response is missing version and/or encryption option.");
}
throwInvalidTDS();
}
@@ -2718,27 +2808,25 @@ final void throwInvalidTDSToken(String tokenName) throws SQLServerException {
/**
* Terminates the connection and throws an exception detailing the reason for termination.
*
- * This method is similar to SQLServerException.makeFromDriverError, except that it always terminates the connection, and does so with the
- * appropriate state code.
+ * This method is similar to SQLServerException.makeFromDriverError, except that it always terminates the
+ * connection, and does so with the appropriate state code.
*/
- final void terminate(int driverErrorCode,
- String message) throws SQLServerException {
+ final void terminate(int driverErrorCode, String message) throws SQLServerException {
terminate(driverErrorCode, message, null);
}
- final void terminate(int driverErrorCode,
- String message,
- Throwable throwable) throws SQLServerException {
+ final void terminate(int driverErrorCode, String message, Throwable throwable) throws SQLServerException {
String state = this.state.equals(State.Opened) ? SQLServerException.EXCEPTION_XOPEN_CONNECTION_FAILURE
- : SQLServerException.EXCEPTION_XOPEN_CONNECTION_CANT_ESTABLISH;
+ : SQLServerException.EXCEPTION_XOPEN_CONNECTION_CANT_ESTABLISH;
if (!xopenStates)
state = SQLServerException.mapFromXopen(state);
- SQLServerException ex = new SQLServerException(this, SQLServerException.checkAndAppendClientConnId(message, this), state, // X/Open or SQL99
- // SQLState
- 0, // database error number (0 -> driver error)
- true); // include stack trace in log
+ SQLServerException ex = new SQLServerException(this,
+ SQLServerException.checkAndAppendClientConnId(message, this), state, // X/Open or SQL99
+ // SQLState
+ 0, // database error number (0 -> driver error)
+ true); // include stack trace in log
if (null != throwable)
ex.initCause(throwable);
@@ -2758,7 +2846,7 @@ final void terminate(int driverErrorCode,
* Executes a command through the scheduler.
*
* @param newCommand
- * the command to execute
+ * the command to execute
*/
boolean executeCommand(TDSCommand newCommand) throws SQLServerException {
synchronized (schedulerLock) {
@@ -2779,8 +2867,7 @@ boolean executeCommand(TDSCommand newCommand) throws SQLServerException {
boolean commandComplete = false;
try {
commandComplete = newCommand.execute(tdsChannel.getWriter(), tdsChannel.getReader(newCommand));
- }
- finally {
+ } finally {
// We should never displace an existing currentCommand
// assert null == currentCommand;
@@ -2806,13 +2893,11 @@ void resetCurrentCommand() throws SQLServerException {
/*
* Executes a connection-level command
*/
- private void connectionCommand(String sql,
- String logContext) throws SQLServerException {
+ private void connectionCommand(String sql, String logContext) throws SQLServerException {
final class ConnectionCommand extends UninterruptableTDSCommand {
final String sql;
- ConnectionCommand(String sql,
- String logContext) {
+ ConnectionCommand(String sql, String logContext) {
super(logContext);
this.sql = sql;
}
@@ -2840,10 +2925,10 @@ private String sqlStatementToInitialize() {
}
/**
- * Return the syntax to set the database calatog to use.
+ * Sets the syntax to set the database calatog to use.
*
* @param sDB
- * the new catalog
+ * the new catalog
* @return the required syntax
*/
void setCatalogName(String sDB) {
@@ -2855,7 +2940,7 @@ void setCatalogName(String sDB) {
}
/**
- * Return the syntax to set the database isolation level.
+ * Returns the syntax to set the database isolation level.
*
* @return the required syntax
*/
@@ -2893,7 +2978,7 @@ String sqlStatementToSetTransactionIsolationLevel() throws SQLServerException {
}
/**
- * Return the syntax to set the database commit mode.
+ * Returns the syntax to set the database commit mode.
*
* @return the required syntax
*/
@@ -2952,7 +3037,8 @@ public void setAutoCommit(boolean newAutoCommitMode) throws SQLServerException {
commitPendingTransaction = "IF @@TRANCOUNT > 0 COMMIT TRAN ";
if (connectionlogger.isLoggable(Level.FINER)) {
- connectionlogger.finer(toString() + " Autocommitmode current :" + databaseAutoCommitMode + " new: " + newAutoCommitMode);
+ connectionlogger.finer(
+ toString() + " Autocommitmode current :" + databaseAutoCommitMode + " new: " + newAutoCommitMode);
}
rolledBackTransaction = false;
@@ -2997,9 +3083,9 @@ public void rollback() throws SQLServerException {
checkClosed();
if (databaseAutoCommitMode) {
- SQLServerException.makeFromDriverError(this, this, SQLServerException.getErrString("R_cantInvokeRollback"), null, true);
- }
- else
+ SQLServerException.makeFromDriverError(this, this, SQLServerException.getErrString("R_cantInvokeRollback"),
+ null, true);
+ } else
connectionCommand("IF @@TRANCOUNT > 0 ROLLBACK TRAN", "Connection.rollback");
loggerExternal.exiting(getClassNameLogging(), "rollback");
}
@@ -3024,8 +3110,7 @@ public void abort(Executor executor) throws SQLException {
try {
SQLPermission perm = new SQLPermission(callAbortPerm);
secMgr.checkPermission(perm);
- }
- catch (SecurityException ex) {
+ } catch (SecurityException ex) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_permissionDenied"));
Object[] msgArgs = {callAbortPerm};
SQLServerException.makeFromDriverError(this, this, form.format(msgArgs), null, true);
@@ -3034,7 +3119,7 @@ public void abort(Executor executor) throws SQLException {
setState(State.Closed);
- if (null != tdsChannel)
+ if (null != tdsChannel && null != executor)
executor.execute(() -> tdsChannel.close());
loggerExternal.exiting(getClassNameLogging(), "abort");
@@ -3205,8 +3290,7 @@ private void addWarning(String warningString) {
if (null == sqlWarnings) {
sqlWarnings = warning;
- }
- else {
+ } else {
sqlWarnings.setNextWarning(warning);
}
}
@@ -3224,10 +3308,10 @@ public void clearWarnings() throws SQLServerException {
// --------------------------JDBC 2.0-----------------------------
@Override
- public Statement createStatement(int resultSetType,
- int resultSetConcurrency) throws SQLServerException {
+ public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLServerException {
if (loggerExternal.isLoggable(Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "createStatement", new Object[] {resultSetType, resultSetConcurrency});
+ loggerExternal.entering(getClassNameLogging(), "createStatement",
+ new Object[] {resultSetType, resultSetConcurrency});
checkClosed();
Statement st = new SQLServerStatement(this, resultSetType, resultSetConcurrency,
SQLServerStatementColumnEncryptionSetting.UseConnectionSetting);
@@ -3239,11 +3323,11 @@ public Statement createStatement(int resultSetType,
}
@Override
- public PreparedStatement prepareStatement(String sql,
- int resultSetType,
+ public PreparedStatement prepareStatement(String sql, int resultSetType,
int resultSetConcurrency) throws SQLServerException {
if (loggerExternal.isLoggable(Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "prepareStatement", new Object[] {sql, resultSetType, resultSetConcurrency});
+ loggerExternal.entering(getClassNameLogging(), "prepareStatement",
+ new Object[] {sql, resultSetType, resultSetConcurrency});
checkClosed();
PreparedStatement st = new SQLServerPreparedStatement(this, sql, resultSetType, resultSetConcurrency,
@@ -3256,16 +3340,15 @@ public PreparedStatement prepareStatement(String sql,
return st;
}
- private PreparedStatement prepareStatement(String sql,
- int resultSetType,
- int resultSetConcurrency,
+ private PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency,
SQLServerStatementColumnEncryptionSetting stmtColEncSetting) throws SQLServerException {
if (loggerExternal.isLoggable(Level.FINER))
loggerExternal.entering(getClassNameLogging(), "prepareStatement",
new Object[] {sql, resultSetType, resultSetConcurrency, stmtColEncSetting});
checkClosed();
- PreparedStatement st = new SQLServerPreparedStatement(this, sql, resultSetType, resultSetConcurrency, stmtColEncSetting);
+ PreparedStatement st = new SQLServerPreparedStatement(this, sql, resultSetType, resultSetConcurrency,
+ stmtColEncSetting);
if (requestStarted) {
addOpenStatement(st);
@@ -3276,11 +3359,11 @@ private PreparedStatement prepareStatement(String sql,
}
@Override
- public CallableStatement prepareCall(String sql,
- int resultSetType,
+ public CallableStatement prepareCall(String sql, int resultSetType,
int resultSetConcurrency) throws SQLServerException {
if (loggerExternal.isLoggable(Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "prepareCall", new Object[] {sql, resultSetType, resultSetConcurrency});
+ loggerExternal.entering(getClassNameLogging(), "prepareCall",
+ new Object[] {sql, resultSetType, resultSetConcurrency});
checkClosed();
CallableStatement st = new SQLServerCallableStatement(this, sql, resultSetType, resultSetConcurrency,
@@ -3323,7 +3406,8 @@ public java.util.Map> getTypeMap() throws SQLServerException {
int writeAEFeatureRequest(boolean write,
TDSWriter tdsWriter) throws SQLServerException /* if false just calculates the length */
{
- // This includes the length of the terminator byte. If there are other extension features, re-adjust accordingly.
+ // This includes the length of the terminator byte. If there are other extension features, re-adjust
+ // accordingly.
int len = 6; // (1byte = featureID, 4bytes = featureData length, 1 bytes = Version)
if (write) {
@@ -3334,12 +3418,11 @@ int writeAEFeatureRequest(boolean write,
return len;
}
- int writeFedAuthFeatureRequest(boolean write,
- TDSWriter tdsWriter,
- FederatedAuthenticationFeatureExtensionData fedAuthFeatureExtensionData) throws SQLServerException { /*
- * if false just calculates the
- * length
- */
+ // if false just calculates the length
+
+ int writeFedAuthFeatureRequest(boolean write, TDSWriter tdsWriter,
+ FederatedAuthenticationFeatureExtensionData fedAuthFeatureExtensionData) throws SQLServerException {
+
assert (fedAuthFeatureExtensionData.libraryType == TDS.TDS_FEDAUTH_LIBRARY_ADAL
|| fedAuthFeatureExtensionData.libraryType == TDS.TDS_FEDAUTH_LIBRARY_SECURITYTOKEN);
@@ -3348,19 +3431,21 @@ int writeFedAuthFeatureRequest(boolean write,
// set dataLen and totalLen
switch (fedAuthFeatureExtensionData.libraryType) {
case TDS.TDS_FEDAUTH_LIBRARY_ADAL:
- dataLen = 2; // length of feature data = 1 byte for library and echo + 1 byte for workflow
+ dataLen = 2; // length of feature data = 1 byte for library and echo + 1 byte for workflow
break;
case TDS.TDS_FEDAUTH_LIBRARY_SECURITYTOKEN:
assert null != fedAuthFeatureExtensionData.accessToken;
- dataLen = 1 + 4 + fedAuthFeatureExtensionData.accessToken.length; // length of feature data = 1 byte for library and echo, security
- // token length and sizeof(int) for token lengh itself
+ // length of feature data = 1 byte for library and echo,
+ // security token length and sizeof(int) for token length itself
+ dataLen = 1 + 4 + fedAuthFeatureExtensionData.accessToken.length;
break;
default:
- assert (false); // Unrecognized library type for fedauth feature extension request"
+ assert (false); // Unrecognized library type for fedauth feature extension request"
break;
}
- int totalLen = dataLen + 5; // length of feature id (1 byte), data length field (4 bytes), and feature data (dataLen)
+ int totalLen = dataLen + 5; // length of feature id (1 byte), data length field (4 bytes), and feature data
+ // (dataLen)
// write feature id
if (write) {
@@ -3380,7 +3465,7 @@ int writeFedAuthFeatureRequest(boolean write,
options |= TDS.TDS_FEDAUTH_LIBRARY_SECURITYTOKEN << 1;
break;
default:
- assert (false); // Unrecognized library type for fedauth feature extension request
+ assert (false); // Unrecognized library type for fedauth feature extension request
break;
}
@@ -3406,7 +3491,7 @@ int writeFedAuthFeatureRequest(boolean write,
workflow = TDS.ADALWORKFLOW_ACTIVEDIRECTORYINTEGRATED;
break;
default:
- assert (false); // Unrecognized Authentication type for fedauth ADAL request
+ assert (false); // Unrecognized Authentication type for fedauth ADAL request
break;
}
@@ -3414,16 +3499,17 @@ int writeFedAuthFeatureRequest(boolean write,
break;
case TDS.TDS_FEDAUTH_LIBRARY_SECURITYTOKEN:
tdsWriter.writeInt(fedAuthFeatureExtensionData.accessToken.length);
- tdsWriter.writeBytes(fedAuthFeatureExtensionData.accessToken, 0, fedAuthFeatureExtensionData.accessToken.length);
+ tdsWriter.writeBytes(fedAuthFeatureExtensionData.accessToken, 0,
+ fedAuthFeatureExtensionData.accessToken.length);
break;
default:
- assert (false); // Unrecognized FedAuthLibrary type for feature extension request
+ assert (false); // Unrecognized FedAuthLibrary type for feature extension request
break;
}
}
return totalLen;
}
-
+
int writeDataClassificationFeatureRequest(boolean write /* if false just calculates the length */,
TDSWriter tdsWriter) throws SQLServerException {
int len = 6; // 1byte = featureID, 4bytes = featureData length, 1 bytes = Version
@@ -3435,7 +3521,7 @@ int writeDataClassificationFeatureRequest(boolean write /* if false just calcula
}
return len; // size of data written
}
-
+
int writeUTF8SupportFeatureRequest(boolean write,
TDSWriter tdsWriter /* if false just calculates the length */) throws SQLServerException {
int len = 5; // 1byte = featureID, 4bytes = featureData length
@@ -3460,31 +3546,35 @@ final boolean doExecute() throws SQLServerException {
private void logon(LogonCommand command) throws SQLServerException {
SSPIAuthentication authentication = null;
if (integratedSecurity && AuthenticationScheme.nativeAuthentication == intAuthScheme)
- authentication = new AuthenticationJNI(this, currentConnectPlaceHolder.getServerName(), currentConnectPlaceHolder.getPortNumber());
+ authentication = new AuthenticationJNI(this, currentConnectPlaceHolder.getServerName(),
+ currentConnectPlaceHolder.getPortNumber());
if (integratedSecurity && AuthenticationScheme.javaKerberos == intAuthScheme) {
if (null != ImpersonatedUserCred) {
- authentication = new KerbAuthentication(this, currentConnectPlaceHolder.getServerName(), currentConnectPlaceHolder.getPortNumber(),
- ImpersonatedUserCred, isUserCreatedCredential);
- }
- else
- authentication = new KerbAuthentication(this, currentConnectPlaceHolder.getServerName(), currentConnectPlaceHolder.getPortNumber());
+ authentication = new KerbAuthentication(this, currentConnectPlaceHolder.getServerName(),
+ currentConnectPlaceHolder.getPortNumber(), ImpersonatedUserCred, isUserCreatedCredential);
+ } else
+ authentication = new KerbAuthentication(this, currentConnectPlaceHolder.getServerName(),
+ currentConnectPlaceHolder.getPortNumber());
}
- // If the workflow being used is Active Directory Password or Active Directory Integrated and server's prelogin response
- // for FEDAUTHREQUIRED option indicates Federated Authentication is required, we have to insert FedAuth Feature Extension
+ // If the workflow being used is Active Directory Password or Active Directory Integrated and server's prelogin
+ // response
+ // for FEDAUTHREQUIRED option indicates Federated Authentication is required, we have to insert FedAuth Feature
+ // Extension
// in Login7, indicating the intent to use Active Directory Authentication Library for SQL Server.
if (authenticationString.trim().equalsIgnoreCase(SqlAuthentication.ActiveDirectoryPassword.toString())
|| (authenticationString.trim().equalsIgnoreCase(SqlAuthentication.ActiveDirectoryIntegrated.toString())
&& fedAuthRequiredPreLoginResponse)) {
federatedAuthenticationInfoRequested = true;
- fedAuthFeatureExtensionData = new FederatedAuthenticationFeatureExtensionData(TDS.TDS_FEDAUTH_LIBRARY_ADAL, authenticationString,
- fedAuthRequiredPreLoginResponse);
+ fedAuthFeatureExtensionData = new FederatedAuthenticationFeatureExtensionData(TDS.TDS_FEDAUTH_LIBRARY_ADAL,
+ authenticationString, fedAuthRequiredPreLoginResponse);
}
if (null != accessTokenInByte) {
- fedAuthFeatureExtensionData = new FederatedAuthenticationFeatureExtensionData(TDS.TDS_FEDAUTH_LIBRARY_SECURITYTOKEN,
- fedAuthRequiredPreLoginResponse, accessTokenInByte);
- // No need any further info from the server for token based authentication. So set _federatedAuthenticationRequested to true
+ fedAuthFeatureExtensionData = new FederatedAuthenticationFeatureExtensionData(
+ TDS.TDS_FEDAUTH_LIBRARY_SECURITYTOKEN, fedAuthRequiredPreLoginResponse, accessTokenInByte);
+ // No need any further info from the server for token based authentication. So set
+ // _federatedAuthenticationRequested to true
federatedAuthenticationRequested = true;
}
try {
@@ -3500,8 +3590,7 @@ private void logon(LogonCommand command) throws SQLServerException {
connectionCommand(sqlStmt, "Change Settings");
}
}
- }
- finally {
+ } finally {
if (integratedSecurity) {
if (null != authentication) {
authentication.ReleaseClientContext();
@@ -3547,8 +3636,7 @@ final void processEnvChange(TDSReader tdsReader) throws SQLServerException {
// Set NEW value as new TDS packet size
try {
tdsPacketSize = Integer.parseInt(tdsReader.readUnicodeString(tdsReader.readUnsignedByte()));
- }
- catch (NumberFormatException e) {
+ } catch (NumberFormatException e) {
tdsReader.throwInvalidTDS();
}
if (connectionlogger.isLoggable(Level.FINER))
@@ -3561,8 +3649,7 @@ final void processEnvChange(TDSReader tdsReader) throws SQLServerException {
try {
databaseCollation = new SQLCollation(tdsReader);
- }
- catch (java.io.UnsupportedEncodingException e) {
+ } catch (java.io.UnsupportedEncodingException e) {
terminate(SQLServerException.DRIVER_ERROR_INVALID_TDS, e.getMessage(), e);
}
@@ -3597,11 +3684,11 @@ final void processEnvChange(TDSReader tdsReader) throws SQLServerException {
connectionlogger.finer(toString() + " rolled back. (DTC)");
// Do not clear the transaction descriptor if the connection is in DT.
- // For a DTC transaction, a ENV_ROLLBACKTRAN token won't cleanup the xactID previously cached on the connection
+ // For a DTC transaction, a ENV_ROLLBACKTRAN token won't cleanup the xactID previously cached on the
+ // connection
// because user is required to explicitly un-enlist/defect a connection from a DTC.
// A ENV_DEFECTTRAN token though will clean the DTC xactID on the connection.
- }
- else {
+ } else {
if (connectionlogger.isLoggable(Level.FINER))
connectionlogger.finer(toString() + " rolled back");
@@ -3656,7 +3743,8 @@ final void processEnvChange(TDSReader tdsReader) throws SQLServerException {
try {
routingDataValueLength = tdsReader.readUnsignedShort();
- if (routingDataValueLength <= 5)// (5 is the no of bytes in protocol + port number+ length field of server name)
+ if (routingDataValueLength <= 5)// (5 is the no of bytes in protocol + port number+ length field of
+ // server name)
{
throwInvalidTDS();
}
@@ -3679,21 +3767,26 @@ final void processEnvChange(TDSReader tdsReader) throws SQLServerException {
routingServerName = tdsReader.readUnicodeString(routingServerNameLength);
assert routingServerName != null;
- }
- finally {
+ } finally {
if (connectionlogger.isLoggable(Level.FINER)) {
- connectionlogger.finer(toString() + " Received routing ENVCHANGE with the following values." + " routingDataValueLength:"
- + routingDataValueLength + " protocol:" + routingProtocol + " portNumber:" + routingPortNumber + " serverNameLength:"
- + routingServerNameLength + " serverName:" + ((routingServerName != null) ? routingServerName : "null"));
+ connectionlogger.finer(toString() + " Received routing ENVCHANGE with the following values."
+ + " routingDataValueLength:" + routingDataValueLength + " protocol:" + routingProtocol
+ + " portNumber:" + routingPortNumber + " serverNameLength:" + routingServerNameLength
+ + " serverName:" + ((routingServerName != null) ? routingServerName : "null"));
}
}
// Check if the hostNameInCertificate needs to be updated to handle the rerouted subdomain in Azure
String currentHostName = activeConnectionProperties.getProperty("hostNameInCertificate");
if (null != currentHostName && currentHostName.startsWith("*") && (null != routingServerName) /*
- * skip the check for
- * hostNameInCertificate if
- * routingServerName is null
+ * skip
+ * the
+ * check
+ * for
+ * hostNameInCertificate
+ * if
+ * routingServerName
+ * is null
*/
&& routingServerName.indexOf('.') != -1) {
char[] currentHostNameCharArray = currentHostName.toCharArray();
@@ -3701,10 +3794,12 @@ final void processEnvChange(TDSReader tdsReader) throws SQLServerException {
boolean hostNameNeedsUpdate = true;
/*
- * Check if routingServerName and hostNameInCertificate are from same domain by verifying each character in currentHostName from
- * last until it reaches the character before the wildcard symbol (i.e. currentHostNameCharArray[1])
+ * Check if routingServerName and hostNameInCertificate are from same domain by verifying each
+ * character in currentHostName from last until it reaches the character before the wildcard symbol
+ * (i.e. currentHostNameCharArray[1])
*/
- for (int i = currentHostName.length() - 1, j = routingServerName.length() - 1; i > 0 && j > 0; i--, j--) {
+ for (int i = currentHostName.length() - 1, j = routingServerName.length() - 1; i > 0 && j > 0;
+ i--, j--) {
if (routingServerNameCharArray[j] != currentHostNameCharArray[i]) {
hostNameNeedsUpdate = false;
break;
@@ -3741,8 +3836,7 @@ final void processEnvChange(TDSReader tdsReader) throws SQLServerException {
tdsReader.readBytes(new byte[envValueLength], 0, envValueLength);
}
- final void processFedAuthInfo(TDSReader tdsReader,
- TDSTokenHandler tdsTokenHandler) throws SQLServerException {
+ final void processFedAuthInfo(TDSReader tdsReader, TDSTokenHandler tdsTokenHandler) throws SQLServerException {
SqlFedAuthInfo sqlFedAuthInfo = new SqlFedAuthInfo();
tdsReader.readUnsignedByte(); // token type, 0xEE
@@ -3759,7 +3853,8 @@ final void processFedAuthInfo(TDSReader tdsReader,
if (connectionlogger.isLoggable(Level.SEVERE)) {
connectionlogger.severe(toString() + "FEDAUTHINFO token stream length too short for CountOfInfoIDs.");
}
- throw new SQLServerException(SQLServerException.getErrString("R_FedAuthInfoLengthTooShortForCountOfInfoIds"), null);
+ throw new SQLServerException(
+ SQLServerException.getErrString("R_FedAuthInfoLengthTooShortForCountOfInfoIds"), null);
}
// read how many FedAuthInfo options there are
@@ -3778,7 +3873,8 @@ final void processFedAuthInfo(TDSReader tdsReader,
tdsReader.readBytes(tokenData, 0, tokenLen);
if (connectionlogger.isLoggable(Level.FINER)) {
- connectionlogger.fine(toString() + " Read rest of FEDAUTHINFO token stream: " + Arrays.toString(tokenData));
+ connectionlogger
+ .fine(toString() + " Read rest of FEDAUTHINFO token stream: " + Arrays.toString(tokenData));
}
// each FedAuthInfoOpt is 9 bytes:
@@ -3812,7 +3908,8 @@ final void processFedAuthInfo(TDSReader tdsReader,
int dataOffset = wrapped.getInt();
if (connectionlogger.isLoggable(Level.FINER)) {
- connectionlogger.fine(toString() + " FedAuthInfoOpt: ID=" + id + ", DataLen=" + dataLen + ", Offset=" + dataOffset);
+ connectionlogger.fine(toString() + " FedAuthInfoOpt: ID=" + id + ", DataLen=" + dataLen
+ + ", Offset=" + dataOffset);
}
// offset is measured from optCount, so subtract to make offset measured
@@ -3824,7 +3921,8 @@ final void processFedAuthInfo(TDSReader tdsReader,
if (connectionlogger.isLoggable(Level.SEVERE)) {
connectionlogger.severe(toString() + "FedAuthInfoDataOffset points to an invalid location.");
}
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_FedAuthInfoInvalidOffset"));
+ MessageFormat form = new MessageFormat(
+ SQLServerException.getErrString("R_FedAuthInfoInvalidOffset"));
throw new SQLServerException(form.format(new Object[] {dataOffset}), null);
}
@@ -3834,8 +3932,7 @@ final void processFedAuthInfo(TDSReader tdsReader,
byte[] dataArray = new byte[dataLen];
System.arraycopy(tokenData, dataOffset, dataArray, 0, dataLen);
data = new String(dataArray, UTF_16LE);
- }
- catch (Exception e) {
+ } catch (Exception e) {
connectionlogger.severe(toString() + "Failed to read FedAuthInfoData.");
throw new SQLServerException(SQLServerException.getErrString("R_FedAuthInfoFailedToReadData"), e);
}
@@ -3854,17 +3951,19 @@ final void processFedAuthInfo(TDSReader tdsReader,
break;
default:
if (connectionlogger.isLoggable(Level.FINER)) {
- connectionlogger.fine(toString() + " Ignoring unknown federated authentication info option: " + id);
+ connectionlogger
+ .fine(toString() + " Ignoring unknown federated authentication info option: " + id);
}
break;
}
}
- }
- else {
+ } else {
if (connectionlogger.isLoggable(Level.SEVERE)) {
- connectionlogger.severe(toString() + "FEDAUTHINFO token stream is not long enough to contain the data it claims to.");
+ connectionlogger.severe(
+ toString() + "FEDAUTHINFO token stream is not long enough to contain the data it claims to.");
}
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_FedAuthInfoLengthTooShortForData"));
+ MessageFormat form = new MessageFormat(
+ SQLServerException.getErrString("R_FedAuthInfoLengthTooShortForData"));
throw new SQLServerException(form.format(new Object[] {tokenLen}), null);
}
@@ -3874,7 +3973,8 @@ final void processFedAuthInfo(TDSReader tdsReader,
if (connectionlogger.isLoggable(Level.SEVERE)) {
connectionlogger.severe(toString() + "FEDAUTHINFO token stream does not contain both STSURL and SPN.");
}
- throw new SQLServerException(SQLServerException.getErrString("R_FedAuthInfoDoesNotContainStsurlAndSpn"), null);
+ throw new SQLServerException(SQLServerException.getErrString("R_FedAuthInfoDoesNotContainStsurlAndSpn"),
+ null);
}
onFedAuthInfo(sqlFedAuthInfo, tdsTokenHandler);
@@ -3884,8 +3984,7 @@ final class FedAuthTokenCommand extends UninterruptableTDSCommand {
TDSTokenHandler tdsTokenHandler = null;
SqlFedAuthToken fedAuthToken = null;
- FedAuthTokenCommand(SqlFedAuthToken fedAuthToken,
- TDSTokenHandler tdsTokenHandler) {
+ FedAuthTokenCommand(SqlFedAuthToken fedAuthToken, TDSTokenHandler tdsTokenHandler) {
super("FedAuth");
this.tdsTokenHandler = tdsTokenHandler;
this.fedAuthToken = fedAuthToken;
@@ -3898,14 +3997,14 @@ final boolean doExecute() throws SQLServerException {
}
/**
- * Generates (if appropriate) and sends a Federated Authentication Access token to the server, using the Federated Authentication Info.
+ * Generates (if appropriate) and sends a Federated Authentication Access token to the server, using the Federated
+ * Authentication Info.
*/
- void onFedAuthInfo(SqlFedAuthInfo fedAuthInfo,
- TDSTokenHandler tdsTokenHandler) throws SQLServerException {
+ void onFedAuthInfo(SqlFedAuthInfo fedAuthInfo, TDSTokenHandler tdsTokenHandler) throws SQLServerException {
assert (null != activeConnectionProperties.getProperty(SQLServerDriverStringProperty.USER.toString())
&& null != activeConnectionProperties.getProperty(SQLServerDriverStringProperty.PASSWORD.toString()))
- || ((authenticationString.trim().equalsIgnoreCase(SqlAuthentication.ActiveDirectoryIntegrated.toString())
- && fedAuthRequiredPreLoginResponse));
+ || ((authenticationString.trim().equalsIgnoreCase(
+ SqlAuthentication.ActiveDirectoryIntegrated.toString()) && fedAuthRequiredPreLoginResponse));
assert null != fedAuthInfo;
attemptRefreshTokenLocked = true;
@@ -3933,19 +4032,22 @@ private SqlFedAuthToken getFedAuthToken(SqlFedAuthInfo fedAuthInfo) throws SQLSe
while (true) {
if (authenticationString.trim().equalsIgnoreCase(SqlAuthentication.ActiveDirectoryPassword.toString())) {
- fedAuthToken = SQLServerADAL4JUtils.getSqlFedAuthToken(fedAuthInfo, user, password, authenticationString);
+ fedAuthToken = SQLServerADAL4JUtils.getSqlFedAuthToken(fedAuthInfo, user, password,
+ authenticationString);
// Break out of the retry loop in successful case.
break;
- }
- else if (authenticationString.trim().equalsIgnoreCase(SqlAuthentication.ActiveDirectoryIntegrated.toString())) {
+ } else if (authenticationString.trim()
+ .equalsIgnoreCase(SqlAuthentication.ActiveDirectoryIntegrated.toString())) {
// If operating system is windows and sqljdbc_auth is loaded then choose the DLL authentication.
- if (System.getProperty("os.name").toLowerCase(Locale.ENGLISH).startsWith("windows") && AuthenticationJNI.isDllLoaded()) {
+ if (System.getProperty("os.name").toLowerCase(Locale.ENGLISH).startsWith("windows")
+ && AuthenticationJNI.isDllLoaded()) {
try {
long expirationFileTime = 0;
- FedAuthDllInfo dllInfo = AuthenticationJNI.getAccessTokenForWindowsIntegrated(fedAuthInfo.stsurl, fedAuthInfo.spn,
- clientConnectionId.toString(), ActiveDirectoryAuthentication.JDBC_FEDAUTH_CLIENT_ID, expirationFileTime);
+ FedAuthDllInfo dllInfo = AuthenticationJNI.getAccessTokenForWindowsIntegrated(
+ fedAuthInfo.stsurl, fedAuthInfo.spn, clientConnectionId.toString(),
+ ActiveDirectoryAuthentication.JDBC_FEDAUTH_CLIENT_ID, expirationFileTime);
// AccessToken should not be null.
assert null != dllInfo.accessTokenBytes;
@@ -3958,32 +4060,35 @@ else if (authenticationString.trim().equalsIgnoreCase(SqlAuthentication.ActiveDi
// Break out of the retry loop in successful case.
break;
- }
- catch (DLLException adalException) {
+ } catch (DLLException adalException) {
// the sqljdbc_auth.dll return -1 for errorCategory, if unable to load the adalsql.dll
int errorCategory = adalException.GetCategory();
if (-1 == errorCategory) {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_UnableLoadADALSqlDll"));
+ MessageFormat form = new MessageFormat(
+ SQLServerException.getErrString("R_UnableLoadADALSqlDll"));
Object[] msgArgs = {Integer.toHexString(adalException.GetState())};
throw new SQLServerException(form.format(msgArgs), null);
}
int millisecondsRemaining = TimerRemaining(timerExpire);
- if (ActiveDirectoryAuthentication.GET_ACCESS_TOKEN_TANSISENT_ERROR != errorCategory || timerHasExpired(timerExpire)
- || (sleepInterval >= millisecondsRemaining)) {
+ if (ActiveDirectoryAuthentication.GET_ACCESS_TOKEN_TANSISENT_ERROR != errorCategory
+ || timerHasExpired(timerExpire) || (sleepInterval >= millisecondsRemaining)) {
String errorStatus = Integer.toHexString(adalException.GetStatus());
if (connectionlogger.isLoggable(Level.FINER)) {
- connectionlogger.fine(toString() + " SQLServerConnection.getFedAuthToken.AdalException category:" + errorCategory
- + " error: " + errorStatus);
+ connectionlogger.fine(
+ toString() + " SQLServerConnection.getFedAuthToken.AdalException category:"
+ + errorCategory + " error: " + errorStatus);
}
- MessageFormat form1 = new MessageFormat(SQLServerException.getErrString("R_ADALAuthenticationMiddleErrorMessage"));
+ MessageFormat form1 = new MessageFormat(
+ SQLServerException.getErrString("R_ADALAuthenticationMiddleErrorMessage"));
String errorCode = Integer.toHexString(adalException.GetStatus()).toUpperCase();
Object[] msgArgs1 = {errorCode, adalException.GetState()};
- SQLServerException middleException = new SQLServerException(form1.format(msgArgs1), adalException);
+ SQLServerException middleException = new SQLServerException(form1.format(msgArgs1),
+ adalException);
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_ADALExecution"));
Object[] msgArgs = {user, authenticationString};
@@ -3991,22 +4096,23 @@ else if (authenticationString.trim().equalsIgnoreCase(SqlAuthentication.ActiveDi
}
if (connectionlogger.isLoggable(Level.FINER)) {
- connectionlogger.fine(toString() + " SQLServerConnection.getFedAuthToken sleeping: " + sleepInterval + " milliseconds.");
- connectionlogger
- .fine(toString() + " SQLServerConnection.getFedAuthToken remaining: " + millisecondsRemaining + " milliseconds.");
+ connectionlogger.fine(toString() + " SQLServerConnection.getFedAuthToken sleeping: "
+ + sleepInterval + " milliseconds.");
+ connectionlogger.fine(toString() + " SQLServerConnection.getFedAuthToken remaining: "
+ + millisecondsRemaining + " milliseconds.");
}
try {
Thread.sleep(sleepInterval);
- }
- catch (InterruptedException e1) {
+ } catch (InterruptedException e1) {
// re-interrupt the current thread, in order to restore the thread's interrupt status.
Thread.currentThread().interrupt();
}
sleepInterval = sleepInterval * 2;
}
}
- // else choose ADAL4J for integrated authentication. This option is supported for both windows and unix, so we don't need to check the
+ // else choose ADAL4J for integrated authentication. This option is supported for both windows and unix,
+ // so we don't need to check the
// OS version here.
else {
fedAuthToken = SQLServerADAL4JUtils.getSqlFedAuthTokenIntegrated(fedAuthInfo, authenticationString);
@@ -4022,8 +4128,7 @@ else if (authenticationString.trim().equalsIgnoreCase(SqlAuthentication.ActiveDi
/**
* Send the access token to the server.
*/
- private void sendFedAuthToken(FedAuthTokenCommand fedAuthCommand,
- SqlFedAuthToken fedAuthToken,
+ private void sendFedAuthToken(FedAuthTokenCommand fedAuthCommand, SqlFedAuthToken fedAuthToken,
TDSTokenHandler tdsTokenHandler) throws SQLServerException {
assert null != fedAuthToken;
assert null != fedAuthToken.accessToken;
@@ -4055,7 +4160,7 @@ private void sendFedAuthToken(FedAuthTokenCommand fedAuthCommand,
}
final void processFeatureExtAck(TDSReader tdsReader) throws SQLServerException {
- tdsReader.readUnsignedByte(); // Reading FEATUREEXTACK_TOKEN 0xAE
+ tdsReader.readUnsignedByte(); // Reading FEATUREEXTACK_TOKEN 0xAE
// read feature ID
byte featureId;
@@ -4072,12 +4177,10 @@ final void processFeatureExtAck(TDSReader tdsReader) throws SQLServerException {
}
onFeatureExtAck(featureId, data);
}
- }
- while (featureId != TDS.FEATURE_EXT_TERMINATOR);
+ } while (featureId != TDS.FEATURE_EXT_TERMINATOR);
}
- private void onFeatureExtAck(byte featureId,
- byte[] data) throws SQLServerException {
+ private void onFeatureExtAck(byte featureId, byte[] data) throws SQLServerException {
if (null != routingInfo) {
return;
}
@@ -4085,14 +4188,16 @@ private void onFeatureExtAck(byte featureId,
switch (featureId) {
case TDS.TDS_FEATURE_EXT_FEDAUTH: {
if (connectionlogger.isLoggable(Level.FINER)) {
- connectionlogger.fine(toString() + " Received feature extension acknowledgement for federated authentication.");
+ connectionlogger.fine(
+ toString() + " Received feature extension acknowledgement for federated authentication.");
}
if (!federatedAuthenticationRequested) {
if (connectionlogger.isLoggable(Level.SEVERE)) {
connectionlogger.severe(toString() + " Did not request federated authentication.");
}
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_UnrequestedFeatureAckReceived"));
+ MessageFormat form = new MessageFormat(
+ SQLServerException.getErrString("R_UnrequestedFeatureAckReceived"));
Object[] msgArgs = {featureId};
throw new SQLServerException(form.format(msgArgs), null);
}
@@ -4109,16 +4214,19 @@ private void onFeatureExtAck(byte featureId,
connectionlogger.severe(toString()
+ " Federated authentication feature extension ack for ADAL and Security Token includes extra data.");
}
- throw new SQLServerException(SQLServerException.getErrString("R_FedAuthFeatureAckContainsExtraData"), null);
+ throw new SQLServerException(
+ SQLServerException.getErrString("R_FedAuthFeatureAckContainsExtraData"), null);
}
break;
default:
- assert false; // Unknown _fedAuthLibrary type
+ assert false; // Unknown _fedAuthLibrary type
if (connectionlogger.isLoggable(Level.SEVERE)) {
- connectionlogger.severe(toString() + " Attempting to use unknown federated authentication library.");
+ connectionlogger.severe(
+ toString() + " Attempting to use unknown federated authentication library.");
}
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_FedAuthFeatureAckUnknownLibraryType"));
+ MessageFormat form = new MessageFormat(
+ SQLServerException.getErrString("R_FedAuthFeatureAckUnknownLibraryType"));
Object[] msgArgs = {fedAuthFeatureExtensionData.libraryType};
throw new SQLServerException(form.format(msgArgs), null);
}
@@ -4149,7 +4257,8 @@ private void onFeatureExtAck(byte featureId,
}
case TDS.TDS_FEATURE_EXT_DATACLASSIFICATION: {
if (connectionlogger.isLoggable(Level.FINER)) {
- connectionlogger.fine(toString() + " Received feature extension acknowledgement for Data Classification.");
+ connectionlogger
+ .fine(toString() + " Received feature extension acknowledgement for Data Classification.");
}
if (2 != data.length) {
@@ -4165,7 +4274,8 @@ private void onFeatureExtAck(byte featureId,
if (connectionlogger.isLoggable(Level.SEVERE)) {
connectionlogger.severe(toString() + " Invalid version number for Data Classification");
}
- throw new SQLServerException(SQLServerException.getErrString("R_InvalidDataClsVersionNumber"), null);
+ throw new SQLServerException(SQLServerException.getErrString("R_InvalidDataClsVersionNumber"),
+ null);
}
byte enabled = data[1];
@@ -4197,16 +4307,12 @@ private void onFeatureExtAck(byte featureId,
/*
* Executes a DTC command
*/
- private void executeDTCCommand(int requestType,
- byte[] payload,
- String logContext) throws SQLServerException {
+ private void executeDTCCommand(int requestType, byte[] payload, String logContext) throws SQLServerException {
final class DTCCommand extends UninterruptableTDSCommand {
private final int requestType;
private final byte[] payload;
- DTCCommand(int requestType,
- byte[] payload,
- String logContext) {
+ DTCCommand(int requestType, byte[] payload, String logContext) {
super(logContext);
this.requestType = requestType;
this.payload = payload;
@@ -4218,8 +4324,7 @@ final boolean doExecute() throws SQLServerException {
tdsWriter.writeShort((short) requestType);
if (null == payload) {
tdsWriter.writeShort((short) 0);
- }
- else {
+ } else {
assert payload.length <= Short.MAX_VALUE;
tdsWriter.writeShort((short) payload.length);
tdsWriter.writeBytes(payload);
@@ -4248,7 +4353,7 @@ final void JTAUnenlistConnection() throws SQLServerException {
* Enlist this connection's local transaction with MS DTC
*
* @param cookie
- * the cookie identifying the transaction
+ * the cookie identifying the transaction
* @throws SQLServerException
*/
final void JTAEnlistConnection(byte cookie[]) throws SQLServerException {
@@ -4265,7 +4370,7 @@ final void JTAEnlistConnection(byte cookie[]) throws SQLServerException {
* Convert to a String UCS16 encoding.
*
* @param s
- * the string
+ * the string
* @throws SQLServerException
* @return the encoded data
*/
@@ -4288,7 +4393,7 @@ private byte[] toUCS16(String s) throws SQLServerException {
* Encrypt a password for the SQL Server logon.
*
* @param pwd
- * the password
+ * the password
* @return the encryption
*/
private byte[] encryptPassword(String pwd) {
@@ -4312,11 +4417,10 @@ private byte[] encryptPassword(String pwd) {
* Send a TDS 7.x logon packet.
*
* @param secsTimeout
- * (optional) if non-zero, seconds to wait for logon to be sent.
+ * (optional) if non-zero, seconds to wait for logon to be sent.
* @throws SQLServerException
*/
- private void sendLogon(LogonCommand logonCommand,
- SSPIAuthentication authentication,
+ private void sendLogon(LogonCommand logonCommand, SSPIAuthentication authentication,
FederatedAuthenticationFeatureExtensionData fedAuthFeatureExtensionData) throws SQLServerException {
// TDS token handler class for processing logon responses.
//
@@ -4358,8 +4462,7 @@ boolean onLoginAck(TDSReader tdsReader) throws SQLServerException {
return true;
}
- final boolean complete(LogonCommand logonCommand,
- TDSReader tdsReader) throws SQLServerException {
+ final boolean complete(LogonCommand logonCommand, TDSReader tdsReader) throws SQLServerException {
// If we have the login ack already then we're done processing.
if (null != loginAckToken)
return true;
@@ -4392,21 +4495,24 @@ final boolean complete(LogonCommand logonCommand,
// Cannot use both SSPI and FedAuth
assert (!integratedSecurity) || !(federatedAuthenticationInfoRequested || federatedAuthenticationRequested);
// fedAuthFeatureExtensionData provided without fed auth feature request
- assert (null == fedAuthFeatureExtensionData) || (federatedAuthenticationInfoRequested || federatedAuthenticationRequested);
+ assert (null == fedAuthFeatureExtensionData)
+ || (federatedAuthenticationInfoRequested || federatedAuthenticationRequested);
// Fed Auth feature requested without specifying fedAuthFeatureExtensionData.
- assert (null != fedAuthFeatureExtensionData || !(federatedAuthenticationInfoRequested || federatedAuthenticationRequested));
+ assert (null != fedAuthFeatureExtensionData
+ || !(federatedAuthenticationInfoRequested || federatedAuthenticationRequested));
String sUser = activeConnectionProperties.getProperty(SQLServerDriverStringProperty.USER.toString());
String sPwd = activeConnectionProperties.getProperty(SQLServerDriverStringProperty.PASSWORD.toString());
- String appName = activeConnectionProperties.getProperty(SQLServerDriverStringProperty.APPLICATION_NAME.toString());
+ String appName = activeConnectionProperties
+ .getProperty(SQLServerDriverStringProperty.APPLICATION_NAME.toString());
String interfaceLibName = "Microsoft JDBC Driver " + SQLJdbcVersion.major + "." + SQLJdbcVersion.minor;
- String databaseName = activeConnectionProperties.getProperty(SQLServerDriverStringProperty.DATABASE_NAME.toString());
+ String databaseName = activeConnectionProperties
+ .getProperty(SQLServerDriverStringProperty.DATABASE_NAME.toString());
String serverName;
// currentConnectPlaceHolder should not be null here. Still doing the check for extra security.
if (null != currentConnectPlaceHolder) {
serverName = currentConnectPlaceHolder.getServerName();
- }
- else {
+ } else {
serverName = activeConnectionProperties.getProperty(SQLServerDriverStringProperty.SERVER_NAME.toString());
}
@@ -4428,8 +4534,8 @@ final boolean complete(LogonCommand logonCommand,
byte appNameBytes[] = toUCS16(appName);
byte serverNameBytes[] = toUCS16(serverName);
byte interfaceLibNameBytes[] = toUCS16(interfaceLibName);
- byte interfaceLibVersionBytes[] = {(byte) SQLJdbcVersion.build, (byte) SQLJdbcVersion.patch, (byte) SQLJdbcVersion.minor,
- (byte) SQLJdbcVersion.major};
+ byte interfaceLibVersionBytes[] = {(byte) SQLJdbcVersion.build, (byte) SQLJdbcVersion.patch,
+ (byte) SQLJdbcVersion.minor, (byte) SQLJdbcVersion.major};
byte databaseNameBytes[] = toUCS16(databaseName);
byte netAddress[] = new byte[6];
int dataLen = 0;
@@ -4439,24 +4545,21 @@ final boolean complete(LogonCommand logonCommand,
if (serverMajorVersion >= 11) // Denali --> TDS 7.4
{
tdsVersion = TDS.VER_DENALI;
- }
- else if (serverMajorVersion >= 10) // Katmai (10.0) & later 7.3B
+ } else if (serverMajorVersion >= 10) // Katmai (10.0) & later 7.3B
{
tdsVersion = TDS.VER_KATMAI;
- }
- else if (serverMajorVersion >= 9) // Yukon (9.0) --> TDS 7.2 // Prelogin disconnects anything older
+ } else if (serverMajorVersion >= 9) // Yukon (9.0) --> TDS 7.2 // Prelogin disconnects anything older
{
tdsVersion = TDS.VER_YUKON;
- }
- else // Shiloh (8.x) --> TDS 7.1
+ } else // Shiloh (8.x) --> TDS 7.1
{
assert false : "prelogin did not disconnect for the old version: " + serverMajorVersion;
}
TDSWriter tdsWriter = logonCommand.startRequest(TDS.PKT_LOGON70);
- int len2 = TDS_LOGIN_REQUEST_BASE_LEN + hostnameBytes.length + appNameBytes.length + serverNameBytes.length + interfaceLibNameBytes.length
- + databaseNameBytes.length + secBlob.length + 4;// AE is always on;
+ int len2 = TDS_LOGIN_REQUEST_BASE_LEN + hostnameBytes.length + appNameBytes.length + serverNameBytes.length
+ + interfaceLibNameBytes.length + databaseNameBytes.length + secBlob.length + 4;// AE is always on;
// only add lengths of password and username if not using SSPI or requesting federated authentication info
if (!integratedSecurity && !(federatedAuthenticationInfoRequested || federatedAuthenticationRequested)) {
@@ -4472,9 +4575,9 @@ else if (serverMajorVersion >= 9) // Yukon (9.0) --> TDS 7.2 // Prelogin disconn
// Data Classification is always enabled (by default)
len2 += writeDataClassificationFeatureRequest(false, tdsWriter);
-
+
len2 = len2 + writeUTF8SupportFeatureRequest(false, tdsWriter);
-
+
len2 = len2 + 1; // add 1 to length because of FeatureEx terminator
// Length of entire Login 7 packet
@@ -4485,26 +4588,28 @@ else if (serverMajorVersion >= 9) // Yukon (9.0) --> TDS 7.2 // Prelogin disconn
tdsWriter.writeInt(0); // Client process ID (0 = ??)
tdsWriter.writeInt(0); // Primary server connection ID
- tdsWriter.writeByte((byte) ( // OptionFlags1:
+ tdsWriter.writeByte((byte) ( // OptionFlags1:
TDS.LOGIN_OPTION1_ORDER_X86 | // X86 byte order for numeric & datetime types
TDS.LOGIN_OPTION1_CHARSET_ASCII | // ASCII character set
TDS.LOGIN_OPTION1_FLOAT_IEEE_754 | // IEEE 754 floating point representation
TDS.LOGIN_OPTION1_DUMPLOAD_ON | // Require dump/load BCP capabilities
TDS.LOGIN_OPTION1_USE_DB_OFF | // No ENVCHANGE after USE DATABASE
TDS.LOGIN_OPTION1_INIT_DB_FATAL | // Fail connection if initial database change fails
- TDS.LOGIN_OPTION1_SET_LANG_ON // Warn on SET LANGUAGE stmt
+ TDS.LOGIN_OPTION1_SET_LANG_ON // Warn on SET LANGUAGE stmt
));
- tdsWriter.writeByte((byte) ( // OptionFlags2:
+ tdsWriter.writeByte((byte) ( // OptionFlags2:
TDS.LOGIN_OPTION2_INIT_LANG_FATAL | // Fail connection if initial language change fails
- TDS.LOGIN_OPTION2_ODBC_ON | // Use ODBC defaults (ANSI_DEFAULTS ON, IMPLICIT_TRANSACTIONS OFF, TEXTSIZE inf, ROWCOUNT inf)
- (integratedSecurity ? // Use integrated security if requested
- TDS.LOGIN_OPTION2_INTEGRATED_SECURITY_ON : TDS.LOGIN_OPTION2_INTEGRATED_SECURITY_OFF)));
+ TDS.LOGIN_OPTION2_ODBC_ON | // Use ODBC defaults (ANSI_DEFAULTS ON, IMPLICIT_TRANSACTIONS OFF, TEXTSIZE
+ // inf, ROWCOUNT inf)
+ (integratedSecurity ? // Use integrated security if requested
+ TDS.LOGIN_OPTION2_INTEGRATED_SECURITY_ON
+ : TDS.LOGIN_OPTION2_INTEGRATED_SECURITY_OFF)));
// TypeFlags
- tdsWriter.writeByte((byte) (TDS.LOGIN_SQLTYPE_DEFAULT
- | (applicationIntent != null && applicationIntent.equals(ApplicationIntent.READ_ONLY) ? TDS.LOGIN_READ_ONLY_INTENT
- : TDS.LOGIN_READ_WRITE_INTENT)));
+ tdsWriter.writeByte((byte) (TDS.LOGIN_SQLTYPE_DEFAULT | (applicationIntent != null
+ && applicationIntent.equals(ApplicationIntent.READ_ONLY) ? TDS.LOGIN_READ_ONLY_INTENT
+ : TDS.LOGIN_READ_WRITE_INTENT)));
// OptionFlags3
byte colEncSetting;
@@ -4512,16 +4617,16 @@ else if (serverMajorVersion >= 9) // Yukon (9.0) --> TDS 7.2 // Prelogin disconn
{
colEncSetting = TDS.LOGIN_OPTION3_FEATURE_EXTENSION;
}
- tdsWriter.writeByte(
- (byte) (TDS.LOGIN_OPTION3_DEFAULT | colEncSetting | ((serverMajorVersion >= 10) ? TDS.LOGIN_OPTION3_UNKNOWN_COLLATION_HANDLING : 0) // Accept
- // unknown
- // collations
- // from
- // Katmai
- // &
- // later
- // servers
- ));
+ tdsWriter.writeByte((byte) (TDS.LOGIN_OPTION3_DEFAULT | colEncSetting
+ | ((serverMajorVersion >= 10) ? TDS.LOGIN_OPTION3_UNKNOWN_COLLATION_HANDLING : 0) // Accept
+ // unknown
+ // collations
+ // from
+ // Katmai
+ // &
+ // later
+ // servers
+ ));
tdsWriter.writeInt((byte) 0); // Client time zone
tdsWriter.writeInt((byte) 0); // Client LCID
@@ -4544,8 +4649,7 @@ else if (serverMajorVersion >= 9) // Yukon (9.0) --> TDS 7.2 // Prelogin disconn
tdsWriter.writeShort((short) (sPwd == null ? 0 : sPwd.length()));
dataLen += passwordLen;
- }
- else {
+ } else {
// User and Password are null
tdsWriter.writeShort((short) (0));
tdsWriter.writeShort((short) (0));
@@ -4594,13 +4698,11 @@ else if (serverMajorVersion >= 9) // Yukon (9.0) --> TDS 7.2 // Prelogin disconn
if (!integratedSecurity) {
tdsWriter.writeShort((short) 0);
tdsWriter.writeShort((short) 0);
- }
- else {
+ } else {
tdsWriter.writeShort((short) (TDS_LOGIN_REQUEST_BASE_LEN + dataLen));
if (USHRT_MAX <= secBlob.length) {
tdsWriter.writeShort((short) (USHRT_MAX));
- }
- else
+ } else
tdsWriter.writeShort((short) (secBlob.length));
}
@@ -4632,16 +4734,16 @@ else if (serverMajorVersion >= 9) // Yukon (9.0) --> TDS 7.2 // Prelogin disconn
}
tdsWriter.setDataLoggable(true);
- tdsWriter.writeBytes(appNameBytes); // application name
- tdsWriter.writeBytes(serverNameBytes); // server name
+ tdsWriter.writeBytes(appNameBytes); // application name
+ tdsWriter.writeBytes(serverNameBytes); // server name
// AE is always ON
{
tdsWriter.writeInt(aeOffset);
}
- tdsWriter.writeBytes(interfaceLibNameBytes); // interfaceLibName
- tdsWriter.writeBytes(databaseNameBytes); // databaseName
+ tdsWriter.writeBytes(interfaceLibNameBytes); // interfaceLibName
+ tdsWriter.writeBytes(databaseNameBytes); // databaseName
// Don't allow user credentials to be logged
tdsWriter.setDataLoggable(false);
@@ -4668,8 +4770,7 @@ else if (serverMajorVersion >= 9) // Yukon (9.0) --> TDS 7.2 // Prelogin disconn
do {
tdsReader = logonCommand.startResponse();
TDSParser.parse(tdsReader, logonProcessor);
- }
- while (!logonProcessor.complete(logonCommand, tdsReader));
+ } while (!logonProcessor.complete(logonCommand, tdsReader));
}
/* --------------- JDBC 3.0 ------------- */
@@ -4687,33 +4788,34 @@ private void checkValidHoldability(int holdability) throws SQLServerException {
/**
* Checks that the proposed statement holdability matches this connection's current holdability.
*
- * SQL Server doesn't support per-statement holdability, so the statement's proposed holdability must match its parent connection's. Note that
- * this doesn't stop anyone from changing the holdability of the connection after creating the statement. Apps should always call
- * Statement.getResultSetHoldability to check the holdability of ResultSets that would be created, and/or ResultSet.getHoldability to check the
- * holdability of an existing ResultSet.
+ * SQL Server doesn't support per-statement holdability, so the statement's proposed holdability must match its
+ * parent connection's. Note that this doesn't stop anyone from changing the holdability of the connection after
+ * creating the statement. Apps should always call Statement.getResultSetHoldability to check the holdability of
+ * ResultSets that would be created, and/or ResultSet.getHoldability to check the holdability of an existing
+ * ResultSet.
*/
private void checkMatchesCurrentHoldability(int resultSetHoldability) throws SQLServerException {
if (resultSetHoldability != this.holdability) {
- SQLServerException.makeFromDriverError(this, this, SQLServerException.getErrString("R_sqlServerHoldability"), null, false);
+ SQLServerException.makeFromDriverError(this, this,
+ SQLServerException.getErrString("R_sqlServerHoldability"), null, false);
}
}
@Override
- public Statement createStatement(int nType,
- int nConcur,
- int resultSetHoldability) throws SQLServerException {
- loggerExternal.entering(getClassNameLogging(), "createStatement", new Object[] {nType, nConcur, resultSetHoldability});
- Statement st = createStatement(nType, nConcur, resultSetHoldability, SQLServerStatementColumnEncryptionSetting.UseConnectionSetting);
+ public Statement createStatement(int nType, int nConcur, int resultSetHoldability) throws SQLServerException {
+ loggerExternal.entering(getClassNameLogging(), "createStatement",
+ new Object[] {nType, nConcur, resultSetHoldability});
+ Statement st = createStatement(nType, nConcur, resultSetHoldability,
+ SQLServerStatementColumnEncryptionSetting.UseConnectionSetting);
loggerExternal.exiting(getClassNameLogging(), "createStatement", st);
return st;
}
@Override
- public Statement createStatement(int nType,
- int nConcur,
- int resultSetHoldability,
+ public Statement createStatement(int nType, int nConcur, int resultSetHoldability,
SQLServerStatementColumnEncryptionSetting stmtColEncSetting) throws SQLServerException {
- loggerExternal.entering(getClassNameLogging(), "createStatement", new Object[] {nType, nConcur, resultSetHoldability, stmtColEncSetting});
+ loggerExternal.entering(getClassNameLogging(), "createStatement",
+ new Object[] {nType, nConcur, resultSetHoldability, stmtColEncSetting});
checkClosed();
checkValidHoldability(resultSetHoldability);
checkMatchesCurrentHoldability(resultSetHoldability);
@@ -4726,11 +4828,10 @@ public Statement createStatement(int nType,
}
@Override
- public PreparedStatement prepareStatement(java.lang.String sql,
- int nType,
- int nConcur,
+ public PreparedStatement prepareStatement(java.lang.String sql, int nType, int nConcur,
int resultSetHoldability) throws SQLServerException {
- loggerExternal.entering(getClassNameLogging(), "prepareStatement", new Object[] {nType, nConcur, resultSetHoldability});
+ loggerExternal.entering(getClassNameLogging(), "prepareStatement",
+ new Object[] {nType, nConcur, resultSetHoldability});
PreparedStatement st = prepareStatement(sql, nType, nConcur, resultSetHoldability,
SQLServerStatementColumnEncryptionSetting.UseConnectionSetting);
loggerExternal.exiting(getClassNameLogging(), "prepareStatement", st);
@@ -4738,12 +4839,10 @@ public PreparedStatement prepareStatement(java.lang.String sql,
}
@Override
- public PreparedStatement prepareStatement(java.lang.String sql,
- int nType,
- int nConcur,
- int resultSetHoldability,
+ public PreparedStatement prepareStatement(java.lang.String sql, int nType, int nConcur, int resultSetHoldability,
SQLServerStatementColumnEncryptionSetting stmtColEncSetting) throws SQLServerException {
- loggerExternal.entering(getClassNameLogging(), "prepareStatement", new Object[] {nType, nConcur, resultSetHoldability, stmtColEncSetting});
+ loggerExternal.entering(getClassNameLogging(), "prepareStatement",
+ new Object[] {nType, nConcur, resultSetHoldability, stmtColEncSetting});
checkClosed();
checkValidHoldability(resultSetHoldability);
checkMatchesCurrentHoldability(resultSetHoldability);
@@ -4759,23 +4858,21 @@ public PreparedStatement prepareStatement(java.lang.String sql,
}
@Override
- public CallableStatement prepareCall(String sql,
- int nType,
- int nConcur,
+ public CallableStatement prepareCall(String sql, int nType, int nConcur,
int resultSetHoldability) throws SQLServerException {
- loggerExternal.entering(getClassNameLogging(), "prepareStatement", new Object[] {nType, nConcur, resultSetHoldability});
- CallableStatement st = prepareCall(sql, nType, nConcur, resultSetHoldability, SQLServerStatementColumnEncryptionSetting.UseConnectionSetting);
+ loggerExternal.entering(getClassNameLogging(), "prepareStatement",
+ new Object[] {nType, nConcur, resultSetHoldability});
+ CallableStatement st = prepareCall(sql, nType, nConcur, resultSetHoldability,
+ SQLServerStatementColumnEncryptionSetting.UseConnectionSetting);
loggerExternal.exiting(getClassNameLogging(), "prepareCall", st);
return st;
}
@Override
- public CallableStatement prepareCall(String sql,
- int nType,
- int nConcur,
- int resultSetHoldability,
+ public CallableStatement prepareCall(String sql, int nType, int nConcur, int resultSetHoldability,
SQLServerStatementColumnEncryptionSetting stmtColEncSetiing) throws SQLServerException {
- loggerExternal.entering(getClassNameLogging(), "prepareStatement", new Object[] {nType, nConcur, resultSetHoldability, stmtColEncSetiing});
+ loggerExternal.entering(getClassNameLogging(), "prepareStatement",
+ new Object[] {nType, nConcur, resultSetHoldability, stmtColEncSetiing});
checkClosed();
checkValidHoldability(resultSetHoldability);
checkMatchesCurrentHoldability(resultSetHoldability);
@@ -4793,8 +4890,7 @@ public CallableStatement prepareCall(String sql,
/* JDBC 3.0 Auto generated keys */
@Override
- public PreparedStatement prepareStatement(String sql,
- int flag) throws SQLServerException {
+ public PreparedStatement prepareStatement(String sql, int flag) throws SQLServerException {
loggerExternal.entering(getClassNameLogging(), "prepareStatement", new Object[] {sql, flag});
SQLServerPreparedStatement ps = (SQLServerPreparedStatement) prepareStatement(sql, flag,
@@ -4805,21 +4901,19 @@ public PreparedStatement prepareStatement(String sql,
}
@Override
- public PreparedStatement prepareStatement(String sql,
- int flag,
+ public PreparedStatement prepareStatement(String sql, int flag,
SQLServerStatementColumnEncryptionSetting stmtColEncSetting) throws SQLServerException {
loggerExternal.entering(getClassNameLogging(), "prepareStatement", new Object[] {sql, flag, stmtColEncSetting});
checkClosed();
- SQLServerPreparedStatement ps = (SQLServerPreparedStatement) prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY,
- stmtColEncSetting);
+ SQLServerPreparedStatement ps = (SQLServerPreparedStatement) prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY,
+ ResultSet.CONCUR_READ_ONLY, stmtColEncSetting);
ps.bRequestedGeneratedKeys = (flag == Statement.RETURN_GENERATED_KEYS);
loggerExternal.exiting(getClassNameLogging(), "prepareStatement", ps);
return ps;
}
@Override
- public PreparedStatement prepareStatement(String sql,
- int[] columnIndexes) throws SQLServerException {
+ public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLServerException {
loggerExternal.entering(getClassNameLogging(), "prepareStatement", new Object[] {sql, columnIndexes});
SQLServerPreparedStatement ps = (SQLServerPreparedStatement) prepareStatement(sql, columnIndexes,
SQLServerStatementColumnEncryptionSetting.UseConnectionSetting);
@@ -4829,25 +4923,25 @@ public PreparedStatement prepareStatement(String sql,
}
@Override
- public PreparedStatement prepareStatement(String sql,
- int[] columnIndexes,
+ public PreparedStatement prepareStatement(String sql, int[] columnIndexes,
SQLServerStatementColumnEncryptionSetting stmtColEncSetting) throws SQLServerException {
- loggerExternal.entering(getClassNameLogging(), "prepareStatement", new Object[] {sql, columnIndexes, stmtColEncSetting});
+ loggerExternal.entering(getClassNameLogging(), "prepareStatement",
+ new Object[] {sql, columnIndexes, stmtColEncSetting});
checkClosed();
if (columnIndexes == null || columnIndexes.length != 1) {
- SQLServerException.makeFromDriverError(this, this, SQLServerException.getErrString("R_invalidColumnArrayLength"), null, false);
+ SQLServerException.makeFromDriverError(this, this,
+ SQLServerException.getErrString("R_invalidColumnArrayLength"), null, false);
}
- SQLServerPreparedStatement ps = (SQLServerPreparedStatement) prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY,
- stmtColEncSetting);
+ SQLServerPreparedStatement ps = (SQLServerPreparedStatement) prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY,
+ ResultSet.CONCUR_READ_ONLY, stmtColEncSetting);
ps.bRequestedGeneratedKeys = true;
loggerExternal.exiting(getClassNameLogging(), "prepareStatement", ps);
return ps;
}
@Override
- public PreparedStatement prepareStatement(String sql,
- String[] columnNames) throws SQLServerException {
+ public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLServerException {
loggerExternal.entering(getClassNameLogging(), "prepareStatement", new Object[] {sql, columnNames});
SQLServerPreparedStatement ps = (SQLServerPreparedStatement) prepareStatement(sql, columnNames,
@@ -4858,16 +4952,17 @@ public PreparedStatement prepareStatement(String sql,
}
@Override
- public PreparedStatement prepareStatement(String sql,
- String[] columnNames,
+ public PreparedStatement prepareStatement(String sql, String[] columnNames,
SQLServerStatementColumnEncryptionSetting stmtColEncSetting) throws SQLServerException {
- loggerExternal.entering(getClassNameLogging(), "prepareStatement", new Object[] {sql, columnNames, stmtColEncSetting});
+ loggerExternal.entering(getClassNameLogging(), "prepareStatement",
+ new Object[] {sql, columnNames, stmtColEncSetting});
checkClosed();
if (columnNames == null || columnNames.length != 1) {
- SQLServerException.makeFromDriverError(this, this, SQLServerException.getErrString("R_invalidColumnArrayLength"), null, false);
+ SQLServerException.makeFromDriverError(this, this,
+ SQLServerException.getErrString("R_invalidColumnArrayLength"), null, false);
}
- SQLServerPreparedStatement ps = (SQLServerPreparedStatement) prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY,
- stmtColEncSetting);
+ SQLServerPreparedStatement ps = (SQLServerPreparedStatement) prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY,
+ ResultSet.CONCUR_READ_ONLY, stmtColEncSetting);
ps.bRequestedGeneratedKeys = true;
loggerExternal.exiting(getClassNameLogging(), "prepareStatement", ps);
return ps;
@@ -4883,7 +4978,8 @@ public void releaseSavepoint(Savepoint savepoint) throws SQLException {
final private Savepoint setNamedSavepoint(String sName) throws SQLServerException {
if (true == databaseAutoCommitMode) {
- SQLServerException.makeFromDriverError(this, this, SQLServerException.getErrString("R_cantSetSavepoint"), null, false);
+ SQLServerException.makeFromDriverError(this, this, SQLServerException.getErrString("R_cantSetSavepoint"),
+ null, false);
}
SQLServerSavepoint s = new SQLServerSavepoint(this, sName);
@@ -4895,8 +4991,8 @@ final private Savepoint setNamedSavepoint(String sName) throws SQLServerExceptio
// This is because the server creates a nested transaction (@@TRANCOUNT = 2) rather
// than just the outer transaction (@@TRANCOUNT = 1). Should this limitation ever
// change, the T-SQL below should still work.
- connectionCommand("IF @@TRANCOUNT = 0 BEGIN BEGIN TRAN IF @@TRANCOUNT = 2 COMMIT TRAN END SAVE TRAN " + Util.escapeSQLId(s.getLabel()),
- "setSavepoint");
+ connectionCommand("IF @@TRANCOUNT = 0 BEGIN BEGIN TRAN IF @@TRANCOUNT = 2 COMMIT TRAN END SAVE TRAN "
+ + Util.escapeSQLId(s.getLabel()), "setSavepoint");
return s;
}
@@ -4933,9 +5029,11 @@ public void rollback(Savepoint s) throws SQLServerException {
}
checkClosed();
if (true == databaseAutoCommitMode) {
- SQLServerException.makeFromDriverError(this, this, SQLServerException.getErrString("R_cantInvokeRollback"), null, false);
+ SQLServerException.makeFromDriverError(this, this, SQLServerException.getErrString("R_cantInvokeRollback"),
+ null, false);
}
- connectionCommand("IF @@TRANCOUNT > 0 ROLLBACK TRAN " + Util.escapeSQLId(((SQLServerSavepoint) s).getLabel()), "rollbackSavepoint");
+ connectionCommand("IF @@TRANCOUNT > 0 ROLLBACK TRAN " + Util.escapeSQLId(((SQLServerSavepoint) s).getLabel()),
+ "rollbackSavepoint");
loggerExternal.exiting(getClassNameLogging(), "rollback");
}
@@ -4958,10 +5056,12 @@ public void setHoldability(int holdability) throws SQLServerException {
checkClosed();
if (this.holdability != holdability) {
- assert ResultSet.HOLD_CURSORS_OVER_COMMIT == holdability || ResultSet.CLOSE_CURSORS_AT_COMMIT == holdability : "invalid holdability "
- + holdability;
+ assert ResultSet.HOLD_CURSORS_OVER_COMMIT == holdability
+ || ResultSet.CLOSE_CURSORS_AT_COMMIT == holdability : "invalid holdability " + holdability;
- connectionCommand((holdability == ResultSet.CLOSE_CURSORS_AT_COMMIT) ? "SET CURSOR_CLOSE_ON_COMMIT ON" : "SET CURSOR_CLOSE_ON_COMMIT OFF",
+ connectionCommand(
+ (holdability == ResultSet.CLOSE_CURSORS_AT_COMMIT) ? "SET CURSOR_CLOSE_ON_COMMIT ON"
+ : "SET CURSOR_CLOSE_ON_COMMIT OFF",
"setHoldability");
this.holdability = holdability;
@@ -4979,8 +5079,7 @@ public int getNetworkTimeout() throws SQLException {
int timeout = 0;
try {
timeout = tdsChannel.getNetworkTimeout();
- }
- catch (IOException ioe) {
+ } catch (IOException ioe) {
terminate(SQLServerException.DRIVER_ERROR_IO_FAILED, ioe.getMessage(), ioe);
}
@@ -4989,8 +5088,7 @@ public int getNetworkTimeout() throws SQLException {
}
@Override
- public void setNetworkTimeout(Executor executor,
- int timeout) throws SQLException {
+ public void setNetworkTimeout(Executor executor, int timeout) throws SQLException {
loggerExternal.entering(getClassNameLogging(), "setNetworkTimeout", timeout);
if (timeout < 0) {
@@ -5007,8 +5105,7 @@ public void setNetworkTimeout(Executor executor,
try {
SQLPermission perm = new SQLPermission(SET_NETWORK_TIMEOUT_PERM);
secMgr.checkPermission(perm);
- }
- catch (SecurityException ex) {
+ } catch (SecurityException ex) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_permissionDenied"));
Object[] msgArgs = {SET_NETWORK_TIMEOUT_PERM};
SQLServerException.makeFromDriverError(this, this, form.format(msgArgs), null, true);
@@ -5017,8 +5114,7 @@ public void setNetworkTimeout(Executor executor,
try {
tdsChannel.setNetworkTimeout(timeout);
- }
- catch (IOException ioe) {
+ } catch (IOException ioe) {
terminate(SQLServerException.DRIVER_ERROR_IO_FAILED, ioe.getMessage(), ioe);
}
@@ -5040,19 +5136,18 @@ public String getSchema() throws SQLException {
if (resultSet != null) {
resultSet.next();
return resultSet.getString(1);
+ } else {
+ SQLServerException.makeFromDriverError(this, this, SQLServerException.getErrString("R_getSchemaError"),
+ null, true);
}
- else {
- SQLServerException.makeFromDriverError(this, this, SQLServerException.getErrString("R_getSchemaError"), null, true);
- }
- }
- catch (SQLException e) {
+ } catch (SQLException e) {
if (isSessionUnAvailable()) {
throw e;
}
- SQLServerException.makeFromDriverError(this, this, SQLServerException.getErrString("R_getSchemaError"), null, true);
- }
- finally {
+ SQLServerException.makeFromDriverError(this, this, SQLServerException.getErrString("R_getSchemaError"),
+ null, true);
+ } finally {
if (resultSet != null) {
resultSet.close();
}
@@ -5080,8 +5175,7 @@ public void setSendTimeAsDatetime(boolean sendTimeAsDateTimeValue) {
}
@Override
- public java.sql.Array createArrayOf(String typeName,
- Object[] elements) throws SQLException {
+ public java.sql.Array createArrayOf(String typeName, Object[] elements) throws SQLException {
SQLServerException.throwNotSupportedException(this, null);
return null;
}
@@ -5115,8 +5209,7 @@ public SQLXML createSQLXML() throws SQLException {
}
@Override
- public java.sql.Struct createStruct(String typeName,
- Object[] attributes) throws SQLException {
+ public java.sql.Struct createStruct(String typeName, Object[] attributes) throws SQLException {
SQLServerException.throwNotSupportedException(this, null);
return null;
}
@@ -5148,8 +5241,7 @@ public void setClientInfo(Properties properties) throws SQLClientInfoException {
// This function is only marked as throwing only SQLClientInfoException so the conversion is necessary
try {
checkClosed();
- }
- catch (SQLServerException ex) {
+ } catch (SQLServerException ex) {
SQLClientInfoException info = new SQLClientInfoException();
info.initCause(ex);
throw info;
@@ -5167,14 +5259,12 @@ public void setClientInfo(Properties properties) throws SQLClientInfoException {
}
@Override
- public void setClientInfo(String name,
- String value) throws SQLClientInfoException {
+ public void setClientInfo(String name, String value) throws SQLClientInfoException {
loggerExternal.entering(getClassNameLogging(), "setClientInfo", new Object[] {name, value});
// This function is only marked as throwing only SQLClientInfoException so the conversion is necessary
try {
checkClosed();
- }
- catch (SQLServerException ex) {
+ } catch (SQLServerException ex) {
SQLClientInfoException info = new SQLClientInfoException();
info.initCause(ex);
throw info;
@@ -5188,22 +5278,24 @@ public void setClientInfo(String name,
/**
* Determine whether the connection is still valid.
*
- * The driver shall submit a query on the connection or use some other mechanism that positively verifies the connection is still valid when this
- * method is called.
+ * The driver shall submit a query on the connection or use some other mechanism that positively verifies the
+ * connection is still valid when this method is called.
*
- * The query submitted by the driver to validate the connection shall be executed in the context of the current transaction.
+ * The query submitted by the driver to validate the connection shall be executed in the context of the current
+ * transaction.
*
* @param timeout
- * The time in seconds to wait for the database operation used to validate the connection to complete. If the timeout period expires
- * before the operation completes, this method returns false. A value of 0 indicates a timeout is not applied to the database
- * operation. Note that if the value is 0, the call to isValid may block indefinitely if the connection is not valid...
+ * The time in seconds to wait for the database operation used to validate the connection to complete. If the
+ * timeout period expires before the operation completes, this method returns false. A value of 0 indicates a
+ * timeout is not applied to the database operation. Note that if the value is 0, the call to isValid may
+ * block indefinitely if the connection is not valid...
*
* @return true if the connection has not been closed and is still valid.
*
* @throws SQLException
- * if the value supplied for the timeout is less than 0.
+ * if the value supplied for the timeout is less than 0.
*/
- @Override
+ @Override
public boolean isValid(int timeout) throws SQLException {
boolean isValid = false;
@@ -5221,8 +5313,8 @@ public boolean isValid(int timeout) throws SQLException {
return false;
try {
- SQLServerStatement stmt = new SQLServerStatement(this, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY,
- SQLServerStatementColumnEncryptionSetting.UseConnectionSetting);
+ SQLServerStatement stmt = new SQLServerStatement(this, ResultSet.TYPE_FORWARD_ONLY,
+ ResultSet.CONCUR_READ_ONLY, SQLServerStatementColumnEncryptionSetting.UseConnectionSetting);
// If asked, limit the time to wait for the query to complete.
if (0 != timeout)
@@ -5235,8 +5327,7 @@ public boolean isValid(int timeout) throws SQLException {
stmt.executeQueryInternal("SELECT 1");
stmt.close();
isValid = true;
- }
- catch (SQLException e) {
+ } catch (SQLException e) {
// Do not propagate SQLExceptions from query execution or statement closure.
// The connection is considered to be invalid if the statement fails to close,
// even though query execution succeeded.
@@ -5261,8 +5352,7 @@ public T unwrap(Class iface) throws SQLException {
T t;
try {
t = iface.cast(this);
- }
- catch (ClassCastException e) {
+ } catch (ClassCastException e) {
SQLServerException newe = new SQLServerException(e.getMessage(), e);
throw newe;
@@ -5282,6 +5372,7 @@ public T unwrap(Class iface) throws SQLException {
private int originalServerPreparedStatementDiscardThreshold;
private Boolean originalEnablePrepareOnFirstPreparedStatementCall;
private String originalSCatalog;
+ private boolean originalUseBulkCopyForBatchInsert;
private volatile SQLWarning originalSqlWarnings;
private List openStatements;
@@ -5299,6 +5390,7 @@ protected void beginRequestInternal() throws SQLException {
originalServerPreparedStatementDiscardThreshold = getServerPreparedStatementDiscardThreshold();
originalEnablePrepareOnFirstPreparedStatementCall = getEnablePrepareOnFirstPreparedStatementCall();
originalSCatalog = sCatalog;
+ originalUseBulkCopyForBatchInsert = getUseBulkCopyForBatchInsert();
originalSqlWarnings = sqlWarnings;
openStatements = new LinkedList();
requestStarted = true;
@@ -5344,11 +5436,13 @@ protected void endRequestInternal() throws SQLException {
if (!sCatalog.equals(originalSCatalog)) {
setCatalog(originalSCatalog);
}
+ if (getUseBulkCopyForBatchInsert() != originalUseBulkCopyForBatchInsert) {
+ setUseBulkCopyForBatchInsert(originalUseBulkCopyForBatchInsert);
+ }
sqlWarnings = originalSqlWarnings;
if (null != openStatements) {
while (!openStatements.isEmpty()) {
- try (Statement st = openStatements.get(0)) {
- }
+ try (Statement st = openStatements.get(0)) {}
}
openStatements.clear();
}
@@ -5359,17 +5453,16 @@ protected void endRequestInternal() throws SQLException {
}
/**
- * Replace JDBC syntax parameter markets '?' with SQL Server paramter markers @p1, @p2 etc...
+ * Replaces JDBC syntax parameter markets '?' with SQL Server paramter markers @p1, @p2 etc...
*
* @param sql
- * the user's SQL
+ * the user's SQL
* @throws SQLServerException
* @return the returned syntax
*/
static final char[] OUT = {' ', 'O', 'U', 'T'};
- String replaceParameterMarkers(String sqlSrc,
- Parameter[] params,
+ String replaceParameterMarkers(String sqlSrc, int[] paramPositions, Parameter[] params,
boolean isReturnValueSyntax) throws SQLServerException {
final int MAX_PARAM_NAME_LEN = 6;
char[] sqlDst = new char[sqlSrc.length() + params.length * (MAX_PARAM_NAME_LEN + OUT.length)];
@@ -5379,7 +5472,7 @@ String replaceParameterMarkers(String sqlSrc,
int paramIndex = 0;
while (true) {
- int srcEnd = ParameterUtils.scanSQLForChar('?', sqlSrc, srcBegin);
+ int srcEnd = (paramIndex >= paramPositions.length) ? sqlSrc.length() : paramPositions[paramIndex];
sqlSrc.getChars(srcBegin, srcEnd, sqlDst, dstBegin);
dstBegin += srcEnd - srcBegin;
@@ -5404,25 +5497,22 @@ String replaceParameterMarkers(String sqlSrc,
}
/**
- * Make a SQL Server style parameter name.
+ * Makes a SQL Server style parameter name.
*
* @param nParam
- * the parameter number
+ * the parameter number
* @param name
- * the paramter name
+ * the paramter name
* @param offset
* @return int
*/
- static int makeParamName(int nParam,
- char[] name,
- int offset) {
+ static int makeParamName(int nParam, char[] name, int offset) {
name[offset + 0] = '@';
name[offset + 1] = 'P';
if (nParam < 10) {
name[offset + 2] = (char) ('0' + nParam);
return 3;
- }
- else {
+ } else {
if (nParam < 100) {
int nBase = 2;
while (true) { // make a char[] representation of the param number 2.26
@@ -5433,8 +5523,7 @@ static int makeParamName(int nParam,
}
nBase++;
}
- }
- else {
+ } else {
String sParam = "" + nParam;
sParam.getChars(0, sParam.length(), name, offset + 2);
return 2 + sParam.length();
@@ -5442,11 +5531,12 @@ static int makeParamName(int nParam,
}
}
- // Notify any interested parties (e.g. pooling managers) of a ConnectionEvent activity
- // on the connection. Calling notifyPooledConnection with null event will place this
- // connection back in the pool. Calling notifyPooledConnection with a non-null event is
- // used to notify the pooling manager that the connection is bad and should be removed
- // from the pool.
+ /**
+ * Notify any interested parties (e.g. pooling managers) of a ConnectionEvent activity on the connection. Calling
+ * notifyPooledConnection with null event will place this connection back in the pool. Calling
+ * notifyPooledConnection with a non-null event is used to notify the pooling manager that the connection is bad and
+ * should be removed from the pool.
+ */
void notifyPooledConnection(SQLServerException e) {
synchronized (this) {
if (null != pooledConnectionParent) {
@@ -5464,19 +5554,18 @@ void DetachFromPool() {
}
/**
- * Determine the listening port of a named SQL Server instance.
+ * Determines the listening port of a named SQL Server instance.
*
* @param server
- * the server name
+ * the server name
* @param instanceName
- * the instance
+ * the instance
* @throws SQLServerException
* @return the instance's port
*/
private static final int BROWSER_PORT = 1434;
- String getInstancePort(String server,
- String instanceName) throws SQLServerException {
+ String getInstancePort(String server, String instanceName) throws SQLServerException {
String browserResult = null;
DatagramSocket datagramSocket = null;
String lastErrorMessage = null;
@@ -5488,8 +5577,7 @@ String getInstancePort(String server,
try {
datagramSocket = new DatagramSocket();
datagramSocket.setSoTimeout(1000);
- }
- catch (SocketException socketException) {
+ } catch (SocketException socketException) {
// Errors creating a local socket
// Log the error and bail.
lastErrorMessage = "Unable to create local datagram socket";
@@ -5497,13 +5585,15 @@ String getInstancePort(String server,
}
// Second, we need to get the IP address of the server to which we'll send the UDP request.
- // This may require a DNS lookup, which may fail due to transient conditions, so retry after logging the first time.
+ // This may require a DNS lookup, which may fail due to transient conditions, so retry after logging the
+ // first time.
// send UDP packet
assert null != datagramSocket;
try {
if (multiSubnetFailover) {
- // If instance name is specified along with multiSubnetFailover, we get all IPs resolved by server name
+ // If instance name is specified along with multiSubnetFailover, we get all IPs resolved by server
+ // name
InetAddress[] inetAddrs = InetAddress.getAllByName(server);
assert null != inetAddrs;
for (InetAddress inetAddr : inetAddrs) {
@@ -5511,18 +5601,18 @@ String getInstancePort(String server,
try {
byte sendBuffer[] = (" " + instanceName).getBytes();
sendBuffer[0] = 4;
- DatagramPacket udpRequest = new DatagramPacket(sendBuffer, sendBuffer.length, inetAddr, BROWSER_PORT);
+ DatagramPacket udpRequest = new DatagramPacket(sendBuffer, sendBuffer.length, inetAddr,
+ BROWSER_PORT);
datagramSocket.send(udpRequest);
- }
- catch (IOException ioException) {
- lastErrorMessage = "Error sending SQL Server Browser Service UDP request to address: " + inetAddr + ", port: "
- + BROWSER_PORT;
+ } catch (IOException ioException) {
+ lastErrorMessage = "Error sending SQL Server Browser Service UDP request to address: "
+ + inetAddr + ", port: " + BROWSER_PORT;
throw ioException;
}
}
- }
- else {
- // If instance name is not specified along with multiSubnetFailover, we resolve only the first IP for server name
+ } else {
+ // If instance name is not specified along with multiSubnetFailover, we resolve only the first IP
+ // for server name
InetAddress inetAddr = InetAddress.getByName(server);
assert null != inetAddr;
@@ -5530,16 +5620,16 @@ String getInstancePort(String server,
try {
byte sendBuffer[] = (" " + instanceName).getBytes();
sendBuffer[0] = 4;
- DatagramPacket udpRequest = new DatagramPacket(sendBuffer, sendBuffer.length, inetAddr, BROWSER_PORT);
+ DatagramPacket udpRequest = new DatagramPacket(sendBuffer, sendBuffer.length, inetAddr,
+ BROWSER_PORT);
datagramSocket.send(udpRequest);
- }
- catch (IOException ioException) {
- lastErrorMessage = "Error sending SQL Server Browser Service UDP request to address: " + inetAddr + ", port: " + BROWSER_PORT;
+ } catch (IOException ioException) {
+ lastErrorMessage = "Error sending SQL Server Browser Service UDP request to address: "
+ + inetAddr + ", port: " + BROWSER_PORT;
throw ioException;
}
}
- }
- catch (UnknownHostException unknownHostException) {
+ } catch (UnknownHostException unknownHostException) {
lastErrorMessage = "Unable to determine IP address of host: " + server;
throw unknownHostException;
}
@@ -5551,22 +5641,20 @@ String getInstancePort(String server,
datagramSocket.receive(udpResponse);
browserResult = new String(receiveBuffer, 3, receiveBuffer.length - 3);
if (connectionlogger.isLoggable(Level.FINER))
- connectionlogger.fine(toString() + " Received SSRP UDP response from IP address: " + udpResponse.getAddress().getHostAddress());
- }
- catch (IOException ioException) {
+ connectionlogger.fine(toString() + " Received SSRP UDP response from IP address: "
+ + udpResponse.getAddress().getHostAddress());
+ } catch (IOException ioException) {
// Warn and retry
lastErrorMessage = "Error receiving SQL Server Browser Service UDP response from server: " + server;
throw ioException;
}
- }
- catch (IOException ioException) {
+ } catch (IOException ioException) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_sqlBrowserFailed"));
Object[] msgArgs = {server, instanceName, ioException.toString()};
connectionlogger.log(Level.FINE, toString() + " " + lastErrorMessage, ioException);
- SQLServerException.makeFromDriverError(this, this, form.format(msgArgs), SQLServerException.EXCEPTION_XOPEN_CONNECTION_CANT_ESTABLISH,
- false);
- }
- finally {
+ SQLServerException.makeFromDriverError(this, this, form.format(msgArgs),
+ SQLServerException.EXCEPTION_XOPEN_CONNECTION_CANT_ESTABLISH, false);
+ } finally {
if (null != datagramSocket)
datagramSocket.close();
}
@@ -5576,8 +5664,8 @@ String getInstancePort(String server,
if (-1 == p) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_notConfiguredToListentcpip"));
Object[] msgArgs = {instanceName};
- SQLServerException.makeFromDriverError(this, this, form.format(msgArgs), SQLServerException.EXCEPTION_XOPEN_CONNECTION_CANT_ESTABLISH,
- false);
+ SQLServerException.makeFromDriverError(this, this, form.format(msgArgs),
+ SQLServerException.EXCEPTION_XOPEN_CONNECTION_CANT_ESTABLISH, false);
}
// All went well, so return the TCP port of the SQL Server instance
int p1 = p + 4;
@@ -5590,28 +5678,31 @@ int getNextSavepointId() {
return nNextSavePointId;
}
- // Returns this connection's SQLServerConnectionSecurityManager class to caller.
- // Used by SQLServerPooledConnection to verify security when passing out Connection objects.
+ /**
+ * Returns this connection's SQLServerConnectionSecurityManager class to caller. Used by SQLServerPooledConnection
+ * to verify security when passing out Connection objects.
+ */
void doSecurityCheck() {
assert null != currentConnectPlaceHolder;
currentConnectPlaceHolder.doSecurityCheck();
}
- // ColumnEncryptionKeyCache sets time-to-live for column encryption key entries in
- // the column encryption key cache for the Always Encrypted feature. The default value is 2 hours.
- // This variable holds the value in seconds.
+ /**
+ * Sets time-to-live for column encryption key entries in the column encryption key cache for the Always Encrypted
+ * feature. The default value is 2 hours. This variable holds the value in seconds.
+ */
private static long columnEncryptionKeyCacheTtl = TimeUnit.SECONDS.convert(2, TimeUnit.HOURS);
/**
- * Sets time-to-live for column encryption key entries in the column encryption key cache for the Always Encrypted feature. The default value is 2
- * hours. This variable holds the value in seconds.
+ * Sets time-to-live for column encryption key entries in the column encryption key cache for the Always Encrypted
+ * feature. The default value is 2 hours. This variable holds the value in seconds.
*
* @param columnEncryptionKeyCacheTTL
- * The timeunit in seconds
+ * The timeunit in seconds
* @param unit
- * The Timeunit.
+ * The Timeunit.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
public static synchronized void setColumnEncryptionKeyCacheTtl(int columnEncryptionKeyCacheTTL,
TimeUnit unit) throws SQLServerException {
@@ -5628,17 +5719,18 @@ static synchronized long getColumnEncryptionKeyCacheTtl() {
}
/**
- * Enqueue a discarded prepared statement handle to be clean-up on the server.
+ * Enqueues a discarded prepared statement handle to be clean-up on the server.
*
* @param statementHandle
- * The prepared statement handle that should be scheduled for unprepare.
+ * The prepared statement handle that should be scheduled for unprepare.
*/
final void enqueueUnprepareStatementHandle(PreparedStatementHandle statementHandle) {
if (null == statementHandle)
return;
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.finer(this + ": Adding PreparedHandle to queue for un-prepare:" + statementHandle.getHandle());
+ loggerExternal
+ .finer(this + ": Adding PreparedHandle to queue for un-prepare:" + statementHandle.getHandle());
// Add the new handle to the discarding queue and find out current # enqueued.
this.discardedPreparedStatementHandles.add(statementHandle);
@@ -5656,7 +5748,7 @@ public void closeUnreferencedPreparedStatementHandles() {
}
/**
- * Remove references to outstanding un-prepare requests. Should be run when connection is closed.
+ * Removes references to outstanding un-prepare requests. Should be run when connection is closed.
*/
private final void cleanupPreparedStatementDiscardActions() {
discardedPreparedStatementHandles.clear();
@@ -5694,10 +5786,12 @@ final boolean isPreparedStatementUnprepareBatchingEnabled() {
}
/**
- * Cleans-up discarded prepared statement handles on the server using batched un-prepare actions if the batching threshold has been reached.
+ * Cleans up discarded prepared statement handles on the server using batched un-prepare actions if the batching
+ * threshold has been reached.
*
* @param force
- * When force is set to true we ignore the current threshold for if the discard actions should run and run them anyway.
+ * When force is set to true we ignore the current threshold for if the discard actions should run and run
+ * them anyway.
*/
final void unprepareUnreferencedPreparedStatementHandles(boolean force) {
// Skip out if session is unavailable to adhere to previous non-batched behavior.
@@ -5722,8 +5816,8 @@ final void unprepareUnreferencedPreparedStatementHandles(boolean force) {
while (null != (statementHandle = discardedPreparedStatementHandles.poll())) {
++handlesRemoved;
- sql.append(statementHandle.isDirectSql() ? "EXEC sp_unprepare " : "EXEC sp_cursorunprepare ").append(statementHandle.getHandle())
- .append(';');
+ sql.append(statementHandle.isDirectSql() ? "EXEC sp_unprepare " : "EXEC sp_cursorunprepare ")
+ .append(statementHandle.getHandle()).append(';');
}
try {
@@ -5734,8 +5828,7 @@ final void unprepareUnreferencedPreparedStatementHandles(boolean force) {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.finer(this + ": Finished un-preparing handle count:" + handlesRemoved);
- }
- catch (SQLException e) {
+ } catch (SQLException e) {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.log(Level.FINER, this + ": Error batch-closing at least one prepared handle", e);
}
@@ -5773,7 +5866,8 @@ public int getStatementHandleCacheEntryCount() {
@Override
public boolean isStatementPoolingEnabled() {
- return null != preparedStatementHandleCache && 0 < this.getStatementPoolingCacheSize() && !this.getDisableStatementPooling();
+ return null != preparedStatementHandleCache && 0 < this.getStatementPoolingCacheSize()
+ && !this.getDisableStatementPooling();
}
@Override
@@ -5792,46 +5886,45 @@ public void setStatementPoolingCacheSize(int value) {
}
/**
- * Internal method to prepare the cache handle
+ * Prepares the cache handle.
*
* @param value
*/
private void prepareCache() {
- preparedStatementHandleCache = new Builder().maximumWeightedCapacity(getStatementPoolingCacheSize())
+ preparedStatementHandleCache = new Builder()
+ .maximumWeightedCapacity(getStatementPoolingCacheSize())
.listener(new PreparedStatementCacheEvictionListener()).build();
- parameterMetadataCache = new Builder().maximumWeightedCapacity(getStatementPoolingCacheSize())
- .build();
+ parameterMetadataCache = new Builder()
+ .maximumWeightedCapacity(getStatementPoolingCacheSize()).build();
}
- /** Get a parameter metadata cache entry if statement pooling is enabled */
- final SQLServerParameterMetaData getCachedParameterMetadata(Sha1HashKey key) {
+ /** Returns a parameter metadata cache entry if statement pooling is enabled */
+ final SQLServerParameterMetaData getCachedParameterMetadata(CityHash128Key key) {
if (!isStatementPoolingEnabled())
return null;
return parameterMetadataCache.get(key);
}
- /** Register a parameter metadata cache entry if statement pooling is enabled */
- final void registerCachedParameterMetadata(Sha1HashKey key,
- SQLServerParameterMetaData pmd) {
+ /** Registers a parameter metadata cache entry if statement pooling is enabled */
+ final void registerCachedParameterMetadata(CityHash128Key key, SQLServerParameterMetaData pmd) {
if (!isStatementPoolingEnabled() || null == pmd)
return;
parameterMetadataCache.put(key, pmd);
}
- /** Get or create prepared statement handle cache entry if statement pooling is enabled */
- final PreparedStatementHandle getCachedPreparedStatementHandle(Sha1HashKey key) {
+ /** Gets or creates prepared statement handle cache entry if statement pooling is enabled */
+ final PreparedStatementHandle getCachedPreparedStatementHandle(CityHash128Key key) {
if (!isStatementPoolingEnabled())
return null;
return preparedStatementHandleCache.get(key);
}
- /** Get or create prepared statement handle cache entry if statement pooling is enabled */
- final PreparedStatementHandle registerCachedPreparedStatementHandle(Sha1HashKey key,
- int handle,
+ /** Gets or creates prepared statement handle cache entry if statement pooling is enabled */
+ final PreparedStatementHandle registerCachedPreparedStatementHandle(CityHash128Key key, int handle,
boolean isDirectSql) {
if (!isStatementPoolingEnabled() || null == key)
return null;
@@ -5841,7 +5934,7 @@ final PreparedStatementHandle registerCachedPreparedStatementHandle(Sha1HashKey
return cacheItem;
}
- /** Return prepared statement handle cache entry so it can be un-prepared. */
+ /** Returns prepared statement handle cache entry so it can be un-prepared. */
final void returnCachedPreparedStatementHandle(PreparedStatementHandle handle) {
handle.removeReference();
@@ -5849,7 +5942,7 @@ final void returnCachedPreparedStatementHandle(PreparedStatementHandle handle) {
enqueueUnprepareStatementHandle(handle);
}
- /** Force eviction of prepared statement handle cache entry. */
+ /** Forces eviction of prepared statement handle cache entry. */
final void evictCachedPreparedStatementHandle(PreparedStatementHandle handle) {
if (null == handle || null == handle.getKey())
return;
@@ -5857,10 +5950,12 @@ final void evictCachedPreparedStatementHandle(PreparedStatementHandle handle) {
preparedStatementHandleCache.remove(handle.getKey());
}
- // Handle closing handles when removed from cache.
- final class PreparedStatementCacheEvictionListener implements EvictionListener {
- public void onEviction(Sha1HashKey key,
- PreparedStatementHandle handle) {
+ /*
+ * Handles closing handles when removed from cache.
+ */
+ final class PreparedStatementCacheEvictionListener
+ implements EvictionListener {
+ public void onEviction(CityHash128Key key, PreparedStatementHandle handle) {
if (null != handle) {
handle.setIsEvictedFromCache(true); // Mark as evicted from cache.
@@ -5875,16 +5970,17 @@ public void onEviction(Sha1HashKey key,
boolean isAzureDW() throws SQLServerException, SQLException {
if (null == isAzureDW) {
- try (Statement stmt = this.createStatement(); ResultSet rs = stmt.executeQuery("SELECT CAST(SERVERPROPERTY('EngineEdition') as INT)");)
- {
- // SERVERPROPERTY('EngineEdition') can be used to determine whether the db server is SQL Azure.
- // It should return 6 for SQL Azure DW. This is more reliable than @@version or serverproperty('edition').
- // Reference: http://msdn.microsoft.com/en-us/library/ee336261.aspx
- //
- // SERVERPROPERTY('EngineEdition') means
+ try (Statement stmt = this.createStatement();
+ ResultSet rs = stmt.executeQuery("SELECT CAST(SERVERPROPERTY('EngineEdition') as INT)");) {
+ // SERVERPROPERTY('EngineEdition') can be used to determine whether the db server is SQL Azure.
+ // It should return 6 for SQL Azure DW. This is more reliable than @@version or
+ // serverproperty('edition').
+ // Reference: http://msdn.microsoft.com/en-us/library/ee336261.aspx
+ //
+ // SERVERPROPERTY('EngineEdition') means
// Database Engine edition of the instance of SQL Server installed on the server.
// 1 = Personal or Desktop Engine (Not available for SQL Server.)
- // 2 = Standard (This is returned for Standard and Workgroup.)
+ // 2 = Standard (This is returned for Standard and Workgroup.)
// 3 = Enterprise (This is returned for Enterprise, Enterprise Evaluation, and Developer.)
// 4 = Express (This is returned for Express, Express with Advanced Services, and Windows Embedded SQL.)
// 5 = SQL Azure
@@ -5901,8 +5997,10 @@ boolean isAzureDW() throws SQLServerException, SQLException {
}
/**
+ * Adds statement to openStatements
+ *
* @param st
- * Statement to add to openStatements
+ * Statement to add to openStatements
*/
final synchronized void addOpenStatement(Statement st) {
if (null != openStatements) {
@@ -5911,8 +6009,10 @@ final synchronized void addOpenStatement(Statement st) {
}
/**
+ * Removes state from openStatements
+ *
* @param st
- * Statement to remove from openStatements
+ * Statement to remove from openStatements
*/
final synchronized void removeOpenStatement(Statement st) {
if (null != openStatements) {
@@ -5921,24 +6021,27 @@ final synchronized void removeOpenStatement(Statement st) {
}
}
-// Helper class for security manager functions used by SQLServerConnection class.
+
+/**
+ * Provides Helper class for security manager functions used by SQLServerConnection class.
+ *
+ */
final class SQLServerConnectionSecurityManager {
static final String dllName = "sqljdbc_auth.dll";
String serverName;
int portNumber;
- SQLServerConnectionSecurityManager(String serverName,
- int portNumber) {
+ SQLServerConnectionSecurityManager(String serverName, int portNumber) {
this.serverName = serverName;
this.portNumber = portNumber;
}
/**
- * checkConnect will throws a SecurityException if the calling thread is not allowed to open a socket connection to the specified serverName and
- * portNumber.
+ * Throws a SecurityException if the calling thread is not allowed to open a socket connection to the specified
+ * serverName and portNumber.
*
* @throws SecurityException
- * when an error occurs
+ * when an error occurs
*/
public void checkConnect() throws SecurityException {
SecurityManager security = System.getSecurityManager();
@@ -5951,7 +6054,7 @@ public void checkConnect() throws SecurityException {
* Throws a SecurityException
if the calling thread is not allowed to dynamic link the library code.
*
* @throws SecurityException
- * when an error occurs
+ * when an error occurs
*/
public void checkLink() throws SecurityException {
SecurityManager security = System.getSecurityManager();
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection43.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection43.java
index 27c782c0c..93505f5f1 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection43.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection43.java
@@ -1,9 +1,6 @@
/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc;
@@ -11,14 +8,16 @@
import java.sql.SQLException;
import java.sql.ShardingKey;
+
/**
- * SQLServerConnection43 extends {@link SQLServerConnection43} class and implements {@link ISQLServerConnection43} with methods introduced in JDBC 4.3
- * Specifications. This class is used by the drdiver when initializing a class with 43 driver version
+ * Extends {@link SQLServerConnection43} and implements {@link ISQLServerConnection43} with methods introduced in JDBC
+ * 4.3 Specifications. This class is used by the driver when initializing a class with with JDBC 4.3 Specs supported
+ * JVM.
*/
public class SQLServerConnection43 extends SQLServerConnection implements ISQLServerConnection43 {
/**
- * Always refresh SerialVersionUID when prompted
+ * Always refresh SerialVersionUID when prompted.
*/
private static final long serialVersionUID = -6904163521498951547L;
@@ -42,21 +41,18 @@ public void setShardingKey(ShardingKey shardingKey) throws SQLException {
}
@Override
- public void setShardingKey(ShardingKey shardingKey,
- ShardingKey superShardingKey) throws SQLException {
+ public void setShardingKey(ShardingKey shardingKey, ShardingKey superShardingKey) throws SQLException {
SQLServerException.throwFeatureNotSupportedException();
}
@Override
- public boolean setShardingKeyIfValid(ShardingKey shardingKey,
- int timeout) throws SQLException {
+ public boolean setShardingKeyIfValid(ShardingKey shardingKey, int timeout) throws SQLException {
SQLServerException.throwFeatureNotSupportedException();
return false;
}
@Override
- public boolean setShardingKeyIfValid(ShardingKey shardingKey,
- ShardingKey superShardingKey,
+ public boolean setShardingKeyIfValid(ShardingKey shardingKey, ShardingKey superShardingKey,
int timeout) throws SQLException {
SQLServerException.throwFeatureNotSupportedException();
return false;
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnectionPoolDataSource.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnectionPoolDataSource.java
index 50115cd05..4ac11100f 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnectionPoolDataSource.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnectionPoolDataSource.java
@@ -1,9 +1,6 @@
/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc;
@@ -15,11 +12,12 @@
import javax.sql.ConnectionPoolDataSource;
import javax.sql.PooledConnection;
+
/**
- * SQLServerConnectionPoolDataSource provides physical database connections for connection pool managers. SQLServerConnectionPoolDataSource is
- * typically used in Java Application Server environments that support built-in connection pooling and require a ConnectionPoolDataSource to provide
- * physical connections. For example, J2EE application servers that provide JDBC 3.0 API spec connection pooling.
- *
+ * Provides physical database connections for connection pool managers. SQLServerConnectionPoolDataSource is typically
+ * used in Java Application Server environments that support built-in connection pooling and require a
+ * ConnectionPoolDataSource to provide physical connections. For example, J2EE application servers that provide JDBC 3.0
+ * API spec connection pooling.
*/
public class SQLServerConnectionPoolDataSource extends SQLServerDataSource implements ConnectionPoolDataSource {
// Get a new physical connection that the pool manager will issue logical connections from
@@ -34,10 +32,10 @@ public PooledConnection getPooledConnection() throws SQLException {
}
@Override
- public PooledConnection getPooledConnection(String user,
- String password) throws SQLException {
+ public PooledConnection getPooledConnection(String user, String password) throws SQLException {
if (loggerExternal.isLoggable(Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "getPooledConnection", new Object[] {user, "Password not traced"});
+ loggerExternal.entering(getClassNameLogging(), "getPooledConnection",
+ new Object[] {user, "Password not traced"});
SQLServerPooledConnection pc = new SQLServerPooledConnection(this, user, password);
if (loggerExternal.isLoggable(Level.FINER))
loggerExternal.exiting(getClassNameLogging(), "getPooledConnection", pc);
@@ -66,8 +64,9 @@ private void readObject(java.io.ObjectInputStream stream) throws java.io.Invalid
throw new java.io.InvalidObjectException("");
}
- // This is 90% duplicate from the SQLServerDataSource, the serialization proxy pattern does not lend itself to inheritance
- // so the duplication is necessary
+ /**
+ * Implements java.io.Serializable the same way as {@link SQLServerDataSource}
+ */
private static class SerializationProxy implements java.io.Serializable {
private final Reference ref;
private static final long serialVersionUID = 654661379842314126L;
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnectionPoolProxy.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnectionPoolProxy.java
index cca04ad76..1ee3d0128 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnectionPoolProxy.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnectionPoolProxy.java
@@ -1,9 +1,6 @@
/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc;
@@ -18,16 +15,16 @@
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicInteger;
+
/**
- * SQLServerConnectionPoolProxy is a wrapper around SQLServerConnection object. When returning a connection object from PooledConnection.getConnection
- * we return this proxy per SPEC.
+ * Provides a wrapper around SQLServerConnection object. When returning a connection object from
+ * PooledConnection.getConnection we return this proxy per SPEC.
*
* This class's public functions need to be kept identical to the SQLServerConnection's.
*
- * The API javadoc for JDBC API methods that this class implements are not repeated here. Please see Sun's JDBC API interfaces javadoc for those
- * details.
+ * The API javadoc for JDBC API methods that this class implements are not repeated here. Please see Sun's JDBC API
+ * interfaces javadoc for those details.
*/
-
class SQLServerConnectionPoolProxy implements ISQLServerConnection, java.io.Serializable {
/**
* Always refresh SerialVersionUID when prompted
@@ -41,12 +38,13 @@ class SQLServerConnectionPoolProxy implements ISQLServerConnection, java.io.Seri
// dispenser
final private String traceID;
- // Permission targets
- // currently only callAbort is implemented
+ /**
+ * Permission targets currently only callAbort is implemented
+ */
private static final String callAbortPerm = "callAbort";
/**
- * Generate the next unique connection id.
+ * Generates the next unique connection id.
*
* @return the next conn id
*/
@@ -69,7 +67,8 @@ public String toString() {
void checkClosed() throws SQLServerException {
if (!bIsOpen) {
- SQLServerException.makeFromDriverError(null, null, SQLServerException.getErrString("R_connectionIsClosed"), null, false);
+ SQLServerException.makeFromDriverError(null, null, SQLServerException.getErrString("R_connectionIsClosed"),
+ null, false);
}
}
@@ -138,8 +137,7 @@ public void abort(Executor executor) throws SQLException {
try {
java.sql.SQLPermission perm = new java.sql.SQLPermission(callAbortPerm);
secMgr.checkPermission(perm);
- }
- catch (SecurityException ex) {
+ } catch (SecurityException ex) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_permissionDenied"));
Object[] msgArgs = {callAbortPerm};
throw new SQLServerException(form.format(msgArgs), null, 0, ex);
@@ -155,8 +153,7 @@ public void run() {
try {
wrappedConnection.poolCloseEventNotify();
wrappedConnection = null;
- }
- catch (SQLException e) {
+ } catch (SQLException e) {
throw new RuntimeException(e);
}
}
@@ -242,24 +239,20 @@ public void clearWarnings() throws SQLServerException {
// --------------------------JDBC 2.0-----------------------------
@Override
- public Statement createStatement(int resultSetType,
- int resultSetConcurrency) throws SQLException {
+ public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
checkClosed();
return wrappedConnection.createStatement(resultSetType, resultSetConcurrency);
}
@Override
- public PreparedStatement prepareStatement(String sSql,
- int resultSetType,
+ public PreparedStatement prepareStatement(String sSql, int resultSetType,
int resultSetConcurrency) throws SQLException {
checkClosed();
return wrappedConnection.prepareStatement(sSql, resultSetType, resultSetConcurrency);
}
@Override
- public CallableStatement prepareCall(String sql,
- int resultSetType,
- int resultSetConcurrency) throws SQLException {
+ public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
checkClosed();
return wrappedConnection.prepareCall(sql, resultSetType, resultSetConcurrency);
}
@@ -277,55 +270,40 @@ public java.util.Map> getTypeMap() throws SQLServerException {
}
@Override
- public Statement createStatement(int nType,
- int nConcur,
- int nHold) throws SQLServerException {
+ public Statement createStatement(int nType, int nConcur, int nHold) throws SQLServerException {
checkClosed();
return wrappedConnection.createStatement(nType, nConcur, nHold);
}
@Override
- public Statement createStatement(int nType,
- int nConcur,
- int nHold,
+ public Statement createStatement(int nType, int nConcur, int nHold,
SQLServerStatementColumnEncryptionSetting stmtColEncSetting) throws SQLServerException {
checkClosed();
return wrappedConnection.createStatement(nType, nConcur, nHold, stmtColEncSetting);
}
@Override
- public PreparedStatement prepareStatement(java.lang.String sql,
- int nType,
- int nConcur,
+ public PreparedStatement prepareStatement(java.lang.String sql, int nType, int nConcur,
int nHold) throws SQLServerException {
checkClosed();
return wrappedConnection.prepareStatement(sql, nType, nConcur, nHold);
}
@Override
- public PreparedStatement prepareStatement(String sql,
- int nType,
- int nConcur,
- int nHold,
+ public PreparedStatement prepareStatement(String sql, int nType, int nConcur, int nHold,
SQLServerStatementColumnEncryptionSetting stmtColEncSetting) throws SQLServerException {
checkClosed();
return wrappedConnection.prepareStatement(sql, nType, nConcur, nHold, stmtColEncSetting);
}
@Override
- public CallableStatement prepareCall(String sql,
- int nType,
- int nConcur,
- int nHold) throws SQLServerException {
+ public CallableStatement prepareCall(String sql, int nType, int nConcur, int nHold) throws SQLServerException {
checkClosed();
return wrappedConnection.prepareCall(sql, nType, nConcur, nHold);
}
@Override
- public CallableStatement prepareCall(String sql,
- int nType,
- int nConcur,
- int nHold,
+ public CallableStatement prepareCall(String sql, int nType, int nConcur, int nHold,
SQLServerStatementColumnEncryptionSetting stmtColEncSetiing) throws SQLServerException {
checkClosed();
return wrappedConnection.prepareCall(sql, nType, nConcur, nHold, stmtColEncSetiing);
@@ -334,45 +312,39 @@ public CallableStatement prepareCall(String sql,
/* JDBC 3.0 Auto generated keys */
@Override
- public PreparedStatement prepareStatement(String sql,
- int flag) throws SQLServerException {
+ public PreparedStatement prepareStatement(String sql, int flag) throws SQLServerException {
checkClosed();
return wrappedConnection.prepareStatement(sql, flag);
}
@Override
- public PreparedStatement prepareStatement(String sql,
- int flag,
+ public PreparedStatement prepareStatement(String sql, int flag,
SQLServerStatementColumnEncryptionSetting stmtColEncSetting) throws SQLServerException {
checkClosed();
return wrappedConnection.prepareStatement(sql, flag, stmtColEncSetting);
}
@Override
- public PreparedStatement prepareStatement(String sql,
- int[] columnIndexes) throws SQLServerException {
+ public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLServerException {
checkClosed();
return wrappedConnection.prepareStatement(sql, columnIndexes);
}
@Override
- public PreparedStatement prepareStatement(String sql,
- int[] columnIndexes,
+ public PreparedStatement prepareStatement(String sql, int[] columnIndexes,
SQLServerStatementColumnEncryptionSetting stmtColEncSetting) throws SQLServerException {
checkClosed();
return wrappedConnection.prepareStatement(sql, columnIndexes, stmtColEncSetting);
}
@Override
- public PreparedStatement prepareStatement(String sql,
- String[] columnNames) throws SQLServerException {
+ public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLServerException {
checkClosed();
return wrappedConnection.prepareStatement(sql, columnNames);
}
@Override
- public PreparedStatement prepareStatement(String sql,
- String[] columnNames,
+ public PreparedStatement prepareStatement(String sql, String[] columnNames,
SQLServerStatementColumnEncryptionSetting stmtColEncSetting) throws SQLServerException {
checkClosed();
return wrappedConnection.prepareStatement(sql, columnNames, stmtColEncSetting);
@@ -423,8 +395,7 @@ public int getNetworkTimeout() throws SQLException {
}
@Override
- public void setNetworkTimeout(Executor executor,
- int timeout) throws SQLException {
+ public void setNetworkTimeout(Executor executor, int timeout) throws SQLException {
checkClosed();
wrappedConnection.setNetworkTimeout(executor, timeout);
}
@@ -442,8 +413,7 @@ public void setSchema(String schema) throws SQLException {
}
@Override
- public java.sql.Array createArrayOf(String typeName,
- Object[] elements) throws SQLException {
+ public java.sql.Array createArrayOf(String typeName, Object[] elements) throws SQLException {
checkClosed();
return wrappedConnection.createArrayOf(typeName, elements);
}
@@ -473,8 +443,7 @@ public java.sql.SQLXML createSQLXML() throws SQLException {
}
@Override
- public java.sql.Struct createStruct(String typeName,
- Object[] attributes) throws SQLException {
+ public java.sql.Struct createStruct(String typeName, Object[] attributes) throws SQLException {
checkClosed();
return wrappedConnection.createStruct(typeName, attributes);
}
@@ -499,8 +468,7 @@ public void setClientInfo(java.util.Properties properties) throws SQLClientInfoE
}
@Override
- public void setClientInfo(String name,
- String value) throws SQLClientInfoException {
+ public void setClientInfo(String name, String value) throws SQLClientInfoException {
// No checkClosed() call since we can only throw SQLClientInfoException
// from here
wrappedConnection.setClientInfo(name, value);
@@ -526,8 +494,7 @@ public T unwrap(Class iface) throws SQLException {
T t;
try {
t = iface.cast(this);
- }
- catch (ClassCastException e) {
+ } catch (ClassCastException e) {
SQLServerException newe = new SQLServerException(e.getMessage(), e);
throw newe;
}
@@ -542,7 +509,7 @@ public java.util.UUID getClientConnectionId() throws SQLServerException {
}
@Override
- public synchronized void setSendTimeAsDatetime(boolean sendTimeAsDateTimeValue) throws SQLServerException {
+ public void setSendTimeAsDatetime(boolean sendTimeAsDateTimeValue) throws SQLServerException {
checkClosed();
wrappedConnection.setSendTimeAsDatetime(sendTimeAsDateTimeValue);
}
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDataColumn.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDataColumn.java
index 7877cf3ab..218f58dbb 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDataColumn.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDataColumn.java
@@ -1,52 +1,48 @@
-/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
- */
-
-package com.microsoft.sqlserver.jdbc;
-
-/**
- * This class represents a column of the in-memory data table represented by SQLServerDataTable.
- */
-public final class SQLServerDataColumn {
- String columnName;
- int javaSqlType;
- int precision = 0;
- int scale = 0;
- int numberOfDigitsIntegerPart = 0;
-
- /**
- * Initializes a new instance of SQLServerDataColumn with the column name and type.
- *
- * @param columnName
- * the name of the column
- * @param sqlType
- * the type of the column
- */
- public SQLServerDataColumn(String columnName,
- int sqlType) {
- this.columnName = columnName;
- this.javaSqlType = sqlType;
- }
-
- /**
- * Retrieves the column name.
- *
- * @return the name of the column.
- */
- public String getColumnName() {
- return columnName;
- }
-
- /**
- * Retrieves the column type.
- *
- * @return the column type.
- */
- public int getColumnType() {
- return javaSqlType;
- }
-}
\ No newline at end of file
+/*
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ */
+
+package com.microsoft.sqlserver.jdbc;
+
+/**
+ * Represents a column of the in-memory data table represented by {@link SQLServerDataTable}.
+ */
+public final class SQLServerDataColumn {
+ String columnName;
+ int javaSqlType;
+ int precision = 0;
+ int scale = 0;
+ int numberOfDigitsIntegerPart = 0;
+
+ /**
+ * Constructs a SQLServerDataColumn with the column name and type.
+ *
+ * @param columnName
+ * the name of the column
+ * @param sqlType
+ * the type of the column
+ */
+ public SQLServerDataColumn(String columnName, int sqlType) {
+ this.columnName = columnName;
+ this.javaSqlType = sqlType;
+ }
+
+ /**
+ * Returns the column name.
+ *
+ * @return the name of the column.
+ */
+ public String getColumnName() {
+ return columnName;
+ }
+
+ /**
+ * Returns the column type.
+ *
+ * @return the column type.
+ */
+ public int getColumnType() {
+ return javaSqlType;
+ }
+}
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDataSource.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDataSource.java
index 607c2d89f..a0b32b32e 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDataSource.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDataSource.java
@@ -1,9 +1,6 @@
/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc;
@@ -22,14 +19,19 @@
import org.ietf.jgss.GSSCredential;
+
/**
- * This datasource lists properties specific for the SQLServerConnection class.
+ * Contains a list of properties specific for the {@link SQLServerConnection} class.
*/
-public class SQLServerDataSource implements ISQLServerDataSource, javax.sql.DataSource, java.io.Serializable, javax.naming.Referenceable {
+public class SQLServerDataSource
+ implements ISQLServerDataSource, javax.sql.DataSource, java.io.Serializable, javax.naming.Referenceable {
// dsLogger is logger used for all SQLServerDataSource instances.
- static final java.util.logging.Logger dsLogger = java.util.logging.Logger.getLogger("com.microsoft.sqlserver.jdbc.internals.SQLServerDataSource");
- static final java.util.logging.Logger loggerExternal = java.util.logging.Logger.getLogger("com.microsoft.sqlserver.jdbc.DataSource");
- static final private java.util.logging.Logger parentLogger = java.util.logging.Logger.getLogger("com.microsoft.sqlserver.jdbc");
+ static final java.util.logging.Logger dsLogger = java.util.logging.Logger
+ .getLogger("com.microsoft.sqlserver.jdbc.internals.SQLServerDataSource");
+ static final java.util.logging.Logger loggerExternal = java.util.logging.Logger
+ .getLogger("com.microsoft.sqlserver.jdbc.DataSource");
+ static final private java.util.logging.Logger parentLogger = java.util.logging.Logger
+ .getLogger("com.microsoft.sqlserver.jdbc");
final private String loggingClassName;
private boolean trustStorePasswordStripped = false;
@@ -55,14 +57,15 @@ public class SQLServerDataSource implements ISQLServerDataSource, javax.sql.Data
final private String traceID;
/**
- * Initializes a new instance of the SQLServerDataSource class.
+ * Constructs a SQLServerDataSource.
*/
public SQLServerDataSource() {
connectionProps = new Properties();
int dataSourceID = nextDataSourceID();
String nameL = getClass().getName();
traceID = nameL.substring(1 + nameL.lastIndexOf('.')) + ":" + dataSourceID;
- loggingClassName = "com.microsoft.sqlserver.jdbc." + nameL.substring(1 + nameL.lastIndexOf('.')) + ":" + dataSourceID;
+ loggingClassName = "com.microsoft.sqlserver.jdbc." + nameL.substring(1 + nameL.lastIndexOf('.')) + ":"
+ + dataSourceID;
}
String getClassNameLogging() {
@@ -85,17 +88,19 @@ public Connection getConnection() throws SQLServerException {
}
@Override
- public Connection getConnection(String username,
- String password) throws SQLServerException {
+ public Connection getConnection(String username, String password) throws SQLServerException {
if (loggerExternal.isLoggable(Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "getConnection", new Object[] {username, "Password not traced"});
+ loggerExternal.entering(getClassNameLogging(), "getConnection",
+ new Object[] {username, "Password not traced"});
Connection con = getConnectionInternal(username, password, null);
loggerExternal.exiting(getClassNameLogging(), "getConnection", con);
return con;
}
- // Sets the maximum time in seconds that this data source will wait while
- // attempting to connect to a database. Note default value is 0.
+ /**
+ * Sets the maximum time in seconds that this data source will wait while attempting to connect to a database. Note
+ * default value is 0.
+ */
@Override
public void setLoginTimeout(int loginTimeout) {
setIntProperty(connectionProps, SQLServerDriverIntProperty.LOGIN_TIMEOUT.toString(), loginTimeout);
@@ -104,14 +109,16 @@ public void setLoginTimeout(int loginTimeout) {
@Override
public int getLoginTimeout() {
int defaultTimeOut = SQLServerDriverIntProperty.LOGIN_TIMEOUT.getDefaultValue();
- final int logintimeout = getIntProperty(connectionProps, SQLServerDriverIntProperty.LOGIN_TIMEOUT.toString(), defaultTimeOut);
+ final int logintimeout = getIntProperty(connectionProps, SQLServerDriverIntProperty.LOGIN_TIMEOUT.toString(),
+ defaultTimeOut);
// even if the user explicitly sets the timeout to zero, convert to 15
return (logintimeout == 0) ? defaultTimeOut : logintimeout;
}
- // Sets the log writer for this DataSource.
- // Currently we just hold onto this logWriter and pass it back to callers,
- // nothing else.
+ /**
+ * Sets the log writer for this DataSource. Currently we just hold onto this logWriter and pass it back to callers,
+ * nothing else.
+ */
private transient PrintWriter logWriter;
@Override
@@ -121,7 +128,9 @@ public void setLogWriter(PrintWriter out) {
loggerExternal.exiting(getClassNameLogging(), "setLogWriter");
}
- // Retrieves the log writer for this DataSource.
+ /**
+ * Returns the log writer for this DataSource.
+ */
@Override
public PrintWriter getLogWriter() {
loggerExternal.entering(getClassNameLogging(), "getLogWriter");
@@ -136,9 +145,9 @@ public Logger getParentLogger() throws java.sql.SQLFeatureNotSupportedException
// Core Connection property setters/getters.
- // applicationName is used to identify the specific application in various
- // SQL Server
- // profiling and logging tools.
+ /**
+ * Sets the specific application in various SQL Server profiling and logging tools.
+ */
@Override
public void setApplicationName(String applicationName) {
setStringProperty(connectionProps, SQLServerDriverStringProperty.APPLICATION_NAME.toString(), applicationName);
@@ -150,9 +159,12 @@ public String getApplicationName() {
SQLServerDriverStringProperty.APPLICATION_NAME.getDefaultValue());
}
- // databaseName is the name of the database to connect to. If databaseName
- // is not set,
- // getDatabaseName returns the default value of null.
+ /**
+ * Sets the the database to connect to.
+ *
+ * @param databaseName
+ * if not set, returns the default value of null.
+ */
@Override
public void setDatabaseName(String databaseName) {
setStringProperty(connectionProps, SQLServerDriverStringProperty.DATABASE_NAME.toString(), databaseName);
@@ -163,9 +175,12 @@ public String getDatabaseName() {
return getStringProperty(connectionProps, SQLServerDriverStringProperty.DATABASE_NAME.toString(), null);
}
- // instanceName is the SQL Server instance name to connect to.
- // If instanceName is not set, getInstanceName returns the default value of
- // null.
+ /**
+ * Sets the the SQL Server instance name to connect to.
+ *
+ * @param instanceName
+ * if not set, returns the default value of null.
+ */
@Override
public void setInstanceName(String instanceName) {
setStringProperty(connectionProps, SQLServerDriverStringProperty.INSTANCE_NAME.toString(), instanceName);
@@ -183,7 +198,8 @@ public void setIntegratedSecurity(boolean enable) {
@Override
public void setAuthenticationScheme(String authenticationScheme) {
- setStringProperty(connectionProps, SQLServerDriverStringProperty.AUTHENTICATION_SCHEME.toString(), authenticationScheme);
+ setStringProperty(connectionProps, SQLServerDriverStringProperty.AUTHENTICATION_SCHEME.toString(),
+ authenticationScheme);
}
@Override
@@ -204,7 +220,8 @@ public void setGSSCredentials(GSSCredential userCredential) {
@Override
public GSSCredential getGSSCredentials() {
- return (GSSCredential) getObjectProperty(connectionProps, SQLServerDriverObjectProperty.GSS_CREDENTIAL.toString(),
+ return (GSSCredential) getObjectProperty(connectionProps,
+ SQLServerDriverObjectProperty.GSS_CREDENTIAL.toString(),
SQLServerDriverObjectProperty.GSS_CREDENTIAL.getDefaultValue());
}
@@ -218,16 +235,15 @@ public String getAccessToken() {
return getStringProperty(connectionProps, SQLServerDriverStringProperty.ACCESS_TOKEN.toString(), null);
}
- // If lastUpdateCount is set to true, the driver will return only the last
- // update
- // count from all the update counts returned by a batch. The default of
- // false will
- // return all update counts. If lastUpdateCount is not set,
- // getLastUpdateCount
- // returns the default value of false.
+ /**
+ * Sets the Column Encryption setting. If lastUpdateCount is set to true, the driver will return only the last
+ * update count from all the update counts returned by a batch. The default of false will return all update counts.
+ * If lastUpdateCount is not set, getLastUpdateCount returns the default value of false.
+ */
@Override
public void setColumnEncryptionSetting(String columnEncryptionSetting) {
- setStringProperty(connectionProps, SQLServerDriverStringProperty.COLUMN_ENCRYPTION.toString(), columnEncryptionSetting);
+ setStringProperty(connectionProps, SQLServerDriverStringProperty.COLUMN_ENCRYPTION.toString(),
+ columnEncryptionSetting);
}
@Override
@@ -238,7 +254,8 @@ public String getColumnEncryptionSetting() {
@Override
public void setKeyStoreAuthentication(String keyStoreAuthentication) {
- setStringProperty(connectionProps, SQLServerDriverStringProperty.KEY_STORE_AUTHENTICATION.toString(), keyStoreAuthentication);
+ setStringProperty(connectionProps, SQLServerDriverStringProperty.KEY_STORE_AUTHENTICATION.toString(),
+ keyStoreAuthentication);
}
@Override
@@ -254,7 +271,8 @@ public void setKeyStoreSecret(String keyStoreSecret) {
@Override
public void setKeyStoreLocation(String keyStoreLocation) {
- setStringProperty(connectionProps, SQLServerDriverStringProperty.KEY_STORE_LOCATION.toString(), keyStoreLocation);
+ setStringProperty(connectionProps, SQLServerDriverStringProperty.KEY_STORE_LOCATION.toString(),
+ keyStoreLocation);
}
@Override
@@ -265,7 +283,8 @@ public String getKeyStoreLocation() {
@Override
public void setLastUpdateCount(boolean lastUpdateCount) {
- setBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.LAST_UPDATE_COUNT.toString(), lastUpdateCount);
+ setBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.LAST_UPDATE_COUNT.toString(),
+ lastUpdateCount);
}
@Override
@@ -287,12 +306,14 @@ public boolean getEncrypt() {
@Override
public void setTransparentNetworkIPResolution(boolean tnir) {
- setBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.TRANSPARENT_NETWORK_IP_RESOLUTION.toString(), tnir);
+ setBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.TRANSPARENT_NETWORK_IP_RESOLUTION.toString(),
+ tnir);
}
@Override
public boolean getTransparentNetworkIPResolution() {
- return getBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.TRANSPARENT_NETWORK_IP_RESOLUTION.toString(),
+ return getBooleanProperty(connectionProps,
+ SQLServerDriverBooleanProperty.TRANSPARENT_NETWORK_IP_RESOLUTION.toString(),
SQLServerDriverBooleanProperty.TRANSPARENT_NETWORK_IP_RESOLUTION.getDefaultValue());
}
@@ -333,7 +354,8 @@ public void setTrustStorePassword(String trustStorePassword) {
// if a non value property is set
if (trustStorePassword != null)
trustStorePasswordStripped = false;
- setStringProperty(connectionProps, SQLServerDriverStringProperty.TRUST_STORE_PASSWORD.toString(), trustStorePassword);
+ setStringProperty(connectionProps, SQLServerDriverStringProperty.TRUST_STORE_PASSWORD.toString(),
+ trustStorePassword);
}
@Override
@@ -343,17 +365,18 @@ public void setHostNameInCertificate(String hostName) {
@Override
public String getHostNameInCertificate() {
- return getStringProperty(connectionProps, SQLServerDriverStringProperty.HOSTNAME_IN_CERTIFICATE.toString(), null);
+ return getStringProperty(connectionProps, SQLServerDriverStringProperty.HOSTNAME_IN_CERTIFICATE.toString(),
+ null);
}
- // lockTimeout is the number of milliseconds to wait before the database
- // reports
- // a lock timeout. The default value of -1 means wait forever. If specified,
- // this value will be the default for all statements on the connection. Note
- // a
- // value of 0 means no wait. If lockTimeout is not set, getLockTimeout
- // returns
- // the default of -1.
+ /**
+ * Sets the lock timeout value.
+ *
+ * @param lockTimeout
+ * the number of milliseconds to wait before the database reports a lock timeout. The default value of -1
+ * means wait forever. If specified, this value will be the default for all statements on the connection.
+ * Note a value of 0 means no wait. If lockTimeout is not set, getLockTimeout returns the default of -1.
+ */
@Override
public void setLockTimeout(int lockTimeout) {
setIntProperty(connectionProps, SQLServerDriverIntProperty.LOCK_TIMEOUT.toString(), lockTimeout);
@@ -365,12 +388,13 @@ public int getLockTimeout() {
SQLServerDriverIntProperty.LOCK_TIMEOUT.getDefaultValue());
}
- // setPassword sets the password that will be used when connecting to SQL
- // Server.
- // Note getPassword is deliberately declared non-public for security
- // reasons.
- // If the password is not set, getPassword returns the default value of
- // null.
+ /**
+ * Sets the password that will be used when connecting to SQL Server.
+ *
+ * @param password
+ * Note getPassword is deliberately declared non-public for security reasons. If the password is not set,
+ * getPassword returns the default value of null.
+ */
@Override
public void setPassword(String password) {
setStringProperty(connectionProps, SQLServerDriverStringProperty.PASSWORD.toString(), password);
@@ -380,13 +404,14 @@ String getPassword() {
return getStringProperty(connectionProps, SQLServerDriverStringProperty.PASSWORD.toString(), null);
}
- // portNumber is the TCP-IP port number used when opening a socket
- // connection
- // to SQL Server. If portNumber is not set, getPortNumber returns the
- // default
- // of 1433. Note as mentioned above, setPortNumber does not do any range
- // checking on the port value passed in, invalid port numbers like 99999 can
- // be passed in without triggering any error.
+ /**
+ * Sets the TCP-IP port number used when opening a socket connection to SQL Server.
+ *
+ * @param portNumber
+ * if not set, getPortNumber returns the default of 1433. Note as mentioned above, setPortNumber does not do
+ * any range checking on the port value passed in,\ invalid port numbers like 99999 can be passed in without
+ * triggering any error.
+ */
@Override
public void setPortNumber(int portNumber) {
setIntProperty(connectionProps, SQLServerDriverIntProperty.PORT_NUMBER.toString(), portNumber);
@@ -398,14 +423,16 @@ public int getPortNumber() {
SQLServerDriverIntProperty.PORT_NUMBER.getDefaultValue());
}
- // selectMethod is the default cursor type used for the result set. This
- // property is useful when you are dealing with large result sets and don't
- // want to store the whole result set in memory on the client side. By
- // setting
- // the property to "cursor" you will be able to create a server side cursor
- // that
- // can fetch smaller chunks of data at a time. If selectMethod is not set,
- // getSelectMethod returns the default value of "direct".
+ /**
+ * Sets the default cursor type used for the result set.
+ *
+ * @param selectMethod
+ * This(non-Javadoc) @see com.microsoft.sqlserver.jdbc.ISQLServerDataSource#setSelectMethod(java.lang.String)
+ * property is useful when you are dealing with large result sets and do not want to store the whole result
+ * set in memory on the client side. By setting the property to "cursor" you will be able to create a server
+ * side cursor that can fetch smaller chunks of data at a time. If selectMethod is not set, getSelectMethod
+ * returns the default value of "direct".
+ */
@Override
public void setSelectMethod(String selectMethod) {
setStringProperty(connectionProps, SQLServerDriverStringProperty.SELECT_METHOD.toString(), selectMethod);
@@ -430,7 +457,8 @@ public String getResponseBuffering() {
@Override
public void setApplicationIntent(String applicationIntent) {
- setStringProperty(connectionProps, SQLServerDriverStringProperty.APPLICATION_INTENT.toString(), applicationIntent);
+ setStringProperty(connectionProps, SQLServerDriverStringProperty.APPLICATION_INTENT.toString(),
+ applicationIntent);
}
@Override
@@ -441,7 +469,8 @@ public String getApplicationIntent() {
@Override
public void setSendTimeAsDatetime(boolean sendTimeAsDatetime) {
- setBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.SEND_TIME_AS_DATETIME.toString(), sendTimeAsDatetime);
+ setBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.SEND_TIME_AS_DATETIME.toString(),
+ sendTimeAsDatetime);
}
@Override
@@ -450,14 +479,14 @@ public boolean getSendTimeAsDatetime() {
SQLServerDriverBooleanProperty.SEND_TIME_AS_DATETIME.getDefaultValue());
}
- // If sendStringParametersAsUnicode is set to true (which is the default),
- // string parameters are sent to the server in UNICODE format. If
- // sendStringParametersAsUnicode
- // is set to false, string parameters are sent to the server in the native
- // TDS collation
- // format of the database, not in UNICODE. If sendStringParametersAsUnicode
- // is not set,
- // getSendStringParametersAsUnicode returns the default of true.
+ /**
+ * Sets whether string parameters are sent to the server in UNICODE format.
+ *
+ * @param sendStringParametersAsUnicode
+ * if true (default), string parameters are sent to the server in UNICODE format. if false, string parameters
+ * are sent to the server in the native TDS collation format of the database, not in UNICODE. if set, returns
+ * the default of true.
+ */
@Override
public void setSendStringParametersAsUnicode(boolean sendStringParametersAsUnicode) {
setBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.SEND_STRING_PARAMETERS_AS_UNICODE.toString(),
@@ -466,13 +495,15 @@ public void setSendStringParametersAsUnicode(boolean sendStringParametersAsUnico
@Override
public boolean getSendStringParametersAsUnicode() {
- return getBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.SEND_STRING_PARAMETERS_AS_UNICODE.toString(),
+ return getBooleanProperty(connectionProps,
+ SQLServerDriverBooleanProperty.SEND_STRING_PARAMETERS_AS_UNICODE.toString(),
SQLServerDriverBooleanProperty.SEND_STRING_PARAMETERS_AS_UNICODE.getDefaultValue());
}
@Override
public void setServerNameAsACE(boolean serverNameAsACE) {
- setBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.SERVER_NAME_AS_ACE.toString(), serverNameAsACE);
+ setBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.SERVER_NAME_AS_ACE.toString(),
+ serverNameAsACE);
}
@Override
@@ -481,9 +512,12 @@ public boolean getServerNameAsACE() {
SQLServerDriverBooleanProperty.SERVER_NAME_AS_ACE.getDefaultValue());
}
- // serverName is the host name of the target SQL Server. If serverName is
- // not set,
- // getServerName returns the default value of null is returned.
+ /**
+ * Sets the host name of the target SQL Server.
+ *
+ * @param serverName
+ * if not set, returns the default value of null is returned.
+ */
@Override
public void setServerName(String serverName) {
setStringProperty(connectionProps, SQLServerDriverStringProperty.SERVER_NAME.toString(), serverName);
@@ -494,8 +528,13 @@ public String getServerName() {
return getStringProperty(connectionProps, SQLServerDriverStringProperty.SERVER_NAME.toString(), null);
}
- // Specify an Service Principal Name (SPN) of the target SQL Server.
- // https://msdn.microsoft.com/en-us/library/cc280459.aspx
+ /**
+ * Sets the Service Principal Name (SPN) of the target SQL Server.
+ * https://msdn.microsoft.com/en-us/library/cc280459.aspx
+ *
+ * @param serverSpn
+ * service principal name
+ */
@Override
public void setServerSpn(String serverSpn) {
setStringProperty(connectionProps, SQLServerDriverStringProperty.SERVER_SPN.toString(), serverSpn);
@@ -506,9 +545,12 @@ public String getServerSpn() {
return getStringProperty(connectionProps, SQLServerDriverStringProperty.SERVER_SPN.toString(), null);
}
- // serverName is the host name of the target SQL Server. If serverName is
- // not set,
- // getServerName returns the default value of null is returned.
+ /**
+ * Sets the fail over partner of the target SQL Server.
+ *
+ * @param serverName
+ * if not set, returns the default value of null.
+ */
@Override
public void setFailoverPartner(String serverName) {
setStringProperty(connectionProps, SQLServerDriverStringProperty.FAILOVER_PARTNER.toString(), serverName);
@@ -521,7 +563,8 @@ public String getFailoverPartner() {
@Override
public void setMultiSubnetFailover(boolean multiSubnetFailover) {
- setBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.MULTI_SUBNET_FAILOVER.toString(), multiSubnetFailover);
+ setBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.MULTI_SUBNET_FAILOVER.toString(),
+ multiSubnetFailover);
}
@Override
@@ -530,9 +573,12 @@ public boolean getMultiSubnetFailover() {
SQLServerDriverBooleanProperty.MULTI_SUBNET_FAILOVER.getDefaultValue());
}
- // setUser set's the user name that will be used when connecting to SQL
- // Server.
- // If user is not set, getUser returns the default value of null.
+ /**
+ * Sets the user name that will be used when connecting to SQL Server.
+ *
+ * @param user
+ * if not set, returns the default value of null.
+ */
@Override
public void setUser(String user) {
setStringProperty(connectionProps, SQLServerDriverStringProperty.USER.toString(), user);
@@ -543,12 +589,14 @@ public String getUser() {
return getStringProperty(connectionProps, SQLServerDriverStringProperty.USER.toString(), null);
}
- // workstationID is the name of the client machine (or client workstation).
- // workstationID is the host name of the client in other words. If
- // workstationID
- // is not set, the default value is constructed by calling
- // InetAddress.getLocalHost().getHostName()
- // or if getHostName() returns blank then getHostAddress().toString().
+ /**
+ * Sets the name of the client machine (or client workstation).
+ *
+ * @param workstationID
+ * host name of the client. if not set, the default value is constructed by calling
+ * InetAddress.getLocalHost().getHostName() or if getHostName() returns blank then
+ * getHostAddress().toString().
+ */
@Override
public void setWorkstationID(String workstationID) {
setStringProperty(connectionProps, SQLServerDriverStringProperty.WORKSTATION_ID.toString(), workstationID);
@@ -568,13 +616,13 @@ public String getWorkstationID() {
return getWSID;
}
- // If xopenStates is set to true, the driver will convert SQL states to
- // XOPEN
- // compliant states. The default is false which causes the driver to
- // generate SQL 99
- // state codes. If xopenStates is not set, getXopenStates returns the
- // default value
- // of false.
+ /**
+ * Sets whether the driver will convert SQL states to XOPEN compliant states.
+ *
+ * @param xopenStates
+ * if true, the driver will convert SQL states to XOPEN compliant states. The default is false which causes
+ * the driver to generate SQL 99 state codes. If not set, getXopenStates returns the default value of false.
+ */
@Override
public void setXopenStates(boolean xopenStates) {
setBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.XOPEN_STATES.toString(), xopenStates);
@@ -610,7 +658,8 @@ public String getSSLProtocol() {
@Override
public void setTrustManagerClass(String trustManagerClass) {
- setStringProperty(connectionProps, SQLServerDriverStringProperty.TRUST_MANAGER_CLASS.toString(), trustManagerClass);
+ setStringProperty(connectionProps, SQLServerDriverStringProperty.TRUST_MANAGER_CLASS.toString(),
+ trustManagerClass);
}
@Override
@@ -621,35 +670,30 @@ public String getTrustManagerClass() {
@Override
public void setTrustManagerConstructorArg(String trustManagerConstructorArg) {
- setStringProperty(connectionProps, SQLServerDriverStringProperty.TRUST_MANAGER_CONSTRUCTOR_ARG.toString(), trustManagerConstructorArg);
+ setStringProperty(connectionProps, SQLServerDriverStringProperty.TRUST_MANAGER_CONSTRUCTOR_ARG.toString(),
+ trustManagerConstructorArg);
}
@Override
public String getTrustManagerConstructorArg() {
- return getStringProperty(connectionProps, SQLServerDriverStringProperty.TRUST_MANAGER_CONSTRUCTOR_ARG.toString(),
+ return getStringProperty(connectionProps,
+ SQLServerDriverStringProperty.TRUST_MANAGER_CONSTRUCTOR_ARG.toString(),
SQLServerDriverStringProperty.TRUST_MANAGER_CONSTRUCTOR_ARG.getDefaultValue());
}
- // The URL property is exposed for backwards compatibility reasons. Also,
- // several
- // Java Application servers expect a setURL function on the DataSource and
- // set it
- // by default (JBoss and WebLogic).
-
- // Note for security reasons we do not recommend that customers include the
- // password
- // in the url supplied to setURL. The reason for this is third-party Java
- // Application
- // Servers will very often display the value set to URL property in their
- // DataSource
- // configuration GUI. We recommend instead that clients use the setPassword
- // method
- // to set the password value. The Java Application Servers will not display
- // a password
- // that is set on the DataSource in the configuration GUI.
-
- // Note if setURL is not called, getURL returns the default value of
- // "jdbc:sqlserver://".
+ /**
+ * Sets the datasource URL.
+ *
+ * @param url
+ * The URL property is exposed for backwards compatibility reasons. Also, several Java Application servers
+ * expect a setURL function on the DataSource and set it by default (JBoss and WebLogic) Note for security
+ * reasons we do not recommend that customers include the password in the url supplied to setURL. The reason
+ * for this is third-party Java Application Servers will very often display the value set to URL property in
+ * their DataSource configuration GUI. We recommend instead that clients use the setPassword method to set
+ * the password value. The Java Application Servers will not display a password that is set on the DataSource
+ * in the configuration GUI. Note if setURL is not called, getURL returns the default value of
+ * "jdbc:sqlserver://".
+ */
@Override
public void setURL(String url) {
loggerExternal.entering(getClassNameLogging(), "setURL", url);
@@ -669,9 +713,10 @@ public String getURL() {
return url;
}
- // DataSource specific property setters/getters.
- // Per JDBC specification 16.1.1 "...the only property that all DataSource
- // implementations are required to support is the description property".
+ /**
+ * Sets the DataSource description. Per JDBC specification 16.1.1 "...the only property that all DataSource
+ * implementations are required to support is the description property".
+ */
@Override
public void setDescription(String description) {
loggerExternal.entering(getClassNameLogging(), "setDescription", description);
@@ -679,6 +724,9 @@ public void setDescription(String description) {
loggerExternal.exiting(getClassNameLogging(), "setDescription");
}
+ /**
+ * Returns the DataSource description
+ */
@Override
public String getDescription() {
loggerExternal.entering(getClassNameLogging(), "getDescription");
@@ -686,10 +734,14 @@ public String getDescription() {
return dataSourceDescription;
}
- // packetSize is the size (in bytes) to use for the TCP/IP send and receive
- // buffer. It is also the value used for the TDS packet size (SQL Server
- // Network Packet Size). Validity of the value is checked at connect time.
- // If no value is set for this property, its default value is 4KB.
+ /**
+ * Sets the packet size.
+ *
+ * @param packetSize
+ * the size (in bytes) to use for the TCP/IP send and receive buffer. It is also the value used for the TDS
+ * packet size (SQL Server Network Packet Size). Validity of the value is checked at connect time. If no
+ * value is set for this property, its default value is 4KB.
+ */
@Override
public void setPacketSize(int packetSize) {
setIntProperty(connectionProps, SQLServerDriverIntProperty.PACKET_SIZE.toString(), packetSize);
@@ -725,49 +777,57 @@ public int getCancelQueryTimeout() {
@Override
public void setEnablePrepareOnFirstPreparedStatementCall(boolean enablePrepareOnFirstPreparedStatementCall) {
- setBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.ENABLE_PREPARE_ON_FIRST_PREPARED_STATEMENT.toString(),
+ setBooleanProperty(connectionProps,
+ SQLServerDriverBooleanProperty.ENABLE_PREPARE_ON_FIRST_PREPARED_STATEMENT.toString(),
enablePrepareOnFirstPreparedStatementCall);
}
@Override
public boolean getEnablePrepareOnFirstPreparedStatementCall() {
- boolean defaultValue = SQLServerDriverBooleanProperty.ENABLE_PREPARE_ON_FIRST_PREPARED_STATEMENT.getDefaultValue();
- return getBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.ENABLE_PREPARE_ON_FIRST_PREPARED_STATEMENT.toString(),
- defaultValue);
+ boolean defaultValue = SQLServerDriverBooleanProperty.ENABLE_PREPARE_ON_FIRST_PREPARED_STATEMENT
+ .getDefaultValue();
+ return getBooleanProperty(connectionProps,
+ SQLServerDriverBooleanProperty.ENABLE_PREPARE_ON_FIRST_PREPARED_STATEMENT.toString(), defaultValue);
}
@Override
public void setServerPreparedStatementDiscardThreshold(int serverPreparedStatementDiscardThreshold) {
- setIntProperty(connectionProps, SQLServerDriverIntProperty.SERVER_PREPARED_STATEMENT_DISCARD_THRESHOLD.toString(),
+ setIntProperty(connectionProps,
+ SQLServerDriverIntProperty.SERVER_PREPARED_STATEMENT_DISCARD_THRESHOLD.toString(),
serverPreparedStatementDiscardThreshold);
}
@Override
public int getServerPreparedStatementDiscardThreshold() {
int defaultSize = SQLServerDriverIntProperty.SERVER_PREPARED_STATEMENT_DISCARD_THRESHOLD.getDefaultValue();
- return getIntProperty(connectionProps, SQLServerDriverIntProperty.SERVER_PREPARED_STATEMENT_DISCARD_THRESHOLD.toString(), defaultSize);
+ return getIntProperty(connectionProps,
+ SQLServerDriverIntProperty.SERVER_PREPARED_STATEMENT_DISCARD_THRESHOLD.toString(), defaultSize);
}
@Override
public void setStatementPoolingCacheSize(int statementPoolingCacheSize) {
- setIntProperty(connectionProps, SQLServerDriverIntProperty.STATEMENT_POOLING_CACHE_SIZE.toString(), statementPoolingCacheSize);
+ setIntProperty(connectionProps, SQLServerDriverIntProperty.STATEMENT_POOLING_CACHE_SIZE.toString(),
+ statementPoolingCacheSize);
}
@Override
public int getStatementPoolingCacheSize() {
int defaultSize = SQLServerDriverIntProperty.STATEMENT_POOLING_CACHE_SIZE.getDefaultValue();
- return getIntProperty(connectionProps, SQLServerDriverIntProperty.STATEMENT_POOLING_CACHE_SIZE.toString(), defaultSize);
+ return getIntProperty(connectionProps, SQLServerDriverIntProperty.STATEMENT_POOLING_CACHE_SIZE.toString(),
+ defaultSize);
}
@Override
public void setDisableStatementPooling(boolean disableStatementPooling) {
- setBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.DISABLE_STATEMENT_POOLING.toString(), disableStatementPooling);
+ setBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.DISABLE_STATEMENT_POOLING.toString(),
+ disableStatementPooling);
}
@Override
public boolean getDisableStatementPooling() {
boolean defaultValue = SQLServerDriverBooleanProperty.DISABLE_STATEMENT_POOLING.getDefaultValue();
- return getBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.DISABLE_STATEMENT_POOLING.toString(), defaultValue);
+ return getBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.DISABLE_STATEMENT_POOLING.toString(),
+ defaultValue);
}
@Override
@@ -783,18 +843,21 @@ public int getSocketTimeout() {
@Override
public void setUseBulkCopyForBatchInsert(boolean useBulkCopyForBatchInsert) {
- setBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.USE_BULK_COPY_FOR_BATCH_INSERT.toString(), useBulkCopyForBatchInsert);
+ setBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.USE_BULK_COPY_FOR_BATCH_INSERT.toString(),
+ useBulkCopyForBatchInsert);
}
@Override
public boolean getUseBulkCopyForBatchInsert() {
- return getBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.USE_BULK_COPY_FOR_BATCH_INSERT.toString(),
+ return getBooleanProperty(connectionProps,
+ SQLServerDriverBooleanProperty.USE_BULK_COPY_FOR_BATCH_INSERT.toString(),
SQLServerDriverBooleanProperty.USE_BULK_COPY_FOR_BATCH_INSERT.getDefaultValue());
}
@Override
public void setJASSConfigurationName(String configurationName) {
- setStringProperty(connectionProps, SQLServerDriverStringProperty.JAAS_CONFIG_NAME.toString(), configurationName);
+ setStringProperty(connectionProps, SQLServerDriverStringProperty.JAAS_CONFIG_NAME.toString(),
+ configurationName);
}
@Override
@@ -803,77 +866,67 @@ public String getJASSConfigurationName() {
SQLServerDriverStringProperty.JAAS_CONFIG_NAME.getDefaultValue());
}
- // responseBuffering controls the driver's buffering of responses from SQL
- // Server.
- // Possible values are:
- //
- // "full" - Fully buffer the response at execution time.
- // Advantages:
- // 100% back compat with v1.1 driver
- // Maximizes concurrency on the server
- // Disadvantages:
- // Consumes more client-side memory
- // Client scalability limits with large responses
- // More execute latency
- //
- // "adaptive" - Data Pipe adaptive buffering
- // Advantages:
- // Buffers only when necessary, only as much as necessary
- // Enables handling very large responses, values
- // Disadvantages
- // Reduced concurrency on the server
- // Internal functions for setting/getting property values.
-
- // Set a string property value.
- // Caller will always supply a non-null props and propKey.
- // Caller may supply a null propValue, in this case no property value is
- // set.
- private void setStringProperty(Properties props,
- String propKey,
- String propValue) {
- if (loggerExternal.isLoggable(java.util.logging.Level.FINER) && !propKey.contains("password") && !propKey.contains("Password")) {
+ /**
+ * Sets a property string value.
+ *
+ * @param props
+ * @param propKey
+ * @param propValue
+ * Caller will always supply a non-null props and propKey. Caller may supply a null propValue, in this case
+ * no property value is set.
+ */
+ private void setStringProperty(Properties props, String propKey, String propValue) {
+ if (loggerExternal.isLoggable(java.util.logging.Level.FINER) && !propKey.contains("password")
+ && !propKey.contains("Password")) {
loggerExternal.entering(getClassNameLogging(), "set" + propKey, propValue);
- }
- else
+ } else
loggerExternal.entering(getClassNameLogging(), "set" + propKey);
if (null != propValue)
props.setProperty(propKey, propValue);
loggerExternal.exiting(getClassNameLogging(), "set" + propKey);
}
- // Reads property value in String format.
- // Caller will always supply a non-null props and propKey.
- // Returns null if the specific property value is not set.
- private String getStringProperty(Properties props,
- String propKey,
- String defaultValue) {
+ /**
+ * Returns a property value in String format.
+ *
+ * @param props
+ * @param propKey
+ * @param defaultValue
+ * @return Caller will always supply a non-null props and propKey. Returns null if the specific property value is
+ * not set.
+ */
+ private String getStringProperty(Properties props, String propKey, String defaultValue) {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "get" + propKey);
String propValue = props.getProperty(propKey);
if (null == propValue)
propValue = defaultValue;
- if (loggerExternal.isLoggable(java.util.logging.Level.FINER) && !propKey.contains("password") && !propKey.contains("Password"))
+ if (loggerExternal.isLoggable(java.util.logging.Level.FINER) && !propKey.contains("password")
+ && !propKey.contains("Password"))
loggerExternal.exiting(getClassNameLogging(), "get" + propKey, propValue);
return propValue;
}
- // Set an integer property value.
- // Caller will always supply a non-null props and propKey.
- private void setIntProperty(Properties props,
- String propKey,
- int propValue) {
+ /**
+ * Sets an integer property value.
+ *
+ * @param props
+ * @param propKey
+ * @param propValue
+ * Caller will always supply a non-null props and propKey.
+ */
+ private void setIntProperty(Properties props, String propKey, int propValue) {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "set" + propKey, propValue);
props.setProperty(propKey, Integer.valueOf(propValue).toString());
loggerExternal.exiting(getClassNameLogging(), "set" + propKey);
}
- // Reads a property value in int format.
- // Caller will always supply a non-null props and propKey.
- // Returns defaultValue if the specific property value is not set.
- private int getIntProperty(Properties props,
- String propKey,
- int defaultValue) {
+ /**
+ * Returns a property value in int format. Caller will always supply a non-null props and propKey. Returns
+ * defaultValue if the specific property value is not set.
+ */
+ private int getIntProperty(Properties props, String propKey, int defaultValue) {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "get" + propKey);
String propValue = props.getProperty(propKey);
@@ -881,8 +934,7 @@ private int getIntProperty(Properties props,
if (null != propValue) {
try {
value = Integer.parseInt(propValue);
- }
- catch (NumberFormatException nfe) {
+ } catch (NumberFormatException nfe) {
// This exception cannot occur as all of our properties
// are set internally by int -> Integer.toString.
assert false : "Bad portNumber:-" + propValue;
@@ -893,31 +945,28 @@ private int getIntProperty(Properties props,
return value;
}
- // Set a boolean property value.
- // Caller will always supply a non-null props and propKey.
- private void setBooleanProperty(Properties props,
- String propKey,
- boolean propValue) {
+ /**
+ * Set a boolean property value. Caller will always supply a non-null props and propKey.
+ */
+ private void setBooleanProperty(Properties props, String propKey, boolean propValue) {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "set" + propKey, propValue);
props.setProperty(propKey, (propValue) ? "true" : "false");
loggerExternal.exiting(getClassNameLogging(), "set" + propKey);
}
- // Reads a property value in boolean format.
- // Caller will always supply a non-null props and propKey.
- // Returns defaultValue if the specific property value is not set.
- private boolean getBooleanProperty(Properties props,
- String propKey,
- boolean defaultValue) {
+ /**
+ * Returns a property value in boolean format. Caller will always supply a non-null props and propKey. Returns
+ * defaultValue if the specific property value is not set.
+ */
+ private boolean getBooleanProperty(Properties props, String propKey, boolean defaultValue) {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "get" + propKey);
String propValue = props.getProperty(propKey);
Boolean value;
if (null == propValue) {
value = defaultValue;
- }
- else {
+ } else {
// Since we set the value of the String property ourselves to
// "true" or "false", we can do this.
value = Boolean.valueOf(propValue);
@@ -926,9 +975,7 @@ private boolean getBooleanProperty(Properties props,
return value;
}
- private void setObjectProperty(Properties props,
- String propKey,
- Object propValue) {
+ private void setObjectProperty(Properties props, String propKey, Object propValue) {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER)) {
loggerExternal.entering(getClassNameLogging(), "set" + propKey);
}
@@ -938,9 +985,7 @@ private void setObjectProperty(Properties props,
loggerExternal.exiting(getClassNameLogging(), "set" + propKey);
}
- private Object getObjectProperty(Properties props,
- String propKey,
- Object defaultValue) {
+ private Object getObjectProperty(Properties props, String propKey, Object defaultValue) {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "get" + propKey);
Object propValue = props.get(propKey);
@@ -950,26 +995,21 @@ private Object getObjectProperty(Properties props,
return propValue;
}
- // Returns a SQLServerConnection given username, password, and
- // pooledConnection.
- // Note that the DataSource properties set to connectionProps are used when
- // creating
- // the connection.
-
- // Both username and password can be null.
-
- // If pooledConnection is not null, then connection returned is attached to
- // the pooledConnection
- // and participates in connection pooling.
- SQLServerConnection getConnectionInternal(String username,
- String password,
+ /**
+ * Returns a SQLServerConnection given username, password, and pooledConnection. Note that the DataSource properties
+ * set to connectionProps are used when creating the connection. Both username and password can be null. If
+ * pooledConnection is not null, then connection returned is attached to the pooledConnection and participates in
+ * connection pooling.
+ */
+ SQLServerConnection getConnectionInternal(String username, String password,
SQLServerPooledConnection pooledConnection) throws SQLServerException {
Properties userSuppliedProps;
Properties mergedProps;
// Trust store password stripped and this object got created via
// Objectfactory referencing.
if (trustStorePasswordStripped)
- SQLServerException.makeFromDriverError(null, null, SQLServerException.getErrString("R_referencingFailedTSP"), null, true);
+ SQLServerException.makeFromDriverError(null, null,
+ SQLServerException.getErrString("R_referencingFailedTSP"), null, true);
// If username or password is passed in, clone the property set so we
// don't alter original connectionProps.
@@ -986,8 +1026,7 @@ SQLServerConnection getConnectionInternal(String username,
userSuppliedProps.put(SQLServerDriverStringProperty.USER.toString(), username);
if (null != password)
userSuppliedProps.put(SQLServerDriverStringProperty.PASSWORD.toString(), password);
- }
- else {
+ } else {
userSuppliedProps = connectionProps;
}
@@ -997,11 +1036,11 @@ SQLServerConnection getConnectionInternal(String username,
// null returned properties means that the passed in URL is not
// supported.
if (null == urlProps)
- SQLServerException.makeFromDriverError(null, null, SQLServerException.getErrString("R_errorConnectionString"), null, true);
+ SQLServerException.makeFromDriverError(null, null,
+ SQLServerException.getErrString("R_errorConnectionString"), null, true);
// Manually merge URL props and user supplied props.
mergedProps = SQLServerDriver.mergeURLAndSuppliedProperties(urlProps, userSuppliedProps);
- }
- else {
+ } else {
mergedProps = userSuppliedProps;
}
@@ -1011,8 +1050,7 @@ SQLServerConnection getConnectionInternal(String username,
SQLServerConnection result = null;
if (Util.use43Wrapper()) {
result = new SQLServerConnection43(toString());
- }
- else {
+ } else {
result = new SQLServerConnection(toString());
}
result.connect(mergedProps, pooledConnection);
@@ -1035,7 +1073,8 @@ Reference getReferenceInternal(String dataSourceClassString) {
if (dsLogger.isLoggable(Level.FINER))
dsLogger.finer(toString() + " creating reference for " + dataSourceClassString + ".");
- Reference ref = new Reference(this.getClass().getName(), "com.microsoft.sqlserver.jdbc.SQLServerDataSourceObjectFactory", null);
+ Reference ref = new Reference(this.getClass().getName(),
+ "com.microsoft.sqlserver.jdbc.SQLServerDataSourceObjectFactory", null);
if (null != dataSourceClassString)
ref.add(new StringRefAddr("class", dataSourceClassString));
@@ -1053,8 +1092,7 @@ Reference getReferenceInternal(String dataSourceClassString) {
// possible
assert trustStorePasswordStripped == false;
ref.add(new StringRefAddr("trustStorePasswordStripped", "true"));
- }
- else {
+ } else {
// do not add passwords to the collection. we have normal
// password
if (!propertyName.contains(SQLServerDriverStringProperty.PASSWORD.toString()))
@@ -1073,10 +1111,12 @@ Reference getReferenceInternal(String dataSourceClassString) {
return ref;
}
- // Initialize this datasource from properties found inside the reference
- // ref.
- // Called by SQLServerDataSourceObjectFactory to initialize new DataSource
- // instance.
+ /**
+ * Initializes the datasource from properties found inside the reference
+ *
+ * @param ref
+ * Called by SQLServerDataSourceObjectFactory to initialize new DataSource instance.
+ */
void initializeFromReference(javax.naming.Reference ref) {
// Enumerate all the StringRefAddr objects in the Reference and assign
// properties appropriately.
@@ -1089,11 +1129,9 @@ void initializeFromReference(javax.naming.Reference ref) {
// Special case dataSourceURL and dataSourceDescription.
if ("dataSourceURL".equals(propertyName)) {
dataSourceURL = propertyValue;
- }
- else if ("dataSourceDescription".equals(propertyName)) {
+ } else if ("dataSourceDescription".equals(propertyName)) {
dataSourceDescription = propertyValue;
- }
- else if ("trustStorePasswordStripped".equals(propertyName)) {
+ } else if ("trustStorePasswordStripped".equals(propertyName)) {
trustStorePasswordStripped = true;
}
// Just skip "class" StringRefAddr, it does not go into
@@ -1119,8 +1157,7 @@ public T unwrap(Class iface) throws SQLException {
T t;
try {
t = iface.cast(this);
- }
- catch (ClassCastException e) {
+ } catch (ClassCastException e) {
throw new SQLServerException(e.getMessage(), e);
}
loggerExternal.exiting(getClassNameLogging(), "unwrap", t);
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDataSourceObjectFactory.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDataSourceObjectFactory.java
index 256635954..59fc884b1 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDataSourceObjectFactory.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDataSourceObjectFactory.java
@@ -1,9 +1,6 @@
/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc;
@@ -15,28 +12,26 @@
import javax.naming.Name;
import javax.naming.spi.ObjectFactory;
+
/**
- * SQLServerDataSourceObjectFactory is an object factory to materialize datasources from JNDI.
+ * Defines an object factory to materialize datasources from JNDI.
*/
-
public final class SQLServerDataSourceObjectFactory implements ObjectFactory {
// NOTE: Per ObjectFactory spec, the ObjectFactory class requires a public
// class with public constructor.
/**
- * Initializes a new instance of the SQLServerDataSourceObjectFactory class.
+ * Constructs a SQLServerDataSourceObjectFactory.
*/
- public SQLServerDataSourceObjectFactory() {
- }
+ public SQLServerDataSourceObjectFactory() {}
- // getObjectInstance is a factory for rehydrating references to SQLServerDataSource and its child classes.
- // Caller gets the reference by calling SQLServerDataSource.getReference.
- // References are used by JNDI to persist and rehydrate objects.
- public Object getObjectInstance(Object ref,
- Name name,
- Context c,
- Hashtable, ?> h) throws SQLServerException {
+ /**
+ * Returns an reference to the SQLServerDataSource instance getObjectInstance is a factory for rehydrating
+ * references to SQLServerDataSource and its child classes. Caller gets the reference by calling
+ * SQLServerDataSource.getReference. References are used by JNDI to persist and rehydrate objects.
+ */
+ public Object getObjectInstance(Object ref, Name name, Context c, Hashtable, ?> h) throws SQLServerException {
// Create a new instance of a DataSource class from the given reference.
try {
javax.naming.Reference r = (javax.naming.Reference) ref;
@@ -71,9 +66,8 @@ public Object getObjectInstance(Object ref,
}
// Class not found, throw invalid reference exception.
throwInvalidDataSourceRefException();
- }
- catch (ClassNotFoundException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
- | NoSuchMethodException | SecurityException e) {
+ } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | IllegalArgumentException
+ | InvocationTargetException | NoSuchMethodException | SecurityException e) {
throwInvalidDataSourceRefException();
}
// no chance of getting here but to keep the compiler happy
@@ -81,7 +75,8 @@ public Object getObjectInstance(Object ref,
}
private void throwInvalidDataSourceRefException() throws SQLServerException {
- SQLServerException.makeFromDriverError(null, null, SQLServerException.getErrString("R_invalidDataSourceReference"), null, true);
+ SQLServerException.makeFromDriverError(null, null,
+ SQLServerException.getErrString("R_invalidDataSourceReference"), null, true);
}
}
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDataTable.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDataTable.java
index 1e894bdf9..e64827187 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDataTable.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDataTable.java
@@ -1,9 +1,6 @@
/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc;
@@ -21,6 +18,10 @@
import java.util.Set;
import java.util.UUID;
+
+/**
+ * Represents the data table for SQL Server.
+ */
public final class SQLServerDataTable {
int rowCount = 0;
@@ -32,10 +33,11 @@ public final class SQLServerDataTable {
private String tvpName = null;
/**
- * The constant in the Java programming language, sometimes referred to as a type code, that identifies the type TVP.
+ * The constant in the Java programming language, sometimes referred to as a type code, that identifies the type
+ * TVP.
*
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
// Name used in CREATE TYPE
public SQLServerDataTable() throws SQLServerException {
@@ -55,7 +57,7 @@ public synchronized void clear() {
}
/**
- * Retrieves an iterator on the rows of the data table.
+ * Returns an iterator on the rows of the data table.
*
* @return an iterator on the rows of the data table.
*/
@@ -67,29 +69,28 @@ public synchronized Iterator> getIterator() {
}
/**
- * Adds meta data for the specified column
+ * Adds meta data for the specified column.
*
* @param columnName
- * the name of the column
+ * the name of the column
* @param sqlType
- * the sql type of the column
+ * the sql type of the column
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- public synchronized void addColumnMetadata(String columnName,
- int sqlType) throws SQLServerException {
+ public synchronized void addColumnMetadata(String columnName, int sqlType) throws SQLServerException {
// column names must be unique
Util.checkDuplicateColumnName(columnName, columnNames);
columnMetadata.put(columnCount++, new SQLServerDataColumn(columnName, sqlType));
}
/**
- * Adds meta data for the specified column
+ * Adds meta data for the specified column.
*
* @param column
- * the name of the column
+ * the name of the column
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
public synchronized void addColumnMetadata(SQLServerDataColumn column) throws SQLServerException {
// column names must be unique
@@ -101,16 +102,17 @@ public synchronized void addColumnMetadata(SQLServerDataColumn column) throws SQ
* Adds one row of data to the data table.
*
* @param values
- * values to be added in one row of data to the data table.
+ * values to be added in one row of data to the data table.
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
public synchronized void addRow(Object... values) throws SQLServerException {
try {
int columnCount = columnMetadata.size();
if ((null != values) && values.length > columnCount) {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_moreDataInRowThanColumnInTVP"));
+ MessageFormat form = new MessageFormat(
+ SQLServerException.getErrString("R_moreDataInRowThanColumnInTVP"));
Object[] msgArgs = {};
throw new SQLServerException(null, form.format(msgArgs), null, 0, false);
}
@@ -129,11 +131,9 @@ public synchronized void addRow(Object... values) throws SQLServerException {
internalAddrow(jdbcType, val, rowValues, pair);
}
rows.put(rowCount++, rowValues);
- }
- catch (NumberFormatException e) {
+ } catch (NumberFormatException e) {
throw new SQLServerException(SQLServerException.getErrString("R_TVPInvalidColumnValue"), e);
- }
- catch (ClassCastException e) {
+ } catch (ClassCastException e) {
throw new SQLServerException(SQLServerException.getErrString("R_TVPInvalidColumnValue"), e);
}
@@ -143,19 +143,17 @@ public synchronized void addRow(Object... values) throws SQLServerException {
* Adding rows one row of data to data table.
*
* @param jdbcType
- * The jdbcType
+ * The jdbcType
* @param val
- * The data value
+ * The data value
* @param rowValues
- * Row of data
+ * Row of data
* @param pair
- * pair to be added to data table
+ * pair to be added to data table
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- private void internalAddrow(JDBCType jdbcType,
- Object val,
- Object[] rowValues,
+ private void internalAddrow(JDBCType jdbcType, Object val, Object[] rowValues,
Map.Entry pair) throws SQLServerException {
SQLServerDataColumn currentColumnMetadata = pair.getValue();
@@ -205,7 +203,8 @@ private void internalAddrow(JDBCType jdbcType,
}
if (isColumnMetadataUpdated) {
- currentColumnMetadata.precision = currentColumnMetadata.scale + currentColumnMetadata.numberOfDigitsIntegerPart;
+ currentColumnMetadata.precision = currentColumnMetadata.scale
+ + currentColumnMetadata.numberOfDigitsIntegerPart;
columnMetadata.put(pair.getKey(), currentColumnMetadata);
}
}
@@ -230,7 +229,8 @@ private void internalAddrow(JDBCType jdbcType,
case DATETIME:
case SMALLDATETIME:
// Sending temporal types as string. Error from database is thrown if parsing fails
- // no need to send precision for temporal types, string literal will never exceed DataTypes.SHORT_VARTYPE_MAX_BYTES
+ // no need to send precision for temporal types, string literal will never exceed
+ // DataTypes.SHORT_VARTYPE_MAX_BYTES
if (null == val)
rowValues[pair.getKey()] = null;
@@ -282,7 +282,8 @@ else if (val instanceof OffsetTime)
case SQL_VARIANT:
JDBCType internalJDBCType;
if (null == val) { // TODO:Check this later
- throw new SQLServerException(SQLServerException.getErrString("R_invalidValueForTVPWithSQLVariant"), null);
+ throw new SQLServerException(SQLServerException.getErrString("R_invalidValueForTVPWithSQLVariant"),
+ null);
}
JavaType javaType = JavaType.of(val);
internalJDBCType = javaType.getJDBCType(SSType.UNKNOWN, jdbcType);
@@ -296,8 +297,8 @@ else if (val instanceof OffsetTime)
}
/**
- * Retrieves java.util.Map
object type of columnMetaData for all columns where column indexes are mapped with their
- * respective {@link SQLServerDataColumn} Java object
+ * Returns the java.util.Map
object type of columnMetaData for all columns where column indexes are
+ * mapped with their respective {@link SQLServerDataColumn} Java object.
*
* @return Map
*/
@@ -306,7 +307,7 @@ public synchronized Map getColumnMetadata() {
}
/**
- * Returns name of TVP type set by {@link #setTvpName(String)}
+ * Returns name of TVP type set by {@link #setTvpName(String)}.
*
* @return tvpName
*/
@@ -315,10 +316,10 @@ public String getTvpName() {
}
/**
- * Sets the TVP Name
+ * Sets the TVP Name.
*
* @param tvpName
- * the name of TVP
+ * the name of TVP
*/
public void setTvpName(String tvpName) {
this.tvpName = tvpName;
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDatabaseMetaData.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDatabaseMetaData.java
index 9c9fb5513..aca757bc9 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDatabaseMetaData.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDatabaseMetaData.java
@@ -1,9 +1,6 @@
/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc;
@@ -21,11 +18,12 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level;
+
/**
- * SQLServerDatabaseMetaData provides JDBC database meta data.
+ * Provides the JDBC database meta data.
*
- * The API javadoc for JDBC API methods that this class implements are not repeated here. Please see Sun's JDBC API interfaces javadoc for those
- * details.
+ * The API javadoc for JDBC API methods that this class implements are not repeated here. Please see Sun's JDBC API
+ * interfaces javadoc for those details.
*/
public final class SQLServerDatabaseMetaData implements java.sql.DatabaseMetaData {
private SQLServerConnection connection;
@@ -71,8 +69,7 @@ enum CallableHandles {
// procs on or after katmai
private final String katProc;
- private CallableHandles(String name,
- String katName) {
+ private CallableHandles(String name, String katName) {
this.preKatProc = name;
this.katProc = katName;
}
@@ -86,8 +83,7 @@ final class HandleAssociation {
final String databaseName;
final CallableStatement stmt;
- HandleAssociation(String databaseName,
- CallableStatement stmt) {
+ HandleAssociation(String databaseName, CallableStatement stmt) {
this.databaseName = databaseName;
this.stmt = stmt;
}
@@ -105,7 +101,7 @@ private static int nextInstanceID() {
}
/**
- * This is a helper function to provide an ID string suitable for tracing.
+ * Provides a helper function to provide an ID string suitable for tracing.
*
* @return traceID string
*/
@@ -114,10 +110,10 @@ final public String toString() {
}
/**
- * Create new database meta data
+ * Constructs a SQLServerDatabaseMetaData database meta data
*
* @param con
- * the connection
+ * the connection
*/
public SQLServerDatabaseMetaData(SQLServerConnection con) {
traceID = " SQLServerDatabaseMetaData:" + nextInstanceID();
@@ -138,8 +134,7 @@ public T unwrap(Class iface) throws SQLException {
T t;
try {
t = iface.cast(this);
- }
- catch (ClassCastException e) {
+ } catch (ClassCastException e) {
throw new SQLServerException(e.getMessage(), e);
}
return t;
@@ -238,12 +233,12 @@ private void checkClosed() throws SQLServerException {
private static final String IS_AUTOINCREMENT = "IS_AUTOINCREMENT";
/**
- * Make a simple query execute and return the result from it. This is to be used only for internal queries without any user input.
+ * Returns the result from a simple query. This is to be used only for internal queries without any user input.
*
* @param catalog
- * catalog the query to be made in
+ * catalog the query to be made in
* @param query
- * to execute
+ * to execute
* @return Resultset from the execution
* @throws SQLTimeoutException
*/
@@ -255,8 +250,7 @@ private SQLServerResultSet getResultSetFromInternalQueries(String catalog,
SQLServerResultSet rs = null;
try {
rs = ((SQLServerStatement) connection.createStatement()).executeQueryInternal(query);
- }
- finally {
+ } finally {
if (null != orgCat) {
connection.setCatalog(orgCat);
}
@@ -264,8 +258,8 @@ private SQLServerResultSet getResultSetFromInternalQueries(String catalog,
return rs;
}
- /*
- * Note we pool the handles per object.
+ /**
+ * Returns the CallableStatement handle. Note we pool the handles per object.
*/
private CallableStatement getCallableStatementHandle(CallableHandles request,
String catalog) throws SQLServerException {
@@ -283,19 +277,18 @@ private CallableStatement getCallableStatementHandle(CallableHandles request,
}
/**
- * Make the stored procedure call and return the result from it.
+ * Returns the result from the stored procedure call.
*
* @param catalog
- * catalog the query to be made in
+ * catalog the query to be made in
* @param procedure
- * to execute
+ * to execute
* @param arguments
- * for the stored procedure
+ * for the stored procedure
* @return Resultset from the execution
* @throws SQLTimeoutException
*/
- private SQLServerResultSet getResultSetFromStoredProc(String catalog,
- CallableHandles procedure,
+ private SQLServerResultSet getResultSetFromStoredProc(String catalog, CallableHandles procedure,
String[] arguments) throws SQLServerException, SQLTimeoutException {
checkClosed();
assert null != arguments;
@@ -303,15 +296,15 @@ private SQLServerResultSet getResultSetFromStoredProc(String catalog,
orgCat = switchCatalogs(catalog);
SQLServerResultSet rs = null;
try {
- SQLServerCallableStatement call = (SQLServerCallableStatement) getCallableStatementHandle(procedure, catalog);
+ SQLServerCallableStatement call = (SQLServerCallableStatement) getCallableStatementHandle(procedure,
+ catalog);
for (int i = 1; i <= arguments.length; i++) {
// note individual arguments can be null.
call.setString(i, arguments[i - 1]);
}
rs = (SQLServerResultSet) call.executeQueryInternal();
- }
- finally {
+ } finally {
if (null != orgCat) {
connection.setCatalog(orgCat);
}
@@ -319,10 +312,8 @@ private SQLServerResultSet getResultSetFromStoredProc(String catalog,
return rs;
}
- private SQLServerResultSet getResultSetWithProvidedColumnNames(String catalog,
- CallableHandles procedure,
- String[] arguments,
- String[] columnNames) throws SQLServerException, SQLTimeoutException {
+ private SQLServerResultSet getResultSetWithProvidedColumnNames(String catalog, CallableHandles procedure,
+ String[] arguments, String[] columnNames) throws SQLServerException, SQLTimeoutException {
// Execute the query
SQLServerResultSet rs = getResultSetFromStoredProc(catalog, procedure, arguments);
@@ -333,10 +324,10 @@ private SQLServerResultSet getResultSetWithProvidedColumnNames(String catalog,
}
/**
- * Switch database catalogs.
+ * Switches the database catalogs.
*
* @param catalog
- * the new catalog
+ * the new catalog
* @throws SQLServerException
* @return the old catalog
*/
@@ -446,13 +437,12 @@ public String getCatalogTerm() throws SQLServerException {
return "database";
}
- private static final String[] getColumnPrivilegesColumnNames = {/* 1 */ TABLE_CAT, /* 2 */ TABLE_SCHEM, /* 3 */ TABLE_NAME, /* 4 */ COLUMN_NAME,
- /* 5 */ GRANTOR, /* 6 */ GRANTEE, /* 7 */ PRIVILEGE, /* 8 */ IS_GRANTABLE};
+ private static final String[] getColumnPrivilegesColumnNames = {/* 1 */ TABLE_CAT, /* 2 */ TABLE_SCHEM,
+ /* 3 */ TABLE_NAME, /* 4 */ COLUMN_NAME, /* 5 */ GRANTOR, /* 6 */ GRANTEE, /* 7 */ PRIVILEGE,
+ /* 8 */ IS_GRANTABLE};
@Override
- public java.sql.ResultSet getColumnPrivileges(String catalog,
- String schema,
- String table,
+ public java.sql.ResultSet getColumnPrivileges(String catalog, String schema, String table,
String col) throws SQLServerException, SQLTimeoutException {
if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) {
loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString());
@@ -461,8 +451,8 @@ public java.sql.ResultSet getColumnPrivileges(String catalog,
// column_privileges supports columns being escaped.
col = EscapeIDName(col);
/*
- * sp_column_privileges [ @table_name = ] 'table_name' [ , [ @table_owner = ] 'table_owner' ] [ , [ @table_qualifier = ] 'table_qualifier' ] [
- * , [ @column_name = ] 'column' ]
+ * sp_column_privileges [ @table_name = ] 'table_name' [ , [ @table_owner = ] 'table_owner' ] [ ,
+ * [ @table_qualifier = ] 'table_qualifier' ] [ , [ @column_name = ] 'column' ]
*/
String[] arguments = new String[4];
@@ -470,16 +460,15 @@ public java.sql.ResultSet getColumnPrivileges(String catalog,
arguments[1] = schema;
arguments[2] = catalog;
arguments[3] = col;
- return getResultSetWithProvidedColumnNames(catalog, CallableHandles.SP_COLUMN_PRIVILEGES, arguments, getColumnPrivilegesColumnNames);
+ return getResultSetWithProvidedColumnNames(catalog, CallableHandles.SP_COLUMN_PRIVILEGES, arguments,
+ getColumnPrivilegesColumnNames);
}
- private static final String[] getTablesColumnNames = {/* 1 */ TABLE_CAT, /* 2 */ TABLE_SCHEM, /* 3 */ TABLE_NAME, /* 4 */ TABLE_TYPE,
- /* 5 */ REMARKS};
+ private static final String[] getTablesColumnNames = {/* 1 */ TABLE_CAT, /* 2 */ TABLE_SCHEM, /* 3 */ TABLE_NAME,
+ /* 4 */ TABLE_TYPE, /* 5 */ REMARKS};
@Override
- public java.sql.ResultSet getTables(String catalog,
- String schema,
- String table,
+ public java.sql.ResultSet getTables(String catalog, String schema, String table,
String types[]) throws SQLServerException, SQLTimeoutException {
if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) {
loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString());
@@ -490,8 +479,8 @@ public java.sql.ResultSet getTables(String catalog,
table = EscapeIDName(table);
schema = EscapeIDName(schema);
/*
- * sp_tables [ [ @table_name = ] 'name' ] [ , [ @table_owner = ] 'owner' ] [ , [ @table_qualifier = ] 'qualifier' ] [ , [ @table_type = ]
- * "type" ]
+ * sp_tables [ [ @table_name = ] 'name' ] [ , [ @table_owner = ] 'owner' ] [ , [ @table_qualifier = ]
+ * 'qualifier' ] [ , [ @table_type = ] "type" ]
*/
String[] arguments = new String[4];
@@ -521,8 +510,9 @@ public java.sql.ResultSet getTables(String catalog,
static final char DOUBLE_RIGHT_BRACKET[] = {']', ']'};
/**
- * Accepts a SQL identifier (such as a column name or table name) and escapes the identifier so sql 92 wild card characters can be escaped
- * properly to be passed to functions like sp_columns or sp_tables. Assumes that the incoming identifier is unescaped.
+ * Accepts a SQL identifier (such as a column name or table name) and escapes the identifier so sql 92 wild card
+ * characters can be escaped properly to be passed to functions like sp_columns or sp_tables. Assumes that the
+ * incoming identifier is un-escaped.
*
* @inID input identifier to escape.
* @return the escaped value.
@@ -565,8 +555,7 @@ private static String EscapeIDName(String inID) throws SQLServerException {
outID.append(ch);
}
- }
- else {
+ } else {
// no escape just copy
outID.append(ch);
}
@@ -574,25 +563,25 @@ private static String EscapeIDName(String inID) throws SQLServerException {
return outID.toString();
}
- private static final String[] getColumnsColumnNames = {/* 1 */ TABLE_CAT, /* 2 */ TABLE_SCHEM, /* 3 */ TABLE_NAME, /* 4 */ COLUMN_NAME,
- /* 5 */ DATA_TYPE, /* 6 */ TYPE_NAME, /* 7 */ COLUMN_SIZE, /* 8 */ BUFFER_LENGTH, /* 9 */ DECIMAL_DIGITS, /* 10 */ NUM_PREC_RADIX,
- /* 11 */ NULLABLE, /* 12 */ REMARKS, /* 13 */ COLUMN_DEF, /* 14 */ SQL_DATA_TYPE, /* 15 */ SQL_DATETIME_SUB, /* 16 */ CHAR_OCTET_LENGTH,
- /* 17 */ ORDINAL_POSITION, /* 18 */ IS_NULLABLE};
+ private static final String[] getColumnsColumnNames = {/* 1 */ TABLE_CAT, /* 2 */ TABLE_SCHEM, /* 3 */ TABLE_NAME,
+ /* 4 */ COLUMN_NAME, /* 5 */ DATA_TYPE, /* 6 */ TYPE_NAME, /* 7 */ COLUMN_SIZE, /* 8 */ BUFFER_LENGTH,
+ /* 9 */ DECIMAL_DIGITS, /* 10 */ NUM_PREC_RADIX, /* 11 */ NULLABLE, /* 12 */ REMARKS, /* 13 */ COLUMN_DEF,
+ /* 14 */ SQL_DATA_TYPE, /* 15 */ SQL_DATETIME_SUB, /* 16 */ CHAR_OCTET_LENGTH, /* 17 */ ORDINAL_POSITION,
+ /* 18 */ IS_NULLABLE};
// SQL10 columns not exahustive we only need to set until the one we want to
// change
// in this case we want to change SS_IS_IDENTITY 22nd column to
// IS_AUTOINCREMENT
// to be inline with JDBC spec
- private static final String[] getColumnsColumnNamesKatmai = {/* 1 */ TABLE_CAT, /* 2 */ TABLE_SCHEM, /* 3 */ TABLE_NAME, /* 4 */ COLUMN_NAME,
- /* 5 */ DATA_TYPE, /* 6 */ TYPE_NAME, /* 7 */ COLUMN_SIZE, /* 8 */ BUFFER_LENGTH, /* 9 */ DECIMAL_DIGITS, /* 10 */ NUM_PREC_RADIX,
- /* 11 */ NULLABLE, /* 12 */ REMARKS, /* 13 */ COLUMN_DEF, /* 14 */ SQL_DATA_TYPE, /* 15 */ SQL_DATETIME_SUB, /* 16 */ CHAR_OCTET_LENGTH,
- /* 17 */ ORDINAL_POSITION, /* 18 */ IS_NULLABLE, /* 20 */ SS_IS_SPARSE, /* 20 */ SS_IS_COLUMN_SET, /* 21 */ IS_GENERATEDCOLUMN,
- /* 22 */ IS_AUTOINCREMENT};
+ private static final String[] getColumnsColumnNamesKatmai = {/* 1 */ TABLE_CAT, /* 2 */ TABLE_SCHEM,
+ /* 3 */ TABLE_NAME, /* 4 */ COLUMN_NAME, /* 5 */ DATA_TYPE, /* 6 */ TYPE_NAME, /* 7 */ COLUMN_SIZE,
+ /* 8 */ BUFFER_LENGTH, /* 9 */ DECIMAL_DIGITS, /* 10 */ NUM_PREC_RADIX, /* 11 */ NULLABLE, /* 12 */ REMARKS,
+ /* 13 */ COLUMN_DEF, /* 14 */ SQL_DATA_TYPE, /* 15 */ SQL_DATETIME_SUB, /* 16 */ CHAR_OCTET_LENGTH,
+ /* 17 */ ORDINAL_POSITION, /* 18 */ IS_NULLABLE, /* 20 */ SS_IS_SPARSE, /* 20 */ SS_IS_COLUMN_SET,
+ /* 21 */ IS_GENERATEDCOLUMN, /* 22 */ IS_AUTOINCREMENT};
@Override
- public java.sql.ResultSet getColumns(String catalog,
- String schema,
- String table,
+ public java.sql.ResultSet getColumns(String catalog, String schema, String table,
String col) throws SQLServerException, SQLTimeoutException {
if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) {
loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString());
@@ -605,8 +594,8 @@ public java.sql.ResultSet getColumns(String catalog,
schema = EscapeIDName(schema);
/*
- * sp_columns [ @table_name = ] object [ , [ @table_owner = ] owner ] [ , [ @table_qualifier = ] qualifier ] [ , [ @column_name = ] column ] [
- * , [ @ODBCVer = ] ODBCVer ]
+ * sp_columns [ @table_name = ] object [ , [ @table_owner = ] owner ] [ , [ @table_qualifier = ] qualifier ] [ ,
+ * [ @column_name = ] column ] [ , [ @ODBCVer = ] ODBCVer ]
*/
String[] arguments;
if (connection.isKatmaiOrLater())
@@ -621,14 +610,15 @@ public java.sql.ResultSet getColumns(String catalog,
arguments[4] = "2"; // give information about everything including
// sparse columns
arguments[5] = "3"; // odbc version
- }
- else
+ } else
arguments[4] = "3"; // odbc version
SQLServerResultSet rs;
if (connection.isKatmaiOrLater())
- rs = getResultSetWithProvidedColumnNames(catalog, CallableHandles.SP_COLUMNS, arguments, getColumnsColumnNamesKatmai);
+ rs = getResultSetWithProvidedColumnNames(catalog, CallableHandles.SP_COLUMNS, arguments,
+ getColumnsColumnNamesKatmai);
else
- rs = getResultSetWithProvidedColumnNames(catalog, CallableHandles.SP_COLUMNS, arguments, getColumnsColumnNames);
+ rs = getResultSetWithProvidedColumnNames(catalog, CallableHandles.SP_COLUMNS, arguments,
+ getColumnsColumnNames);
// Hook in a filter on the DATA_TYPE column of the result set we're
// going to return that converts the ODBC values from sp_columns
// into JDBC values.
@@ -643,18 +633,18 @@ public java.sql.ResultSet getColumns(String catalog,
return rs;
}
- private static final String[] getFunctionsColumnNames = {/* 1 */ FUNCTION_CAT, /* 2 */ FUNCTION_SCHEM, /* 3 */ FUNCTION_NAME,
- /* 4 */ NUM_INPUT_PARAMS, /* 5 */ NUM_OUTPUT_PARAMS, /* 6 */ NUM_RESULT_SETS, /* 7 */ REMARKS, /* 8 */ FUNCTION_TYPE};
+ private static final String[] getFunctionsColumnNames = {/* 1 */ FUNCTION_CAT, /* 2 */ FUNCTION_SCHEM,
+ /* 3 */ FUNCTION_NAME, /* 4 */ NUM_INPUT_PARAMS, /* 5 */ NUM_OUTPUT_PARAMS, /* 6 */ NUM_RESULT_SETS,
+ /* 7 */ REMARKS, /* 8 */ FUNCTION_TYPE};
@Override
- public java.sql.ResultSet getFunctions(String catalog,
- String schemaPattern,
+ public java.sql.ResultSet getFunctions(String catalog, String schemaPattern,
String functionNamePattern) throws SQLException {
checkClosed();
/*
- * sp_stored_procedures [ [ @sp_name = ] 'name' ] [ , [ @sp_owner = ] 'schema'] [ , [ @sp_qualifier = ] 'qualifier' ] [ , [@fUsePattern = ]
- * 'fUsePattern' ]
+ * sp_stored_procedures [ [ @sp_name = ] 'name' ] [ , [ @sp_owner = ] 'schema'] [ , [ @sp_qualifier = ]
+ * 'qualifier' ] [ , [@fUsePattern = ] 'fUsePattern' ]
*/ // use default ie use pattern matching.
// catalog cannot be empty in sql server
if (catalog != null && catalog.length() == 0) {
@@ -667,23 +657,23 @@ public java.sql.ResultSet getFunctions(String catalog,
arguments[0] = EscapeIDName(functionNamePattern);
arguments[1] = EscapeIDName(schemaPattern);
arguments[2] = catalog;
- return getResultSetWithProvidedColumnNames(catalog, CallableHandles.SP_STORED_PROCEDURES, arguments, getFunctionsColumnNames);
+ return getResultSetWithProvidedColumnNames(catalog, CallableHandles.SP_STORED_PROCEDURES, arguments,
+ getFunctionsColumnNames);
}
- private static final String[] getFunctionsColumnsColumnNames = {/* 1 */ FUNCTION_CAT, /* 2 */ FUNCTION_SCHEM, /* 3 */ FUNCTION_NAME,
- /* 4 */ COLUMN_NAME, /* 5 */ COLUMN_TYPE, /* 6 */ DATA_TYPE, /* 7 */ TYPE_NAME, /* 8 */ PRECISION, /* 9 */ LENGTH, /* 10 */ SCALE,
- /* 11 */ RADIX, /* 12 */ NULLABLE, /* 13 */ REMARKS, /* 14 */ COLUMN_DEF, /* 15 */ SQL_DATA_TYPE, /* 16 */ SQL_DATETIME_SUB,
- /* 17 */ CHAR_OCTET_LENGTH, /* 18 */ ORDINAL_POSITION, /* 19 */ IS_NULLABLE};
+ private static final String[] getFunctionsColumnsColumnNames = {/* 1 */ FUNCTION_CAT, /* 2 */ FUNCTION_SCHEM,
+ /* 3 */ FUNCTION_NAME, /* 4 */ COLUMN_NAME, /* 5 */ COLUMN_TYPE, /* 6 */ DATA_TYPE, /* 7 */ TYPE_NAME,
+ /* 8 */ PRECISION, /* 9 */ LENGTH, /* 10 */ SCALE, /* 11 */ RADIX, /* 12 */ NULLABLE, /* 13 */ REMARKS,
+ /* 14 */ COLUMN_DEF, /* 15 */ SQL_DATA_TYPE, /* 16 */ SQL_DATETIME_SUB, /* 17 */ CHAR_OCTET_LENGTH,
+ /* 18 */ ORDINAL_POSITION, /* 19 */ IS_NULLABLE};
@Override
- public java.sql.ResultSet getFunctionColumns(String catalog,
- String schemaPattern,
- String functionNamePattern,
+ public java.sql.ResultSet getFunctionColumns(String catalog, String schemaPattern, String functionNamePattern,
String columnNamePattern) throws SQLException {
checkClosed();
/*
- * sp_sproc_columns [[@procedure_name =] 'name'] [,[@procedure_owner =] 'owner'] [,[@procedure_qualifier =] 'qualifier'] [,[@column_name =]
- * 'column_name'] [,[@ODBCVer =] 'ODBCVer']
+ * sp_sproc_columns [[@procedure_name =] 'name'] [,[@procedure_owner =] 'owner'] [,[@procedure_qualifier =]
+ * 'qualifier'] [,[@column_name =] 'column_name'] [,[@ODBCVer =] 'ODBCVer']
*/
// catalog cannot be empty in sql server
@@ -703,8 +693,8 @@ public java.sql.ResultSet getFunctionColumns(String catalog,
// col name supports escaping
arguments[3] = EscapeIDName(columnNamePattern);
arguments[4] = "3";
- SQLServerResultSet rs = getResultSetWithProvidedColumnNames(catalog, CallableHandles.SP_SPROC_COLUMNS, arguments,
- getFunctionsColumnsColumnNames);
+ SQLServerResultSet rs = getResultSetWithProvidedColumnNames(catalog, CallableHandles.SP_SPROC_COLUMNS,
+ arguments, getFunctionsColumnsColumnNames);
// Hook in a filter on the DATA_TYPE column of the result set we're
// going to return that converts the ODBC values from sp_columns
@@ -729,22 +719,21 @@ public java.sql.ResultSet getClientInfoProperties() throws SQLException {
/* 4 */ " cast(NULL as char(1)) as DESCRIPTION " + " where 0 = 1");
}
- private static final String[] getBestRowIdentifierColumnNames = {/* 1 */ SCOPE, /* 2 */ COLUMN_NAME, /* 3 */ DATA_TYPE, /* 4 */ TYPE_NAME,
- /* 5 */ COLUMN_SIZE, /* 6 */ BUFFER_LENGTH, /* 7 */ DECIMAL_DIGITS, /* 8 */ PSEUDO_COLUMN};
+ private static final String[] getBestRowIdentifierColumnNames = {/* 1 */ SCOPE, /* 2 */ COLUMN_NAME,
+ /* 3 */ DATA_TYPE, /* 4 */ TYPE_NAME, /* 5 */ COLUMN_SIZE, /* 6 */ BUFFER_LENGTH, /* 7 */ DECIMAL_DIGITS,
+ /* 8 */ PSEUDO_COLUMN};
@Override
- public java.sql.ResultSet getBestRowIdentifier(String catalog,
- String schema,
- String table,
- int scope,
+ public java.sql.ResultSet getBestRowIdentifier(String catalog, String schema, String table, int scope,
boolean nullable) throws SQLServerException, SQLTimeoutException {
if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) {
loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString());
}
checkClosed();
/*
- * sp_special_columns [@table_name =] 'table_name' [,[@table_owner =] 'table_owner'] [,[@qualifier =] 'qualifier'] [,[@col_type =] 'col_type']
- * [,[@scope =] 'scope'] [,[@nullable =] 'nullable'] [,[@ODBCVer =] 'ODBCVer'] ;
+ * sp_special_columns [@table_name =] 'table_name' [,[@table_owner =] 'table_owner'] [,[@qualifier =]
+ * 'qualifier'] [,[@col_type =] 'col_type'] [,[@scope =] 'scope'] [,[@nullable =] 'nullable'] [,[@ODBCVer =]
+ * 'ODBCVer'] ;
*/
String[] arguments = new String[7];
arguments[0] = table;
@@ -760,8 +749,8 @@ public java.sql.ResultSet getBestRowIdentifier(String catalog,
else
arguments[5] = "O"; // nullable
arguments[6] = "3"; // Use 3 unless required otherwise
- SQLServerResultSet rs = getResultSetWithProvidedColumnNames(catalog, CallableHandles.SP_SPECIAL_COLUMNS, arguments,
- getBestRowIdentifierColumnNames);
+ SQLServerResultSet rs = getResultSetWithProvidedColumnNames(catalog, CallableHandles.SP_SPECIAL_COLUMNS,
+ arguments, getBestRowIdentifierColumnNames);
// Hook in a filter on the DATA_TYPE column of the result set we're
// going to return that converts the ODBC values from sp_columns
@@ -771,11 +760,7 @@ public java.sql.ResultSet getBestRowIdentifier(String catalog,
}
@Override
- public java.sql.ResultSet getCrossReference(String cat1,
- String schem1,
- String tab1,
- String cat2,
- String schem2,
+ public java.sql.ResultSet getCrossReference(String cat1, String schem1, String tab1, String cat2, String schem2,
String tab2) throws SQLServerException, SQLTimeoutException {
if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) {
loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString());
@@ -783,8 +768,9 @@ public java.sql.ResultSet getCrossReference(String cat1,
checkClosed();
/*
- * sp_fkeys [ @pktable_name = ] 'pktable_name' [ , [ @pktable_owner = ] 'pktable_owner' ] [ , [ @pktable_qualifier = ] 'pktable_qualifier' ] {
- * , [ @fktable_name = ] 'fktable_name' } [ , [ @fktable_owner = ] 'fktable_owner' ] [ , [ @fktable_qualifier = ] 'fktable_qualifier' ]
+ * sp_fkeys [ @pktable_name = ] 'pktable_name' [ , [ @pktable_owner = ] 'pktable_owner' ] [ ,
+ * [ @pktable_qualifier = ] 'pktable_qualifier' ] { , [ @fktable_name = ] 'fktable_name' } [ , [ @fktable_owner
+ * = ] 'fktable_owner' ] [ , [ @fktable_qualifier = ] 'fktable_qualifier' ]
*/
String[] arguments = {tab1, schem1, cat1, tab2, schem2, cat2};
return executeSPFkeys(arguments);
@@ -839,8 +825,7 @@ public String getDriverVersion() throws SQLServerException {
}
@Override
- public java.sql.ResultSet getExportedKeys(String cat,
- String schema,
+ public java.sql.ResultSet getExportedKeys(String cat, String schema,
String table) throws SQLServerException, SQLTimeoutException {
return getCrossReference(cat, schema, table, null, null, null);
}
@@ -858,40 +843,42 @@ public String getIdentifierQuoteString() throws SQLServerException {
}
@Override
- public java.sql.ResultSet getImportedKeys(String cat,
- String schema,
+ public java.sql.ResultSet getImportedKeys(String cat, String schema,
String table) throws SQLServerException, SQLTimeoutException {
return getCrossReference(null, null, null, cat, schema, table);
}
private ResultSet executeSPFkeys(String[] procParams) throws SQLServerException, SQLTimeoutException {
String tempTableName = "@jdbc_temp_fkeys_result";
- String sql = "DECLARE " + tempTableName + " table (PKTABLE_QUALIFIER sysname, " + "PKTABLE_OWNER sysname, " + "PKTABLE_NAME sysname, "
- + "PKCOLUMN_NAME sysname, " + "FKTABLE_QUALIFIER sysname, " + "FKTABLE_OWNER sysname, " + "FKTABLE_NAME sysname, "
- + "FKCOLUMN_NAME sysname, " + "KEY_SEQ smallint, " + "UPDATE_RULE smallint, " + "DELETE_RULE smallint, " + "FK_NAME sysname, "
- + "PK_NAME sysname, " + "DEFERRABILITY smallint);" + "INSERT INTO " + tempTableName + " EXEC sp_fkeys ?,?,?,?,?,?;"
- + "SELECT t.PKTABLE_QUALIFIER AS PKTABLE_CAT, " + "t.PKTABLE_OWNER AS PKTABLE_SCHEM, " + "t.PKTABLE_NAME, " + "t.PKCOLUMN_NAME, "
- + "t.FKTABLE_QUALIFIER AS FKTABLE_CAT, " + "t.FKTABLE_OWNER AS FKTABLE_SCHEM, " + "t.FKTABLE_NAME, " + "t.FKCOLUMN_NAME, "
- + "t.KEY_SEQ, " + "CASE s.update_referential_action " + "WHEN 1 THEN 0 " + // cascade
- // -
- // note
- // that
- // sp_fkey
- // and
- // sys.foreign_keys
- // have
- // flipped
- // values
- // for
- // cascade
- // and
- // no
- // action
+ String sql = "DECLARE " + tempTableName + " table (PKTABLE_QUALIFIER sysname, " + "PKTABLE_OWNER sysname, "
+ + "PKTABLE_NAME sysname, " + "PKCOLUMN_NAME sysname, " + "FKTABLE_QUALIFIER sysname, "
+ + "FKTABLE_OWNER sysname, " + "FKTABLE_NAME sysname, " + "FKCOLUMN_NAME sysname, "
+ + "KEY_SEQ smallint, " + "UPDATE_RULE smallint, " + "DELETE_RULE smallint, " + "FK_NAME sysname, "
+ + "PK_NAME sysname, " + "DEFERRABILITY smallint);" + "INSERT INTO " + tempTableName
+ + " EXEC sp_fkeys ?,?,?,?,?,?;" + "SELECT t.PKTABLE_QUALIFIER AS PKTABLE_CAT, "
+ + "t.PKTABLE_OWNER AS PKTABLE_SCHEM, " + "t.PKTABLE_NAME, " + "t.PKCOLUMN_NAME, "
+ + "t.FKTABLE_QUALIFIER AS FKTABLE_CAT, " + "t.FKTABLE_OWNER AS FKTABLE_SCHEM, " + "t.FKTABLE_NAME, "
+ + "t.FKCOLUMN_NAME, " + "t.KEY_SEQ, " + "CASE s.update_referential_action " + "WHEN 1 THEN 0 " + // cascade
+ // -
+ // note
+ // that
+ // sp_fkey
+ // and
+ // sys.foreign_keys
+ // have
+ // flipped
+ // values
+ // for
+ // cascade
+ // and
+ // no
+ // action
"WHEN 0 THEN 3 " + // no action
"WHEN 2 THEN 2 " + // set null
"WHEN 3 THEN 4 " + // set default
- "END as UPDATE_RULE, " + "CASE s.delete_referential_action " + "WHEN 1 THEN 0 " + "WHEN 0 THEN 3 " + "WHEN 2 THEN 2 "
- + "WHEN 3 THEN 4 " + "END as DELETE_RULE, " + "t.FK_NAME, " + "t.PK_NAME, " + "t.DEFERRABILITY " + "FROM " + tempTableName + " t "
+ "END as UPDATE_RULE, " + "CASE s.delete_referential_action " + "WHEN 1 THEN 0 " + "WHEN 0 THEN 3 "
+ + "WHEN 2 THEN 2 " + "WHEN 3 THEN 4 " + "END as DELETE_RULE, " + "t.FK_NAME, " + "t.PK_NAME, "
+ + "t.DEFERRABILITY " + "FROM " + tempTableName + " t "
+ "LEFT JOIN sys.foreign_keys s ON t.FK_NAME = s.name collate database_default;";
SQLServerCallableStatement cstmt = (SQLServerCallableStatement) connection.prepareCall(sql);
for (int i = 0; i < 6; i++) {
@@ -900,8 +887,7 @@ private ResultSet executeSPFkeys(String[] procParams) throws SQLServerException,
String currentDB = null;
if (procParams[2] != null && procParams[2] != "") {// pktable_qualifier
currentDB = switchCatalogs(procParams[2]);
- }
- else if (procParams[5] != null && procParams[5] != "") {// fktable_qualifier
+ } else if (procParams[5] != null && procParams[5] != "") {// fktable_qualifier
currentDB = switchCatalogs(procParams[5]);
}
ResultSet rs = cstmt.executeQuery();
@@ -911,23 +897,21 @@ else if (procParams[5] != null && procParams[5] != "") {// fktable_qualifier
return rs;
}
- private static final String[] getIndexInfoColumnNames = {/* 1 */ TABLE_CAT, /* 2 */ TABLE_SCHEM, /* 3 */ TABLE_NAME, /* 4 */ NON_UNIQUE,
- /* 5 */ INDEX_QUALIFIER, /* 6 */ INDEX_NAME, /* 7 */ TYPE, /* 8 */ ORDINAL_POSITION, /* 9 */ COLUMN_NAME, /* 10 */ ASC_OR_DESC,
- /* 11 */ CARDINALITY, /* 12 */ PAGES, /* 13 */ FILTER_CONDITION};
+ private static final String[] getIndexInfoColumnNames = {/* 1 */ TABLE_CAT, /* 2 */ TABLE_SCHEM, /* 3 */ TABLE_NAME,
+ /* 4 */ NON_UNIQUE, /* 5 */ INDEX_QUALIFIER, /* 6 */ INDEX_NAME, /* 7 */ TYPE, /* 8 */ ORDINAL_POSITION,
+ /* 9 */ COLUMN_NAME, /* 10 */ ASC_OR_DESC, /* 11 */ CARDINALITY, /* 12 */ PAGES, /* 13 */ FILTER_CONDITION};
@Override
- public java.sql.ResultSet getIndexInfo(String cat,
- String schema,
- String table,
- boolean unique,
+ public java.sql.ResultSet getIndexInfo(String cat, String schema, String table, boolean unique,
boolean approximate) throws SQLServerException, SQLTimeoutException {
if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) {
loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString());
}
checkClosed();
/*
- * sp_statistics [ @table_name = ] 'table_name' [ , [ @table_owner = ] 'owner' ] [ , [ @table_qualifier = ] 'qualifier' ] [ , [ @index_name =
- * ] 'index_name' ] [ , [ @is_unique = ] 'is_unique' ] [ , [ @accuracy = ] 'accuracy' ]
+ * sp_statistics [ @table_name = ] 'table_name' [ , [ @table_owner = ] 'owner' ] [ , [ @table_qualifier = ]
+ * 'qualifier' ] [ , [ @index_name = ] 'index_name' ] [ , [ @is_unique = ] 'is_unique' ] [ , [ @accuracy = ]
+ * 'accuracy' ]
*/
String[] arguments = new String[6];
arguments[0] = table;
@@ -943,7 +927,8 @@ public java.sql.ResultSet getIndexInfo(String cat,
arguments[5] = "Q";
else
arguments[5] = "E";
- return getResultSetWithProvidedColumnNames(cat, CallableHandles.SP_STATISTICS, arguments, getIndexInfoColumnNames);
+ return getResultSetWithProvidedColumnNames(cat, CallableHandles.SP_STATISTICS, arguments,
+ getIndexInfoColumnNames);
}
@Override
@@ -1009,8 +994,7 @@ public int getMaxConnections() throws SQLServerException, SQLTimeoutException {
if (!rs.next())
return 0;
return rs.getInt("maximum");
- }
- catch (SQLServerException e) {
+ } catch (SQLServerException e) {
return 0;
}
@@ -1090,12 +1074,11 @@ public String getNumericFunctions() throws SQLServerException {
return "ABS,ACOS,ASIN,ATAN,ATAN2,CEILING,COS,COT,DEGREES,EXP, FLOOR,LOG,LOG10,MOD,PI,POWER,RADIANS,RAND,ROUND,SIGN,SIN,SQRT,TAN,TRUNCATE";
}
- private static final String[] getPrimaryKeysColumnNames = {/* 1 */ TABLE_CAT, /* 2 */ TABLE_SCHEM, /* 3 */ TABLE_NAME, /* 4 */ COLUMN_NAME,
- /* 5 */ KEY_SEQ, /* 6 */ PK_NAME};
+ private static final String[] getPrimaryKeysColumnNames = {/* 1 */ TABLE_CAT, /* 2 */ TABLE_SCHEM,
+ /* 3 */ TABLE_NAME, /* 4 */ COLUMN_NAME, /* 5 */ KEY_SEQ, /* 6 */ PK_NAME};
@Override
- public java.sql.ResultSet getPrimaryKeys(String cat,
- String schema,
+ public java.sql.ResultSet getPrimaryKeys(String cat, String schema,
String table) throws SQLServerException, SQLTimeoutException {
if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) {
loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString());
@@ -1111,23 +1094,22 @@ public java.sql.ResultSet getPrimaryKeys(String cat,
return getResultSetWithProvidedColumnNames(cat, CallableHandles.SP_PKEYS, arguments, getPrimaryKeysColumnNames);
}
- private static final String[] getProcedureColumnsColumnNames = {/* 1 */ PROCEDURE_CAT, /* 2 */ PROCEDURE_SCHEM, /* 3 */ PROCEDURE_NAME,
- /* 4 */ COLUMN_NAME, /* 5 */ COLUMN_TYPE, /* 6 */ DATA_TYPE, /* 7 */ TYPE_NAME, /* 8 */ PRECISION, /* 9 */ LENGTH, /* 10 */ SCALE,
- /* 11 */ RADIX, /* 12 */ NULLABLE, /* 13 */ REMARKS, /* 14 */ COLUMN_DEF, /* 15 */ SQL_DATA_TYPE, /* 16 */ SQL_DATETIME_SUB,
- /* 17 */ CHAR_OCTET_LENGTH, /* 18 */ ORDINAL_POSITION, /* 19 */ IS_NULLABLE};
+ private static final String[] getProcedureColumnsColumnNames = {/* 1 */ PROCEDURE_CAT, /* 2 */ PROCEDURE_SCHEM,
+ /* 3 */ PROCEDURE_NAME, /* 4 */ COLUMN_NAME, /* 5 */ COLUMN_TYPE, /* 6 */ DATA_TYPE, /* 7 */ TYPE_NAME,
+ /* 8 */ PRECISION, /* 9 */ LENGTH, /* 10 */ SCALE, /* 11 */ RADIX, /* 12 */ NULLABLE, /* 13 */ REMARKS,
+ /* 14 */ COLUMN_DEF, /* 15 */ SQL_DATA_TYPE, /* 16 */ SQL_DATETIME_SUB, /* 17 */ CHAR_OCTET_LENGTH,
+ /* 18 */ ORDINAL_POSITION, /* 19 */ IS_NULLABLE};
@Override
- public java.sql.ResultSet getProcedureColumns(String catalog,
- String schema,
- String proc,
+ public java.sql.ResultSet getProcedureColumns(String catalog, String schema, String proc,
String col) throws SQLServerException, SQLTimeoutException {
if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) {
loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString());
}
checkClosed();
/*
- * sp_sproc_columns [[@procedure_name =] 'name'] [,[@procedure_owner =] 'owner'] [,[@procedure_qualifier =] 'qualifier'] [,[@column_name =]
- * 'column_name'] [,[@ODBCVer =] 'ODBCVer']
+ * sp_sproc_columns [[@procedure_name =] 'name'] [,[@procedure_owner =] 'owner'] [,[@procedure_qualifier =]
+ * 'qualifier'] [,[@column_name =] 'column_name'] [,[@ODBCVer =] 'ODBCVer']
*/
String[] arguments = new String[5];
@@ -1141,8 +1123,8 @@ public java.sql.ResultSet getProcedureColumns(String catalog,
col = EscapeIDName(col);
arguments[3] = col;
arguments[4] = "3";
- SQLServerResultSet rs = getResultSetWithProvidedColumnNames(catalog, CallableHandles.SP_SPROC_COLUMNS, arguments,
- getProcedureColumnsColumnNames);
+ SQLServerResultSet rs = getResultSetWithProvidedColumnNames(catalog, CallableHandles.SP_SPROC_COLUMNS,
+ arguments, getProcedureColumnsColumnNames);
// Hook in a filter on the DATA_TYPE column of the result set we're
// going to return that converts the ODBC values from sp_columns
@@ -1157,12 +1139,12 @@ public java.sql.ResultSet getProcedureColumns(String catalog,
return rs;
}
- private static final String[] getProceduresColumnNames = {/* 1 */ PROCEDURE_CAT, /* 2 */ PROCEDURE_SCHEM, /* 3 */ PROCEDURE_NAME,
- /* 4 */ NUM_INPUT_PARAMS, /* 5 */ NUM_OUTPUT_PARAMS, /* 6 */ NUM_RESULT_SETS, /* 7 */ REMARKS, /* 8 */ PROCEDURE_TYPE};
+ private static final String[] getProceduresColumnNames = {/* 1 */ PROCEDURE_CAT, /* 2 */ PROCEDURE_SCHEM,
+ /* 3 */ PROCEDURE_NAME, /* 4 */ NUM_INPUT_PARAMS, /* 5 */ NUM_OUTPUT_PARAMS, /* 6 */ NUM_RESULT_SETS,
+ /* 7 */ REMARKS, /* 8 */ PROCEDURE_TYPE};
@Override
- public java.sql.ResultSet getProcedures(String catalog,
- String schema,
+ public java.sql.ResultSet getProcedures(String catalog, String schema,
String proc) throws SQLServerException, SQLTimeoutException {
if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) {
loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString());
@@ -1170,14 +1152,15 @@ public java.sql.ResultSet getProcedures(String catalog,
checkClosed();
/*
- * sp_stored_procedures [ [ @sp_name = ] 'name' ] [ , [ @sp_owner = ] 'schema'] [ , [ @sp_qualifier = ] 'qualifier' ] [ , [@fUsePattern = ]
- * 'fUsePattern' ]
+ * sp_stored_procedures [ [ @sp_name = ] 'name' ] [ , [ @sp_owner = ] 'schema'] [ , [ @sp_qualifier = ]
+ * 'qualifier' ] [ , [@fUsePattern = ] 'fUsePattern' ]
*/
String[] arguments = new String[3];
arguments[0] = EscapeIDName(proc);
arguments[1] = schema;
arguments[2] = catalog;
- return getResultSetWithProvidedColumnNames(catalog, CallableHandles.SP_STORED_PROCEDURES, arguments, getProceduresColumnNames);
+ return getResultSetWithProvidedColumnNames(catalog, CallableHandles.SP_STORED_PROCEDURES, arguments,
+ getProceduresColumnNames);
}
@Override
@@ -1187,9 +1170,7 @@ public String getProcedureTerm() throws SQLServerException {
}
@Override
- public ResultSet getPseudoColumns(String catalog,
- String schemaPattern,
- String tableNamePattern,
+ public ResultSet getPseudoColumns(String catalog, String schemaPattern, String tableNamePattern,
String columnNamePattern) throws SQLException {
if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) {
loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString());
@@ -1253,13 +1234,11 @@ private java.sql.ResultSet getSchemasInternal(String catalog,
s = "select " + schemaName + " 'TABLE_SCHEM',";
if (null != catalog && catalog.length() == 0) {
s += "null 'TABLE_CATALOG' ";
- }
- else {
+ } else {
s += " CASE WHEN " + schemaName + " IN " + constSchemas + " THEN null ELSE ";
if (null != catalog && catalog.length() != 0) {
s += "'" + catalog + "' ";
- }
- else
+ } else
s += " DB_NAME() ";
s += " END 'TABLE_CATALOG' ";
@@ -1274,8 +1253,7 @@ private java.sql.ResultSet getSchemasInternal(String catalog,
else
s += " where ";
s += schemaName + " in " + constSchemas;
- }
- else if (null != schemaPattern)
+ } else if (null != schemaPattern)
s += " where " + schemaName + " like ? ";
s += " order by 2, 1";
@@ -1286,8 +1264,7 @@ else if (null != schemaPattern)
if (null == schemaPattern) {
catalog = null;
rs = getResultSetFromInternalQueries(catalog, s);
- }
- else {
+ } else {
// The prepared statement is not closed after execution.
// Yes we will "leak a server handle" per execution but the
@@ -1301,8 +1278,7 @@ else if (null != schemaPattern)
}
@Override
- public java.sql.ResultSet getSchemas(String catalog,
- String schemaPattern) throws SQLException {
+ public java.sql.ResultSet getSchemas(String catalog, String schemaPattern) throws SQLException {
if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) {
loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString());
}
@@ -1340,12 +1316,11 @@ public String getSystemFunctions() throws SQLServerException {
// CTS certification.
}
- private static final String[] getTablePrivilegesColumnNames = {/* 1 */ TABLE_CAT, /* 2 */ TABLE_SCHEM, /* 3 */ TABLE_NAME, /* 4 */ GRANTOR,
- /* 5 */ GRANTEE, /* 6 */ PRIVILEGE, /* 7 */ IS_GRANTABLE};
+ private static final String[] getTablePrivilegesColumnNames = {/* 1 */ TABLE_CAT, /* 2 */ TABLE_SCHEM,
+ /* 3 */ TABLE_NAME, /* 4 */ GRANTOR, /* 5 */ GRANTEE, /* 6 */ PRIVILEGE, /* 7 */ IS_GRANTABLE};
@Override
- public java.sql.ResultSet getTablePrivileges(String catalog,
- String schema,
+ public java.sql.ResultSet getTablePrivileges(String catalog, String schema,
String table) throws SQLServerException, SQLTimeoutException {
if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) {
loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString());
@@ -1354,15 +1329,16 @@ public java.sql.ResultSet getTablePrivileges(String catalog,
table = EscapeIDName(table);
schema = EscapeIDName(schema);
/*
- * sp_table_privileges [ @table_name = ] 'table_name' [ , [ @table_owner = ] 'table_owner' ] [ , [ @table_qualifier = ] 'table_qualifier' ] [
- * , [@fUsePattern =] 'fUsePattern']
+ * sp_table_privileges [ @table_name = ] 'table_name' [ , [ @table_owner = ] 'table_owner' ] [ ,
+ * [ @table_qualifier = ] 'table_qualifier' ] [ , [@fUsePattern =] 'fUsePattern']
*/
String[] arguments = new String[3];
arguments[0] = table;
arguments[1] = schema;
arguments[2] = catalog;
- return getResultSetWithProvidedColumnNames(catalog, CallableHandles.SP_TABLE_PRIVILEGES, arguments, getTablePrivilegesColumnNames);
+ return getResultSetWithProvidedColumnNames(catalog, CallableHandles.SP_TABLE_PRIVILEGES, arguments,
+ getTablePrivilegesColumnNames);
}
@Override
@@ -1425,7 +1401,8 @@ public String getURL() throws SQLServerException {
// making sure no security info is exposed.
if (!name.equals(SQLServerDriverBooleanProperty.INTEGRATED_SECURITY.toString())
- && !name.equals(SQLServerDriverStringProperty.USER.toString()) && !name.equals(SQLServerDriverStringProperty.PASSWORD.toString())
+ && !name.equals(SQLServerDriverStringProperty.USER.toString())
+ && !name.equals(SQLServerDriverStringProperty.PASSWORD.toString())
&& !name.equals(SQLServerDriverStringProperty.KEY_STORE_SECRET.toString())) {
String val = info[index].value;
// skip empty strings
@@ -1434,14 +1411,11 @@ public String getURL() throws SQLServerException {
// number as these go in the front
if (name.equals(SQLServerDriverStringProperty.SERVER_NAME.toString())) {
serverName = val;
- }
- else if (name.equals(SQLServerDriverStringProperty.INSTANCE_NAME.toString())) {
+ } else if (name.equals(SQLServerDriverStringProperty.INSTANCE_NAME.toString())) {
instanceName = val;
- }
- else if (name.equals(SQLServerDriverIntProperty.PORT_NUMBER.toString())) {
+ } else if (name.equals(SQLServerDriverIntProperty.PORT_NUMBER.toString())) {
portNumber = val;
- }
- else {
+ } else {
// build name value pairs separated by a semi colon
url.append(name);
url.append("=");
@@ -1487,8 +1461,7 @@ public String getUserName() throws SQLServerException, SQLTimeoutException {
assert next;
result = rs.getString(1);
- }
- finally {
+ } finally {
if (rs != null) {
rs.close();
}
@@ -1499,20 +1472,21 @@ public String getUserName() throws SQLServerException, SQLTimeoutException {
return result;
}
- private static final String[] getVersionColumnsColumnNames = {/* 1 */ SCOPE, /* 2 */ COLUMN_NAME, /* 3 */ DATA_TYPE, /* 4 */ TYPE_NAME,
- /* 5 */ COLUMN_SIZE, /* 6 */ BUFFER_LENGTH, /* 7 */ DECIMAL_DIGITS, /* 8 */ PSEUDO_COLUMN};
+ private static final String[] getVersionColumnsColumnNames = {/* 1 */ SCOPE, /* 2 */ COLUMN_NAME, /* 3 */ DATA_TYPE,
+ /* 4 */ TYPE_NAME, /* 5 */ COLUMN_SIZE, /* 6 */ BUFFER_LENGTH, /* 7 */ DECIMAL_DIGITS,
+ /* 8 */ PSEUDO_COLUMN};
@Override
- public java.sql.ResultSet getVersionColumns(String catalog,
- String schema,
+ public java.sql.ResultSet getVersionColumns(String catalog, String schema,
String table) throws SQLServerException, SQLTimeoutException {
if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) {
loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString());
}
checkClosed();
/*
- * sp_special_columns [@table_name =] 'table_name' [,[@table_owner =] 'table_owner'] [,[@qualifier =] 'qualifier'] [,[@col_type =] 'col_type']
- * [,[@scope =] 'scope'] [,[@nullable =] 'nullable'] [,[@ODBCVer =] 'ODBCVer'] ;
+ * sp_special_columns [@table_name =] 'table_name' [,[@table_owner =] 'table_owner'] [,[@qualifier =]
+ * 'qualifier'] [,[@col_type =] 'col_type'] [,[@scope =] 'scope'] [,[@nullable =] 'nullable'] [,[@ODBCVer =]
+ * 'ODBCVer'] ;
*/
String[] arguments = new String[7];
arguments[0] = table;
@@ -1522,8 +1496,8 @@ public java.sql.ResultSet getVersionColumns(String catalog,
arguments[4] = "T"; // scope
arguments[5] = "U"; // nullable
arguments[6] = "3"; // odbc ver
- SQLServerResultSet rs = getResultSetWithProvidedColumnNames(catalog, CallableHandles.SP_SPECIAL_COLUMNS, arguments,
- getVersionColumnsColumnNames);
+ SQLServerResultSet rs = getResultSetWithProvidedColumnNames(catalog, CallableHandles.SP_SPECIAL_COLUMNS,
+ arguments, getVersionColumnsColumnNames);
// Hook in a filter on the DATA_TYPE column of the result set we're
// going to return that converts the ODBC values from sp_columns
@@ -1683,8 +1657,7 @@ public boolean supportsConvert() throws SQLServerException {
}
@Override
- public boolean supportsConvert(int fromType,
- int toType) throws SQLServerException {
+ public boolean supportsConvert(int fromType, int toType) throws SQLServerException {
checkClosed();
return true;
}
@@ -1994,8 +1967,7 @@ public boolean supportsResultSetType(int type) throws SQLServerException {
}
@Override
- public boolean supportsResultSetConcurrency(int type,
- int concurrency) throws SQLServerException {
+ public boolean supportsResultSetConcurrency(int type, int concurrency) throws SQLServerException {
checkClosed();
checkResultType(type);
checkConcurrencyType(concurrency);
@@ -2137,9 +2109,7 @@ public boolean supportsBatchUpdates() throws SQLServerException {
}
@Override
- public java.sql.ResultSet getUDTs(String catalog,
- String schemaPattern,
- String typeNamePattern,
+ public java.sql.ResultSet getUDTs(String catalog, String schemaPattern, String typeNamePattern,
int[] types) throws SQLServerException, SQLTimeoutException {
if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) {
loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString());
@@ -2181,8 +2151,7 @@ public int getDatabaseMajorVersion() throws SQLServerException {
s = s.substring(0, p);
try {
return Integer.parseInt(s);
- }
- catch (NumberFormatException e) {
+ } catch (NumberFormatException e) {
return 0;
}
}
@@ -2197,8 +2166,7 @@ public int getDatabaseMinorVersion() throws SQLServerException {
s = s.substring(p + 1, q);
try {
return Integer.parseInt(s);
- }
- catch (NumberFormatException e) {
+ } catch (NumberFormatException e) {
return 0;
}
}
@@ -2243,9 +2211,7 @@ public boolean supportsResultSetHoldability(int holdability) throws SQLServerExc
}
@Override
- public ResultSet getAttributes(String catalog,
- String schemaPattern,
- String typeNamePattern,
+ public ResultSet getAttributes(String catalog, String schemaPattern, String typeNamePattern,
String attributeNamePattern) throws SQLServerException, SQLTimeoutException {
if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) {
loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString());
@@ -2276,8 +2242,7 @@ public ResultSet getAttributes(String catalog,
}
@Override
- public ResultSet getSuperTables(String catalog,
- String schemaPattern,
+ public ResultSet getSuperTables(String catalog, String schemaPattern,
String tableNamePattern) throws SQLServerException, SQLTimeoutException {
if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) {
loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString());
@@ -2291,8 +2256,7 @@ public ResultSet getSuperTables(String catalog,
}
@Override
- public ResultSet getSuperTypes(String catalog,
- String schemaPattern,
+ public ResultSet getSuperTypes(String catalog, String schemaPattern,
String typeNamePattern) throws SQLServerException, SQLTimeoutException {
if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) {
loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString());
@@ -2350,8 +2314,11 @@ public boolean locatorsUpdateCopy() throws SQLException {
}
}
-// Filter to convert DATA_TYPE column values from the ODBC types
-// returned by SQL Server to their equivalent JDBC types.
+
+/**
+ * Provides filter to convert DATA_TYPE column values from the ODBC types returned by SQL Server to their equivalent
+ * JDBC types.
+ */
final class DataTypeFilter extends IntColumnFilter {
private static final int ODBC_SQL_GUID = -11;
private static final int ODBC_SQL_WCHAR = -8;
@@ -2388,6 +2355,7 @@ int oneValueToAnother(int odbcType) {
}
+
class ZeroFixupFilter extends IntColumnFilter {
int oneValueToAnother(int precl) {
if (0 == precl)
@@ -2397,14 +2365,14 @@ int oneValueToAnother(int precl) {
}
}
-// abstract class converts one value to another solely based on the column
-// integer value
-// apply to integer columns only
+
+/**
+ * Converts one value to another solely based on the column integer value. Apply to integer columns only
+ */
abstract class IntColumnFilter extends ColumnFilter {
abstract int oneValueToAnother(int value);
- final Object apply(Object value,
- JDBCType asJDBCType) throws SQLServerException {
+ final Object apply(Object value, JDBCType asJDBCType) throws SQLServerException {
if (value == null)
return value;
// Assumption: values will only be requested in integral or textual
@@ -2433,16 +2401,17 @@ final Object apply(Object value,
}
-// Filter to convert int identity column values from 0,1 to YES, NO
-// There is a mismatch between what the stored proc returns and what the
-// JDBC spec expects.
+
+/**
+ * Provides filter to convert int identity column values from 0,1 to YES, NO There is a mismatch between what the stored
+ * proc returns and what the JDBC spec expects.
+ */
class IntColumnIdentityFilter extends ColumnFilter {
private static String zeroOneToYesNo(int i) {
return 0 == i ? "NO" : "YES";
}
- final Object apply(Object value,
- JDBCType asJDBCType) throws SQLServerException {
+ final Object apply(Object value, JDBCType asJDBCType) throws SQLServerException {
if (value == null)
return value;
// Assumption: values will only be requested in integral or textual
@@ -2477,5 +2446,4 @@ final Object apply(Object value,
return value;
}
}
-
-}
\ No newline at end of file
+}
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDriver.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDriver.java
index 5f67f93db..30a0c4d76 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDriver.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDriver.java
@@ -1,9 +1,6 @@
/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc;
@@ -22,11 +19,11 @@
import org.ietf.jgss.GSSCredential;
+
/**
- * SQLServerDriver implements the java.sql.Driver for SQLServerConnect.
+ * Implements the java.sql.Driver for SQLServerConnect.
*
*/
-
final class SQLServerDriverPropertyInfo {
private final String name;
@@ -39,10 +36,7 @@ final String getName() {
private final boolean required;
private final String[] choices;
- SQLServerDriverPropertyInfo(String name,
- String defaultValue,
- boolean required,
- String[] choices) {
+ SQLServerDriverPropertyInfo(String name, String defaultValue, boolean required, String[] choices) {
this.name = name;
this.description = SQLServerResource.getResource("R_" + name + "PropertyDescription");
this.defaultValue = defaultValue;
@@ -51,7 +45,8 @@ final String getName() {
}
DriverPropertyInfo build(Properties connProperties) {
- String propValue = name.equals(SQLServerDriverStringProperty.PASSWORD.toString()) ? "" : connProperties.getProperty(name);
+ String propValue = name.equals(SQLServerDriverStringProperty.PASSWORD.toString()) ? "" : connProperties
+ .getProperty(name);
if (null == propValue)
propValue = defaultValue;
@@ -65,6 +60,7 @@ DriverPropertyInfo build(Properties connProperties) {
}
}
+
enum SqlAuthentication {
NotSpecified,
SqlPassword,
@@ -76,17 +72,15 @@ static SqlAuthentication valueOfString(String value) throws SQLServerException {
if (value.toLowerCase(Locale.US).equalsIgnoreCase(SqlAuthentication.NotSpecified.toString())) {
method = SqlAuthentication.NotSpecified;
- }
- else if (value.toLowerCase(Locale.US).equalsIgnoreCase(SqlAuthentication.SqlPassword.toString())) {
+ } else if (value.toLowerCase(Locale.US).equalsIgnoreCase(SqlAuthentication.SqlPassword.toString())) {
method = SqlAuthentication.SqlPassword;
- }
- else if (value.toLowerCase(Locale.US).equalsIgnoreCase(SqlAuthentication.ActiveDirectoryPassword.toString())) {
+ } else if (value.toLowerCase(Locale.US)
+ .equalsIgnoreCase(SqlAuthentication.ActiveDirectoryPassword.toString())) {
method = SqlAuthentication.ActiveDirectoryPassword;
- }
- else if (value.toLowerCase(Locale.US).equalsIgnoreCase(SqlAuthentication.ActiveDirectoryIntegrated.toString())) {
+ } else if (value.toLowerCase(Locale.US)
+ .equalsIgnoreCase(SqlAuthentication.ActiveDirectoryIntegrated.toString())) {
method = SqlAuthentication.ActiveDirectoryIntegrated;
- }
- else {
+ } else {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_InvalidConnectionSetting"));
Object[] msgArgs = {"authentication", value};
throw new SQLServerException(null, form.format(msgArgs), null, 0, false);
@@ -95,6 +89,7 @@ else if (value.toLowerCase(Locale.US).equalsIgnoreCase(SqlAuthentication.ActiveD
}
}
+
enum ColumnEncryptionSetting {
Enabled,
Disabled;
@@ -104,11 +99,9 @@ static ColumnEncryptionSetting valueOfString(String value) throws SQLServerExcep
if (value.toLowerCase(Locale.US).equalsIgnoreCase(ColumnEncryptionSetting.Enabled.toString())) {
method = ColumnEncryptionSetting.Enabled;
- }
- else if (value.toLowerCase(Locale.US).equalsIgnoreCase(ColumnEncryptionSetting.Disabled.toString())) {
+ } else if (value.toLowerCase(Locale.US).equalsIgnoreCase(ColumnEncryptionSetting.Disabled.toString())) {
method = ColumnEncryptionSetting.Disabled;
- }
- else {
+ } else {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_InvalidConnectionSetting"));
Object[] msgArgs = {"columnEncryptionSetting", value};
throw new SQLServerException(form.format(msgArgs), null);
@@ -117,6 +110,7 @@ else if (value.toLowerCase(Locale.US).equalsIgnoreCase(ColumnEncryptionSetting.D
}
}
+
enum SSLProtocol {
TLS("TLS"),
TLS_V10("TLSv1"),
@@ -138,17 +132,13 @@ static SSLProtocol valueOfString(String value) throws SQLServerException {
if (value.toLowerCase(Locale.ENGLISH).equalsIgnoreCase(SSLProtocol.TLS.toString())) {
protocol = SSLProtocol.TLS;
- }
- else if (value.toLowerCase(Locale.ENGLISH).equalsIgnoreCase(SSLProtocol.TLS_V10.toString())) {
+ } else if (value.toLowerCase(Locale.ENGLISH).equalsIgnoreCase(SSLProtocol.TLS_V10.toString())) {
protocol = SSLProtocol.TLS_V10;
- }
- else if (value.toLowerCase(Locale.ENGLISH).equalsIgnoreCase(SSLProtocol.TLS_V11.toString())) {
+ } else if (value.toLowerCase(Locale.ENGLISH).equalsIgnoreCase(SSLProtocol.TLS_V11.toString())) {
protocol = SSLProtocol.TLS_V11;
- }
- else if (value.toLowerCase(Locale.ENGLISH).equalsIgnoreCase(SSLProtocol.TLS_V12.toString())) {
+ } else if (value.toLowerCase(Locale.ENGLISH).equalsIgnoreCase(SSLProtocol.TLS_V12.toString())) {
protocol = SSLProtocol.TLS_V12;
- }
- else {
+ } else {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidSSLProtocol"));
Object[] msgArgs = {value};
throw new SQLServerException(null, form.format(msgArgs), null, 0, false);
@@ -157,6 +147,7 @@ else if (value.toLowerCase(Locale.ENGLISH).equalsIgnoreCase(SSLProtocol.TLS_V12.
}
}
+
enum KeyStoreAuthentication {
JavaKeyStorePassword;
@@ -165,8 +156,7 @@ static KeyStoreAuthentication valueOfString(String value) throws SQLServerExcept
if (value.toLowerCase(Locale.US).equalsIgnoreCase(KeyStoreAuthentication.JavaKeyStorePassword.toString())) {
method = KeyStoreAuthentication.JavaKeyStorePassword;
- }
- else {
+ } else {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_InvalidConnectionSetting"));
Object[] msgArgs = {"keyStoreAuthentication", value};
throw new SQLServerException(form.format(msgArgs), null);
@@ -175,19 +165,19 @@ static KeyStoreAuthentication valueOfString(String value) throws SQLServerExcept
}
}
+
enum AuthenticationScheme {
nativeAuthentication,
javaKerberos;
-
+
static AuthenticationScheme valueOfString(String value) throws SQLServerException {
AuthenticationScheme scheme;
if (value.toLowerCase(Locale.US).equalsIgnoreCase(AuthenticationScheme.javaKerberos.toString())) {
scheme = AuthenticationScheme.javaKerberos;
- }
- else if (value.toLowerCase(Locale.US).equalsIgnoreCase(AuthenticationScheme.nativeAuthentication.toString())) {
+ } else if (value.toLowerCase(Locale.US)
+ .equalsIgnoreCase(AuthenticationScheme.nativeAuthentication.toString())) {
scheme = AuthenticationScheme.nativeAuthentication;
- }
- else {
+ } else {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidAuthenticationScheme"));
Object[] msgArgs = {value};
throw new SQLServerException(null, form.format(msgArgs), null, 0, false);
@@ -196,6 +186,7 @@ else if (value.toLowerCase(Locale.US).equalsIgnoreCase(AuthenticationScheme.nati
}
}
+
enum ApplicationIntent {
READ_WRITE("readwrite"),
READ_ONLY("readonly");
@@ -203,12 +194,16 @@ enum ApplicationIntent {
// the value of the enum
private final String value;
- // constructor that sets the string value of the enum
+ /**
+ * Constructs a ApplicationIntent that sets the string value of the enum.
+ */
private ApplicationIntent(String value) {
this.value = value;
}
- // returns the string value of enum
+ /**
+ * Returns the string value of enum.
+ */
public String toString() {
return value;
}
@@ -220,11 +215,9 @@ static ApplicationIntent valueOfString(String value) throws SQLServerException {
value = value.toUpperCase(Locale.US).toLowerCase(Locale.US);
if (value.equalsIgnoreCase(ApplicationIntent.READ_ONLY.toString())) {
applicationIntent = ApplicationIntent.READ_ONLY;
- }
- else if (value.equalsIgnoreCase(ApplicationIntent.READ_WRITE.toString())) {
+ } else if (value.equalsIgnoreCase(ApplicationIntent.READ_WRITE.toString())) {
applicationIntent = ApplicationIntent.READ_WRITE;
- }
- else {
+ } else {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidapplicationIntent"));
Object[] msgArgs = {value};
throw new SQLServerException(null, form.format(msgArgs), null, 0, false);
@@ -234,68 +227,65 @@ else if (value.equalsIgnoreCase(ApplicationIntent.READ_WRITE.toString())) {
}
}
+
enum SQLServerDriverObjectProperty {
GSS_CREDENTIAL("gsscredential", null);
private final String name;
private final String defaultValue;
- private SQLServerDriverObjectProperty(String name,
- String defaultValue) {
+ private SQLServerDriverObjectProperty(String name, String defaultValue) {
this.name = name;
this.defaultValue = defaultValue;
}
/**
- * returning string due to structure of DRIVER_PROPERTIES_PROPERTY_ONLY
+ * Returns string due to structure of DRIVER_PROPERTIES_PROPERTY_ONLY.
+ *
* @return
*/
public String getDefaultValue() {
return defaultValue;
}
-
+
public String toString() {
return name;
}
}
-
-enum SQLServerDriverStringProperty
-{
- APPLICATION_INTENT ("applicationIntent", ApplicationIntent.READ_WRITE.toString()),
- APPLICATION_NAME ("applicationName", SQLServerDriver.DEFAULT_APP_NAME),
- DATABASE_NAME ("databaseName", ""),
- FAILOVER_PARTNER ("failoverPartner", ""),
- HOSTNAME_IN_CERTIFICATE ("hostNameInCertificate", ""),
- INSTANCE_NAME ("instanceName", ""),
- JAAS_CONFIG_NAME ("jaasConfigurationName", "SQLJDBCDriver"),
- PASSWORD ("password", ""),
- RESPONSE_BUFFERING ("responseBuffering", "adaptive"),
- SELECT_METHOD ("selectMethod", "direct"),
- SERVER_NAME ("serverName", ""),
- SERVER_SPN ("serverSpn", ""),
- TRUST_STORE_TYPE ("trustStoreType", "JKS"),
- TRUST_STORE ("trustStore", ""),
- TRUST_STORE_PASSWORD ("trustStorePassword", ""),
- TRUST_MANAGER_CLASS ("trustManagerClass", ""),
- TRUST_MANAGER_CONSTRUCTOR_ARG("trustManagerConstructorArg", ""),
- USER ("user", ""),
- WORKSTATION_ID ("workstationID", Util.WSIDNotAvailable),
- AUTHENTICATION_SCHEME ("authenticationScheme", AuthenticationScheme.nativeAuthentication.toString()),
- AUTHENTICATION ("authentication", SqlAuthentication.NotSpecified.toString()),
- ACCESS_TOKEN ("accessToken", ""),
- COLUMN_ENCRYPTION ("columnEncryptionSetting", ColumnEncryptionSetting.Disabled.toString()),
- KEY_STORE_AUTHENTICATION ("keyStoreAuthentication", ""),
- KEY_STORE_SECRET ("keyStoreSecret", ""),
- KEY_STORE_LOCATION ("keyStoreLocation", ""),
- SSL_PROTOCOL ("sslProtocol", SSLProtocol.TLS.toString()),
- ;
+enum SQLServerDriverStringProperty {
+ APPLICATION_INTENT("applicationIntent", ApplicationIntent.READ_WRITE.toString()),
+ APPLICATION_NAME("applicationName", SQLServerDriver.DEFAULT_APP_NAME),
+ DATABASE_NAME("databaseName", ""),
+ FAILOVER_PARTNER("failoverPartner", ""),
+ HOSTNAME_IN_CERTIFICATE("hostNameInCertificate", ""),
+ INSTANCE_NAME("instanceName", ""),
+ JAAS_CONFIG_NAME("jaasConfigurationName", "SQLJDBCDriver"),
+ PASSWORD("password", ""),
+ RESPONSE_BUFFERING("responseBuffering", "adaptive"),
+ SELECT_METHOD("selectMethod", "direct"),
+ SERVER_NAME("serverName", ""),
+ SERVER_SPN("serverSpn", ""),
+ TRUST_STORE_TYPE("trustStoreType", "JKS"),
+ TRUST_STORE("trustStore", ""),
+ TRUST_STORE_PASSWORD("trustStorePassword", ""),
+ TRUST_MANAGER_CLASS("trustManagerClass", ""),
+ TRUST_MANAGER_CONSTRUCTOR_ARG("trustManagerConstructorArg", ""),
+ USER("user", ""),
+ WORKSTATION_ID("workstationID", Util.WSIDNotAvailable),
+ AUTHENTICATION_SCHEME("authenticationScheme", AuthenticationScheme.nativeAuthentication.toString()),
+ AUTHENTICATION("authentication", SqlAuthentication.NotSpecified.toString()),
+ ACCESS_TOKEN("accessToken", ""),
+ COLUMN_ENCRYPTION("columnEncryptionSetting", ColumnEncryptionSetting.Disabled.toString()),
+ KEY_STORE_AUTHENTICATION("keyStoreAuthentication", ""),
+ KEY_STORE_SECRET("keyStoreSecret", ""),
+ KEY_STORE_LOCATION("keyStoreLocation", ""),
+ SSL_PROTOCOL("sslProtocol", SSLProtocol.TLS.toString()),;
private final String name;
private final String defaultValue;
- private SQLServerDriverStringProperty(String name,
- String defaultValue) {
+ private SQLServerDriverStringProperty(String name, String defaultValue) {
this.name = name;
this.defaultValue = defaultValue;
}
@@ -309,23 +299,22 @@ public String toString() {
}
}
+
enum SQLServerDriverIntProperty {
- PACKET_SIZE ("packetSize", TDS.DEFAULT_PACKET_SIZE),
- LOCK_TIMEOUT ("lockTimeout", -1),
- LOGIN_TIMEOUT ("loginTimeout", 15),
- QUERY_TIMEOUT ("queryTimeout", -1),
- PORT_NUMBER ("portNumber", 1433),
- SOCKET_TIMEOUT ("socketTimeout", 0),
+ PACKET_SIZE("packetSize", TDS.DEFAULT_PACKET_SIZE),
+ LOCK_TIMEOUT("lockTimeout", -1),
+ LOGIN_TIMEOUT("loginTimeout", 15),
+ QUERY_TIMEOUT("queryTimeout", -1),
+ PORT_NUMBER("portNumber", 1433),
+ SOCKET_TIMEOUT("socketTimeout", 0),
SERVER_PREPARED_STATEMENT_DISCARD_THRESHOLD("serverPreparedStatementDiscardThreshold", SQLServerConnection.DEFAULT_SERVER_PREPARED_STATEMENT_DISCARD_THRESHOLD),
- STATEMENT_POOLING_CACHE_SIZE ("statementPoolingCacheSize", SQLServerConnection.DEFAULT_STATEMENT_POOLING_CACHE_SIZE),
- CANCEL_QUERY_TIMEOUT ("cancelQueryTimeout", -1),
- ;
-
+ STATEMENT_POOLING_CACHE_SIZE("statementPoolingCacheSize", SQLServerConnection.DEFAULT_STATEMENT_POOLING_CACHE_SIZE),
+ CANCEL_QUERY_TIMEOUT("cancelQueryTimeout", -1),;
+
private final String name;
private final int defaultValue;
- private SQLServerDriverIntProperty(String name,
- int defaultValue) {
+ private SQLServerDriverIntProperty(String name, int defaultValue) {
this.name = name;
this.defaultValue = defaultValue;
}
@@ -339,28 +328,27 @@ public String toString() {
}
}
-enum SQLServerDriverBooleanProperty
-{
- DISABLE_STATEMENT_POOLING ("disableStatementPooling", true),
- ENCRYPT ("encrypt", false),
- INTEGRATED_SECURITY ("integratedSecurity", false),
- LAST_UPDATE_COUNT ("lastUpdateCount", true),
- MULTI_SUBNET_FAILOVER ("multiSubnetFailover", false),
- SERVER_NAME_AS_ACE ("serverNameAsACE", false),
- SEND_STRING_PARAMETERS_AS_UNICODE ("sendStringParametersAsUnicode", true),
- SEND_TIME_AS_DATETIME ("sendTimeAsDatetime", true),
- TRANSPARENT_NETWORK_IP_RESOLUTION ("TransparentNetworkIPResolution", true),
- TRUST_SERVER_CERTIFICATE ("trustServerCertificate", false),
- XOPEN_STATES ("xopenStates", false),
- FIPS ("fips", false),
+
+enum SQLServerDriverBooleanProperty {
+ DISABLE_STATEMENT_POOLING("disableStatementPooling", true),
+ ENCRYPT("encrypt", false),
+ INTEGRATED_SECURITY("integratedSecurity", false),
+ LAST_UPDATE_COUNT("lastUpdateCount", true),
+ MULTI_SUBNET_FAILOVER("multiSubnetFailover", false),
+ SERVER_NAME_AS_ACE("serverNameAsACE", false),
+ SEND_STRING_PARAMETERS_AS_UNICODE("sendStringParametersAsUnicode", true),
+ SEND_TIME_AS_DATETIME("sendTimeAsDatetime", true),
+ TRANSPARENT_NETWORK_IP_RESOLUTION("TransparentNetworkIPResolution", true),
+ TRUST_SERVER_CERTIFICATE("trustServerCertificate", false),
+ XOPEN_STATES("xopenStates", false),
+ FIPS("fips", false),
ENABLE_PREPARE_ON_FIRST_PREPARED_STATEMENT("enablePrepareOnFirstPreparedStatementCall", SQLServerConnection.DEFAULT_ENABLE_PREPARE_ON_FIRST_PREPARED_STATEMENT_CALL),
- USE_BULK_COPY_FOR_BATCH_INSERT ("useBulkCopyForBatchInsert", false);
+ USE_BULK_COPY_FOR_BATCH_INSERT("useBulkCopyForBatchInsert", false);
private final String name;
private final boolean defaultValue;
- private SQLServerDriverBooleanProperty(String name,
- boolean defaultValue) {
+ private SQLServerDriverBooleanProperty(String name, boolean defaultValue) {
this.name = name;
this.defaultValue = defaultValue;
}
@@ -374,83 +362,169 @@ public String toString() {
}
}
+
+/**
+ * Provides methods to connect to a SQL Server database and to obtain information about the JDBC driver.
+ */
public final class SQLServerDriver implements java.sql.Driver {
- static final String PRODUCT_NAME = "Microsoft JDBC Driver " + SQLJdbcVersion.major + "." + SQLJdbcVersion.minor + " for SQL Server";
+ static final String PRODUCT_NAME = "Microsoft JDBC Driver " + SQLJdbcVersion.major + "." + SQLJdbcVersion.minor
+ + " for SQL Server";
static final String DEFAULT_APP_NAME = "Microsoft JDBC Driver for SQL Server";
private static final String[] TRUE_FALSE = {"true", "false"};
- private static final SQLServerDriverPropertyInfo[] DRIVER_PROPERTIES =
- {
- // default required available choices
- // property name value property (if appropriate)
- new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.APPLICATION_INTENT.toString(), SQLServerDriverStringProperty.APPLICATION_INTENT.getDefaultValue(), false, new String[]{ApplicationIntent.READ_ONLY.toString(), ApplicationIntent.READ_WRITE.toString()}),
- new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.APPLICATION_NAME.toString(), SQLServerDriverStringProperty.APPLICATION_NAME.getDefaultValue(), false, null),
- new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.COLUMN_ENCRYPTION.toString(), SQLServerDriverStringProperty.COLUMN_ENCRYPTION.getDefaultValue(), false, new String[] {ColumnEncryptionSetting.Disabled.toString(), ColumnEncryptionSetting.Enabled.toString()}),
- new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.DATABASE_NAME.toString(), SQLServerDriverStringProperty.DATABASE_NAME.getDefaultValue(), false, null),
- new SQLServerDriverPropertyInfo(SQLServerDriverBooleanProperty.DISABLE_STATEMENT_POOLING.toString(), Boolean.toString(SQLServerDriverBooleanProperty.DISABLE_STATEMENT_POOLING.getDefaultValue()), false, new String[] {"true"}),
- new SQLServerDriverPropertyInfo(SQLServerDriverBooleanProperty.ENCRYPT.toString(), Boolean.toString(SQLServerDriverBooleanProperty.ENCRYPT.getDefaultValue()), false, TRUE_FALSE),
- new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.FAILOVER_PARTNER.toString(), SQLServerDriverStringProperty.FAILOVER_PARTNER.getDefaultValue(), false, null),
- new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.HOSTNAME_IN_CERTIFICATE.toString(), SQLServerDriverStringProperty.HOSTNAME_IN_CERTIFICATE.getDefaultValue(), false, null),
- new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.INSTANCE_NAME.toString(), SQLServerDriverStringProperty.INSTANCE_NAME.getDefaultValue(), false, null),
- new SQLServerDriverPropertyInfo(SQLServerDriverBooleanProperty.INTEGRATED_SECURITY.toString(), Boolean.toString(SQLServerDriverBooleanProperty.INTEGRATED_SECURITY.getDefaultValue()), false, TRUE_FALSE),
- new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.KEY_STORE_AUTHENTICATION.toString(), SQLServerDriverStringProperty.KEY_STORE_AUTHENTICATION.getDefaultValue(), false, new String[] {KeyStoreAuthentication.JavaKeyStorePassword.toString()}),
- new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.KEY_STORE_SECRET .toString(), SQLServerDriverStringProperty.KEY_STORE_SECRET.getDefaultValue(), false, null),
- new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.KEY_STORE_LOCATION .toString(), SQLServerDriverStringProperty.KEY_STORE_LOCATION.getDefaultValue(), false, null),
- new SQLServerDriverPropertyInfo(SQLServerDriverBooleanProperty.LAST_UPDATE_COUNT.toString(), Boolean.toString(SQLServerDriverBooleanProperty.LAST_UPDATE_COUNT.getDefaultValue()), false, TRUE_FALSE),
- new SQLServerDriverPropertyInfo(SQLServerDriverIntProperty.LOCK_TIMEOUT.toString(), Integer.toString(SQLServerDriverIntProperty.LOCK_TIMEOUT.getDefaultValue()), false, null),
- new SQLServerDriverPropertyInfo(SQLServerDriverIntProperty.LOGIN_TIMEOUT.toString(), Integer.toString(SQLServerDriverIntProperty.LOGIN_TIMEOUT.getDefaultValue()), false, null),
- new SQLServerDriverPropertyInfo(SQLServerDriverBooleanProperty.MULTI_SUBNET_FAILOVER.toString(), Boolean.toString(SQLServerDriverBooleanProperty.MULTI_SUBNET_FAILOVER.getDefaultValue()), false, TRUE_FALSE),
- new SQLServerDriverPropertyInfo(SQLServerDriverIntProperty.PACKET_SIZE.toString(), Integer.toString(SQLServerDriverIntProperty.PACKET_SIZE.getDefaultValue()), false, null),
- new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.PASSWORD.toString(), SQLServerDriverStringProperty.PASSWORD.getDefaultValue(), true, null),
- new SQLServerDriverPropertyInfo(SQLServerDriverIntProperty.PORT_NUMBER.toString(), Integer.toString(SQLServerDriverIntProperty.PORT_NUMBER.getDefaultValue()), false, null),
- new SQLServerDriverPropertyInfo(SQLServerDriverIntProperty.QUERY_TIMEOUT.toString(), Integer.toString(SQLServerDriverIntProperty.QUERY_TIMEOUT.getDefaultValue()), false, null),
- new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.RESPONSE_BUFFERING.toString(), SQLServerDriverStringProperty.RESPONSE_BUFFERING.getDefaultValue(), false, new String[] {"adaptive", "full"}),
- new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.SELECT_METHOD.toString(), SQLServerDriverStringProperty.SELECT_METHOD.getDefaultValue(), false, new String[] {"direct", "cursor"}),
- new SQLServerDriverPropertyInfo(SQLServerDriverBooleanProperty.SEND_STRING_PARAMETERS_AS_UNICODE.toString(), Boolean.toString(SQLServerDriverBooleanProperty.SEND_STRING_PARAMETERS_AS_UNICODE.getDefaultValue()), false, TRUE_FALSE),
- new SQLServerDriverPropertyInfo(SQLServerDriverBooleanProperty.SERVER_NAME_AS_ACE.toString(), Boolean.toString(SQLServerDriverBooleanProperty.SERVER_NAME_AS_ACE.getDefaultValue()), false, TRUE_FALSE),
- new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.SERVER_NAME.toString(), SQLServerDriverStringProperty.SERVER_NAME.getDefaultValue(), false, null),
- new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.SERVER_SPN.toString(), SQLServerDriverStringProperty.SERVER_SPN.getDefaultValue(), false, null),
- new SQLServerDriverPropertyInfo(SQLServerDriverBooleanProperty.TRANSPARENT_NETWORK_IP_RESOLUTION.toString(), Boolean.toString(SQLServerDriverBooleanProperty.TRANSPARENT_NETWORK_IP_RESOLUTION.getDefaultValue()), false, TRUE_FALSE),
- new SQLServerDriverPropertyInfo(SQLServerDriverBooleanProperty.TRUST_SERVER_CERTIFICATE.toString(), Boolean.toString(SQLServerDriverBooleanProperty.TRUST_SERVER_CERTIFICATE.getDefaultValue()), false, TRUE_FALSE),
- new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.TRUST_STORE_TYPE.toString(), SQLServerDriverStringProperty.TRUST_STORE_TYPE.getDefaultValue(), false, null),
- new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.TRUST_STORE.toString(), SQLServerDriverStringProperty.TRUST_STORE.getDefaultValue(), false, null),
- new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.TRUST_STORE_PASSWORD.toString(), SQLServerDriverStringProperty.TRUST_STORE_PASSWORD.getDefaultValue(), false, null),
- new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.TRUST_MANAGER_CLASS.toString(), SQLServerDriverStringProperty.TRUST_MANAGER_CLASS.getDefaultValue(), false, null),
- new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.TRUST_MANAGER_CONSTRUCTOR_ARG.toString(), SQLServerDriverStringProperty.TRUST_MANAGER_CONSTRUCTOR_ARG.getDefaultValue(), false, null),
- new SQLServerDriverPropertyInfo(SQLServerDriverBooleanProperty.SEND_TIME_AS_DATETIME.toString(), Boolean.toString(SQLServerDriverBooleanProperty.SEND_TIME_AS_DATETIME.getDefaultValue()), false, TRUE_FALSE),
- new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.USER.toString(), SQLServerDriverStringProperty.USER.getDefaultValue(), true, null),
- new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.WORKSTATION_ID.toString(), SQLServerDriverStringProperty.WORKSTATION_ID.getDefaultValue(), false, null),
- new SQLServerDriverPropertyInfo(SQLServerDriverBooleanProperty.XOPEN_STATES.toString(), Boolean.toString(SQLServerDriverBooleanProperty.XOPEN_STATES.getDefaultValue()), false, TRUE_FALSE),
- new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.AUTHENTICATION_SCHEME.toString(), SQLServerDriverStringProperty.AUTHENTICATION_SCHEME.getDefaultValue(), false, new String[] {AuthenticationScheme.javaKerberos.toString(),AuthenticationScheme.nativeAuthentication.toString()}),
- new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.AUTHENTICATION.toString(), SQLServerDriverStringProperty.AUTHENTICATION.getDefaultValue(), false, new String[] {SqlAuthentication.NotSpecified.toString(),SqlAuthentication.SqlPassword.toString(),SqlAuthentication.ActiveDirectoryPassword.toString(),SqlAuthentication.ActiveDirectoryIntegrated.toString()}),
- new SQLServerDriverPropertyInfo(SQLServerDriverIntProperty.SOCKET_TIMEOUT.toString(), Integer.toString(SQLServerDriverIntProperty.SOCKET_TIMEOUT.getDefaultValue()), false, null),
- new SQLServerDriverPropertyInfo(SQLServerDriverBooleanProperty.FIPS.toString(), Boolean.toString(SQLServerDriverBooleanProperty.FIPS.getDefaultValue()), false, TRUE_FALSE),
- new SQLServerDriverPropertyInfo(SQLServerDriverBooleanProperty.ENABLE_PREPARE_ON_FIRST_PREPARED_STATEMENT.toString(), Boolean.toString(SQLServerDriverBooleanProperty.ENABLE_PREPARE_ON_FIRST_PREPARED_STATEMENT.getDefaultValue()), false,TRUE_FALSE),
- new SQLServerDriverPropertyInfo(SQLServerDriverIntProperty.SERVER_PREPARED_STATEMENT_DISCARD_THRESHOLD.toString(), Integer.toString(SQLServerDriverIntProperty.SERVER_PREPARED_STATEMENT_DISCARD_THRESHOLD.getDefaultValue()), false, null),
- new SQLServerDriverPropertyInfo(SQLServerDriverIntProperty.STATEMENT_POOLING_CACHE_SIZE.toString(), Integer.toString(SQLServerDriverIntProperty.STATEMENT_POOLING_CACHE_SIZE.getDefaultValue()), false, null),
- new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.JAAS_CONFIG_NAME.toString(), SQLServerDriverStringProperty.JAAS_CONFIG_NAME.getDefaultValue(), false, null),
- new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.SSL_PROTOCOL.toString(), SQLServerDriverStringProperty.SSL_PROTOCOL.getDefaultValue(), false, new String[] {SSLProtocol.TLS.toString(), SSLProtocol.TLS_V10.toString(), SSLProtocol.TLS_V11.toString(), SSLProtocol.TLS_V12.toString()}),
- new SQLServerDriverPropertyInfo(SQLServerDriverIntProperty.CANCEL_QUERY_TIMEOUT.toString(), Integer.toString(SQLServerDriverIntProperty.CANCEL_QUERY_TIMEOUT.getDefaultValue()), false, null),
- new SQLServerDriverPropertyInfo(SQLServerDriverBooleanProperty.USE_BULK_COPY_FOR_BATCH_INSERT.toString(), Boolean.toString(SQLServerDriverBooleanProperty.USE_BULK_COPY_FOR_BATCH_INSERT.getDefaultValue()), false, TRUE_FALSE),
- };
-
- // Properties that can only be set by using Properties.
- // Cannot set in connection string
+ private static final SQLServerDriverPropertyInfo[] DRIVER_PROPERTIES = {
+ // default required available choices
+ // property name value property (if appropriate)
+ new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.APPLICATION_INTENT.toString(),
+ SQLServerDriverStringProperty.APPLICATION_INTENT.getDefaultValue(), false,
+ new String[] {ApplicationIntent.READ_ONLY.toString(), ApplicationIntent.READ_WRITE.toString()}),
+ new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.APPLICATION_NAME.toString(),
+ SQLServerDriverStringProperty.APPLICATION_NAME.getDefaultValue(), false, null),
+ new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.COLUMN_ENCRYPTION.toString(),
+ SQLServerDriverStringProperty.COLUMN_ENCRYPTION.getDefaultValue(), false,
+ new String[] {ColumnEncryptionSetting.Disabled.toString(),
+ ColumnEncryptionSetting.Enabled.toString()}),
+ new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.DATABASE_NAME.toString(),
+ SQLServerDriverStringProperty.DATABASE_NAME.getDefaultValue(), false, null),
+ new SQLServerDriverPropertyInfo(SQLServerDriverBooleanProperty.DISABLE_STATEMENT_POOLING.toString(),
+ Boolean.toString(SQLServerDriverBooleanProperty.DISABLE_STATEMENT_POOLING.getDefaultValue()), false,
+ new String[] {"true"}),
+ new SQLServerDriverPropertyInfo(SQLServerDriverBooleanProperty.ENCRYPT.toString(),
+ Boolean.toString(SQLServerDriverBooleanProperty.ENCRYPT.getDefaultValue()), false, TRUE_FALSE),
+ new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.FAILOVER_PARTNER.toString(),
+ SQLServerDriverStringProperty.FAILOVER_PARTNER.getDefaultValue(), false, null),
+ new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.HOSTNAME_IN_CERTIFICATE.toString(),
+ SQLServerDriverStringProperty.HOSTNAME_IN_CERTIFICATE.getDefaultValue(), false, null),
+ new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.INSTANCE_NAME.toString(),
+ SQLServerDriverStringProperty.INSTANCE_NAME.getDefaultValue(), false, null),
+ new SQLServerDriverPropertyInfo(SQLServerDriverBooleanProperty.INTEGRATED_SECURITY.toString(),
+ Boolean.toString(SQLServerDriverBooleanProperty.INTEGRATED_SECURITY.getDefaultValue()), false,
+ TRUE_FALSE),
+ new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.KEY_STORE_AUTHENTICATION.toString(),
+ SQLServerDriverStringProperty.KEY_STORE_AUTHENTICATION.getDefaultValue(), false,
+ new String[] {KeyStoreAuthentication.JavaKeyStorePassword.toString()}),
+ new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.KEY_STORE_SECRET.toString(),
+ SQLServerDriverStringProperty.KEY_STORE_SECRET.getDefaultValue(), false, null),
+ new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.KEY_STORE_LOCATION.toString(),
+ SQLServerDriverStringProperty.KEY_STORE_LOCATION.getDefaultValue(), false, null),
+ new SQLServerDriverPropertyInfo(SQLServerDriverBooleanProperty.LAST_UPDATE_COUNT.toString(),
+ Boolean.toString(SQLServerDriverBooleanProperty.LAST_UPDATE_COUNT.getDefaultValue()), false,
+ TRUE_FALSE),
+ new SQLServerDriverPropertyInfo(SQLServerDriverIntProperty.LOCK_TIMEOUT.toString(),
+ Integer.toString(SQLServerDriverIntProperty.LOCK_TIMEOUT.getDefaultValue()), false, null),
+ new SQLServerDriverPropertyInfo(SQLServerDriverIntProperty.LOGIN_TIMEOUT.toString(),
+ Integer.toString(SQLServerDriverIntProperty.LOGIN_TIMEOUT.getDefaultValue()), false, null),
+ new SQLServerDriverPropertyInfo(SQLServerDriverBooleanProperty.MULTI_SUBNET_FAILOVER.toString(),
+ Boolean.toString(SQLServerDriverBooleanProperty.MULTI_SUBNET_FAILOVER.getDefaultValue()), false,
+ TRUE_FALSE),
+ new SQLServerDriverPropertyInfo(SQLServerDriverIntProperty.PACKET_SIZE.toString(),
+ Integer.toString(SQLServerDriverIntProperty.PACKET_SIZE.getDefaultValue()), false, null),
+ new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.PASSWORD.toString(),
+ SQLServerDriverStringProperty.PASSWORD.getDefaultValue(), true, null),
+ new SQLServerDriverPropertyInfo(SQLServerDriverIntProperty.PORT_NUMBER.toString(),
+ Integer.toString(SQLServerDriverIntProperty.PORT_NUMBER.getDefaultValue()), false, null),
+ new SQLServerDriverPropertyInfo(SQLServerDriverIntProperty.QUERY_TIMEOUT.toString(),
+ Integer.toString(SQLServerDriverIntProperty.QUERY_TIMEOUT.getDefaultValue()), false, null),
+ new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.RESPONSE_BUFFERING.toString(),
+ SQLServerDriverStringProperty.RESPONSE_BUFFERING.getDefaultValue(), false,
+ new String[] {"adaptive", "full"}),
+ new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.SELECT_METHOD.toString(),
+ SQLServerDriverStringProperty.SELECT_METHOD.getDefaultValue(), false,
+ new String[] {"direct", "cursor"}),
+ new SQLServerDriverPropertyInfo(SQLServerDriverBooleanProperty.SEND_STRING_PARAMETERS_AS_UNICODE.toString(),
+ Boolean.toString(
+ SQLServerDriverBooleanProperty.SEND_STRING_PARAMETERS_AS_UNICODE.getDefaultValue()),
+ false, TRUE_FALSE),
+ new SQLServerDriverPropertyInfo(SQLServerDriverBooleanProperty.SERVER_NAME_AS_ACE.toString(),
+ Boolean.toString(SQLServerDriverBooleanProperty.SERVER_NAME_AS_ACE.getDefaultValue()), false,
+ TRUE_FALSE),
+ new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.SERVER_NAME.toString(),
+ SQLServerDriverStringProperty.SERVER_NAME.getDefaultValue(), false, null),
+ new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.SERVER_SPN.toString(),
+ SQLServerDriverStringProperty.SERVER_SPN.getDefaultValue(), false, null),
+ new SQLServerDriverPropertyInfo(SQLServerDriverBooleanProperty.TRANSPARENT_NETWORK_IP_RESOLUTION.toString(),
+ Boolean.toString(
+ SQLServerDriverBooleanProperty.TRANSPARENT_NETWORK_IP_RESOLUTION.getDefaultValue()),
+ false, TRUE_FALSE),
+ new SQLServerDriverPropertyInfo(SQLServerDriverBooleanProperty.TRUST_SERVER_CERTIFICATE.toString(),
+ Boolean.toString(SQLServerDriverBooleanProperty.TRUST_SERVER_CERTIFICATE.getDefaultValue()), false,
+ TRUE_FALSE),
+ new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.TRUST_STORE_TYPE.toString(),
+ SQLServerDriverStringProperty.TRUST_STORE_TYPE.getDefaultValue(), false, null),
+ new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.TRUST_STORE.toString(),
+ SQLServerDriverStringProperty.TRUST_STORE.getDefaultValue(), false, null),
+ new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.TRUST_STORE_PASSWORD.toString(),
+ SQLServerDriverStringProperty.TRUST_STORE_PASSWORD.getDefaultValue(), false, null),
+ new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.TRUST_MANAGER_CLASS.toString(),
+ SQLServerDriverStringProperty.TRUST_MANAGER_CLASS.getDefaultValue(), false, null),
+ new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.TRUST_MANAGER_CONSTRUCTOR_ARG.toString(),
+ SQLServerDriverStringProperty.TRUST_MANAGER_CONSTRUCTOR_ARG.getDefaultValue(), false, null),
+ new SQLServerDriverPropertyInfo(SQLServerDriverBooleanProperty.SEND_TIME_AS_DATETIME.toString(),
+ Boolean.toString(SQLServerDriverBooleanProperty.SEND_TIME_AS_DATETIME.getDefaultValue()), false,
+ TRUE_FALSE),
+ new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.USER.toString(),
+ SQLServerDriverStringProperty.USER.getDefaultValue(), true, null),
+ new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.WORKSTATION_ID.toString(),
+ SQLServerDriverStringProperty.WORKSTATION_ID.getDefaultValue(), false, null),
+ new SQLServerDriverPropertyInfo(SQLServerDriverBooleanProperty.XOPEN_STATES.toString(),
+ Boolean.toString(SQLServerDriverBooleanProperty.XOPEN_STATES.getDefaultValue()), false, TRUE_FALSE),
+ new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.AUTHENTICATION_SCHEME.toString(),
+ SQLServerDriverStringProperty.AUTHENTICATION_SCHEME.getDefaultValue(), false,
+ new String[] {AuthenticationScheme.javaKerberos.toString(),
+ AuthenticationScheme.nativeAuthentication.toString()}),
+ new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.AUTHENTICATION.toString(),
+ SQLServerDriverStringProperty.AUTHENTICATION.getDefaultValue(), false,
+ new String[] {SqlAuthentication.NotSpecified.toString(), SqlAuthentication.SqlPassword.toString(),
+ SqlAuthentication.ActiveDirectoryPassword.toString(),
+ SqlAuthentication.ActiveDirectoryIntegrated.toString()}),
+ new SQLServerDriverPropertyInfo(SQLServerDriverIntProperty.SOCKET_TIMEOUT.toString(),
+ Integer.toString(SQLServerDriverIntProperty.SOCKET_TIMEOUT.getDefaultValue()), false, null),
+ new SQLServerDriverPropertyInfo(SQLServerDriverBooleanProperty.FIPS.toString(),
+ Boolean.toString(SQLServerDriverBooleanProperty.FIPS.getDefaultValue()), false, TRUE_FALSE),
+ new SQLServerDriverPropertyInfo(
+ SQLServerDriverBooleanProperty.ENABLE_PREPARE_ON_FIRST_PREPARED_STATEMENT.toString(),
+ Boolean.toString(SQLServerDriverBooleanProperty.ENABLE_PREPARE_ON_FIRST_PREPARED_STATEMENT
+ .getDefaultValue()),
+ false, TRUE_FALSE),
+ new SQLServerDriverPropertyInfo(
+ SQLServerDriverIntProperty.SERVER_PREPARED_STATEMENT_DISCARD_THRESHOLD.toString(),
+ Integer.toString(
+ SQLServerDriverIntProperty.SERVER_PREPARED_STATEMENT_DISCARD_THRESHOLD.getDefaultValue()),
+ false, null),
+ new SQLServerDriverPropertyInfo(SQLServerDriverIntProperty.STATEMENT_POOLING_CACHE_SIZE.toString(),
+ Integer.toString(SQLServerDriverIntProperty.STATEMENT_POOLING_CACHE_SIZE.getDefaultValue()), false,
+ null),
+ new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.JAAS_CONFIG_NAME.toString(),
+ SQLServerDriverStringProperty.JAAS_CONFIG_NAME.getDefaultValue(), false, null),
+ new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.SSL_PROTOCOL.toString(),
+ SQLServerDriverStringProperty.SSL_PROTOCOL.getDefaultValue(), false,
+ new String[] {SSLProtocol.TLS.toString(), SSLProtocol.TLS_V10.toString(),
+ SSLProtocol.TLS_V11.toString(), SSLProtocol.TLS_V12.toString()}),
+ new SQLServerDriverPropertyInfo(SQLServerDriverIntProperty.CANCEL_QUERY_TIMEOUT.toString(),
+ Integer.toString(SQLServerDriverIntProperty.CANCEL_QUERY_TIMEOUT.getDefaultValue()), false, null),
+ new SQLServerDriverPropertyInfo(SQLServerDriverBooleanProperty.USE_BULK_COPY_FOR_BATCH_INSERT.toString(),
+ Boolean.toString(SQLServerDriverBooleanProperty.USE_BULK_COPY_FOR_BATCH_INSERT.getDefaultValue()),
+ false, TRUE_FALSE),};
+
+ /**
+ * Properties that can only be set by using Properties. Cannot set in connection string
+ */
private static final SQLServerDriverPropertyInfo[] DRIVER_PROPERTIES_PROPERTY_ONLY = {
- // default required available choices
- // property name value property (if appropriate)
- new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.ACCESS_TOKEN.toString(), SQLServerDriverStringProperty.ACCESS_TOKEN.getDefaultValue(), false, null),
- new SQLServerDriverPropertyInfo(SQLServerDriverObjectProperty.GSS_CREDENTIAL.toString(), SQLServerDriverObjectProperty.GSS_CREDENTIAL.getDefaultValue(), false, null),
- };
-
- private static final String driverPropertiesSynonyms[][] = {
- {"database", SQLServerDriverStringProperty.DATABASE_NAME.toString()},
- {"userName",SQLServerDriverStringProperty.USER.toString()},
- {"server",SQLServerDriverStringProperty.SERVER_NAME.toString()},
- {"port", SQLServerDriverIntProperty.PORT_NUMBER.toString()}
- };
- static private final AtomicInteger baseID = new AtomicInteger(0); // Unique id generator for each instance (used for logging).
- final private int instanceID; // Unique id for this instance.
+ // default required available choices
+ // property name value property (if appropriate)
+ new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.ACCESS_TOKEN.toString(),
+ SQLServerDriverStringProperty.ACCESS_TOKEN.getDefaultValue(), false, null),
+ new SQLServerDriverPropertyInfo(SQLServerDriverObjectProperty.GSS_CREDENTIAL.toString(),
+ SQLServerDriverObjectProperty.GSS_CREDENTIAL.getDefaultValue(), false, null),};
+
+ private static final String driverPropertiesSynonyms[][] = {
+ {"database", SQLServerDriverStringProperty.DATABASE_NAME.toString()},
+ {"userName", SQLServerDriverStringProperty.USER.toString()},
+ {"server", SQLServerDriverStringProperty.SERVER_NAME.toString()},
+ {"port", SQLServerDriverIntProperty.PORT_NUMBER.toString()}};
+ static private final AtomicInteger baseID = new AtomicInteger(0); // Unique id generator for each instance (used for
+ // logging).
+ final private int instanceID; // Unique id for this instance.
final private String traceID;
// Returns unique id for each instance.
@@ -462,8 +536,10 @@ final public String toString() {
return traceID;
}
- static final private java.util.logging.Logger loggerExternal = java.util.logging.Logger.getLogger("com.microsoft.sqlserver.jdbc.Driver");
- static final private java.util.logging.Logger parentLogger = java.util.logging.Logger.getLogger("com.microsoft.sqlserver.jdbc");
+ static final private java.util.logging.Logger loggerExternal = java.util.logging.Logger
+ .getLogger("com.microsoft.sqlserver.jdbc.Driver");
+ static final private java.util.logging.Logger parentLogger = java.util.logging.Logger
+ .getLogger("com.microsoft.sqlserver.jdbc");
final private String loggingClassName;
String getClassNameLogging() {
@@ -476,8 +552,7 @@ String getClassNameLogging() {
static {
try {
java.sql.DriverManager.registerDriver(new SQLServerDriver());
- }
- catch (SQLException e) {
+ } catch (SQLException e) {
if (drLogger.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) {
drLogger.finer("Error registering driver: " + e);
}
@@ -490,8 +565,10 @@ public SQLServerDriver() {
loggingClassName = "com.microsoft.sqlserver.jdbc." + "SQLServerDriver:" + instanceID;
}
- // Helper function used to fixup the case sensitivity, synonyms and remove unknown tokens from the
- // properties
+ /**
+ * Provides Helper function used to fix the case sensitivity, synonyms and remove unknown tokens from the
+ * properties.
+ */
static Properties fixupProperties(Properties props) throws SQLServerException {
// assert props !=null
Properties fixedup = new Properties();
@@ -509,11 +586,9 @@ static Properties fixupProperties(Properties props) throws SQLServerException {
if (null != val) {
// replace with the driver approved name
fixedup.setProperty(newname, val);
- }
- else if(newname.equalsIgnoreCase("gsscredential") && (props.get(name) instanceof GSSCredential)){
- fixedup.put(newname, props.get(name));
- }
- else {
+ } else if (newname.equalsIgnoreCase("gsscredential") && (props.get(name) instanceof GSSCredential)) {
+ fixedup.put(newname, props.get(name));
+ } else {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidpropertyValue"));
Object[] msgArgs = {name};
throw new SQLServerException(null, form.format(msgArgs), null, 0, false);
@@ -524,9 +599,11 @@ else if(newname.equalsIgnoreCase("gsscredential") && (props.get(name) instanceof
return fixedup;
}
- // Helper function used to merge together the property set extracted from the url and the
- // user supplied property set passed in by the caller. This function is used by both SQLServerDriver.connect
- // and SQLServerDataSource.getConnectionInternal to centralize this property merging code.
+ /**
+ * Provides Helper function used to merge together the property set extracted from the url and the user supplied
+ * property set passed in by the caller. This function is used by both SQLServerDriver.connect and
+ * SQLServerDataSource.getConnectionInternal to centralize this property merging code.
+ */
static Properties mergeURLAndSuppliedProperties(Properties urlProps,
Properties suppliedProperties) throws SQLServerException {
if (null == suppliedProperties)
@@ -558,15 +635,14 @@ static Properties mergeURLAndSuppliedProperties(Properties urlProps,
}
/**
- * normalize the property names
+ * Returns the normalized the property names.
*
* @param name
- * name to normalize
+ * name to normalize
* @param logger
* @return the normalized property name
*/
- static String getNormalizedPropertyName(String name,
- Logger logger) {
+ static String getNormalizedPropertyName(String name, Logger logger) {
if (null == name)
return name;
@@ -587,15 +663,14 @@ static String getNormalizedPropertyName(String name,
}
/**
- * get property-only names that do not work with connection string
+ * Returns the property-only names that do not work with connection string.
*
* @param name
- * to normalize
+ * to normalize
* @param logger
* @return the normalized property name
*/
- static String getPropertyOnlyName(String name,
- Logger logger) {
+ static String getPropertyOnlyName(String name, Logger logger) {
if (null == name)
return name;
@@ -610,8 +685,7 @@ static String getPropertyOnlyName(String name,
return null;
}
- /* L0 */ public java.sql.Connection connect(String Url,
- Properties suppliedProperties) throws SQLServerException {
+ public java.sql.Connection connect(String Url, Properties suppliedProperties) throws SQLServerException {
loggerExternal.entering(getClassNameLogging(), "connect", "Arguments not traced.");
SQLServerConnection result = null;
@@ -620,8 +694,7 @@ static String getPropertyOnlyName(String name,
if (connectProperties != null) {
if (Util.use43Wrapper()) {
result = new SQLServerConnection43(toString());
- }
- else {
+ } else {
result = new SQLServerConnection(toString());
}
result.connect(connectProperties, null);
@@ -630,20 +703,20 @@ static String getPropertyOnlyName(String name,
return result;
}
- private Properties parseAndMergeProperties(String Url,
- Properties suppliedProperties) throws SQLServerException {
+ private Properties parseAndMergeProperties(String Url, Properties suppliedProperties) throws SQLServerException {
if (Url == null) {
throw new SQLServerException(null, SQLServerException.getErrString("R_nullConnection"), null, 0, false);
}
Properties connectProperties = Util.parseUrl(Url, drLogger);
if (connectProperties == null)
- return null; // If we are the wrong driver dont throw an exception
+ return null; // If we are the wrong driver dont throw an exception
// put the user properties into the connect properties
int nTimeout = DriverManager.getLoginTimeout();
if (nTimeout > 0) {
- connectProperties.put(SQLServerDriverIntProperty.LOGIN_TIMEOUT.toString(), Integer.valueOf(nTimeout).toString());
+ connectProperties.put(SQLServerDriverIntProperty.LOGIN_TIMEOUT.toString(),
+ Integer.valueOf(nTimeout).toString());
}
// Merge connectProperties (from URL) and supplied properties from user.
@@ -651,7 +724,7 @@ private Properties parseAndMergeProperties(String Url,
return connectProperties;
}
- /* L0 */ public boolean acceptsURL(String url) throws SQLServerException {
+ public boolean acceptsURL(String url) throws SQLServerException {
loggerExternal.entering(getClassNameLogging(), "acceptsURL", "Arguments not traced.");
if (null == url) {
@@ -661,8 +734,7 @@ private Properties parseAndMergeProperties(String Url,
boolean result = false;
try {
result = (Util.parseUrl(url, drLogger) != null);
- }
- catch (SQLServerException e) {
+ } catch (SQLServerException e) {
// ignore the exception from the parse URL failure, if we cant parse the URL we do not accept em
result = false;
}
@@ -670,8 +742,7 @@ private Properties parseAndMergeProperties(String Url,
return result;
}
- public DriverPropertyInfo[] getPropertyInfo(String Url,
- Properties Info) throws SQLServerException {
+ public DriverPropertyInfo[] getPropertyInfo(String Url, Properties Info) throws SQLServerException {
loggerExternal.entering(getClassNameLogging(), "getPropertyInfo", "Arguments not traced.");
Properties connProperties = parseAndMergeProperties(Url, Info);
@@ -708,7 +779,7 @@ public Logger getParentLogger() throws SQLFeatureNotSupportedException {
return parentLogger;
}
- /* L0 */ public boolean jdbcCompliant() {
+ public boolean jdbcCompliant() {
loggerExternal.entering(getClassNameLogging(), "jdbcCompliant");
loggerExternal.exiting(getClassNameLogging(), "jdbcCompliant", Boolean.TRUE);
return true;
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerEncryptionAlgorithm.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerEncryptionAlgorithm.java
index a6bf63340..1805ff57c 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerEncryptionAlgorithm.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerEncryptionAlgorithm.java
@@ -1,35 +1,32 @@
-/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
- */
-
-package com.microsoft.sqlserver.jdbc;
-
-/*
- * Abstract base class for all AE encryption algorithms. It exposes two functions 1. encryptData - This function is used by the driver under the
- * covers to transparently encrypt AE enabled column data. 2. decryptData - This function is used by the driver under the covers to transparently
- * decrypt AE enabled column data.
- */
-abstract class SQLServerEncryptionAlgorithm {
-
- /**
- * Perform encryption of the plain text
- *
- * @param plainText
- * data to be encrypted
- * @return cipher text after encryption
- */
- abstract byte[] encryptData(byte[] plainText) throws SQLServerException;
-
- /**
- * Decrypt cipher text to plain text
- *
- * @param cipherText
- * data to be decrypted
- * @return plain text after decryption
- */
- abstract byte[] decryptData(byte[] cipherText) throws SQLServerException;
-}
+/*
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ */
+
+package com.microsoft.sqlserver.jdbc;
+
+/*
+ * Abstract base class for all AE encryption algorithms. It exposes two functions 1. encryptData - This function is used
+ * by the driver under the covers to transparently encrypt AE enabled column data. 2. decryptData - This function is
+ * used by the driver under the covers to transparently decrypt AE enabled column data.
+ */
+abstract class SQLServerEncryptionAlgorithm {
+
+ /**
+ * Perform encryption of the plain text
+ *
+ * @param plainText
+ * data to be encrypted
+ * @return cipher text after encryption
+ */
+ abstract byte[] encryptData(byte[] plainText) throws SQLServerException;
+
+ /**
+ * Decrypt cipher text to plain text
+ *
+ * @param cipherText
+ * data to be decrypted
+ * @return plain text after decryption
+ */
+ abstract byte[] decryptData(byte[] cipherText) throws SQLServerException;
+}
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerEncryptionAlgorithmFactory.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerEncryptionAlgorithmFactory.java
index ef896a7c0..f32274e1e 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerEncryptionAlgorithmFactory.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerEncryptionAlgorithmFactory.java
@@ -1,34 +1,30 @@
-/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
- */
-
-package com.microsoft.sqlserver.jdbc;
-
-/**
- *
- * Abstract base class for all the encryption algorithm factory classes.
- *
- */
-abstract class SQLServerEncryptionAlgorithmFactory {
-
- /**
- *
- * @param columnEncryptionKey
- * key which will be used in encryption/decryption
- * @param encryptionType
- * specifies kind of encryption
- * @param encryptionAlgorithm
- * name of encryption algorithm
- * @return created SQLServerEncryptionAlgorithm instance
- * @throws SQLServerException
- * when an error occurs
- */
- abstract SQLServerEncryptionAlgorithm create(SQLServerSymmetricKey columnEncryptionKey,
- SQLServerEncryptionType encryptionType,
- String encryptionAlgorithm) throws SQLServerException;
-
-}
+/*
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ */
+
+package com.microsoft.sqlserver.jdbc;
+
+/**
+ *
+ * Abstract base class for all the encryption algorithm factory classes.
+ *
+ */
+abstract class SQLServerEncryptionAlgorithmFactory {
+
+ /**
+ *
+ * @param columnEncryptionKey
+ * key which will be used in encryption/decryption
+ * @param encryptionType
+ * specifies kind of encryption
+ * @param encryptionAlgorithm
+ * name of encryption algorithm
+ * @return created SQLServerEncryptionAlgorithm instance
+ * @throws SQLServerException
+ * when an error occurs
+ */
+ abstract SQLServerEncryptionAlgorithm create(SQLServerSymmetricKey columnEncryptionKey,
+ SQLServerEncryptionType encryptionType, String encryptionAlgorithm) throws SQLServerException;
+
+}
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerEncryptionAlgorithmFactoryList.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerEncryptionAlgorithmFactoryList.java
index a7eb1c0de..9e8f35f61 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerEncryptionAlgorithmFactoryList.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerEncryptionAlgorithmFactoryList.java
@@ -1,79 +1,78 @@
-/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
- */
-
-package com.microsoft.sqlserver.jdbc;
-
-import java.text.MessageFormat;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * Maintain list of all the encryption algorithm factory classes
- */
-final class SQLServerEncryptionAlgorithmFactoryList {
-
- private ConcurrentHashMap encryptionAlgoFactoryMap;
-
- private static final SQLServerEncryptionAlgorithmFactoryList instance = new SQLServerEncryptionAlgorithmFactoryList();
-
- private SQLServerEncryptionAlgorithmFactoryList() {
- encryptionAlgoFactoryMap = new ConcurrentHashMap<>();
- encryptionAlgoFactoryMap.putIfAbsent(SQLServerAeadAes256CbcHmac256Algorithm.algorithmName, new SQLServerAeadAes256CbcHmac256Factory());
- }
-
- static SQLServerEncryptionAlgorithmFactoryList getInstance() {
- return instance;
- }
-
- /**
- * @return list of registered algorithms separated by comma
- */
- String getRegisteredCipherAlgorithmNames() {
- StringBuffer stringBuff = new StringBuffer();
- boolean first = true;
- for (String key : encryptionAlgoFactoryMap.keySet()) {
- if (first) {
- stringBuff.append("'");
- first = false;
- }
- else {
- stringBuff.append(", '");
- }
- stringBuff.append(key);
- stringBuff.append("'");
-
- }
- return stringBuff.toString();
- }
-
- /**
- * Return instance for given algorithm
- *
- * @param key
- * @param encryptionType
- * @param algorithmName
- * @return instance for given algorithm
- * @throws SQLServerException
- */
- SQLServerEncryptionAlgorithm getAlgorithm(SQLServerSymmetricKey key,
- SQLServerEncryptionType encryptionType,
- String algorithmName) throws SQLServerException {
- SQLServerEncryptionAlgorithm encryptionAlgorithm = null;
- SQLServerEncryptionAlgorithmFactory factory = null;
- if (!encryptionAlgoFactoryMap.containsKey(algorithmName)) {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_UnknownColumnEncryptionAlgorithm"));
- Object[] msgArgs = {algorithmName, SQLServerEncryptionAlgorithmFactoryList.getInstance().getRegisteredCipherAlgorithmNames()};
- throw new SQLServerException(this, form.format(msgArgs), null, 0, false);
- }
-
- factory = encryptionAlgoFactoryMap.get(algorithmName);
- assert null != factory : "Null Algorithm Factory class detected";
- encryptionAlgorithm = factory.create(key, encryptionType, algorithmName);
- return encryptionAlgorithm;
- }
-
-}
+/*
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ */
+
+package com.microsoft.sqlserver.jdbc;
+
+import java.text.MessageFormat;
+import java.util.concurrent.ConcurrentHashMap;
+
+
+/**
+ * Maintain list of all the encryption algorithm factory classes
+ */
+final class SQLServerEncryptionAlgorithmFactoryList {
+
+ private ConcurrentHashMap encryptionAlgoFactoryMap;
+
+ private static final SQLServerEncryptionAlgorithmFactoryList instance = new SQLServerEncryptionAlgorithmFactoryList();
+
+ private SQLServerEncryptionAlgorithmFactoryList() {
+ encryptionAlgoFactoryMap = new ConcurrentHashMap<>();
+ encryptionAlgoFactoryMap.putIfAbsent(SQLServerAeadAes256CbcHmac256Algorithm.algorithmName,
+ new SQLServerAeadAes256CbcHmac256Factory());
+ }
+
+ static SQLServerEncryptionAlgorithmFactoryList getInstance() {
+ return instance;
+ }
+
+ /**
+ * @return list of registered algorithms separated by comma
+ */
+ String getRegisteredCipherAlgorithmNames() {
+ StringBuffer stringBuff = new StringBuffer();
+ boolean first = true;
+ for (String key : encryptionAlgoFactoryMap.keySet()) {
+ if (first) {
+ stringBuff.append("'");
+ first = false;
+ } else {
+ stringBuff.append(", '");
+ }
+ stringBuff.append(key);
+ stringBuff.append("'");
+
+ }
+ return stringBuff.toString();
+ }
+
+ /**
+ * Return instance for given algorithm
+ *
+ * @param key
+ * @param encryptionType
+ * @param algorithmName
+ * @return instance for given algorithm
+ * @throws SQLServerException
+ */
+ SQLServerEncryptionAlgorithm getAlgorithm(SQLServerSymmetricKey key, SQLServerEncryptionType encryptionType,
+ String algorithmName) throws SQLServerException {
+ SQLServerEncryptionAlgorithm encryptionAlgorithm = null;
+ SQLServerEncryptionAlgorithmFactory factory = null;
+ if (!encryptionAlgoFactoryMap.containsKey(algorithmName)) {
+ MessageFormat form = new MessageFormat(
+ SQLServerException.getErrString("R_UnknownColumnEncryptionAlgorithm"));
+ Object[] msgArgs = {algorithmName,
+ SQLServerEncryptionAlgorithmFactoryList.getInstance().getRegisteredCipherAlgorithmNames()};
+ throw new SQLServerException(this, form.format(msgArgs), null, 0, false);
+ }
+
+ factory = encryptionAlgoFactoryMap.get(algorithmName);
+ assert null != factory : "Null Algorithm Factory class detected";
+ encryptionAlgorithm = factory.create(key, encryptionType, algorithmName);
+ return encryptionAlgorithm;
+ }
+
+}
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerEncryptionType.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerEncryptionType.java
index 3e7812e17..3205d471c 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerEncryptionType.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerEncryptionType.java
@@ -1,46 +1,44 @@
-/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
- */
-
-package com.microsoft.sqlserver.jdbc;
-
-import java.text.MessageFormat;
-
-/**
- *
- * Encryption types supported
- *
- */
-enum SQLServerEncryptionType {
- Deterministic ((byte) 1),
- Randomized ((byte) 2),
- PlainText ((byte) 0);
-
- final byte value;
-
- SQLServerEncryptionType(byte val) {
- this.value = val;
- }
-
- byte getValue() {
- return this.value;
- }
-
- static SQLServerEncryptionType of(byte val) throws SQLServerException {
- for (SQLServerEncryptionType type : values())
- if (val == type.value)
- return type;
-
- // Invalid type.
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_unknownColumnEncryptionType"));
- Object[] msgArgs = {val};
- SQLServerException.makeFromDriverError(null, null, form.format(msgArgs), null, true);
-
- // Make the compiler happy.
- return null;
- }
-}
+/*
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ */
+
+package com.microsoft.sqlserver.jdbc;
+
+import java.text.MessageFormat;
+
+
+/**
+ *
+ * Encryption types supported
+ *
+ */
+enum SQLServerEncryptionType {
+ Deterministic((byte) 1),
+ Randomized((byte) 2),
+ PlainText((byte) 0);
+
+ final byte value;
+
+ SQLServerEncryptionType(byte val) {
+ this.value = val;
+ }
+
+ byte getValue() {
+ return this.value;
+ }
+
+ static SQLServerEncryptionType of(byte val) throws SQLServerException {
+ for (SQLServerEncryptionType type : values())
+ if (val == type.value)
+ return type;
+
+ // Invalid type.
+ MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_unknownColumnEncryptionType"));
+ Object[] msgArgs = {val};
+ SQLServerException.makeFromDriverError(null, null, form.format(msgArgs), null, true);
+
+ // Make the compiler happy.
+ return null;
+ }
+}
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerException.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerException.java
index 18cf1bbac..0f54156a8 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerException.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerException.java
@@ -1,9 +1,6 @@
/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc;
@@ -13,18 +10,13 @@
import java.util.UUID;
import java.util.logging.Level;
-/**
- * SQLServerException is thrown from any point in the driver that throws a java.sql.SQLException. SQLServerException handles both SQL 92 and XOPEN
- * state codes. They are switchable via a user specified connection property. SQLServerExceptions are written to any open log files the user has
- * specified.
- */
enum SQLState {
- STATEMENT_CANCELED ("HY008"),
- DATA_EXCEPTION_NOT_SPECIFIC ("22000"),
- DATA_EXCEPTION_DATETIME_FIELD_OVERFLOW ("22008"),
- DATA_EXCEPTION_LENGTH_MISMATCH ("22026"),
- COL_NOT_FOUND ("42S22");
+ STATEMENT_CANCELED("HY008"),
+ DATA_EXCEPTION_NOT_SPECIFIC("22000"),
+ DATA_EXCEPTION_DATETIME_FIELD_OVERFLOW("22008"),
+ DATA_EXCEPTION_LENGTH_MISMATCH("22026"),
+ COL_NOT_FOUND("42S22");
private final String sqlStateCode;
@@ -37,6 +29,7 @@ final String getSQLStateCode() {
}
}
+
enum DriverError {
NOT_SET(0);
@@ -51,7 +44,17 @@ final int getErrorCode() {
}
}
+
+/**
+ * Represents the exception thrown from any point in the driver that throws a java.sql.SQLException. SQLServerException
+ * handles both SQL 92 and XOPEN state codes. They are switchable via a user specified connection property.
+ * SQLServerExceptions are written to any open log files the user has specified.
+ */
public final class SQLServerException extends java.sql.SQLException {
+ /**
+ * Always update serialVersionUID when prompted
+ */
+ private static final long serialVersionUID = -2195310557661496761L;
static final String EXCEPTION_XOPEN_CONNECTION_CANT_ESTABLISH = "08001";
static final String EXCEPTION_XOPEN_CONNECTION_DOES_NOT_EXIST = "08003";
static final String EXCEPTION_XOPEN_CONNECTION_FAILURE = "08006"; // After connection was connected OK
@@ -61,7 +64,8 @@ public final class SQLServerException extends java.sql.SQLException {
static final int LOGON_FAILED = 18456;
static final int PASSWORD_EXPIRED = 18488;
static final int USER_ACCOUNT_LOCKED = 18486;
- static java.util.logging.Logger exLogger = java.util.logging.Logger.getLogger("com.microsoft.sqlserver.jdbc.internals.SQLServerException");
+ static java.util.logging.Logger exLogger = java.util.logging.Logger
+ .getLogger("com.microsoft.sqlserver.jdbc.internals.SQLServerException");
// Facility for driver-specific error codes
static final int DRIVER_ERROR_NONE = 0;
@@ -77,7 +81,7 @@ public final class SQLServerException extends java.sql.SQLException {
static final int DATA_CLASSIFICATION_NOT_EXPECTED = 11;
static final int DATA_CLASSIFICATION_INVALID_LABEL_INDEX = 12;
static final int DATA_CLASSIFICATION_INVALID_INFORMATION_TYPE_INDEX = 13;
-
+
private int driverErrorCode = DRIVER_ERROR_NONE;
final int getDriverErrorCode() {
@@ -89,18 +93,16 @@ final void setDriverErrorCode(int value) {
}
/**
- * Log an exception to the driver log file
+ * Logs an exception to the driver log file.
*
* @param o
- * the io buffer that generated the exception
+ * the io buffer that generated the exception
* @param errText
- * the excception message
+ * the excception message
* @param bStack
- * true to generate the stack trace
+ * true to generate the stack trace
*/
- private void logException(Object o,
- String errText,
- boolean bStack) {
+ private void logException(Object o, String errText, boolean bStack) {
String id = "";
if (o != null)
id = o.toString();
@@ -133,97 +135,80 @@ static String getErrString(String errCode) {
}
/**
- * Make a new SQLException
+ * Construct a SQLServerException.
*
* @param errText
- * the exception message
+ * the exception message
* @param sqlState
- * the statement
+ * the statement
* @param driverError
- * the driver error object
+ * the driver error object
* @param cause
- * The exception that caused this exception
+ * The exception that caused this exception
*/
- public SQLServerException(String errText,
- SQLState sqlState,
- DriverError driverError,
- Throwable cause) {
+ SQLServerException(String errText, SQLState sqlState, DriverError driverError, Throwable cause) {
this(errText, sqlState.getSQLStateCode(), driverError.getErrorCode(), cause);
}
- public SQLServerException(String errText,
- String errState,
- int errNum,
- Throwable cause) {
+ SQLServerException(String errText, String errState, int errNum, Throwable cause) {
super(errText, errState, errNum);
initCause(cause);
logException(null, errText, true);
- ActivityCorrelator.setCurrentActivityIdSentFlag(); // set the activityid flag so that we don't send the current ActivityId later.
+ ActivityCorrelator.setCurrentActivityIdSentFlag(); // set the activityid flag so that we don't send the current
+ // ActivityId later.
}
- public SQLServerException(String errText,
- Throwable cause) {
+ SQLServerException(String errText, Throwable cause) {
super(errText);
initCause(cause);
logException(null, errText, true);
ActivityCorrelator.setCurrentActivityIdSentFlag();
}
- /* L0 */ public SQLServerException(Object obj,
- String errText,
- String errState,
- int errNum,
- boolean bStack) {
+ SQLServerException(Object obj, String errText, String errState, int errNum, boolean bStack) {
super(errText, errState, errNum);
logException(obj, errText, bStack);
ActivityCorrelator.setCurrentActivityIdSentFlag();
}
/**
- * Make a new SQLException
+ * Constructs a new SQLServerException.
*
* @param obj
- * the object
+ * the object
* @param errText
- * the exception message
+ * the exception message
* @param errState
- * the exception state
+ * the exception state
* @param streamError
- * the StreamError object
+ * the StreamError object
* @param bStack
- * true to generate the stack trace
+ * true to generate the stack trace
*/
- /* L0 */ public SQLServerException(Object obj,
- String errText,
- String errState,
- StreamError streamError,
- boolean bStack) {
+ SQLServerException(Object obj, String errText, String errState, StreamError streamError, boolean bStack) {
super(errText, errState, streamError.getErrorNumber());
// Log SQL error with info from StreamError.
- errText = "Msg " + streamError.getErrorNumber() + ", Level " + streamError.getErrorSeverity() + ", State " + streamError.getErrorState()
- + ", " + errText;
+ errText = "Msg " + streamError.getErrorNumber() + ", Level " + streamError.getErrorSeverity() + ", State "
+ + streamError.getErrorState() + ", " + errText;
logException(obj, errText, bStack);
}
/**
- * Build a new SQL Exception from an error detected by the driver.
+ * Constructs a SQLServerException from an error detected by the driver.
*
* @param con
- * the connection
+ * the connection
* @param obj
* @param errText
- * the excception message
+ * the excception message
* @param state
- * he excpeption state
+ * he excpeption state
* @param bStack
- * true to generate the stack trace
+ * true to generate the stack trace
* @throws SQLServerException
*/
- /* L0 */static void makeFromDriverError(SQLServerConnection con,
- Object obj,
- String errText,
- String state,
+ static void makeFromDriverError(SQLServerConnection con, Object obj, String errText, String state,
boolean bStack) throws SQLServerException {
// The sql error code is 0 since the error was not returned from the database
// The state code is supplied by the calling code as XOPEN compliant.
@@ -237,8 +222,8 @@ public SQLServerException(String errText,
if (con == null || !con.xopenStates)
stateCode = mapFromXopen(state);
- SQLServerException theException = new SQLServerException(obj, SQLServerException.checkAndAppendClientConnId(errText, con), stateCode, 0,
- bStack);
+ SQLServerException theException = new SQLServerException(obj,
+ SQLServerException.checkAndAppendClientConnId(errText, con), stateCode, 0, bStack);
if ((null != state && state.equals(EXCEPTION_XOPEN_CONNECTION_FAILURE)) && (null != con)) {
con.notifyPooledConnection(theException);
// note this close wont close the connection if there is an associated pooled connection.
@@ -249,27 +234,24 @@ public SQLServerException(String errText,
}
/**
- * Build a new SQL Exception from a streamError detected by the driver.
+ * Builds a new SQL Exception from a streamError detected by the driver.
*
* @param con
- * the connection
+ * the connection
* @param obj
* @param errText
- * the excception message
+ * the excception message
* @param streamError
* @param bStack
- * true to generate the stack trace
+ * true to generate the stack trace
* @throws SQLServerException
*/
- /* L0 */ static void makeFromDatabaseError(SQLServerConnection con,
- Object obj,
- String errText,
- StreamError streamError,
+ static void makeFromDatabaseError(SQLServerConnection con, Object obj, String errText, StreamError streamError,
boolean bStack) throws SQLServerException {
String state = generateStateCode(con, streamError.getErrorNumber(), streamError.getErrorState());
- SQLServerException theException = new SQLServerException(obj, SQLServerException.checkAndAppendClientConnId(errText, con), state, streamError,
- bStack);
+ SQLServerException theException = new SQLServerException(obj,
+ SQLServerException.checkAndAppendClientConnId(errText, con), state, streamError, bStack);
theException.setDriverErrorCode(DRIVER_ERROR_FROM_DATABASE);
// Close the connection if we get a severity 20 or higher error class (nClass is severity of error).
@@ -282,9 +264,7 @@ public SQLServerException(String errText,
}
// This code is same as the conversion logic that previously existed in connecthelper.
- static void ConvertConnectExceptionToSQLServerException(String hostName,
- int portNumber,
- SQLServerConnection conn,
+ static void ConvertConnectExceptionToSQLServerException(String hostName, int portNumber, SQLServerConnection conn,
Exception ex) throws SQLServerException {
Exception connectException = ex;
// Throw the exception if exception was caught by code above (stored in connectException).
@@ -294,18 +274,19 @@ static void ConvertConnectExceptionToSQLServerException(String hostName,
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_tcpipConnectionFailed"));
Object[] msgArgs = {hostName, Integer.toString(portNumber), formDetail.format(msgArgsDetail)};
String s = form.format(msgArgs);
- SQLServerException.makeFromDriverError(conn, conn, s, SQLServerException.EXCEPTION_XOPEN_CONNECTION_CANT_ESTABLISH, false);
+ SQLServerException.makeFromDriverError(conn, conn, s,
+ SQLServerException.EXCEPTION_XOPEN_CONNECTION_CANT_ESTABLISH, false);
}
}
/**
- * Map XOPEN states.
+ * Maps XOPEN states.
*
* @param state
- * the state
+ * the state
* @return the mapped state
*/
- /* L0 */ static String mapFromXopen(String state) {
+ static String mapFromXopen(String state) {
// Exceptions generated by the driver (not the database) are instanced with an XOPEN state code
// since the SQL99 states cant be located on the web (must pay) and the XOPEN states appear to
// be specific. Therefore if the driver is in SQL 99 mode we must map to SQL 99 state codes.
@@ -328,19 +309,17 @@ static void ConvertConnectExceptionToSQLServerException(String hostName,
}
/**
- * Generate the JDBC state code based on the error number returned from the database
+ * Generates the JDBC state code based on the error number returned from the database.
*
* @param con
- * the connection
+ * the connection
* @param errNum
- * the error number
+ * the error number
* @param databaseState
- * the database state
+ * the database state
* @return the state code
*/
- /* L0 */ static String generateStateCode(SQLServerConnection con,
- int errNum,
- int databaseState) {
+ static String generateStateCode(SQLServerConnection con, int errNum, int databaseState) {
// Generate a SQL 99 or XOPEN state from a database generated error code
boolean xopenStates = (con != null && con.xopenStates);
if (xopenStates) {
@@ -359,21 +338,20 @@ static void ConvertConnectExceptionToSQLServerException(String hostName,
}
return "42000"; // Use XOPEN 'Syntax error or access violation'
// The error code came from the db but XOPEN does not have a specific case for it.
- }
- else {
+ } else {
switch (errNum) {
// case 18456: return "08001"; //username password wrong at login
case 8152:
return "22001"; // String data right truncation
case 515: // 2.2705
case 547:
- return "23000"; // Integrity constraint violation
+ return "23000"; // Integrity constraint violation
case 2601:
- return "23000"; // Integrity constraint violation
+ return "23000"; // Integrity constraint violation
case 2714:
return "S0001"; // table already exists
case 208:
- return "S0002"; // table not found
+ return "S0002"; // table not found
case 1205:
return "40001"; // deadlock detected
case 2627:
@@ -384,16 +362,16 @@ static void ConvertConnectExceptionToSQLServerException(String hostName,
}
/**
- * Append ClientConnectionId to an error message if applicable
+ * Appends ClientConnectionId to an error message if applicable.
*
* @param errMsg
- * - the orginal error message.
+ * - the orginal error message.
* @param conn
- * - the SQLServerConnection object
- * @return error string concated by ClientConnectionId(in string format) if applicable, otherwise, return original error string.
+ * - the SQLServerConnection object
+ * @return error string concated by ClientConnectionId(in string format) if applicable, otherwise, return original
+ * error string.
*/
- static String checkAndAppendClientConnId(String errMsg,
- SQLServerConnection conn) throws SQLServerException {
+ static String checkAndAppendClientConnId(String errMsg, SQLServerConnection conn) throws SQLServerException {
if (null != conn && conn.attachConnId()) {
UUID clientConnId = conn.getClientConIdInternal();
assert null != clientConnId;
@@ -403,16 +381,16 @@ static String checkAndAppendClientConnId(String errMsg,
sb.append(LOG_CLIENT_CONNECTION_ID_PREFIX);
sb.append(clientConnId.toString());
return sb.toString();
- }
- else {
+ } else {
return errMsg;
}
}
static void throwNotSupportedException(SQLServerConnection con, Object obj) throws SQLServerException {
- SQLServerException.makeFromDriverError(con, obj, SQLServerException.getErrString("R_notSupported"), null, false);
+ SQLServerException.makeFromDriverError(con, obj, SQLServerException.getErrString("R_notSupported"), null,
+ false);
}
-
+
static void throwFeatureNotSupportedException() throws SQLFeatureNotSupportedException {
throw new SQLFeatureNotSupportedException(SQLServerException.getErrString("R_notSupported"));
}
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerJdbc43.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerJdbc43.java
index 1100f132d..4c7f2db6f 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerJdbc43.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerJdbc43.java
@@ -1,20 +1,18 @@
/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc;
import java.sql.BatchUpdateException;
+
/**
* Shims for JDBC 4.3 JAR.
*
- * JDBC 4.3 public methods should always check the SQLServerJdbcVersion first to make sure that they are not operable in any earlier driver version.
- * That is, they should throw an exception, be a no-op, or whatever.
+ * JDBC 4.3 public methods should always check the SQLServerJdbcVersion first to make sure that they are not operable in
+ * any earlier driver version. That is, they should throw an exception, be a no-op, or whatever.
*/
final class DriverJDBCVersion {
@@ -22,12 +20,11 @@ final class DriverJDBCVersion {
static final int major = 4;
static final int minor = 3;
- static final void checkSupportsJDBC43() {
- }
+ static final void checkSupportsJDBC43() {}
static final void throwBatchUpdateException(SQLServerException lastError,
long[] updateCounts) throws BatchUpdateException {
- throw new BatchUpdateException(lastError.getMessage(), lastError.getSQLState(), lastError.getErrorCode(), updateCounts,
- new Throwable(lastError.getMessage()));
+ throw new BatchUpdateException(lastError.getMessage(), lastError.getSQLState(), lastError.getErrorCode(),
+ updateCounts, new Throwable(lastError.getMessage()));
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerKeyVaultAuthenticationCallback.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerKeyVaultAuthenticationCallback.java
index dc4bddda1..daa475b99 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerKeyVaultAuthenticationCallback.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerKeyVaultAuthenticationCallback.java
@@ -1,27 +1,26 @@
/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc;
+/**
+ * Provides a callback delegate which is to be implemented by the client code
+ *
+ */
public interface SQLServerKeyVaultAuthenticationCallback {
/**
- * The authentication callback delegate which is to be implemented by the client code
+ * Returns the acesss token of the authentication request
*
* @param authority
- * - Identifier of the authority, a URL.
+ * - Identifier of the authority, a URL.
* @param resource
- * - Identifier of the target resource that is the recipient of the requested token, a URL.
+ * - Identifier of the target resource that is the recipient of the requested token, a URL.
* @param scope
- * - The scope of the authentication request.
+ * - The scope of the authentication request.
* @return access token
*/
- public String getAccessToken(String authority,
- String resource,
- String scope);
-}
\ No newline at end of file
+ public String getAccessToken(String authority, String resource, String scope);
+}
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerLob.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerLob.java
index 1849915be..0fdee293d 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerLob.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerLob.java
@@ -1,18 +1,16 @@
/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc;
import java.sql.SQLException;
+
abstract class SQLServerLob {
/**
- * Function for the result set to maintain blobs it has created
+ * Provides functionality for the result set to maintain blobs it has created.
*
* @throws SQLException
*/
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerMetaData.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerMetaData.java
index 00614ff8b..da9db54b7 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerMetaData.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerMetaData.java
@@ -1,202 +1,203 @@
-/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
- */
-
-package com.microsoft.sqlserver.jdbc;
-
-import java.text.MessageFormat;
-
-/**
- *
- * This class represents metadata for a column. It is used in the ISQLServerDataRecord interface to pass column metadata to the table-valued
- * parameter.
- *
- */
-public class SQLServerMetaData {
-
- String columnName = null;
- int javaSqlType;
- int precision = 0;
- int scale = 0;
- boolean useServerDefault = false;
- boolean isUniqueKey = false;
- SQLServerSortOrder sortOrder = SQLServerSortOrder.Unspecified;
- int sortOrdinal;
- private SQLCollation collation;
-
- static final int defaultSortOrdinal = -1;
-
- /**
- * Creates a new SQLServerMetaData
- *
- * @param columnName
- * the name of the column
- * @param sqlType
- * the SQL type of the column
- */
- public SQLServerMetaData(String columnName,
- int sqlType) {
- this.columnName = columnName;
- this.javaSqlType = sqlType;
- }
-
- /**
- * creates a new SQLServerMetaData
- *
- * @param columnName
- * the name of the column
- * @param sqlType
- * the SQL type of the column
- * @param precision
- * the precision of the column
- * @param scale
- * the scale of the column
- */
- public SQLServerMetaData(String columnName,
- int sqlType,
- int precision,
- int scale) {
- this.columnName = columnName;
- this.javaSqlType = sqlType;
- this.precision = precision;
- this.scale = scale;
- }
-
- /**
- * Creates a new SQLServerMetaData
- *
- * @param columnName
- * the name of the column
- * @param sqlType
- * the sql type of the column
- * @param precision
- * the precision of the column
- * @param scale
- * the scale of the column
- * @param useServerDefault
- * specifies if this column should use the default server value; Default value is false.
- * @param isUniqueKey
- * indicates if the column in the table-valued parameter is unique; Default value is false.
- * @param sortOrder
- * indicates the sort order for a column; Default value is SQLServerSortOrder.Unspecified.
- * @param sortOrdinal
- * specifies ordinal of the sort column; sortOrdinal starts from 0; Default value is -1.
- * @throws SQLServerException
- * when an error occurs
- */
- public SQLServerMetaData(String columnName,
- int sqlType,
- int precision,
- int scale,
- boolean useServerDefault,
- boolean isUniqueKey,
- SQLServerSortOrder sortOrder,
- int sortOrdinal) throws SQLServerException {
- this.columnName = columnName;
- this.javaSqlType = sqlType;
- this.precision = precision;
- this.scale = scale;
- this.useServerDefault = useServerDefault;
- this.isUniqueKey = isUniqueKey;
- this.sortOrder = sortOrder;
- this.sortOrdinal = sortOrdinal;
- validateSortOrder();
- }
-
- /**
- * Initializes a new instance of SQLServerMetaData from another SQLServerMetaData object.
- *
- * @param sqlServerMetaData
- * the object passed to initialize a new instance of SQLServerMetaData
- */
- public SQLServerMetaData(SQLServerMetaData sqlServerMetaData) {
- this.columnName = sqlServerMetaData.columnName;
- this.javaSqlType = sqlServerMetaData.javaSqlType;
- this.precision = sqlServerMetaData.precision;
- this.scale = sqlServerMetaData.scale;
- this.useServerDefault = sqlServerMetaData.useServerDefault;
- this.isUniqueKey = sqlServerMetaData.isUniqueKey;
- this.sortOrder = sqlServerMetaData.sortOrder;
- this.sortOrdinal = sqlServerMetaData.sortOrdinal;
- }
-
- /**
- *
- * @return Retrieves the column name.
- */
- public String getColumName() {
- return columnName;
- }
-
- /**
- *
- * @return Retrieves the java sql type.
- */
- public int getSqlType() {
- return javaSqlType;
- }
-
- /**
- *
- * @return retrieves the precision of the type passed to the column.
- */
- public int getPrecision() {
- return precision;
- }
-
- /**
- *
- * @return retrieves the scale of the type passed to the column.
- */
- public int getScale() {
- return scale;
- }
-
- /**
- *
- * @return returns whether the column uses the default server value.
- */
- public boolean useServerDefault() {
- return useServerDefault;
- }
-
- /**
- *
- * @return retrieves the whether the column is unique.
- */
- public boolean isUniqueKey() {
- return isUniqueKey;
- }
-
- /**
- *
- * @return retrieves the sort order.
- */
- public SQLServerSortOrder getSortOrder() {
- return sortOrder;
- }
-
- /**
- *
- * @return retrieves the sort ordinal.
- */
- public int getSortOrdinal() {
- return sortOrdinal;
- }
-
- SQLCollation getCollation() {
- return this.collation;
- }
-
- void validateSortOrder() throws SQLServerException {
- // should specify both sort order and ordinal, or neither
- if ((SQLServerSortOrder.Unspecified == sortOrder) != (defaultSortOrdinal == sortOrdinal)) {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_TVPMissingSortOrderOrOrdinal"));
- throw new SQLServerException(form.format(new Object[] {sortOrder, sortOrdinal}), null, 0, null);
- }
- }
-}
+/*
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ */
+
+package com.microsoft.sqlserver.jdbc;
+
+import java.text.MessageFormat;
+
+
+/**
+ *
+ * Represents metadata for a column. It is used in the ISQLServerDataRecord interface to pass column metadata to the
+ * table-valued parameter.
+ *
+ */
+public class SQLServerMetaData {
+
+ String columnName = null;
+ int javaSqlType;
+ int precision = 0;
+ int scale = 0;
+ boolean useServerDefault = false;
+ boolean isUniqueKey = false;
+ SQLServerSortOrder sortOrder = SQLServerSortOrder.Unspecified;
+ int sortOrdinal;
+ private SQLCollation collation;
+
+ static final int defaultSortOrdinal = -1;
+
+ /**
+ * Constructs a SQLServerMetaData with the column name and SQL type.
+ *
+ * @param columnName
+ * the name of the column
+ * @param sqlType
+ * the SQL type of the column
+ */
+ public SQLServerMetaData(String columnName, int sqlType) {
+ this.columnName = columnName;
+ this.javaSqlType = sqlType;
+ }
+
+ /**
+ * Constructs a SQLServerMetaData with the column name, SQL type, precision, and scale.
+ *
+ * @param columnName
+ * the name of the column
+ * @param sqlType
+ * the SQL type of the column
+ * @param precision
+ * the precision of the column
+ * @param scale
+ * the scale of the column
+ */
+ public SQLServerMetaData(String columnName, int sqlType, int precision, int scale) {
+ this.columnName = columnName;
+ this.javaSqlType = sqlType;
+ this.precision = precision;
+ this.scale = scale;
+ }
+
+ /**
+ * Constructs a SQLServerMetaData.
+ *
+ * @param columnName
+ * the name of the column
+ * @param sqlType
+ * the sql type of the column
+ * @param precision
+ * the precision of the column
+ * @param scale
+ * the scale of the column
+ * @param useServerDefault
+ * specifies if this column should use the default server value; Default value is false.
+ * @param isUniqueKey
+ * indicates if the column in the table-valued parameter is unique; Default value is false.
+ * @param sortOrder
+ * indicates the sort order for a column; Default value is SQLServerSortOrder.Unspecified.
+ * @param sortOrdinal
+ * specifies ordinal of the sort column; sortOrdinal starts from 0; Default value is -1.
+ * @throws SQLServerException
+ * when an error occurs
+ */
+ public SQLServerMetaData(String columnName, int sqlType, int precision, int scale, boolean useServerDefault,
+ boolean isUniqueKey, SQLServerSortOrder sortOrder, int sortOrdinal) throws SQLServerException {
+ this.columnName = columnName;
+ this.javaSqlType = sqlType;
+ this.precision = precision;
+ this.scale = scale;
+ this.useServerDefault = useServerDefault;
+ this.isUniqueKey = isUniqueKey;
+ this.sortOrder = sortOrder;
+ this.sortOrdinal = sortOrdinal;
+ validateSortOrder();
+ }
+
+ /**
+ * Constructs a SQLServerMetaData from another SQLServerMetaData object.
+ *
+ * @param sqlServerMetaData
+ * the object passed to initialize a new instance of SQLServerMetaData
+ */
+ public SQLServerMetaData(SQLServerMetaData sqlServerMetaData) {
+ this.columnName = sqlServerMetaData.columnName;
+ this.javaSqlType = sqlServerMetaData.javaSqlType;
+ this.precision = sqlServerMetaData.precision;
+ this.scale = sqlServerMetaData.scale;
+ this.useServerDefault = sqlServerMetaData.useServerDefault;
+ this.isUniqueKey = sqlServerMetaData.isUniqueKey;
+ this.sortOrder = sqlServerMetaData.sortOrder;
+ this.sortOrdinal = sqlServerMetaData.sortOrdinal;
+ }
+
+ /**
+ * Returns the column name.
+ *
+ * @return column name
+ */
+ public String getColumName() {
+ return columnName;
+ }
+
+ /**
+ * Returns the java sql type.
+ *
+ * @return java sql type
+ */
+ public int getSqlType() {
+ return javaSqlType;
+ }
+
+ /**
+ * Returns the precision of the type passed to the column.
+ *
+ * @return precision
+ */
+ public int getPrecision() {
+ return precision;
+ }
+
+ /**
+ * Returns the scale of the type passed to the column.
+ *
+ * @return scale
+ */
+ public int getScale() {
+ return scale;
+ }
+
+ /**
+ * Returns whether the column uses the default server value.
+ *
+ * @return whether the column uses the default server value.
+ */
+ public boolean useServerDefault() {
+ return useServerDefault;
+ }
+
+ /**
+ * Returns whether the column is unique.
+ *
+ * @return whether the column is unique.
+ */
+ public boolean isUniqueKey() {
+ return isUniqueKey;
+ }
+
+ /**
+ * Returns the sort order.
+ *
+ * @return sort order
+ */
+ public SQLServerSortOrder getSortOrder() {
+ return sortOrder;
+ }
+
+ /**
+ * Returns the sort ordinal.
+ *
+ * @return sort ordinal
+ */
+ public int getSortOrdinal() {
+ return sortOrdinal;
+ }
+
+ /**
+ * Returns the collation.
+ *
+ * @return SQL collation
+ */
+ SQLCollation getCollation() {
+ return this.collation;
+ }
+
+ void validateSortOrder() throws SQLServerException {
+ // should specify both sort order and ordinal, or neither
+ if ((SQLServerSortOrder.Unspecified == sortOrder) != (defaultSortOrdinal == sortOrdinal)) {
+ MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_TVPMissingSortOrderOrOrdinal"));
+ throw new SQLServerException(form.format(new Object[] {sortOrder, sortOrdinal}), null, 0, null);
+ }
+ }
+}
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerNClob.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerNClob.java
index f3930381c..dfa9fb12d 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerNClob.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerNClob.java
@@ -1,9 +1,6 @@
/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc;
@@ -18,10 +15,10 @@
import java.sql.SQLException;
import java.util.logging.Logger;
+
/**
- * SQLServerNClob represents a National Character Set LOB object and implements java.sql.NClob.
+ * Represents a National Character Set LOB object and implements java.sql.NClob.
*/
-
public final class SQLServerNClob extends SQLServerClobBase implements NClob {
/**
@@ -37,8 +34,7 @@ public final class SQLServerNClob extends SQLServerClobBase implements NClob {
super(connection, "", connection.getDatabaseCollation(), logger, null);
}
- SQLServerNClob(BaseInputStream stream,
- TypeInfo typeInfo) throws SQLServerException, UnsupportedEncodingException {
+ SQLServerNClob(BaseInputStream stream, TypeInfo typeInfo) throws SQLServerException, UnsupportedEncodingException {
super(null, stream, typeInfo.getSQLCollation(), logger, typeInfo);
}
@@ -58,14 +54,12 @@ public Reader getCharacterStream() throws SQLException {
}
@Override
- public Reader getCharacterStream(long pos,
- long length) throws SQLException {
+ public Reader getCharacterStream(long pos, long length) throws SQLException {
return super.getCharacterStream(pos, length);
}
@Override
- public String getSubString(long pos,
- int length) throws SQLException {
+ public String getSubString(long pos, int length) throws SQLException {
return super.getSubString(pos, length);
}
@@ -80,14 +74,12 @@ void fillFromStream() throws SQLException {
}
@Override
- public long position(Clob searchstr,
- long start) throws SQLException {
+ public long position(Clob searchstr, long start) throws SQLException {
return super.position(searchstr, start);
}
@Override
- public long position(String searchstr,
- long start) throws SQLException {
+ public long position(String searchstr, long start) throws SQLException {
return super.position(searchstr, start);
}
@@ -107,16 +99,12 @@ public Writer setCharacterStream(long pos) throws SQLException {
}
@Override
- public int setString(long pos,
- String s) throws SQLException {
+ public int setString(long pos, String s) throws SQLException {
return super.setString(pos, s);
}
@Override
- public int setString(long pos,
- String str,
- int offset,
- int len) throws SQLException {
+ public int setString(long pos, String str, int offset, int len) throws SQLException {
return super.setString(pos, str, offset, len);
}
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerParameterMetaData.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerParameterMetaData.java
index f9ebd3b1c..49cf07a34 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerParameterMetaData.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerParameterMetaData.java
@@ -1,15 +1,11 @@
/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc;
import java.sql.ParameterMetaData;
-import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
@@ -23,14 +19,15 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+
/**
- * SQLServerParameterMetaData provides JDBC 3.0 meta data for prepared statement parameters.
+ * Provides meta data for prepared statement parameters.
*
- * The API javadoc for JDBC API methods that this class implements are not repeated here. Please see Sun's JDBC API interfaces javadoc for those
- * details.
+ * The API javadoc for JDBC API methods that this class implements are not repeated here. Please see Sun's JDBC API
+ * interfaces javadoc for those details.
*
- * Prepared statements are executed with SET FMT ONLY to retrieve column meta data Callable statements : sp_sp_sproc_columns is called to retrieve
- * names and meta data for the procedures params.
+ * Prepared statements are executed with SET FMT ONLY to retrieve column meta data Callable statements :
+ * sp_sp_sproc_columns is called to retrieve names and meta data for the procedures params.
*/
public final class SQLServerParameterMetaData implements ParameterMetaData {
@@ -43,16 +40,17 @@ public final class SQLServerParameterMetaData implements ParameterMetaData {
/* Used for callable statement meta data */
private Statement stmtCall;
private SQLServerResultSet rsProcedureMeta;
-
+
protected boolean procedureIsFound = false;
static final private java.util.logging.Logger logger = java.util.logging.Logger
.getLogger("com.microsoft.sqlserver.jdbc.internals.SQLServerParameterMetaData");
- static private final AtomicInteger baseID = new AtomicInteger(0); // Unique id generator for each instance (used for logging).
+ static private final AtomicInteger baseID = new AtomicInteger(0); // Unique id generator for each instance (used for
+ // logging).
final private String traceID = " SQLServerParameterMetaData:" + nextInstanceID();
boolean isTVP = false;
-
+
private String stringToParse = null;
private int indexToBeginParse = -1;
@@ -62,7 +60,7 @@ private static int nextInstanceID() {
}
/**
- * This is a helper function to provide an ID string suitable for tracing.
+ * Provides a helper function to provide an ID string suitable for tracing.
*
* @return traceID string
*/
@@ -72,16 +70,15 @@ final public String toString() {
}
/**
- * Parse the columns in a column set.
+ * Parses the columns in a column set.
*
* @param columnSet
- * the list of columns
+ * the list of columns
* @param columnStartToken
- * the token that prfixes the column set
- * @throws SQLServerException
+ * the token that prfixes the column set
+ * @throws SQLServerException
*/
- private String parseColumns(String columnSet,
- String columnStartToken) throws SQLServerException {
+ private String parseColumns(String columnSet, String columnStartToken) throws SQLServerException {
StringTokenizer st = new StringTokenizer(columnSet, " =?<>!\r\n\t\f", true);
final int START = 0;
final int PARAMNAME = 1;
@@ -96,16 +93,16 @@ private String parseColumns(String columnSet,
String sToken = st.nextToken();
sTokenIndex = sTokenIndex + sToken.length();
-
+
if (sToken.equalsIgnoreCase(columnStartToken)) {
nState = PARAMNAME;
continue;
}
if (nState == START)
continue;
- if ((sToken.charAt(0) == '=') || sToken.equalsIgnoreCase("is") || (sToken.charAt(0) == '<') || (sToken.charAt(0) == '>')
- || sToken.equalsIgnoreCase("like") || sToken.equalsIgnoreCase("not") || sToken.equalsIgnoreCase("in")
- || (sToken.charAt(0) == '!')) {
+ if ((sToken.charAt(0) == '=') || sToken.equalsIgnoreCase("is") || (sToken.charAt(0) == '<')
+ || (sToken.charAt(0) == '>') || sToken.equalsIgnoreCase("like") || sToken.equalsIgnoreCase("not")
+ || sToken.equalsIgnoreCase("in") || (sToken.charAt(0) == '!')) {
nState = PARAMVALUE;
continue;
}
@@ -134,16 +131,15 @@ private String parseColumns(String columnSet,
}
/**
- * Parse the column set in an insert syntax.
+ * Parses the column set in an insert syntax.
*
* @param sql
- * the sql syntax
+ * the sql syntax
* @param columnMarker
- * the token that denotes the start of the column set
- * @throws SQLServerException
+ * the token that denotes the start of the column set
+ * @throws SQLServerException
*/
- private String parseInsertColumns(String sql,
- String columnMarker) throws SQLServerException {
+ private String parseInsertColumns(String sql, String columnMarker) throws SQLServerException {
StringTokenizer st = new StringTokenizer(sql, " (),", true);
int nState = 0;
String sLastField = null;
@@ -153,7 +149,7 @@ private String parseInsertColumns(String sql,
while (st.hasMoreTokens()) {
String sToken = st.nextToken();
sTokenIndex = sTokenIndex + sToken.length();
-
+
if (sToken.equalsIgnoreCase(columnMarker)) {
nState = 1;
continue;
@@ -180,7 +176,8 @@ private String parseInsertColumns(String sql,
if (sToken.charAt(0) != ',') {
sLastField = escapeParse(st, sToken);
- // in case the parameter has braces in its name, e.g. [c2_nvarchar(max)], the original sToken variable just
+ // in case the parameter has braces in its name, e.g. [c2_nvarchar(max)], the original sToken
+ // variable just
// contains [c2_nvarchar, sLastField actually has the whole name [c2_nvarchar(max)]
sTokenIndex = sTokenIndex + (sLastField.length() - sToken.length());
}
@@ -206,7 +203,7 @@ class QueryMeta {
Map queryMetaMap = null;
/*
- * Parse query metadata.
+ * Parses query metadata.
*/
private void parseQueryMeta(ResultSet rsQueryMeta) throws SQLServerException {
Pattern datatypePattern = Pattern.compile("(.*)\\((.*)(\\)|,(.*)\\))");
@@ -220,8 +217,8 @@ private void parseQueryMeta(ResultSet rsQueryMeta) throws SQLServerException {
if (null == typename) {
typename = rsQueryMeta.getString("suggested_user_type_name");
- SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) con
- .prepareCall("select max_length, precision, scale, is_nullable from sys.assembly_types where name = ?");
+ SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) con.prepareCall(
+ "select max_length, precision, scale, is_nullable from sys.assembly_types where name = ?");
pstmt.setNString(1, typename);
ResultSet assemblyRs = pstmt.executeQuery();
if (assemblyRs.next()) {
@@ -230,8 +227,7 @@ private void parseQueryMeta(ResultSet rsQueryMeta) throws SQLServerException {
qm.scale = assemblyRs.getInt("scale");
ssType = SSType.UDT;
}
- }
- else {
+ } else {
qm.precision = rsQueryMeta.getInt("suggested_precision");
qm.scale = rsQueryMeta.getInt("suggested_scale");
@@ -241,24 +237,24 @@ private void parseQueryMeta(ResultSet rsQueryMeta) throws SQLServerException {
ssType = SSType.of(matcher.group(1));
if (typename.equalsIgnoreCase("varchar(max)") || typename.equalsIgnoreCase("varbinary(max)")) {
qm.precision = SQLServerDatabaseMetaData.MAXLOBSIZE;
- }
- else if (typename.equalsIgnoreCase("nvarchar(max)")) {
+ } else if (typename.equalsIgnoreCase("nvarchar(max)")) {
qm.precision = SQLServerDatabaseMetaData.MAXLOBSIZE / 2;
- }
- else if (SSType.Category.CHARACTER == ssType.category || SSType.Category.BINARY == ssType.category
+ } else if (SSType.Category.CHARACTER == ssType.category
+ || SSType.Category.BINARY == ssType.category
|| SSType.Category.NCHARACTER == ssType.category) {
try {
- // For character/binary data types "suggested_precision" is 0. So get the precision from the type itself.
+ // For character/binary data types "suggested_precision" is 0. So get the precision from
+ // the type itself.
qm.precision = Integer.parseInt(matcher.group(2));
- }
- catch (NumberFormatException e) {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_metaDataErrorForParameter"));
+ } catch (NumberFormatException e) {
+ MessageFormat form = new MessageFormat(
+ SQLServerException.getErrString("R_metaDataErrorForParameter"));
Object[] msgArgs = {paramOrdinal};
- SQLServerException.makeFromDriverError(con, stmtParent, form.format(msgArgs) + " " + e.toString(), null, false);
+ SQLServerException.makeFromDriverError(con, stmtParent,
+ form.format(msgArgs) + " " + e.toString(), null, false);
}
}
- }
- else
+ } else
ssType = SSType.of(typename);
// For float and real types suggested_precision returns the number of bits, not digits.
@@ -266,26 +262,19 @@ else if (SSType.Category.CHARACTER == ssType.category || SSType.Category.BINARY
// https://msdn.microsoft.com/en-CA/library/ms173773.aspx
// real is float(24) and is 7 digits. Float is 15 digits.
qm.precision = 15;
- }
- else if (SSType.REAL == ssType) {
+ } else if (SSType.REAL == ssType) {
qm.precision = 7;
- }
- else if (SSType.TEXT == ssType) {
+ } else if (SSType.TEXT == ssType) {
qm.precision = SQLServerDatabaseMetaData.MAXLOBSIZE;
- }
- else if (SSType.NTEXT == ssType) {
+ } else if (SSType.NTEXT == ssType) {
qm.precision = SQLServerDatabaseMetaData.MAXLOBSIZE / 2;
- }
- else if (SSType.IMAGE == ssType) {
+ } else if (SSType.IMAGE == ssType) {
qm.precision = SQLServerDatabaseMetaData.MAXLOBSIZE;
- }
- else if (SSType.GUID == ssType) {
+ } else if (SSType.GUID == ssType) {
qm.precision = SQLServerDatabaseMetaData.uniqueidentifierSize;
- }
- else if (SSType.TIMESTAMP == ssType) {
+ } else if (SSType.TIMESTAMP == ssType) {
qm.precision = 8;
- }
- else if (SSType.XML == ssType) {
+ } else if (SSType.XML == ssType) {
qm.precision = SQLServerDatabaseMetaData.MAXLOBSIZE / 2;
}
@@ -301,11 +290,11 @@ else if (SSType.XML == ssType) {
qm.parameterClassName = jdbcType.className();
qm.parameterType = jdbcType.getIntValue();
// The parameter can be signed if it is a NUMERIC type (except bit or tinyint).
- qm.isSigned = ((SSType.Category.NUMERIC == ssType.category) && (SSType.BIT != ssType) && (SSType.TINYINT != ssType));
+ qm.isSigned = ((SSType.Category.NUMERIC == ssType.category) && (SSType.BIT != ssType)
+ && (SSType.TINYINT != ssType));
queryMetaMap.put(paramOrdinal, qm);
}
- }
- catch (SQLException e) {
+ } catch (SQLException e) {
throw new SQLServerException(SQLServerException.getErrString("R_metaDataErrorForParameter"), e);
}
}
@@ -330,23 +319,21 @@ private void parseQueryMetaFor2008(ResultSet rsQueryMeta) throws SQLServerExcept
queryMetaMap.put(i, qm);
}
- }
- catch (SQLException e) {
+ } catch (SQLException e) {
throw new SQLServerException(SQLServerException.getErrString("R_metaDataErrorForParameter"), e);
}
}
/**
- * Escape parser, using the tokenizer tokenizes escaped strings properly e.g.[Table Name, ]
+ * Parses escaped strings properly e.g.[Table Name, ] using tokenizer.
*
* @param st
- * string tokenizer
+ * string tokenizer
* @param firstToken
* @throws SQLServerException
* @returns the full token
*/
- private String escapeParse(StringTokenizer st,
- String firstToken) throws SQLServerException {
+ private String escapeParse(StringTokenizer st, String firstToken) throws SQLServerException {
if (null == firstToken) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_NullValue"));
@@ -378,24 +365,22 @@ private class MetaInfo {
String table;
String fields;
- MetaInfo(String table,
- String fields) {
+ MetaInfo(String table, String fields) {
this.table = table;
this.fields = fields;
}
}
/**
- * Parse a SQL syntax.
+ * Parses a SQL syntax.
*
* @param sql
- * String
+ * String
* @param sTableMarker
- * the location of the table in the syntax
- * @throws SQLServerException
+ * the location of the table in the syntax
+ * @throws SQLServerException
*/
- private MetaInfo parseStatement(String sql,
- String sTableMarker) throws SQLServerException {
+ private MetaInfo parseStatement(String sql, String sTableMarker) throws SQLServerException {
StringTokenizer st = new StringTokenizer(sql, " ,\r\n\t\f(", true);
/* Find the table */
@@ -405,7 +390,7 @@ private MetaInfo parseStatement(String sql,
while (st.hasMoreTokens()) {
String sToken = st.nextToken().trim();
- if(sToken.contains("*/")){
+ if (sToken.contains("*/")) {
sToken = removeCommentsInTheBeginning(sToken, 0, 0, "/*", "*/");
}
@@ -421,8 +406,7 @@ private MetaInfo parseStatement(String sql,
if (sTableMarker.equalsIgnoreCase("UPDATE")) {
metaFields = parseColumns(sql, "SET"); // Get the set fields
stringToParse = "";
- }
- else if (sTableMarker.equalsIgnoreCase("INTO")) { // insert
+ } else if (sTableMarker.equalsIgnoreCase("INTO")) { // insert
metaFields = parseInsertColumns(sql, "("); // Get the value fields
stringToParse = sql.substring(indexToBeginParse); // the index of ')'
@@ -431,8 +415,7 @@ else if (sTableMarker.equalsIgnoreCase("INTO")) { // insert
parseInsertColumns(stringToParse, "(");
stringToParse = stringToParse.substring(indexToBeginParse); // the index of ')'
}
- }
- else {
+ } else {
metaFields = parseColumns(sql, "WHERE"); // Get the where fields
stringToParse = "";
}
@@ -444,10 +427,10 @@ else if (sTableMarker.equalsIgnoreCase("INTO")) { // insert
}
/**
- * Parse a SQL syntax.
+ * Parses a SQL syntax.
*
* @param sql
- * the syntax
+ * the syntax
* @throws SQLServerException
*/
private MetaInfo parseStatement(String sql) throws SQLServerException {
@@ -482,12 +465,9 @@ private MetaInfo parseStatement(String sql) throws SQLServerException {
return null;
}
-
- private String removeCommentsInTheBeginning(String sql,
- int startCommentMarkCount,
- int endCommentMarkCount,
- String startMark,
- String endMark) {
+
+ private String removeCommentsInTheBeginning(String sql, int startCommentMarkCount, int endCommentMarkCount,
+ String startMark, String endMark) {
int startCommentMarkIndex = sql.indexOf(startMark);
int endCommentMarkIndex = sql.indexOf(endMark);
@@ -498,7 +478,8 @@ private String removeCommentsInTheBeginning(String sql,
endCommentMarkIndex = Integer.MAX_VALUE;
}
- // Base case. startCommentMarkCount is guaranteed to be bigger than 0 because the method is called when /* occurs
+ // Base case. startCommentMarkCount is guaranteed to be bigger than 0 because the method is called when /*
+ // occurs
if (startCommentMarkCount == endCommentMarkCount) {
if (startCommentMarkCount != 0 && endCommentMarkCount != 0) {
return sql;
@@ -508,7 +489,8 @@ private String removeCommentsInTheBeginning(String sql,
// filter out first start comment mark
if (startCommentMarkIndex < endCommentMarkIndex) {
String sqlWithoutCommentsInBeginning = sql.substring(startCommentMarkIndex + startMark.length());
- return removeCommentsInTheBeginning(sqlWithoutCommentsInBeginning, ++startCommentMarkCount, endCommentMarkCount, startMark, endMark);
+ return removeCommentsInTheBeginning(sqlWithoutCommentsInBeginning, ++startCommentMarkCount,
+ endCommentMarkCount, startMark, endMark);
}
// filter out first end comment mark
else {
@@ -517,7 +499,8 @@ private String removeCommentsInTheBeginning(String sql,
}
String sqlWithoutCommentsInBeginning = sql.substring(endCommentMarkIndex + endMark.length());
- return removeCommentsInTheBeginning(sqlWithoutCommentsInBeginning, startCommentMarkCount, ++endCommentMarkCount, startMark, endMark);
+ return removeCommentsInTheBeginning(sqlWithoutCommentsInBeginning, startCommentMarkCount,
+ ++endCommentMarkCount, startMark, endMark);
}
}
@@ -538,7 +521,8 @@ String parseProcIdentifier(String procIdentifier) throws SQLServerException {
sb.append("@procedure_name=");
sb.append(threePartName.getProcedurePart());
} else {
- SQLServerException.makeFromDriverError(con, stmtParent, SQLServerException.getErrString("R_noMetadata"), null, false);
+ SQLServerException.makeFromDriverError(con, stmtParent, SQLServerException.getErrString("R_noMetadata"),
+ null, false);
}
return sb.toString();
}
@@ -550,16 +534,15 @@ private void checkClosed() throws SQLServerException {
}
/**
- * Create new parameter meta data.
+ * Construct a SQLServerParameterMetaData parameter meta data.
*
* @param st
- * the prepared statement
+ * the prepared statement
* @param sProcString
- * the pricedure name
+ * the pricedure name
* @throws SQLServerException
*/
- SQLServerParameterMetaData(SQLServerStatement st,
- String sProcString) throws SQLServerException {
+ SQLServerParameterMetaData(SQLServerStatement st, String sProcString) throws SQLServerException {
assert null != st;
stmtParent = st;
@@ -574,18 +557,18 @@ private void checkClosed() throws SQLServerException {
// If the CallableStatement/PreparedStatement is a stored procedure call
// then we can extract metadata using sp_sproc_columns
if (null != st.procedureName) {
- s = (SQLServerStatement) con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
+ s = (SQLServerStatement) con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
+ ResultSet.CONCUR_READ_ONLY);
String sProc = parseProcIdentifier(st.procedureName);
if (con.isKatmaiOrLater())
rsProcedureMeta = s.executeQueryInternal("exec sp_sproc_columns_100 " + sProc + ", @ODBCVer=3");
else
rsProcedureMeta = s.executeQueryInternal("exec sp_sproc_columns " + sProc + ", @ODBCVer=3");
-
+
// if rsProcedureMeta has next row, it means the stored procedure is found
if (rsProcedureMeta.next()) {
procedureIsFound = true;
- }
- else {
+ } else {
procedureIsFound = false;
}
rsProcedureMeta.beforeFirst();
@@ -609,22 +592,25 @@ private void checkClosed() throws SQLServerException {
if (con.getServerMajorVersion() >= SQL_SERVER_2012_VERSION) {
// new implementation for SQL verser 2012 and above
String preparedSQL = con.replaceParameterMarkers(((SQLServerPreparedStatement) stmtParent).userSQL,
- ((SQLServerPreparedStatement) stmtParent).inOutParam, ((SQLServerPreparedStatement) stmtParent).bReturnValueSyntax);
+ ((SQLServerPreparedStatement) stmtParent).userSQLParamPositions,
+ ((SQLServerPreparedStatement) stmtParent).inOutParam,
+ ((SQLServerPreparedStatement) stmtParent).bReturnValueSyntax);
- SQLServerCallableStatement cstmt = (SQLServerCallableStatement) con.prepareCall("exec sp_describe_undeclared_parameters ?");
+ SQLServerCallableStatement cstmt = (SQLServerCallableStatement) con
+ .prepareCall("exec sp_describe_undeclared_parameters ?");
cstmt.setNString(1, preparedSQL);
parseQueryMeta(cstmt.executeQueryInternal());
cstmt.close();
- }
- else {
+ } else {
// old implementation for SQL server 2008
stringToParse = sProcString;
ArrayList metaInfoList = new ArrayList<>();
-
+
while (stringToParse.length() > 0) {
MetaInfo metaInfo = parseStatement(stringToParse);
if (null == metaInfo) {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_cantIdentifyTableMetadata"));
+ MessageFormat form = new MessageFormat(
+ SQLServerException.getErrString("R_cantIdentifyTableMetadata"));
Object[] msgArgs = {stringToParse};
SQLServerException.makeFromDriverError(con, stmtParent, form.format(msgArgs), null, false);
}
@@ -634,7 +620,7 @@ private void checkClosed() throws SQLServerException {
if (metaInfoList.size() <= 0 || metaInfoList.get(0).fields.length() <= 0) {
return;
}
-
+
StringBuilder sbColumns = new StringBuilder();
for (MetaInfo mi : metaInfoList) {
@@ -648,15 +634,14 @@ private void checkClosed() throws SQLServerException {
for (int i = 0; i < metaInfoList.size(); i++) {
if (i == 0) {
sbTablesAndJoins = sbTablesAndJoins.append(metaInfoList.get(i).table);
- }
- else {
+ } else {
if (metaInfoList.get(i).table.equals(metaInfoList.get(i - 1).table)
&& metaInfoList.get(i).fields.equals(metaInfoList.get(i - 1).fields)) {
continue;
}
- sbTablesAndJoins = sbTablesAndJoins
- .append(" LEFT JOIN " + metaInfoList.get(i).table + " ON " + metaInfoList.get(i - 1).table + "."
- + metaInfoList.get(i - 1).fields + "=" + metaInfoList.get(i).table + "." + metaInfoList.get(i).fields);
+ sbTablesAndJoins = sbTablesAndJoins.append(" LEFT JOIN " + metaInfoList.get(i).table
+ + " ON " + metaInfoList.get(i - 1).table + "." + metaInfoList.get(i - 1).fields
+ + "=" + metaInfoList.get(i).table + "." + metaInfoList.get(i).fields);
}
}
@@ -673,14 +658,11 @@ private void checkClosed() throws SQLServerException {
// Do not need to wrapper SQLServerException again
catch (SQLServerException e) {
throw e;
- }
- catch (SQLException e) {
+ } catch (SQLException e) {
SQLServerException.makeFromDriverError(con, stmtParent, e.toString(), null, false);
- }
- catch(StringIndexOutOfBoundsException e){
+ } catch (StringIndexOutOfBoundsException e) {
SQLServerException.makeFromDriverError(con, stmtParent, e.toString(), null, false);
- }
- finally {
+ } finally {
if (null != stmt)
stmt.close();
}
@@ -697,8 +679,7 @@ public T unwrap(Class iface) throws SQLException {
T t;
try {
t = iface.cast(this);
- }
- catch (ClassCastException e) {
+ } catch (ClassCastException e) {
throw new SQLServerException(e.getMessage(), e);
}
return t;
@@ -709,15 +690,14 @@ private void verifyParameterPosition(int param) throws SQLServerException {
try {
if (((SQLServerPreparedStatement) stmtParent).bReturnValueSyntax && isTVP) {
bFound = rsProcedureMeta.absolute(param);
+ } else {
+ bFound = rsProcedureMeta.absolute(param + 1); // Note row 1 is the 'return value' meta data
}
- else {
- bFound = rsProcedureMeta.absolute(param + 1); // Note row 1 is the 'return value' meta data
- }
- }
- catch (SQLException e) {
+ } catch (SQLException e) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_metaDataErrorForParameter"));
Object[] msgArgs = {param};
- SQLServerException.makeFromDriverError(con, stmtParent, form.format(msgArgs) + " " + e.toString(), null, false);
+ SQLServerException.makeFromDriverError(con, stmtParent, form.format(msgArgs) + " " + e.toString(), null,
+ false);
}
if (!bFound) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidParameterNumber"));
@@ -728,7 +708,8 @@ private void verifyParameterPosition(int param) throws SQLServerException {
private void checkParam(int n) throws SQLServerException {
if (!queryMetaMap.containsKey(n)) {
- SQLServerException.makeFromDriverError(con, stmtParent, SQLServerException.getErrString("R_noMetadata"), null, false);
+ SQLServerException.makeFromDriverError(con, stmtParent, SQLServerException.getErrString("R_noMetadata"),
+ null, false);
}
}
@@ -740,14 +721,12 @@ public String getParameterClassName(int param) throws SQLServerException {
// PreparedStatement.
checkParam(param);
return queryMetaMap.get(param).parameterClassName;
- }
- else {
+ } else {
verifyParameterPosition(param);
JDBCType jdbcType = JDBCType.of(rsProcedureMeta.getShort("DATA_TYPE"));
return jdbcType.className();
}
- }
- catch (SQLException e) {
+ } catch (SQLException e) {
SQLServerException.makeFromDriverError(con, stmtParent, e.toString(), null, false);
return null;
}
@@ -760,16 +739,14 @@ public int getParameterCount() throws SQLServerException {
if (rsProcedureMeta == null) {
// PreparedStatement
return queryMetaMap.size();
- }
- else {
+ } else {
rsProcedureMeta.last();
int nCount = rsProcedureMeta.getRow() - 1;
if (nCount < 0)
nCount = 0;
return nCount;
}
- }
- catch (SQLException e) {
+ } catch (SQLException e) {
SQLServerException.makeFromDriverError(con, stmtParent, e.toString(), null, false);
return 0;
}
@@ -783,8 +760,7 @@ public int getParameterMode(int param) throws SQLServerException {
checkParam(param);
// if it is not a stored proc, the param can only be input.
return parameterModeIn;
- }
- else {
+ } else {
verifyParameterPosition(param);
int n = rsProcedureMeta.getInt("COLUMN_TYPE");
switch (n) {
@@ -796,8 +772,7 @@ public int getParameterMode(int param) throws SQLServerException {
return parameterModeUnknown;
}
}
- }
- catch (SQLException e) {
+ } catch (SQLException e) {
SQLServerException.makeFromDriverError(con, stmtParent, e.toString(), null, false);
return parameterModeUnknown;
}
@@ -813,8 +788,7 @@ public int getParameterType(int param) throws SQLServerException {
// PreparedStatement.
checkParam(param);
parameterType = queryMetaMap.get(param).parameterType;
- }
- else {
+ } else {
verifyParameterPosition(param);
parameterType = rsProcedureMeta.getShort("DATA_TYPE");
}
@@ -834,8 +808,7 @@ public int getParameterType(int param) throws SQLServerException {
}
return parameterType;
- }
- catch (SQLException e) {
+ } catch (SQLException e) {
SQLServerException.makeFromDriverError(con, stmtParent, e.toString(), null, false);
return 0;
}
@@ -849,13 +822,11 @@ public String getParameterTypeName(int param) throws SQLServerException {
// PreparedStatement.
checkParam(param);
return queryMetaMap.get(param).parameterTypeName;
- }
- else {
+ } else {
verifyParameterPosition(param);
return rsProcedureMeta.getString("TYPE_NAME");
}
- }
- catch (SQLException e) {
+ } catch (SQLException e) {
SQLServerException.makeFromDriverError(con, stmtParent, e.toString(), null, false);
return null;
}
@@ -869,14 +840,12 @@ public int getPrecision(int param) throws SQLServerException {
// PreparedStatement.
checkParam(param);
return queryMetaMap.get(param).precision;
- }
- else {
+ } else {
verifyParameterPosition(param);
int nPrec = rsProcedureMeta.getInt("PRECISION");
return nPrec;
}
- }
- catch (SQLException e) {
+ } catch (SQLException e) {
SQLServerException.makeFromDriverError(con, stmtParent, e.toString(), null, false);
return 0;
}
@@ -890,14 +859,12 @@ public int getScale(int param) throws SQLServerException {
// PreparedStatement.
checkParam(param);
return queryMetaMap.get(param).scale;
- }
- else {
+ } else {
verifyParameterPosition(param);
int nScale = rsProcedureMeta.getInt("SCALE");
return nScale;
}
- }
- catch (SQLException e) {
+ } catch (SQLException e) {
SQLServerException.makeFromDriverError(con, stmtParent, e.toString(), null, false);
return 0;
}
@@ -911,8 +878,7 @@ public int isNullable(int param) throws SQLServerException {
// PreparedStatement.
checkParam(param);
return queryMetaMap.get(param).isNullable;
- }
- else {
+ } else {
verifyParameterPosition(param);
int nNull = rsProcedureMeta.getInt("NULLABLE");
if (nNull == 1)
@@ -921,20 +887,19 @@ public int isNullable(int param) throws SQLServerException {
return parameterNoNulls;
return parameterNullableUnknown;
}
- }
- catch (SQLException e) {
+ } catch (SQLException e) {
SQLServerException.makeFromDriverError(con, stmtParent, e.toString(), null, false);
return parameterNoNulls;
}
}
/**
- * Verify a supplied parameter index is valid
+ * Returns if a supplied parameter index is valid.
*
* @param param
- * the param index
+ * the param index
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
* @return boolean
*/
@Override
@@ -945,13 +910,11 @@ public boolean isSigned(int param) throws SQLServerException {
// PreparedStatement.
checkParam(param);
return queryMetaMap.get(param).isSigned;
- }
- else {
+ } else {
verifyParameterPosition(param);
return JDBCType.of(rsProcedureMeta.getShort("DATA_TYPE")).isSigned();
}
- }
- catch (SQLException e) {
+ } catch (SQLException e) {
SQLServerException.makeFromDriverError(con, stmtParent, e.toString(), null, false);
return false;
}
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerPooledConnection.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerPooledConnection.java
index f17368e6f..91b8a5144 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerPooledConnection.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerPooledConnection.java
@@ -1,9 +1,6 @@
/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc;
@@ -19,9 +16,10 @@
import javax.sql.PooledConnection;
import javax.sql.StatementEventListener;
+
/**
- * SQLServerPooledConnection represents a database physical connection in a connection pool. If provides methods for the connection pool manager to
- * manage the connection pool. Applications typically do not instantiate these connections directly.
+ * Represents a physical database connection in a connection pool. If provides methods for the connection pool manager
+ * to manage the connection pool. Applications typically do not instantiate these connections directly.
*/
public class SQLServerPooledConnection implements PooledConnection {
@@ -31,13 +29,12 @@ public class SQLServerPooledConnection implements PooledConnection {
private SQLServerConnectionPoolProxy lastProxyConnection;
private String factoryUser, factoryPassword;
private java.util.logging.Logger pcLogger;
- static private final AtomicInteger basePooledConnectionID = new AtomicInteger(0); // Unique id generator for each PooledConnection instance
- // (used for logging).
+ static private final AtomicInteger basePooledConnectionID = new AtomicInteger(0); // Unique id generator for each
+ // PooledConnection instance
+ // (used for logging).
private final String traceID;
- SQLServerPooledConnection(SQLServerDataSource ds,
- String user,
- String password) throws SQLException {
+ SQLServerPooledConnection(SQLServerDataSource ds, String user, String password) throws SQLException {
listeners = new Vector<>();
// Piggyback SQLServerDataSource logger for now.
pcLogger = SQLServerDataSource.dsLogger;
@@ -59,7 +56,7 @@ public class SQLServerPooledConnection implements PooledConnection {
}
/**
- * This is a helper function to provide an ID string suitable for tracing.
+ * Provides a helper function to provide an ID string suitable for tracing.
*
* @return traceID String
*/
@@ -74,10 +71,10 @@ private SQLServerConnection createNewConnection() throws SQLException {
}
/**
- * Creates an object handle for the physical connection that this PooledConnection object represents.
+ * Returns an object handle for the physical connection that this PooledConnection object represents.
*
* @throws SQLException
- * when an error occurs
+ * when an error occurs
* @return a Connection object that is a handle to this PooledConnection object
*/
@Override
@@ -87,7 +84,8 @@ public Connection getConnection() throws SQLException {
synchronized (this) {
// If physical connection is closed, throw exception per spec, this PooledConnection is dead.
if (physicalConnection == null) {
- SQLServerException.makeFromDriverError(null, this, SQLServerException.getErrString("R_physicalConnectionIsClosed"), "", true);
+ SQLServerException.makeFromDriverError(null, this,
+ SQLServerException.getErrString("R_physicalConnectionIsClosed"), "", true);
}
// Check with security manager to insure caller has rights to connect.
@@ -108,7 +106,8 @@ public Connection getConnection() throws SQLException {
// if there was a last proxy connection send reset
physicalConnection.resetPooledConnection();
if (pcLogger.isLoggable(Level.FINE) && !lastProxyConnection.isClosed())
- pcLogger.fine(toString() + "proxy " + lastProxyConnection.toString() + " is not closed before getting the connection.");
+ pcLogger.fine(toString() + "proxy " + lastProxyConnection.toString()
+ + " is not closed before getting the connection.");
// use internal close so there wont be an event due to us closing the connection, if not closed already.
lastProxyConnection.internalClose();
}
@@ -121,11 +120,11 @@ public Connection getConnection() throws SQLException {
}
}
- // Notify any interested parties (e.g. pooling managers) of a ConnectionEvent activity
- // on the connection. Calling notifyEvent with null event will place the
- // connection back in the pool. Calling notifyEvent with a non-null event is
- // used to notify the pooling manager that the connection is bad and should be removed
- // from the pool.
+ /**
+ * Notifies any interested parties (e.g. pooling managers) of a ConnectionEvent activity on the connection. Calling
+ * notifyEvent with null event will place the connection back in the pool. Calling notifyEvent with a non-null event
+ * is used to notify the pooling manager that the connection is bad and should be removed from the pool.
+ */
void notifyEvent(SQLServerException e) {
if (pcLogger.isLoggable(Level.FINER))
pcLogger.finer(toString() + " Exception:" + e + safeCID());
@@ -153,8 +152,7 @@ void notifyEvent(SQLServerException e) {
if (pcLogger.isLoggable(Level.FINER))
pcLogger.finer(toString() + " notifyEvent:connectionClosed " + safeCID());
listener.connectionClosed(ev);
- }
- else {
+ } else {
if (pcLogger.isLoggable(Level.FINER))
pcLogger.finer(toString() + " notifyEvent:connectionErrorOccurred " + safeCID());
listener.connectionErrorOccurred(ev);
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerPreparedStatement.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerPreparedStatement.java
index 063dabe39..34b42e50a 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerPreparedStatement.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerPreparedStatement.java
@@ -1,9 +1,6 @@
/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc;
@@ -32,23 +29,23 @@
import java.util.Vector;
import java.util.logging.Level;
+import com.microsoft.sqlserver.jdbc.SQLServerConnection.CityHash128Key;
import com.microsoft.sqlserver.jdbc.SQLServerConnection.PreparedStatementHandle;
-import com.microsoft.sqlserver.jdbc.SQLServerConnection.Sha1HashKey;
+
/**
- * SQLServerPreparedStatement provides JDBC prepared statement functionality. SQLServerPreparedStatement provides methods for the user to supply
- * parameters as any native Java type and many Java object types.
+ * Provides an implementation of java.sql.PreparedStatement interface that assists in preparing Statements for SQL
+ * Server.
*
- * SQLServerPreparedStatement prepares a statement using SQL Server's sp_prepexec and re-uses the returned statement handle for each subsequent
- * execution of the statement (typically using different parameters provided by the user)
+ * SQLServerPreparedStatement prepares a statement using SQL Server's sp_prepexec and re-uses the returned statement
+ * handle for each subsequent execution of the statement (typically using different parameters provided by the user)
*
- * SQLServerPreparedStatement supports batching whereby a set of prepared statements are executed in a single database round trip to improve runtime
- * performance.
+ * SQLServerPreparedStatement supports batching whereby a set of prepared statements are executed in a single database
+ * round trip to improve runtime performance.
*
- * The API javadoc for JDBC API methods that this class implements are not repeated here. Please see Sun's JDBC API interfaces javadoc for those
- * details.
+ * The API javadoc for JDBC API methods that this class implements are not repeated here. Please see Sun's JDBC API
+ * interfaces javadoc for those details.
*/
-
public class SQLServerPreparedStatement extends SQLServerStatement implements ISQLServerPreparedStatement {
/** Flag to indicate that it is an internal query to retrieve encryption metadata. */
boolean isInternalEncryptionQuery = false;
@@ -65,6 +62,9 @@ public class SQLServerPreparedStatement extends SQLServerStatement implements IS
/** Processed SQL statement text, may not be same as what user initially passed. */
final String userSQL;
+ /** Parameter positions in processed SQL statement text. */
+ final int[] userSQLParamPositions;
+
/** SQL statement with expanded parameter tokens */
private String preparedSQL;
@@ -75,11 +75,12 @@ public class SQLServerPreparedStatement extends SQLServerStatement implements IS
private PreparedStatementHandle cachedPreparedStatementHandle;
/** Hash of user supplied SQL statement used for various cache lookups */
- private Sha1HashKey sqlTextCacheKey;
+ private CityHash128Key sqlTextCacheKey;
/**
- * Array with parameter names generated in buildParamTypeDefinitions For mapping encryption information to parameters, as the second result set
- * returned by sp_describe_parameter_encryption doesn't depend on order of input parameter
+ * Array with parameter names generated in buildParamTypeDefinitions For mapping encryption information to
+ * parameters, as the second result set returned by sp_describe_parameter_encryption doesn't depend on order of
+ * input parameter
**/
private ArrayList parameterNames;
@@ -89,9 +90,9 @@ public class SQLServerPreparedStatement extends SQLServerStatement implements IS
/**
* The number of OUT parameters to skip in the response to get to the first app-declared OUT parameter.
*
- * When executing prepared and callable statements and/or statements that produce cursored results, the first OUT parameters returned by the
- * server contain the internal values like the prepared statement handle and the cursor ID and row count. This value indicates how many of those
- * internal OUT parameters were in the response.
+ * When executing prepared and callable statements and/or statements that produce cursored results, the first OUT
+ * parameters returned by the server contain the internal values like the prepared statement handle and the cursor
+ * ID and row count. This value indicates how many of those internal OUT parameters were in the response.
*/
int outParamIndexAdjustment;
@@ -107,30 +108,33 @@ public class SQLServerPreparedStatement extends SQLServerStatement implements IS
private void setPreparedStatementHandle(int handle) {
this.prepStmtHandle = handle;
}
-
+
/**
* boolean value for deciding if the driver should use bulk copy API for batch inserts
*/
private boolean useBulkCopyForBatchInsert;
-
- /** Gets the prepared statement's useBulkCopyForBatchInsert value.
+
+ /**
+ * Returns the prepared statement's useBulkCopyForBatchInsert value.
*
- * @return
- * Per the description.
- * @throws SQLServerException when an error occurs
- */
+ * @return Per the description.
+ * @throws SQLServerException
+ * when an error occurs
+ */
@SuppressWarnings("unused")
private boolean getUseBulkCopyForBatchInsert() throws SQLServerException {
checkClosed();
return useBulkCopyForBatchInsert;
}
-
- /** Sets the prepared statement's useBulkCopyForBatchInsert value.
+
+ /**
+ * Sets the prepared statement's useBulkCopyForBatchInsert value.
*
* @param useBulkCopyForBatchInsert
- * the boolean value
- * @throws SQLServerException when an error occurs
- */
+ * the boolean value
+ * @throws SQLServerException
+ * when an error occurs
+ */
@SuppressWarnings("unused")
private void setUseBulkCopyForBatchInsert(boolean useBulkCopyForBatchInsert) throws SQLServerException {
checkClosed();
@@ -176,32 +180,29 @@ private boolean resetPrepStmtHandle(boolean discardCurrentCacheItem) {
private boolean encryptionMetadataIsRetrieved = false;
private String localUserSQL;
-
+
// Internal function used in tracing
String getClassNameInternal() {
return "SQLServerPreparedStatement";
}
/**
- * Create a new prepaed statement.
+ * Constructs a SQLServerPreparedStatement.
*
* @param conn
- * the connection
+ * the connection
* @param sql
- * the user's sql
+ * the user's sql
* @param nRSType
- * the result set type
+ * the result set type
* @param nRSConcur
- * the result set concurrency
+ * the result set concurrency
* @param stmtColEncSetting
- * the statement column encryption setting
+ * the statement column encryption setting
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
- SQLServerPreparedStatement(SQLServerConnection conn,
- String sql,
- int nRSType,
- int nRSConcur,
+ SQLServerPreparedStatement(SQLServerConnection conn, String sql, int nRSType, int nRSConcur,
SQLServerStatementColumnEncryptionSetting stmtColEncSetting) throws SQLServerException {
super(conn, nRSType, nRSConcur, stmtColEncSetting);
@@ -214,7 +215,7 @@ String getClassNameInternal() {
stmtPoolable = true;
// Create a cache key for this statement.
- sqlTextCacheKey = new Sha1HashKey(sql);
+ sqlTextCacheKey = new CityHash128Key(sql);
// Parse or fetch SQL metadata from cache.
ParsedSQLCacheItem parsedSQL = getCachedParsedSQL(sqlTextCacheKey);
@@ -222,8 +223,7 @@ String getClassNameInternal() {
if (null != connection && connection.isStatementPoolingEnabled()) {
isExecutedAtLeastOnce = true;
}
- }
- else {
+ } else {
parsedSQL = parseAndCacheSQL(sqlTextCacheKey, sql);
}
@@ -231,12 +231,13 @@ String getClassNameInternal() {
procedureName = parsedSQL.procedureName;
bReturnValueSyntax = parsedSQL.bReturnValueSyntax;
userSQL = parsedSQL.processedSQL;
- initParams(parsedSQL.parameterCount);
+ userSQLParamPositions = parsedSQL.parameterPositions;
+ initParams(userSQLParamPositions.length);
useBulkCopyForBatchInsert = conn.getUseBulkCopyForBatchInsert();
}
/**
- * Close the prepared statement's prepared handle.
+ * Closes the prepared statement's prepared handle.
*/
private void closePreparedHandle() {
if (!hasPreparedStatementHandle())
@@ -247,9 +248,9 @@ private void closePreparedHandle() {
// on the server anyway.
if (connection.isSessionUnAvailable()) {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.finer(this + ": Not closing PreparedHandle:" + prepStmtHandle + "; connection is already closed.");
- }
- else {
+ loggerExternal.finer(
+ this + ": Not closing PreparedHandle:" + prepStmtHandle + "; connection is already closed.");
+ } else {
isExecutedAtLeastOnce = false;
final int handleToClose = prepStmtHandle;
@@ -257,11 +258,12 @@ private void closePreparedHandle() {
if (resetPrepStmtHandle(false)) {
connection.returnCachedPreparedStatementHandle(cachedPreparedStatementHandle);
}
- // If no reference to a statement pool cache item is found handle unprepare actions through batching @ connection level.
+ // If no reference to a statement pool cache item is found handle unprepare actions through batching @
+ // connection level.
else if (connection.isPreparedStatementUnprepareBatchingEnabled()) {
- connection.enqueueUnprepareStatementHandle(connection.new PreparedStatementHandle(null, handleToClose, executedSqlDirectly, true));
- }
- else {
+ connection.enqueueUnprepareStatementHandle(
+ connection.new PreparedStatementHandle(null, handleToClose, executedSqlDirectly, true));
+ } else {
// Non batched behavior (same as pre batch clean-up implementation)
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.finer(this + ": Closing PreparedHandle:" + handleToClose);
@@ -274,9 +276,10 @@ final class PreparedHandleClose extends UninterruptableTDSCommand {
final boolean doExecute() throws SQLServerException {
TDSWriter tdsWriter = startRequest(TDS.PKT_RPC);
tdsWriter.writeShort((short) 0xFFFF); // procedure name length -> use ProcIDs
- tdsWriter.writeShort(executedSqlDirectly ? TDS.PROCID_SP_UNPREPARE : TDS.PROCID_SP_CURSORUNPREPARE);
- tdsWriter.writeByte((byte) 0); // RPC procedure option 1
- tdsWriter.writeByte((byte) 0); // RPC procedure option 2
+ tdsWriter.writeShort(
+ executedSqlDirectly ? TDS.PROCID_SP_UNPREPARE : TDS.PROCID_SP_CURSORUNPREPARE);
+ tdsWriter.writeByte((byte) 0); // RPC procedure option 1
+ tdsWriter.writeByte((byte) 0); // RPC procedure option 2
tdsWriter.writeRPCInt(null, handleToClose, false);
TDSParser.parse(startResponse(), getLogContext());
return true;
@@ -286,10 +289,10 @@ final boolean doExecute() throws SQLServerException {
// Try to close the server cursor. Any failure is caught, logged, and ignored.
try {
executeCommand(new PreparedHandleClose());
- }
- catch (SQLServerException e) {
+ } catch (SQLServerException e) {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.log(Level.FINER, this + ": Error (ignored) closing PreparedHandle:" + handleToClose, e);
+ loggerExternal.log(Level.FINER,
+ this + ": Error (ignored) closing PreparedHandle:" + handleToClose, e);
}
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
@@ -304,9 +307,10 @@ final boolean doExecute() throws SQLServerException {
/**
* Closes this prepared statement.
*
- * Note that the public Statement.close() method performs all of the cleanup work through this internal method which cannot throw any exceptions.
- * This is done deliberately to ensure that ALL of the object's client-side and server-side state is cleaned up as best as possible, even under
- * conditions which would normally result in exceptions being thrown.
+ * Note that the public Statement.close() method performs all of the cleanup work through this internal method which
+ * cannot throw any exceptions. This is done deliberately to ensure that ALL of the object's client-side and
+ * server-side state is cleaned up as best as possible, even under conditions which would normally result in
+ * exceptions being thrown.
*/
final void closeInternal() {
super.closeInternal();
@@ -318,12 +322,11 @@ final void closeInternal() {
try {
if (null != internalStmt)
internalStmt.close();
- }
- catch (SQLServerException e) {
+ } catch (SQLServerException e) {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.finer("Ignored error closing internal statement: " + e.getErrorCode() + " " + e.getMessage());
- }
- finally {
+ loggerExternal
+ .finer("Ignored error closing internal statement: " + e.getErrorCode() + " " + e.getMessage());
+ } finally {
internalStmt = null;
}
@@ -332,10 +335,10 @@ final void closeInternal() {
}
/**
- * Intialize the statement parameters.
+ * Initializes the statement parameters.
*
* @param nParams
- * Number of parameters to Intialize.
+ * Number of parameters to initialize.
*/
final void initParams(int nParams) {
inOutParam = new Parameter[nParams];
@@ -359,11 +362,10 @@ public final void clearParameters() throws SQLServerException {
}
/**
- * Determines whether the statement needs to be reprepared based on a change in any of the type definitions of any of the parameters due to
- * changes in scale, length, etc., and, if so, sets the new type definition string.
+ * Determines whether the statement needs to be reprepared based on a change in any of the type definitions of any
+ * of the parameters due to changes in scale, length, etc., and, if so, sets the new type definition string.
*/
- private boolean buildPreparedStrings(Parameter[] params,
- boolean renewDefinition) throws SQLServerException {
+ private boolean buildPreparedStrings(Parameter[] params, boolean renewDefinition) throws SQLServerException {
String newTypeDefinitions = buildParamTypeDefinitions(params, renewDefinition);
if (null != preparedTypeDefinitions && newTypeDefinitions.equalsIgnoreCase(preparedTypeDefinitions))
return false;
@@ -371,7 +373,7 @@ private boolean buildPreparedStrings(Parameter[] params,
preparedTypeDefinitions = newTypeDefinitions;
/* Replace the parameter marker '?' with the param numbers @p1, @p2 etc */
- preparedSQL = connection.replaceParameterMarkers(userSQL, params, bReturnValueSyntax);
+ preparedSQL = connection.replaceParameterMarkers(userSQL, userSQLParamPositions, params, bReturnValueSyntax);
if (bRequestedGeneratedKeys)
preparedSQL = preparedSQL + identityQuery;
@@ -379,18 +381,17 @@ private boolean buildPreparedStrings(Parameter[] params,
}
/**
- * Build the parameter type definitons for a JDBC prepared statement that will be used to prepare the statement.
+ * Builds the parameter type definitons for a JDBC prepared statement that will be used to prepare the statement.
*
* @param params
- * the statement parameters
+ * the statement parameters
* @param renewDefinition
- * True if renewing parameter definition, False otherwise
+ * True if renewing parameter definition, False otherwise
* @throws SQLServerException
- * when an error occurs.
+ * when an error occurs.
* @return the required data type defintions.
*/
- private String buildParamTypeDefinitions(Parameter[] params,
- boolean renewDefinition) throws SQLServerException {
+ private String buildParamTypeDefinitions(Parameter[] params, boolean renewDefinition) throws SQLServerException {
StringBuilder sb = new StringBuilder();
int nCols = params.length;
char cParamName[] = new char[10];
@@ -436,7 +437,7 @@ public java.sql.ResultSet executeQuery() throws SQLServerException, SQLTimeoutEx
}
/**
- * Execute a query without cursoring for metadata.
+ * Executes a query without cursoring for metadata.
*
* @throws SQLServerException
* @return ResultSet
@@ -461,7 +462,8 @@ public int executeUpdate() throws SQLServerException, SQLTimeoutException {
// this shouldn't happen, caller probably meant to call executeLargeUpdate
if (updateCount < Integer.MIN_VALUE || updateCount > Integer.MAX_VALUE)
- SQLServerException.makeFromDriverError(connection, this, SQLServerException.getErrString("R_updateCountOutofRange"), null, true);
+ SQLServerException.makeFromDriverError(connection, this,
+ SQLServerException.getErrString("R_updateCountOutofRange"), null, true);
loggerExternal.exiting(getClassNameLogging(), "executeUpdate", updateCount);
@@ -496,8 +498,7 @@ public boolean execute() throws SQLServerException, SQLTimeoutException {
private final class PrepStmtExecCmd extends TDSCommand {
private final SQLServerPreparedStatement stmt;
- PrepStmtExecCmd(SQLServerPreparedStatement stmt,
- int executeMethod) {
+ PrepStmtExecCmd(SQLServerPreparedStatement stmt, int executeMethod) {
super(stmt.toString() + " executeXXX", queryTimeout, cancelQueryTimeoutSeconds);
this.stmt = stmt;
stmt.executeMethod = executeMethod;
@@ -539,7 +540,8 @@ final void doExecutePreparedStatement(PrepStmtExecCmd command) throws SQLServerE
hasNewTypeDefinitions = buildPreparedStrings(inOutParam, false);
}
- if ((Util.shouldHonorAEForParameters(stmtColumnEncriptionSetting, connection)) && (0 < inOutParam.length) && !isInternalEncryptionQuery) {
+ if ((Util.shouldHonorAEForParameters(stmtColumnEncriptionSetting, connection)) && (0 < inOutParam.length)
+ && !isInternalEncryptionQuery) {
// retrieve paramater encryption metadata if they are not retrieved yet
if (!encryptionMetadataIsRetrieved) {
@@ -551,7 +553,8 @@ final void doExecutePreparedStatement(PrepStmtExecCmd command) throws SQLServerE
setMaxRowsAndMaxFieldSize();
}
- // fix an issue when inserting unicode into non-encrypted nchar column using setString() and AE is on on Connection
+ // fix an issue when inserting unicode into non-encrypted nchar column using setString() and AE is on on
+ // Connection
hasNewTypeDefinitions = buildPreparedStrings(inOutParam, true);
}
@@ -573,8 +576,7 @@ final void doExecutePreparedStatement(PrepStmtExecCmd command) throws SQLServerE
ensureExecuteResultsReader(command.startResponse(getIsResponseBufferingAdaptive()));
startResults();
getNextResult();
- }
- catch (SQLException e) {
+ } catch (SQLException e) {
if (retryBasedOnFailedReuseOfCachedHandle(e, attempt, needsPrepare, false))
continue;
else
@@ -584,32 +586,36 @@ final void doExecutePreparedStatement(PrepStmtExecCmd command) throws SQLServerE
}
if (EXECUTE_QUERY == executeMethod && null == resultSet) {
- SQLServerException.makeFromDriverError(connection, this, SQLServerException.getErrString("R_noResultset"), null, true);
- }
- else if (EXECUTE_UPDATE == executeMethod && null != resultSet) {
- SQLServerException.makeFromDriverError(connection, this, SQLServerException.getErrString("R_resultsetGeneratedForUpdate"), null, false);
+ SQLServerException.makeFromDriverError(connection, this, SQLServerException.getErrString("R_noResultset"),
+ null, true);
+ } else if (EXECUTE_UPDATE == executeMethod && null != resultSet) {
+ SQLServerException.makeFromDriverError(connection, this,
+ SQLServerException.getErrString("R_resultsetGeneratedForUpdate"), null, false);
}
}
- /** Should the execution be retried because the re-used cached handle could not be re-used due to server side state changes? */
- private boolean retryBasedOnFailedReuseOfCachedHandle(SQLException e,
- int attempt,
- boolean needsPrepare,
+ /**
+ * Returns if the execution should be retried because the re-used cached handle could not be re-used due to server
+ * side state changes.
+ */
+ private boolean retryBasedOnFailedReuseOfCachedHandle(SQLException e, int attempt, boolean needsPrepare,
boolean isBatch) {
// Only retry based on these error codes and if statementPooling is enabled:
- // 586: The prepared statement handle %d is not valid in this context. Please verify that current database, user default schema, and
+ // 586: The prepared statement handle %d is not valid in this context. Please verify that current database, user
+ // default schema, and
// ANSI_NULLS and QUOTED_IDENTIFIER set options are not changed since the handle is prepared.
// 8179: Could not find prepared statement with handle %d.
if (needsPrepare && !isBatch)
return false;
- return 1 == attempt && (586 == e.getErrorCode() || 8179 == e.getErrorCode()) && connection.isStatementPoolingEnabled();
+ return 1 == attempt && (586 == e.getErrorCode() || 8179 == e.getErrorCode())
+ && connection.isStatementPoolingEnabled();
}
/**
- * Consume the OUT parameter for the statement object itself.
+ * Consumes the OUT parameter for the statement object itself.
*
- * When a prepared statement handle is expected as the first OUT parameter from PreparedStatement or CallableStatement execution, then it gets
- * consumed here.
+ * When a prepared statement handle is expected as the first OUT parameter from PreparedStatement or
+ * CallableStatement execution, then it gets consumed here.
*/
boolean consumeExecOutParam(TDSReader tdsReader) throws SQLServerException {
final class PrepStmtExecOutParamHandler extends StmtExecOutParamHandler {
@@ -623,7 +629,8 @@ boolean onRetValue(TDSReader tdsReader) throws SQLServerException {
// If a prepared statement handle is expected then consume it
// and continue processing.
expectPrepStmtHandle = false;
- Parameter param = new Parameter(Util.shouldHonorAEForParameters(stmtColumnEncriptionSetting, connection));
+ Parameter param = new Parameter(
+ Util.shouldHonorAEForParameters(stmtColumnEncriptionSetting, connection));
param.skipRetValStatus(tdsReader);
setPreparedStatementHandle(param.getInt(tdsReader));
@@ -631,7 +638,8 @@ boolean onRetValue(TDSReader tdsReader) throws SQLServerException {
// Cache the reference to the newly created handle, NOT for cursorable handles.
if (null == cachedPreparedStatementHandle && !isCursorable(executeMethod)) {
cachedPreparedStatementHandle = connection.registerCachedPreparedStatementHandle(
- new Sha1HashKey(preparedSQL, preparedTypeDefinitions), prepStmtHandle, executedSqlDirectly);
+ new CityHash128Key(preparedSQL, preparedTypeDefinitions), prepStmtHandle,
+ executedSqlDirectly);
}
param.skipValue(tdsReader, true);
@@ -651,10 +659,9 @@ boolean onRetValue(TDSReader tdsReader) throws SQLServerException {
}
/**
- * Send the statement parameters by RPC
+ * Sends the statement parameters by RPC.
*/
- void sendParamsByRPC(TDSWriter tdsWriter,
- Parameter[] params) throws SQLServerException {
+ void sendParamsByRPC(TDSWriter tdsWriter, Parameter[] params) throws SQLServerException {
char cParamName[];
for (int index = 0; index < params.length; index++) {
if (JDBCType.TVP == params[index].getJdbcType()) {
@@ -669,8 +676,8 @@ void sendParamsByRPC(TDSWriter tdsWriter,
private void buildServerCursorPrepExecParams(TDSWriter tdsWriter) throws SQLServerException {
if (getStatementLogger().isLoggable(java.util.logging.Level.FINE))
- getStatementLogger()
- .fine(toString() + ": calling sp_cursorprepexec: PreparedHandle:" + getPreparedStatementHandle() + ", SQL:" + preparedSQL);
+ getStatementLogger().fine(toString() + ": calling sp_cursorprepexec: PreparedHandle:"
+ + getPreparedStatementHandle() + ", SQL:" + preparedSQL);
expectPrepStmtHandle = true;
executedSqlDirectly = false;
@@ -679,8 +686,8 @@ private void buildServerCursorPrepExecParams(TDSWriter tdsWriter) throws SQLServ
tdsWriter.writeShort((short) 0xFFFF); // procedure name length -> use ProcIDs
tdsWriter.writeShort(TDS.PROCID_SP_CURSORPREPEXEC);
- tdsWriter.writeByte((byte) 0); // RPC procedure option 1
- tdsWriter.writeByte((byte) 0); // RPC procedure option 2
+ tdsWriter.writeByte((byte) 0); // RPC procedure option 1
+ tdsWriter.writeByte((byte) 0); // RPC procedure option 2
//
// IN (reprepare): Old handle to unprepare before repreparing
@@ -700,8 +707,8 @@ private void buildServerCursorPrepExecParams(TDSWriter tdsWriter) throws SQLServ
// IN
// Note: we must strip out SCROLLOPT_PARAMETERIZED_STMT if we don't
// actually have any parameters.
- tdsWriter.writeRPCInt(null, getResultSetScrollOpt() & ~((0 == preparedTypeDefinitions.length()) ? TDS.SCROLLOPT_PARAMETERIZED_STMT : 0),
- false);
+ tdsWriter.writeRPCInt(null, getResultSetScrollOpt()
+ & ~((0 == preparedTypeDefinitions.length()) ? TDS.SCROLLOPT_PARAMETERIZED_STMT : 0), false);
// IN
tdsWriter.writeRPCInt(null, getResultSetCCOpt(), false);
@@ -712,7 +719,8 @@ private void buildServerCursorPrepExecParams(TDSWriter tdsWriter) throws SQLServ
private void buildPrepExecParams(TDSWriter tdsWriter) throws SQLServerException {
if (getStatementLogger().isLoggable(java.util.logging.Level.FINE))
- getStatementLogger().fine(toString() + ": calling sp_prepexec: PreparedHandle:" + getPreparedStatementHandle() + ", SQL:" + preparedSQL);
+ getStatementLogger().fine(toString() + ": calling sp_prepexec: PreparedHandle:"
+ + getPreparedStatementHandle() + ", SQL:" + preparedSQL);
expectPrepStmtHandle = true;
executedSqlDirectly = true;
@@ -721,8 +729,8 @@ private void buildPrepExecParams(TDSWriter tdsWriter) throws SQLServerException
tdsWriter.writeShort((short) 0xFFFF); // procedure name length -> use ProcIDs
tdsWriter.writeShort(TDS.PROCID_SP_PREPEXEC);
- tdsWriter.writeByte((byte) 0); // RPC procedure option 1
- tdsWriter.writeByte((byte) 0); // RPC procedure option 2
+ tdsWriter.writeByte((byte) 0); // RPC procedure option 1
+ tdsWriter.writeByte((byte) 0); // RPC procedure option 2
//
// IN (reprepare): Old handle to unprepare before repreparing
@@ -748,8 +756,8 @@ private void buildExecSQLParams(TDSWriter tdsWriter) throws SQLServerException {
tdsWriter.writeShort((short) 0xFFFF); // procedure name length -> use ProcIDs
tdsWriter.writeShort(TDS.PROCID_SP_EXECUTESQL);
- tdsWriter.writeByte((byte) 0); // RPC procedure option 1
- tdsWriter.writeByte((byte) 0); // RPC procedure option 2
+ tdsWriter.writeByte((byte) 0); // RPC procedure option 1
+ tdsWriter.writeByte((byte) 0); // RPC procedure option 2
// No handle used.
resetPrepStmtHandle(false);
@@ -764,8 +772,8 @@ private void buildExecSQLParams(TDSWriter tdsWriter) throws SQLServerException {
private void buildServerCursorExecParams(TDSWriter tdsWriter) throws SQLServerException {
if (getStatementLogger().isLoggable(java.util.logging.Level.FINE))
- getStatementLogger()
- .fine(toString() + ": calling sp_cursorexecute: PreparedHandle:" + getPreparedStatementHandle() + ", SQL:" + preparedSQL);
+ getStatementLogger().fine(toString() + ": calling sp_cursorexecute: PreparedHandle:"
+ + getPreparedStatementHandle() + ", SQL:" + preparedSQL);
expectPrepStmtHandle = false;
executedSqlDirectly = false;
@@ -774,8 +782,8 @@ private void buildServerCursorExecParams(TDSWriter tdsWriter) throws SQLServerEx
tdsWriter.writeShort((short) 0xFFFF); // procedure name length -> use ProcIDs
tdsWriter.writeShort(TDS.PROCID_SP_CURSOREXECUTE);
- tdsWriter.writeByte((byte) 0); // RPC procedure option 1
- tdsWriter.writeByte((byte) 0); // RPC procedure option 2 */
+ tdsWriter.writeByte((byte) 0); // RPC procedure option 1
+ tdsWriter.writeByte((byte) 0); // RPC procedure option 2 */
// IN
assert hasPreparedStatementHandle();
@@ -796,7 +804,8 @@ private void buildServerCursorExecParams(TDSWriter tdsWriter) throws SQLServerEx
private void buildExecParams(TDSWriter tdsWriter) throws SQLServerException {
if (getStatementLogger().isLoggable(java.util.logging.Level.FINE))
- getStatementLogger().fine(toString() + ": calling sp_execute: PreparedHandle:" + getPreparedStatementHandle() + ", SQL:" + preparedSQL);
+ getStatementLogger().fine(toString() + ": calling sp_execute: PreparedHandle:"
+ + getPreparedStatementHandle() + ", SQL:" + preparedSQL);
expectPrepStmtHandle = false;
executedSqlDirectly = true;
@@ -805,8 +814,8 @@ private void buildExecParams(TDSWriter tdsWriter) throws SQLServerException {
tdsWriter.writeShort((short) 0xFFFF); // procedure name length -> use ProcIDs
tdsWriter.writeShort(TDS.PROCID_SP_EXECUTE);
- tdsWriter.writeByte((byte) 0); // RPC procedure option 1
- tdsWriter.writeByte((byte) 0); // RPC procedure option 2 */
+ tdsWriter.writeByte((byte) 0); // RPC procedure option 1
+ tdsWriter.writeByte((byte) 0); // RPC procedure option 2 */
// IN
assert hasPreparedStatementHandle();
@@ -815,9 +824,9 @@ private void buildExecParams(TDSWriter tdsWriter) throws SQLServerException {
private void getParameterEncryptionMetadata(Parameter[] params) throws SQLServerException {
/*
- * The parameter list is created from the data types provided by the user for the parameters. the data types do not need to be the same as in
- * the table definition. Also, when string is sent to an int field, the parameter is defined as nvarchar(). Same for varchar
- * datatypes, exact length is used.
+ * The parameter list is created from the data types provided by the user for the parameters. the data types do
+ * not need to be the same as in the table definition. Also, when string is sent to an int field, the parameter
+ * is defined as nvarchar(). Same for varchar datatypes, exact length is used.
*/
SQLServerResultSet rs = null;
SQLServerCallableStatement stmt = null;
@@ -826,7 +835,8 @@ private void getParameterEncryptionMetadata(Parameter[] params) throws SQLServer
try {
if (getStatementLogger().isLoggable(java.util.logging.Level.FINE)) {
- getStatementLogger().fine("Calling stored procedure sp_describe_parameter_encryption to get parameter encryption information.");
+ getStatementLogger().fine(
+ "Calling stored procedure sp_describe_parameter_encryption to get parameter encryption information.");
}
stmt = (SQLServerCallableStatement) connection.prepareCall("exec sp_describe_parameter_encryption ?,?");
@@ -834,13 +844,12 @@ private void getParameterEncryptionMetadata(Parameter[] params) throws SQLServer
stmt.setNString(1, preparedSQL);
stmt.setNString(2, preparedTypeDefinitions);
rs = (SQLServerResultSet) stmt.executeQueryInternal();
- }
- catch (SQLException e) {
+ } catch (SQLException e) {
if (e instanceof SQLServerException) {
throw (SQLServerException) e;
- }
- else {
- throw new SQLServerException(SQLServerException.getErrString("R_UnableRetrieveParameterMetadata"), null, 0, e);
+ } else {
+ throw new SQLServerException(SQLServerException.getErrString("R_UnableRetrieveParameterMetadata"), null,
+ 0, e);
}
}
@@ -858,12 +867,12 @@ private void getParameterEncryptionMetadata(Parameter[] params) throws SQLServer
if (!cekList.containsKey(currentOrdinal)) {
cekEntry = new CekTableEntry(currentOrdinal);
cekList.put(cekEntry.ordinal, cekEntry);
- }
- else {
+ } else {
cekEntry = cekList.get(currentOrdinal);
}
cekEntry.add(rs.getBytes(DescribeParameterEncryptionResultSet1.EncryptedKey.value()),
- rs.getInt(DescribeParameterEncryptionResultSet1.DbId.value()), rs.getInt(DescribeParameterEncryptionResultSet1.KeyId.value()),
+ rs.getInt(DescribeParameterEncryptionResultSet1.DbId.value()),
+ rs.getInt(DescribeParameterEncryptionResultSet1.KeyId.value()),
rs.getInt(DescribeParameterEncryptionResultSet1.KeyVersion.value()),
rs.getBytes(DescribeParameterEncryptionResultSet1.KeyMdVersion.value()),
rs.getString(DescribeParameterEncryptionResultSet1.KeyPath.value()),
@@ -873,19 +882,19 @@ private void getParameterEncryptionMetadata(Parameter[] params) throws SQLServer
if (getStatementLogger().isLoggable(java.util.logging.Level.FINE)) {
getStatementLogger().fine("Matadata of CEKs is retrieved.");
}
- }
- catch (SQLException e) {
+ } catch (SQLException e) {
if (e instanceof SQLServerException) {
throw (SQLServerException) e;
- }
- else {
- throw new SQLServerException(SQLServerException.getErrString("R_UnableRetrieveParameterMetadata"), null, 0, e);
+ } else {
+ throw new SQLServerException(SQLServerException.getErrString("R_UnableRetrieveParameterMetadata"), null,
+ 0, e);
}
}
// Process the second resultset.
if (!stmt.getMoreResults()) {
- throw new SQLServerException(this, SQLServerException.getErrString("R_UnexpectedDescribeParamFormat"), null, 0, false);
+ throw new SQLServerException(this, SQLServerException.getErrString("R_UnexpectedDescribeParamFormat"), null,
+ 0, false);
}
// Parameter count in the result set.
@@ -901,7 +910,8 @@ private void getParameterEncryptionMetadata(Parameter[] params) throws SQLServer
// cekEntry will be null if none of the parameters are encrypted.
if ((null != cekEntry) && (cekList.size() < cekOrdinal)) {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_InvalidEncryptionKeyOridnal"));
+ MessageFormat form = new MessageFormat(
+ SQLServerException.getErrString("R_InvalidEncryptionKeyOridnal"));
Object[] msgArgs = {cekOrdinal, cekEntry.getSize()};
throw new SQLServerException(this, form.format(msgArgs), null, 0, false);
}
@@ -909,12 +919,12 @@ private void getParameterEncryptionMetadata(Parameter[] params) throws SQLServer
.of((byte) rs.getInt(DescribeParameterEncryptionResultSet2.ColumnEncrytionType.value()));
if (SQLServerEncryptionType.PlainText != encType) {
params[paramIndex].cryptoMeta = new CryptoMetadata(cekEntry, (short) cekOrdinal,
- (byte) rs.getInt(DescribeParameterEncryptionResultSet2.ColumnEncryptionAlgorithm.value()), null, encType.value,
+ (byte) rs.getInt(DescribeParameterEncryptionResultSet2.ColumnEncryptionAlgorithm.value()),
+ null, encType.value,
(byte) rs.getInt(DescribeParameterEncryptionResultSet2.NormalizationRuleVersion.value()));
// Decrypt the symmetric key.(This will also validate and throw if needed).
SQLServerSecurityUtility.decryptSymmetricKey(params[paramIndex].cryptoMeta, connection);
- }
- else {
+ } else {
if (true == params[paramIndex].getForceEncryption()) {
MessageFormat form = new MessageFormat(
SQLServerException.getErrString("R_ForceEncryptionTrue_HonorAETrue_UnencryptedColumn"));
@@ -926,19 +936,19 @@ private void getParameterEncryptionMetadata(Parameter[] params) throws SQLServer
if (getStatementLogger().isLoggable(java.util.logging.Level.FINE)) {
getStatementLogger().fine("Parameter encryption metadata is set.");
}
- }
- catch (SQLException e) {
+ } catch (SQLException e) {
if (e instanceof SQLServerException) {
throw (SQLServerException) e;
- }
- else {
- throw new SQLServerException(SQLServerException.getErrString("R_UnableRetrieveParameterMetadata"), null, 0, e);
+ } else {
+ throw new SQLServerException(SQLServerException.getErrString("R_UnableRetrieveParameterMetadata"), null,
+ 0, e);
}
}
if (paramCount != params.length) {
// Encryption metadata wasn't sent by the server.
- // We expect the metadata to be sent for all the parameters in the original sp_describe_parameter_encryption.
+ // We expect the metadata to be sent for all the parameters in the original
+ // sp_describe_parameter_encryption.
// For parameters that don't need encryption, the encryption type is set to plaintext.
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_MissingParamEncryptionMetadata"));
Object[] msgArgs = {userSQL};
@@ -954,18 +964,20 @@ private void getParameterEncryptionMetadata(Parameter[] params) throws SQLServer
connection.resetCurrentCommand();
}
- /** Manage re-using cached handles */
- private boolean reuseCachedHandle(boolean hasNewTypeDefinitions,
- boolean discardCurrentCacheItem) {
+ /**
+ * Manages re-using cached handles.
+ */
+ private boolean reuseCachedHandle(boolean hasNewTypeDefinitions, boolean discardCurrentCacheItem) {
// No re-use of caching for cursorable statements (statements that WILL use sp_cursor*)
if (isCursorable(executeMethod))
return false;
- // If current cache items needs to be discarded or New type definitions found with existing cached handle reference then deregister cached
+ // If current cache items needs to be discarded or New type definitions found with existing cached handle
+ // reference then deregister cached
// handle.
if (discardCurrentCacheItem || hasNewTypeDefinitions) {
- if (null != cachedPreparedStatementHandle
- && (discardCurrentCacheItem || (hasPreparedStatementHandle() && prepStmtHandle == cachedPreparedStatementHandle.getHandle()))) {
+ if (null != cachedPreparedStatementHandle && (discardCurrentCacheItem
+ || (hasPreparedStatementHandle() && prepStmtHandle == cachedPreparedStatementHandle.getHandle()))) {
cachedPreparedStatementHandle.removeReference();
}
@@ -978,9 +990,12 @@ private boolean reuseCachedHandle(boolean hasNewTypeDefinitions,
// Check for new cache reference.
if (null == cachedPreparedStatementHandle) {
- PreparedStatementHandle cachedHandle = connection.getCachedPreparedStatementHandle(new Sha1HashKey(preparedSQL, preparedTypeDefinitions));
- // If handle was found then re-use, only if AE is not on and is not a batch query with new type definitions (We shouldn't reuse handle
- // if it is batch query and has new type definition, or if it is on, make sure encryptionMetadataIsRetrieved is retrieved.
+ PreparedStatementHandle cachedHandle = connection
+ .getCachedPreparedStatementHandle(new CityHash128Key(preparedSQL, preparedTypeDefinitions));
+ // If handle was found then re-use, only if AE is not on and is not a batch query with new type definitions
+ // (We shouldn't reuse handle
+ // if it is batch query and has new type definition, or if it is on, make sure encryptionMetadataIsRetrieved
+ // is retrieved.
if (null != cachedHandle) {
if (!connection.isColumnEncryptionSettingEnabled()
|| (connection.isColumnEncryptionSettingEnabled() && encryptionMetadataIsRetrieved)) {
@@ -995,9 +1010,7 @@ private boolean reuseCachedHandle(boolean hasNewTypeDefinitions,
return false;
}
- private boolean doPrepExec(TDSWriter tdsWriter,
- Parameter[] params,
- boolean hasNewTypeDefinitions,
+ private boolean doPrepExec(TDSWriter tdsWriter, Parameter[] params, boolean hasNewTypeDefinitions,
boolean hasExistingTypeDefinitions) throws SQLServerException {
boolean needsPrepare = (hasNewTypeDefinitions && hasExistingTypeDefinitions) || !hasPreparedStatementHandle();
@@ -1009,8 +1022,7 @@ private boolean doPrepExec(TDSWriter tdsWriter,
buildServerCursorPrepExecParams(tdsWriter);
else
buildServerCursorExecParams(tdsWriter);
- }
- else {
+ } else {
// Move overhead of needing to do prepare & unprepare to only use cases that need more than one execution.
// First execution, use sp_executesql, optimizing for asumption we will not re-use statement.
if (needsPrepare && !connection.getEnablePrepareOnFirstPreparedStatementCall() && !isExecutedAtLeastOnce) {
@@ -1039,16 +1051,14 @@ public final java.sql.ResultSetMetaData getMetaData() throws SQLServerException
// if the result is closed, cant get the metadata from it.
if (resultSet != null)
resultSet.checkClosed();
- }
- catch (SQLServerException e) {
+ } catch (SQLServerException e) {
rsclosed = true;
}
if (resultSet == null || rsclosed) {
SQLServerResultSet emptyResultSet = (SQLServerResultSet) buildExecuteMetaData();
if (null != emptyResultSet)
rsmd = emptyResultSet.getMetaData();
- }
- else if (resultSet != null) {
+ } else if (resultSet != null) {
rsmd = resultSet.getMetaData();
}
loggerExternal.exiting(getClassNameLogging(), "getMetaData", rsmd);
@@ -1056,8 +1066,8 @@ else if (resultSet != null) {
}
/**
- * Retreive meta data for the statement before executing it. This is called in cases where the driver needs the meta data prior to executing the
- * statement.
+ * Returns meta data for the statement before executing it. This is called in cases where the driver needs the meta
+ * data prior to executing the statement.
*
* @throws SQLServerException
* @return the result set containing the meta data
@@ -1070,8 +1080,7 @@ private ResultSet buildExecuteMetaData() throws SQLServerException {
fmtSQL = replaceMarkerWithNull(fmtSQL);
internalStmt = (SQLServerStatement) connection.createStatement();
emptyResultSet = internalStmt.executeQueryInternal("set fmtonly on " + fmtSQL + "\nset fmtonly off");
- }
- catch (SQLException sqle) {
+ } catch (SQLException sqle) {
if (false == sqle.getMessage().equals(SQLServerException.getErrString("R_noResultset"))) {
// if the error is not no resultset then throw a processings error.
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_processingError"));
@@ -1086,13 +1095,13 @@ private ResultSet buildExecuteMetaData() throws SQLServerException {
/* -------------- JDBC API Implementation ------------------ */
/**
- * Set the parameter value for a statement.
+ * Sets the parameter value for a statement.
*
* @param index
- * The index of the parameter to set starting at 1.
+ * The index of the parameter to set starting at 1.
* @return A reference the to Parameter object created or referenced.
* @exception SQLServerException
- * The index specified was outside the number of paramters for the statement.
+ * The index specified was outside the number of paramters for the statement.
*/
final Parameter setterGetParam(int index) throws SQLServerException {
if (index < 1 || index > inOutParam.length) {
@@ -1104,64 +1113,45 @@ final Parameter setterGetParam(int index) throws SQLServerException {
return inOutParam[index - 1];
}
- final void setValue(int parameterIndex,
- JDBCType jdbcType,
- Object value,
- JavaType javaType,
+ final void setValue(int parameterIndex, JDBCType jdbcType, Object value, JavaType javaType,
String tvpName) throws SQLServerException {
- setterGetParam(parameterIndex).setValue(jdbcType, value, javaType, null, null, null, null, connection, false, stmtColumnEncriptionSetting,
- parameterIndex, userSQL, tvpName);
+ setterGetParam(parameterIndex).setValue(jdbcType, value, javaType, null, null, null, null, connection, false,
+ stmtColumnEncriptionSetting, parameterIndex, userSQL, tvpName);
}
- final void setValue(int parameterIndex,
- JDBCType jdbcType,
- Object value,
- JavaType javaType,
+ final void setValue(int parameterIndex, JDBCType jdbcType, Object value, JavaType javaType,
boolean forceEncrypt) throws SQLServerException {
- setterGetParam(parameterIndex).setValue(jdbcType, value, javaType, null, null, null, null, connection, forceEncrypt,
- stmtColumnEncriptionSetting, parameterIndex, userSQL, null);
+ setterGetParam(parameterIndex).setValue(jdbcType, value, javaType, null, null, null, null, connection,
+ forceEncrypt, stmtColumnEncriptionSetting, parameterIndex, userSQL, null);
}
- final void setValue(int parameterIndex,
- JDBCType jdbcType,
- Object value,
- JavaType javaType,
- Integer precision,
- Integer scale,
- boolean forceEncrypt) throws SQLServerException {
- setterGetParam(parameterIndex).setValue(jdbcType, value, javaType, null, null, precision, scale, connection, forceEncrypt,
- stmtColumnEncriptionSetting, parameterIndex, userSQL, null);
+ final void setValue(int parameterIndex, JDBCType jdbcType, Object value, JavaType javaType, Integer precision,
+ Integer scale, boolean forceEncrypt) throws SQLServerException {
+ setterGetParam(parameterIndex).setValue(jdbcType, value, javaType, null, null, precision, scale, connection,
+ forceEncrypt, stmtColumnEncriptionSetting, parameterIndex, userSQL, null);
}
- final void setValue(int parameterIndex,
- JDBCType jdbcType,
- Object value,
- JavaType javaType,
- Calendar cal,
+ final void setValue(int parameterIndex, JDBCType jdbcType, Object value, JavaType javaType, Calendar cal,
boolean forceEncrypt) throws SQLServerException {
- setterGetParam(parameterIndex).setValue(jdbcType, value, javaType, null, cal, null, null, connection, forceEncrypt,
- stmtColumnEncriptionSetting, parameterIndex, userSQL, null);
+ setterGetParam(parameterIndex).setValue(jdbcType, value, javaType, null, cal, null, null, connection,
+ forceEncrypt, stmtColumnEncriptionSetting, parameterIndex, userSQL, null);
}
- final void setStream(int parameterIndex,
- StreamType streamType,
- Object streamValue,
- JavaType javaType,
+ final void setStream(int parameterIndex, StreamType streamType, Object streamValue, JavaType javaType,
long length) throws SQLServerException {
- setterGetParam(parameterIndex).setValue(streamType.getJDBCType(), streamValue, javaType, new StreamSetterArgs(streamType, length), null, null,
- null, connection, false, stmtColumnEncriptionSetting, parameterIndex, userSQL, null);
+ setterGetParam(parameterIndex).setValue(streamType.getJDBCType(), streamValue, javaType,
+ new StreamSetterArgs(streamType, length), null, null, null, connection, false,
+ stmtColumnEncriptionSetting, parameterIndex, userSQL, null);
}
- final void setSQLXMLInternal(int parameterIndex,
- SQLXML value) throws SQLServerException {
+ final void setSQLXMLInternal(int parameterIndex, SQLXML value) throws SQLServerException {
setterGetParam(parameterIndex).setValue(JDBCType.SQLXML, value, JavaType.SQLXML,
- new StreamSetterArgs(StreamType.SQLXML, DataTypes.UNKNOWN_STREAM_LENGTH), null, null, null, connection, false,
- stmtColumnEncriptionSetting, parameterIndex, userSQL, null);
+ new StreamSetterArgs(StreamType.SQLXML, DataTypes.UNKNOWN_STREAM_LENGTH), null, null, null, connection,
+ false, stmtColumnEncriptionSetting, parameterIndex, userSQL, null);
}
@Override
- public final void setAsciiStream(int parameterIndex,
- InputStream x) throws SQLException {
+ public final void setAsciiStream(int parameterIndex, InputStream x) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setAsciiStream", new Object[] {parameterIndex, x});
checkClosed();
@@ -1170,9 +1160,7 @@ public final void setAsciiStream(int parameterIndex,
}
@Override
- public final void setAsciiStream(int n,
- java.io.InputStream x,
- int length) throws SQLServerException {
+ public final void setAsciiStream(int n, java.io.InputStream x, int length) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setAsciiStream", new Object[] {n, x, length});
checkClosed();
@@ -1181,9 +1169,7 @@ public final void setAsciiStream(int n,
}
@Override
- public final void setAsciiStream(int parameterIndex,
- InputStream x,
- long length) throws SQLException {
+ public final void setAsciiStream(int parameterIndex, InputStream x, long length) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setAsciiStream", new Object[] {parameterIndex, x, length});
checkClosed();
@@ -1192,8 +1178,7 @@ public final void setAsciiStream(int parameterIndex,
}
@Override
- public final void setBigDecimal(int paramterIndex,
- BigDecimal x) throws SQLServerException {
+ public final void setBigDecimal(int paramterIndex, BigDecimal x) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setBigDecimal", new Object[] {paramterIndex, x});
checkClosed();
@@ -1202,33 +1187,29 @@ public final void setBigDecimal(int paramterIndex,
}
@Override
- public final void setBigDecimal(int paramterIndex,
- BigDecimal x,
- int precision,
+ public final void setBigDecimal(int paramterIndex, BigDecimal x, int precision,
int scale) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "setBigDecimal", new Object[] {paramterIndex, x, precision, scale});
+ loggerExternal.entering(getClassNameLogging(), "setBigDecimal",
+ new Object[] {paramterIndex, x, precision, scale});
checkClosed();
setValue(paramterIndex, JDBCType.DECIMAL, x, JavaType.BIGDECIMAL, precision, scale, false);
loggerExternal.exiting(getClassNameLogging(), "setBigDecimal");
}
@Override
- public final void setBigDecimal(int paramterIndex,
- BigDecimal x,
- int precision,
- int scale,
+ public final void setBigDecimal(int paramterIndex, BigDecimal x, int precision, int scale,
boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "setBigDecimal", new Object[] {paramterIndex, x, precision, scale, forceEncrypt});
+ loggerExternal.entering(getClassNameLogging(), "setBigDecimal",
+ new Object[] {paramterIndex, x, precision, scale, forceEncrypt});
checkClosed();
setValue(paramterIndex, JDBCType.DECIMAL, x, JavaType.BIGDECIMAL, precision, scale, forceEncrypt);
loggerExternal.exiting(getClassNameLogging(), "setBigDecimal");
}
@Override
- public final void setMoney(int n,
- BigDecimal x) throws SQLServerException {
+ public final void setMoney(int n, BigDecimal x) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setMoney", new Object[] {n, x});
checkClosed();
@@ -1237,9 +1218,7 @@ public final void setMoney(int n,
}
@Override
- public final void setMoney(int n,
- BigDecimal x,
- boolean forceEncrypt) throws SQLServerException {
+ public final void setMoney(int n, BigDecimal x, boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setMoney", new Object[] {n, x, forceEncrypt});
checkClosed();
@@ -1248,8 +1227,7 @@ public final void setMoney(int n,
}
@Override
- public final void setSmallMoney(int n,
- BigDecimal x) throws SQLServerException {
+ public final void setSmallMoney(int n, BigDecimal x) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setSmallMoney", new Object[] {n, x});
checkClosed();
@@ -1258,9 +1236,7 @@ public final void setSmallMoney(int n,
}
@Override
- public final void setSmallMoney(int n,
- BigDecimal x,
- boolean forceEncrypt) throws SQLServerException {
+ public final void setSmallMoney(int n, BigDecimal x, boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setSmallMoney", new Object[] {n, x, forceEncrypt});
checkClosed();
@@ -1269,8 +1245,7 @@ public final void setSmallMoney(int n,
}
@Override
- public final void setBinaryStream(int parameterIndex,
- InputStream x) throws SQLException {
+ public final void setBinaryStream(int parameterIndex, InputStream x) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setBinaryStreaml", new Object[] {parameterIndex, x});
checkClosed();
@@ -1279,9 +1254,7 @@ public final void setBinaryStream(int parameterIndex,
}
@Override
- public final void setBinaryStream(int n,
- java.io.InputStream x,
- int length) throws SQLServerException {
+ public final void setBinaryStream(int n, java.io.InputStream x, int length) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setBinaryStream", new Object[] {n, x, length});
checkClosed();
@@ -1290,9 +1263,7 @@ public final void setBinaryStream(int n,
}
@Override
- public final void setBinaryStream(int parameterIndex,
- InputStream x,
- long length) throws SQLException {
+ public final void setBinaryStream(int parameterIndex, InputStream x, long length) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setBinaryStream", new Object[] {parameterIndex, x, length});
checkClosed();
@@ -1301,8 +1272,7 @@ public final void setBinaryStream(int parameterIndex,
}
@Override
- public final void setBoolean(int n,
- boolean x) throws SQLServerException {
+ public final void setBoolean(int n, boolean x) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setBoolean", new Object[] {n, x});
checkClosed();
@@ -1311,9 +1281,7 @@ public final void setBoolean(int n,
}
@Override
- public final void setBoolean(int n,
- boolean x,
- boolean forceEncrypt) throws SQLServerException {
+ public final void setBoolean(int n, boolean x, boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setBoolean", new Object[] {n, x, forceEncrypt});
checkClosed();
@@ -1322,8 +1290,7 @@ public final void setBoolean(int n,
}
@Override
- public final void setByte(int n,
- byte x) throws SQLServerException {
+ public final void setByte(int n, byte x) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setByte", new Object[] {n, x});
checkClosed();
@@ -1332,9 +1299,7 @@ public final void setByte(int n,
}
@Override
- public final void setByte(int n,
- byte x,
- boolean forceEncrypt) throws SQLServerException {
+ public final void setByte(int n, byte x, boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setByte", new Object[] {n, x, forceEncrypt});
checkClosed();
@@ -1343,8 +1308,7 @@ public final void setByte(int n,
}
@Override
- public final void setBytes(int n,
- byte x[]) throws SQLServerException {
+ public final void setBytes(int n, byte x[]) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setBytes", new Object[] {n, x});
checkClosed();
@@ -1353,9 +1317,7 @@ public final void setBytes(int n,
}
@Override
- public final void setBytes(int n,
- byte x[],
- boolean forceEncrypt) throws SQLServerException {
+ public final void setBytes(int n, byte x[], boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setBytes", new Object[] {n, x, forceEncrypt});
checkClosed();
@@ -1364,8 +1326,7 @@ public final void setBytes(int n,
}
@Override
- public final void setUniqueIdentifier(int index,
- String guid) throws SQLServerException {
+ public final void setUniqueIdentifier(int index, String guid) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setUniqueIdentifier", new Object[] {index, guid});
checkClosed();
@@ -1374,19 +1335,17 @@ public final void setUniqueIdentifier(int index,
}
@Override
- public final void setUniqueIdentifier(int index,
- String guid,
- boolean forceEncrypt) throws SQLServerException {
+ public final void setUniqueIdentifier(int index, String guid, boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "setUniqueIdentifier", new Object[] {index, guid, forceEncrypt});
+ loggerExternal.entering(getClassNameLogging(), "setUniqueIdentifier",
+ new Object[] {index, guid, forceEncrypt});
checkClosed();
setValue(index, JDBCType.GUID, guid, JavaType.STRING, forceEncrypt);
loggerExternal.exiting(getClassNameLogging(), "setUniqueIdentifier");
}
@Override
- public final void setDouble(int n,
- double x) throws SQLServerException {
+ public final void setDouble(int n, double x) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setDouble", new Object[] {n, x});
checkClosed();
@@ -1395,9 +1354,7 @@ public final void setDouble(int n,
}
@Override
- public final void setDouble(int n,
- double x,
- boolean forceEncrypt) throws SQLServerException {
+ public final void setDouble(int n, double x, boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setDouble", new Object[] {n, x, forceEncrypt});
checkClosed();
@@ -1406,8 +1363,7 @@ public final void setDouble(int n,
}
@Override
- public final void setFloat(int n,
- float x) throws SQLServerException {
+ public final void setFloat(int n, float x) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setFloat", new Object[] {n, x});
checkClosed();
@@ -1416,9 +1372,7 @@ public final void setFloat(int n,
}
@Override
- public final void setFloat(int n,
- float x,
- boolean forceEncrypt) throws SQLServerException {
+ public final void setFloat(int n, float x, boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setFloat", new Object[] {n, x, forceEncrypt});
checkClosed();
@@ -1427,8 +1381,7 @@ public final void setFloat(int n,
}
@Override
- public final void setGeometry(int n,
- Geometry x) throws SQLServerException {
+ public final void setGeometry(int n, Geometry x) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setGeometry", new Object[] {n, x});
checkClosed();
@@ -1437,8 +1390,7 @@ public final void setGeometry(int n,
}
@Override
- public final void setGeography(int n,
- Geography x) throws SQLServerException {
+ public final void setGeography(int n, Geography x) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setGeography", new Object[] {n, x});
checkClosed();
@@ -1447,8 +1399,7 @@ public final void setGeography(int n,
}
@Override
- public final void setInt(int n,
- int value) throws SQLServerException {
+ public final void setInt(int n, int value) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setInt", new Object[] {n, value});
checkClosed();
@@ -1457,9 +1408,7 @@ public final void setInt(int n,
}
@Override
- public final void setInt(int n,
- int value,
- boolean forceEncrypt) throws SQLServerException {
+ public final void setInt(int n, int value, boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setInt", new Object[] {n, value, forceEncrypt});
checkClosed();
@@ -1468,8 +1417,7 @@ public final void setInt(int n,
}
@Override
- public final void setLong(int n,
- long x) throws SQLServerException {
+ public final void setLong(int n, long x) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setLong", new Object[] {n, x});
checkClosed();
@@ -1478,9 +1426,7 @@ public final void setLong(int n,
}
@Override
- public final void setLong(int n,
- long x,
- boolean forceEncrypt) throws SQLServerException {
+ public final void setLong(int n, long x, boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setLong", new Object[] {n, x, forceEncrypt});
checkClosed();
@@ -1489,8 +1435,7 @@ public final void setLong(int n,
}
@Override
- public final void setNull(int index,
- int jdbcType) throws SQLServerException {
+ public final void setNull(int index, int jdbcType) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setNull", new Object[] {index, jdbcType});
checkClosed();
@@ -1498,9 +1443,7 @@ public final void setNull(int index,
loggerExternal.exiting(getClassNameLogging(), "setNull");
}
- final void setObjectNoType(int index,
- Object obj,
- boolean forceEncrypt) throws SQLServerException {
+ final void setObjectNoType(int index, Object obj, boolean forceEncrypt) throws SQLServerException {
// Default to the JDBC type of the parameter, determined by a previous setter call or through registerOutParam.
// This avoids repreparing unnecessarily for null values.
Parameter param = setterGetParam(index);
@@ -1514,14 +1457,14 @@ final void setObjectNoType(int index,
targetJDBCType = JDBCType.CHAR;
setObject(param, null, JavaType.OBJECT, targetJDBCType, null, null, forceEncrypt, index, null);
- }
- else {
+ } else {
JavaType javaType = JavaType.of(obj);
if (JavaType.TVP == javaType) {
- tvpName = getTVPNameIfNull(index, null); // will return null if called from preparedStatement
+ tvpName = getTVPNameIfNull(index, null); // will return null if called from preparedStatement
if ((null == tvpName) && (obj instanceof ResultSet)) {
- throw new SQLServerException(SQLServerException.getErrString("R_TVPnotWorkWithSetObjectResultSet"), null);
+ throw new SQLServerException(SQLServerException.getErrString("R_TVPnotWorkWithSetObjectResultSet"),
+ null);
}
}
targetJDBCType = javaType.getJDBCType(SSType.UNKNOWN, targetJDBCType);
@@ -1538,8 +1481,7 @@ final void setObjectNoType(int index,
}
@Override
- public final void setObject(int index,
- Object obj) throws SQLServerException {
+ public final void setObject(int index, Object obj) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setObject", new Object[] {index, obj});
checkClosed();
@@ -1548,9 +1490,7 @@ public final void setObject(int index,
}
@Override
- public final void setObject(int n,
- Object obj,
- int jdbcType) throws SQLServerException {
+ public final void setObject(int n, Object obj, int jdbcType) throws SQLServerException {
String tvpName = null;
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setObject", new Object[] {n, obj, jdbcType});
@@ -1562,12 +1502,11 @@ public final void setObject(int n,
}
@Override
- public final void setObject(int parameterIndex,
- Object x,
- int targetSqlType,
+ public final void setObject(int parameterIndex, Object x, int targetSqlType,
int scaleOrLength) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "setObject", new Object[] {parameterIndex, x, targetSqlType, scaleOrLength});
+ loggerExternal.entering(getClassNameLogging(), "setObject",
+ new Object[] {parameterIndex, x, targetSqlType, scaleOrLength});
checkClosed();
// scaleOrLength - for java.sql.Types.DECIMAL, java.sql.Types.NUMERIC or temporal types,
@@ -1576,22 +1515,21 @@ public final void setObject(int parameterIndex,
// For all other types, this value will be ignored.
setObject(setterGetParam(parameterIndex), x, JavaType.of(x), JDBCType.of(targetSqlType),
- (java.sql.Types.NUMERIC == targetSqlType || java.sql.Types.DECIMAL == targetSqlType || java.sql.Types.TIMESTAMP == targetSqlType
- || java.sql.Types.TIME == targetSqlType || microsoft.sql.Types.DATETIMEOFFSET == targetSqlType
- || InputStream.class.isInstance(x) || Reader.class.isInstance(x)) ? scaleOrLength : null,
+ (java.sql.Types.NUMERIC == targetSqlType || java.sql.Types.DECIMAL == targetSqlType
+ || java.sql.Types.TIMESTAMP == targetSqlType || java.sql.Types.TIME == targetSqlType
+ || microsoft.sql.Types.DATETIMEOFFSET == targetSqlType || InputStream.class.isInstance(x)
+ || Reader.class.isInstance(x)) ? scaleOrLength : null,
null, false, parameterIndex, null);
loggerExternal.exiting(getClassNameLogging(), "setObject");
}
@Override
- public final void setObject(int parameterIndex,
- Object x,
- int targetSqlType,
- Integer precision,
+ public final void setObject(int parameterIndex, Object x, int targetSqlType, Integer precision,
int scale) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "setObject", new Object[] {parameterIndex, x, targetSqlType, precision, scale});
+ loggerExternal.entering(getClassNameLogging(), "setObject",
+ new Object[] {parameterIndex, x, targetSqlType, precision, scale});
checkClosed();
// scale - for java.sql.Types.DECIMAL or java.sql.Types.NUMERIC types,
@@ -1599,20 +1537,16 @@ public final void setObject(int parameterIndex,
// InputStream and Reader, this is the length of the data in the stream or reader.
// For all other types, this value will be ignored.
- setObject(
- setterGetParam(parameterIndex), x, JavaType.of(x), JDBCType.of(targetSqlType), (java.sql.Types.NUMERIC == targetSqlType
- || java.sql.Types.DECIMAL == targetSqlType || InputStream.class.isInstance(x) || Reader.class.isInstance(x)) ? scale : null,
+ setObject(setterGetParam(parameterIndex), x, JavaType.of(x), JDBCType.of(targetSqlType),
+ (java.sql.Types.NUMERIC == targetSqlType || java.sql.Types.DECIMAL == targetSqlType
+ || InputStream.class.isInstance(x) || Reader.class.isInstance(x)) ? scale : null,
precision, false, parameterIndex, null);
loggerExternal.exiting(getClassNameLogging(), "setObject");
}
@Override
- public final void setObject(int parameterIndex,
- Object x,
- int targetSqlType,
- Integer precision,
- int scale,
+ public final void setObject(int parameterIndex, Object x, int targetSqlType, Integer precision, int scale,
boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setObject",
@@ -1624,23 +1558,16 @@ public final void setObject(int parameterIndex,
// InputStream and Reader, this is the length of the data in the stream or reader.
// For all other types, this value will be ignored.
- setObject(
- setterGetParam(parameterIndex), x, JavaType.of(x), JDBCType.of(targetSqlType), (java.sql.Types.NUMERIC == targetSqlType
- || java.sql.Types.DECIMAL == targetSqlType || InputStream.class.isInstance(x) || Reader.class.isInstance(x)) ? scale : null,
+ setObject(setterGetParam(parameterIndex), x, JavaType.of(x), JDBCType.of(targetSqlType),
+ (java.sql.Types.NUMERIC == targetSqlType || java.sql.Types.DECIMAL == targetSqlType
+ || InputStream.class.isInstance(x) || Reader.class.isInstance(x)) ? scale : null,
precision, forceEncrypt, parameterIndex, null);
loggerExternal.exiting(getClassNameLogging(), "setObject");
}
- final void setObject(Parameter param,
- Object obj,
- JavaType javaType,
- JDBCType jdbcType,
- Integer scale,
- Integer precision,
- boolean forceEncrypt,
- int parameterIndex,
- String tvpName) throws SQLServerException {
+ final void setObject(Parameter param, Object obj, JavaType javaType, JDBCType jdbcType, Integer scale,
+ Integer precision, boolean forceEncrypt, int parameterIndex, String tvpName) throws SQLServerException {
assert JDBCType.UNKNOWN != jdbcType;
// For non-null values, infer the object's JDBC type from its Java type
@@ -1661,7 +1588,8 @@ final void setObject(Parameter param,
break;
case INPUTSTREAM:
- streamSetterArgs = new StreamSetterArgs(jdbcType.isTextual() ? StreamType.CHARACTER : StreamType.BINARY,
+ streamSetterArgs = new StreamSetterArgs(
+ jdbcType.isTextual() ? StreamType.CHARACTER : StreamType.BINARY,
DataTypes.UNKNOWN_STREAM_LENGTH);
break;
@@ -1674,8 +1602,8 @@ final void setObject(Parameter param,
}
// typeInfo is set as null
- param.setValue(jdbcType, obj, javaType, streamSetterArgs, null, precision, scale, connection, forceEncrypt, stmtColumnEncriptionSetting,
- parameterIndex, userSQL, tvpName);
+ param.setValue(jdbcType, obj, javaType, streamSetterArgs, null, precision, scale, connection, forceEncrypt,
+ stmtColumnEncriptionSetting, parameterIndex, userSQL, tvpName);
}
// For null values, use the specified JDBC type directly, with the exception
@@ -1687,48 +1615,36 @@ final void setObject(Parameter param,
jdbcType = JDBCType.BINARY;
// typeInfo is set as null
- param.setValue(jdbcType, null, JavaType.OBJECT, null, null, precision, scale, connection, false, stmtColumnEncriptionSetting,
- parameterIndex, userSQL, tvpName);
+ param.setValue(jdbcType, null, JavaType.OBJECT, null, null, precision, scale, connection, false,
+ stmtColumnEncriptionSetting, parameterIndex, userSQL, tvpName);
}
}
@Override
- public final void setObject(int index,
- Object obj,
- SQLType jdbcType) throws SQLServerException {
+ public final void setObject(int index, Object obj, SQLType jdbcType) throws SQLServerException {
setObject(index, obj, jdbcType.getVendorTypeNumber());
}
@Override
- public final void setObject(int parameterIndex,
- Object x,
- SQLType targetSqlType,
+ public final void setObject(int parameterIndex, Object x, SQLType targetSqlType,
int scaleOrLength) throws SQLServerException {
setObject(parameterIndex, x, targetSqlType.getVendorTypeNumber(), scaleOrLength);
}
@Override
- public final void setObject(int parameterIndex,
- Object x,
- SQLType targetSqlType,
- Integer precision,
+ public final void setObject(int parameterIndex, Object x, SQLType targetSqlType, Integer precision,
Integer scale) throws SQLServerException {
setObject(parameterIndex, x, targetSqlType.getVendorTypeNumber(), precision, scale);
}
@Override
- public final void setObject(int parameterIndex,
- Object x,
- SQLType targetSqlType,
- Integer precision,
- Integer scale,
+ public final void setObject(int parameterIndex, Object x, SQLType targetSqlType, Integer precision, Integer scale,
boolean forceEncrypt) throws SQLServerException {
setObject(parameterIndex, x, targetSqlType.getVendorTypeNumber(), precision, scale, forceEncrypt);
}
@Override
- public final void setShort(int index,
- short x) throws SQLServerException {
+ public final void setShort(int index, short x) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setShort", new Object[] {index, x});
checkClosed();
@@ -1737,9 +1653,7 @@ public final void setShort(int index,
}
@Override
- public final void setShort(int index,
- short x,
- boolean forceEncrypt) throws SQLServerException {
+ public final void setShort(int index, short x, boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setShort", new Object[] {index, x, forceEncrypt});
checkClosed();
@@ -1748,8 +1662,7 @@ public final void setShort(int index,
}
@Override
- public final void setString(int index,
- String str) throws SQLServerException {
+ public final void setString(int index, String str) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setString", new Object[] {index, str});
checkClosed();
@@ -1758,9 +1671,7 @@ public final void setString(int index,
}
@Override
- public final void setString(int index,
- String str,
- boolean forceEncrypt) throws SQLServerException {
+ public final void setString(int index, String str, boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setString", new Object[] {index, str, forceEncrypt});
checkClosed();
@@ -1769,8 +1680,7 @@ public final void setString(int index,
}
@Override
- public final void setNString(int parameterIndex,
- String value) throws SQLException {
+ public final void setNString(int parameterIndex, String value) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setNString", new Object[] {parameterIndex, value});
checkClosed();
@@ -1779,19 +1689,17 @@ public final void setNString(int parameterIndex,
}
@Override
- public final void setNString(int parameterIndex,
- String value,
- boolean forceEncrypt) throws SQLServerException {
+ public final void setNString(int parameterIndex, String value, boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "setNString", new Object[] {parameterIndex, value, forceEncrypt});
+ loggerExternal.entering(getClassNameLogging(), "setNString",
+ new Object[] {parameterIndex, value, forceEncrypt});
checkClosed();
setValue(parameterIndex, JDBCType.NVARCHAR, value, JavaType.STRING, forceEncrypt);
loggerExternal.exiting(getClassNameLogging(), "setNString");
}
@Override
- public final void setTime(int n,
- java.sql.Time x) throws SQLServerException {
+ public final void setTime(int n, java.sql.Time x) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setTime", new Object[] {n, x});
checkClosed();
@@ -1800,9 +1708,7 @@ public final void setTime(int n,
}
@Override
- public final void setTime(int n,
- java.sql.Time x,
- int scale) throws SQLServerException {
+ public final void setTime(int n, java.sql.Time x, int scale) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setTime", new Object[] {n, x, scale});
checkClosed();
@@ -1811,10 +1717,7 @@ public final void setTime(int n,
}
@Override
- public final void setTime(int n,
- java.sql.Time x,
- int scale,
- boolean forceEncrypt) throws SQLServerException {
+ public final void setTime(int n, java.sql.Time x, int scale, boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setTime", new Object[] {n, x, scale, forceEncrypt});
checkClosed();
@@ -1823,8 +1726,7 @@ public final void setTime(int n,
}
@Override
- public final void setTimestamp(int n,
- java.sql.Timestamp x) throws SQLServerException {
+ public final void setTimestamp(int n, java.sql.Timestamp x) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setTimestamp", new Object[] {n, x});
checkClosed();
@@ -1833,9 +1735,7 @@ public final void setTimestamp(int n,
}
@Override
- public final void setTimestamp(int n,
- java.sql.Timestamp x,
- int scale) throws SQLServerException {
+ public final void setTimestamp(int n, java.sql.Timestamp x, int scale) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setTimestamp", new Object[] {n, x, scale});
checkClosed();
@@ -1844,9 +1744,7 @@ public final void setTimestamp(int n,
}
@Override
- public final void setTimestamp(int n,
- java.sql.Timestamp x,
- int scale,
+ public final void setTimestamp(int n, java.sql.Timestamp x, int scale,
boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setTimestamp", new Object[] {n, x, scale, forceEncrypt});
@@ -1856,8 +1754,7 @@ public final void setTimestamp(int n,
}
@Override
- public final void setDateTimeOffset(int n,
- microsoft.sql.DateTimeOffset x) throws SQLServerException {
+ public final void setDateTimeOffset(int n, microsoft.sql.DateTimeOffset x) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setDateTimeOffset", new Object[] {n, x});
checkClosed();
@@ -1866,9 +1763,7 @@ public final void setDateTimeOffset(int n,
}
@Override
- public final void setDateTimeOffset(int n,
- microsoft.sql.DateTimeOffset x,
- int scale) throws SQLServerException {
+ public final void setDateTimeOffset(int n, microsoft.sql.DateTimeOffset x, int scale) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setDateTimeOffset", new Object[] {n, x, scale});
checkClosed();
@@ -1877,20 +1772,18 @@ public final void setDateTimeOffset(int n,
}
@Override
- public final void setDateTimeOffset(int n,
- microsoft.sql.DateTimeOffset x,
- int scale,
+ public final void setDateTimeOffset(int n, microsoft.sql.DateTimeOffset x, int scale,
boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "setDateTimeOffset", new Object[] {n, x, scale, forceEncrypt});
+ loggerExternal.entering(getClassNameLogging(), "setDateTimeOffset",
+ new Object[] {n, x, scale, forceEncrypt});
checkClosed();
setValue(n, JDBCType.DATETIMEOFFSET, x, JavaType.DATETIMEOFFSET, null, scale, forceEncrypt);
loggerExternal.exiting(getClassNameLogging(), "setDateTimeOffset");
}
@Override
- public final void setDate(int n,
- java.sql.Date x) throws SQLServerException {
+ public final void setDate(int n, java.sql.Date x) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setDate", new Object[] {n, x});
checkClosed();
@@ -1899,8 +1792,7 @@ public final void setDate(int n,
}
@Override
- public final void setDateTime(int n,
- java.sql.Timestamp x) throws SQLServerException {
+ public final void setDateTime(int n, java.sql.Timestamp x) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setDateTime", new Object[] {n, x});
checkClosed();
@@ -1909,9 +1801,7 @@ public final void setDateTime(int n,
}
@Override
- public final void setDateTime(int n,
- java.sql.Timestamp x,
- boolean forceEncrypt) throws SQLServerException {
+ public final void setDateTime(int n, java.sql.Timestamp x, boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setDateTime", new Object[] {n, x, forceEncrypt});
checkClosed();
@@ -1920,8 +1810,7 @@ public final void setDateTime(int n,
}
@Override
- public final void setSmallDateTime(int n,
- java.sql.Timestamp x) throws SQLServerException {
+ public final void setSmallDateTime(int n, java.sql.Timestamp x) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setSmallDateTime", new Object[] {n, x});
checkClosed();
@@ -1930,9 +1819,7 @@ public final void setSmallDateTime(int n,
}
@Override
- public final void setSmallDateTime(int n,
- java.sql.Timestamp x,
- boolean forceEncrypt) throws SQLServerException {
+ public final void setSmallDateTime(int n, java.sql.Timestamp x, boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setSmallDateTime", new Object[] {n, x, forceEncrypt});
checkClosed();
@@ -1941,9 +1828,7 @@ public final void setSmallDateTime(int n,
}
@Override
- public final void setStructured(int n,
- String tvpName,
- SQLServerDataTable tvpDataTable) throws SQLServerException {
+ public final void setStructured(int n, String tvpName, SQLServerDataTable tvpDataTable) throws SQLServerException {
tvpName = getTVPNameIfNull(n, tvpName);
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setStructured", new Object[] {n, tvpName, tvpDataTable});
@@ -1953,9 +1838,7 @@ public final void setStructured(int n,
}
@Override
- public final void setStructured(int n,
- String tvpName,
- ResultSet tvpResultSet) throws SQLServerException {
+ public final void setStructured(int n, String tvpName, ResultSet tvpResultSet) throws SQLServerException {
tvpName = getTVPNameIfNull(n, tvpName);
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setStructured", new Object[] {n, tvpName, tvpResultSet});
@@ -1965,8 +1848,7 @@ public final void setStructured(int n,
}
@Override
- public final void setStructured(int n,
- String tvpName,
+ public final void setStructured(int n, String tvpName,
ISQLServerDataRecord tvpBulkRecord) throws SQLServerException {
tvpName = getTVPNameIfNull(n, tvpName);
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
@@ -1976,8 +1858,7 @@ public final void setStructured(int n,
loggerExternal.exiting(getClassNameLogging(), "setStructured");
}
- String getTVPNameIfNull(int n,
- String tvpName) throws SQLServerException {
+ String getTVPNameIfNull(int n, String tvpName) throws SQLServerException {
if ((null == tvpName) || (0 == tvpName.length())) {
// Check if the CallableStatement/PreparedStatement is a stored procedure call
if (null != this.procedureName) {
@@ -1985,7 +1866,8 @@ String getTVPNameIfNull(int n,
pmd.isTVP = true;
if (!pmd.procedureIsFound) {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_StoredProcedureNotFound"));
+ MessageFormat form = new MessageFormat(
+ SQLServerException.getErrString("R_StoredProcedureNotFound"));
Object[] msgArgs = {this.procedureName};
SQLServerException.makeFromDriverError(connection, pmd, form.format(msgArgs), null, false);
}
@@ -1996,13 +1878,12 @@ String getTVPNameIfNull(int n,
if (null != tvpSchema) {
tvpName = "[" + tvpSchema + "].[" + tvpNameWithoutSchema + "]";
- }
- else {
+ } else {
tvpName = tvpNameWithoutSchema;
}
- }
- catch (SQLException e) {
- throw new SQLServerException(SQLServerException.getErrString("R_metaDataErrorForParameter"), null, 0, e);
+ } catch (SQLException e) {
+ throw new SQLServerException(SQLServerException.getErrString("R_metaDataErrorForParameter"), null,
+ 0, e);
}
}
}
@@ -2011,9 +1892,7 @@ String getTVPNameIfNull(int n,
@Deprecated
@Override
- public final void setUnicodeStream(int n,
- java.io.InputStream x,
- int length) throws SQLException {
+ public final void setUnicodeStream(int n, java.io.InputStream x, int length) throws SQLException {
SQLServerException.throwNotSupportedException(connection, this);
}
@@ -2050,13 +1929,13 @@ public int[] executeBatch() throws SQLServerException, BatchUpdateException, SQL
}
checkClosed();
discardLastExecutionResults();
-
+
int updateCounts[];
-
+
localUserSQL = userSQL;
-
+
try {
- if (isInsert(localUserSQL) && connection.isAzureDW() && (this.useBulkCopyForBatchInsert)) {
+ if (this.useBulkCopyForBatchInsert && connection.isAzureDW() && isInsert(localUserSQL)) {
// From the JDBC spec, section 9.1.4 - Making Batch Updates:
// The CallableStatement.executeBatch method (inherited from PreparedStatement) will
// throw a BatchUpdateException if the stored procedure returns anything other than an
@@ -2070,11 +1949,12 @@ public int[] executeBatch() throws SQLServerException, BatchUpdateException, SQL
for (Parameter[] paramValues : batchParamValues) {
for (Parameter paramValue : paramValues) {
if (paramValue.isOutput()) {
- throw new BatchUpdateException(SQLServerException.getErrString("R_outParamsNotPermittedinBatch"), null, 0, null);
+ throw new BatchUpdateException(
+ SQLServerException.getErrString("R_outParamsNotPermittedinBatch"), null, 0, null);
}
}
}
-
+
if (batchParamValues == null) {
updateCounts = new int[0];
loggerExternal.exiting(getClassNameLogging(), "executeBatch", updateCounts);
@@ -2085,25 +1965,37 @@ public int[] executeBatch() throws SQLServerException, BatchUpdateException, SQL
ArrayList columnList = parseUserSQLForColumnListDW();
ArrayList valueList = parseUserSQLForValueListDW(false);
- String destinationTableName = tableName;
- SQLServerStatement stmt = (SQLServerStatement) connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY,
- connection.getHoldability(), stmtColumnEncriptionSetting);
-
- // Get destination metadata
- try (SQLServerResultSet rs = stmt
- .executeQueryInternal("sp_executesql N'SET FMTONLY ON SELECT * FROM " + destinationTableName + " '");) {
+ checkAdditionalQuery();
+
+ try (SQLServerStatement stmt = (SQLServerStatement) connection.createStatement(
+ ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, connection.getHoldability(),
+ stmtColumnEncriptionSetting);
+ SQLServerResultSet rs = stmt.executeQueryInternal(
+ "sp_executesql N'SET FMTONLY ON SELECT * FROM " + tableName + " '");) {
+ if (null != columnList && columnList.size() > 0) {
+ if (columnList.size() != valueList.size()) {
+ throw new IllegalArgumentException(
+ "Number of provided columns does not match the table definition.");
+ }
+ } else {
+ if (rs.getColumnCount() != valueList.size()) {
+ throw new IllegalArgumentException(
+ "Number of provided columns does not match the table definition.");
+ }
+ }
- SQLServerBulkBatchInsertRecord batchRecord = new SQLServerBulkBatchInsertRecord(batchParamValues, columnList, valueList, null);
+ SQLServerBulkBatchInsertRecord batchRecord = new SQLServerBulkBatchInsertRecord(batchParamValues,
+ columnList, valueList, null);
for (int i = 1; i <= rs.getColumnCount(); i++) {
Column c = rs.getColumn(i);
CryptoMetadata cryptoMetadata = c.getCryptoMetadata();
int jdbctype;
TypeInfo ti = c.getTypeInfo();
+ checkValidColumns(ti);
if (null != cryptoMetadata) {
jdbctype = cryptoMetadata.getBaseTypeInfo().getSSType().getJDBCType().getIntValue();
- }
- else {
+ } else {
jdbctype = ti.getSSType().getJDBCType().getIntValue();
}
batchRecord.addColumnMetadata(i, c.getColumnName(), jdbctype, ti.getPrecision(), ti.getScale());
@@ -2124,20 +2016,14 @@ public int[] executeBatch() throws SQLServerException, BatchUpdateException, SQL
loggerExternal.exiting(getClassNameLogging(), "executeBatch", updateCounts);
return updateCounts;
}
- finally {
- if (null != stmt)
- stmt.close();
- }
}
- }
- catch (SQLException e) {
+ } catch (SQLException e) {
// throw a BatchUpdateException with the given error message, and return null for the updateCounts.
throw new BatchUpdateException(e.getMessage(), null, 0, null);
- }
- catch (IllegalArgumentException e) {
+ } catch (IllegalArgumentException e) {
// If we fail with IllegalArgumentException, fall back to the original batch insert logic.
if (getStatementLogger().isLoggable(java.util.logging.Level.FINE)) {
- getStatementLogger().fine("Parsing user's Batch Insert SQL Query failed: " + e.toString());
+ getStatementLogger().fine("Parsing user's Batch Insert SQL Query failed: " + e.getMessage());
getStatementLogger().fine("Falling back to the original implementation for Batch Insert.");
}
}
@@ -2159,7 +2045,8 @@ public int[] executeBatch() throws SQLServerException, BatchUpdateException, SQL
for (Parameter[] paramValues : batchParamValues) {
for (Parameter paramValue : paramValues) {
if (paramValue.isOutput()) {
- throw new BatchUpdateException(SQLServerException.getErrString("R_outParamsNotPermittedinBatch"), null, 0, null);
+ throw new BatchUpdateException(
+ SQLServerException.getErrString("R_outParamsNotPermittedinBatch"), null, 0, null);
}
}
}
@@ -2174,12 +2061,12 @@ public int[] executeBatch() throws SQLServerException, BatchUpdateException, SQL
// Transform the SQLException into a BatchUpdateException with the update counts.
if (null != batchCommand.batchException) {
- throw new BatchUpdateException(batchCommand.batchException.getMessage(), batchCommand.batchException.getSQLState(),
- batchCommand.batchException.getErrorCode(), updateCounts);
+ throw new BatchUpdateException(batchCommand.batchException.getMessage(),
+ batchCommand.batchException.getSQLState(), batchCommand.batchException.getErrorCode(),
+ updateCounts);
}
- }
- finally {
+ } finally {
batchParamValues = null;
}
@@ -2197,11 +2084,11 @@ public long[] executeLargeBatch() throws SQLServerException, BatchUpdateExceptio
discardLastExecutionResults();
long updateCounts[];
-
+
localUserSQL = userSQL;
-
+
try {
- if (isInsert(localUserSQL) && connection.isAzureDW() && (this.useBulkCopyForBatchInsert)) {
+ if (this.useBulkCopyForBatchInsert && connection.isAzureDW() && isInsert(localUserSQL)) {
// From the JDBC spec, section 9.1.4 - Making Batch Updates:
// The CallableStatement.executeBatch method (inherited from PreparedStatement) will
// throw a BatchUpdateException if the stored procedure returns anything other than an
@@ -2215,11 +2102,12 @@ public long[] executeLargeBatch() throws SQLServerException, BatchUpdateExceptio
for (Parameter[] paramValues : batchParamValues) {
for (Parameter paramValue : paramValues) {
if (paramValue.isOutput()) {
- throw new BatchUpdateException(SQLServerException.getErrString("R_outParamsNotPermittedinBatch"), null, 0, null);
+ throw new BatchUpdateException(
+ SQLServerException.getErrString("R_outParamsNotPermittedinBatch"), null, 0, null);
}
}
}
-
+
if (batchParamValues == null) {
updateCounts = new long[0];
loggerExternal.exiting(getClassNameLogging(), "executeLargeBatch", updateCounts);
@@ -2230,25 +2118,37 @@ public long[] executeLargeBatch() throws SQLServerException, BatchUpdateExceptio
ArrayList columnList = parseUserSQLForColumnListDW();
ArrayList valueList = parseUserSQLForValueListDW(false);
- String destinationTableName = tableName;
- SQLServerStatement stmt = (SQLServerStatement) connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY,
- connection.getHoldability(), stmtColumnEncriptionSetting);
-
- // Get destination metadata
- try (SQLServerResultSet rs = stmt
- .executeQueryInternal("sp_executesql N'SET FMTONLY ON SELECT * FROM " + destinationTableName + " '");) {
+ checkAdditionalQuery();
+
+ try (SQLServerStatement stmt = (SQLServerStatement) connection.createStatement(
+ ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, connection.getHoldability(),
+ stmtColumnEncriptionSetting);
+ SQLServerResultSet rs = stmt.executeQueryInternal(
+ "sp_executesql N'SET FMTONLY ON SELECT * FROM " + tableName + " '");) {
+ if (null != columnList && columnList.size() > 0) {
+ if (columnList.size() != valueList.size()) {
+ throw new IllegalArgumentException(
+ "Number of provided columns does not match the table definition.");
+ }
+ } else {
+ if (rs.getColumnCount() != valueList.size()) {
+ throw new IllegalArgumentException(
+ "Number of provided columns does not match the table definition.");
+ }
+ }
- SQLServerBulkBatchInsertRecord batchRecord = new SQLServerBulkBatchInsertRecord(batchParamValues, columnList, valueList, null);
+ SQLServerBulkBatchInsertRecord batchRecord = new SQLServerBulkBatchInsertRecord(batchParamValues,
+ columnList, valueList, null);
for (int i = 1; i <= rs.getColumnCount(); i++) {
Column c = rs.getColumn(i);
CryptoMetadata cryptoMetadata = c.getCryptoMetadata();
int jdbctype;
TypeInfo ti = c.getTypeInfo();
+ checkValidColumns(ti);
if (null != cryptoMetadata) {
jdbctype = cryptoMetadata.getBaseTypeInfo().getSSType().getJDBCType().getIntValue();
- }
- else {
+ } else {
jdbctype = ti.getSSType().getJDBCType().getIntValue();
}
batchRecord.addColumnMetadata(i, c.getColumnName(), jdbctype, ti.getPrecision(), ti.getScale());
@@ -2269,20 +2169,14 @@ public long[] executeLargeBatch() throws SQLServerException, BatchUpdateExceptio
loggerExternal.exiting(getClassNameLogging(), "executeLargeBatch", updateCounts);
return updateCounts;
}
- finally {
- if (null != stmt)
- stmt.close();
- }
}
- }
- catch (SQLException e) {
+ } catch (SQLException e) {
// throw a BatchUpdateException with the given error message, and return null for the updateCounts.
throw new BatchUpdateException(e.getMessage(), null, 0, null);
- }
- catch (IllegalArgumentException e) {
+ } catch (IllegalArgumentException e) {
// If we fail with IllegalArgumentException, fall back to the original batch insert logic.
if (getStatementLogger().isLoggable(java.util.logging.Level.FINE)) {
- getStatementLogger().fine("Parsing user's Batch Insert SQL Query failed: " + e.toString());
+ getStatementLogger().fine("Parsing user's Batch Insert SQL Query failed: " + e.getMessage());
getStatementLogger().fine("Falling back to the original implementation for Batch Insert.");
}
}
@@ -2304,7 +2198,8 @@ public long[] executeLargeBatch() throws SQLServerException, BatchUpdateExceptio
for (Parameter[] paramValues : batchParamValues) {
for (Parameter paramValue : paramValues) {
if (paramValue.isOutput()) {
- throw new BatchUpdateException(SQLServerException.getErrString("R_outParamsNotPermittedinBatch"), null, 0, null);
+ throw new BatchUpdateException(
+ SQLServerException.getErrString("R_outParamsNotPermittedinBatch"), null, 0, null);
}
}
}
@@ -2322,33 +2217,87 @@ public long[] executeLargeBatch() throws SQLServerException, BatchUpdateExceptio
DriverJDBCVersion.throwBatchUpdateException(batchCommand.batchException, updateCounts);
}
- }
- finally {
+ } finally {
batchParamValues = null;
}
loggerExternal.exiting(getClassNameLogging(), "executeLargeBatch", updateCounts);
return updateCounts;
}
-
-
- private String parseUserSQLForTableNameDW(boolean hasInsertBeenFound, boolean hasIntoBeenFound, boolean hasTableBeenFound,
- boolean isExpectingTableName) {
+
+ private void checkValidColumns(TypeInfo ti) throws SQLServerException {
+ int jdbctype = ti.getSSType().getJDBCType().getIntValue();
+ // currently, we do not support: geometry, geography, datetime and smalldatetime
+ switch (jdbctype) {
+ case java.sql.Types.INTEGER:
+ case java.sql.Types.SMALLINT:
+ case java.sql.Types.BIGINT:
+ case java.sql.Types.BIT:
+ case java.sql.Types.TINYINT:
+ case java.sql.Types.DOUBLE:
+ case java.sql.Types.REAL:
+ case microsoft.sql.Types.MONEY:
+ case microsoft.sql.Types.SMALLMONEY:
+ case java.sql.Types.DECIMAL:
+ case java.sql.Types.NUMERIC:
+ case microsoft.sql.Types.GUID:
+ case java.sql.Types.CHAR:
+ case java.sql.Types.NCHAR:
+ case java.sql.Types.LONGVARCHAR:
+ case java.sql.Types.VARCHAR:
+ case java.sql.Types.LONGNVARCHAR:
+ case java.sql.Types.NVARCHAR:
+ case java.sql.Types.BINARY:
+ case java.sql.Types.LONGVARBINARY:
+ case java.sql.Types.VARBINARY:
+ // Spatial datatypes fall under Varbinary, check if the UDT is geometry/geography.
+ String typeName = ti.getSSTypeName();
+ if (typeName.equalsIgnoreCase("geometry") || typeName.equalsIgnoreCase("geography")) {
+ MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_BulkTypeNotSupported"));
+ throw new IllegalArgumentException(form.format(new Object[] {typeName}));
+ }
+ case java.sql.Types.TIMESTAMP:
+ case java.sql.Types.DATE:
+ case java.sql.Types.TIME:
+ case 2013: // java.sql.Types.TIME_WITH_TIMEZONE
+ case 2014: // java.sql.Types.TIMESTAMP_WITH_TIMEZONE
+ case microsoft.sql.Types.DATETIMEOFFSET:
+ case microsoft.sql.Types.SQL_VARIANT:
+ return;
+ default: {
+ MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_BulkTypeNotSupported"));
+ String unsupportedDataType = JDBCType.of(jdbctype).toString();
+ throw new IllegalArgumentException(form.format(new Object[] {unsupportedDataType}));
+ }
+ }
+ }
+
+ private void checkAdditionalQuery() {
+ while (checkAndRemoveCommentsAndSpace(true)) {}
+
+ // At this point, if localUserSQL is not empty (after removing all whitespaces, semicolons and comments), we
+ // have a
+ // new query. reject this.
+ if (localUserSQL.length() > 0) {
+ throw new IllegalArgumentException("Multiple queries are not allowed.");
+ }
+ }
+
+ private String parseUserSQLForTableNameDW(boolean hasInsertBeenFound, boolean hasIntoBeenFound,
+ boolean hasTableBeenFound, boolean isExpectingTableName) {
// As far as finding the table name goes, There are two cases:
// Insert into and Insert
// And there could be in-line comments (with /* and */) in between.
// This method assumes the localUserSQL string starts with "insert".
- localUserSQL = localUserSQL.trim();
- if (checkAndRemoveComments()) {
- return parseUserSQLForTableNameDW(hasInsertBeenFound, hasIntoBeenFound, hasTableBeenFound, isExpectingTableName);
- }
-
+ while (checkAndRemoveCommentsAndSpace(false)) {}
+
StringBuilder sb = new StringBuilder();
-
- // If table has been found and the next character is not a . at this point, we've finished parsing the table name.
+
+ // If table has been found and the next character is not a . at this point, we've finished parsing the table
+ // name.
// This if statement is needed to handle the case where the user has something like:
- // [dbo] . /* random comment */ [tableName]
+ // [dbo] . /* random comment */ [tableName]
if (hasTableBeenFound && !isExpectingTableName) {
- if (localUserSQL.substring(0, 1).equalsIgnoreCase(".")) {
+ if (checkSQLLength(1) && localUserSQL.substring(0, 1).equalsIgnoreCase(".")) {
sb.append(".");
localUserSQL = localUserSQL.substring(1);
return sb.toString() + parseUserSQLForTableNameDW(true, true, true, true);
@@ -2356,87 +2305,98 @@ private String parseUserSQLForTableNameDW(boolean hasInsertBeenFound, boolean ha
return "";
}
}
-
- if (localUserSQL.substring(0, 6).equalsIgnoreCase("insert") && !hasInsertBeenFound) {
+
+ if (!hasInsertBeenFound && checkSQLLength(6) && localUserSQL.substring(0, 6).equalsIgnoreCase("insert")) {
localUserSQL = localUserSQL.substring(6);
return parseUserSQLForTableNameDW(true, hasIntoBeenFound, hasTableBeenFound, isExpectingTableName);
}
-
- if (localUserSQL.substring(0, 4).equalsIgnoreCase("into") && !hasIntoBeenFound) {
+
+ if (!hasIntoBeenFound && checkSQLLength(6) && localUserSQL.substring(0, 4).equalsIgnoreCase("into")) {
// is it really "into"?
// if the "into" is followed by a blank space or /*, then yes.
- if (Character.isWhitespace(localUserSQL.charAt(4)) ||
- (localUserSQL.charAt(4) == '/' && localUserSQL.charAt(5) == '*')) {
+ if (Character.isWhitespace(localUserSQL.charAt(4))
+ || (localUserSQL.charAt(4) == '/' && localUserSQL.charAt(5) == '*')) {
localUserSQL = localUserSQL.substring(4);
return parseUserSQLForTableNameDW(hasInsertBeenFound, true, hasTableBeenFound, isExpectingTableName);
}
-
+
// otherwise, we found the token that either contains the databasename.tablename or tablename.
- // Recursively handle this, but into has been found. (or rather, it's absent in the query - the "into" keyword is optional)
+ // Recursively handle this, but into has been found. (or rather, it's absent in the query - the "into"
+ // keyword is optional)
return parseUserSQLForTableNameDW(hasInsertBeenFound, true, hasTableBeenFound, isExpectingTableName);
}
-
+
// At this point, the next token has to be the table name.
// It could be encapsulated in [], "", or have a database name preceding the table name.
// If it's encapsulated in [] or "", we need be more careful with parsing as anything could go into []/"".
// For ] or ", they can be escaped by ]] or "", watch out for this too.
- if (localUserSQL.substring(0, 1).equalsIgnoreCase("[")) {
+ if (checkSQLLength(1) && localUserSQL.substring(0, 1).equalsIgnoreCase("[")) {
int tempint = localUserSQL.indexOf("]", 1);
-
+
+ // ] has not been found, this is wrong.
+ if (tempint < 0) {
+ throw new IllegalArgumentException("Invalid SQL Query.");
+ }
+
// keep checking if it's escaped
- while (localUserSQL.charAt(tempint + 1) == ']') {
+ while (tempint >= 0 && checkSQLLength(tempint + 2) && localUserSQL.charAt(tempint + 1) == ']') {
tempint = localUserSQL.indexOf("]", tempint + 2);
}
-
+
// we've found a ] that is actually trying to close the square bracket.
// return tablename + potentially more that's part of the table name
sb.append(localUserSQL.substring(0, tempint + 1));
localUserSQL = localUserSQL.substring(tempint + 1);
return sb.toString() + parseUserSQLForTableNameDW(true, true, true, false);
}
-
+
// do the same for ""
- if (localUserSQL.substring(0, 1).equalsIgnoreCase("\"")) {
+ if (checkSQLLength(1) && localUserSQL.substring(0, 1).equalsIgnoreCase("\"")) {
int tempint = localUserSQL.indexOf("\"", 1);
-
+
+ // \" has not been found, this is wrong.
+ if (tempint < 0) {
+ throw new IllegalArgumentException("Invalid SQL Query.");
+ }
+
// keep checking if it's escaped
- while (localUserSQL.charAt(tempint + 1) == '\"') {
+ while (tempint >= 0 && checkSQLLength(tempint + 2) && localUserSQL.charAt(tempint + 1) == '\"') {
tempint = localUserSQL.indexOf("\"", tempint + 2);
}
-
+
// we've found a " that is actually trying to close the quote.
// return tablename + potentially more that's part of the table name
sb.append(localUserSQL.substring(0, tempint + 1));
localUserSQL = localUserSQL.substring(tempint + 1);
return sb.toString() + parseUserSQLForTableNameDW(true, true, true, false);
}
-
+
// At this point, the next chunk of string is the table name, without starting with [ or ".
while (localUserSQL.length() > 0) {
- // Keep going until the end of the table name is signalled - either a ., whitespace, or comment is encountered
- if (localUserSQL.charAt(0) == '.' || Character.isWhitespace(localUserSQL.charAt(0)) || checkAndRemoveComments()) {
+ // Keep going until the end of the table name is signalled - either a ., whitespace, ; or comment is
+ // encountered.
+ if (localUserSQL.charAt(0) == '.' || Character.isWhitespace(localUserSQL.charAt(0))
+ || checkAndRemoveCommentsAndSpace(false)) {
return sb.toString() + parseUserSQLForTableNameDW(true, true, true, false);
+ } else if (localUserSQL.charAt(0) == ';') {
+ throw new IllegalArgumentException("End of query detected before VALUES have been found.");
} else {
sb.append(localUserSQL.charAt(0));
localUserSQL = localUserSQL.substring(1);
}
}
-
+
// It shouldn't come here. If we did, something is wrong.
- throw new IllegalArgumentException("localUserSQL");
+ throw new IllegalArgumentException("Invalid SQL Query.");
}
-
+
private ArrayList parseUserSQLForColumnListDW() {
- localUserSQL = localUserSQL.trim();
-
// ignore all comments
- if (checkAndRemoveComments()) {
- return parseUserSQLForColumnListDW();
- }
-
- //check if optional column list was provided
+ while (checkAndRemoveCommentsAndSpace(false)) {}
+
+ // check if optional column list was provided
// Columns can have the form of c1, [c1] or "c1". It can escape ] or " by ]] or "".
- if (localUserSQL.substring(0, 1).equalsIgnoreCase("(")) {
+ if (checkSQLLength(1) && localUserSQL.substring(0, 1).equalsIgnoreCase("(")) {
localUserSQL = localUserSQL.substring(1);
return parseUserSQLForColumnListDWHelper(new ArrayList());
}
@@ -2444,201 +2404,229 @@ private ArrayList parseUserSQLForColumnListDW() {
}
private ArrayList parseUserSQLForColumnListDWHelper(ArrayList listOfColumns) {
- localUserSQL = localUserSQL.trim();
-
// ignore all comments
- if (checkAndRemoveComments()) {
- return parseUserSQLForColumnListDWHelper(listOfColumns);
- }
-
- if (localUserSQL.charAt(0) == ')') {
- localUserSQL = localUserSQL.substring(1);
- return listOfColumns;
- }
-
- if (localUserSQL.charAt(0) == ',') {
- localUserSQL = localUserSQL.substring(1);
- return parseUserSQLForColumnListDWHelper(listOfColumns);
- }
-
- if (localUserSQL.charAt(0) == '[') {
- int tempint = localUserSQL.indexOf("]", 1);
-
- // keep checking if it's escaped
- while (localUserSQL.charAt(tempint + 1) == ']') {
- localUserSQL = localUserSQL.substring(0, tempint) + localUserSQL.substring(tempint + 1);
- tempint = localUserSQL.indexOf("]", tempint + 1);
- }
-
- // we've found a ] that is actually trying to close the square bracket.
- String tempstr = localUserSQL.substring(1, tempint);
- localUserSQL = localUserSQL.substring(tempint + 1);
- listOfColumns.add(tempstr);
- return parseUserSQLForColumnListDWHelper(listOfColumns);
- }
-
- if (localUserSQL.charAt(0) == '\"') {
- int tempint = localUserSQL.indexOf("\"", 1);
-
- // keep checking if it's escaped
- while (localUserSQL.charAt(tempint + 1) == '\"') {
- localUserSQL = localUserSQL.substring(0, tempint) + localUserSQL.substring(tempint + 1);
- tempint = localUserSQL.indexOf("\"", tempint + 1);
- }
-
- // we've found a " that is actually trying to close the quote.
- String tempstr = localUserSQL.substring(1, tempint);
- localUserSQL = localUserSQL.substring(tempint + 1);
- listOfColumns.add(tempstr);
- return parseUserSQLForColumnListDWHelper(listOfColumns);
- }
+ while (checkAndRemoveCommentsAndSpace(false)) {}
- // At this point, the next chunk of string is the column name, without starting with [ or ".
StringBuilder sb = new StringBuilder();
while (localUserSQL.length() > 0) {
- if (localUserSQL.charAt(0) == ',') {
- localUserSQL = localUserSQL.substring(1);
- listOfColumns.add(sb.toString());
- return parseUserSQLForColumnListDWHelper(listOfColumns);
- } else if (localUserSQL.charAt(0) == ')'){
+ while (checkAndRemoveCommentsAndSpace(false)) {}
+
+ // exit condition
+ if (checkSQLLength(1) && localUserSQL.charAt(0) == ')') {
localUserSQL = localUserSQL.substring(1);
- listOfColumns.add(sb.toString());
return listOfColumns;
- } else if (checkAndRemoveComments()) {
- localUserSQL = localUserSQL.trim();
- } else {
- sb.append(localUserSQL.charAt(0));
+ }
+
+ // ignore ,
+ // we've confirmed length is more than 0.
+ if (localUserSQL.charAt(0) == ',') {
localUserSQL = localUserSQL.substring(1);
- localUserSQL = localUserSQL.trim();
+ while (checkAndRemoveCommentsAndSpace(false)) {}
+ }
+
+ // handle [] case
+ if (localUserSQL.charAt(0) == '[') {
+ int tempint = localUserSQL.indexOf("]", 1);
+
+ // ] has not been found, this is wrong.
+ if (tempint < 0) {
+ throw new IllegalArgumentException("Invalid SQL Query.");
+ }
+
+ // keep checking if it's escaped
+ while (tempint >= 0 && checkSQLLength(tempint + 2) && localUserSQL.charAt(tempint + 1) == ']') {
+ localUserSQL = localUserSQL.substring(0, tempint) + localUserSQL.substring(tempint + 1);
+ tempint = localUserSQL.indexOf("]", tempint + 1);
+ }
+
+ // we've found a ] that is actually trying to close the square bracket.
+ String tempstr = localUserSQL.substring(1, tempint);
+ localUserSQL = localUserSQL.substring(tempint + 1);
+ listOfColumns.add(tempstr);
+ continue; // proceed with the rest of the string
+ }
+
+ // handle "" case
+ if (localUserSQL.charAt(0) == '\"') {
+ int tempint = localUserSQL.indexOf("\"", 1);
+
+ // \" has not been found, this is wrong.
+ if (tempint < 0) {
+ throw new IllegalArgumentException("Invalid SQL Query.");
+ }
+
+ // keep checking if it's escaped
+ while (tempint >= 0 && checkSQLLength(tempint + 2) && localUserSQL.charAt(tempint + 1) == '\"') {
+ localUserSQL = localUserSQL.substring(0, tempint) + localUserSQL.substring(tempint + 1);
+ tempint = localUserSQL.indexOf("\"", tempint + 1);
+ }
+
+ // we've found a " that is actually trying to close the quote.
+ String tempstr = localUserSQL.substring(1, tempint);
+ localUserSQL = localUserSQL.substring(tempint + 1);
+ listOfColumns.add(tempstr);
+ continue; // proceed with the rest of the string
+ }
+
+ // At this point, the next chunk of string is the column name, without starting with [ or ".
+ while (localUserSQL.length() > 0) {
+ if (checkAndRemoveCommentsAndSpace(false)) {
+ continue;
+ }
+ if (localUserSQL.charAt(0) == ',') {
+ localUserSQL = localUserSQL.substring(1);
+ listOfColumns.add(sb.toString());
+ sb.setLength(0);
+ break; // exit this while loop, but continue parsing.
+ } else if (localUserSQL.charAt(0) == ')') {
+ localUserSQL = localUserSQL.substring(1);
+ listOfColumns.add(sb.toString());
+ return listOfColumns; // reached exit condition.
+ } else {
+ sb.append(localUserSQL.charAt(0));
+ localUserSQL = localUserSQL.substring(1);
+ localUserSQL = localUserSQL.trim(); // add an entry.
+ }
}
}
-
+
// It shouldn't come here. If we did, something is wrong.
- throw new IllegalArgumentException("localUserSQL");
+ // most likely we couldn't hit the exit condition and just parsed until the end of the string.
+ throw new IllegalArgumentException("Invalid SQL Query.");
}
-
private ArrayList parseUserSQLForValueListDW(boolean hasValuesBeenFound) {
- localUserSQL = localUserSQL.trim();
-
// ignore all comments
- if (checkAndRemoveComments()) {
- return parseUserSQLForValueListDW(hasValuesBeenFound);
- }
-
+ if (checkAndRemoveCommentsAndSpace(false)) {}
+
if (!hasValuesBeenFound) {
// look for keyword "VALUES"
- if (localUserSQL.substring(0, 6).equalsIgnoreCase("VALUES")) {
+ if (checkSQLLength(6) && localUserSQL.substring(0, 6).equalsIgnoreCase("VALUES")) {
localUserSQL = localUserSQL.substring(6);
-
- localUserSQL = localUserSQL.trim();
-
+
// ignore all comments
- if (checkAndRemoveComments()) {
- return parseUserSQLForValueListDW(true);
- }
-
- if (localUserSQL.substring(0, 1).equalsIgnoreCase("(")) {
+ while (checkAndRemoveCommentsAndSpace(false)) {}
+
+ if (checkSQLLength(1) && localUserSQL.substring(0, 1).equalsIgnoreCase("(")) {
localUserSQL = localUserSQL.substring(1);
return parseUserSQLForValueListDWHelper(new ArrayList());
}
}
} else {
// ignore all comments
- if (checkAndRemoveComments()) {
- return parseUserSQLForValueListDW(hasValuesBeenFound);
- }
-
- if (localUserSQL.substring(0, 1).equalsIgnoreCase("(")) {
+ while (checkAndRemoveCommentsAndSpace(false)) {}
+
+ if (checkSQLLength(1) && localUserSQL.substring(0, 1).equalsIgnoreCase("(")) {
localUserSQL = localUserSQL.substring(1);
return parseUserSQLForValueListDWHelper(new ArrayList());
}
}
-
+
// shouldn't come here, as the list of values is mandatory.
- throw new IllegalArgumentException("localUserSQL");
+ throw new IllegalArgumentException("Invalid SQL Query.");
}
private ArrayList parseUserSQLForValueListDWHelper(ArrayList listOfValues) {
- localUserSQL = localUserSQL.trim();
-
// ignore all comments
- if (checkAndRemoveComments()) {
- return parseUserSQLForValueListDWHelper(listOfValues);
- }
+ while (checkAndRemoveCommentsAndSpace(false)) {}
- if (localUserSQL.charAt(0) == ')') {
- localUserSQL = localUserSQL.substring(1);
- return listOfValues;
- }
-
- if (localUserSQL.charAt(0) == ',') {
- localUserSQL = localUserSQL.substring(1);
- return parseUserSQLForValueListDWHelper(listOfValues);
- }
-
- if (localUserSQL.charAt(0) == '\'') {
- int tempint = localUserSQL.indexOf("\'", 1);
-
- // keep checking if it's escaped
- while (localUserSQL.charAt(tempint + 1) == '\'') {
- localUserSQL = localUserSQL.substring(0, tempint) + localUserSQL.substring(tempint + 1);
- tempint = localUserSQL.indexOf("\'", tempint + 1);
- }
-
- // we've found a ' that is actually trying to close the quote.
- // Include 's around the string as well, so we can distinguish '?' and ? later on.
- String tempstr = localUserSQL.substring(0, tempint + 1);
- localUserSQL = localUserSQL.substring(tempint + 1);
- listOfValues.add(tempstr);
- return parseUserSQLForValueListDWHelper(listOfValues);
- }
-
// At this point, the next chunk of string is the value, without starting with ' (most likely a ?).
StringBuilder sb = new StringBuilder();
while (localUserSQL.length() > 0) {
+ if (checkAndRemoveCommentsAndSpace(false)) {
+ continue;
+ }
if (localUserSQL.charAt(0) == ',' || localUserSQL.charAt(0) == ')') {
if (localUserSQL.charAt(0) == ',') {
localUserSQL = localUserSQL.substring(1);
+ if (!sb.toString().equals("?")) {
+ // throw IllegalArgumentException and fallback to original logic for batch insert
+ throw new IllegalArgumentException(
+ "Only fully parameterized queries are allowed for using Bulk Copy API for batch insert at the moment.");
+ }
listOfValues.add(sb.toString());
- return parseUserSQLForValueListDWHelper(listOfValues);
+ sb.setLength(0);
} else {
localUserSQL = localUserSQL.substring(1);
listOfValues.add(sb.toString());
- return listOfValues;
+ return listOfValues; // reached exit condition.
}
- } else if (checkAndRemoveComments()) {
- localUserSQL = localUserSQL.trim();
} else {
sb.append(localUserSQL.charAt(0));
localUserSQL = localUserSQL.substring(1);
- localUserSQL = localUserSQL.trim();
+ localUserSQL = localUserSQL.trim(); // add entry.
}
}
-
+
+ // Don't need this anymore since we removed support for non-parameterized query.
+ // if (localUserSQL.charAt(0) == '\'') {
+ // int tempint = localUserSQL.indexOf("\'", 1);
+ //
+ // // \' has not been found, this is wrong.
+ // if (tempint < 0) {
+ // throw new IllegalArgumentException("Invalid SQL Query.");
+ // }
+ //
+ // // keep checking if it's escaped
+ // while (tempint >= 0 && checkSQLLength(tempint + 2) && localUserSQL.charAt(tempint + 1) == '\'') {
+ // localUserSQL = localUserSQL.substring(0, tempint) + localUserSQL.substring(tempint + 1);
+ // tempint = localUserSQL.indexOf("\'", tempint + 1);
+ // }
+ //
+ // // we've found a ' that is actually trying to close the quote.
+ // // Include 's around the string as well, so we can distinguish '?' and ? later on.
+ // String tempstr = localUserSQL.substring(0, tempint + 1);
+ // localUserSQL = localUserSQL.substring(tempint + 1);
+ // listOfValues.add(tempstr);
+ // return parseUserSQLForValueListDWHelper(listOfValues);
+ // }
+
// It shouldn't come here. If we did, something is wrong.
- throw new IllegalArgumentException("localUserSQL");
+ throw new IllegalArgumentException("Invalid SQL Query.");
}
-
- private boolean checkAndRemoveComments() {
+
+ private boolean checkAndRemoveCommentsAndSpace(boolean checkForSemicolon) {
+ localUserSQL = localUserSQL.trim();
+
+ while (checkForSemicolon && null != localUserSQL && localUserSQL.length() > 0
+ && localUserSQL.charAt(0) == ';') {
+ localUserSQL = localUserSQL.substring(1);
+ }
+
if (null == localUserSQL || localUserSQL.length() < 2) {
return false;
}
-
+
if (localUserSQL.substring(0, 2).equalsIgnoreCase("/*")) {
int temp = localUserSQL.indexOf("*/") + 2;
+ if (temp <= 0) {
+ localUserSQL = "";
+ return false;
+ }
localUserSQL = localUserSQL.substring(temp);
return true;
}
-
+
if (localUserSQL.substring(0, 2).equalsIgnoreCase("--")) {
- int temp = localUserSQL.indexOf("\n") + 2;
+ int temp = localUserSQL.indexOf("\n") + 1;
+ if (temp <= 0) {
+ localUserSQL = "";
+ return false;
+ }
localUserSQL = localUserSQL.substring(temp);
return true;
}
+
return false;
}
+ private boolean checkSQLLength(int length) {
+ if (null == localUserSQL || localUserSQL.length() < length) {
+ throw new IllegalArgumentException("Invalid SQL Query.");
+ }
+ return true;
+ }
+
private final class PrepStmtBatchExecCmd extends TDSCommand {
private final SQLServerPreparedStatement stmt;
SQLServerException batchException;
@@ -2674,7 +2662,8 @@ final void doExecutePreparedStatementBatch(PrepStmtBatchExecCmd batchCommand) th
Vector cryptoMetaBatch = new Vector<>();
if (isSelect(userSQL)) {
- SQLServerException.makeFromDriverError(connection, this, SQLServerException.getErrString("R_selectNotPermittedinBatch"), null, true);
+ SQLServerException.makeFromDriverError(connection, this,
+ SQLServerException.getErrString("R_selectNotPermittedinBatch"), null, true);
}
// Make sure any previous maxRows limitation on the connection is removed.
@@ -2687,16 +2676,14 @@ final void doExecutePreparedStatementBatch(PrepStmtBatchExecCmd batchCommand) th
Parameter[] batchParam = new Parameter[inOutParam.length];
/*
- * TDSWriter tdsWriter = null; while (numBatchesExecuted < numBatches) { // Fill in the parameter values for this batch Parameter
- * paramValues[] = batchParamValues.get(numBatchesPrepared); assert paramValues.length == batchParam.length; System.arraycopy(paramValues, 0,
- * batchParam, 0, paramValues.length);
- *
- * boolean hasExistingTypeDefinitions = preparedTypeDefinitions != null; boolean hasNewTypeDefinitions = buildPreparedStrings(batchParam,
- * false);
- *
- * // Get the encryption metadata for the first batch only. if ((0 == numBatchesExecuted) &&
- * (Util.shouldHonorAEForParameters(stmtColumnEncriptionSetting, connection)) && (0 < batchParam.length) && !isInternalEncryptionQuery &&
- * !encryptionMetadataIsRetrieved) { getParameterEncryptionMetadata(batchParam);
+ * TDSWriter tdsWriter = null; while (numBatchesExecuted < numBatches) { // Fill in the parameter values for
+ * this batch Parameter paramValues[] = batchParamValues.get(numBatchesPrepared); assert paramValues.length ==
+ * batchParam.length; System.arraycopy(paramValues, 0, batchParam, 0, paramValues.length); boolean
+ * hasExistingTypeDefinitions = preparedTypeDefinitions != null; boolean hasNewTypeDefinitions =
+ * buildPreparedStrings(batchParam, false); // Get the encryption metadata for the first batch only. if ((0 ==
+ * numBatchesExecuted) && (Util.shouldHonorAEForParameters(stmtColumnEncriptionSetting, connection)) && (0 <
+ * batchParam.length) && !isInternalEncryptionQuery && !encryptionMetadataIsRetrieved) {
+ * getParameterEncryptionMetadata(batchParam);
*/
TDSWriter tdsWriter = null;
@@ -2710,14 +2697,16 @@ final void doExecutePreparedStatementBatch(PrepStmtBatchExecCmd batchCommand) th
boolean hasNewTypeDefinitions = buildPreparedStrings(batchParam, false);
// Get the encryption metadata for the first batch only.
- if ((0 == numBatchesExecuted) && (Util.shouldHonorAEForParameters(stmtColumnEncriptionSetting, connection)) && (0 < batchParam.length)
- && !isInternalEncryptionQuery && !encryptionMetadataIsRetrieved) {
+ if ((0 == numBatchesExecuted) && (Util.shouldHonorAEForParameters(stmtColumnEncriptionSetting, connection))
+ && (0 < batchParam.length) && !isInternalEncryptionQuery && !encryptionMetadataIsRetrieved) {
getParameterEncryptionMetadata(batchParam);
- // fix an issue when inserting unicode into non-encrypted nchar column using setString() and AE is on on Connection
+ // fix an issue when inserting unicode into non-encrypted nchar column using setString() and AE is on on
+ // Connection
buildPreparedStrings(batchParam, true);
- // Save the crypto metadata retrieved for the first batch. We will re-use these for the rest of the batches.
+ // Save the crypto metadata retrieved for the first batch. We will re-use these for the rest of the
+ // batches.
for (Parameter aBatchParam : batchParam) {
cryptoMetaBatch.add(aBatchParam.cryptoMeta);
}
@@ -2744,8 +2733,7 @@ final void doExecutePreparedStatementBatch(PrepStmtBatchExecCmd batchCommand) th
if (numBatchesExecuted < numBatchesPrepared) {
// assert null != tdsWriter;
tdsWriter.writeByte((byte) nBatchStatementDelimiter);
- }
- else {
+ } else {
resetForReexecute();
tdsWriter = batchCommand.startRequest(TDS.PKT_RPC);
}
@@ -2783,10 +2771,10 @@ final void doExecutePreparedStatementBatch(PrepStmtBatchExecCmd batchCommand) th
// translated into (or added to) a BatchUpdateException.
if (null != resultSet) {
SQLServerException.makeFromDriverError(connection, this,
- SQLServerException.getErrString("R_resultsetGeneratedForUpdate"), null, false);
+ SQLServerException.getErrString("R_resultsetGeneratedForUpdate"), null,
+ false);
}
- }
- catch (SQLServerException e) {
+ } catch (SQLServerException e) {
// If the failure was severe enough to close the connection or roll back a
// manual transaction, then propagate the error up as a SQLServerException
// now, rather than continue with the batch.
@@ -2811,7 +2799,8 @@ final void doExecutePreparedStatementBatch(PrepStmtBatchExecCmd batchCommand) th
// In batch execution, we have a special update count
// to indicate that no information was returned
- batchCommand.updateCounts[numBatchesExecuted] = (-1 == updateCount) ? Statement.SUCCESS_NO_INFO : updateCount;
+ batchCommand.updateCounts[numBatchesExecuted] = (-1 == updateCount) ? Statement.SUCCESS_NO_INFO
+ : updateCount;
processBatch();
numBatchesExecuted++;
@@ -2823,20 +2812,18 @@ final void doExecutePreparedStatementBatch(PrepStmtBatchExecCmd batchCommand) th
// we successfully executed the previously prepared set.
assert numBatchesExecuted == numBatchesPrepared;
}
- }
- catch (SQLException e) {
- if (retryBasedOnFailedReuseOfCachedHandle(e, attempt, needsPrepare, true) && connection.isStatementPoolingEnabled()) {
+ } catch (SQLException e) {
+ if (retryBasedOnFailedReuseOfCachedHandle(e, attempt, needsPrepare, true)
+ && connection.isStatementPoolingEnabled()) {
// Reset number of batches prepared.
numBatchesPrepared = numBatchesExecuted;
continue;
- }
- else if (null != batchCommand.batchException) {
+ } else if (null != batchCommand.batchException) {
// if batch exception occurred, loop out to throw the initial batchException
numBatchesExecuted = numBatchesPrepared;
attempt++;
continue;
- }
- else {
+ } else {
throw e;
}
}
@@ -2846,8 +2833,7 @@ else if (null != batchCommand.batchException) {
}
@Override
- public final void setCharacterStream(int parameterIndex,
- Reader reader) throws SQLException {
+ public final void setCharacterStream(int parameterIndex, Reader reader) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setCharacterStream", new Object[] {parameterIndex, reader});
checkClosed();
@@ -2856,9 +2842,7 @@ public final void setCharacterStream(int parameterIndex,
}
@Override
- public final void setCharacterStream(int n,
- java.io.Reader reader,
- int length) throws SQLServerException {
+ public final void setCharacterStream(int n, java.io.Reader reader, int length) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setCharacterStream", new Object[] {n, reader, length});
checkClosed();
@@ -2867,19 +2851,17 @@ public final void setCharacterStream(int n,
}
@Override
- public final void setCharacterStream(int parameterIndex,
- Reader reader,
- long length) throws SQLException {
+ public final void setCharacterStream(int parameterIndex, Reader reader, long length) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "setCharacterStream", new Object[] {parameterIndex, reader, length});
+ loggerExternal.entering(getClassNameLogging(), "setCharacterStream",
+ new Object[] {parameterIndex, reader, length});
checkClosed();
setStream(parameterIndex, StreamType.CHARACTER, reader, JavaType.READER, length);
loggerExternal.exiting(getClassNameLogging(), "setCharacterStream");
}
@Override
- public final void setNCharacterStream(int parameterIndex,
- Reader value) throws SQLException {
+ public final void setNCharacterStream(int parameterIndex, Reader value) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setNCharacterStream", new Object[] {parameterIndex, value});
checkClosed();
@@ -2888,25 +2870,22 @@ public final void setNCharacterStream(int parameterIndex,
}
@Override
- public final void setNCharacterStream(int parameterIndex,
- Reader value,
- long length) throws SQLException {
+ public final void setNCharacterStream(int parameterIndex, Reader value, long length) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "setNCharacterStream", new Object[] {parameterIndex, value, length});
+ loggerExternal.entering(getClassNameLogging(), "setNCharacterStream",
+ new Object[] {parameterIndex, value, length});
checkClosed();
setStream(parameterIndex, StreamType.NCHARACTER, value, JavaType.READER, length);
loggerExternal.exiting(getClassNameLogging(), "setNCharacterStream");
}
@Override
- public final void setRef(int i,
- java.sql.Ref x) throws SQLException {
+ public final void setRef(int i, java.sql.Ref x) throws SQLException {
SQLServerException.throwNotSupportedException(connection, this);
}
@Override
- public final void setBlob(int i,
- java.sql.Blob x) throws SQLException {
+ public final void setBlob(int i, java.sql.Blob x) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setBlob", new Object[] {i, x});
checkClosed();
@@ -2915,29 +2894,27 @@ public final void setBlob(int i,
}
@Override
- public final void setBlob(int parameterIndex,
- InputStream inputStream) throws SQLException {
+ public final void setBlob(int parameterIndex, InputStream inputStream) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setBlob", new Object[] {parameterIndex, inputStream});
checkClosed();
- setStream(parameterIndex, StreamType.BINARY, inputStream, JavaType.INPUTSTREAM, DataTypes.UNKNOWN_STREAM_LENGTH);
+ setStream(parameterIndex, StreamType.BINARY, inputStream, JavaType.INPUTSTREAM,
+ DataTypes.UNKNOWN_STREAM_LENGTH);
loggerExternal.exiting(getClassNameLogging(), "setBlob");
}
@Override
- public final void setBlob(int parameterIndex,
- InputStream inputStream,
- long length) throws SQLException {
+ public final void setBlob(int parameterIndex, InputStream inputStream, long length) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "setBlob", new Object[] {parameterIndex, inputStream, length});
+ loggerExternal.entering(getClassNameLogging(), "setBlob",
+ new Object[] {parameterIndex, inputStream, length});
checkClosed();
setStream(parameterIndex, StreamType.BINARY, inputStream, JavaType.INPUTSTREAM, length);
loggerExternal.exiting(getClassNameLogging(), "setBlob");
}
@Override
- public final void setClob(int parameterIndex,
- java.sql.Clob clobValue) throws SQLException {
+ public final void setClob(int parameterIndex, java.sql.Clob clobValue) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setClob", new Object[] {parameterIndex, clobValue});
checkClosed();
@@ -2946,8 +2923,7 @@ public final void setClob(int parameterIndex,
}
@Override
- public final void setClob(int parameterIndex,
- Reader reader) throws SQLException {
+ public final void setClob(int parameterIndex, Reader reader) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setClob", new Object[] {parameterIndex, reader});
checkClosed();
@@ -2956,9 +2932,7 @@ public final void setClob(int parameterIndex,
}
@Override
- public final void setClob(int parameterIndex,
- Reader reader,
- long length) throws SQLException {
+ public final void setClob(int parameterIndex, Reader reader, long length) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setClob", new Object[] {parameterIndex, reader, length});
checkClosed();
@@ -2967,8 +2941,7 @@ public final void setClob(int parameterIndex,
}
@Override
- public final void setNClob(int parameterIndex,
- NClob value) throws SQLException {
+ public final void setNClob(int parameterIndex, NClob value) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setNClob", new Object[] {parameterIndex, value});
checkClosed();
@@ -2977,8 +2950,7 @@ public final void setNClob(int parameterIndex,
}
@Override
- public final void setNClob(int parameterIndex,
- Reader reader) throws SQLException {
+ public final void setNClob(int parameterIndex, Reader reader) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setNClob", new Object[] {parameterIndex, reader});
checkClosed();
@@ -2987,9 +2959,7 @@ public final void setNClob(int parameterIndex,
}
@Override
- public final void setNClob(int parameterIndex,
- Reader reader,
- long length) throws SQLException {
+ public final void setNClob(int parameterIndex, Reader reader, long length) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setNClob", new Object[] {parameterIndex, reader, length});
checkClosed();
@@ -2998,15 +2968,12 @@ public final void setNClob(int parameterIndex,
}
@Override
- public final void setArray(int i,
- java.sql.Array x) throws SQLException {
+ public final void setArray(int i, java.sql.Array x) throws SQLException {
SQLServerException.throwNotSupportedException(connection, this);
}
@Override
- public final void setDate(int n,
- java.sql.Date x,
- java.util.Calendar cal) throws SQLServerException {
+ public final void setDate(int n, java.sql.Date x, java.util.Calendar cal) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setDate", new Object[] {n, x, cal});
checkClosed();
@@ -3015,9 +2982,7 @@ public final void setDate(int n,
}
@Override
- public final void setDate(int n,
- java.sql.Date x,
- java.util.Calendar cal,
+ public final void setDate(int n, java.sql.Date x, java.util.Calendar cal,
boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setDate", new Object[] {n, x, cal, forceEncrypt});
@@ -3027,9 +2992,7 @@ public final void setDate(int n,
}
@Override
- public final void setTime(int n,
- java.sql.Time x,
- java.util.Calendar cal) throws SQLServerException {
+ public final void setTime(int n, java.sql.Time x, java.util.Calendar cal) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setTime", new Object[] {n, x, cal});
checkClosed();
@@ -3038,9 +3001,7 @@ public final void setTime(int n,
}
@Override
- public final void setTime(int n,
- java.sql.Time x,
- java.util.Calendar cal,
+ public final void setTime(int n, java.sql.Time x, java.util.Calendar cal,
boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setTime", new Object[] {n, x, cal, forceEncrypt});
@@ -3050,9 +3011,7 @@ public final void setTime(int n,
}
@Override
- public final void setTimestamp(int n,
- java.sql.Timestamp x,
- java.util.Calendar cal) throws SQLServerException {
+ public final void setTimestamp(int n, java.sql.Timestamp x, java.util.Calendar cal) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setTimestamp", new Object[] {n, x, cal});
checkClosed();
@@ -3061,9 +3020,7 @@ public final void setTimestamp(int n,
}
@Override
- public final void setTimestamp(int n,
- java.sql.Timestamp x,
- java.util.Calendar cal,
+ public final void setTimestamp(int n, java.sql.Timestamp x, java.util.Calendar cal,
boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setTimestamp", new Object[] {n, x, cal, forceEncrypt});
@@ -3073,17 +3030,16 @@ public final void setTimestamp(int n,
}
@Override
- public final void setNull(int paramIndex,
- int sqlType,
- String typeName) throws SQLServerException {
+ public final void setNull(int paramIndex, int sqlType, String typeName) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setNull", new Object[] {paramIndex, sqlType, typeName});
checkClosed();
if (microsoft.sql.Types.STRUCTURED == sqlType) {
- setObject(setterGetParam(paramIndex), null, JavaType.TVP, JDBCType.of(sqlType), null, null, false, paramIndex, typeName);
- }
- else {
- setObject(setterGetParam(paramIndex), null, JavaType.OBJECT, JDBCType.of(sqlType), null, null, false, paramIndex, typeName);
+ setObject(setterGetParam(paramIndex), null, JavaType.TVP, JDBCType.of(sqlType), null, null, false,
+ paramIndex, typeName);
+ } else {
+ setObject(setterGetParam(paramIndex), null, JavaType.OBJECT, JDBCType.of(sqlType), null, null, false,
+ paramIndex, typeName);
}
loggerExternal.exiting(getClassNameLogging(), "setNull");
}
@@ -3095,8 +3051,7 @@ public final ParameterMetaData getParameterMetaData(boolean forceRefresh) throws
if (!forceRefresh && null != pmd) {
return pmd;
- }
- else {
+ } else {
loggerExternal.entering(getClassNameLogging(), "getParameterMetaData");
checkClosed();
pmd = new SQLServerParameterMetaData(this, userSQL);
@@ -3114,20 +3069,17 @@ public final ParameterMetaData getParameterMetaData() throws SQLServerException
}
@Override
- public final void setURL(int parameterIndex,
- java.net.URL x) throws SQLException {
+ public final void setURL(int parameterIndex, java.net.URL x) throws SQLException {
SQLServerException.throwNotSupportedException(connection, this);
}
@Override
- public final void setRowId(int parameterIndex,
- RowId x) throws SQLException {
+ public final void setRowId(int parameterIndex, RowId x) throws SQLException {
SQLServerException.throwNotSupportedException(connection, this);
}
@Override
- public final void setSQLXML(int parameterIndex,
- SQLXML xmlObject) throws SQLException {
+ public final void setSQLXML(int parameterIndex, SQLXML xmlObject) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "setSQLXML", new Object[] {parameterIndex, xmlObject});
checkClosed();
@@ -3135,11 +3087,11 @@ public final void setSQLXML(int parameterIndex,
loggerExternal.exiting(getClassNameLogging(), "setSQLXML");
}
- /* make sure we throw here */
@Override
public final int executeUpdate(String sql) throws SQLServerException {
loggerExternal.entering(getClassNameLogging(), "executeUpdate", sql);
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_cannotTakeArgumentsPreparedOrCallable"));
+ MessageFormat form = new MessageFormat(
+ SQLServerException.getErrString("R_cannotTakeArgumentsPreparedOrCallable"));
Object[] msgArgs = {"executeUpdate()"};
throw new SQLServerException(this, form.format(msgArgs), null, 0, false);
}
@@ -3147,7 +3099,8 @@ public final int executeUpdate(String sql) throws SQLServerException {
@Override
public final boolean execute(String sql) throws SQLServerException {
loggerExternal.entering(getClassNameLogging(), "execute", sql);
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_cannotTakeArgumentsPreparedOrCallable"));
+ MessageFormat form = new MessageFormat(
+ SQLServerException.getErrString("R_cannotTakeArgumentsPreparedOrCallable"));
Object[] msgArgs = {"execute()"};
throw new SQLServerException(this, form.format(msgArgs), null, 0, false);
}
@@ -3155,7 +3108,8 @@ public final boolean execute(String sql) throws SQLServerException {
@Override
public final java.sql.ResultSet executeQuery(String sql) throws SQLServerException {
loggerExternal.entering(getClassNameLogging(), "executeQuery", sql);
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_cannotTakeArgumentsPreparedOrCallable"));
+ MessageFormat form = new MessageFormat(
+ SQLServerException.getErrString("R_cannotTakeArgumentsPreparedOrCallable"));
Object[] msgArgs = {"executeQuery()"};
throw new SQLServerException(this, form.format(msgArgs), null, 0, false);
}
@@ -3163,7 +3117,8 @@ public final java.sql.ResultSet executeQuery(String sql) throws SQLServerExcepti
@Override
public void addBatch(String sql) throws SQLServerException {
loggerExternal.entering(getClassNameLogging(), "addBatch", sql);
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_cannotTakeArgumentsPreparedOrCallable"));
+ MessageFormat form = new MessageFormat(
+ SQLServerException.getErrString("R_cannotTakeArgumentsPreparedOrCallable"));
Object[] msgArgs = {"addBatch()"};
throw new SQLServerException(this, form.format(msgArgs), null, 0, false);
}
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResource.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResource.java
index afe0799bb..609dc7e13 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResource.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResource.java
@@ -1,17 +1,15 @@
/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc;
import java.util.ListResourceBundle;
+
/**
- * A simple resource bundle containing the strings for localizing.
+ * Represents a simple resource bundle containing the strings for localizing.
*
*/
public final class SQLServerResource extends ListResourceBundle {
@@ -23,381 +21,517 @@ protected Object[][] getContents() {
return contents;
}
- // the keys must be prefixed with R_ to denote they are resource strings and their names should follow the camelCasing
+ // the keys must be prefixed with R_ to denote they are resource strings and their names should follow the
+ // camelCasing
// convention and be descriptive
static final Object[][] contents = {
- // LOCALIZE THIS
- {"R_timedOutBeforeRouting", "The timeout expired before connecting to the routing destination."},
- {"R_invalidRoutingInfo", "Unexpected routing information received. Please check your connection properties and SQL Server configuration."},
- {"R_multipleRedirections", "Two or more redirections have occurred. Only one redirection per login attempt is allowed."},
- {"R_dbMirroringWithMultiSubnetFailover", "Connecting to a mirrored SQL Server instance using the multiSubnetFailover connection property is not supported."},
- {"R_dbMirroringWithReadOnlyIntent", "Connecting to a mirrored SQL Server instance using the ApplicationIntent ReadOnly connection property is not supported."},
- {"R_ipAddressLimitWithMultiSubnetFailover", "Connecting with the multiSubnetFailover connection property to a SQL Server instance configured with more than {0} IP addresses is not supported."},
- {"R_connectionTimedOut", "Connection timed out: no further information."},
- {"R_invalidPositionIndex", "The position index {0} is not valid."},
- {"R_invalidLength", "The length {0} is not valid."},
- {"R_unknownSSType", "Invalid SQL Server data type {0}."},
- {"R_unknownJDBCType", "Invalid JDBC data type {0}."},
- {"R_notSQLServer", "The driver received an unexpected pre-login response. Verify the connection properties and check that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. This driver can be used only with SQL Server 2005 or later."},
- {"R_tcpOpenFailed", "{0}. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall."},
- {"R_unsupportedServerVersion", "SQL Server version {0} is not supported by this driver."},
- {"R_noServerResponse", "SQL Server did not return a response. The connection has been closed."},
- {"R_truncatedServerResponse", "SQL Server returned an incomplete response. The connection has been closed."},
- {"R_queryTimedOut", "The query has timed out."},
- {"R_queryCancelled", "The query was canceled."},
- {"R_errorReadingStream", "An error occurred while reading the value from the stream object. Error: \"{0}\""},
- {"R_streamReadReturnedInvalidValue", "The stream read operation returned an invalid value for the amount of data read."},
- {"R_mismatchedStreamLength", "The stream value is not the specified length. The specified length was {0}, the actual length is {1}."},
- {"R_notSupported", "This operation is not supported."},
- {"R_invalidOutputParameter", "The index {0} of the output parameter is not valid."},
- {"R_outputParameterNotRegisteredForOutput", "The output parameter {0} was not registered for output."},
- {"R_parameterNotDefinedForProcedure", "Parameter {0} was not defined for stored procedure {1}."},
- {"R_connectionIsClosed", "The connection is closed."},
- {"R_invalidBooleanValue", "The property {0} does not contain a valid boolean value. Only true or false can be used."},
- {"R_propertyMaximumExceedsChars", "The {0} property exceeds the maximum number of {1} characters."},
- {"R_invalidPortNumber", "The port number {0} is not valid."},
- {"R_invalidTimeOut", "The timeout {0} is not valid."},
- {"R_invalidLockTimeOut", "The lockTimeOut {0} is not valid."},
- {"R_invalidAuthenticationScheme", "The authenticationScheme {0} is not valid."},
- {"R_invalidPacketSize", "The packetSize {0} is not valid."},
- {"R_packetSizeTooBigForSSL", "SSL encryption cannot be used with a network packet size larger than {0} bytes. Please check your connection properties and SQL Server configuration."},
- {"R_tcpipConnectionFailed", "The TCP/IP connection to the host {0}, port {1} has failed. Error: \"{2}\"."}, //{PlaceHolder="TCP/IP"}
- {"R_invalidTransactionLevel", "The transaction level {0} is not valid."},
- {"R_cantInvokeRollback", "Cannot invoke a rollback operation when the AutoCommit mode is set to \"true\"."},
- {"R_cantSetSavepoint", "Cannot set a savepoint when the AutoCommit mode is set to \"true\"."},
- {"R_sqlServerHoldability", "SQL Server supports holdability at the connection level only. Use the connection.setHoldability() method."}, //{PlaceHolder="connection.setHoldability()"}
- {"R_invalidHoldability", "The holdability value {0} is not valid."},
- {"R_invalidColumnArrayLength", "The column array is not valid. Its length must be 1."},
- {"R_valueNotSetForParameter", "The value is not set for the parameter number {0}."},
- {"R_sqlBrowserFailed", "The connection to the host {0}, named instance {1} failed. Error: \"{2}\". Verify the server and instance names and check that no firewall is blocking UDP traffic to port 1434. For SQL Server 2005 or later, verify that the SQL Server Browser Service is running on the host."},
- {"R_notConfiguredToListentcpip", "The server {0} is not configured to listen with TCP/IP."},
- {"R_cantIdentifyTableMetadata", "Unable to identify the table {0} for the metadata."},
- {"R_metaDataErrorForParameter", "A metadata error for the parameter {0} occurred."},
- {"R_invalidParameterNumber", "The parameter number {0} is not valid."},
- {"R_noMetadata", "There is no metadata."},
- {"R_resultsetClosed", "The result set is closed."},
- {"R_invalidColumnName", "The column name {0} is not valid."},
- {"R_resultsetNotUpdatable", "The result set is not updatable."},
- {"R_indexOutOfRange", "The index {0} is out of range."},
- {"R_savepointNotNamed", "The savepoint is not named."},
- {"R_savepointNamed", "The savepoint {0} is named."},
- {"R_resultsetNoCurrentRow", "The result set has no current row."},
- {"R_mustBeOnInsertRow", "The cursor is not on the insert row."},
- {"R_mustNotBeOnInsertRow", "The requested operation is not valid on the insert row."},
- {"R_cantUpdateDeletedRow", "A deleted row cannot be updated."},
- {"R_noResultset", "The statement did not return a result set."},
- {"R_resultsetGeneratedForUpdate", "A result set was generated for update."},
- {"R_statementIsClosed", "The statement is closed."},
- {"R_invalidRowcount", "The maximum row count {0} for a result set must be non-negative."},
- {"R_invalidQueryTimeOutValue", "The query timeout value {0} is not valid."},
- {"R_invalidFetchDirection", "The fetch direction {0} is not valid."},
- {"R_invalidFetchSize", "The fetch size cannot be negative."},
- {"R_noColumnParameterValue", "No column parameter values were specified to update the row."},
- {"R_statementMustBeExecuted", "The statement must be executed before any results can be obtained."},
- {"R_modeSuppliedNotValid", "The supplied mode is not valid."},
- {"R_errorConnectionString", "The connection string contains a badly formed name or value."},
- {"R_errorProcessingComplexQuery", "An error occurred while processing the complex query."},
- {"R_invalidOffset", "The offset {0} is not valid."},
- {"R_nullConnection", "The connection URL is null."},
- {"R_invalidConnection", "The connection URL is invalid."},
- {"R_cannotTakeArgumentsPreparedOrCallable", "The method {0} cannot take arguments on a PreparedStatement or CallableStatement."},
- {"R_unsupportedConversionFromTo", "The conversion from {0} to {1} is unsupported."}, // Invalid conversion (e.g. MONEY to Timestamp)
- {"R_unsupportedConversionTo", "The conversion to {0} is unsupported."}, // Invalid conversion to an unknown type
- {"R_errorConvertingValue","An error occurred while converting the {0} value to JDBC data type {1}."}, // Data-dependent conversion failure (e.g. "foo" vs. "123", to Integer)
- {"R_streamIsClosed", "The stream is closed."},
- {"R_invalidTDS", "The TDS protocol stream is not valid."},
- {"R_unexpectedToken", " Unexpected token {0}."},
- {"R_selectNotPermittedinBatch", "The SELECT statement is not permitted in a batch."},
- {"R_failedToCreateXAConnection", "Failed to create the XA control connection. Error: \"{0}\""},
- {"R_codePageNotSupported", "Codepage {0} is not supported by the Java environment."},
- {"R_unknownSortId", "SQL Server collation {0} is not supported by this driver."},
- {"R_unknownLCID", "Windows collation {0} is not supported by this driver."},
- {"R_encodingErrorWritingTDS", "An encoding error occurred while writing a string to the TDS buffer. Error: \"{0}\""},
- {"R_processingError", "A processing error \"{0}\" occurred."},
- {"R_requestedOpNotSupportedOnForward", "The requested operation is not supported on forward only result sets."},
- {"R_unsupportedCursor", "The cursor type is not supported."},
- {"R_unsupportedCursorOperation", "The requested operation is not supported with this cursor type."},
- {"R_unsupportedConcurrency", "The concurrency is not supported."},
- {"R_unsupportedCursorAndConcurrency", "The cursor type/concurrency combination is not supported."},
- {"R_stringReadError", "A string read error occurred at offset:{0}."},
- {"R_stringWriteError", "A string write error occurred at offset:{0}."},
- {"R_stringNotInHex", "The string is not in a valid hex format."},
- {"R_unknownType", "The Java type {0} is not a supported type."},
- {"R_physicalConnectionIsClosed", "The physical connection is closed for this pooled connection."},
- {"R_invalidDataSourceReference", "Invalid DataSource reference."},
- {"R_cantGetColumnValueFromDeletedRow", "Cannot get a value from a deleted row."},
- {"R_cantGetUpdatedColumnValue", "Updated columns cannot be accessed until updateRow() or cancelRowUpdates() has been called."},
- {"R_cantUpdateColumn","The column value cannot be updated."},
- {"R_positionedUpdatesNotSupported", "Positioned updates and deletes are not supported."},
- {"R_invalidAutoGeneratedKeys", "The autoGeneratedKeys parameter value {0} is not valid. Only the values Statement.RETURN_GENERATED_KEYS and Statement.NO_GENERATED_KEYS can be used."},
- {"R_notConfiguredForIntegrated", "This driver is not configured for integrated authentication."},
- {"R_failoverPartnerWithoutDB", "databaseName is required when using the failoverPartner connection property."},
- {"R_invalidPartnerConfiguration", "The database {0} on server {1} is not configured for database mirroring."},
- {"R_invaliddisableStatementPooling", "The disableStatementPooling value {0} is not valid."},
- {"R_invalidselectMethod", "The selectMethod {0} is not valid."},
- {"R_invalidpropertyValue", "The data type of connection property {0} is not valid. All the properties for this connection must be of String type."},
- {"R_invalidArgument", "The argument {0} is not valid."},
- {"R_streamWasNotMarkedBefore", "The stream has not been marked."},
- {"R_invalidresponseBuffering", "The responseBuffering connection property {0} is not valid."},
- {"R_invalidapplicationIntent", "The applicationIntent connection property {0} is not valid."},
- {"R_dataAlreadyAccessed", "The data has been accessed and is not available for this column or parameter."},
- {"R_outParamsNotPermittedinBatch", "The OUT and INOUT parameters are not permitted in a batch."},
- {"R_sslRequiredNoServerSupport", "The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. The application requested encryption but the server is not configured to support SSL."},
- {"R_sslRequiredByServer", "SQL Server login requires an encrypted connection that uses Secure Sockets Layer (SSL)."},
- {"R_sslFailed", "The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. Error: \"{0}\"."},
- {"R_certNameFailed", "Failed to validate the server name in a certificate during Secure Sockets Layer (SSL) initialization."},
- {"R_failedToInitializeXA", "Failed to initialize the stored procedure xp_sqljdbc_xa_init. The status is: {0}. Error: \"{1}\""},
- {"R_failedFunctionXA", "The function {0} failed. The status is: {1}. Error: \"{2}\""},
- {"R_noTransactionCookie", "The function {0} failed. No transaction cookie was returned."},
- {"R_failedToEnlist", "Failed to enlist. Error: \"{0}\""},
- {"R_failedToUnEnlist", "Failed to unenlist. Error: \"{0}\""},
- {"R_failedToReadRecoveryXIDs", "Failed to read recovery XA branch transaction IDs (XIDs). Error: \"{0}\""},
- {"R_userPropertyDescription", "The database user."},
- {"R_passwordPropertyDescription", "The database password."},
- {"R_databaseNamePropertyDescription", "The name of the database to connect to."},
- {"R_serverNamePropertyDescription", "The computer running SQL Server."},
- {"R_portNumberPropertyDescription", "The TCP port where an instance of SQL Server is listening."},
- {"R_serverSpnPropertyDescription", "SQL Server SPN."},
- {"R_columnEncryptionSettingPropertyDescription", "The column encryption setting."},
- {"R_serverNameAsACEPropertyDescription", "Translates the serverName from Unicode to ASCII Compatible Encoding (ACE), as defined by the ToASCII operation of RFC 3490."},
- {"R_sendStringParametersAsUnicodePropertyDescription", "Determines if the string parameters are sent to the server as Unicode or the database's character set."},
- {"R_multiSubnetFailoverPropertyDescription", "Indicates that the application is connecting to the Availability Group Listener of an Availability Group or Failover Cluster Instance."},
- {"R_applicationNamePropertyDescription", "The application name for SQL Server profiling and logging tools."},
- {"R_lastUpdateCountPropertyDescription", "Ensures that only the last update count is returned from an SQL statement passed to the server."},
- {"R_disableStatementPoolingPropertyDescription", "Disables the statement pooling feature."},
- {"R_integratedSecurityPropertyDescription", "Indicates whether Windows authentication will be used to connect to SQL Server."},
- {"R_authenticationSchemePropertyDescription", "The authentication scheme to be used for integrated authentication."},
- {"R_lockTimeoutPropertyDescription", "The number of milliseconds to wait before the database reports a lock time-out."},
- {"R_loginTimeoutPropertyDescription", "The number of seconds the driver should wait before timing out a failed connection."},
- {"R_instanceNamePropertyDescription", "The name of the SQL Server instance to connect to."},
- {"R_xopenStatesPropertyDescription", "Determines if the driver returns XOPEN-compliant SQL state codes in exceptions."},
- {"R_selectMethodPropertyDescription", "Enables the application to use server cursors to process forward only, read only result sets."},
- {"R_responseBufferingPropertyDescription", "Controls the adaptive buffering behavior to allow the application to process large result sets without requiring server cursors."},
- {"R_applicationIntentPropertyDescription", "Declares the application workload type when connecting to a server. Possible values are ReadOnly and ReadWrite."},
- {"R_workstationIDPropertyDescription", "The host name of the workstation."},
- {"R_failoverPartnerPropertyDescription", "The name of the failover server used in a database mirroring configuration."},
- {"R_packetSizePropertyDescription", "The network packet size used to communicate with SQL Server."},
- {"R_encryptPropertyDescription", "Determines if Secure Sockets Layer (SSL) encryption should be used between the client and the server."},
- {"R_trustServerCertificatePropertyDescription", "Determines if the driver should validate the SQL Server Secure Sockets Layer (SSL) certificate."},
- {"R_trustStoreTypePropertyDescription", "KeyStore type."},
- {"R_trustStorePropertyDescription", "The path to the certificate TrustStore file."},
- {"R_trustStorePasswordPropertyDescription", "The password used to check the integrity of the trust store data."},
- {"R_trustManagerClassPropertyDescription", "The class to instantiate as the TrustManager for SSL connections."},
- {"R_trustManagerConstructorArgPropertyDescription", "The optional argument to pass to the constructor specified by trustManagerClass."},
- {"R_hostNameInCertificatePropertyDescription", "The host name to be used when validating the SQL Server Secure Sockets Layer (SSL) certificate."},
- {"R_sendTimeAsDatetimePropertyDescription", "Determines whether to use the SQL Server datetime data type to send java.sql.Time values to the database."},
- {"R_TransparentNetworkIPResolutionPropertyDescription", "Determines whether to use the Transparent Network IP Resolution feature."},
- {"R_queryTimeoutPropertyDescription", "The number of seconds to wait before the database reports a query time-out."},
- {"R_socketTimeoutPropertyDescription", "The number of milliseconds to wait before the java.net.SocketTimeoutException is raised."},
- {"R_serverPreparedStatementDiscardThresholdPropertyDescription", "The threshold for when to close discarded prepare statements on the server (calling a batch of sp_unprepares). A value of 1 or less will cause sp_unprepare to be called immediately on PreparedStatment close."},
- {"R_enablePrepareOnFirstPreparedStatementCallPropertyDescription", "This setting specifies whether a prepared statement is prepared (sp_prepexec) on first use (property=true) or on second after first calling sp_executesql (property=false)."},
- {"R_statementPoolingCacheSizePropertyDescription", "This setting specifies the size of the prepared statement cache for a connection. A value less than 1 means no cache."},
- {"R_gsscredentialPropertyDescription", "Impersonated GSS Credential to access SQL Server."},
- {"R_noParserSupport", "An error occurred while instantiating the required parser. Error: \"{0}\""},
- {"R_writeOnlyXML", "Cannot read from this SQLXML instance. This instance is for writing data only."},
- {"R_dataHasBeenReadXML", "Cannot read from this SQLXML instance. The data has already been read."},
- {"R_readOnlyXML", "Cannot write to this SQLXML instance. This instance is for reading data only."},
- {"R_dataHasBeenSetXML", "Cannot write to this SQLXML instance. The data has already been set."},
- {"R_noDataXML", "No data has been set in this SQLXML instance."},
- {"R_cantSetNull", "Cannot set a null value."},
- {"R_failedToParseXML", "Failed to parse the XML. Error: \"{0}\""},
- {"R_isFreed", "This {0} object has been freed. It can no longer be accessed."},
- {"R_invalidProperty", "This property is not supported: {0}." },
- {"R_referencingFailedTSP", "The DataSource trustStore password needs to be set." },
- {"R_valueOutOfRange", "One or more values is out of range of values for the {0} SQL Server data type." },
- {"R_integratedAuthenticationFailed", "Integrated authentication failed."},
- {"R_permissionDenied", "Security violation. Permission to target \"{0}\" denied."},
- {"R_getSchemaError", "Error getting default schema name."},
- {"R_setSchemaWarning", "Warning: setSchema is a no-op in this driver version."},
- {"R_updateCountOutofRange", "The update count value is out of range."},
- {"R_limitOffsetNotSupported", "OFFSET clause in limit escape sequence is not supported."},
- {"R_limitEscapeSyntaxError", "Error in limit escape syntax. Failed to parse query."},
- {"R_featureNotSupported", "{0} is not supported."},
- {"R_zoneOffsetError", "Error in retrieving zone offset."},
- {"R_invalidMaxRows", "The supported maximum row count for a result set is Integer.MAX_VALUE or less."},
- {"R_schemaMismatch", "Source and destination schemas do not match."},
- {"R_invalidColumn", "Column {0} is invalid. Please check your column mappings."},
- {"R_invalidDestinationTable", "Destination table name is missing or invalid."},
- {"R_unableRetrieveColMeta", "Unable to retrieve column metadata."},
- {"R_invalidDestConnection", "Destination connection must be a connection from the Microsoft JDBC Driver for SQL Server."},
- {"R_unableRetrieveSourceData", "Unable to retrieve data from the source."},
- {"R_ParsingError", "Failed to parse data for the {0} type."},
- {"R_BulkTypeNotSupported", "Data type {0} is not supported in bulk copy."},
- {"R_invalidTransactionOption", "UseInternalTransaction option cannot be set to TRUE when used with a Connection object."},
- {"R_invalidNegativeArg", "The {0} argument cannot be negative."},
- {"R_BulkColumnMappingsIsEmpty", "Cannot perform bulk copy operation if the only mapping is an identity column and KeepIdentity is set to false."},
- {"R_DataSchemaMismatch", "Source data does not match source schema."},
- {"R_BulkDataDuplicateColumn", "Duplicate column names are not allowed."},
- {"R_invalidColumnOrdinal", "Column {0} is invalid. Column number should be greater than zero."},
- {"R_unsupportedEncoding", "The encoding {0} is not supported."},
- {"R_UnexpectedDescribeParamFormat", "Internal error. The format of the resultset returned by sp_describe_parameter_encryption is invalid. One of the resultsets is missing."},
- {"R_InvalidEncryptionKeyOridnal", "Internal error. The referenced column encryption key ordinal \"{0}\" is missing in the encryption metadata returned by sp_describe_parameter_encryption. Max ordinal is \"{1}\"."},
- {"R_MissingParamEncryptionMetadata", "Internal error. Metadata for some parameters in statement or procedure \"{0}\" is missing in the resultset returned by sp_describe_parameter_encryption."},
- {"R_UnableRetrieveParameterMetadata", "Unable to retrieve parameter encryption metadata."},
- {"R_InvalidCipherTextSize", "Specified ciphertext has an invalid size of {0} bytes, which is below the minimum {1} bytes required for decryption."},
- {"R_InvalidAlgorithmVersion","The specified ciphertext''s encryption algorithm version {0} does not match the expected encryption algorithm version {1} ."},
- {"R_InvalidAuthenticationTag", "Specified ciphertext has an invalid authentication tag. "},
- {"R_EncryptionFailed", "Internal error while encryption: {0} " },
- {"R_DecryptionFailed", "Internal error while decryption: {0} " },
- {"R_InvalidKeySize", "The column encryption key has been successfully decrypted but it''s length: {0} does not match the length: {1} for algorithm \"{2}\". Verify the encrypted value of the column encryption key in the database." },
- {"R_InvalidEncryptionType", "Encryption type {0} specified for the column in the database is either invalid or corrupted. Valid encryption types for algorithm {1} are: {2}." },
- {"R_UnknownColumnEncryptionAlgorithm", "The Algorithm {0} does not exist. Algorithms registered in the factory are {1}." },
- {"R_KeyExtractionFailed", "Key extraction failed : {0} ."},
- {"R_UntrustedKeyPath", "The column master key path {0} received from server {1} is not a trusted key path. The column master key path may be corrupt or you should set {0} as a trusted key path using SQLServerConnection.setColumnEncryptionTrustedMasterKeyPaths()."},
- {"R_UnrecognizedKeyStoreProviderName", "Failed to decrypt a column encryption key. Invalid key store provider name: {0}. A key store provider name must denote either a system key store provider or a registered custom key store provider. Valid system key provider names are: {1}. Valid (currently registered) custom key store provider names are: {2}. Please verify key store provider information in column master key definitions in the database, and verify all custom key store providers used in your application are registered properly."},
- {"R_UnsupportedDataTypeAE", "Encryption and decryption of data type {0} is not supported."},
- {"R_NormalizationErrorAE", "Decryption of the data type {0} failed. Normalization error."},
- {"R_UnsupportedNormalizationVersionAE", "Normalization version \"{0}\" received from SQL Server is either invalid or corrupted. Valid normalization versions are: {1}."},
- {"R_NullCipherTextAE", "Internal error. Ciphertext value cannot be null."},
- {"R_NullColumnEncryptionAlgorithmAE", "Internal error. Encryption algorithm cannot be null. Valid algorithms are: {1}."},
- {"R_CustomCipherAlgorithmNotSupportedAE", "Custom cipher algorithm not supported."},
- {"R_PlainTextNullAE", "Internal error. Plaintext value cannot be null."},
- {"R_StreamingDataTypeAE", "Data of length greater than {0} is not supported in encrypted {1} column."},
- {"R_AE_NotSupportedByServer","SQL Server instance in use does not support column encryption."},
- {"R_InvalidAEVersionNumber","Received invalid version number \"{0}\" for Always Encrypted."}, // From Server
- {"R_NullEncryptedColumnEncryptionKey", "Internal error. Encrypted column encryption key cannot be null."},
- {"R_EmptyEncryptedColumnEncryptionKey", "Internal error. Empty encrypted column encryption key specified."},
- {"R_InvalidMasterKeyDetails", "Invalid master key details specified."},
- {"R_CertificateError", "Error occurred while retrieving certificate \"{0}\" from keystore \"{1}\"."},
- {"R_ByteToShortConversion", "Error occurred while decrypting column encryption key."},
- {"R_InvalidCertificateSignature", "The specified encrypted column encryption key signature does not match the signature computed with the column master key (certificate) in \"{0}\". The encrypted column encryption key may be corrupt, or the specified path may be incorrect."},
- {"R_CEKDecryptionFailed", "Exception while decryption of encrypted column encryption key: {0} "},
- {"R_NullKeyEncryptionAlgorithm", "Key encryption algorithm cannot be null."},
- {"R_NullKeyEncryptionAlgorithmInternal", "Internal error. Key encryption algorithm cannot be null."},
- {"R_InvalidKeyEncryptionAlgorithm", "Invalid key encryption algorithm specified: {0}. Expected value: {1}."},
- {"R_InvalidKeyEncryptionAlgorithmInternal", "Internal error. Invalid key encryption algorithm specified: {0}. Expected value: {1}."},
- {"R_NullColumnEncryptionKey", "Column encryption key cannot be null."},
- {"R_EmptyColumnEncryptionKey", "Empty column encryption key specified."},
- {"R_CertificateNotFoundForAlias", "Certificate with alias {0} not found in the store provided by {1}. Verify the certificate has been imported correctly into the certificate location/store."},
- {"R_UnrecoverableKeyAE", "Cannot recover private key from keystore with certificate details {0}. Verify that imported certificate for Always Encrypted contains private key and password provided for certificate is correct."},
- {"R_KeyStoreNotFound", "System cannot find the key store file at the specified path. Verify that the path is correct and you have proper permissions to access it."},
- {"R_CustomKeyStoreProviderMapNull", "Column encryption key store provider map cannot be null. Expecting a non-null value."},
- {"R_EmptyCustomKeyStoreProviderName", "Invalid key store provider name specified. Key store provider names cannot be null or empty."},
- {"R_InvalidCustomKeyStoreProviderName", "Invalid key store provider name {0}. {1} prefix is reserved for system key store providers."},
- {"R_CustomKeyStoreProviderValueNull", "Null reference specified for key store provider {0}. Expecting a non-null value."},
- {"R_CustomKeyStoreProviderSetOnce", "Key store providers cannot be set more than once."},
- {"R_unknownColumnEncryptionType", "Invalid column encryption type {0}."},
- {"R_unsupportedStmtColEncSetting", "SQLServerStatementColumnEncryptionSetting cannot be null."},
- {"R_unsupportedConversionAE", "The conversion from {0} to {1} is unsupported for encrypted column."},
- {"R_InvalidDataForAE", "The given value of type {0} from the data source cannot be converted to type {1} of the specified target column."},
- {"R_authenticationPropertyDescription", "The authentication to use."},
- {"R_accessTokenPropertyDescription", "The access token to use for Azure Active Directory."},
- {"R_FedAuthRequiredPreLoginResponseInvalidValue", "Server sent an unexpected value for FedAuthRequired PreLogin Option. Value was {0}."},
- {"R_FedAuthInfoLengthTooShortForCountOfInfoIds", "The FedAuthInfo token must at least contain 4 bytes indicating the number of info IDs."},
- {"R_FedAuthInfoInvalidOffset", "FedAuthInfoDataOffset points to an invalid location. Current dataOffset is {0}."},
- {"R_FedAuthInfoFailedToReadData", "Failed to read FedAuthInfoData."},
- {"R_FedAuthInfoLengthTooShortForData", "FEDAUTHINFO token stream is not long enough ({0}) to contain the data it claims to."},
- {"R_FedAuthInfoDoesNotContainStsurlAndSpn", "FEDAUTHINFO token stream does not contain both STSURL and SPN."},
- {"R_ADALExecution", "Failed to authenticate the user {0} in Active Directory (Authentication={1})."},
- {"R_UnrequestedFeatureAckReceived", "Unrequested feature acknowledge is received. Feature ID: {0}."},
- {"R_FedAuthFeatureAckContainsExtraData", "Federated authentication feature extension ack for ADAL and Security Token includes extra data."},
- {"R_FedAuthFeatureAckUnknownLibraryType", "Attempting to use unknown federated authentication library. Library ID: {0}."},
- {"R_UnknownFeatureAck", "Unknown feature acknowledge is received."},
- {"R_SetAuthenticationWhenIntegratedSecurityTrue", "Cannot set \"Authentication\" with \"IntegratedSecurity\" set to \"true\"."},
- {"R_SetAccesstokenWhenIntegratedSecurityTrue","Cannot set the AccessToken property if the \"IntegratedSecurity\" connection string keyword has been set to \"true\"."},
- {"R_IntegratedAuthenticationWithUserPassword", "Cannot use \"Authentication=ActiveDirectoryIntegrated\" with \"User\", \"UserName\" or \"Password\" connection string keywords."},
- {"R_AccessTokenWithUserPassword","Cannot set the AccessToken property if \"User\", \"UserName\" or \"Password\" has been specified in the connection string."},
- {"R_AccessTokenCannotBeEmpty","AccesToken cannot be empty."},
- {"R_SetBothAuthenticationAndAccessToken","Cannot set the AccessToken property if \"Authentication\" has been specified in the connection string."},
- {"R_NoUserPasswordForActivePassword","Both \"User\" (or \"UserName\") and \"Password\" connection string keywords must be specified, if \"Authentication=ActiveDirectoryPassword\"."},
- {"R_NoUserPasswordForSqlPassword","Both \"User\" (or \"UserName\") and \"Password\" connection string keywords must be specified, if \"Authentication=SqlPassword\"."},
- {"R_ForceEncryptionTrue_HonorAEFalse", "Cannot set Force Encryption to true for parameter {0} because enryption is not enabled for the statement or procedure {1}."},
- {"R_ForceEncryptionTrue_HonorAETrue_UnencryptedColumn", "Cannot execute statement or procedure {0} because Force Encryption was set as true for parameter {1} and the database expects this parameter to be sent as plaintext. This may be due to a configuration error."},
- {"R_ForceEncryptionTrue_HonorAEFalseRS", "Cannot set Force Encryption to true for parameter {0} because encryption is not enabled for the statement or procedure."},
- {"R_ForceEncryptionTrue_HonorAETrue_UnencryptedColumnRS", "Cannot execute update because Force Encryption was set as true for parameter {0} and the database expects this parameter to be sent as plaintext. This may be due to a configuration error."},
- {"R_NullValue","{0} cannot be null."},
- {"R_AKVPathNull", "Azure Key Vault key path cannot be null." },
- {"R_AKVURLInvalid", "Invalid URL specified: {0}." },
- {"R_AKVMasterKeyPathInvalid", "Invalid Azure Key Vault key path specified: {0}."},
- {"R_EmptyCEK","Empty column encryption key specified."},
- {"R_EncryptedCEKNull","Encrypted column encryption key cannot be null."},
- {"R_EmptyEncryptedCEK","Encrypted Column Encryption Key length should not be zero."},
- {"R_NonRSAKey","Cannot use a non-RSA key: {0}."},
- {"R_GetAKVKeySize","Unable to get the Azure Key Vault public key size in bytes."},
- {"R_InvalidEcryptionAlgorithmVersion","Specified encrypted column encryption key contains an invalid encryption algorithm version {0}. Expected version is {1}."},
- {"R_AKVKeyLengthError","The specified encrypted column encryption key''s ciphertext length: {0} does not match the ciphertext length: {1} when using column master key (Azure Key Vault key) in {2}. The encrypted column encryption key may be corrupt, or the specified Azure Key Vault key path may be incorrect."},
- {"R_AKVSignatureLengthError","The specified encrypted column encryption key''s signature length: {0} does not match the signature length: {1} when using column master key (Azure Key Vault key) in {2}. The encrypted column encryption key may be corrupt, or the specified Azure Key Vault key path may be incorrect."},
- {"R_HashNull","Hash should not be null while decrypting encrypted column encryption key."},
- {"R_NoSHA256Algorithm","SHA-256 Algorithm is not supported."},
- {"R_VerifySignature","Unable to verify signature of the column encryption key."},
- {"R_CEKSignatureNotMatchCMK","The specified encrypted column encryption key signature does not match the signature computed with the column master key (Asymmetric key in Azure Key Vault) in {0}. The encrypted column encryption key may be corrupt, or the specified path may be incorrect."},
- {"R_DecryptCEKError","Unable to decrypt column encryption key using specified Azure Key Vault key."},
- {"R_EncryptCEKError","Unable to encrypt column encryption key using specified Azure Key Vault key."},
- {"R_CipherTextLengthNotMatchRSASize","CipherText length does not match the RSA key size."},
- {"R_GenerateSignature","Unable to generate signature using a specified Azure Key Vault Key URL."},
- {"R_SignedHashLengthError","Signed hash length does not match the RSA key size."},
- {"R_InvalidSignatureComputed","Invalid signature of the encrypted column encryption key computed."},
- {"R_UnableLoadADALSqlDll","Unable to load adalsql.dll. Error code: 0x{0}. For details, see: http://go.microsoft.com/fwlink/?LinkID=513072"},
- {"R_ADALAuthenticationMiddleErrorMessage","Error code 0x{0}; state {1}."},
- {"R_unsupportedDataTypeTVP", "Data type {0} not supported in Table-Valued Parameter."},
- {"R_moreDataInRowThanColumnInTVP", "Input array is longer than the number of columns in this table."},
- {"R_invalidTVPName"," The Table-Valued Parameter must have a valid type name."},
- {"R_invalidThreePartName","Invalid 3 part name format for TypeName."},
- {"R_unsupportedConversionTVP", "The conversion from {0} to {1} is unsupported for Table-Valued Parameter."},
- {"R_TVPMixedSource", "Cannot add column metadata. This Table-Valued Parameter has a ResultSet from which metadata will be derived."},
- {"R_TVPEmptyMetadata", "There are not enough fields in the Structured type. Structured types must have at least one field."},
- {"R_TVPInvalidValue", "The value provided for Table-Valued Parameter {0} is not valid. Only SQLServerDataTable, ResultSet and ISQLServerDataRecord objects are supported."},
- {"R_TVPInvalidColumnValue", "Input data is not in correct format."},
- {"R_TVPSortOrdinalGreaterThanFieldCount", "The sort ordinal {0} on field {1} exceeds the total number of fields."},
- {"R_TVPMissingSortOrderOrOrdinal", "The sort order and ordinal must either both be specified, or neither should be specified (SortOrder.Unspecified and -1). The values given were: order = {0}, ordinal = {1}."},
- {"R_TVPDuplicateSortOrdinal", "The sort ordinal {0} was specified twice."},
- {"R_TVPMissingSortOrdinal", "The sort ordinal {0} was not specified."},
- {"R_TVPDuplicateColumnName","A column name {0} already belongs to this SQLServerDataTable."},
- {"R_InvalidConnectionSetting", "The {0} value \"{1}\" is not valid."}, // This is used for connection settings. {0}-> property name as is, {1}-> value
- {"R_InvalidWindowsCertificateStoreEncryption", "Cannot encrypt a column encryption key with the Windows Certificate Store."},
- {"R_AEKeypathEmpty", "Internal error. Certificate path cannot be null. Use the following format: \"certificate location/certificate store/certificate thumbprint\", where \"certificate location\" is either LocalMachine or CurrentUser."},
- {"R_AEWinApiErr", "Windows Api native error."},
- {"R_AECertpathBad", "Internal error. Invalid certificate path: {0}. Use the following format: \"certificate location/certificate store/certificate thumbprint\", where \"certificate location\" is either LocalMachine or CurrentUser."},
- {"R_AECertLocBad", "Internal error. Invalid certificate location {0} in certificate path {1}. Use the following format: \"certificate location/certificate store/certificate thumbprint\", where \"certificate location\" is either LocalMachine or CurrentUser."},
- {"R_AECertStoreBad", "Internal error. Invalid certificate store {0} specified in certificate path {1}. Expected value: My."},
- {"R_AECertHashEmpty", "Internal error. Empty certificate thumbprint specified in certificate path {0}."},
- {"R_AECertNotFound", "Certificate with thumbprint {2} not found in certificate store {1} in certificate location {0}. Verify the certificate path in the column master key definition in the database is correct, and the certificate has been imported correctly into the certificate location/store."},
- {"R_AEMaloc", "Memory allocation failure."},
- {"R_AEKeypathLong", "Internal error. Specified certificate path has {0} bytes, which exceeds maximum length of {1} bytes."},
- {"R_AEECEKLenBad", "The specified encrypted column encryption key''s ciphertext length: {0} does not match the ciphertext length: {1} when using column master key (certificate) in \"{2}\". The encrypted column encryption key may be corrupt, or the specified certificate path may be incorrect."},
- {"R_AEECEKSigLenBad", "The specified encrypted column encryption key''s signature length {0} does not match the length {1} when using the column master key (certificate) in \"{2}\". The encrypted column encryption key may be corrupt, or the specified certificate path may be incorrect."},
- {"R_AEKeyPathEmptyOrReserved","The certificate path \"{0}\" is invalid; it is empty or contains reserved directory names."},
- {"R_AEKeyPathCurUser","CurrentUser was specified in key path but an error occurred obtaining the current user''s initial working directory."},
- {"R_AEKeyFileOpenError","Error opening certificate file {0}."},
- {"R_AEKeyFileReadError","Error reading certificate file {0}."},
- {"R_keyStoreAuthenticationPropertyDescription", "The name that identifies a key store."},
- {"R_keyStoreSecretPropertyDescription", "The authentication secret or information needed to locate the secret."},
- {"R_keyStoreLocationPropertyDescription", "The key store location."},
- {"R_keyStoreAuthenticationNotSet", "\"keyStoreAuthentication\" connection string keyword must be specified, if \"{0}\" is specified."},
- {"R_keyStoreSecretOrLocationNotSet", "Both \"keyStoreSecret\" and \"keyStoreLocation\" must be set, if \"keyStoreAuthentication=JavaKeyStorePassword\" has been specified in the connection string."},
- {"R_certificateStoreInvalidKeyword", "Cannot set \"keyStoreSecret\", if \"keyStoreAuthentication=CertificateStore\" has been specified in the connection string."},
- {"R_certificateStoreLocationNotSet", "\"keyStoreLocation\" must be specified, if \"keyStoreAuthentication=CertificateStore\" has been specified in the connection string."},
- {"R_certificateStorePlatformInvalid", "Cannot set \"keyStoreAuthentication=CertificateStore\" on a Windows operating system."},
- {"R_invalidKeyStoreFile", "Cannot parse \"{0}\". Either the file format is not valid or the password is not correct."}, // for JKS/PKCS
- {"R_invalidCEKCacheTtl", "Invalid column encryption key cache time-to-live specified. The columnEncryptionKeyCacheTtl value cannot be negative and timeUnit can only be DAYS, HOURS, MINUTES or SECONDS."},
- {"R_sendTimeAsDateTimeForAE", "Use sendTimeAsDateTime=false with Always Encrypted."},
- {"R_TVPnotWorkWithSetObjectResultSet", "setObject() with ResultSet is not supported for Table-Valued Parameter. Please use setStructured()."},
- {"R_invalidQueryTimeout", "The queryTimeout {0} is not valid."},
- {"R_invalidSocketTimeout", "The socketTimeout {0} is not valid."},
- {"R_fipsPropertyDescription", "Determines if FIPS mode is enabled."},
- {"R_invalidFipsConfig", "Unable to verify FIPS mode settings."},
- {"R_serverPreparedStatementDiscardThreshold", "The serverPreparedStatementDiscardThreshold {0} is not valid."},
- {"R_statementPoolingCacheSize", "The statementPoolingCacheSize {0} is not valid."},
- {"R_kerberosLoginFailedForUsername", "Cannot login with Kerberos principal {0}, check your credentials. {1}"},
- {"R_kerberosLoginFailed", "Kerberos Login failed: {0} due to {1} ({2})"},
- {"R_StoredProcedureNotFound", "Could not find stored procedure ''{0}''."},
- {"R_jaasConfigurationNamePropertyDescription", "Login configuration file for Kerberos authentication."},
- {"R_AKVKeyNotFound", "Key not found: {0}"},
- {"R_SQLVariantSupport", "SQL_VARIANT is not supported in versions of SQL Server before 2008."},
- {"R_invalidProbbytes", "SQL_VARIANT: invalid probBytes for {0} type."},
- {"R_invalidStringValue", "SQL_VARIANT does not support string values of length greater than 8000."},
- {"R_invalidValueForTVPWithSQLVariant", "Use of TVPs containing null sql_variant columns is not supported."},
- {"R_invalidDataTypeSupportForSQLVariant", "Unexpected TDS type ' '{0}' ' in SQL_VARIANT."},
- {"R_sslProtocolPropertyDescription", "SSL protocol label from TLS, TLSv1, TLSv1.1, and TLSv1.2. The default is TLS."},
- {"R_invalidSSLProtocol", "SSL Protocol {0} label is not valid. Only TLS, TLSv1, TLSv1.1, and TLSv1.2 are supported."},
- {"R_cancelQueryTimeoutPropertyDescription", "The number of seconds to wait to cancel sending a query timeout."},
- {"R_invalidCancelQueryTimeout", "The cancel timeout value {0} is not valid."},
- {"R_useBulkCopyForBatchInsertPropertyDescription", "Whether the driver will use bulk copy API for batch insert operations"},
- {"R_UnknownDataClsTokenNumber", "Unknown token for Data Classification."}, // From Server
- {"R_InvalidDataClsVersionNumber", "Invalid version number {0} for Data Classification."}, // From Server
- {"R_unknownUTF8SupportValue", "Unknown value for UTF8 support."},
- {"R_illegalWKT", "Illegal Well-Known text. Please make sure Well-Known text is valid."},
- {"R_illegalTypeForGeometry", "{0} is not supported for Geometry."},
- {"R_illegalWKTposition", "Illegal character in Well-Known text at position {0}."},
- };
+ // LOCALIZE THIS
+ {"R_timedOutBeforeRouting", "The timeout expired before connecting to the routing destination."},
+ {"R_invalidRoutingInfo",
+ "Unexpected routing information received. Please check your connection properties and SQL Server configuration."},
+ {"R_multipleRedirections",
+ "Two or more redirections have occurred. Only one redirection per login attempt is allowed."},
+ {"R_dbMirroringWithMultiSubnetFailover",
+ "Connecting to a mirrored SQL Server instance using the multiSubnetFailover connection property is not supported."},
+ {"R_dbMirroringWithReadOnlyIntent",
+ "Connecting to a mirrored SQL Server instance using the ApplicationIntent ReadOnly connection property is not supported."},
+ {"R_ipAddressLimitWithMultiSubnetFailover",
+ "Connecting with the multiSubnetFailover connection property to a SQL Server instance configured with more than {0} IP addresses is not supported."},
+ {"R_connectionTimedOut", "Connection timed out: no further information."},
+ {"R_invalidPositionIndex", "The position index {0} is not valid."},
+ {"R_invalidLength", "The length {0} is not valid."},
+ {"R_unknownSSType", "Invalid SQL Server data type {0}."},
+ {"R_unknownJDBCType", "Invalid JDBC data type {0}."},
+ {"R_notSQLServer",
+ "The driver received an unexpected pre-login response. Verify the connection properties and check that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. This driver can be used only with SQL Server 2005 or later."},
+ {"R_tcpOpenFailed",
+ "{0}. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall."},
+ {"R_unsupportedServerVersion", "SQL Server version {0} is not supported by this driver."},
+ {"R_noServerResponse", "SQL Server did not return a response. The connection has been closed."},
+ {"R_truncatedServerResponse",
+ "SQL Server returned an incomplete response. The connection has been closed."},
+ {"R_queryTimedOut", "The query has timed out."}, {"R_queryCancelled", "The query was canceled."},
+ {"R_errorReadingStream",
+ "An error occurred while reading the value from the stream object. Error: \"{0}\""},
+ {"R_streamReadReturnedInvalidValue",
+ "The stream read operation returned an invalid value for the amount of data read."},
+ {"R_mismatchedStreamLength",
+ "The stream value is not the specified length. The specified length was {0}, the actual length is {1}."},
+ {"R_notSupported", "This operation is not supported."},
+ {"R_invalidOutputParameter", "The index {0} of the output parameter is not valid."},
+ {"R_outputParameterNotRegisteredForOutput", "The output parameter {0} was not registered for output."},
+ {"R_parameterNotDefinedForProcedure", "Parameter {0} was not defined for stored procedure {1}."},
+ {"R_connectionIsClosed", "The connection is closed."},
+ {"R_invalidBooleanValue",
+ "The property {0} does not contain a valid boolean value. Only true or false can be used."},
+ {"R_propertyMaximumExceedsChars", "The {0} property exceeds the maximum number of {1} characters."},
+ {"R_invalidPortNumber", "The port number {0} is not valid."},
+ {"R_invalidTimeOut", "The timeout {0} is not valid."},
+ {"R_invalidLockTimeOut", "The lockTimeOut {0} is not valid."},
+ {"R_invalidAuthenticationScheme", "The authenticationScheme {0} is not valid."},
+ {"R_invalidPacketSize", "The packetSize {0} is not valid."},
+ {"R_packetSizeTooBigForSSL",
+ "SSL encryption cannot be used with a network packet size larger than {0} bytes. Please check your connection properties and SQL Server configuration."},
+ {"R_tcpipConnectionFailed", "The TCP/IP connection to the host {0}, port {1} has failed. Error: \"{2}\"."}, // {PlaceHolder="TCP/IP"}
+ {"R_invalidTransactionLevel", "The transaction level {0} is not valid."},
+ {"R_cantInvokeRollback", "Cannot invoke a rollback operation when the AutoCommit mode is set to \"true\"."},
+ {"R_cantSetSavepoint", "Cannot set a savepoint when the AutoCommit mode is set to \"true\"."},
+ {"R_sqlServerHoldability",
+ "SQL Server supports holdability at the connection level only. Use the connection.setHoldability() method."}, // {PlaceHolder="connection.setHoldability()"}
+ {"R_invalidHoldability", "The holdability value {0} is not valid."},
+ {"R_invalidColumnArrayLength", "The column array is not valid. Its length must be 1."},
+ {"R_valueNotSetForParameter", "The value is not set for the parameter number {0}."},
+ {"R_sqlBrowserFailed",
+ "The connection to the host {0}, named instance {1} failed. Error: \"{2}\". Verify the server and instance names and check that no firewall is blocking UDP traffic to port 1434. For SQL Server 2005 or later, verify that the SQL Server Browser Service is running on the host."},
+ {"R_notConfiguredToListentcpip", "The server {0} is not configured to listen with TCP/IP."},
+ {"R_cantIdentifyTableMetadata", "Unable to identify the table {0} for the metadata."},
+ {"R_metaDataErrorForParameter", "A metadata error for the parameter {0} occurred."},
+ {"R_invalidParameterNumber", "The parameter number {0} is not valid."},
+ {"R_noMetadata", "There is no metadata."}, {"R_resultsetClosed", "The result set is closed."},
+ {"R_invalidColumnName", "The column name {0} is not valid."},
+ {"R_resultsetNotUpdatable", "The result set is not updatable."},
+ {"R_indexOutOfRange", "The index {0} is out of range."},
+ {"R_savepointNotNamed", "The savepoint is not named."}, {"R_savepointNamed", "The savepoint {0} is named."},
+ {"R_resultsetNoCurrentRow", "The result set has no current row."},
+ {"R_mustBeOnInsertRow", "The cursor is not on the insert row."},
+ {"R_mustNotBeOnInsertRow", "The requested operation is not valid on the insert row."},
+ {"R_cantUpdateDeletedRow", "A deleted row cannot be updated."},
+ {"R_noResultset", "The statement did not return a result set."},
+ {"R_resultsetGeneratedForUpdate", "A result set was generated for update."},
+ {"R_statementIsClosed", "The statement is closed."},
+ {"R_invalidRowcount", "The maximum row count {0} for a result set must be non-negative."},
+ {"R_invalidQueryTimeOutValue", "The query timeout value {0} is not valid."},
+ {"R_invalidFetchDirection", "The fetch direction {0} is not valid."},
+ {"R_invalidFetchSize", "The fetch size cannot be negative."},
+ {"R_noColumnParameterValue", "No column parameter values were specified to update the row."},
+ {"R_statementMustBeExecuted", "The statement must be executed before any results can be obtained."},
+ {"R_modeSuppliedNotValid", "The supplied mode is not valid."},
+ {"R_errorConnectionString", "The connection string contains a badly formed name or value."},
+ {"R_errorProcessingComplexQuery", "An error occurred while processing the complex query."},
+ {"R_invalidOffset", "The offset {0} is not valid."}, {"R_nullConnection", "The connection URL is null."},
+ {"R_invalidConnection", "The connection URL is invalid."},
+ {"R_cannotTakeArgumentsPreparedOrCallable",
+ "The method {0} cannot take arguments on a PreparedStatement or CallableStatement."},
+ // Invalid conversion (e.g. MONEY to Timestamp)
+ {"R_unsupportedConversionFromTo", "The conversion from {0} to {1} is unsupported."},
+ // Invalid conversion to an unknown type
+ {"R_unsupportedConversionTo", "The conversion to {0} is unsupported."},
+ // Data-dependent conversion failure (e.g. "foo" vs. "123", to Integer)
+ {"R_errorConvertingValue", "An error occurred while converting the {0} value to JDBC data type {1}."},
+ {"R_streamIsClosed", "The stream is closed."}, {"R_invalidTDS", "The TDS protocol stream is not valid."},
+ {"R_unexpectedToken", " Unexpected token {0}."},
+ {"R_selectNotPermittedinBatch", "The SELECT statement is not permitted in a batch."},
+ {"R_failedToCreateXAConnection", "Failed to create the XA control connection. Error: \"{0}\""},
+ {"R_codePageNotSupported", "Codepage {0} is not supported by the Java environment."},
+ {"R_unknownSortId", "SQL Server collation {0} is not supported by this driver."},
+ {"R_unknownLCID", "Windows collation {0} is not supported by this driver."},
+ {"R_encodingErrorWritingTDS",
+ "An encoding error occurred while writing a string to the TDS buffer. Error: \"{0}\""},
+ {"R_processingError", "A processing error \"{0}\" occurred."},
+ {"R_requestedOpNotSupportedOnForward",
+ "The requested operation is not supported on forward only result sets."},
+ {"R_unsupportedCursor", "The cursor type is not supported."},
+ {"R_unsupportedCursorOperation", "The requested operation is not supported with this cursor type."},
+ {"R_unsupportedConcurrency", "The concurrency is not supported."},
+ {"R_unsupportedCursorAndConcurrency", "The cursor type/concurrency combination is not supported."},
+ {"R_stringReadError", "A string read error occurred at offset:{0}."},
+ {"R_stringWriteError", "A string write error occurred at offset:{0}."},
+ {"R_stringNotInHex", "The string is not in a valid hex format."},
+ {"R_unknownType", "The Java type {0} is not a supported type."},
+ {"R_physicalConnectionIsClosed", "The physical connection is closed for this pooled connection."},
+ {"R_invalidDataSourceReference", "Invalid DataSource reference."},
+ {"R_cantGetColumnValueFromDeletedRow", "Cannot get a value from a deleted row."},
+ {"R_cantGetUpdatedColumnValue",
+ "Updated columns cannot be accessed until updateRow() or cancelRowUpdates() has been called."},
+ {"R_cantUpdateColumn", "The column value cannot be updated."},
+ {"R_positionedUpdatesNotSupported", "Positioned updates and deletes are not supported."},
+ {"R_invalidAutoGeneratedKeys",
+ "The autoGeneratedKeys parameter value {0} is not valid. Only the values Statement.RETURN_GENERATED_KEYS and Statement.NO_GENERATED_KEYS can be used."},
+ {"R_notConfiguredForIntegrated", "This driver is not configured for integrated authentication."},
+ {"R_failoverPartnerWithoutDB",
+ "databaseName is required when using the failoverPartner connection property."},
+ {"R_invalidPartnerConfiguration",
+ "The database {0} on server {1} is not configured for database mirroring."},
+ {"R_invaliddisableStatementPooling", "The disableStatementPooling value {0} is not valid."},
+ {"R_invalidselectMethod", "The selectMethod {0} is not valid."},
+ {"R_invalidpropertyValue",
+ "The data type of connection property {0} is not valid. All the properties for this connection must be of String type."},
+ {"R_invalidArgument", "The argument {0} is not valid."},
+ {"R_streamWasNotMarkedBefore", "The stream has not been marked."},
+ {"R_invalidresponseBuffering", "The responseBuffering connection property {0} is not valid."},
+ {"R_invalidapplicationIntent", "The applicationIntent connection property {0} is not valid."},
+ {"R_dataAlreadyAccessed", "The data has been accessed and is not available for this column or parameter."},
+ {"R_outParamsNotPermittedinBatch", "The OUT and INOUT parameters are not permitted in a batch."},
+ {"R_sslRequiredNoServerSupport",
+ "The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. The application requested encryption but the server is not configured to support SSL."},
+ {"R_sslRequiredByServer",
+ "SQL Server login requires an encrypted connection that uses Secure Sockets Layer (SSL)."},
+ {"R_sslFailed",
+ "The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. Error: \"{0}\"."},
+ {"R_certNameFailed",
+ "Failed to validate the server name in a certificate during Secure Sockets Layer (SSL) initialization."},
+ {"R_failedToInitializeXA",
+ "Failed to initialize the stored procedure xp_sqljdbc_xa_init. The status is: {0}. Error: \"{1}\""},
+ {"R_failedFunctionXA", "The function {0} failed. The status is: {1}. Error: \"{2}\""},
+ {"R_noTransactionCookie", "The function {0} failed. No transaction cookie was returned."},
+ {"R_failedToEnlist", "Failed to enlist. Error: \"{0}\""},
+ {"R_failedToUnEnlist", "Failed to unenlist. Error: \"{0}\""},
+ {"R_failedToReadRecoveryXIDs", "Failed to read recovery XA branch transaction IDs (XIDs). Error: \"{0}\""},
+ {"R_userPropertyDescription", "The database user."},
+ {"R_passwordPropertyDescription", "The database password."},
+ {"R_databaseNamePropertyDescription", "The name of the database to connect to."},
+ {"R_serverNamePropertyDescription", "The computer running SQL Server."},
+ {"R_portNumberPropertyDescription", "The TCP port where an instance of SQL Server is listening."},
+ {"R_serverSpnPropertyDescription", "SQL Server SPN."},
+ {"R_columnEncryptionSettingPropertyDescription", "The column encryption setting."},
+ {"R_serverNameAsACEPropertyDescription",
+ "Translates the serverName from Unicode to ASCII Compatible Encoding (ACE), as defined by the ToASCII operation of RFC 3490."},
+ {"R_sendStringParametersAsUnicodePropertyDescription",
+ "Determines if the string parameters are sent to the server as Unicode or the database's character set."},
+ {"R_multiSubnetFailoverPropertyDescription",
+ "Indicates that the application is connecting to the Availability Group Listener of an Availability Group or Failover Cluster Instance."},
+ {"R_applicationNamePropertyDescription",
+ "The application name for SQL Server profiling and logging tools."},
+ {"R_lastUpdateCountPropertyDescription",
+ "Ensures that only the last update count is returned from an SQL statement passed to the server."},
+ {"R_disableStatementPoolingPropertyDescription", "Disables the statement pooling feature."},
+ {"R_integratedSecurityPropertyDescription",
+ "Indicates whether Windows authentication will be used to connect to SQL Server."},
+ {"R_authenticationSchemePropertyDescription",
+ "The authentication scheme to be used for integrated authentication."},
+ {"R_lockTimeoutPropertyDescription",
+ "The number of milliseconds to wait before the database reports a lock time-out."},
+ {"R_loginTimeoutPropertyDescription",
+ "The number of seconds the driver should wait before timing out a failed connection."},
+ {"R_instanceNamePropertyDescription", "The name of the SQL Server instance to connect to."},
+ {"R_xopenStatesPropertyDescription",
+ "Determines if the driver returns XOPEN-compliant SQL state codes in exceptions."},
+ {"R_selectMethodPropertyDescription",
+ "Enables the application to use server cursors to process forward only, read only result sets."},
+ {"R_responseBufferingPropertyDescription",
+ "Controls the adaptive buffering behavior to allow the application to process large result sets without requiring server cursors."},
+ {"R_applicationIntentPropertyDescription",
+ "Declares the application workload type when connecting to a server. Possible values are ReadOnly and ReadWrite."},
+ {"R_workstationIDPropertyDescription", "The host name of the workstation."},
+ {"R_failoverPartnerPropertyDescription",
+ "The name of the failover server used in a database mirroring configuration."},
+ {"R_packetSizePropertyDescription", "The network packet size used to communicate with SQL Server."},
+ {"R_encryptPropertyDescription",
+ "Determines if Secure Sockets Layer (SSL) encryption should be used between the client and the server."},
+ {"R_trustServerCertificatePropertyDescription",
+ "Determines if the driver should validate the SQL Server Secure Sockets Layer (SSL) certificate."},
+ {"R_trustStoreTypePropertyDescription", "KeyStore type."},
+ {"R_trustStorePropertyDescription", "The path to the certificate TrustStore file."},
+ {"R_trustStorePasswordPropertyDescription",
+ "The password used to check the integrity of the trust store data."},
+ {"R_trustManagerClassPropertyDescription",
+ "The class to instantiate as the TrustManager for SSL connections."},
+ {"R_trustManagerConstructorArgPropertyDescription",
+ "The optional argument to pass to the constructor specified by trustManagerClass."},
+ {"R_hostNameInCertificatePropertyDescription",
+ "The host name to be used when validating the SQL Server Secure Sockets Layer (SSL) certificate."},
+ {"R_sendTimeAsDatetimePropertyDescription",
+ "Determines whether to use the SQL Server datetime data type to send java.sql.Time values to the database."},
+ {"R_TransparentNetworkIPResolutionPropertyDescription",
+ "Determines whether to use the Transparent Network IP Resolution feature."},
+ {"R_queryTimeoutPropertyDescription",
+ "The number of seconds to wait before the database reports a query time-out."},
+ {"R_socketTimeoutPropertyDescription",
+ "The number of milliseconds to wait before the java.net.SocketTimeoutException is raised."},
+ {"R_serverPreparedStatementDiscardThresholdPropertyDescription",
+ "The threshold for when to close discarded prepare statements on the server (calling a batch of sp_unprepares). A value of 1 or less will cause sp_unprepare to be called immediately on PreparedStatment close."},
+ {"R_enablePrepareOnFirstPreparedStatementCallPropertyDescription",
+ "This setting specifies whether a prepared statement is prepared (sp_prepexec) on first use (property=true) or on second after first calling sp_executesql (property=false)."},
+ {"R_statementPoolingCacheSizePropertyDescription",
+ "This setting specifies the size of the prepared statement cache for a connection. A value less than 1 means no cache."},
+ {"R_gsscredentialPropertyDescription", "Impersonated GSS Credential to access SQL Server."},
+ {"R_noParserSupport", "An error occurred while instantiating the required parser. Error: \"{0}\""},
+ {"R_writeOnlyXML", "Cannot read from this SQLXML instance. This instance is for writing data only."},
+ {"R_dataHasBeenReadXML", "Cannot read from this SQLXML instance. The data has already been read."},
+ {"R_readOnlyXML", "Cannot write to this SQLXML instance. This instance is for reading data only."},
+ {"R_dataHasBeenSetXML", "Cannot write to this SQLXML instance. The data has already been set."},
+ {"R_noDataXML", "No data has been set in this SQLXML instance."},
+ {"R_cantSetNull", "Cannot set a null value."},
+ {"R_failedToParseXML", "Failed to parse the XML. Error: \"{0}\""},
+ {"R_isFreed", "This {0} object has been freed. It can no longer be accessed."},
+ {"R_invalidProperty", "This property is not supported: {0}."},
+ {"R_referencingFailedTSP", "The DataSource trustStore password needs to be set."},
+ {"R_valueOutOfRange", "One or more values is out of range of values for the {0} SQL Server data type."},
+ {"R_integratedAuthenticationFailed", "Integrated authentication failed."},
+ {"R_permissionDenied", "Security violation. Permission to target \"{0}\" denied."},
+ {"R_getSchemaError", "Error getting default schema name."},
+ {"R_setSchemaWarning", "Warning: setSchema is a no-op in this driver version."},
+ {"R_updateCountOutofRange", "The update count value is out of range."},
+ {"R_limitOffsetNotSupported", "OFFSET clause in limit escape sequence is not supported."},
+ {"R_limitEscapeSyntaxError", "Error in limit escape syntax. Failed to parse query."},
+ {"R_featureNotSupported", "{0} is not supported."},
+ {"R_zoneOffsetError", "Error in retrieving zone offset."},
+ {"R_invalidMaxRows", "The supported maximum row count for a result set is Integer.MAX_VALUE or less."},
+ {"R_schemaMismatch", "Source and destination schemas do not match."},
+ {"R_invalidColumn", "Column {0} is invalid. Please check your column mappings."},
+ {"R_invalidDestinationTable", "Destination table name is missing or invalid."},
+ {"R_unableRetrieveColMeta", "Unable to retrieve column metadata."},
+ {"R_invalidDestConnection",
+ "Destination connection must be a connection from the Microsoft JDBC Driver for SQL Server."},
+ {"R_unableRetrieveSourceData", "Unable to retrieve data from the source."},
+ {"R_ParsingError", "Failed to parse data for the {0} type."},
+ {"R_BulkTypeNotSupported", "Data type {0} is not supported in bulk copy."},
+ {"R_invalidTransactionOption",
+ "UseInternalTransaction option cannot be set to TRUE when used with a Connection object."},
+ {"R_invalidNegativeArg", "The {0} argument cannot be negative."},
+ {"R_BulkColumnMappingsIsEmpty",
+ "Cannot perform bulk copy operation if the only mapping is an identity column and KeepIdentity is set to false."},
+ {"R_DataSchemaMismatch", "Source data does not match source schema."},
+ {"R_BulkDataDuplicateColumn", "Duplicate column names are not allowed."},
+ {"R_invalidColumnOrdinal", "Column {0} is invalid. Column number should be greater than zero."},
+ {"R_unsupportedEncoding", "The encoding {0} is not supported."},
+ {"R_UnexpectedDescribeParamFormat",
+ "Internal error. The format of the resultset returned by sp_describe_parameter_encryption is invalid. One of the resultsets is missing."},
+ {"R_InvalidEncryptionKeyOridnal",
+ "Internal error. The referenced column encryption key ordinal \"{0}\" is missing in the encryption metadata returned by sp_describe_parameter_encryption. Max ordinal is \"{1}\"."},
+ {"R_MissingParamEncryptionMetadata",
+ "Internal error. Metadata for some parameters in statement or procedure \"{0}\" is missing in the resultset returned by sp_describe_parameter_encryption."},
+ {"R_UnableRetrieveParameterMetadata", "Unable to retrieve parameter encryption metadata."},
+ {"R_InvalidCipherTextSize",
+ "Specified ciphertext has an invalid size of {0} bytes, which is below the minimum {1} bytes required for decryption."},
+ {"R_InvalidAlgorithmVersion",
+ "The specified ciphertext''s encryption algorithm version {0} does not match the expected encryption algorithm version {1} ."},
+ {"R_InvalidAuthenticationTag", "Specified ciphertext has an invalid authentication tag. "},
+ {"R_EncryptionFailed", "Internal error while encryption: {0} "},
+ {"R_DecryptionFailed", "Internal error while decryption: {0} "},
+ {"R_InvalidKeySize",
+ "The column encryption key has been successfully decrypted but it''s length: {0} does not match the length: {1} for algorithm \"{2}\". Verify the encrypted value of the column encryption key in the database."},
+ {"R_InvalidEncryptionType",
+ "Encryption type {0} specified for the column in the database is either invalid or corrupted. Valid encryption types for algorithm {1} are: {2}."},
+ {"R_UnknownColumnEncryptionAlgorithm",
+ "The Algorithm {0} does not exist. Algorithms registered in the factory are {1}."},
+ {"R_KeyExtractionFailed", "Key extraction failed : {0} ."},
+ {"R_UntrustedKeyPath",
+ "The column master key path {0} received from server {1} is not a trusted key path. The column master key path may be corrupt or you should set {0} as a trusted key path using SQLServerConnection.setColumnEncryptionTrustedMasterKeyPaths()."},
+ {"R_UnrecognizedKeyStoreProviderName",
+ "Failed to decrypt a column encryption key. Invalid key store provider name: {0}. A key store provider name must denote either a system key store provider or a registered custom key store provider. Valid system key provider names are: {1}. Valid (currently registered) custom key store provider names are: {2}. Please verify key store provider information in column master key definitions in the database, and verify all custom key store providers used in your application are registered properly."},
+ {"R_UnsupportedDataTypeAE", "Encryption and decryption of data type {0} is not supported."},
+ {"R_NormalizationErrorAE", "Decryption of the data type {0} failed. Normalization error."},
+ {"R_UnsupportedNormalizationVersionAE",
+ "Normalization version \"{0}\" received from SQL Server is either invalid or corrupted. Valid normalization versions are: {1}."},
+ {"R_NullCipherTextAE", "Internal error. Ciphertext value cannot be null."},
+ {"R_NullColumnEncryptionAlgorithmAE",
+ "Internal error. Encryption algorithm cannot be null. Valid algorithms are: {1}."},
+ {"R_CustomCipherAlgorithmNotSupportedAE", "Custom cipher algorithm not supported."},
+ {"R_PlainTextNullAE", "Internal error. Plaintext value cannot be null."},
+ {"R_StreamingDataTypeAE", "Data of length greater than {0} is not supported in encrypted {1} column."},
+ {"R_AE_NotSupportedByServer", "SQL Server instance in use does not support column encryption."},
+ {"R_InvalidAEVersionNumber", "Received invalid version number \"{0}\" for Always Encrypted."}, // From
+ // Server
+ {"R_NullEncryptedColumnEncryptionKey", "Internal error. Encrypted column encryption key cannot be null."},
+ {"R_EmptyEncryptedColumnEncryptionKey", "Internal error. Empty encrypted column encryption key specified."},
+ {"R_InvalidMasterKeyDetails", "Invalid master key details specified."},
+ {"R_CertificateError", "Error occurred while retrieving certificate \"{0}\" from keystore \"{1}\"."},
+ {"R_ByteToShortConversion", "Error occurred while decrypting column encryption key."},
+ {"R_InvalidCertificateSignature",
+ "The specified encrypted column encryption key signature does not match the signature computed with the column master key (certificate) in \"{0}\". The encrypted column encryption key may be corrupt, or the specified path may be incorrect."},
+ {"R_CEKDecryptionFailed", "Exception while decryption of encrypted column encryption key: {0} "},
+ {"R_NullKeyEncryptionAlgorithm", "Key encryption algorithm cannot be null."},
+ {"R_NullKeyEncryptionAlgorithmInternal", "Internal error. Key encryption algorithm cannot be null."},
+ {"R_InvalidKeyEncryptionAlgorithm",
+ "Invalid key encryption algorithm specified: {0}. Expected value: {1}."},
+ {"R_InvalidKeyEncryptionAlgorithmInternal",
+ "Internal error. Invalid key encryption algorithm specified: {0}. Expected value: {1}."},
+ {"R_NullColumnEncryptionKey", "Column encryption key cannot be null."},
+ {"R_EmptyColumnEncryptionKey", "Empty column encryption key specified."},
+ {"R_CertificateNotFoundForAlias",
+ "Certificate with alias {0} not found in the store provided by {1}. Verify the certificate has been imported correctly into the certificate location/store."},
+ {"R_UnrecoverableKeyAE",
+ "Cannot recover private key from keystore with certificate details {0}. Verify that imported certificate for Always Encrypted contains private key and password provided for certificate is correct."},
+ {"R_KeyStoreNotFound",
+ "System cannot find the key store file at the specified path. Verify that the path is correct and you have proper permissions to access it."},
+ {"R_CustomKeyStoreProviderMapNull",
+ "Column encryption key store provider map cannot be null. Expecting a non-null value."},
+ {"R_EmptyCustomKeyStoreProviderName",
+ "Invalid key store provider name specified. Key store provider names cannot be null or empty."},
+ {"R_InvalidCustomKeyStoreProviderName",
+ "Invalid key store provider name {0}. {1} prefix is reserved for system key store providers."},
+ {"R_CustomKeyStoreProviderValueNull",
+ "Null reference specified for key store provider {0}. Expecting a non-null value."},
+ {"R_CustomKeyStoreProviderSetOnce", "Key store providers cannot be set more than once."},
+ {"R_unknownColumnEncryptionType", "Invalid column encryption type {0}."},
+ {"R_unsupportedStmtColEncSetting", "SQLServerStatementColumnEncryptionSetting cannot be null."},
+ {"R_unsupportedConversionAE", "The conversion from {0} to {1} is unsupported for encrypted column."},
+ {"R_InvalidDataForAE",
+ "The given value of type {0} from the data source cannot be converted to type {1} of the specified target column."},
+ {"R_authenticationPropertyDescription", "The authentication to use."},
+ {"R_accessTokenPropertyDescription", "The access token to use for Azure Active Directory."},
+ {"R_FedAuthRequiredPreLoginResponseInvalidValue",
+ "Server sent an unexpected value for FedAuthRequired PreLogin Option. Value was {0}."},
+ {"R_FedAuthInfoLengthTooShortForCountOfInfoIds",
+ "The FedAuthInfo token must at least contain 4 bytes indicating the number of info IDs."},
+ {"R_FedAuthInfoInvalidOffset",
+ "FedAuthInfoDataOffset points to an invalid location. Current dataOffset is {0}."},
+ {"R_FedAuthInfoFailedToReadData", "Failed to read FedAuthInfoData."},
+ {"R_FedAuthInfoLengthTooShortForData",
+ "FEDAUTHINFO token stream is not long enough ({0}) to contain the data it claims to."},
+ {"R_FedAuthInfoDoesNotContainStsurlAndSpn",
+ "FEDAUTHINFO token stream does not contain both STSURL and SPN."},
+ {"R_ADALExecution", "Failed to authenticate the user {0} in Active Directory (Authentication={1})."},
+ {"R_UnrequestedFeatureAckReceived", "Unrequested feature acknowledge is received. Feature ID: {0}."},
+ {"R_FedAuthFeatureAckContainsExtraData",
+ "Federated authentication feature extension ack for ADAL and Security Token includes extra data."},
+ {"R_FedAuthFeatureAckUnknownLibraryType",
+ "Attempting to use unknown federated authentication library. Library ID: {0}."},
+ {"R_UnknownFeatureAck", "Unknown feature acknowledge is received."},
+ {"R_SetAuthenticationWhenIntegratedSecurityTrue",
+ "Cannot set \"Authentication\" with \"IntegratedSecurity\" set to \"true\"."},
+ {"R_SetAccesstokenWhenIntegratedSecurityTrue",
+ "Cannot set the AccessToken property if the \"IntegratedSecurity\" connection string keyword has been set to \"true\"."},
+ {"R_IntegratedAuthenticationWithUserPassword",
+ "Cannot use \"Authentication=ActiveDirectoryIntegrated\" with \"User\", \"UserName\" or \"Password\" connection string keywords."},
+ {"R_AccessTokenWithUserPassword",
+ "Cannot set the AccessToken property if \"User\", \"UserName\" or \"Password\" has been specified in the connection string."},
+ {"R_AccessTokenCannotBeEmpty", "AccesToken cannot be empty."},
+ {"R_SetBothAuthenticationAndAccessToken",
+ "Cannot set the AccessToken property if \"Authentication\" has been specified in the connection string."},
+ {"R_NoUserPasswordForActivePassword",
+ "Both \"User\" (or \"UserName\") and \"Password\" connection string keywords must be specified, if \"Authentication=ActiveDirectoryPassword\"."},
+ {"R_NoUserPasswordForSqlPassword",
+ "Both \"User\" (or \"UserName\") and \"Password\" connection string keywords must be specified, if \"Authentication=SqlPassword\"."},
+ {"R_ForceEncryptionTrue_HonorAEFalse",
+ "Cannot set Force Encryption to true for parameter {0} because enryption is not enabled for the statement or procedure {1}."},
+ {"R_ForceEncryptionTrue_HonorAETrue_UnencryptedColumn",
+ "Cannot execute statement or procedure {0} because Force Encryption was set as true for parameter {1} and the database expects this parameter to be sent as plaintext. This may be due to a configuration error."},
+ {"R_ForceEncryptionTrue_HonorAEFalseRS",
+ "Cannot set Force Encryption to true for parameter {0} because encryption is not enabled for the statement or procedure."},
+ {"R_ForceEncryptionTrue_HonorAETrue_UnencryptedColumnRS",
+ "Cannot execute update because Force Encryption was set as true for parameter {0} and the database expects this parameter to be sent as plaintext. This may be due to a configuration error."},
+ {"R_NullValue", "{0} cannot be null."}, {"R_AKVPathNull", "Azure Key Vault key path cannot be null."},
+ {"R_AKVURLInvalid", "Invalid URL specified: {0}."},
+ {"R_AKVMasterKeyPathInvalid", "Invalid Azure Key Vault key path specified: {0}."},
+ {"R_EmptyCEK", "Empty column encryption key specified."},
+ {"R_EncryptedCEKNull", "Encrypted column encryption key cannot be null."},
+ {"R_EmptyEncryptedCEK", "Encrypted Column Encryption Key length should not be zero."},
+ {"R_NonRSAKey", "Cannot use a non-RSA key: {0}."},
+ {"R_GetAKVKeySize", "Unable to get the Azure Key Vault public key size in bytes."},
+ {"R_InvalidEcryptionAlgorithmVersion",
+ "Specified encrypted column encryption key contains an invalid encryption algorithm version {0}. Expected version is {1}."},
+ {"R_AKVKeyLengthError",
+ "The specified encrypted column encryption key''s ciphertext length: {0} does not match the ciphertext length: {1} when using column master key (Azure Key Vault key) in {2}. The encrypted column encryption key may be corrupt, or the specified Azure Key Vault key path may be incorrect."},
+ {"R_AKVSignatureLengthError",
+ "The specified encrypted column encryption key''s signature length: {0} does not match the signature length: {1} when using column master key (Azure Key Vault key) in {2}. The encrypted column encryption key may be corrupt, or the specified Azure Key Vault key path may be incorrect."},
+ {"R_HashNull", "Hash should not be null while decrypting encrypted column encryption key."},
+ {"R_NoSHA256Algorithm", "SHA-256 Algorithm is not supported."},
+ {"R_VerifySignature", "Unable to verify signature of the column encryption key."},
+ {"R_CEKSignatureNotMatchCMK",
+ "The specified encrypted column encryption key signature does not match the signature computed with the column master key (Asymmetric key in Azure Key Vault) in {0}. The encrypted column encryption key may be corrupt, or the specified path may be incorrect."},
+ {"R_DecryptCEKError", "Unable to decrypt column encryption key using specified Azure Key Vault key."},
+ {"R_EncryptCEKError", "Unable to encrypt column encryption key using specified Azure Key Vault key."},
+ {"R_CipherTextLengthNotMatchRSASize", "CipherText length does not match the RSA key size."},
+ {"R_GenerateSignature", "Unable to generate signature using a specified Azure Key Vault Key URL."},
+ {"R_SignedHashLengthError", "Signed hash length does not match the RSA key size."},
+ {"R_InvalidSignatureComputed", "Invalid signature of the encrypted column encryption key computed."},
+ {"R_UnableLoadADALSqlDll",
+ "Unable to load adalsql.dll. Error code: 0x{0}. For details, see: http://go.microsoft.com/fwlink/?LinkID=513072"},
+ {"R_ADALAuthenticationMiddleErrorMessage", "Error code 0x{0}; state {1}."},
+ {"R_unsupportedDataTypeTVP", "Data type {0} not supported in Table-Valued Parameter."},
+ {"R_moreDataInRowThanColumnInTVP", "Input array is longer than the number of columns in this table."},
+ {"R_invalidTVPName", " The Table-Valued Parameter must have a valid type name."},
+ {"R_invalidThreePartName", "Invalid 3 part name format for TypeName."},
+ {"R_unsupportedConversionTVP", "The conversion from {0} to {1} is unsupported for Table-Valued Parameter."},
+ {"R_TVPMixedSource",
+ "Cannot add column metadata. This Table-Valued Parameter has a ResultSet from which metadata will be derived."},
+ {"R_TVPEmptyMetadata",
+ "There are not enough fields in the Structured type. Structured types must have at least one field."},
+ {"R_TVPInvalidValue",
+ "The value provided for Table-Valued Parameter {0} is not valid. Only SQLServerDataTable, ResultSet and ISQLServerDataRecord objects are supported."},
+ {"R_TVPInvalidColumnValue", "Input data is not in correct format."},
+ {"R_TVPSortOrdinalGreaterThanFieldCount",
+ "The sort ordinal {0} on field {1} exceeds the total number of fields."},
+ {"R_TVPMissingSortOrderOrOrdinal",
+ "The sort order and ordinal must either both be specified, or neither should be specified (SortOrder.Unspecified and -1). The values given were: order = {0}, ordinal = {1}."},
+ {"R_TVPDuplicateSortOrdinal", "The sort ordinal {0} was specified twice."},
+ {"R_TVPMissingSortOrdinal", "The sort ordinal {0} was not specified."},
+ {"R_TVPDuplicateColumnName", "A column name {0} already belongs to this SQLServerDataTable."},
+ {"R_InvalidConnectionSetting", "The {0} value \"{1}\" is not valid."}, // This is used for connection
+ // settings. {0}-> property name as
+ // is, {1}-> value
+ {"R_InvalidWindowsCertificateStoreEncryption",
+ "Cannot encrypt a column encryption key with the Windows Certificate Store."},
+ {"R_AEKeypathEmpty",
+ "Internal error. Certificate path cannot be null. Use the following format: \"certificate location/certificate store/certificate thumbprint\", where \"certificate location\" is either LocalMachine or CurrentUser."},
+ {"R_AEWinApiErr", "Windows Api native error."},
+ {"R_AECertpathBad",
+ "Internal error. Invalid certificate path: {0}. Use the following format: \"certificate location/certificate store/certificate thumbprint\", where \"certificate location\" is either LocalMachine or CurrentUser."},
+ {"R_AECertLocBad",
+ "Internal error. Invalid certificate location {0} in certificate path {1}. Use the following format: \"certificate location/certificate store/certificate thumbprint\", where \"certificate location\" is either LocalMachine or CurrentUser."},
+ {"R_AECertStoreBad",
+ "Internal error. Invalid certificate store {0} specified in certificate path {1}. Expected value: My."},
+ {"R_AECertHashEmpty", "Internal error. Empty certificate thumbprint specified in certificate path {0}."},
+ {"R_AECertNotFound",
+ "Certificate with thumbprint {2} not found in certificate store {1} in certificate location {0}. Verify the certificate path in the column master key definition in the database is correct, and the certificate has been imported correctly into the certificate location/store."},
+ {"R_AEMaloc", "Memory allocation failure."},
+ {"R_AEKeypathLong",
+ "Internal error. Specified certificate path has {0} bytes, which exceeds maximum length of {1} bytes."},
+ {"R_AEECEKLenBad",
+ "The specified encrypted column encryption key''s ciphertext length: {0} does not match the ciphertext length: {1} when using column master key (certificate) in \"{2}\". The encrypted column encryption key may be corrupt, or the specified certificate path may be incorrect."},
+ {"R_AEECEKSigLenBad",
+ "The specified encrypted column encryption key''s signature length {0} does not match the length {1} when using the column master key (certificate) in \"{2}\". The encrypted column encryption key may be corrupt, or the specified certificate path may be incorrect."},
+ {"R_AEKeyPathEmptyOrReserved",
+ "The certificate path \"{0}\" is invalid; it is empty or contains reserved directory names."},
+ {"R_AEKeyPathCurUser",
+ "CurrentUser was specified in key path but an error occurred obtaining the current user''s initial working directory."},
+ {"R_AEKeyFileOpenError", "Error opening certificate file {0}."},
+ {"R_AEKeyFileReadError", "Error reading certificate file {0}."},
+ {"R_keyStoreAuthenticationPropertyDescription", "The name that identifies a key store."},
+ {"R_keyStoreSecretPropertyDescription",
+ "The authentication secret or information needed to locate the secret."},
+ {"R_keyStoreLocationPropertyDescription", "The key store location."},
+ {"R_keyStoreAuthenticationNotSet",
+ "\"keyStoreAuthentication\" connection string keyword must be specified, if \"{0}\" is specified."},
+ {"R_keyStoreSecretOrLocationNotSet",
+ "Both \"keyStoreSecret\" and \"keyStoreLocation\" must be set, if \"keyStoreAuthentication=JavaKeyStorePassword\" has been specified in the connection string."},
+ {"R_certificateStoreInvalidKeyword",
+ "Cannot set \"keyStoreSecret\", if \"keyStoreAuthentication=CertificateStore\" has been specified in the connection string."},
+ {"R_certificateStoreLocationNotSet",
+ "\"keyStoreLocation\" must be specified, if \"keyStoreAuthentication=CertificateStore\" has been specified in the connection string."},
+ {"R_certificateStorePlatformInvalid",
+ "Cannot set \"keyStoreAuthentication=CertificateStore\" on a Windows operating system."},
+ {"R_invalidKeyStoreFile",
+ "Cannot parse \"{0}\". Either the file format is not valid or the password is not correct."}, // for
+ // JKS/PKCS
+ {"R_invalidCEKCacheTtl",
+ "Invalid column encryption key cache time-to-live specified. The columnEncryptionKeyCacheTtl value cannot be negative and timeUnit can only be DAYS, HOURS, MINUTES or SECONDS."},
+ {"R_sendTimeAsDateTimeForAE", "Use sendTimeAsDateTime=false with Always Encrypted."},
+ {"R_TVPnotWorkWithSetObjectResultSet",
+ "setObject() with ResultSet is not supported for Table-Valued Parameter. Please use setStructured()."},
+ {"R_invalidQueryTimeout", "The queryTimeout {0} is not valid."},
+ {"R_invalidSocketTimeout", "The socketTimeout {0} is not valid."},
+ {"R_fipsPropertyDescription", "Determines if FIPS mode is enabled."},
+ {"R_invalidFipsConfig", "Unable to verify FIPS mode settings."},
+ {"R_serverPreparedStatementDiscardThreshold",
+ "The serverPreparedStatementDiscardThreshold {0} is not valid."},
+ {"R_statementPoolingCacheSize", "The statementPoolingCacheSize {0} is not valid."},
+ {"R_kerberosLoginFailedForUsername",
+ "Cannot login with Kerberos principal {0}, check your credentials. {1}"},
+ {"R_kerberosLoginFailed", "Kerberos Login failed: {0} due to {1} ({2})"},
+ {"R_StoredProcedureNotFound", "Could not find stored procedure ''{0}''."},
+ {"R_jaasConfigurationNamePropertyDescription", "Login configuration file for Kerberos authentication."},
+ {"R_AKVKeyNotFound", "Key not found: {0}"},
+ {"R_SQLVariantSupport", "SQL_VARIANT is not supported in versions of SQL Server before 2008."},
+ {"R_invalidProbbytes", "SQL_VARIANT: invalid probBytes for {0} type."},
+ {"R_invalidStringValue", "SQL_VARIANT does not support string values of length greater than 8000."},
+ {"R_invalidValueForTVPWithSQLVariant", "Use of TVPs containing null sql_variant columns is not supported."},
+ {"R_invalidDataTypeSupportForSQLVariant", "Unexpected TDS type ' '{0}' ' in SQL_VARIANT."},
+ {"R_sslProtocolPropertyDescription",
+ "SSL protocol label from TLS, TLSv1, TLSv1.1, and TLSv1.2. The default is TLS."},
+ {"R_invalidSSLProtocol",
+ "SSL Protocol {0} label is not valid. Only TLS, TLSv1, TLSv1.1, and TLSv1.2 are supported."},
+ {"R_cancelQueryTimeoutPropertyDescription",
+ "The number of seconds to wait to cancel sending a query timeout."},
+ {"R_invalidCancelQueryTimeout", "The cancel timeout value {0} is not valid."},
+ {"R_useBulkCopyForBatchInsertPropertyDescription",
+ "Whether the driver will use bulk copy API for batch insert operations"},
+ {"R_UnknownDataClsTokenNumber", "Unknown token for Data Classification."}, // From Server
+ {"R_InvalidDataClsVersionNumber", "Invalid version number {0} for Data Classification."}, // From Server
+ {"R_unknownUTF8SupportValue", "Unknown value for UTF8 support."},
+ {"R_illegalWKT", "Illegal Well-Known text. Please make sure Well-Known text is valid."},
+ {"R_illegalTypeForGeometry", "{0} is not supported for Geometry."},
+ {"R_illegalWKTposition", "Illegal character in Well-Known text at position {0}."},};
}
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResultSet.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResultSet.java
index b7b2370c9..89502cd2a 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResultSet.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResultSet.java
@@ -1,9 +1,6 @@
/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc;
@@ -22,6 +19,7 @@
import java.sql.ResultSetMetaData;
import java.sql.RowId;
import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
import java.sql.SQLType;
import java.sql.SQLWarning;
import java.sql.SQLXML;
@@ -33,8 +31,9 @@
import com.microsoft.sqlserver.jdbc.dataclassification.SensitivityClassification;
+
/**
- * Indicates the type of the row received from the server
+ * Indicates the type of the row received from the server.
*/
enum RowType {
ROW,
@@ -42,8 +41,9 @@ enum RowType {
UNKNOWN,
}
+
/**
- * Top-level JDBC ResultSet implementation
+ * Defines the Top-level JDBC ResultSet implementation.
*/
public class SQLServerResultSet implements ISQLServerResultSet, java.io.Serializable {
@@ -60,7 +60,8 @@ private static int nextResultSetID() {
return lastResultSetID.incrementAndGet();
}
- final static java.util.logging.Logger logger = java.util.logging.Logger.getLogger("com.microsoft.sqlserver.jdbc.internals.SQLServerResultSet");
+ final static java.util.logging.Logger logger = java.util.logging.Logger
+ .getLogger("com.microsoft.sqlserver.jdbc.internals.SQLServerResultSet");
@Override
public String toString() {
@@ -71,7 +72,8 @@ String logCursorState() {
return " currentRow:" + currentRow + " numFetchedRows:" + numFetchedRows + " rowCount:" + rowCount;
}
- protected static final java.util.logging.Logger loggerExternal = java.util.logging.Logger.getLogger("com.microsoft.sqlserver.jdbc.ResultSet");
+ protected static final java.util.logging.Logger loggerExternal = java.util.logging.Logger
+ .getLogger("com.microsoft.sqlserver.jdbc.ResultSet");
final private String loggingClassName;
@@ -130,8 +132,8 @@ final void setCurrentRowType(RowType rowType) {
}
/**
- * Currently active Stream Note only one stream can be active at a time, JDBC spec calls for the streams to be closed when a column or row move
- * occurs
+ * Currently active Stream Note only one stream can be active at a time, JDBC spec calls for the streams to be
+ * closed when a column or row move occurs
*/
private Closeable activeStream;
private SQLServerLob activeLOB;
@@ -174,8 +176,8 @@ final void setDeletedCurrentRow(boolean rowDeleted) {
/**
* Count of rows in this result set.
*
- * The number of rows in the result set may be known when this ResultSet object is created, after the first full traversal of the result set, or
- * possibly never (as is the case with DYNAMIC cursors).
+ * The number of rows in the result set may be known when this ResultSet object is created, after the first full
+ * traversal of the result set, or possibly never (as is the case with DYNAMIC cursors).
*/
static final int UNKNOWN_ROW_COUNT = -3;
private int rowCount;
@@ -186,21 +188,20 @@ final void setDeletedCurrentRow(boolean rowDeleted) {
// The CekTable retrieved from the COLMETADATA token for this resultset.
private CekTable cekTable = null;
- /* Gets the CekTable */
+ /* Returns the CekTable */
CekTable getCekTable() {
return cekTable;
}
- final void setColumnName(int index,
- String name) {
+ final void setColumnName(int index, String name) {
columns[index - 1].setColumnName(name);
}
/**
- * Skips columns between the last marked column and the target column, inclusive, optionally discarding their values as they are skipped.
+ * Skips columns between the last marked column and the target column, inclusive, optionally discarding their values
+ * as they are skipped.
*/
- private void skipColumns(int columnsToSkip,
- boolean discardValues) throws SQLServerException {
+ private void skipColumns(int columnsToSkip, boolean discardValues) throws SQLServerException {
assert lastColumnIndex >= 1;
assert 0 <= columnsToSkip && columnsToSkip <= columns.length;
@@ -227,10 +228,10 @@ public SensitivityClassification getSensitivityClassification() {
}
/**
- * Make a new result set
+ * Constructs a SQLServerResultSet.
*
* @param stmtIn
- * the generating statement
+ * the generating statement
*/
SQLServerResultSet(SQLServerStatement stmtIn) throws SQLServerException {
int resultSetID = nextResultSetID();
@@ -271,7 +272,8 @@ boolean onTabName(TDSReader tdsReader) throws SQLServerException {
}
boolean onColMetaData(TDSReader tdsReader) throws SQLServerException {
- columnMetaData = new StreamColumns(Util.shouldHonorAEForRead(stmt.stmtColumnEncriptionSetting, stmt.connection));
+ columnMetaData = new StreamColumns(
+ Util.shouldHonorAEForRead(stmt.stmtColumnEncriptionSetting, stmt.connection));
columnMetaData.setFromTDS(tdsReader);
cekTable = columnMetaData.getCekTable();
return true;
@@ -378,7 +380,8 @@ boolean onDone(TDSReader tdsReader) throws SQLServerException {
this.fetchSize = stmtIn.nFetchSize;
this.fetchDirection = stmtIn.nFetchDirection;
- CursorInitializer initializer = stmtIn.executedSqlDirectly ? (new ClientCursorInitializer()) : (new ServerCursorInitializer(stmtIn));
+ CursorInitializer initializer = stmtIn.executedSqlDirectly ? (new ClientCursorInitializer())
+ : (new ServerCursorInitializer(stmtIn));
TDSParser.parse(stmtIn.resultsReader(), initializer);
this.columns = initializer.buildColumns();
@@ -421,8 +424,7 @@ public T unwrap(Class iface) throws SQLException {
T t;
try {
t = iface.cast(this);
- }
- catch (ClassCastException e) {
+ } catch (ClassCastException e) {
throw new SQLServerException(e.getMessage(), e);
}
loggerExternal.exiting(getClassNameLogging(), "unwrap", t);
@@ -432,14 +434,15 @@ public T unwrap(Class iface) throws SQLException {
private SQLServerException rowErrorException = null;
/**
- * Check if the result set is closed
+ * Checks if the result set is closed
*
* @throws SQLServerException
*/
void checkClosed() throws SQLServerException {
if (isClosed) {
- SQLServerException.makeFromDriverError(null, null, SQLServerException.getErrString("R_resultsetClosed"), null, false);
+ SQLServerException.makeFromDriverError(null, null, SQLServerException.getErrString("R_resultsetClosed"),
+ null, false);
}
stmt.checkClosed();
@@ -463,16 +466,17 @@ public boolean isClosed() throws SQLException {
* Called by ResultSet API methods to disallow method use on forward only result sets.
*
* @throws SQLException
- * if the result set is forward only.
+ * if the result set is forward only.
* @throws SQLFeatureNotSupportedException
*/
private void throwNotScrollable() throws SQLException {
- SQLServerException.makeFromDriverError(stmt.connection, this, SQLServerException.getErrString("R_requestedOpNotSupportedOnForward"), null,
- true);
+ SQLServerException.makeFromDriverError(stmt.connection, this,
+ SQLServerException.getErrString("R_requestedOpNotSupportedOnForward"), null, true);
}
protected boolean isForwardOnly() {
- return TYPE_SS_DIRECT_FORWARD_ONLY == stmt.getSQLResultSetType() || TYPE_SS_SERVER_CURSOR_FORWARD_ONLY == stmt.getSQLResultSetType();
+ return TYPE_SS_DIRECT_FORWARD_ONLY == stmt.getSQLResultSetType()
+ || TYPE_SS_SERVER_CURSOR_FORWARD_ONLY == stmt.getSQLResultSetType();
}
private boolean isDynamic() {
@@ -488,10 +492,11 @@ private void verifyResultSetIsScrollable() throws SQLException {
* Called by ResultSet API methods to disallow method use on read only result sets.
*
* @throws SQLServerException
- * if the result set is read only.
+ * if the result set is read only.
*/
private void throwNotUpdatable() throws SQLServerException {
- SQLServerException.makeFromDriverError(stmt.connection, this, SQLServerException.getErrString("R_resultsetNotUpdatable"), null, true);
+ SQLServerException.makeFromDriverError(stmt.connection, this,
+ SQLServerException.getErrString("R_resultsetNotUpdatable"), null, true);
}
private void verifyResultSetIsUpdatable() throws SQLServerException {
@@ -500,7 +505,7 @@ private void verifyResultSetIsUpdatable() throws SQLServerException {
}
/**
- * Checks whether the result set has a current row.
+ * Returns whether the result set has a current row.
*
* @return true if there is a current row
* @return false if the result set is positioned before the first row or after the last row.
@@ -512,20 +517,22 @@ private boolean hasCurrentRow() {
/**
* Verifies whether this result set has a current row.
*
- * This check DOES NOT consider whether the cursor is on the insert row. The result set may or may not have a current row regardless whether the
- * cursor is on the insert row. Consider the following scenarios:
+ * This check DOES NOT consider whether the cursor is on the insert row. The result set may or may not have a
+ * current row regardless whether the cursor is on the insert row. Consider the following scenarios:
*
- * beforeFirst(); moveToInsertRow(); relative(1); No current row to move relative to. Throw "no current row" exception.
+ * beforeFirst(); moveToInsertRow(); relative(1); No current row to move relative to. Throw "no current row"
+ * exception.
*
- * first(); moveToInsertRow(); relative(1); Call to relative moves off of the insert row one row past the current row. That is, the cursor ends up
- * on the second row of the result set.
+ * first(); moveToInsertRow(); relative(1); Call to relative moves off of the insert row one row past the current
+ * row. That is, the cursor ends up on the second row of the result set.
*
* @throws SQLServerException
- * if the result set has no current row
+ * if the result set has no current row
*/
private void verifyResultSetHasCurrentRow() throws SQLServerException {
if (!hasCurrentRow()) {
- SQLServerException.makeFromDriverError(stmt.connection, stmt, SQLServerException.getErrString("R_resultsetNoCurrentRow"), null, true);
+ SQLServerException.makeFromDriverError(stmt.connection, stmt,
+ SQLServerException.getErrString("R_resultsetNoCurrentRow"), null, true);
}
}
@@ -533,19 +540,21 @@ private void verifyResultSetHasCurrentRow() throws SQLServerException {
* Called by ResultSet API methods to disallow method use when cursor is on a deleted row.
*
* @throws SQLServerException
- * if the cursor is not on an updatable row.
+ * if the cursor is not on an updatable row.
*/
private void verifyCurrentRowIsNotDeleted(String errResource) throws SQLServerException {
if (currentRowDeleted()) {
- SQLServerException.makeFromDriverError(stmt.connection, stmt, SQLServerException.getErrString(errResource), null, true);
+ SQLServerException.makeFromDriverError(stmt.connection, stmt, SQLServerException.getErrString(errResource),
+ null, true);
}
}
/**
- * Called by ResultSet API methods to disallow method use when the column index is not in the range of columns returned in the results.
+ * Called by ResultSet API methods to disallow method use when the column index is not in the range of columns
+ * returned in the results.
*
* @throws SQLServerException
- * if the column index is out of bounds
+ * if the column index is out of bounds
*/
private void verifyValidColumnIndex(int index) throws SQLServerException {
int nCols = columns.length;
@@ -567,25 +576,28 @@ private void verifyValidColumnIndex(int index) throws SQLServerException {
* Called by ResultSet API methods to disallow method use when cursor is on the insert row.
*
* @throws SQLServerException
- * if the cursor is on the insert row.
+ * if the cursor is on the insert row.
*/
private void verifyResultSetIsNotOnInsertRow() throws SQLServerException {
if (isOnInsertRow) {
- SQLServerException.makeFromDriverError(stmt.connection, stmt, SQLServerException.getErrString("R_mustNotBeOnInsertRow"), null, true);
+ SQLServerException.makeFromDriverError(stmt.connection, stmt,
+ SQLServerException.getErrString("R_mustNotBeOnInsertRow"), null, true);
}
}
private void throwUnsupportedCursorOp() throws SQLServerException {
// Absolute positioning of dynamic cursors is unsupported.
- SQLServerException.makeFromDriverError(stmt.connection, this, SQLServerException.getErrString("R_unsupportedCursorOperation"), null, true);
+ SQLServerException.makeFromDriverError(stmt.connection, this,
+ SQLServerException.getErrString("R_unsupportedCursorOperation"), null, true);
}
/**
- * Close the result set.
+ * Closes the result set.
*
- * Note that the public close() method performs all of the cleanup work through this internal method which cannot throw any exceptions. This is
- * done deliberately to ensure that ALL of the object's client-side and server-side state is cleaned up as best as possible, even under conditions
- * which would normally result in exceptions being thrown.
+ * Note that the public close() method performs all of the cleanup work through this internal method which cannot
+ * throw any exceptions. This is done deliberately to ensure that ALL of the object's client-side and server-side
+ * state is cleaned up as best as possible, even under conditions which would normally result in exceptions being
+ * thrown.
*/
private void closeInternal() {
// Calling close on a closed ResultSet is a no-op per JDBC spec
@@ -619,12 +631,12 @@ public void close() throws SQLServerException {
}
/**
- * Find a column index given a column name
+ * Finds a column index given a column name.
*
* @param columnName
- * the name of the column
+ * the name of the column
* @throws SQLServerException
- * If any errors occur.
+ * If any errors occur.
* @return the column index
*/
@Override
@@ -691,11 +703,9 @@ final Column getColumn(int columnIndex) throws SQLServerException {
try {
fillLOBs();
activeStream.close();
- }
- catch (IOException e) {
+ } catch (IOException e) {
SQLServerException.makeFromDriverError(null, null, e.getMessage(), null, true);
- }
- finally {
+ } finally {
activeStream = null;
}
}
@@ -704,8 +714,8 @@ final Column getColumn(int columnIndex) throws SQLServerException {
}
/**
- * This function initializes null compressed columns only when the row type is NBCROW and if the areNullCompressedColumnsInitialized is false. In
- * all other cases this will be a no-op.
+ * Initializes null compressed columns only when the row type is NBCROW and if the
+ * areNullCompressedColumnsInitialized is false. In all other cases this will be a no-op.
*
* @throws SQLServerException
*/
@@ -713,7 +723,9 @@ private void initializeNullCompressedColumns() throws SQLServerException {
if (resultSetCurrentRowType.equals(RowType.NBCROW) && (!areNullCompressedColumnsInitialized)) {
int columnNo = 0;
// no of bytes to be read from the stream
- int noOfBytes = ((this.columns.length - 1) >> 3) + 1;// equivalent of (int)Math.ceil(this.columns.length/8.0) and gives better perf
+ int noOfBytes = ((this.columns.length - 1) >> 3) + 1;// equivalent of
+ // (int)Math.ceil(this.columns.length/8.0) and gives
+ // better perf
for (int byteNo = 0; byteNo < noOfBytes; byteNo++) {
int byteValue = tdsReader.readUnsignedByte();
@@ -751,10 +763,10 @@ private Column loadColumn(int index) throws SQLServerException {
}
/**
- * Clear result set warnings
+ * Clears result set warnings.
*
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
*/
@Override
public void clearWarnings() throws SQLServerException {
@@ -886,8 +898,7 @@ private void moveBackward(int rowsToMove) throws SQLServerException {
// to clientMoveAbsolute is interpreted as relative to the last row, not the first.
if (currentRow + rowsToMove < 1) {
moveBeforeFirst();
- }
- else {
+ } else {
currentRow = clientMoveAbsolute(currentRow + rowsToMove);
}
@@ -920,13 +931,11 @@ private void moveBackward(int rowsToMove) throws SQLServerException {
}
// Scroll past the last of the returned rows, and ...
- while (scrollWindow.next(this))
- ;
+ while (scrollWindow.next(this));
// back up one row.
scrollWindow.previous(this);
- }
- else {
+ } else {
doServerFetch(TDS.FETCH_RELATIVE, rowsToMove + scrollWindow.getRow() - 1, fetchSize);
// If the new fetch buffer returned no rows, then the cursor has reached the start of the result set.
@@ -941,10 +950,10 @@ private void moveBackward(int rowsToMove) throws SQLServerException {
}
/**
- * Update the current row's position if known.
+ * Updates the current row's position if known.
*
- * If known, the current row is assumed to be at a valid position somewhere in the ResultSet. That is, the current row is not before the first row
- * or after the last row.
+ * If known, the current row is assumed to be at a valid position somewhere in the ResultSet. That is, the current
+ * row is not before the first row or after the last row.
*/
private void updateCurrentRow(int rowsToMove) {
if (UNKNOWN_ROW != currentRow) {
@@ -955,8 +964,8 @@ private void updateCurrentRow(int rowsToMove) {
}
/**
- * Initially moves the cursor to the first row of this ResultSet object, with subsequent calls moving the cursor to the second row, the third row,
- * and so on.
+ * Moves the cursor to the first row of this ResultSet object initially, then subsequent calls move the cursor to
+ * the second row, the third row, and so on.
*
* @return false when there are no more rows to read
*/
@@ -1063,7 +1072,10 @@ public boolean wasNull() throws SQLServerException {
}
/**
- * @return true if the cursor is before the first row in this result set, returns false otherwise or if the result set contains no rows.
+ * Returns if the cursor is before the first row in this result set.
+ *
+ * @return true if the cursor is before the first row in this result set, returns false otherwise or if the result
+ * set contains no rows.
*/
@Override
public boolean isBeforeFirst() throws SQLException {
@@ -1161,19 +1173,19 @@ public boolean isAfterLast() throws SQLException {
}
/**
- * Retrieves whether the cursor is on the first row of this ResultSet
object.
+ * Returns whether the cursor is on the first row of this ResultSet
object.
*
- * This method should be called only on ResultSet objects that are scrollable: TYPE_SCROLL_SENSITIVE, TYPE_SCROLL_INSENSITIVE,
- * TYPE_SS_SCROLL_STATIC, TYPE_SS_SCROLL_KEYSET, TYPE_SS_SCROLL_DYNAMIC.
+ * This method should be called only on ResultSet objects that are scrollable: TYPE_SCROLL_SENSITIVE,
+ * TYPE_SCROLL_INSENSITIVE, TYPE_SS_SCROLL_STATIC, TYPE_SS_SCROLL_KEYSET, TYPE_SS_SCROLL_DYNAMIC.
*
*
- * Note:Support for the isFirst
method is optional for ResultSet
s with a result set type of
- * TYPE_FORWARD_ONLY
+ * Note:Support for the isFirst
method is optional for ResultSet
s with a
+ * result set type of TYPE_FORWARD_ONLY
*
* @return true
if the cursor is on the first row; false
otherwise
*
* @exception SQLException
- * if a database access error occurs or this method is called on a closed result set
+ * if a database access error occurs or this method is called on a closed result set
*
* @since 1.2
*/
@@ -1208,22 +1220,22 @@ public boolean isFirst() throws SQLException {
}
/**
- * Retrieves whether the cursor is on the last row of this ResultSet
object. Note: Calling the method
- * isLast
may be expensive because the JDBC driver might need to fetch ahead one row in order to determine whether the current row is
- * the last row in the result set.
+ * Returns whether the cursor is on the last row of this ResultSet
object. Note:
+ * Calling the method isLast
may be expensive because the JDBC driver might need to fetch ahead one row
+ * in order to determine whether the current row is the last row in the result set.
*
*
- * This method should be called only on ResultSet objects that are scrollable: TYPE_SCROLL_SENSITIVE, TYPE_SCROLL_INSENSITIVE,
- * TYPE_SS_SCROLL_STATIC, TYPE_SS_SCROLL_KEYSET, TYPE_SS_SCROLL_DYNAMIC.
+ * This method should be called only on ResultSet objects that are scrollable: TYPE_SCROLL_SENSITIVE,
+ * TYPE_SCROLL_INSENSITIVE, TYPE_SS_SCROLL_STATIC, TYPE_SS_SCROLL_KEYSET, TYPE_SS_SCROLL_DYNAMIC.
*
*
- * Note: Support for the isLast
method is optional for ResultSet
s with a result set type of
- * TYPE_FORWARD_ONLY
+ * Note: Support for the isLast
method is optional for ResultSet
s with a
+ * result set type of TYPE_FORWARD_ONLY
*
* @return true
if the cursor is on the last row; false
otherwise
*
* @exception SQLException
- * if a database access error occurs or this method is called on a closed result set
+ * if a database access error occurs or this method is called on a closed result set
*
* @since 1.2
*/
@@ -1302,8 +1314,7 @@ private void moveBeforeFirst() throws SQLServerException {
if (0 == serverCursorId) {
fetchBufferBeforeFirst();
scrollWindow.clear();
- }
- else {
+ } else {
doServerFetch(TDS.FETCH_FIRST, 0, 0);
}
@@ -1346,15 +1357,16 @@ private void moveAfterLast() throws SQLServerException {
* Moves the cursor to the first row in this ResultSet
object.
*
*
- * This method should be called only on ResultSet objects that are scrollable: TYPE_SCROLL_SENSITIVE, TYPE_SCROLL_INSENSITIVE,
- * TYPE_SS_SCROLL_STATIC, TYPE_SS_SCROLL_KEYSET, TYPE_SS_SCROLL_DYNAMIC.
+ * This method should be called only on ResultSet objects that are scrollable: TYPE_SCROLL_SENSITIVE,
+ * TYPE_SCROLL_INSENSITIVE, TYPE_SS_SCROLL_STATIC, TYPE_SS_SCROLL_KEYSET, TYPE_SS_SCROLL_DYNAMIC.
*
*
- * @return true
if the cursor is on a valid row; false
if there are no rows in the result set
+ * @return true
if the cursor is on a valid row; false
if there are no rows in the result
+ * set
*
* @exception SQLException
- * if a database access error occurs; this method is called on a closed result set or the result set type is
- * TYPE_FORWARD_ONLY
+ * if a database access error occurs; this method is called on a closed result set or the result set type
+ * is TYPE_FORWARD_ONLY
*
* @since 1.2
*/
@@ -1380,8 +1392,7 @@ public boolean first() throws SQLException {
private void moveFirst() throws SQLServerException {
if (0 == serverCursorId) {
moveBeforeFirst();
- }
- else {
+ } else {
// Fetch the first block of up to fetchSize rows
doServerFetch(TDS.FETCH_FIRST, 0, fetchSize);
}
@@ -1404,14 +1415,15 @@ private void moveFirst() throws SQLServerException {
/**
* Moves the cursor to the last row in this ResultSet
object.
*
- * This method should be called only on ResultSet objects that are scrollable: TYPE_SCROLL_SENSITIVE, TYPE_SCROLL_INSENSITIVE,
- * TYPE_SS_SCROLL_STATIC, TYPE_SS_SCROLL_KEYSET, TYPE_SS_SCROLL_DYNAMIC.
+ * This method should be called only on ResultSet objects that are scrollable: TYPE_SCROLL_SENSITIVE,
+ * TYPE_SCROLL_INSENSITIVE, TYPE_SS_SCROLL_STATIC, TYPE_SS_SCROLL_KEYSET, TYPE_SS_SCROLL_DYNAMIC.
*
- * @return true
if the cursor is on a valid row; false
if there are no rows in the result set
+ * @return true
if the cursor is on a valid row; false
if there are no rows in the result
+ * set
*
* @exception SQLException
- * if a database access error occurs; this method is called on a closed result set or the result set type is
- * TYPE_FORWARD_ONLY
+ * if a database access error occurs; this method is called on a closed result set or the result set type
+ * is TYPE_FORWARD_ONLY
*
* @since 1.2
*/
@@ -1455,8 +1467,7 @@ private void moveLast() throws SQLServerException {
}
// Scroll to the last of the returned rows
- while (scrollWindow.next(this))
- ;
+ while (scrollWindow.next(this));
scrollWindow.previous(this);
// Adjust the current row appropriately
@@ -1496,40 +1507,41 @@ public int getRow() throws SQLException {
* Moves the cursor to the given row number in this ResultSet
object.
*
*
- * This method should be called only on ResultSet objects that are scrollable: TYPE_SCROLL_SENSITIVE, TYPE_SCROLL_INSENSITIVE,
- * TYPE_SS_SCROLL_STATIC, TYPE_SS_SCROLL_KEYSET, TYPE_SS_SCROLL_DYNAMIC.
+ * This method should be called only on ResultSet objects that are scrollable: TYPE_SCROLL_SENSITIVE,
+ * TYPE_SCROLL_INSENSITIVE, TYPE_SS_SCROLL_STATIC, TYPE_SS_SCROLL_KEYSET, TYPE_SS_SCROLL_DYNAMIC.
*
*
*
- * If the row number is positive, the cursor moves to the given row number with respect to the beginning of the result set. The first row is row
- * 1, the second is row 2, and so on.
+ * If the row number is positive, the cursor moves to the given row number with respect to the beginning of the
+ * result set. The first row is row 1, the second is row 2, and so on.
*
*
- * If the given row number is negative, the cursor moves to an absolute row position with respect to the end of the result set. For example,
- * calling the method absolute(-1)
positions the cursor on the last row; calling the method absolute(-2)
moves the
- * cursor to the next-to-last row, and so on.
+ * If the given row number is negative, the cursor moves to an absolute row position with respect to the end of the
+ * result set. For example, calling the method absolute(-1)
positions the cursor on the last row;
+ * calling the method absolute(-2)
moves the cursor to the next-to-last row, and so on.
*
*
* If the row number specified is zero, the cursor is moved to before the first row.
*
*
- * An attempt to position the cursor beyond the first/last row in the result set leaves the cursor before the first row or after the last row.
+ * An attempt to position the cursor beyond the first/last row in the result set leaves the cursor before the first
+ * row or after the last row.
*
*
- * Note: Calling absolute(1)
is the same as calling first()
. Calling absolute(-1)
is the same as
- * calling last()
.
+ * Note: Calling absolute(1)
is the same as calling first()
. Calling
+ * absolute(-1)
is the same as calling last()
.
*
* @param row
- * the number of the row to which the cursor should move. A value of zero indicates that the cursor will be positioned before the first
- * row; a positive number indicates the row number counting from the beginning of the result set; a negative number indicates the row
- * number counting from the end of the result set
+ * the number of the row to which the cursor should move. A value of zero indicates that the cursor will be
+ * positioned before the first row; a positive number indicates the row number counting from the beginning of
+ * the result set; a negative number indicates the row number counting from the end of the result set
*
- * @return true
if the cursor is moved to a position in this ResultSet
object; false
if the cursor is
- * before the first row or after the last row
+ * @return true
if the cursor is moved to a position in this ResultSet
object;
+ * false
if the cursor is before the first row or after the last row
*
* @exception SQLException
- * if a database access error occurs; this method is called on a closed result set or the result set type is
- * TYPE_FORWARD_ONLY
+ * if a database access error occurs; this method is called on a closed result set or the result set type
+ * is TYPE_FORWARD_ONLY
*
* @since 1.2
*/
@@ -1637,8 +1649,7 @@ private void moveAbsolute(int row) throws SQLServerException {
if (row > 0) {
// The current row is just the row to which we moved.
currentRow = row;
- }
- else {
+ } else {
// Absolute fetch with -ve row is relative to the end of the result set.
assert row < 0;
assert rowCount + row + 1 >= 1;
@@ -1664,7 +1675,8 @@ private boolean fetchBufferHasRows() throws SQLServerException {
// Return whether the next item in the response appears to be a row or something
// that should have been a row.
- return (TDS.TDS_ROW == tdsTokenType || TDS.TDS_NBCROW == tdsTokenType || TDS.TDS_MSG == tdsTokenType || TDS.TDS_ERR == tdsTokenType);
+ return (TDS.TDS_ROW == tdsTokenType || TDS.TDS_NBCROW == tdsTokenType || TDS.TDS_MSG == tdsTokenType
+ || TDS.TDS_ERR == tdsTokenType);
}
final void discardCurrentRow() throws SQLServerException {
@@ -1742,13 +1754,11 @@ final boolean fetchBufferNext() throws SQLServerException {
fetchBufferCurrentRowType = fetchBuffer.nextRow();
if (fetchBufferCurrentRowType.equals(RowType.UNKNOWN))
return false;
- }
- catch (SQLServerException e) {
+ } catch (SQLServerException e) {
currentRow = AFTER_LAST_ROW;
rowErrorException = e;
throw e;
- }
- finally {
+ } finally {
lastColumnIndex = 0;
resultSetCurrentRowType = fetchBufferCurrentRowType;
}
@@ -1844,14 +1854,15 @@ private int clientMoveAbsolute(int row) throws SQLServerException {
/**
* Moves the cursor to the previous row in this ResultSet
object.
*
- * This method should be called only on ResultSet objects that are scrollable: TYPE_SCROLL_SENSITIVE, TYPE_SCROLL_INSENSITIVE,
- * TYPE_SS_SCROLL_STATIC, TYPE_SS_SCROLL_KEYSET, TYPE_SS_SCROLL_DYNAMIC.
+ * This method should be called only on ResultSet objects that are scrollable: TYPE_SCROLL_SENSITIVE,
+ * TYPE_SCROLL_INSENSITIVE, TYPE_SS_SCROLL_STATIC, TYPE_SS_SCROLL_KEYSET, TYPE_SS_SCROLL_DYNAMIC.
*
- * @return true
if the cursor is now positioned on a valid row; false
if the cursor is positioned before the first row
+ * @return true
if the cursor is now positioned on a valid row; false
if the cursor is
+ * positioned before the first row
*
* @exception SQLException
- * if a database access error occurs; this method is called on a closed result set or the result set type is
- * TYPE_FORWARD_ONLY
+ * if a database access error occurs; this method is called on a closed result set or the result set type
+ * is TYPE_FORWARD_ONLY
*
* @since 1.2
*/
@@ -1911,10 +1922,12 @@ public void setFetchDirection(int direction) throws SQLException {
// Throws SQLException if the type of this ResultSet object is TYPE_FORWARD_ONLY.
verifyResultSetIsScrollable();
- if ((ResultSet.FETCH_FORWARD != direction && ResultSet.FETCH_REVERSE != direction && ResultSet.FETCH_UNKNOWN != direction) ||
+ if ((ResultSet.FETCH_FORWARD != direction && ResultSet.FETCH_REVERSE != direction
+ && ResultSet.FETCH_UNKNOWN != direction) ||
- (ResultSet.FETCH_FORWARD != direction && (SQLServerResultSet.TYPE_SS_DIRECT_FORWARD_ONLY == stmt.resultSetType
- || SQLServerResultSet.TYPE_SS_SERVER_CURSOR_FORWARD_ONLY == stmt.resultSetType))) {
+ (ResultSet.FETCH_FORWARD != direction
+ && (SQLServerResultSet.TYPE_SS_DIRECT_FORWARD_ONLY == stmt.resultSetType
+ || SQLServerResultSet.TYPE_SS_SERVER_CURSOR_FORWARD_ONLY == stmt.resultSetType))) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidFetchDirection"));
Object[] msgArgs = {direction};
SQLServerException.makeFromDriverError(stmt.connection, stmt, form.format(msgArgs), null, false);
@@ -1937,7 +1950,8 @@ public void setFetchSize(int rows) throws SQLServerException {
loggerExternal.entering(getClassNameLogging(), "setFetchSize", rows);
checkClosed();
if (rows < 0)
- SQLServerException.makeFromDriverError(stmt.connection, stmt, SQLServerException.getErrString("R_invalidFetchSize"), null, false);
+ SQLServerException.makeFromDriverError(stmt.connection, stmt,
+ SQLServerException.getErrString("R_invalidFetchSize"), null, false);
fetchSize = (0 == rows) ? stmt.defaultFetchSize : rows;
loggerExternal.exiting(getClassNameLogging(), "setFetchSize");
@@ -1977,7 +1991,7 @@ public int getConcurrency() throws SQLServerException {
* Does all the common stuff necessary when calling a getter for the column at index.
*
* @param index
- * the index of the column to get
+ * the index of the column to get
*/
Column getterGetColumn(int index) throws SQLServerException {
// Note that we don't verify here that we're not on the insert row. According to
@@ -2005,34 +2019,27 @@ Column getterGetColumn(int index) throws SQLServerException {
return loadColumn(index);
}
- private Object getValue(int columnIndex,
- JDBCType jdbcType) throws SQLServerException {
+ private Object getValue(int columnIndex, JDBCType jdbcType) throws SQLServerException {
return getValue(columnIndex, jdbcType, null, null);
}
- private Object getValue(int columnIndex,
- JDBCType jdbcType,
- Calendar cal) throws SQLServerException {
+ private Object getValue(int columnIndex, JDBCType jdbcType, Calendar cal) throws SQLServerException {
return getValue(columnIndex, jdbcType, null, cal);
}
- private Object getValue(int columnIndex,
- JDBCType jdbcType,
+ private Object getValue(int columnIndex, JDBCType jdbcType,
InputStreamGetterArgs getterArgs) throws SQLServerException {
return getValue(columnIndex, jdbcType, getterArgs, null);
}
- private Object getValue(int columnIndex,
- JDBCType jdbcType,
- InputStreamGetterArgs getterArgs,
+ private Object getValue(int columnIndex, JDBCType jdbcType, InputStreamGetterArgs getterArgs,
Calendar cal) throws SQLServerException {
Object o = getterGetColumn(columnIndex).getValue(jdbcType, getterArgs, cal, tdsReader);
lastValueWasNull = (null == o);
return o;
}
- void setInternalVariantType(int columnIndex,
- SqlVariant type) throws SQLServerException {
+ void setInternalVariantType(int columnIndex, SqlVariant type) throws SQLServerException {
getterGetColumn(columnIndex).setInternalVariant(type);
}
@@ -2040,18 +2047,17 @@ SqlVariant getVariantInternalType(int columnIndex) throws SQLServerException {
return getterGetColumn(columnIndex).getInternalVariant();
}
- private Object getStream(int columnIndex,
- StreamType streamType) throws SQLServerException {
- Object value = getValue(columnIndex, streamType.getJDBCType(),
- new InputStreamGetterArgs(streamType, stmt.getExecProps().isResponseBufferingAdaptive(), isForwardOnly(), toString()));
+ private Object getStream(int columnIndex, StreamType streamType) throws SQLServerException {
+ Object value = getValue(columnIndex, streamType.getJDBCType(), new InputStreamGetterArgs(streamType,
+ stmt.getExecProps().isResponseBufferingAdaptive(), isForwardOnly(), toString()));
activeStream = (Closeable) value;
return value;
}
private SQLXML getSQLXMLInternal(int columnIndex) throws SQLServerException {
- SQLServerSQLXML value = (SQLServerSQLXML) getValue(columnIndex, JDBCType.SQLXML,
- new InputStreamGetterArgs(StreamType.SQLXML, stmt.getExecProps().isResponseBufferingAdaptive(), isForwardOnly(), toString()));
+ SQLServerSQLXML value = (SQLServerSQLXML) getValue(columnIndex, JDBCType.SQLXML, new InputStreamGetterArgs(
+ StreamType.SQLXML, stmt.getExecProps().isResponseBufferingAdaptive(), isForwardOnly(), toString()));
if (null != value)
activeStream = value.getStream();
@@ -2078,8 +2084,7 @@ public java.io.InputStream getAsciiStream(String columnName) throws SQLServerExc
@Deprecated
@Override
- public BigDecimal getBigDecimal(int columnIndex,
- int scale) throws SQLServerException {
+ public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "getBigDecimal", new Object[] {columnIndex, scale});
checkClosed();
@@ -2092,8 +2097,7 @@ public BigDecimal getBigDecimal(int columnIndex,
@Deprecated
@Override
- public BigDecimal getBigDecimal(String columnName,
- int scale) throws SQLServerException {
+ public BigDecimal getBigDecimal(String columnName, int scale) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "columnName", new Object[] {columnName, scale});
checkClosed();
@@ -2195,8 +2199,7 @@ public java.sql.Date getDate(String columnName) throws SQLServerException {
}
@Override
- public java.sql.Date getDate(int columnIndex,
- Calendar cal) throws SQLServerException {
+ public java.sql.Date getDate(int columnIndex, Calendar cal) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "getDate", new Object[] {columnIndex, cal});
checkClosed();
@@ -2206,8 +2209,7 @@ public java.sql.Date getDate(int columnIndex,
}
@Override
- public java.sql.Date getDate(String colName,
- Calendar cal) throws SQLServerException {
+ public java.sql.Date getDate(String colName, Calendar cal) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "getDate", new Object[] {colName, cal});
checkClosed();
@@ -2344,83 +2346,64 @@ public Object getObject(int columnIndex) throws SQLServerException {
}
@Override
- public T getObject(int columnIndex,
- Class type) throws SQLException {
+ public T getObject(int columnIndex, Class type) throws SQLException {
loggerExternal.entering(getClassNameLogging(), "getObject", columnIndex);
checkClosed();
Object returnValue;
if (type == String.class) {
returnValue = getString(columnIndex);
- }
- else if (type == Byte.class) {
+ } else if (type == Byte.class) {
byte byteValue = getByte(columnIndex);
returnValue = wasNull() ? null : byteValue;
- }
- else if (type == Short.class) {
+ } else if (type == Short.class) {
short shortValue = getShort(columnIndex);
returnValue = wasNull() ? null : shortValue;
- }
- else if (type == Integer.class) {
+ } else if (type == Integer.class) {
int intValue = getInt(columnIndex);
returnValue = wasNull() ? null : intValue;
- }
- else if (type == Long.class) {
+ } else if (type == Long.class) {
long longValue = getLong(columnIndex);
returnValue = wasNull() ? null : longValue;
- }
- else if (type == BigDecimal.class) {
+ } else if (type == BigDecimal.class) {
returnValue = getBigDecimal(columnIndex);
- }
- else if (type == Boolean.class) {
+ } else if (type == Boolean.class) {
boolean booleanValue = getBoolean(columnIndex);
returnValue = wasNull() ? null : booleanValue;
- }
- else if (type == java.sql.Date.class) {
+ } else if (type == java.sql.Date.class) {
returnValue = getDate(columnIndex);
- }
- else if (type == java.sql.Time.class) {
+ } else if (type == java.sql.Time.class) {
returnValue = getTime(columnIndex);
- }
- else if (type == java.sql.Timestamp.class) {
+ } else if (type == java.sql.Timestamp.class) {
returnValue = getTimestamp(columnIndex);
- }
- else if (type == microsoft.sql.DateTimeOffset.class) {
+ } else if (type == microsoft.sql.DateTimeOffset.class) {
returnValue = getDateTimeOffset(columnIndex);
- }
- else if (type == UUID.class) {
+ } else if (type == UUID.class) {
// read binary, avoid string allocation and parsing
byte[] guid = getBytes(columnIndex);
returnValue = guid != null ? Util.readGUIDtoUUID(guid) : null;
- }
- else if (type == SQLXML.class) {
+ } else if (type == SQLXML.class) {
returnValue = getSQLXML(columnIndex);
- }
- else if (type == Blob.class) {
+ } else if (type == Blob.class) {
returnValue = getBlob(columnIndex);
- }
- else if (type == Clob.class) {
+ } else if (type == Clob.class) {
returnValue = getClob(columnIndex);
- }
- else if (type == NClob.class) {
+ } else if (type == NClob.class) {
returnValue = getNClob(columnIndex);
- }
- else if (type == byte[].class) {
+ } else if (type == byte[].class) {
returnValue = getBytes(columnIndex);
- }
- else if (type == Float.class) {
+ } else if (type == Float.class) {
float floatValue = getFloat(columnIndex);
returnValue = wasNull() ? null : floatValue;
- }
- else if (type == Double.class) {
+ } else if (type == Double.class) {
double doubleValue = getDouble(columnIndex);
returnValue = wasNull() ? null : doubleValue;
- }
- else {
+ } else {
// if the type is not supported the specification says the should
// a SQLException instead of SQLFeatureNotSupportedException
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_unsupportedConversionTo"));
Object[] msgArgs = {type};
- throw new SQLServerException(form.format(msgArgs), SQLState.DATA_EXCEPTION_NOT_SPECIFIC, DriverError.NOT_SET, null);
+ throw new SQLServerException(form.format(msgArgs), SQLState.DATA_EXCEPTION_NOT_SPECIFIC,
+ DriverError.NOT_SET, null);
}
loggerExternal.exiting(getClassNameLogging(), "getObject", columnIndex);
return type.cast(returnValue);
@@ -2436,8 +2419,7 @@ public Object getObject(String columnName) throws SQLServerException {
}
@Override
- public T getObject(String columnName,
- Class type) throws SQLException {
+ public T getObject(String columnName, Class type) throws SQLException {
loggerExternal.entering(getClassNameLogging(), "getObject", columnName);
checkClosed();
T value = getObject(findColumn(columnName), type);
@@ -2546,8 +2528,7 @@ public java.sql.Time getTime(String columnName) throws SQLServerException {
}
@Override
- public java.sql.Time getTime(int columnIndex,
- Calendar cal) throws SQLServerException {
+ public java.sql.Time getTime(int columnIndex, Calendar cal) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "getTime", new Object[] {columnIndex, cal});
checkClosed();
@@ -2557,8 +2538,7 @@ public java.sql.Time getTime(int columnIndex,
}
@Override
- public java.sql.Time getTime(String colName,
- Calendar cal) throws SQLServerException {
+ public java.sql.Time getTime(String colName, Calendar cal) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "getTime", new Object[] {colName, cal});
checkClosed();
@@ -2586,8 +2566,7 @@ public java.sql.Timestamp getTimestamp(String columnName) throws SQLServerExcept
}
@Override
- public java.sql.Timestamp getTimestamp(int columnIndex,
- Calendar cal) throws SQLServerException {
+ public java.sql.Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "getTimestamp", new Object[] {columnIndex, cal});
checkClosed();
@@ -2597,8 +2576,7 @@ public java.sql.Timestamp getTimestamp(int columnIndex,
}
@Override
- public java.sql.Timestamp getTimestamp(String colName,
- Calendar cal) throws SQLServerException {
+ public java.sql.Timestamp getTimestamp(String colName, Calendar cal) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "getTimestamp", new Object[] {colName, cal});
checkClosed();
@@ -2626,8 +2604,7 @@ public java.sql.Timestamp getDateTime(String columnName) throws SQLServerExcepti
}
@Override
- public java.sql.Timestamp getDateTime(int columnIndex,
- Calendar cal) throws SQLServerException {
+ public java.sql.Timestamp getDateTime(int columnIndex, Calendar cal) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "getDateTime", new Object[] {columnIndex, cal});
checkClosed();
@@ -2637,8 +2614,7 @@ public java.sql.Timestamp getDateTime(int columnIndex,
}
@Override
- public java.sql.Timestamp getDateTime(String colName,
- Calendar cal) throws SQLServerException {
+ public java.sql.Timestamp getDateTime(String colName, Calendar cal) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "getDateTime", new Object[] {colName, cal});
checkClosed();
@@ -2666,8 +2642,7 @@ public java.sql.Timestamp getSmallDateTime(String columnName) throws SQLServerEx
}
@Override
- public java.sql.Timestamp getSmallDateTime(int columnIndex,
- Calendar cal) throws SQLServerException {
+ public java.sql.Timestamp getSmallDateTime(int columnIndex, Calendar cal) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "getSmallDateTime", new Object[] {columnIndex, cal});
checkClosed();
@@ -2677,8 +2652,7 @@ public java.sql.Timestamp getSmallDateTime(int columnIndex,
}
@Override
- public java.sql.Timestamp getSmallDateTime(String colName,
- Calendar cal) throws SQLServerException {
+ public java.sql.Timestamp getSmallDateTime(String colName, Calendar cal) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "getSmallDateTime", new Object[] {colName, cal});
checkClosed();
@@ -2694,10 +2668,11 @@ public microsoft.sql.DateTimeOffset getDateTimeOffset(int columnIndex) throws SQ
// DateTimeOffset is not supported with SQL Server versions earlier than Katmai
if (!stmt.connection.isKatmaiOrLater())
- throw new SQLServerException(SQLServerException.getErrString("R_notSupported"), SQLState.DATA_EXCEPTION_NOT_SPECIFIC, DriverError.NOT_SET,
- null);
+ throw new SQLServerException(SQLServerException.getErrString("R_notSupported"),
+ SQLState.DATA_EXCEPTION_NOT_SPECIFIC, DriverError.NOT_SET, null);
- microsoft.sql.DateTimeOffset value = (microsoft.sql.DateTimeOffset) getValue(columnIndex, JDBCType.DATETIMEOFFSET);
+ microsoft.sql.DateTimeOffset value = (microsoft.sql.DateTimeOffset) getValue(columnIndex,
+ JDBCType.DATETIMEOFFSET);
loggerExternal.exiting(getClassNameLogging(), "getDateTimeOffset", value);
return value;
}
@@ -2709,10 +2684,11 @@ public microsoft.sql.DateTimeOffset getDateTimeOffset(String columnName) throws
// DateTimeOffset is not supported with SQL Server versions earlier than Katmai
if (!stmt.connection.isKatmaiOrLater())
- throw new SQLServerException(SQLServerException.getErrString("R_notSupported"), SQLState.DATA_EXCEPTION_NOT_SPECIFIC, DriverError.NOT_SET,
- null);
+ throw new SQLServerException(SQLServerException.getErrString("R_notSupported"),
+ SQLState.DATA_EXCEPTION_NOT_SPECIFIC, DriverError.NOT_SET, null);
- microsoft.sql.DateTimeOffset value = (microsoft.sql.DateTimeOffset) getValue(findColumn(columnName), JDBCType.DATETIMEOFFSET);
+ microsoft.sql.DateTimeOffset value = (microsoft.sql.DateTimeOffset) getValue(findColumn(columnName),
+ JDBCType.DATETIMEOFFSET);
loggerExternal.exiting(getClassNameLogging(), "getDateTimeOffset", value);
return value;
}
@@ -2734,8 +2710,7 @@ public java.io.InputStream getUnicodeStream(String columnName) throws SQLExcepti
}
@Override
- public Object getObject(int i,
- java.util.Map> map) throws SQLException {
+ public Object getObject(int i, java.util.Map> map) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "getObject", new Object[] {i, map});
SQLServerException.throwNotSupportedException(stmt.connection, stmt);
@@ -2816,8 +2791,7 @@ public Array getArray(int i) throws SQLException {
}
@Override
- public Object getObject(String colName,
- java.util.Map> map) throws SQLException {
+ public Object getObject(String colName, java.util.Map> map) throws SQLException {
SQLServerException.throwNotSupportedException(stmt.connection, stmt);
return null;
}
@@ -2837,7 +2811,8 @@ public Array getArray(String colName) throws SQLException {
@Override
public String getCursorName() throws SQLException {
loggerExternal.entering(getClassNameLogging(), "getCursorName");
- SQLServerException.makeFromDriverError(null, null, SQLServerException.getErrString("R_positionedUpdatesNotSupported"), null, false);
+ SQLServerException.makeFromDriverError(null, null,
+ SQLServerException.getErrString("R_positionedUpdatesNotSupported"), null, false);
loggerExternal.exiting(getClassNameLogging(), "getCursorName", null);
return null;
}
@@ -3009,8 +2984,8 @@ public boolean rowDeleted() throws SQLServerException {
/**
* Determines whether the current row of this result set is deleted.
*
- * A row may be deleted via the result set cursor (via ResultSet.deleteRow) or it may have been deleted outside the cursor. This function checks
- * for both possibilities.
+ * A row may be deleted via the result set cursor (via ResultSet.deleteRow) or it may have been deleted outside the
+ * cursor. This function checks for both possibilities.
*/
private boolean currentRowDeleted() throws SQLServerException {
// Never call this function without a current row
@@ -3019,7 +2994,8 @@ private boolean currentRowDeleted() throws SQLServerException {
// Having a current row implies we have a fetch buffer in which that row exists.
assert null != tdsReader;
- return deletedCurrentRow || (0 != serverCursorId && TDS.ROWSTAT_FETCH_MISSING == loadColumn(columns.length).getInt(tdsReader));
+ return deletedCurrentRow
+ || (0 != serverCursorId && TDS.ROWSTAT_FETCH_MISSING == loadColumn(columns.length).getInt(tdsReader));
}
/* ---------------- Column updates ---------------------- */
@@ -3028,7 +3004,7 @@ private boolean currentRowDeleted() throws SQLServerException {
* Does all the common stuff necessary when calling a getter for the column at index.
*
* @param index
- * the index of the column to get
+ * the index of the column to get
*/
private Column updaterGetColumn(int index) throws SQLServerException {
// From JDBC spec:
@@ -3039,7 +3015,8 @@ private Column updaterGetColumn(int index) throws SQLServerException {
// Verify that the column is updatable (i.e. that it is not a computed column).
if (!columns[index - 1].isUpdatable()) {
- SQLServerException.makeFromDriverError(stmt.connection, stmt, SQLServerException.getErrString("R_cantUpdateColumn"), "07009", false);
+ SQLServerException.makeFromDriverError(stmt.connection, stmt,
+ SQLServerException.getErrString("R_cantUpdateColumn"), "07009", false);
}
// Column values on the insert row are always updatable,
@@ -3050,7 +3027,8 @@ private Column updaterGetColumn(int index) throws SQLServerException {
// that this ResultSet has a current row (i.e. that the ResultSet's position
// is not before the first row or after the last row).
if (!hasCurrentRow()) {
- SQLServerException.makeFromDriverError(stmt.connection, stmt, SQLServerException.getErrString("R_resultsetNoCurrentRow"), null, true);
+ SQLServerException.makeFromDriverError(stmt.connection, stmt,
+ SQLServerException.getErrString("R_resultsetNoCurrentRow"), null, true);
}
// A current row exists. Its column values are updatable only if the row
@@ -3061,47 +3039,32 @@ private Column updaterGetColumn(int index) throws SQLServerException {
return getColumn(index);
}
- private void updateValue(int columnIndex,
- JDBCType jdbcType,
- Object value,
- JavaType javaType,
+ private void updateValue(int columnIndex, JDBCType jdbcType, Object value, JavaType javaType,
boolean forceEncrypt) throws SQLServerException {
- updaterGetColumn(columnIndex).updateValue(jdbcType, value, javaType, null, null, null, stmt.connection, stmt.stmtColumnEncriptionSetting,
- null, forceEncrypt, columnIndex);
+ updaterGetColumn(columnIndex).updateValue(jdbcType, value, javaType, null, null, null, stmt.connection,
+ stmt.stmtColumnEncriptionSetting, null, forceEncrypt, columnIndex);
}
- private void updateValue(int columnIndex,
- JDBCType jdbcType,
- Object value,
- JavaType javaType,
- Calendar cal,
+ private void updateValue(int columnIndex, JDBCType jdbcType, Object value, JavaType javaType, Calendar cal,
boolean forceEncrypt) throws SQLServerException {
- updaterGetColumn(columnIndex).updateValue(jdbcType, value, javaType, null, cal, null, stmt.connection, stmt.stmtColumnEncriptionSetting, null,
- forceEncrypt, columnIndex);
+ updaterGetColumn(columnIndex).updateValue(jdbcType, value, javaType, null, cal, null, stmt.connection,
+ stmt.stmtColumnEncriptionSetting, null, forceEncrypt, columnIndex);
}
- private void updateValue(int columnIndex,
- JDBCType jdbcType,
- Object value,
- JavaType javaType,
- Integer precision,
- Integer scale,
- boolean forceEncrypt) throws SQLServerException {
- updaterGetColumn(columnIndex).updateValue(jdbcType, value, javaType, null, null, scale, stmt.connection, stmt.stmtColumnEncriptionSetting,
- precision, forceEncrypt, columnIndex);
+ private void updateValue(int columnIndex, JDBCType jdbcType, Object value, JavaType javaType, Integer precision,
+ Integer scale, boolean forceEncrypt) throws SQLServerException {
+ updaterGetColumn(columnIndex).updateValue(jdbcType, value, javaType, null, null, scale, stmt.connection,
+ stmt.stmtColumnEncriptionSetting, precision, forceEncrypt, columnIndex);
}
- private void updateStream(int columnIndex,
- StreamType streamType,
- Object value,
- JavaType javaType,
+ private void updateStream(int columnIndex, StreamType streamType, Object value, JavaType javaType,
long length) throws SQLServerException {
- updaterGetColumn(columnIndex).updateValue(streamType.getJDBCType(), value, javaType, new StreamSetterArgs(streamType, length), null, null,
- stmt.connection, stmt.stmtColumnEncriptionSetting, null, false, columnIndex);
+ updaterGetColumn(columnIndex).updateValue(streamType.getJDBCType(), value, javaType,
+ new StreamSetterArgs(streamType, length), null, null, stmt.connection, stmt.stmtColumnEncriptionSetting,
+ null, false, columnIndex);
}
- private void updateSQLXMLInternal(int columnIndex,
- SQLXML value) throws SQLServerException {
+ private void updateSQLXMLInternal(int columnIndex, SQLXML value) throws SQLServerException {
updaterGetColumn(columnIndex).updateValue(JDBCType.SQLXML, value, JavaType.SQLXML,
new StreamSetterArgs(StreamType.SQLXML, DataTypes.UNKNOWN_STREAM_LENGTH), null, null, stmt.connection,
stmt.stmtColumnEncriptionSetting, null, false, columnIndex);
@@ -3112,14 +3075,14 @@ public void updateNull(int index) throws SQLServerException {
loggerExternal.entering(getClassNameLogging(), "updateNull", index);
checkClosed();
- updateValue(index, updaterGetColumn(index).getTypeInfo().getSSType().getJDBCType(), null, JavaType.OBJECT, false);
+ updateValue(index, updaterGetColumn(index).getTypeInfo().getSSType().getJDBCType(), null, JavaType.OBJECT,
+ false);
loggerExternal.exiting(getClassNameLogging(), "updateNull");
}
@Override
- public void updateBoolean(int index,
- boolean x) throws SQLException {
+ public void updateBoolean(int index, boolean x) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateBoolean", new Object[] {index, x});
checkClosed();
@@ -3129,9 +3092,7 @@ public void updateBoolean(int index,
}
@Override
- public void updateBoolean(int index,
- boolean x,
- boolean forceEncrypt) throws SQLServerException {
+ public void updateBoolean(int index, boolean x, boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateBoolean", new Object[] {index, x, forceEncrypt});
checkClosed();
@@ -3141,8 +3102,7 @@ public void updateBoolean(int index,
}
@Override
- public void updateByte(int index,
- byte x) throws SQLException {
+ public void updateByte(int index, byte x) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateByte", new Object[] {index, x});
@@ -3153,9 +3113,7 @@ public void updateByte(int index,
}
@Override
- public void updateByte(int index,
- byte x,
- boolean forceEncrypt) throws SQLServerException {
+ public void updateByte(int index, byte x, boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateByte", new Object[] {index, x, forceEncrypt});
@@ -3166,8 +3124,7 @@ public void updateByte(int index,
}
@Override
- public void updateShort(int index,
- short x) throws SQLException {
+ public void updateShort(int index, short x) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateShort", new Object[] {index, x});
@@ -3178,9 +3135,7 @@ public void updateShort(int index,
}
@Override
- public void updateShort(int index,
- short x,
- boolean forceEncrypt) throws SQLServerException {
+ public void updateShort(int index, short x, boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateShort", new Object[] {index, x, forceEncrypt});
@@ -3191,8 +3146,7 @@ public void updateShort(int index,
}
@Override
- public void updateInt(int index,
- int x) throws SQLException {
+ public void updateInt(int index, int x) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateInt", new Object[] {index, x});
@@ -3203,9 +3157,7 @@ public void updateInt(int index,
}
@Override
- public void updateInt(int index,
- int x,
- boolean forceEncrypt) throws SQLServerException {
+ public void updateInt(int index, int x, boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateInt", new Object[] {index, x, forceEncrypt});
@@ -3216,8 +3168,7 @@ public void updateInt(int index,
}
@Override
- public void updateLong(int index,
- long x) throws SQLException {
+ public void updateLong(int index, long x) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateLong", new Object[] {index, x});
@@ -3228,9 +3179,7 @@ public void updateLong(int index,
}
@Override
- public void updateLong(int index,
- long x,
- boolean forceEncrypt) throws SQLServerException {
+ public void updateLong(int index, long x, boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateLong", new Object[] {index, x, forceEncrypt});
@@ -3241,8 +3190,7 @@ public void updateLong(int index,
}
@Override
- public void updateFloat(int index,
- float x) throws SQLException {
+ public void updateFloat(int index, float x) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateFloat", new Object[] {index, x});
@@ -3253,9 +3201,7 @@ public void updateFloat(int index,
}
@Override
- public void updateFloat(int index,
- float x,
- boolean forceEncrypt) throws SQLServerException {
+ public void updateFloat(int index, float x, boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateFloat", new Object[] {index, x, forceEncrypt});
@@ -3266,8 +3212,7 @@ public void updateFloat(int index,
}
@Override
- public void updateDouble(int index,
- double x) throws SQLException {
+ public void updateDouble(int index, double x) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateDouble", new Object[] {index, x});
@@ -3278,9 +3223,7 @@ public void updateDouble(int index,
}
@Override
- public void updateDouble(int index,
- double x,
- boolean forceEncrypt) throws SQLServerException {
+ public void updateDouble(int index, double x, boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateDouble", new Object[] {index, x, forceEncrypt});
@@ -3291,8 +3234,7 @@ public void updateDouble(int index,
}
@Override
- public void updateMoney(int index,
- BigDecimal x) throws SQLServerException {
+ public void updateMoney(int index, BigDecimal x) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateMoney", new Object[] {index, x});
checkClosed();
@@ -3302,9 +3244,7 @@ public void updateMoney(int index,
}
@Override
- public void updateMoney(int index,
- BigDecimal x,
- boolean forceEncrypt) throws SQLServerException {
+ public void updateMoney(int index, BigDecimal x, boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateMoney", new Object[] {index, x, forceEncrypt});
checkClosed();
@@ -3314,8 +3254,7 @@ public void updateMoney(int index,
}
@Override
- public void updateMoney(String columnName,
- BigDecimal x) throws SQLServerException {
+ public void updateMoney(String columnName, BigDecimal x) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateMoney", new Object[] {columnName, x});
checkClosed();
@@ -3325,9 +3264,7 @@ public void updateMoney(String columnName,
}
@Override
- public void updateMoney(String columnName,
- BigDecimal x,
- boolean forceEncrypt) throws SQLServerException {
+ public void updateMoney(String columnName, BigDecimal x, boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateMoney", new Object[] {columnName, x, forceEncrypt});
checkClosed();
@@ -3337,8 +3274,7 @@ public void updateMoney(String columnName,
}
@Override
- public void updateSmallMoney(int index,
- BigDecimal x) throws SQLServerException {
+ public void updateSmallMoney(int index, BigDecimal x) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateSmallMoney", new Object[] {index, x});
checkClosed();
@@ -3348,9 +3284,7 @@ public void updateSmallMoney(int index,
}
@Override
- public void updateSmallMoney(int index,
- BigDecimal x,
- boolean forceEncrypt) throws SQLServerException {
+ public void updateSmallMoney(int index, BigDecimal x, boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateSmallMoney", new Object[] {index, x, forceEncrypt});
checkClosed();
@@ -3360,8 +3294,7 @@ public void updateSmallMoney(int index,
}
@Override
- public void updateSmallMoney(String columnName,
- BigDecimal x) throws SQLServerException {
+ public void updateSmallMoney(String columnName, BigDecimal x) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateSmallMoney", new Object[] {columnName, x});
checkClosed();
@@ -3371,11 +3304,10 @@ public void updateSmallMoney(String columnName,
}
@Override
- public void updateSmallMoney(String columnName,
- BigDecimal x,
- boolean forceEncrypt) throws SQLServerException {
+ public void updateSmallMoney(String columnName, BigDecimal x, boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "updateSmallMoney", new Object[] {columnName, x, forceEncrypt});
+ loggerExternal.entering(getClassNameLogging(), "updateSmallMoney",
+ new Object[] {columnName, x, forceEncrypt});
checkClosed();
updateValue(findColumn(columnName), JDBCType.SMALLMONEY, x, JavaType.BIGDECIMAL, forceEncrypt);
@@ -3383,8 +3315,7 @@ public void updateSmallMoney(String columnName,
}
@Override
- public void updateBigDecimal(int index,
- BigDecimal x) throws SQLServerException {
+ public void updateBigDecimal(int index, BigDecimal x) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateBigDecimal", new Object[] {index, x});
@@ -3395,10 +3326,7 @@ public void updateBigDecimal(int index,
}
@Override
- public void updateBigDecimal(int index,
- BigDecimal x,
- Integer precision,
- Integer scale) throws SQLServerException {
+ public void updateBigDecimal(int index, BigDecimal x, Integer precision, Integer scale) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateBigDecimal", new Object[] {index, x, scale});
@@ -3409,13 +3337,11 @@ public void updateBigDecimal(int index,
}
@Override
- public void updateBigDecimal(int index,
- BigDecimal x,
- Integer precision,
- Integer scale,
+ public void updateBigDecimal(int index, BigDecimal x, Integer precision, Integer scale,
boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "updateBigDecimal", new Object[] {index, x, scale, forceEncrypt});
+ loggerExternal.entering(getClassNameLogging(), "updateBigDecimal",
+ new Object[] {index, x, scale, forceEncrypt});
checkClosed();
updateValue(index, JDBCType.DECIMAL, x, JavaType.BIGDECIMAL, precision, scale, forceEncrypt);
@@ -3424,8 +3350,7 @@ public void updateBigDecimal(int index,
}
@Override
- public void updateString(int columnIndex,
- String stringValue) throws SQLServerException {
+ public void updateString(int columnIndex, String stringValue) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateString", new Object[] {columnIndex, stringValue});
@@ -3436,11 +3361,10 @@ public void updateString(int columnIndex,
}
@Override
- public void updateString(int columnIndex,
- String stringValue,
- boolean forceEncrypt) throws SQLServerException {
+ public void updateString(int columnIndex, String stringValue, boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "updateString", new Object[] {columnIndex, stringValue, forceEncrypt});
+ loggerExternal.entering(getClassNameLogging(), "updateString",
+ new Object[] {columnIndex, stringValue, forceEncrypt});
checkClosed();
updateValue(columnIndex, JDBCType.VARCHAR, stringValue, JavaType.STRING, forceEncrypt);
@@ -3449,8 +3373,7 @@ public void updateString(int columnIndex,
}
@Override
- public void updateNString(int columnIndex,
- String nString) throws SQLException {
+ public void updateNString(int columnIndex, String nString) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateNString", new Object[] {columnIndex, nString});
@@ -3461,11 +3384,10 @@ public void updateNString(int columnIndex,
}
@Override
- public void updateNString(int columnIndex,
- String nString,
- boolean forceEncrypt) throws SQLServerException {
+ public void updateNString(int columnIndex, String nString, boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "updateNString", new Object[] {columnIndex, nString, forceEncrypt});
+ loggerExternal.entering(getClassNameLogging(), "updateNString",
+ new Object[] {columnIndex, nString, forceEncrypt});
checkClosed();
updateValue(columnIndex, JDBCType.NVARCHAR, nString, JavaType.STRING, forceEncrypt);
@@ -3474,8 +3396,7 @@ public void updateNString(int columnIndex,
}
@Override
- public void updateNString(String columnLabel,
- String nString) throws SQLException {
+ public void updateNString(String columnLabel, String nString) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateNString", new Object[] {columnLabel, nString});
@@ -3486,11 +3407,10 @@ public void updateNString(String columnLabel,
}
@Override
- public void updateNString(String columnLabel,
- String nString,
- boolean forceEncrypt) throws SQLServerException {
+ public void updateNString(String columnLabel, String nString, boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "updateNString", new Object[] {columnLabel, nString, forceEncrypt});
+ loggerExternal.entering(getClassNameLogging(), "updateNString",
+ new Object[] {columnLabel, nString, forceEncrypt});
checkClosed();
updateValue(findColumn(columnLabel), JDBCType.NVARCHAR, nString, JavaType.STRING, forceEncrypt);
@@ -3499,8 +3419,7 @@ public void updateNString(String columnLabel,
}
@Override
- public void updateBytes(int index,
- byte x[]) throws SQLException {
+ public void updateBytes(int index, byte x[]) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateBytes", new Object[] {index, x});
@@ -3511,9 +3430,7 @@ public void updateBytes(int index,
}
@Override
- public void updateBytes(int index,
- byte x[],
- boolean forceEncrypt) throws SQLServerException {
+ public void updateBytes(int index, byte x[], boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateBytes", new Object[] {index, x, forceEncrypt});
@@ -3524,8 +3441,7 @@ public void updateBytes(int index,
}
@Override
- public void updateDate(int index,
- java.sql.Date x) throws SQLServerException {
+ public void updateDate(int index, java.sql.Date x) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateDate", new Object[] {index, x});
@@ -3536,9 +3452,7 @@ public void updateDate(int index,
}
@Override
- public void updateDate(int index,
- java.sql.Date x,
- boolean forceEncrypt) throws SQLServerException {
+ public void updateDate(int index, java.sql.Date x, boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateDate", new Object[] {index, x, forceEncrypt});
@@ -3549,8 +3463,7 @@ public void updateDate(int index,
}
@Override
- public void updateTime(int index,
- java.sql.Time x) throws SQLServerException {
+ public void updateTime(int index, java.sql.Time x) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateTime", new Object[] {index, x});
@@ -3561,9 +3474,7 @@ public void updateTime(int index,
}
@Override
- public void updateTime(int index,
- java.sql.Time x,
- Integer scale) throws SQLServerException {
+ public void updateTime(int index, java.sql.Time x, Integer scale) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateTime", new Object[] {index, x, scale});
@@ -3574,10 +3485,7 @@ public void updateTime(int index,
}
@Override
- public void updateTime(int index,
- java.sql.Time x,
- Integer scale,
- boolean forceEncrypt) throws SQLServerException {
+ public void updateTime(int index, java.sql.Time x, Integer scale, boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateTime", new Object[] {index, x, scale, forceEncrypt});
@@ -3588,8 +3496,7 @@ public void updateTime(int index,
}
@Override
- public void updateTimestamp(int index,
- java.sql.Timestamp x) throws SQLServerException {
+ public void updateTimestamp(int index, java.sql.Timestamp x) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateTimestamp", new Object[] {index, x});
@@ -3600,9 +3507,7 @@ public void updateTimestamp(int index,
}
@Override
- public void updateTimestamp(int index,
- java.sql.Timestamp x,
- int scale) throws SQLServerException {
+ public void updateTimestamp(int index, java.sql.Timestamp x, int scale) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateTimestamp", new Object[] {index, x, scale});
@@ -3613,12 +3518,11 @@ public void updateTimestamp(int index,
}
@Override
- public void updateTimestamp(int index,
- java.sql.Timestamp x,
- int scale,
+ public void updateTimestamp(int index, java.sql.Timestamp x, int scale,
boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "updateTimestamp", new Object[] {index, x, scale, forceEncrypt});
+ loggerExternal.entering(getClassNameLogging(), "updateTimestamp",
+ new Object[] {index, x, scale, forceEncrypt});
checkClosed();
updateValue(index, JDBCType.TIMESTAMP, x, JavaType.TIMESTAMP, null, scale, forceEncrypt);
@@ -3627,8 +3531,7 @@ public void updateTimestamp(int index,
}
@Override
- public void updateDateTime(int index,
- java.sql.Timestamp x) throws SQLServerException {
+ public void updateDateTime(int index, java.sql.Timestamp x) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateDateTime", new Object[] {index, x});
@@ -3639,9 +3542,7 @@ public void updateDateTime(int index,
}
@Override
- public void updateDateTime(int index,
- java.sql.Timestamp x,
- Integer scale) throws SQLServerException {
+ public void updateDateTime(int index, java.sql.Timestamp x, Integer scale) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateDateTime", new Object[] {index, x, scale});
@@ -3652,12 +3553,11 @@ public void updateDateTime(int index,
}
@Override
- public void updateDateTime(int index,
- java.sql.Timestamp x,
- Integer scale,
+ public void updateDateTime(int index, java.sql.Timestamp x, Integer scale,
boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "updateDateTime", new Object[] {index, x, scale, forceEncrypt});
+ loggerExternal.entering(getClassNameLogging(), "updateDateTime",
+ new Object[] {index, x, scale, forceEncrypt});
checkClosed();
updateValue(index, JDBCType.DATETIME, x, JavaType.TIMESTAMP, null, scale, forceEncrypt);
@@ -3666,8 +3566,7 @@ public void updateDateTime(int index,
}
@Override
- public void updateSmallDateTime(int index,
- java.sql.Timestamp x) throws SQLServerException {
+ public void updateSmallDateTime(int index, java.sql.Timestamp x) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateSmallDateTime", new Object[] {index, x});
@@ -3678,9 +3577,7 @@ public void updateSmallDateTime(int index,
}
@Override
- public void updateSmallDateTime(int index,
- java.sql.Timestamp x,
- Integer scale) throws SQLServerException {
+ public void updateSmallDateTime(int index, java.sql.Timestamp x, Integer scale) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateSmallDateTime", new Object[] {index, x, scale});
@@ -3691,12 +3588,11 @@ public void updateSmallDateTime(int index,
}
@Override
- public void updateSmallDateTime(int index,
- java.sql.Timestamp x,
- Integer scale,
+ public void updateSmallDateTime(int index, java.sql.Timestamp x, Integer scale,
boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "updateSmallDateTime", new Object[] {index, x, scale, forceEncrypt});
+ loggerExternal.entering(getClassNameLogging(), "updateSmallDateTime",
+ new Object[] {index, x, scale, forceEncrypt});
checkClosed();
updateValue(index, JDBCType.SMALLDATETIME, x, JavaType.TIMESTAMP, null, scale, forceEncrypt);
@@ -3705,8 +3601,7 @@ public void updateSmallDateTime(int index,
}
@Override
- public void updateDateTimeOffset(int index,
- microsoft.sql.DateTimeOffset x) throws SQLServerException {
+ public void updateDateTimeOffset(int index, microsoft.sql.DateTimeOffset x) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateDateTimeOffset", new Object[] {index, x});
@@ -3717,8 +3612,7 @@ public void updateDateTimeOffset(int index,
}
@Override
- public void updateDateTimeOffset(int index,
- microsoft.sql.DateTimeOffset x,
+ public void updateDateTimeOffset(int index, microsoft.sql.DateTimeOffset x,
Integer scale) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateDateTimeOffset", new Object[] {index, x, scale});
@@ -3730,12 +3624,11 @@ public void updateDateTimeOffset(int index,
}
@Override
- public void updateDateTimeOffset(int index,
- microsoft.sql.DateTimeOffset x,
- Integer scale,
+ public void updateDateTimeOffset(int index, microsoft.sql.DateTimeOffset x, Integer scale,
boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "updateDateTimeOffset", new Object[] {index, x, scale, forceEncrypt});
+ loggerExternal.entering(getClassNameLogging(), "updateDateTimeOffset",
+ new Object[] {index, x, scale, forceEncrypt});
checkClosed();
updateValue(index, JDBCType.DATETIMEOFFSET, x, JavaType.DATETIMEOFFSET, null, scale, forceEncrypt);
@@ -3744,8 +3637,7 @@ public void updateDateTimeOffset(int index,
}
@Override
- public void updateUniqueIdentifier(int index,
- String x) throws SQLServerException {
+ public void updateUniqueIdentifier(int index, String x) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateUniqueIdentifier", new Object[] {index, x});
@@ -3756,11 +3648,10 @@ public void updateUniqueIdentifier(int index,
}
@Override
- public void updateUniqueIdentifier(int index,
- String x,
- boolean forceEncrypt) throws SQLServerException {
+ public void updateUniqueIdentifier(int index, String x, boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "updateUniqueIdentifier", new Object[] {index, x, forceEncrypt});
+ loggerExternal.entering(getClassNameLogging(), "updateUniqueIdentifier",
+ new Object[] {index, x, forceEncrypt});
checkClosed();
updateValue(index, JDBCType.GUID, x, JavaType.STRING, null, forceEncrypt);
@@ -3769,8 +3660,7 @@ public void updateUniqueIdentifier(int index,
}
@Override
- public void updateAsciiStream(int columnIndex,
- InputStream x) throws SQLException {
+ public void updateAsciiStream(int columnIndex, InputStream x) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateAsciiStream", new Object[] {columnIndex, x});
@@ -3781,9 +3671,7 @@ public void updateAsciiStream(int columnIndex,
}
@Override
- public void updateAsciiStream(int index,
- InputStream x,
- int length) throws SQLServerException {
+ public void updateAsciiStream(int index, InputStream x, int length) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateAsciiStream", new Object[] {index, x, length});
@@ -3794,9 +3682,7 @@ public void updateAsciiStream(int index,
}
@Override
- public void updateAsciiStream(int columnIndex,
- InputStream x,
- long length) throws SQLException {
+ public void updateAsciiStream(int columnIndex, InputStream x, long length) throws SQLException {
loggerExternal.entering(getClassNameLogging(), "updateAsciiStream", new Object[] {columnIndex, x, length});
checkClosed();
@@ -3806,21 +3692,19 @@ public void updateAsciiStream(int columnIndex,
}
@Override
- public void updateAsciiStream(String columnLabel,
- InputStream x) throws SQLException {
+ public void updateAsciiStream(String columnLabel, InputStream x) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateAsciiStream", new Object[] {columnLabel, x});
checkClosed();
- updateStream(findColumn(columnLabel), StreamType.ASCII, x, JavaType.INPUTSTREAM, DataTypes.UNKNOWN_STREAM_LENGTH);
+ updateStream(findColumn(columnLabel), StreamType.ASCII, x, JavaType.INPUTSTREAM,
+ DataTypes.UNKNOWN_STREAM_LENGTH);
loggerExternal.exiting(getClassNameLogging(), "updateAsciiStream");
}
@Override
- public void updateAsciiStream(java.lang.String columnName,
- InputStream x,
- int length) throws SQLServerException {
+ public void updateAsciiStream(java.lang.String columnName, InputStream x, int length) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateAsciiStream", new Object[] {columnName, x, length});
@@ -3831,11 +3715,10 @@ public void updateAsciiStream(java.lang.String columnName,
}
@Override
- public void updateAsciiStream(String columnName,
- InputStream streamValue,
- long length) throws SQLException {
+ public void updateAsciiStream(String columnName, InputStream streamValue, long length) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "updateAsciiStream", new Object[] {columnName, streamValue, length});
+ loggerExternal.entering(getClassNameLogging(), "updateAsciiStream",
+ new Object[] {columnName, streamValue, length});
checkClosed();
updateStream(findColumn(columnName), StreamType.ASCII, streamValue, JavaType.INPUTSTREAM, length);
@@ -3844,8 +3727,7 @@ public void updateAsciiStream(String columnName,
}
@Override
- public void updateBinaryStream(int columnIndex,
- InputStream x) throws SQLException {
+ public void updateBinaryStream(int columnIndex, InputStream x) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateBinaryStream", new Object[] {columnIndex, x});
@@ -3856,11 +3738,10 @@ public void updateBinaryStream(int columnIndex,
}
@Override
- public void updateBinaryStream(int columnIndex,
- InputStream streamValue,
- int length) throws SQLException {
+ public void updateBinaryStream(int columnIndex, InputStream streamValue, int length) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "updateBinaryStream", new Object[] {columnIndex, streamValue, length});
+ loggerExternal.entering(getClassNameLogging(), "updateBinaryStream",
+ new Object[] {columnIndex, streamValue, length});
checkClosed();
updateStream(columnIndex, StreamType.BINARY, streamValue, JavaType.INPUTSTREAM, length);
@@ -3869,9 +3750,7 @@ public void updateBinaryStream(int columnIndex,
}
@Override
- public void updateBinaryStream(int columnIndex,
- InputStream x,
- long length) throws SQLException {
+ public void updateBinaryStream(int columnIndex, InputStream x, long length) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateBinaryStream", new Object[] {columnIndex, x, length});
@@ -3882,23 +3761,22 @@ public void updateBinaryStream(int columnIndex,
}
@Override
- public void updateBinaryStream(String columnLabel,
- InputStream x) throws SQLException {
+ public void updateBinaryStream(String columnLabel, InputStream x) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateBinaryStream", new Object[] {columnLabel, x});
checkClosed();
- updateStream(findColumn(columnLabel), StreamType.BINARY, x, JavaType.INPUTSTREAM, DataTypes.UNKNOWN_STREAM_LENGTH);
+ updateStream(findColumn(columnLabel), StreamType.BINARY, x, JavaType.INPUTSTREAM,
+ DataTypes.UNKNOWN_STREAM_LENGTH);
loggerExternal.exiting(getClassNameLogging(), "updateBinaryStream");
}
@Override
- public void updateBinaryStream(String columnName,
- InputStream streamValue,
- int length) throws SQLException {
+ public void updateBinaryStream(String columnName, InputStream streamValue, int length) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "updateBinaryStream", new Object[] {columnName, streamValue, length});
+ loggerExternal.entering(getClassNameLogging(), "updateBinaryStream",
+ new Object[] {columnName, streamValue, length});
checkClosed();
updateStream(findColumn(columnName), StreamType.BINARY, streamValue, JavaType.INPUTSTREAM, length);
@@ -3907,9 +3785,7 @@ public void updateBinaryStream(String columnName,
}
@Override
- public void updateBinaryStream(String columnLabel,
- InputStream x,
- long length) throws SQLException {
+ public void updateBinaryStream(String columnLabel, InputStream x, long length) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateBinaryStream", new Object[] {columnLabel, x, length});
@@ -3920,8 +3796,7 @@ public void updateBinaryStream(String columnLabel,
}
@Override
- public void updateCharacterStream(int columnIndex,
- Reader x) throws SQLException {
+ public void updateCharacterStream(int columnIndex, Reader x) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateCharacterStream", new Object[] {columnIndex, x});
@@ -3932,11 +3807,10 @@ public void updateCharacterStream(int columnIndex,
}
@Override
- public void updateCharacterStream(int columnIndex,
- Reader readerValue,
- int length) throws SQLServerException {
+ public void updateCharacterStream(int columnIndex, Reader readerValue, int length) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "updateCharacterStream", new Object[] {columnIndex, readerValue, length});
+ loggerExternal.entering(getClassNameLogging(), "updateCharacterStream",
+ new Object[] {columnIndex, readerValue, length});
checkClosed();
updateStream(columnIndex, StreamType.CHARACTER, readerValue, JavaType.READER, length);
@@ -3945,11 +3819,10 @@ public void updateCharacterStream(int columnIndex,
}
@Override
- public void updateCharacterStream(int columnIndex,
- Reader x,
- long length) throws SQLException {
+ public void updateCharacterStream(int columnIndex, Reader x, long length) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "updateCharacterStream", new Object[] {columnIndex, x, length});
+ loggerExternal.entering(getClassNameLogging(), "updateCharacterStream",
+ new Object[] {columnIndex, x, length});
checkClosed();
updateStream(columnIndex, StreamType.CHARACTER, x, JavaType.READER, length);
@@ -3958,23 +3831,22 @@ public void updateCharacterStream(int columnIndex,
}
@Override
- public void updateCharacterStream(String columnLabel,
- Reader reader) throws SQLException {
+ public void updateCharacterStream(String columnLabel, Reader reader) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateCharacterStream", new Object[] {columnLabel, reader});
checkClosed();
- updateStream(findColumn(columnLabel), StreamType.CHARACTER, reader, JavaType.READER, DataTypes.UNKNOWN_STREAM_LENGTH);
+ updateStream(findColumn(columnLabel), StreamType.CHARACTER, reader, JavaType.READER,
+ DataTypes.UNKNOWN_STREAM_LENGTH);
loggerExternal.exiting(getClassNameLogging(), "updateCharacterStream");
}
@Override
- public void updateCharacterStream(String columnName,
- Reader readerValue,
- int length) throws SQLServerException {
+ public void updateCharacterStream(String columnName, Reader readerValue, int length) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "updateCharacterStream", new Object[] {columnName, readerValue, length});
+ loggerExternal.entering(getClassNameLogging(), "updateCharacterStream",
+ new Object[] {columnName, readerValue, length});
checkClosed();
updateStream(findColumn(columnName), StreamType.CHARACTER, readerValue, JavaType.READER, length);
@@ -3983,11 +3855,10 @@ public void updateCharacterStream(String columnName,
}
@Override
- public void updateCharacterStream(String columnLabel,
- Reader reader,
- long length) throws SQLException {
+ public void updateCharacterStream(String columnLabel, Reader reader, long length) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "updateCharacterStream", new Object[] {columnLabel, reader, length});
+ loggerExternal.entering(getClassNameLogging(), "updateCharacterStream",
+ new Object[] {columnLabel, reader, length});
checkClosed();
updateStream(findColumn(columnLabel), StreamType.CHARACTER, reader, JavaType.READER, length);
@@ -3996,8 +3867,7 @@ public void updateCharacterStream(String columnLabel,
}
@Override
- public void updateNCharacterStream(int columnIndex,
- Reader x) throws SQLException {
+ public void updateNCharacterStream(int columnIndex, Reader x) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateNCharacterStream", new Object[] {columnIndex, x});
@@ -4008,11 +3878,10 @@ public void updateNCharacterStream(int columnIndex,
}
@Override
- public void updateNCharacterStream(int columnIndex,
- Reader x,
- long length) throws SQLException {
+ public void updateNCharacterStream(int columnIndex, Reader x, long length) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "updateNCharacterStream", new Object[] {columnIndex, x, length});
+ loggerExternal.entering(getClassNameLogging(), "updateNCharacterStream",
+ new Object[] {columnIndex, x, length});
checkClosed();
updateStream(columnIndex, StreamType.NCHARACTER, x, JavaType.READER, length);
@@ -4021,23 +3890,23 @@ public void updateNCharacterStream(int columnIndex,
}
@Override
- public void updateNCharacterStream(String columnLabel,
- Reader reader) throws SQLException {
+ public void updateNCharacterStream(String columnLabel, Reader reader) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "updateNCharacterStream", new Object[] {columnLabel, reader});
+ loggerExternal.entering(getClassNameLogging(), "updateNCharacterStream",
+ new Object[] {columnLabel, reader});
checkClosed();
- updateStream(findColumn(columnLabel), StreamType.NCHARACTER, reader, JavaType.READER, DataTypes.UNKNOWN_STREAM_LENGTH);
+ updateStream(findColumn(columnLabel), StreamType.NCHARACTER, reader, JavaType.READER,
+ DataTypes.UNKNOWN_STREAM_LENGTH);
loggerExternal.exiting(getClassNameLogging(), "updateNCharacterStream");
}
@Override
- public void updateNCharacterStream(String columnLabel,
- Reader reader,
- long length) throws SQLException {
+ public void updateNCharacterStream(String columnLabel, Reader reader, long length) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "updateNCharacterStream", new Object[] {columnLabel, reader, length});
+ loggerExternal.entering(getClassNameLogging(), "updateNCharacterStream",
+ new Object[] {columnLabel, reader, length});
checkClosed();
updateStream(findColumn(columnLabel), StreamType.NCHARACTER, reader, JavaType.READER, length);
@@ -4046,8 +3915,7 @@ public void updateNCharacterStream(String columnLabel,
}
@Override
- public void updateObject(int index,
- Object obj) throws SQLServerException {
+ public void updateObject(int index, Object obj) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateObject", new Object[] {index, obj});
@@ -4058,9 +3926,7 @@ public void updateObject(int index,
}
@Override
- public void updateObject(int index,
- Object x,
- int scale) throws SQLServerException {
+ public void updateObject(int index, Object x, int scale) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateObject", new Object[] {index, x, scale});
@@ -4071,10 +3937,7 @@ public void updateObject(int index,
}
@Override
- public void updateObject(int index,
- Object x,
- int precision,
- int scale) throws SQLServerException {
+ public void updateObject(int index, Object x, int precision, int scale) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateObject", new Object[] {index, x, scale});
@@ -4085,13 +3948,11 @@ public void updateObject(int index,
}
@Override
- public void updateObject(int index,
- Object x,
- int precision,
- int scale,
+ public void updateObject(int index, Object x, int precision, int scale,
boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "updateObject", new Object[] {index, x, scale, forceEncrypt});
+ loggerExternal.entering(getClassNameLogging(), "updateObject",
+ new Object[] {index, x, scale, forceEncrypt});
checkClosed();
updateObject(index, x, scale, null, precision, forceEncrypt);
@@ -4099,11 +3960,7 @@ public void updateObject(int index,
loggerExternal.exiting(getClassNameLogging(), "updateObject");
}
- protected final void updateObject(int index,
- Object x,
- Integer scale,
- JDBCType jdbcType,
- Integer precision,
+ protected final void updateObject(int index, Object x, Integer scale, JDBCType jdbcType, Integer precision,
boolean forceEncrypt) throws SQLServerException {
Column column = updaterGetColumn(index);
SSType ssType = column.getTypeInfo().getSSType();
@@ -4116,16 +3973,14 @@ protected final void updateObject(int index,
column.updateValue(jdbcType, x, JavaType.OBJECT, null, // streamSetterArgs
null, scale, stmt.connection, stmt.stmtColumnEncriptionSetting, precision, forceEncrypt, index);
- }
- else {
+ } else {
JavaType javaType = JavaType.of(x);
JDBCType objectJdbcType = javaType.getJDBCType(ssType, ssType.getJDBCType());
if (null == jdbcType) {
// JDBCType is not specified by user, derive from the object's JavaType
jdbcType = objectJdbcType;
- }
- else {
+ } else {
// Check convertibility of the value to the desired JDBC type.
if (!objectJdbcType.convertsTo(jdbcType))
DataTypes.throwConversionError(objectJdbcType.toString(), jdbcType.toString());
@@ -4138,7 +3993,8 @@ protected final void updateObject(int index,
break;
case INPUTSTREAM:
- streamSetterArgs = new StreamSetterArgs(jdbcType.isTextual() ? StreamType.CHARACTER : StreamType.BINARY,
+ streamSetterArgs = new StreamSetterArgs(
+ jdbcType.isTextual() ? StreamType.CHARACTER : StreamType.BINARY,
DataTypes.UNKNOWN_STREAM_LENGTH);
break;
@@ -4151,8 +4007,8 @@ protected final void updateObject(int index,
break;
}
- column.updateValue(jdbcType, x, javaType, streamSetterArgs, null, scale, stmt.connection, stmt.stmtColumnEncriptionSetting, precision,
- forceEncrypt, index);
+ column.updateValue(jdbcType, x, javaType, streamSetterArgs, null, scale, stmt.connection,
+ stmt.stmtColumnEncriptionSetting, precision, forceEncrypt, index);
}
}
@@ -4162,14 +4018,14 @@ public void updateNull(String columnName) throws SQLServerException {
checkClosed();
int columnIndex = findColumn(columnName);
- updateValue(columnIndex, updaterGetColumn(columnIndex).getTypeInfo().getSSType().getJDBCType(), null, JavaType.OBJECT, false);
+ updateValue(columnIndex, updaterGetColumn(columnIndex).getTypeInfo().getSSType().getJDBCType(), null,
+ JavaType.OBJECT, false);
loggerExternal.exiting(getClassNameLogging(), "updateNull");
}
@Override
- public void updateBoolean(String columnName,
- boolean x) throws SQLServerException {
+ public void updateBoolean(String columnName, boolean x) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateBoolean", new Object[] {columnName, x});
@@ -4180,9 +4036,7 @@ public void updateBoolean(String columnName,
}
@Override
- public void updateBoolean(String columnName,
- boolean x,
- boolean forceEncrypt) throws SQLServerException {
+ public void updateBoolean(String columnName, boolean x, boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateBoolean", new Object[] {columnName, x, forceEncrypt});
@@ -4193,8 +4047,7 @@ public void updateBoolean(String columnName,
}
@Override
- public void updateByte(String columnName,
- byte x) throws SQLServerException {
+ public void updateByte(String columnName, byte x) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateByte", new Object[] {columnName, x});
@@ -4205,9 +4058,7 @@ public void updateByte(String columnName,
}
@Override
- public void updateByte(String columnName,
- byte x,
- boolean forceEncrypt) throws SQLServerException {
+ public void updateByte(String columnName, byte x, boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateByte", new Object[] {columnName, x, forceEncrypt});
@@ -4218,8 +4069,7 @@ public void updateByte(String columnName,
}
@Override
- public void updateShort(String columnName,
- short x) throws SQLServerException {
+ public void updateShort(String columnName, short x) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateShort", new Object[] {columnName, x});
@@ -4230,9 +4080,7 @@ public void updateShort(String columnName,
}
@Override
- public void updateShort(String columnName,
- short x,
- boolean forceEncrypt) throws SQLServerException {
+ public void updateShort(String columnName, short x, boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateShort", new Object[] {columnName, x, forceEncrypt});
@@ -4243,8 +4091,7 @@ public void updateShort(String columnName,
}
@Override
- public void updateInt(String columnName,
- int x) throws SQLServerException {
+ public void updateInt(String columnName, int x) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateInt", new Object[] {columnName, x});
@@ -4255,9 +4102,7 @@ public void updateInt(String columnName,
}
@Override
- public void updateInt(String columnName,
- int x,
- boolean forceEncrypt) throws SQLServerException {
+ public void updateInt(String columnName, int x, boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateInt", new Object[] {columnName, x, forceEncrypt});
@@ -4268,8 +4113,7 @@ public void updateInt(String columnName,
}
@Override
- public void updateLong(String columnName,
- long x) throws SQLServerException {
+ public void updateLong(String columnName, long x) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateLong", new Object[] {columnName, x});
@@ -4280,9 +4124,7 @@ public void updateLong(String columnName,
}
@Override
- public void updateLong(String columnName,
- long x,
- boolean forceEncrypt) throws SQLServerException {
+ public void updateLong(String columnName, long x, boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateLong", new Object[] {columnName, x, forceEncrypt});
@@ -4293,8 +4135,7 @@ public void updateLong(String columnName,
}
@Override
- public void updateFloat(String columnName,
- float x) throws SQLServerException {
+ public void updateFloat(String columnName, float x) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateFloat", new Object[] {columnName, x});
@@ -4305,9 +4146,7 @@ public void updateFloat(String columnName,
}
@Override
- public void updateFloat(String columnName,
- float x,
- boolean forceEncrypt) throws SQLServerException {
+ public void updateFloat(String columnName, float x, boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateFloat", new Object[] {columnName, x, forceEncrypt});
@@ -4318,8 +4157,7 @@ public void updateFloat(String columnName,
}
@Override
- public void updateDouble(String columnName,
- double x) throws SQLServerException {
+ public void updateDouble(String columnName, double x) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateDouble", new Object[] {columnName, x});
@@ -4330,9 +4168,7 @@ public void updateDouble(String columnName,
}
@Override
- public void updateDouble(String columnName,
- double x,
- boolean forceEncrypt) throws SQLServerException {
+ public void updateDouble(String columnName, double x, boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateDouble", new Object[] {columnName, x, forceEncrypt});
@@ -4343,8 +4179,7 @@ public void updateDouble(String columnName,
}
@Override
- public void updateBigDecimal(String columnName,
- BigDecimal x) throws SQLServerException {
+ public void updateBigDecimal(String columnName, BigDecimal x) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateBigDecimal", new Object[] {columnName, x});
@@ -4355,11 +4190,10 @@ public void updateBigDecimal(String columnName,
}
@Override
- public void updateBigDecimal(String columnName,
- BigDecimal x,
- boolean forceEncrypt) throws SQLServerException {
+ public void updateBigDecimal(String columnName, BigDecimal x, boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "updateBigDecimal", new Object[] {columnName, x, forceEncrypt});
+ loggerExternal.entering(getClassNameLogging(), "updateBigDecimal",
+ new Object[] {columnName, x, forceEncrypt});
checkClosed();
updateValue(findColumn(columnName), JDBCType.DECIMAL, x, JavaType.BIGDECIMAL, forceEncrypt);
@@ -4368,12 +4202,11 @@ public void updateBigDecimal(String columnName,
}
@Override
- public void updateBigDecimal(String columnName,
- BigDecimal x,
- Integer precision,
+ public void updateBigDecimal(String columnName, BigDecimal x, Integer precision,
Integer scale) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "updateBigDecimal", new Object[] {columnName, x, precision, scale});
+ loggerExternal.entering(getClassNameLogging(), "updateBigDecimal",
+ new Object[] {columnName, x, precision, scale});
checkClosed();
updateValue(findColumn(columnName), JDBCType.DECIMAL, x, JavaType.BIGDECIMAL, precision, scale, false);
@@ -4382,13 +4215,11 @@ public void updateBigDecimal(String columnName,
}
@Override
- public void updateBigDecimal(String columnName,
- BigDecimal x,
- Integer precision,
- Integer scale,
+ public void updateBigDecimal(String columnName, BigDecimal x, Integer precision, Integer scale,
boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "updateBigDecimal", new Object[] {columnName, x, precision, scale, forceEncrypt});
+ loggerExternal.entering(getClassNameLogging(), "updateBigDecimal",
+ new Object[] {columnName, x, precision, scale, forceEncrypt});
checkClosed();
updateValue(findColumn(columnName), JDBCType.DECIMAL, x, JavaType.BIGDECIMAL, precision, scale, forceEncrypt);
@@ -4397,8 +4228,7 @@ public void updateBigDecimal(String columnName,
}
@Override
- public void updateString(String columnName,
- String x) throws SQLServerException {
+ public void updateString(String columnName, String x) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateString", new Object[] {columnName, x});
@@ -4409,9 +4239,7 @@ public void updateString(String columnName,
}
@Override
- public void updateString(String columnName,
- String x,
- boolean forceEncrypt) throws SQLServerException {
+ public void updateString(String columnName, String x, boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateString", new Object[] {columnName, x, forceEncrypt});
@@ -4422,8 +4250,7 @@ public void updateString(String columnName,
}
@Override
- public void updateBytes(String columnName,
- byte x[]) throws SQLServerException {
+ public void updateBytes(String columnName, byte x[]) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateBytes", new Object[] {columnName, x});
@@ -4434,9 +4261,7 @@ public void updateBytes(String columnName,
}
@Override
- public void updateBytes(String columnName,
- byte x[],
- boolean forceEncrypt) throws SQLServerException {
+ public void updateBytes(String columnName, byte x[], boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateBytes", new Object[] {columnName, x, forceEncrypt});
@@ -4447,8 +4272,7 @@ public void updateBytes(String columnName,
}
@Override
- public void updateDate(String columnName,
- java.sql.Date x) throws SQLServerException {
+ public void updateDate(String columnName, java.sql.Date x) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateDate", new Object[] {columnName, x});
@@ -4459,9 +4283,7 @@ public void updateDate(String columnName,
}
@Override
- public void updateDate(String columnName,
- java.sql.Date x,
- boolean forceEncrypt) throws SQLServerException {
+ public void updateDate(String columnName, java.sql.Date x, boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateDate", new Object[] {columnName, x, forceEncrypt});
@@ -4472,8 +4294,7 @@ public void updateDate(String columnName,
}
@Override
- public void updateTime(String columnName,
- java.sql.Time x) throws SQLServerException {
+ public void updateTime(String columnName, java.sql.Time x) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateTime", new Object[] {columnName, x});
@@ -4484,9 +4305,7 @@ public void updateTime(String columnName,
}
@Override
- public void updateTime(String columnName,
- java.sql.Time x,
- int scale) throws SQLServerException {
+ public void updateTime(String columnName, java.sql.Time x, int scale) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateTime", new Object[] {columnName, x, scale});
@@ -4497,12 +4316,11 @@ public void updateTime(String columnName,
}
@Override
- public void updateTime(String columnName,
- java.sql.Time x,
- int scale,
+ public void updateTime(String columnName, java.sql.Time x, int scale,
boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "updateTime", new Object[] {columnName, x, scale, forceEncrypt});
+ loggerExternal.entering(getClassNameLogging(), "updateTime",
+ new Object[] {columnName, x, scale, forceEncrypt});
checkClosed();
updateValue(findColumn(columnName), JDBCType.TIME, x, JavaType.TIME, null, scale, forceEncrypt);
@@ -4511,8 +4329,7 @@ public void updateTime(String columnName,
}
@Override
- public void updateTimestamp(String columnName,
- java.sql.Timestamp x) throws SQLServerException {
+ public void updateTimestamp(String columnName, java.sql.Timestamp x) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateTimestamp", new Object[] {columnName, x});
@@ -4523,9 +4340,7 @@ public void updateTimestamp(String columnName,
}
@Override
- public void updateTimestamp(String columnName,
- java.sql.Timestamp x,
- int scale) throws SQLServerException {
+ public void updateTimestamp(String columnName, java.sql.Timestamp x, int scale) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateTimestamp", new Object[] {columnName, x, scale});
@@ -4536,12 +4351,11 @@ public void updateTimestamp(String columnName,
}
@Override
- public void updateTimestamp(String columnName,
- java.sql.Timestamp x,
- int scale,
+ public void updateTimestamp(String columnName, java.sql.Timestamp x, int scale,
boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "updateTimestamp", new Object[] {columnName, x, scale, forceEncrypt});
+ loggerExternal.entering(getClassNameLogging(), "updateTimestamp",
+ new Object[] {columnName, x, scale, forceEncrypt});
checkClosed();
updateValue(findColumn(columnName), JDBCType.TIMESTAMP, x, JavaType.TIMESTAMP, null, scale, forceEncrypt);
@@ -4550,8 +4364,7 @@ public void updateTimestamp(String columnName,
}
@Override
- public void updateDateTime(String columnName,
- java.sql.Timestamp x) throws SQLServerException {
+ public void updateDateTime(String columnName, java.sql.Timestamp x) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateDateTime", new Object[] {columnName, x});
@@ -4562,9 +4375,7 @@ public void updateDateTime(String columnName,
}
@Override
- public void updateDateTime(String columnName,
- java.sql.Timestamp x,
- int scale) throws SQLServerException {
+ public void updateDateTime(String columnName, java.sql.Timestamp x, int scale) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateDateTime", new Object[] {columnName, x, scale});
@@ -4575,12 +4386,11 @@ public void updateDateTime(String columnName,
}
@Override
- public void updateDateTime(String columnName,
- java.sql.Timestamp x,
- int scale,
+ public void updateDateTime(String columnName, java.sql.Timestamp x, int scale,
boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "updateDateTime", new Object[] {columnName, x, scale, forceEncrypt});
+ loggerExternal.entering(getClassNameLogging(), "updateDateTime",
+ new Object[] {columnName, x, scale, forceEncrypt});
checkClosed();
updateValue(findColumn(columnName), JDBCType.DATETIME, x, JavaType.TIMESTAMP, null, scale, forceEncrypt);
@@ -4589,8 +4399,7 @@ public void updateDateTime(String columnName,
}
@Override
- public void updateSmallDateTime(String columnName,
- java.sql.Timestamp x) throws SQLServerException {
+ public void updateSmallDateTime(String columnName, java.sql.Timestamp x) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateSmallDateTime", new Object[] {columnName, x});
@@ -4601,9 +4410,7 @@ public void updateSmallDateTime(String columnName,
}
@Override
- public void updateSmallDateTime(String columnName,
- java.sql.Timestamp x,
- int scale) throws SQLServerException {
+ public void updateSmallDateTime(String columnName, java.sql.Timestamp x, int scale) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateSmallDateTime", new Object[] {columnName, x, scale});
@@ -4614,12 +4421,11 @@ public void updateSmallDateTime(String columnName,
}
@Override
- public void updateSmallDateTime(String columnName,
- java.sql.Timestamp x,
- int scale,
+ public void updateSmallDateTime(String columnName, java.sql.Timestamp x, int scale,
boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "updateSmallDateTime", new Object[] {columnName, x, scale, forceEncrypt});
+ loggerExternal.entering(getClassNameLogging(), "updateSmallDateTime",
+ new Object[] {columnName, x, scale, forceEncrypt});
checkClosed();
updateValue(findColumn(columnName), JDBCType.SMALLDATETIME, x, JavaType.TIMESTAMP, null, scale, forceEncrypt);
@@ -4628,8 +4434,7 @@ public void updateSmallDateTime(String columnName,
}
@Override
- public void updateDateTimeOffset(String columnName,
- microsoft.sql.DateTimeOffset x) throws SQLServerException {
+ public void updateDateTimeOffset(String columnName, microsoft.sql.DateTimeOffset x) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateDateTimeOffset", new Object[] {columnName, x});
@@ -4640,8 +4445,7 @@ public void updateDateTimeOffset(String columnName,
}
@Override
- public void updateDateTimeOffset(String columnName,
- microsoft.sql.DateTimeOffset x,
+ public void updateDateTimeOffset(String columnName, microsoft.sql.DateTimeOffset x,
int scale) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateDateTimeOffset", new Object[] {columnName, x, scale});
@@ -4653,22 +4457,21 @@ public void updateDateTimeOffset(String columnName,
}
@Override
- public void updateDateTimeOffset(String columnName,
- microsoft.sql.DateTimeOffset x,
- int scale,
+ public void updateDateTimeOffset(String columnName, microsoft.sql.DateTimeOffset x, int scale,
boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "updateDateTimeOffset", new Object[] {columnName, x, scale, forceEncrypt});
+ loggerExternal.entering(getClassNameLogging(), "updateDateTimeOffset",
+ new Object[] {columnName, x, scale, forceEncrypt});
checkClosed();
- updateValue(findColumn(columnName), JDBCType.DATETIMEOFFSET, x, JavaType.DATETIMEOFFSET, null, scale, forceEncrypt);
+ updateValue(findColumn(columnName), JDBCType.DATETIMEOFFSET, x, JavaType.DATETIMEOFFSET, null, scale,
+ forceEncrypt);
loggerExternal.exiting(getClassNameLogging(), "updateDateTimeOffset");
}
@Override
- public void updateUniqueIdentifier(String columnName,
- String x) throws SQLServerException {
+ public void updateUniqueIdentifier(String columnName, String x) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateUniqueIdentifier", new Object[] {columnName, x});
@@ -4679,11 +4482,10 @@ public void updateUniqueIdentifier(String columnName,
}
@Override
- public void updateUniqueIdentifier(String columnName,
- String x,
- boolean forceEncrypt) throws SQLServerException {
+ public void updateUniqueIdentifier(String columnName, String x, boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "updateUniqueIdentifier", new Object[] {columnName, x, forceEncrypt});
+ loggerExternal.entering(getClassNameLogging(), "updateUniqueIdentifier",
+ new Object[] {columnName, x, forceEncrypt});
checkClosed();
updateValue(findColumn(columnName), JDBCType.GUID, x, JavaType.STRING, null, forceEncrypt);
@@ -4692,9 +4494,7 @@ public void updateUniqueIdentifier(String columnName,
}
@Override
- public void updateObject(String columnName,
- Object x,
- int scale) throws SQLServerException {
+ public void updateObject(String columnName, Object x, int scale) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateObject", new Object[] {columnName, x, scale});
@@ -4705,12 +4505,10 @@ public void updateObject(String columnName,
}
@Override
- public void updateObject(String columnName,
- Object x,
- int precision,
- int scale) throws SQLServerException {
+ public void updateObject(String columnName, Object x, int precision, int scale) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "updateObject", new Object[] {columnName, x, precision, scale});
+ loggerExternal.entering(getClassNameLogging(), "updateObject",
+ new Object[] {columnName, x, precision, scale});
checkClosed();
updateObject(findColumn(columnName), x, scale, null, precision, false);
@@ -4719,13 +4517,11 @@ public void updateObject(String columnName,
}
@Override
- public void updateObject(String columnName,
- Object x,
- int precision,
- int scale,
+ public void updateObject(String columnName, Object x, int precision, int scale,
boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "updateObject", new Object[] {columnName, x, precision, scale, forceEncrypt});
+ loggerExternal.entering(getClassNameLogging(), "updateObject",
+ new Object[] {columnName, x, precision, scale, forceEncrypt});
checkClosed();
updateObject(findColumn(columnName), x, scale, null, precision, forceEncrypt);
@@ -4734,8 +4530,7 @@ public void updateObject(String columnName,
}
@Override
- public void updateObject(String columnName,
- Object x) throws SQLServerException {
+ public void updateObject(String columnName, Object x) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateObject", new Object[] {columnName, x});
@@ -4746,20 +4541,17 @@ public void updateObject(String columnName,
}
@Override
- public void updateRowId(int columnIndex,
- RowId x) throws SQLException {
+ public void updateRowId(int columnIndex, RowId x) throws SQLException {
SQLServerException.throwNotSupportedException(stmt.connection, stmt);
}
@Override
- public void updateRowId(String columnLabel,
- RowId x) throws SQLException {
+ public void updateRowId(String columnLabel, RowId x) throws SQLException {
SQLServerException.throwNotSupportedException(stmt.connection, stmt);
}
@Override
- public void updateSQLXML(int columnIndex,
- SQLXML xmlObject) throws SQLException {
+ public void updateSQLXML(int columnIndex, SQLXML xmlObject) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateSQLXML", new Object[] {columnIndex, xmlObject});
updateSQLXMLInternal(columnIndex, xmlObject);
@@ -4767,8 +4559,7 @@ public void updateSQLXML(int columnIndex,
}
@Override
- public void updateSQLXML(String columnLabel,
- SQLXML x) throws SQLException {
+ public void updateSQLXML(String columnLabel, SQLXML x) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateSQLXML", new Object[] {columnLabel, x});
updateSQLXMLInternal(findColumn(columnLabel), x);
@@ -4790,7 +4581,7 @@ public int getHoldability() throws SQLException {
// For Yukon and later server-cursored result sets, holdability
// was determined at statement execution time and does not change.
- stmt.getExecProps().getHoldability();
+ stmt.getExecProps().getHoldability();
loggerExternal.exiting(getClassNameLogging(), "getHoldability", holdability);
@@ -4830,7 +4621,8 @@ final boolean doExecute() throws SQLServerException {
verifyResultSetIsUpdatable();
if (!isOnInsertRow) {
- SQLServerException.makeFromDriverError(stmt.connection, stmt, SQLServerException.getErrString("R_mustBeOnInsertRow"), null, true);
+ SQLServerException.makeFromDriverError(stmt.connection, stmt,
+ SQLServerException.getErrString("R_mustBeOnInsertRow"), null, true);
}
// Determine the table/view into which the row is to be inserted.
@@ -4860,7 +4652,8 @@ final boolean doExecute() throws SQLServerException {
}
if (null == tableColumn) {
- SQLServerException.makeFromDriverError(stmt.connection, stmt, SQLServerException.getErrString("R_noColumnParameterValue"), null, true);
+ SQLServerException.makeFromDriverError(stmt.connection, stmt,
+ SQLServerException.getErrString("R_noColumnParameterValue"), null, true);
}
assert tableColumn.isUpdatable();
@@ -4873,8 +4666,7 @@ final boolean doExecute() throws SQLServerException {
loggerExternal.exiting(getClassNameLogging(), "insertRow");
}
- private void doInsertRowRPC(TDSCommand command,
- String tableName) throws SQLServerException {
+ private void doInsertRowRPC(TDSCommand command, String tableName) throws SQLServerException {
assert 0 != serverCursorId;
assert null != tableName;
assert tableName.length() > 0;
@@ -4882,8 +4674,8 @@ private void doInsertRowRPC(TDSCommand command,
TDSWriter tdsWriter = command.startRequest(TDS.PKT_RPC);
tdsWriter.writeShort((short) 0xFFFF); // procedure name length -> use ProcIDs
tdsWriter.writeShort(TDS.PROCID_SP_CURSOR);
- tdsWriter.writeByte((byte) 0); // RPC procedure option 1
- tdsWriter.writeByte((byte) 0); // RPC procedure option 2
+ tdsWriter.writeByte((byte) 0); // RPC procedure option 1
+ tdsWriter.writeByte((byte) 0); // RPC procedure option 2
tdsWriter.writeRPCInt(null, serverCursorId, false);
tdsWriter.writeRPCInt(null, (int) TDS.SP_CURSOR_OP_INSERT, false);
tdsWriter.writeRPCInt(null, fetchBufferGetRow(), false);
@@ -4893,8 +4685,7 @@ private void doInsertRowRPC(TDSCommand command,
for (Column column : columns)
column.sendByRPC(tdsWriter, stmt.connection);
- }
- else {
+ } else {
tdsWriter.writeRPCStringUnicode("");
tdsWriter.writeRPCStringUnicode("INSERT INTO " + tableName + " DEFAULT VALUES");
}
@@ -4938,13 +4729,13 @@ final boolean doExecute() throws SQLServerException {
verifyCurrentRowIsNotDeleted("R_cantUpdateDeletedRow");
if (!hasUpdatedColumns()) {
- SQLServerException.makeFromDriverError(stmt.connection, stmt, SQLServerException.getErrString("R_noColumnParameterValue"), null, true);
+ SQLServerException.makeFromDriverError(stmt.connection, stmt,
+ SQLServerException.getErrString("R_noColumnParameterValue"), null, true);
}
try {
stmt.executeCommand(new UpdateRowRPC());
- }
- finally {
+ } finally {
cancelUpdates();
}
@@ -4958,8 +4749,8 @@ private void doUpdateRowRPC(TDSCommand command) throws SQLServerException {
TDSWriter tdsWriter = command.startRequest(TDS.PKT_RPC);
tdsWriter.writeShort((short) 0xFFFF); // procedure name length -> use ProcIDs
tdsWriter.writeShort(TDS.PROCID_SP_CURSOR);
- tdsWriter.writeByte((byte) 0); // RPC procedure option 1
- tdsWriter.writeByte((byte) 0); // RPC procedure option 2
+ tdsWriter.writeByte((byte) 0); // RPC procedure option 1
+ tdsWriter.writeByte((byte) 0); // RPC procedure option 2
tdsWriter.writeRPCInt(null, serverCursorId, false);
tdsWriter.writeRPCInt(null, TDS.SP_CURSOR_OP_UPDATE | TDS.SP_CURSOR_OP_SETPOSITION, false);
tdsWriter.writeRPCInt(null, fetchBufferGetRow(), false);
@@ -5017,8 +4808,7 @@ final boolean doExecute() throws SQLServerException {
try {
stmt.executeCommand(new DeleteRowRPC());
- }
- finally {
+ } finally {
cancelUpdates();
}
@@ -5032,8 +4822,8 @@ private void doDeleteRowRPC(TDSCommand command) throws SQLServerException {
TDSWriter tdsWriter = command.startRequest(TDS.PKT_RPC);
tdsWriter.writeShort((short) 0xFFFF); // procedure name length -> use ProcIDs
tdsWriter.writeShort(TDS.PROCID_SP_CURSOR);
- tdsWriter.writeByte((byte) 0); // RPC procedure option 1
- tdsWriter.writeByte((byte) 0); // RPC procedure option 2
+ tdsWriter.writeByte((byte) 0); // RPC procedure option 1
+ tdsWriter.writeByte((byte) 0); // RPC procedure option 2
tdsWriter.writeRPCInt(null, serverCursorId, false);
tdsWriter.writeRPCInt(null, TDS.SP_CURSOR_OP_DELETE | TDS.SP_CURSOR_OP_SETPOSITION, false);
tdsWriter.writeRPCInt(null, fetchBufferGetRow(), false);
@@ -5103,7 +4893,8 @@ private void doRefreshRow() throws SQLServerException {
// the refresh -- rows may have been added, modified, or deleted -- so the current row
// may not end up where it was before the refresh.
int fetchBufferRestoredRow = 0;
- while (fetchBufferRestoredRow < fetchBufferSavedRow && (isForwardOnly() ? fetchBufferNext() : scrollWindow.next(this))) {
+ while (fetchBufferRestoredRow < fetchBufferSavedRow
+ && (isForwardOnly() ? fetchBufferNext() : scrollWindow.next(this))) {
++fetchBufferRestoredRow;
}
@@ -5186,8 +4977,7 @@ public java.sql.Statement getStatement() throws SQLServerException {
/* JDBC 3.0 */
@Override
- public void updateClob(int columnIndex,
- Clob clobValue) throws SQLException {
+ public void updateClob(int columnIndex, Clob clobValue) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateClob", new Object[] {columnIndex, clobValue});
@@ -5198,8 +4988,7 @@ public void updateClob(int columnIndex,
}
@Override
- public void updateClob(int columnIndex,
- Reader reader) throws SQLException {
+ public void updateClob(int columnIndex, Reader reader) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateClob", new Object[] {columnIndex, reader});
@@ -5210,9 +4999,7 @@ public void updateClob(int columnIndex,
}
@Override
- public void updateClob(int columnIndex,
- Reader reader,
- long length) throws SQLException {
+ public void updateClob(int columnIndex, Reader reader, long length) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateClob", new Object[] {columnIndex, reader, length});
@@ -5223,8 +5010,7 @@ public void updateClob(int columnIndex,
}
@Override
- public void updateClob(String columnName,
- Clob clobValue) throws SQLException {
+ public void updateClob(String columnName, Clob clobValue) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateClob", new Object[] {columnName, clobValue});
@@ -5235,21 +5021,19 @@ public void updateClob(String columnName,
}
@Override
- public void updateClob(String columnLabel,
- Reader reader) throws SQLException {
+ public void updateClob(String columnLabel, Reader reader) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateClob", new Object[] {columnLabel, reader});
checkClosed();
- updateStream(findColumn(columnLabel), StreamType.CHARACTER, reader, JavaType.READER, DataTypes.UNKNOWN_STREAM_LENGTH);
+ updateStream(findColumn(columnLabel), StreamType.CHARACTER, reader, JavaType.READER,
+ DataTypes.UNKNOWN_STREAM_LENGTH);
loggerExternal.exiting(getClassNameLogging(), "updateClob");
}
@Override
- public void updateClob(String columnLabel,
- Reader reader,
- long length) throws SQLException {
+ public void updateClob(String columnLabel, Reader reader, long length) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateClob", new Object[] {columnLabel, reader, length});
@@ -5260,8 +5044,7 @@ public void updateClob(String columnLabel,
}
@Override
- public void updateNClob(int columnIndex,
- NClob nClob) throws SQLException {
+ public void updateNClob(int columnIndex, NClob nClob) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateClob", new Object[] {columnIndex, nClob});
@@ -5272,8 +5055,7 @@ public void updateNClob(int columnIndex,
}
@Override
- public void updateNClob(int columnIndex,
- Reader reader) throws SQLException {
+ public void updateNClob(int columnIndex, Reader reader) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateNClob", new Object[] {columnIndex, reader});
@@ -5284,9 +5066,7 @@ public void updateNClob(int columnIndex,
}
@Override
- public void updateNClob(int columnIndex,
- Reader reader,
- long length) throws SQLException {
+ public void updateNClob(int columnIndex, Reader reader, long length) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateNClob", new Object[] {columnIndex, reader, length});
@@ -5297,8 +5077,7 @@ public void updateNClob(int columnIndex,
}
@Override
- public void updateNClob(String columnLabel,
- NClob nClob) throws SQLException {
+ public void updateNClob(String columnLabel, NClob nClob) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateNClob", new Object[] {columnLabel, nClob});
@@ -5309,21 +5088,19 @@ public void updateNClob(String columnLabel,
}
@Override
- public void updateNClob(String columnLabel,
- Reader reader) throws SQLException {
+ public void updateNClob(String columnLabel, Reader reader) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateNClob", new Object[] {columnLabel, reader});
checkClosed();
- updateStream(findColumn(columnLabel), StreamType.NCHARACTER, reader, JavaType.READER, DataTypes.UNKNOWN_STREAM_LENGTH);
+ updateStream(findColumn(columnLabel), StreamType.NCHARACTER, reader, JavaType.READER,
+ DataTypes.UNKNOWN_STREAM_LENGTH);
loggerExternal.exiting(getClassNameLogging(), "updateNClob");
}
@Override
- public void updateNClob(String columnLabel,
- Reader reader,
- long length) throws SQLException {
+ public void updateNClob(String columnLabel, Reader reader, long length) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateNClob", new Object[] {columnLabel, reader, length});
@@ -5334,8 +5111,7 @@ public void updateNClob(String columnLabel,
}
@Override
- public void updateBlob(int columnIndex,
- Blob blobValue) throws SQLException {
+ public void updateBlob(int columnIndex, Blob blobValue) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateBlob", new Object[] {columnIndex, blobValue});
@@ -5346,23 +5122,22 @@ public void updateBlob(int columnIndex,
}
@Override
- public void updateBlob(int columnIndex,
- InputStream inputStream) throws SQLException {
+ public void updateBlob(int columnIndex, InputStream inputStream) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateBlob", new Object[] {columnIndex, inputStream});
checkClosed();
- updateStream(columnIndex, StreamType.BINARY, inputStream, JavaType.INPUTSTREAM, DataTypes.UNKNOWN_STREAM_LENGTH);
+ updateStream(columnIndex, StreamType.BINARY, inputStream, JavaType.INPUTSTREAM,
+ DataTypes.UNKNOWN_STREAM_LENGTH);
loggerExternal.exiting(getClassNameLogging(), "updateBlob");
}
@Override
- public void updateBlob(int columnIndex,
- InputStream inputStream,
- long length) throws SQLException {
+ public void updateBlob(int columnIndex, InputStream inputStream, long length) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "updateBlob", new Object[] {columnIndex, inputStream, length});
+ loggerExternal.entering(getClassNameLogging(), "updateBlob",
+ new Object[] {columnIndex, inputStream, length});
checkClosed();
updateStream(columnIndex, StreamType.BINARY, inputStream, JavaType.INPUTSTREAM, length);
@@ -5371,8 +5146,7 @@ public void updateBlob(int columnIndex,
}
@Override
- public void updateBlob(String columnName,
- Blob blobValue) throws SQLException {
+ public void updateBlob(String columnName, Blob blobValue) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateBlob", new Object[] {columnName, blobValue});
@@ -5383,23 +5157,22 @@ public void updateBlob(String columnName,
}
@Override
- public void updateBlob(String columnLabel,
- InputStream inputStream) throws SQLException {
+ public void updateBlob(String columnLabel, InputStream inputStream) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateBlob", new Object[] {columnLabel, inputStream});
checkClosed();
- updateStream(findColumn(columnLabel), StreamType.BINARY, inputStream, JavaType.INPUTSTREAM, DataTypes.UNKNOWN_STREAM_LENGTH);
+ updateStream(findColumn(columnLabel), StreamType.BINARY, inputStream, JavaType.INPUTSTREAM,
+ DataTypes.UNKNOWN_STREAM_LENGTH);
loggerExternal.exiting(getClassNameLogging(), "updateBlob");
}
@Override
- public void updateBlob(String columnLabel,
- InputStream inputStream,
- long length) throws SQLException {
+ public void updateBlob(String columnLabel, InputStream inputStream, long length) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "updateBlob", new Object[] {columnLabel, inputStream, length});
+ loggerExternal.entering(getClassNameLogging(), "updateBlob",
+ new Object[] {columnLabel, inputStream, length});
checkClosed();
updateStream(findColumn(columnLabel), StreamType.BINARY, inputStream, JavaType.INPUTSTREAM, length);
@@ -5408,26 +5181,22 @@ public void updateBlob(String columnLabel,
}
@Override
- public void updateArray(int columnIndex,
- Array x) throws SQLException {
+ public void updateArray(int columnIndex, Array x) throws SQLException {
SQLServerException.throwNotSupportedException(stmt.connection, stmt);
}
@Override
- public void updateArray(java.lang.String columnName,
- Array x) throws SQLException {
+ public void updateArray(java.lang.String columnName, Array x) throws SQLException {
SQLServerException.throwNotSupportedException(stmt.connection, stmt);
}
@Override
- public void updateRef(int columnIndex,
- Ref x) throws SQLException {
+ public void updateRef(int columnIndex, Ref x) throws SQLException {
SQLServerException.throwNotSupportedException(stmt.connection, stmt);
}
@Override
- public void updateRef(java.lang.String columnName,
- Ref x) throws SQLException {
+ public void updateRef(java.lang.String columnName, Ref x) throws SQLException {
SQLServerException.throwNotSupportedException(stmt.connection, stmt);
}
@@ -5449,16 +5218,19 @@ public java.net.URL getURL(String sColumn) throws SQLException {
/**
* Fetch buffer that provides a source of rows to this ResultSet.
*
- * The FetchBuffer class is different conceptually from the ScrollWindow class. The latter provides indexing and arbitrary scrolling over rows
- * provided by the fetch buffer. The fetch buffer itself just provides the rows and supports rewinding back to the start of the buffer. When
- * server cursors are involved, the fetch buffer is typically the same size as the scroll window. However, with client side scrollable cursors,
- * the fetch buffer would contain all of the rows in the result set, but the scroll window would only contain some of them (determined by
- * ResultSet.setFetchSize).
+ * The FetchBuffer class is different conceptually from the ScrollWindow class. The latter provides indexing and
+ * arbitrary scrolling over rows provided by the fetch buffer. The fetch buffer itself just provides the rows and
+ * supports rewinding back to the start of the buffer. When server cursors are involved, the fetch buffer is
+ * typically the same size as the scroll window. However, with client side scrollable cursors, the fetch buffer
+ * would contain all of the rows in the result set, but the scroll window would only contain some of them
+ * (determined by ResultSet.setFetchSize).
*
- * The fetch buffer contains 0 or more ROW tokens followed by a DONE (cmd=SELECT, 0xC1) token indicating the number of rows in the fetch buffer.
+ * The fetch buffer contains 0 or more ROW tokens followed by a DONE (cmd=SELECT, 0xC1) token indicating the number
+ * of rows in the fetch buffer.
*
- * For client-cursored result sets, the fetch buffer contains all of the rows in the result set, and the DONE token indicates the total number of
- * rows in the result set, though we don't use that information, as we always count rows as we encounter them.
+ * For client-cursored result sets, the fetch buffer contains all of the rows in the result set, and the DONE token
+ * indicates the total number of rows in the result set, though we don't use that information, as we always count
+ * rows as we encounter them.
*/
private final class FetchBuffer {
private final class FetchBufferTokenHandler extends TDSTokenHandler {
@@ -5470,7 +5242,8 @@ private final class FetchBufferTokenHandler extends TDSTokenHandler {
// the server still returns a COLMETADATA_TOKEN containing the magic NoMetaData
// value that we need to read through.
boolean onColMetaData(TDSReader tdsReader) throws SQLServerException {
- (new StreamColumns(Util.shouldHonorAEForRead(stmt.stmtColumnEncriptionSetting, stmt.connection))).setFromTDS(tdsReader);
+ (new StreamColumns(Util.shouldHonorAEForRead(stmt.stmtColumnEncriptionSetting, stmt.connection)))
+ .setFromTDS(tdsReader);
return true;
}
@@ -5581,8 +5354,8 @@ final void reset() {
}
/**
- * Initializes the fetch buffer with new contents and optionally sets a TDSReaderMark at the start of the fetch buffer to allow the fetch
- * buffer to be scrolled back to the beginning.
+ * Initializes the fetch buffer with new contents and optionally sets a TDSReaderMark at the start of the fetch
+ * buffer to allow the fetch buffer to be scrolled back to the beginning.
*/
final void init() {
startMark = (0 == serverCursorId && !isForwardOnly()) ? tdsReader.mark() : null;
@@ -5600,8 +5373,10 @@ final RowType nextRow() throws SQLServerException {
while (null != tdsReader && !done && fetchBufferCurrentRowType.equals(RowType.UNKNOWN))
TDSParser.parse(tdsReader, fetchBufferTokenHandler);
- if (fetchBufferCurrentRowType.equals(RowType.UNKNOWN) && null != fetchBufferTokenHandler.getDatabaseError()) {
- SQLServerException.makeFromDatabaseError(stmt.connection, null, fetchBufferTokenHandler.getDatabaseError().getMessage(),
+ if (fetchBufferCurrentRowType.equals(RowType.UNKNOWN)
+ && null != fetchBufferTokenHandler.getDatabaseError()) {
+ SQLServerException.makeFromDatabaseError(stmt.connection, null,
+ fetchBufferTokenHandler.getDatabaseError().getMessage(),
fetchBufferTokenHandler.getDatabaseError(), false);
}
@@ -5615,10 +5390,7 @@ private final class CursorFetchCommand extends TDSCommand {
private int startRow;
private int numRows;
- CursorFetchCommand(int serverCursorId,
- int fetchType,
- int startRow,
- int numRows) {
+ CursorFetchCommand(int serverCursorId, int fetchType, int startRow, int numRows) {
super("doServerFetch", stmt.queryTimeout, stmt.cancelQueryTimeoutSeconds);
this.serverCursorId = serverCursorId;
this.fetchType = fetchType;
@@ -5631,7 +5403,7 @@ final boolean doExecute() throws SQLServerException {
tdsWriter.writeShort((short) 0xFFFF); // procedure name length -> use ProcIDs
tdsWriter.writeShort(TDS.PROCID_SP_CURSORFETCH);
tdsWriter.writeByte(TDS.RPC_OPTION_NO_METADATA);
- tdsWriter.writeByte((byte) 0); // RPC procedure option 2
+ tdsWriter.writeByte((byte) 0); // RPC procedure option 2
tdsWriter.writeRPCInt(null, serverCursorId, false);
tdsWriter.writeRPCInt(null, fetchType, false);
tdsWriter.writeRPCInt(null, startRow, false);
@@ -5644,7 +5416,8 @@ final boolean doExecute() throws SQLServerException {
// can do a forward only updatable pass through a ResultSet with large
// data values.
tdsReader = startResponse(isForwardOnly() && CONCUR_READ_ONLY != stmt.resultSetConcurrency
- && stmt.getExecProps().wasResponseBufferingSet() && stmt.getExecProps().isResponseBufferingAdaptive());
+ && stmt.getExecProps().wasResponseBufferingSet()
+ && stmt.getExecProps().isResponseBufferingAdaptive());
return false;
}
@@ -5659,17 +5432,15 @@ final void processResponse(TDSReader responseTDSReader) throws SQLServerExceptio
* Position a server side cursor.
*
* @param fetchType
- * The type of fetch
+ * The type of fetch
* @param startRow
- * The starting row
+ * The starting row
* @param numRows
- * The number of rows to fetch
+ * The number of rows to fetch
* @exception SQLServerException
- * The cursor was invalid.
+ * The cursor was invalid.
*/
- final void doServerFetch(int fetchType,
- int startRow,
- int numRows) throws SQLServerException {
+ final void doServerFetch(int fetchType, int startRow, int numRows) throws SQLServerException {
if (logger.isLoggable(java.util.logging.Level.FINER))
logger.finer(toString() + " fetchType:" + fetchType + " startRow:" + startRow + " numRows:" + numRows);
@@ -5702,15 +5473,14 @@ final void doServerFetch(int fetchType,
if (numRows < 0 || startRow < 0) {
// Scroll past all the returned rows, caching in the scroll window as we go.
try {
- while (scrollWindow.next(this))
- ;
- }
- catch (SQLException e) {
+ while (scrollWindow.next(this));
+ } catch (SQLException e) {
// If there is a row error in the results, don't throw an exception from here.
// Ignore it for now and defer the exception until the app encounters the
// error through normal cursor movement.
if (logger.isLoggable(java.util.logging.Level.FINER))
- logger.finer(toString() + " Ignored exception from row error during server cursor fixup: " + e.getMessage());
+ logger.finer(toString() + " Ignored exception from row error during server cursor fixup: "
+ + e.getMessage());
}
// Force the cursor to move to before the first row if necessary.
@@ -5725,20 +5495,18 @@ final void doServerFetch(int fetchType,
}
/*
- * Checks for any LOBs which need to be available after the RS is closed, and loads their contents from stream into memory. Closed LOBs will not
- * be populated.
+ * Checks for any LOBs which need to be available after the RS is closed, and loads their contents from stream into
+ * memory. Closed LOBs will not be populated.
*/
private void fillLOBs() {
if (null != activeLOB) {
try {
activeLOB.fillFromStream();
- }
- catch (SQLException e) {
+ } catch (SQLException e) {
if (logger.isLoggable(java.util.logging.Level.FINER)) {
logger.finer(toString() + "Filling Lobs before closing: " + e.getMessage());
}
- }
- finally {
+ } finally {
activeLOB = null;
}
}
@@ -5747,12 +5515,14 @@ private void fillLOBs() {
/**
* Discards the contents of the current fetch buffer.
*
- * This method ensures that the contents of the current fetch buffer have been completely read from the TDS channel, processed, and discarded.
+ * This method ensures that the contents of the current fetch buffer have been completely read from the TDS channel,
+ * processed, and discarded.
*
- * Note that exceptions resulting from database errors, such as row errors or transaction rollbacks, and from I/O errors, such as a closed
- * connection, are caught, logged, and ignored. The expectation is that callers of this method just want the fetch buffer cleared out and do not
- * care about what errors may have occurred when it was last populated. If the connection is closed while discarding the fetch buffer, then the
- * fetch buffer is considered to be discarded.
+ * Note that exceptions resulting from database errors, such as row errors or transaction rollbacks, and from I/O
+ * errors, such as a closed connection, are caught, logged, and ignored. The expectation is that callers of this
+ * method just want the fetch buffer cleared out and do not care about what errors may have occurred when it was
+ * last populated. If the connection is closed while discarding the fetch buffer, then the fetch buffer is
+ * considered to be discarded.
*/
private void discardFetchBuffer() {
// fills blobs before discarding anything
@@ -5768,10 +5538,8 @@ private void discardFetchBuffer() {
// Once there are no TDSReader marks left referring to the fetch buffer
// contents, process the remainder of the current row and all subsequent rows.
try {
- while (fetchBufferNext())
- ;
- }
- catch (SQLServerException e) {
+ while (fetchBufferNext());
+ } catch (SQLServerException e) {
if (logger.isLoggable(java.util.logging.Level.FINER))
logger.finer(this + " Encountered exception discarding fetch buffer: " + e.getMessage());
}
@@ -5791,8 +5559,7 @@ final void closeServerCursor() {
if (stmt.connection.isSessionUnAvailable()) {
if (logger.isLoggable(java.util.logging.Level.FINER))
logger.finer(this + ": Not closing cursor:" + serverCursorId + "; connection is already closed.");
- }
- else {
+ } else {
if (logger.isLoggable(java.util.logging.Level.FINER))
logger.finer(toString() + " Closing cursor:" + serverCursorId);
@@ -5805,8 +5572,8 @@ final boolean doExecute() throws SQLServerException {
TDSWriter tdsWriter = startRequest(TDS.PKT_RPC);
tdsWriter.writeShort((short) 0xFFFF); // procedure name length -> use ProcIDs
tdsWriter.writeShort(TDS.PROCID_SP_CURSORCLOSE);
- tdsWriter.writeByte((byte) 0); // RPC procedure option 1
- tdsWriter.writeByte((byte) 0); // RPC procedure option 2
+ tdsWriter.writeByte((byte) 0); // RPC procedure option 1
+ tdsWriter.writeByte((byte) 0); // RPC procedure option 2
tdsWriter.writeRPCInt(null, serverCursorId, false);
TDSParser.parse(startResponse(), getLogContext());
return true;
@@ -5816,8 +5583,7 @@ final boolean doExecute() throws SQLServerException {
// Try to close the server cursor. Any failure is caught, logged, and ignored.
try {
stmt.executeCommand(new CloseServerCursorCommand());
- }
- catch (SQLServerException e) {
+ } catch (SQLServerException e) {
if (logger.isLoggable(java.util.logging.Level.FINER))
logger.finer(toString() + " Ignored error closing cursor:" + serverCursorId + " " + e.getMessage());
}
@@ -5828,9 +5594,7 @@ final boolean doExecute() throws SQLServerException {
}
@Override
- public void updateObject(int index,
- Object obj,
- SQLType targetSqlType) throws SQLServerException {
+ public void updateObject(int index, Object obj, SQLType targetSqlType) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "updateObject", new Object[] {index, obj, targetSqlType});
@@ -5843,13 +5607,11 @@ public void updateObject(int index,
}
@Override
- public void updateObject(int index,
- Object obj,
- SQLType targetSqlType,
- int scale) throws SQLServerException {
+ public void updateObject(int index, Object obj, SQLType targetSqlType, int scale) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "updateObject", new Object[] {index, obj, targetSqlType, scale});
+ loggerExternal.entering(getClassNameLogging(), "updateObject",
+ new Object[] {index, obj, targetSqlType, scale});
checkClosed();
// getVendorTypeNumber() returns the same constant integer values as in java.sql.Types
@@ -5859,14 +5621,12 @@ public void updateObject(int index,
}
@Override
- public void updateObject(int index,
- Object obj,
- SQLType targetSqlType,
- int scale,
+ public void updateObject(int index, Object obj, SQLType targetSqlType, int scale,
boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "updateObject", new Object[] {index, obj, targetSqlType, scale, forceEncrypt});
+ loggerExternal.entering(getClassNameLogging(), "updateObject",
+ new Object[] {index, obj, targetSqlType, scale, forceEncrypt});
checkClosed();
// getVendorTypeNumber() returns the same constant integer values as in java.sql.Types
@@ -5876,13 +5636,12 @@ public void updateObject(int index,
}
@Override
- public void updateObject(String columnName,
- Object obj,
- SQLType targetSqlType,
+ public void updateObject(String columnName, Object obj, SQLType targetSqlType,
int scale) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "updateObject", new Object[] {columnName, obj, targetSqlType, scale});
+ loggerExternal.entering(getClassNameLogging(), "updateObject",
+ new Object[] {columnName, obj, targetSqlType, scale});
checkClosed();
@@ -5893,30 +5652,28 @@ public void updateObject(String columnName,
}
@Override
- public void updateObject(String columnName,
- Object obj,
- SQLType targetSqlType,
- int scale,
+ public void updateObject(String columnName, Object obj, SQLType targetSqlType, int scale,
boolean forceEncrypt) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "updateObject", new Object[] {columnName, obj, targetSqlType, scale, forceEncrypt});
+ loggerExternal.entering(getClassNameLogging(), "updateObject",
+ new Object[] {columnName, obj, targetSqlType, scale, forceEncrypt});
checkClosed();
// getVendorTypeNumber() returns the same constant integer values as in java.sql.Types
- updateObject(findColumn(columnName), obj, scale, JDBCType.of(targetSqlType.getVendorTypeNumber()), null, forceEncrypt);
+ updateObject(findColumn(columnName), obj, scale, JDBCType.of(targetSqlType.getVendorTypeNumber()), null,
+ forceEncrypt);
loggerExternal.exiting(getClassNameLogging(), "updateObject");
}
@Override
- public void updateObject(String columnName,
- Object obj,
- SQLType targetSqlType) throws SQLServerException {
+ public void updateObject(String columnName, Object obj, SQLType targetSqlType) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
- loggerExternal.entering(getClassNameLogging(), "updateObject", new Object[] {columnName, obj, targetSqlType});
+ loggerExternal.entering(getClassNameLogging(), "updateObject",
+ new Object[] {columnName, obj, targetSqlType});
checkClosed();
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResultSetMetaData.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResultSetMetaData.java
index e3b7679fa..5f36d2d75 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResultSetMetaData.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResultSetMetaData.java
@@ -1,9 +1,6 @@
/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc;
@@ -11,20 +8,22 @@
import java.sql.SQLException;
import java.util.concurrent.atomic.AtomicInteger;
+
/**
- * A ResultSetMetaData object can be used to obtain the meta data (types and type properties) of the columns in a ResultSet.
+ * Provides an implementation of the result set metadata to the SQL Server. A ResultSetMetaData object can be used to
+ * obtain the meta data (types and type properties) of the columns in a ResultSet.
*
- * The API javadoc for JDBC API methods that this class implements are not repeated here. Please see Sun's JDBC API interfaces javadoc for those
- * details.
+ * The API javadoc for JDBC API methods that this class implements are not repeated here. Please see Sun's JDBC API
+ * interfaces javadoc for those details.
*/
-
public final class SQLServerResultSetMetaData implements ISQLServerResultSetMetaData {
private SQLServerConnection con;
private final SQLServerResultSet rs;
static final private java.util.logging.Logger logger = java.util.logging.Logger
.getLogger("com.microsoft.sqlserver.jdbc.internals.SQLServerResultSetMetaData");
- static private final AtomicInteger baseID = new AtomicInteger(0); // Unique id generator for each instance (used for logging).
+ static private final AtomicInteger baseID = new AtomicInteger(0); // Unique id generator for each instance (used for
+ // logging).
final private String traceID;
// Returns unique id for each instance.
@@ -37,15 +36,14 @@ final public String toString() {
}
/**
- * Create a new meta data object for the result set.
+ * Constructs a SQLServerResultSetMetaData meta data object for the result set.
*
* @param con
- * the connection
+ * the connection
* @param rs
- * the parent result set
+ * the parent result set
*/
- SQLServerResultSetMetaData(SQLServerConnection con,
- SQLServerResultSet rs) {
+ SQLServerResultSetMetaData(SQLServerConnection con, SQLServerResultSet rs) {
traceID = " SQLServerResultSetMetaData:" + nextInstanceID();
this.con = con;
this.rs = rs;
@@ -68,8 +66,7 @@ public T unwrap(Class iface) throws SQLException {
T t;
try {
t = iface.cast(this);
- }
- catch (ClassCastException e) {
+ } catch (ClassCastException e) {
throw new SQLServerException(e.getMessage(), e);
}
return t;
@@ -114,11 +111,12 @@ public int getColumnType(int column) throws SQLServerException {
if (null != cryptoMetadata) {
typeInfo = cryptoMetadata.getBaseTypeInfo();
}
-
+
JDBCType jdbcType = typeInfo.getSSType().getJDBCType();
SSType sqlType = typeInfo.getSSType();
- // in bulkcopy for instance, we need to return the real jdbc type which is sql variant and not the default Char one.
- if ( SSType.SQL_VARIANT == sqlType){
+ // in bulkcopy for instance, we need to return the real jdbc type which is sql variant and not the default Char
+ // one.
+ if (SSType.SQL_VARIANT == sqlType) {
jdbcType = JDBCType.SQL_VARIANT;
}
if (SSType.UDT == sqlType) {
@@ -269,8 +267,7 @@ public boolean isSearchable(int column) throws SQLServerException {
if (null != cryptoMetadata) {
ssType = cryptoMetadata.getBaseTypeInfo().getSSType();
- }
- else {
+ } else {
ssType = rs.getColumn(column).getTypeInfo().getSSType();
}
@@ -313,8 +310,7 @@ public boolean isWritable(int column) throws SQLServerException {
CryptoMetadata cryptoMetadata = rs.getColumn(column).getCryptoMetadata();
if (null != cryptoMetadata) {
updatability = cryptoMetadata.getBaseTypeInfo().getUpdatability();
- }
- else {
+ } else {
updatability = rs.getColumn(column).getTypeInfo().getUpdatability();
}
return TypeInfo.UPDATABLE_READ_WRITE == updatability || TypeInfo.UPDATABLE_UNKNOWN == updatability;
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerSQLXML.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerSQLXML.java
index da860456a..b58a715c3 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerSQLXML.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerSQLXML.java
@@ -1,9 +1,6 @@
/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc;
@@ -50,10 +47,11 @@
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
+
+
/**
- * SQLServerSQLXML represents an XML object and implements a java.sql.SQLXML.
+ * Represents an XML object and implements a java.sql.SQLXML.
*/
-
final class SQLServerSQLXML implements java.sql.SQLXML {
// Connection that created this SQLXML only set when created for setting data
private final SQLServerConnection con;
@@ -75,14 +73,19 @@ final class SQLServerSQLXML implements java.sql.SQLXML {
private String strValue;
// End of setter values
- static private final AtomicInteger baseID = new AtomicInteger(0); // Unique id generator for each instance (used for logging).
+ static private final AtomicInteger baseID = new AtomicInteger(0); // Unique id generator for each instance (used for
+ // logging).
final private String traceID;
final public String toString() {
return traceID;
}
- // Returns unique id for each instance.
+ /**
+ * Returns unique id for each instance.
+ *
+ * @return
+ */
private static int nextInstanceID() {
return baseID.incrementAndGet();
}
@@ -92,18 +95,19 @@ private static int nextInstanceID() {
// possible optimization transform DOM straight to tds
InputStream getValue() throws SQLServerException {
checkClosed();
- // the user should have called one of the setter methods, the setter methods "use" the object and write some value.
+ // the user should have called one of the setter methods, the setter methods "use" the object and write some
+ // value.
// Note just calling one of the setters is enough.
if (!isUsed)
- SQLServerException.makeFromDriverError(con, null, SQLServerException.getErrString("R_noDataXML"), null, true);
+ SQLServerException.makeFromDriverError(con, null, SQLServerException.getErrString("R_noDataXML"), null,
+ true);
assert null == contents;
ByteArrayInputStream o = null;
if (null != outputStreamValue) {
o = outputStreamValue.getInputStream();
assert null == docValue;
assert null == strValue;
- }
- else if (null != docValue) {
+ } else if (null != docValue) {
assert null == outputStreamValue;
assert null == strValue;
ByteArrayOutputStreamToInputStream strm = new ByteArrayOutputStreamToInputStream();
@@ -112,15 +116,13 @@ else if (null != docValue) {
try {
factory = TransformerFactory.newInstance();
factory.newTransformer().transform(new DOMSource(docValue), new StreamResult(strm));
- }
- catch (javax.xml.transform.TransformerException e) {
+ } catch (javax.xml.transform.TransformerException e) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_noParserSupport"));
Object[] msgArgs = {e.toString()};
SQLServerException.makeFromDriverError(con, null, form.format(msgArgs), null, true);
}
o = strm.getInputStream();
- }
- else {
+ } else {
assert null == outputStreamValue;
assert null == docValue;
assert null != strValue;
@@ -143,9 +145,7 @@ else if (null != docValue) {
typeInfo = null;
}
- SQLServerSQLXML(InputStream stream,
- InputStreamGetterArgs getterArgs,
- TypeInfo typeInfo) throws SQLServerException {
+ SQLServerSQLXML(InputStream stream, InputStreamGetterArgs getterArgs, TypeInfo typeInfo) throws SQLServerException {
traceID = " SQLServerSQLXML:" + nextInstanceID();
contents = (PLPXMLInputStream) stream;
this.con = null;
@@ -158,7 +158,7 @@ else if (null != docValue) {
InputStream getStream() {
return contents;
}
-
+
@Override
public void free() throws SQLException {
if (!isFreed) {
@@ -166,8 +166,7 @@ public void free() throws SQLException {
if (null != contents) {
try {
contents.close();
- }
- catch (IOException e) {
+ } catch (IOException e) {
SQLServerException.makeFromDriverError(null, null, e.getMessage(), null, true);
}
}
@@ -183,13 +182,14 @@ private void checkClosed() throws SQLServerException {
private void checkReadXML() throws SQLException {
if (null == contents)
- SQLServerException.makeFromDriverError(con, null, SQLServerException.getErrString("R_writeOnlyXML"), null, true);
+ SQLServerException.makeFromDriverError(con, null, SQLServerException.getErrString("R_writeOnlyXML"), null,
+ true);
if (isUsed)
- SQLServerException.makeFromDriverError(con, null, SQLServerException.getErrString("R_dataHasBeenReadXML"), null, true);
+ SQLServerException.makeFromDriverError(con, null, SQLServerException.getErrString("R_dataHasBeenReadXML"),
+ null, true);
try {
contents.checkClosed();
- }
- catch (IOException e) {
+ } catch (IOException e) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_isFreed"));
SQLServerException.makeFromDriverError(con, null, form.format(new Object[] {"SQLXML"}), null, true);
}
@@ -197,17 +197,19 @@ private void checkReadXML() throws SQLException {
void checkWriteXML() throws SQLException {
if (null != contents)
- SQLServerException.makeFromDriverError(con, null, SQLServerException.getErrString("R_readOnlyXML"), null, true);
+ SQLServerException.makeFromDriverError(con, null, SQLServerException.getErrString("R_readOnlyXML"), null,
+ true);
if (isUsed)
- SQLServerException.makeFromDriverError(con, null, SQLServerException.getErrString("R_dataHasBeenSetXML"), null, true);
+ SQLServerException.makeFromDriverError(con, null, SQLServerException.getErrString("R_dataHasBeenSetXML"),
+ null, true);
}
/**
- * Return an input stream to read data from this SQLXML
+ * Returns an input stream to read data from this SQLXML.
*
* @throws SQLException
- * when an error occurs
+ * when an error occurs
* @return the input stream to that contains the SQLXML data
*/
@Override
@@ -219,11 +221,11 @@ public InputStream getBinaryStream() throws SQLException {
}
/**
- * Retrieves a stream that can be used to write to the SQLXML value that this SQLXML object represents The user has to write the BOM for binary
- * streams.
+ * Sets a stream that can be used to write to the SQLXML value that this SQLXML object represents The user has to
+ * write the BOM for binary streams.
*
* @throws SQLException
- * when an error occurs
+ * when an error occurs
* @return OutputStream
*/
@Override
@@ -250,15 +252,15 @@ public Reader getCharacterStream() throws SQLException {
checkReadXML();
isUsed = true;
StreamType type = StreamType.CHARACTER;
- InputStreamGetterArgs newArgs = new InputStreamGetterArgs(type, getterArgs.isAdaptive, getterArgs.isStreaming, getterArgs.logContext);
+ InputStreamGetterArgs newArgs = new InputStreamGetterArgs(type, getterArgs.isAdaptive, getterArgs.isStreaming,
+ getterArgs.logContext);
// Skip the BOM bytes from the plpinputstream we do not need it for the conversion
assert null != contents;
// Read two bytes to eat BOM
try {
contents.read();
contents.read();
- }
- catch (IOException e) {
+ } catch (IOException e) {
SQLServerException.makeFromDriverError(null, null, e.getMessage(), null, true);
}
@@ -276,8 +278,7 @@ public String getString() throws SQLException {
try {
contents.read();
contents.read();
- }
- catch (IOException e) {
+ } catch (IOException e) {
SQLServerException.makeFromDriverError(null, null, e.getMessage(), null, true);
}
@@ -291,7 +292,8 @@ public void setString(String value) throws SQLException {
checkWriteXML();
isUsed = true;
if (null == value)
- SQLServerException.makeFromDriverError(con, null, SQLServerException.getErrString("R_cantSetNull"), null, true);
+ SQLServerException.makeFromDriverError(con, null, SQLServerException.getErrString("R_cantSetNull"), null,
+ true);
strValue = value;
}
// Support the following DOMSource, SAXSource, StAX and Stream. Also, null means default which is stream source
@@ -306,8 +308,7 @@ public T getSource(Class iface) throws SQLException {
@SuppressWarnings("unchecked")
T src = (T) getSourceInternal(StreamSource.class);
return src;
- }
- else
+ } else
return getSourceInternal(iface);
}
@@ -316,19 +317,16 @@ T getSourceInternal(Class iface) throws SQLException {
T src = null;
if (DOMSource.class == iface) {
src = iface.cast(getDOMSource());
- }
- else if (SAXSource.class == iface) {
+ } else if (SAXSource.class == iface) {
src = iface.cast(getSAXSource());
- }
- else if (StAXSource.class == iface) {
+ } else if (StAXSource.class == iface) {
src = iface.cast(getStAXSource());
- }
- else if (StreamSource.class == iface) {
+ } else if (StreamSource.class == iface) {
src = iface.cast(new StreamSource(contents));
- }
- else
+ } else
// Do not support this type
- SQLServerException.makeFromDriverError(con, null, SQLServerException.getErrString("R_notSupported"), null, true);
+ SQLServerException.makeFromDriverError(con, null, SQLServerException.getErrString("R_notSupported"), null,
+ true);
return src;
}
@@ -342,8 +340,7 @@ public T setResult(Class resultClass) throws SQLException
@SuppressWarnings("unchecked")
T result = (T) setResultInternal(StreamResult.class);
return result;
- }
- else
+ } else
return setResultInternal(resultClass);
}
@@ -353,19 +350,16 @@ T setResultInternal(Class resultClass) throws SQLException
T result = null;
if (DOMResult.class == resultClass) {
result = resultClass.cast(getDOMResult());
- }
- else if (SAXResult.class == resultClass) {
+ } else if (SAXResult.class == resultClass) {
result = resultClass.cast(getSAXResult());
- }
- else if (StAXResult.class == resultClass) {
+ } else if (StAXResult.class == resultClass) {
result = resultClass.cast(getStAXResult());
- }
- else if (StreamResult.class == resultClass) {
+ } else if (StreamResult.class == resultClass) {
outputStreamValue = new ByteArrayOutputStreamToInputStream();
result = resultClass.cast(new StreamResult(outputStreamValue));
- }
- else
- SQLServerException.makeFromDriverError(con, null, SQLServerException.getErrString("R_notSupported"), null, true);
+ } else
+ SQLServerException.makeFromDriverError(con, null, SQLServerException.getErrString("R_notSupported"), null,
+ true);
return result;
}
@@ -388,8 +382,7 @@ private DOMSource getDOMSource() throws SQLException {
builder.setEntityResolver(new SQLServerEntityResolver());
try {
document = builder.parse(contents);
- }
- catch (IOException e) {
+ } catch (IOException e) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_errorReadingStream"));
Object[] msgArgs = {e.toString()};
SQLServerException.makeFromDriverError(null, null, form.format(msgArgs), "", true);
@@ -397,13 +390,11 @@ private DOMSource getDOMSource() throws SQLException {
DOMSource inputSource = new DOMSource(document);
return inputSource;
- }
- catch (ParserConfigurationException e) {
+ } catch (ParserConfigurationException e) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_noParserSupport"));
Object[] msgArgs = {e.toString()};
SQLServerException.makeFromDriverError(con, null, form.format(msgArgs), null, true);
- }
- catch (SAXException e) {
+ } catch (SAXException e) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_failedToParseXML"));
Object[] msgArgs = {e.toString()};
SQLServerException.makeFromDriverError(con, null, form.format(msgArgs), null, true);
@@ -420,8 +411,7 @@ private SAXSource getSAXSource() throws SQLException {
SAXSource saxSource = new SAXSource(reader, src);
return saxSource;
- }
- catch (SAXException | ParserConfigurationException e) {
+ } catch (SAXException | ParserConfigurationException e) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_failedToParseXML"));
Object[] msgArgs = {e.toString()};
SQLServerException.makeFromDriverError(con, null, form.format(msgArgs), null, true);
@@ -436,8 +426,7 @@ private StAXSource getStAXSource() throws SQLException {
StAXSource result = new StAXSource(r);
return result;
- }
- catch (XMLStreamException e) {
+ } catch (XMLStreamException e) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_noParserSupport"));
Object[] msgArgs = {e.toString()};
SQLServerException.makeFromDriverError(con, null, form.format(msgArgs), null, true);
@@ -453,8 +442,7 @@ private StAXResult getStAXResult() throws SQLException {
StAXResult result = new StAXResult(r);
return result;
- }
- catch (XMLStreamException e) {
+ } catch (XMLStreamException e) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_noParserSupport"));
Object[] msgArgs = {e.toString()};
SQLServerException.makeFromDriverError(con, null, form.format(msgArgs), null, true);
@@ -467,13 +455,11 @@ private SAXResult getSAXResult() throws SQLException {
try {
SAXTransformerFactory stf = (SAXTransformerFactory) TransformerFactory.newInstance();
handler = stf.newTransformerHandler();
- }
- catch (TransformerConfigurationException e) {
+ } catch (TransformerConfigurationException e) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_noParserSupport"));
Object[] msgArgs = {e.toString()};
SQLServerException.makeFromDriverError(con, null, form.format(msgArgs), null, true);
- }
- catch (ClassCastException e) {
+ } catch (ClassCastException e) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_noParserSupport"));
Object[] msgArgs = {e.toString()};
SQLServerException.makeFromDriverError(con, null, form.format(msgArgs), null, true);
@@ -494,8 +480,7 @@ private DOMResult getDOMResult() throws SQLException {
DOMResult result = new DOMResult(docValue);
return result;
- }
- catch (ParserConfigurationException e) {
+ } catch (ParserConfigurationException e) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_noParserSupport"));
Object[] msgArgs = {e.toString()};
SQLServerException.makeFromDriverError(con, null, form.format(msgArgs), null, true);
@@ -505,8 +490,10 @@ private DOMResult getDOMResult() throws SQLException {
}
-// We use this class to convert the byte information we have in the string to
-// an inputstream which is used when sending to the info to the server
+
+/**
+ * Converts the byte information in the string to an inputstream which is used when sending to the info to the server.
+ */
final class ByteArrayOutputStreamToInputStream extends ByteArrayOutputStream {
ByteArrayInputStream getInputStream() throws SQLServerException {
ByteArrayInputStream is = new ByteArrayInputStream(buf, 0, count);
@@ -514,10 +501,13 @@ ByteArrayInputStream getInputStream() throws SQLServerException {
}
}
-// Resolves External entities in an XML with inline DTDs to empty string
+
+/**
+ * Resolves External entities in an XML with inline DTDs to empty string.
+ *
+ */
final class SQLServerEntityResolver implements EntityResolver {
- public InputSource resolveEntity(String publicId,
- String systemId) {
+ public InputSource resolveEntity(String publicId, String systemId) {
return new InputSource(new StringReader(""));
}
}
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerSavepoint.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerSavepoint.java
index 0d10816f5..94679be97 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerSavepoint.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerSavepoint.java
@@ -1,21 +1,19 @@
/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc;
import java.text.MessageFormat;
+
/**
- * SQLServerSavepoint implements JDBC 3.0 savepoints. A savepoint is checkpoint to which a transaction can be rolled back. Savepoints are defined
- * relative to a connection.
+ * Provides an implementation of JDBC Interface java.sql.Savepoint. A savepoint is checkpoint to which a transaction can
+ * be rolled back. Savepoints are defined relative to a connection.
*
- * The API javadoc for JDBC API methods that this class implements are not repeated here. Please see Sun's JDBC API interfaces javadoc for those
- * details.
+ * The API javadoc for JDBC API methods that this class implements are not repeated here. Please see Sun's JDBC API
+ * interfaces javadoc for those details.
*/
public final class SQLServerSavepoint implements ISQLServerSavepoint {
@@ -24,21 +22,19 @@ public final class SQLServerSavepoint implements ISQLServerSavepoint {
private final SQLServerConnection con;
/**
- * Create a new savepoint
+ * Constructs a SQLServerSavepoint.
*
* @param con
- * the connection
+ * the connection
* @param sName
- * the savepoint name
+ * the savepoint name
*/
- public SQLServerSavepoint(SQLServerConnection con,
- String sName) {
+ public SQLServerSavepoint(SQLServerConnection con, String sName) {
this.con = con;
if (sName == null) {
nId = con.getNextSavepointId();
this.sName = null;
- }
- else {
+ } else {
this.sName = sName;
nId = 0;
}
@@ -47,7 +43,8 @@ public SQLServerSavepoint(SQLServerConnection con,
@Override
public String getSavepointName() throws SQLServerException {
if (sName == null)
- SQLServerException.makeFromDriverError(con, null, SQLServerException.getErrString("R_savepointNotNamed"), null, false);
+ SQLServerException.makeFromDriverError(con, null, SQLServerException.getErrString("R_savepointNotNamed"),
+ null, false);
return sName;
}
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerSecurityUtility.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerSecurityUtility.java
index a54c8a6aa..45fa6c87b 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerSecurityUtility.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerSecurityUtility.java
@@ -1,198 +1,192 @@
-/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
- */
-
-package com.microsoft.sqlserver.jdbc;
-
-import java.security.InvalidKeyException;
-import java.security.NoSuchAlgorithmException;
-import java.util.Iterator;
-
-import javax.crypto.Mac;
-import javax.crypto.spec.SecretKeySpec;
-
-/**
- * Various SQLServer security utilities.
- *
- */
-class SQLServerSecurityUtility {
-
- /**
- * Give the hash of given plain text
- *
- * @param plainText
- * @param key
- * @param length
- * @return hash of the plain text using provided key
- * @throws NoSuchAlgorithmException
- * @throws InvalidKeyException
- */
- static byte[] getHMACWithSHA256(byte[] plainText,
- byte[] key,
- int length) throws NoSuchAlgorithmException, InvalidKeyException {
- byte[] computedHash;
- byte[] hash = new byte[length];
- Mac mac = Mac.getInstance("HmacSHA256");
- SecretKeySpec ivkeySpec = new SecretKeySpec(key, "HmacSHA256");
- mac.init(ivkeySpec);
- computedHash = mac.doFinal(plainText);
- // truncating hash if needed
- System.arraycopy(computedHash, 0, hash, 0, hash.length);
- return hash;
- }
-
- /**
- * Compare two arrays
- *
- * @param buffer1
- * first array
- * @param buffer2
- * second array
- * @param buffer2Index
- * @param lengthToCompare
- * @return true if array contains same bytes otherwise false
- */
- static boolean compareBytes(byte[] buffer1,
- byte[] buffer2,
- int buffer2Index,
- int lengthToCompare) {
- if (null == buffer1 || null == buffer2) {
- return false;
- }
-
- if ((buffer2.length - buffer2Index) < lengthToCompare) {
- return false;
- }
-
- for (int index = 0; index < buffer1.length && index < lengthToCompare; ++index) {
- if (buffer1[index] != buffer2[buffer2Index + index]) {
- return false;
- }
- }
- return true;
-
- }
-
- /*
- * Encrypts the ciphertext.
- */
- static byte[] encryptWithKey(byte[] plainText,
- CryptoMetadata md,
- SQLServerConnection connection) throws SQLServerException {
- String serverName = connection.getTrustedServerNameAE();
- assert serverName != null : "Server name should npt be null in EncryptWithKey";
-
- // Initialize cipherAlgo if not already done.
- if (!md.IsAlgorithmInitialized()) {
- SQLServerSecurityUtility.decryptSymmetricKey(md, connection);
- }
-
- assert md.IsAlgorithmInitialized();
- byte[] cipherText = md.cipherAlgorithm.encryptData(plainText); // this call succeeds or throws.
- if (null == cipherText || 0 == cipherText.length) {
- throw new SQLServerException(null, SQLServerException.getErrString("R_NullCipherTextAE"), null, 0, false);
- }
- return cipherText;
- }
-
- /**
- * Return the algorithm name mapped to an Id
- *
- * @param cipherAlgorithmId
- * The cipher algorithm Id
- * @param cipherAlgorithmName
- * The cipher algorithm name
- * @return The cipher algorithm name
- */
- private static String ValidateAndGetEncryptionAlgorithmName(byte cipherAlgorithmId,
- String cipherAlgorithmName) throws SQLServerException {
- // Custom cipher algorithm not supported for CTP.
- if (TDS.AEAD_AES_256_CBC_HMAC_SHA256 != cipherAlgorithmId) {
- throw new SQLServerException(null, SQLServerException.getErrString("R_CustomCipherAlgorithmNotSupportedAE"), null, 0, false);
- }
- return SQLServerAeadAes256CbcHmac256Algorithm.algorithmName;
- }
-
- /**
- * Decrypts the symmetric key and saves it in metadata. In addition, initializes the SqlClientEncryptionAlgorithm for rapid decryption.
- *
- * @param md
- * The cipher metadata
- * @param connection
- * The connection
- */
- static void decryptSymmetricKey(CryptoMetadata md,
- SQLServerConnection connection) throws SQLServerException {
- assert null != md : "md should not be null in DecryptSymmetricKey.";
- assert null != md.cekTableEntry : "md.EncryptionInfo should not be null in DecryptSymmetricKey.";
- assert null != md.cekTableEntry.columnEncryptionKeyValues : "md.EncryptionInfo.ColumnEncryptionKeyValues should not be null in DecryptSymmetricKey.";
-
- SQLServerSymmetricKey symKey = null;
- EncryptionKeyInfo encryptionkeyInfoChosen = null;
- SQLServerSymmetricKeyCache cache = SQLServerSymmetricKeyCache.getInstance();
- Iterator it = md.cekTableEntry.columnEncryptionKeyValues.iterator();
- SQLServerException lastException = null;
- while (it.hasNext()) {
- EncryptionKeyInfo keyInfo = it.next();
- try {
- symKey = cache.getKey(keyInfo, connection);
- if (null != symKey) {
- encryptionkeyInfoChosen = keyInfo;
- break;
- }
- }
- catch (SQLServerException e) {
- lastException = e;
- }
- }
-
- if (null == symKey) {
- if (null != lastException) {
- throw lastException;
- }
- else {
- throw new SQLServerException(null, SQLServerException.getErrString("R_CEKDecryptionFailed"), null, 0, false);
- }
- }
-
- // Given the symmetric key instantiate a SqlClientEncryptionAlgorithm object and cache it in metadata.
- md.cipherAlgorithm = null;
- SQLServerEncryptionAlgorithm cipherAlgorithm = null;
- String algorithmName = ValidateAndGetEncryptionAlgorithmName(md.cipherAlgorithmId, md.cipherAlgorithmName); // may throw
- cipherAlgorithm = SQLServerEncryptionAlgorithmFactoryList.getInstance().getAlgorithm(symKey, md.encryptionType, algorithmName); // will
- // validate
- // algorithm
- // name and
- // type
- assert null != cipherAlgorithm : "Cipher algorithm cannot be null in DecryptSymmetricKey";
- md.cipherAlgorithm = cipherAlgorithm;
- md.encryptionKeyInfo = encryptionkeyInfoChosen;
- }
-
- /*
- * Decrypts the ciphertext.
- */
- static byte[] decryptWithKey(byte[] cipherText,
- CryptoMetadata md,
- SQLServerConnection connection) throws SQLServerException {
- String serverName = connection.getTrustedServerNameAE();
- assert null != serverName : "serverName should not be null in DecryptWithKey.";
-
- // Initialize cipherAlgo if not already done.
- if (!md.IsAlgorithmInitialized()) {
- SQLServerSecurityUtility.decryptSymmetricKey(md, connection);
- }
-
- assert md.IsAlgorithmInitialized() : "Decryption Algorithm is not initialized";
- byte[] plainText = md.cipherAlgorithm.decryptData(cipherText); // this call succeeds or throws.
- if (null == plainText) {
- throw new SQLServerException(null, SQLServerException.getErrString("R_PlainTextNullAE"), null, 0, false);
- }
-
- return plainText;
- }
-}
+/*
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ */
+
+package com.microsoft.sqlserver.jdbc;
+
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.util.Iterator;
+
+import javax.crypto.Mac;
+import javax.crypto.spec.SecretKeySpec;
+
+
+/**
+ * Various SQLServer security utilities.
+ *
+ */
+class SQLServerSecurityUtility {
+
+ /**
+ * Give the hash of given plain text
+ *
+ * @param plainText
+ * @param key
+ * @param length
+ * @return hash of the plain text using provided key
+ * @throws NoSuchAlgorithmException
+ * @throws InvalidKeyException
+ */
+ static byte[] getHMACWithSHA256(byte[] plainText, byte[] key,
+ int length) throws NoSuchAlgorithmException, InvalidKeyException {
+ byte[] computedHash;
+ byte[] hash = new byte[length];
+ Mac mac = Mac.getInstance("HmacSHA256");
+ SecretKeySpec ivkeySpec = new SecretKeySpec(key, "HmacSHA256");
+ mac.init(ivkeySpec);
+ computedHash = mac.doFinal(plainText);
+ // truncating hash if needed
+ System.arraycopy(computedHash, 0, hash, 0, hash.length);
+ return hash;
+ }
+
+ /**
+ * Compare two arrays
+ *
+ * @param buffer1
+ * first array
+ * @param buffer2
+ * second array
+ * @param buffer2Index
+ * @param lengthToCompare
+ * @return true if array contains same bytes otherwise false
+ */
+ static boolean compareBytes(byte[] buffer1, byte[] buffer2, int buffer2Index, int lengthToCompare) {
+ if (null == buffer1 || null == buffer2) {
+ return false;
+ }
+
+ if ((buffer2.length - buffer2Index) < lengthToCompare) {
+ return false;
+ }
+
+ for (int index = 0; index < buffer1.length && index < lengthToCompare; ++index) {
+ if (buffer1[index] != buffer2[buffer2Index + index]) {
+ return false;
+ }
+ }
+ return true;
+
+ }
+
+ /*
+ * Encrypts the ciphertext.
+ */
+ static byte[] encryptWithKey(byte[] plainText, CryptoMetadata md,
+ SQLServerConnection connection) throws SQLServerException {
+ String serverName = connection.getTrustedServerNameAE();
+ assert serverName != null : "Server name should npt be null in EncryptWithKey";
+
+ // Initialize cipherAlgo if not already done.
+ if (!md.IsAlgorithmInitialized()) {
+ SQLServerSecurityUtility.decryptSymmetricKey(md, connection);
+ }
+
+ assert md.IsAlgorithmInitialized();
+ byte[] cipherText = md.cipherAlgorithm.encryptData(plainText); // this call succeeds or throws.
+ if (null == cipherText || 0 == cipherText.length) {
+ throw new SQLServerException(null, SQLServerException.getErrString("R_NullCipherTextAE"), null, 0, false);
+ }
+ return cipherText;
+ }
+
+ /**
+ * Return the algorithm name mapped to an Id
+ *
+ * @param cipherAlgorithmId
+ * The cipher algorithm Id
+ * @param cipherAlgorithmName
+ * The cipher algorithm name
+ * @return The cipher algorithm name
+ */
+ private static String ValidateAndGetEncryptionAlgorithmName(byte cipherAlgorithmId,
+ String cipherAlgorithmName) throws SQLServerException {
+ // Custom cipher algorithm not supported for CTP.
+ if (TDS.AEAD_AES_256_CBC_HMAC_SHA256 != cipherAlgorithmId) {
+ throw new SQLServerException(null, SQLServerException.getErrString("R_CustomCipherAlgorithmNotSupportedAE"),
+ null, 0, false);
+ }
+ return SQLServerAeadAes256CbcHmac256Algorithm.algorithmName;
+ }
+
+ /**
+ * Decrypts the symmetric key and saves it in metadata. In addition, initializes the SqlClientEncryptionAlgorithm
+ * for rapid decryption.
+ *
+ * @param md
+ * The cipher metadata
+ * @param connection
+ * The connection
+ */
+ static void decryptSymmetricKey(CryptoMetadata md, SQLServerConnection connection) throws SQLServerException {
+ assert null != md : "md should not be null in DecryptSymmetricKey.";
+ assert null != md.cekTableEntry : "md.EncryptionInfo should not be null in DecryptSymmetricKey.";
+ assert null != md.cekTableEntry.columnEncryptionKeyValues : "md.EncryptionInfo.ColumnEncryptionKeyValues should not be null in DecryptSymmetricKey.";
+
+ SQLServerSymmetricKey symKey = null;
+ EncryptionKeyInfo encryptionkeyInfoChosen = null;
+ SQLServerSymmetricKeyCache cache = SQLServerSymmetricKeyCache.getInstance();
+ Iterator it = md.cekTableEntry.columnEncryptionKeyValues.iterator();
+ SQLServerException lastException = null;
+ while (it.hasNext()) {
+ EncryptionKeyInfo keyInfo = it.next();
+ try {
+ symKey = cache.getKey(keyInfo, connection);
+ if (null != symKey) {
+ encryptionkeyInfoChosen = keyInfo;
+ break;
+ }
+ } catch (SQLServerException e) {
+ lastException = e;
+ }
+ }
+
+ if (null == symKey) {
+ if (null != lastException) {
+ throw lastException;
+ } else {
+ throw new SQLServerException(null, SQLServerException.getErrString("R_CEKDecryptionFailed"), null, 0,
+ false);
+ }
+ }
+
+ // Given the symmetric key instantiate a SqlClientEncryptionAlgorithm object and cache it in metadata.
+ md.cipherAlgorithm = null;
+ SQLServerEncryptionAlgorithm cipherAlgorithm = null;
+ String algorithmName = ValidateAndGetEncryptionAlgorithmName(md.cipherAlgorithmId, md.cipherAlgorithmName); // may
+ // throw
+ cipherAlgorithm = SQLServerEncryptionAlgorithmFactoryList.getInstance().getAlgorithm(symKey, md.encryptionType,
+ algorithmName); // will
+ // validate
+ // algorithm
+ // name and
+ // type
+ assert null != cipherAlgorithm : "Cipher algorithm cannot be null in DecryptSymmetricKey";
+ md.cipherAlgorithm = cipherAlgorithm;
+ md.encryptionKeyInfo = encryptionkeyInfoChosen;
+ }
+
+ /*
+ * Decrypts the ciphertext.
+ */
+ static byte[] decryptWithKey(byte[] cipherText, CryptoMetadata md,
+ SQLServerConnection connection) throws SQLServerException {
+ String serverName = connection.getTrustedServerNameAE();
+ assert null != serverName : "serverName should not be null in DecryptWithKey.";
+
+ // Initialize cipherAlgo if not already done.
+ if (!md.IsAlgorithmInitialized()) {
+ SQLServerSecurityUtility.decryptSymmetricKey(md, connection);
+ }
+
+ assert md.IsAlgorithmInitialized() : "Decryption Algorithm is not initialized";
+ byte[] plainText = md.cipherAlgorithm.decryptData(cipherText); // this call succeeds or throws.
+ if (null == plainText) {
+ throw new SQLServerException(null, SQLServerException.getErrString("R_PlainTextNullAE"), null, 0, false);
+ }
+
+ return plainText;
+ }
+}
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerSortOrder.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerSortOrder.java
index 542912b76..8d724643d 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerSortOrder.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerSortOrder.java
@@ -1,26 +1,23 @@
-/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
- */
-
-package com.microsoft.sqlserver.jdbc;
-
-/**
- *
- * Specifies the sorting order
- *
- */
-public enum SQLServerSortOrder {
- Ascending (0),
- Descending (1),
- Unspecified (-1);
-
- final int value;
-
- SQLServerSortOrder(int sortOrderVal) {
- value = sortOrderVal;
- }
-}
+/*
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ */
+
+package com.microsoft.sqlserver.jdbc;
+
+/**
+ *
+ * Specifies the sorting order
+ *
+ */
+public enum SQLServerSortOrder {
+ Ascending(0),
+ Descending(1),
+ Unspecified(-1);
+
+ final int value;
+
+ SQLServerSortOrder(int sortOrderVal) {
+ value = sortOrderVal;
+ }
+}
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerSpatialDatatype.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerSpatialDatatype.java
index 4c75590c3..4d18fcc28 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerSpatialDatatype.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerSpatialDatatype.java
@@ -1,26 +1,29 @@
/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc;
import java.math.BigDecimal;
import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
+
+/**
+ * Abstract parent class for Spatial Datatypes that contains common functionalities.
+ */
+
abstract class SQLServerSpatialDatatype {
/** WKT = Well-Known-Text, WKB = Well-Knwon-Binary */
/**
- * As a general rule, the ~IndexEnd variables are non-inclusive (i.e. pointIndexEnd = 8 means the shape using it will only go up to the 7th index
- * of the array)
+ * As a general rule, the ~IndexEnd variables are non-inclusive (i.e. pointIndexEnd = 8 means the shape using it
+ * will only go up to the 7th index of the array)
*/
protected ByteBuffer buffer;
protected InternalSpatialDatatype internalType;
@@ -40,7 +43,8 @@ abstract class SQLServerSpatialDatatype {
protected int currentFigureIndex = 0;
protected int currentSegmentIndex = 0;
protected int currentShapeIndex = 0;
- protected double points[];
+ protected double xValues[];
+ protected double yValues[];
protected double zValues[];
protected double mValues[];
protected Figure figures[];
@@ -91,48 +95,144 @@ abstract class SQLServerSpatialDatatype {
* Serializes the Geogemetry/Geography instance to WKB.
*
* @param noZM
- * flag to indicate if Z and M coordinates should be included
+ * flag to indicate if Z and M coordinates should be included
*/
- protected abstract void serializeToWkb(boolean noZM);
+ protected void serializeToWkb(boolean noZM, SQLServerSpatialDatatype type) {
+ ByteBuffer buf = ByteBuffer.allocate(determineWkbCapacity());
+ createSerializationProperties();
+
+ buf.order(ByteOrder.LITTLE_ENDIAN);
+ buf.putInt(srid);
+ buf.put(version);
+ buf.put(serializationProperties);
+
+ if (!isSinglePoint && !isSingleLineSegment) {
+ buf.putInt(numberOfPoints);
+ }
+
+ if (type instanceof Geometry) {
+ for (int i = 0; i < numberOfPoints; i++) {
+ buf.putDouble(xValues[i]);
+ buf.putDouble(yValues[i]);
+ }
+ } else { // Geography
+ for (int i = 0; i < numberOfPoints; i++) {
+ buf.putDouble(yValues[i]);
+ buf.putDouble(xValues[i]);
+ }
+ }
+
+ if (!noZM) {
+ if (hasZvalues) {
+ for (int i = 0; i < numberOfPoints; i++) {
+ buf.putDouble(zValues[i]);
+ }
+ }
+
+ if (hasMvalues) {
+ for (int i = 0; i < numberOfPoints; i++) {
+ buf.putDouble(mValues[i]);
+ }
+ }
+ }
+
+ if (isSinglePoint || isSingleLineSegment) {
+ wkb = buf.array();
+ return;
+ }
+
+ buf.putInt(numberOfFigures);
+ for (int i = 0; i < numberOfFigures; i++) {
+ buf.put(figures[i].getFiguresAttribute());
+ buf.putInt(figures[i].getPointOffset());
+ }
+
+ buf.putInt(numberOfShapes);
+ for (int i = 0; i < numberOfShapes; i++) {
+ buf.putInt(shapes[i].getParentOffset());
+ buf.putInt(shapes[i].getFigureOffset());
+ buf.put(shapes[i].getOpenGISType());
+ }
+
+ if (version == 2 && null != segments) {
+ buf.putInt(numberOfSegments);
+ for (int i = 0; i < numberOfSegments; i++) {
+ buf.put(segments[i].getSegmentType());
+ }
+ }
+
+ if (noZM) {
+ wkbNoZM = buf.array();
+ } else {
+ wkb = buf.array();
+ }
+ }
/**
- * Deserialize the buffer (that contains WKB representation of Geometry/Geography data), and stores it into multiple corresponding data
- * structures.
+ * Deserializes the buffer (that contains WKB representation of Geometry/Geography data), and stores it into
+ * multiple corresponding data structures.
*
*/
- protected abstract void parseWkb();
+ protected void parseWkb(SQLServerSpatialDatatype type) throws SQLServerException {
+ srid = readInt();
+ version = readByte();
+ serializationProperties = readByte();
+
+ interpretSerializationPropBytes();
+ readNumberOfPoints();
+ readPoints(type);
+
+ if (hasZvalues) {
+ readZvalues();
+ }
+
+ if (hasMvalues) {
+ readMvalues();
+ }
+
+ if (!(isSinglePoint || isSingleLineSegment)) {
+ readNumberOfFigures();
+ readFigures();
+ readNumberOfShapes();
+ readShapes();
+ }
+
+ determineInternalType();
+
+ if (buffer.hasRemaining()) {
+ if (version == 2 && internalType.getTypeCode() != 8 && internalType.getTypeCode() != 11) {
+ readNumberOfSegments();
+ readSegments();
+ }
+ }
+ }
/**
- * Create the WKT representation of Geometry/Geography from the deserialized data.
+ * Constructs the WKT representation of Geometry/Geography from the deserialized data.
*
* @param sd
- * the Geometry/Geography instance.
+ * the Geometry/Geography instance.
* @param isd
- * internal spatial datatype object
+ * internal spatial datatype object
* @param pointIndexEnd
- * upper bound for reading points
+ * upper bound for reading points
* @param figureIndexEnd
- * upper bound for reading figures
+ * upper bound for reading figures
* @param segmentIndexEnd
- * upper bound for reading segments
+ * upper bound for reading segments
* @param shapeIndexEnd
- * upper bound for reading shapes
+ * upper bound for reading shapes
* @throws SQLServerException
- * if an exception occurs
+ * if an exception occurs
*/
- protected void constructWKT(SQLServerSpatialDatatype sd,
- InternalSpatialDatatype isd,
- int pointIndexEnd,
- int figureIndexEnd,
- int segmentIndexEnd,
- int shapeIndexEnd) throws SQLServerException {
- if (null == points || numberOfPoints == 0) {
+ protected void constructWKT(SQLServerSpatialDatatype sd, InternalSpatialDatatype isd, int pointIndexEnd,
+ int figureIndexEnd, int segmentIndexEnd, int shapeIndexEnd) throws SQLServerException {
+ if (numberOfPoints == 0) {
if (isd.getTypeCode() == 11) { // FULLGLOBE
if (sd instanceof Geometry) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_illegalTypeForGeometry"));
throw new SQLServerException(form.format(new Object[] {"Fullglobe"}), null, 0, null);
- }
- else {
+ } else {
appendToWKTBuffers("FULLGLOBE");
return;
}
@@ -141,8 +241,8 @@ protected void constructWKT(SQLServerSpatialDatatype sd,
if (isd.getTypeCode() == 7 && currentShapeIndex != shapeIndexEnd - 1) {
currentShapeIndex++;
appendToWKTBuffers(isd.getTypeName() + "(");
- constructWKT(this, InternalSpatialDatatype.valueOf(shapes[currentShapeIndex].getOpenGISType()), numberOfPoints, numberOfFigures,
- numberOfSegments, numberOfShapes);
+ constructWKT(this, InternalSpatialDatatype.valueOf(shapes[currentShapeIndex].getOpenGISType()),
+ numberOfPoints, numberOfFigures, numberOfSegments, numberOfShapes);
appendToWKTBuffers(")");
return;
}
@@ -181,8 +281,7 @@ protected void constructWKT(SQLServerSpatialDatatype sd,
constructCurvepolygonWKT(currentFigureIndex, figureIndexEnd, currentSegmentIndex, segmentIndexEnd);
break;
default:
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_illegalWKTposition"));
- throw new SQLServerException(form.format(new Object[] {currentWktPos}), null, 0, null);
+ throwIllegalWKTPosition();
}
appendToWKTBuffers(")");
@@ -192,19 +291,17 @@ protected void constructWKT(SQLServerSpatialDatatype sd,
* Parses WKT and populates the data structures of the Geometry/Geography instance.
*
* @param sd
- * the Geometry/Geography instance.
+ * the Geometry/Geography instance.
* @param startPos
- * The index to start from from the WKT.
+ * The index to start from from the WKT.
* @param parentShapeIndex
- * The index of the parent's Shape in the shapes array. Used to determine this shape's parent.
+ * The index of the parent's Shape in the shapes array. Used to determine this shape's parent.
* @param isGeoCollection
- * flag to indicate if this is part of a GeometryCollection.
+ * flag to indicate if this is part of a GeometryCollection.
* @throws SQLServerException
- * if an exception occurs
+ * if an exception occurs
*/
- protected void parseWKTForSerialization(SQLServerSpatialDatatype sd,
- int startPos,
- int parentShapeIndex,
+ protected void parseWKTForSerialization(SQLServerSpatialDatatype sd, int startPos, int parentShapeIndex,
boolean isGeoCollection) throws SQLServerException {
// after every iteration of this while loop, the currentWktPosition will be set to the
// end of the geometry/geography shape, except for the very first iteration of it.
@@ -215,8 +312,7 @@ protected void parseWKTForSerialization(SQLServerSpatialDatatype sd,
if (startPos != 0) {
if (wkt.charAt(currentWktPos) == ')') {
return;
- }
- else if (wkt.charAt(currentWktPos) == ',') {
+ } else if (wkt.charAt(currentWktPos) == ',') {
currentWktPos++;
}
}
@@ -226,14 +322,13 @@ else if (wkt.charAt(currentWktPos) == ',') {
InternalSpatialDatatype isd = InternalSpatialDatatype.INVALID_TYPE;
try {
isd = InternalSpatialDatatype.valueOf(nextToken);
- }
- catch (Exception e) {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_illegalWKTposition"));
- throw new SQLServerException(form.format(new Object[] {currentWktPos}), null, 0, null);
+ } catch (Exception e) {
+ throwIllegalWKTPosition();
}
byte fa = 0;
- if (version == 1 && (nextToken.equals("CIRCULARSTRING") || nextToken.equals("COMPOUNDCURVE") || nextToken.equals("CURVEPOLYGON"))) {
+ if (version == 1 && (nextToken.equals("CIRCULARSTRING") || nextToken.equals("COMPOUNDCURVE")
+ || nextToken.equals("CURVEPOLYGON"))) {
version = 2;
}
@@ -245,8 +340,7 @@ else if (wkt.charAt(currentWktPos) == ',') {
}
if (startPos != 0) {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_illegalWKTposition"));
- throw new SQLServerException(form.format(new Object[] {currentWktPos}), null, 0, null);
+ throwIllegalWKTPosition();
}
shapeList.add(new Shape(parentShapeIndex, -1, isd.getTypeCode()));
@@ -266,6 +360,7 @@ else if (wkt.charAt(currentWktPos) == ',') {
case "POINT":
if (startPos == 0 && nextToken.toUpperCase().equals("POINT")) {
isSinglePoint = true;
+ internalType = InternalSpatialDatatype.POINT;
}
if (isGeoCollection) {
@@ -278,7 +373,8 @@ else if (wkt.charAt(currentWktPos) == ',') {
case "LINESTRING":
case "CIRCULARSTRING":
shapeList.add(new Shape(parentShapeIndex, figureList.size(), isd.getTypeCode()));
- fa = isd.getTypeCode() == InternalSpatialDatatype.LINESTRING.getTypeCode() ? FA_STROKE : FA_EXTERIOR_RING;
+ fa = isd.getTypeCode() == InternalSpatialDatatype.LINESTRING.getTypeCode() ? FA_STROKE
+ : FA_EXTERIOR_RING;
figureList.add(new Figure(fa, pointList.size()));
readLineWkt();
@@ -324,8 +420,7 @@ else if (wkt.charAt(currentWktPos) == ',') {
break;
default:
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_illegalWKTposition"));
- throw new SQLServerException(form.format(new Object[] {currentWktPos}), null, 0, null);
+ throwIllegalWKTPosition();
}
readCloseBracket();
}
@@ -334,53 +429,47 @@ else if (wkt.charAt(currentWktPos) == ',') {
}
/**
- * Constructs and appends a Point type in WKT form to the stringbuffer. There are two stringbuffers - WKTsb and WKTsbNoZM. WKTsb contains the X,
- * Y, Z and M coordinates, whereas WKTsbNoZM contains only X and Y coordinates.
+ * Constructs and appends a Point type in WKT form to the stringbuffer. There are two stringbuffers - WKTsb and
+ * WKTsbNoZM. WKTsb contains the X, Y, Z and M coordinates, whereas WKTsbNoZM contains only X and Y coordinates.
*
* @param pointIndex
- * indicates which point to append to the stringbuffer.
+ * indicates which point to append to the stringbuffer.
*
*/
protected void constructPointWKT(int pointIndex) {
- int firstPointIndex = pointIndex * 2;
- int secondPointIndex = firstPointIndex + 1;
- int zValueIndex = pointIndex;
- int mValueIndex = pointIndex;
-
- if (points[firstPointIndex] % 1 == 0) {
- appendToWKTBuffers((int) points[firstPointIndex]);
- }
- else {
- appendToWKTBuffers(points[firstPointIndex]);
+ if (xValues[pointIndex] % 1 == 0) {
+ appendToWKTBuffers((int) xValues[pointIndex]);
+ } else {
+ appendToWKTBuffers(xValues[pointIndex]);
}
appendToWKTBuffers(" ");
- if (points[secondPointIndex] % 1 == 0) {
- appendToWKTBuffers((int) points[secondPointIndex]);
- }
- else {
- appendToWKTBuffers(points[secondPointIndex]);
+ if (yValues[pointIndex] % 1 == 0) {
+ appendToWKTBuffers((int) yValues[pointIndex]);
+ } else {
+ appendToWKTBuffers(yValues[pointIndex]);
}
appendToWKTBuffers(" ");
- if (hasZvalues && !Double.isNaN(zValues[zValueIndex]) && !(zValues[zValueIndex] == 0)) {
- if (zValues[zValueIndex] % 1 == 0) {
- WKTsb.append((int) zValues[zValueIndex]);
- }
- else {
- WKTsb.append(zValues[zValueIndex]);
+ if (hasZvalues && !Double.isNaN(zValues[pointIndex])) {
+ if (zValues[pointIndex] % 1 == 0) {
+ WKTsb.append((long) zValues[pointIndex]);
+ } else {
+ WKTsb.append(zValues[pointIndex]);
}
WKTsb.append(" ");
+ } else if (hasMvalues && !Double.isNaN(mValues[pointIndex])) {
+ // Handle the case where the user has POINT (1 2 NULL M) value.
+ WKTsb.append("NULL ");
+ }
- if (hasMvalues && !Double.isNaN(mValues[mValueIndex]) && !(mValues[mValueIndex] <= 0)) {
- if (mValues[mValueIndex] % 1 == 0) {
- WKTsb.append((int) mValues[mValueIndex]);
- }
- else {
- WKTsb.append(mValues[mValueIndex]);
- }
- WKTsb.append(" ");
+ if (hasMvalues && !Double.isNaN(mValues[pointIndex])) {
+ if (mValues[pointIndex] % 1 == 0) {
+ WKTsb.append((long) mValues[pointIndex]);
+ } else {
+ WKTsb.append(mValues[pointIndex]);
}
+ WKTsb.append(" ");
}
currentPointIndex++;
@@ -393,12 +482,11 @@ protected void constructPointWKT(int pointIndex) {
* Constructs a line in WKT form.
*
* @param pointStartIndex
- * .
+ * .
* @param pointEndIndex
- * .
+ * .
*/
- protected void constructLineWKT(int pointStartIndex,
- int pointEndIndex) {
+ protected void constructLineWKT(int pointStartIndex, int pointEndIndex) {
for (int i = pointStartIndex; i < pointEndIndex; i++) {
constructPointWKT(i);
@@ -413,25 +501,22 @@ protected void constructLineWKT(int pointStartIndex,
* Constructs a shape (simple Geometry/Geography entities that are contained within a single bracket) in WKT form.
*
* @param figureStartIndex
- * .
+ * .
* @param figureEndIndex
- * .
+ * .
*/
- protected void constructShapeWKT(int figureStartIndex,
- int figureEndIndex) {
+ protected void constructShapeWKT(int figureStartIndex, int figureEndIndex) {
for (int i = figureStartIndex; i < figureEndIndex; i++) {
appendToWKTBuffers("(");
if (i != numberOfFigures - 1) { // not the last figure
constructLineWKT(figures[i].getPointOffset(), figures[i + 1].getPointOffset());
- }
- else {
+ } else {
constructLineWKT(figures[i].getPointOffset(), numberOfPoints);
}
if (i != figureEndIndex - 1) {
appendToWKTBuffers("), ");
- }
- else {
+ } else {
appendToWKTBuffers(")");
}
}
@@ -441,17 +526,15 @@ protected void constructShapeWKT(int figureStartIndex,
* Constructs a mutli-shape (MultiPoint / MultiLineString) in WKT form.
*
* @param shapeStartIndex
- * .
+ * .
* @param shapeEndIndex
- * .
+ * .
*/
- protected void constructMultiShapeWKT(int shapeStartIndex,
- int shapeEndIndex) {
+ protected void constructMultiShapeWKT(int shapeStartIndex, int shapeEndIndex) {
for (int i = shapeStartIndex + 1; i < shapeEndIndex; i++) {
if (shapes[i].getFigureOffset() == -1) { // EMPTY
appendToWKTBuffers("EMPTY");
- }
- else {
+ } else {
constructShapeWKT(shapes[i].getFigureOffset(), shapes[i].getFigureOffset() + 1);
}
if (i != shapeEndIndex - 1) {
@@ -464,15 +547,13 @@ protected void constructMultiShapeWKT(int shapeStartIndex,
* Constructs a CompoundCurve in WKT form.
*
* @param segmentStartIndex
- * .
+ * .
* @param segmentEndIndex
- * .
+ * .
* @param pointEndIndex
- * .
+ * .
*/
- protected void constructCompoundcurveWKT(int segmentStartIndex,
- int segmentEndIndex,
- int pointEndIndex) {
+ protected void constructCompoundcurveWKT(int segmentStartIndex, int segmentEndIndex, int pointEndIndex) {
for (int i = segmentStartIndex; i < segmentEndIndex; i++) {
byte segment = segments[i].getSegmentType();
constructSegmentWKT(i, segment, pointEndIndex);
@@ -505,12 +586,11 @@ protected void constructCompoundcurveWKT(int segmentStartIndex,
* Constructs a MultiPolygon in WKT form.
*
* @param shapeStartIndex
- * .
+ * .
* @param shapeEndIndex
- * .
+ * .
*/
- protected void constructMultipolygonWKT(int shapeStartIndex,
- int shapeEndIndex) {
+ protected void constructMultipolygonWKT(int shapeStartIndex, int shapeEndIndex) {
int figureStartIndex;
int figureEndIndex;
@@ -526,8 +606,7 @@ protected void constructMultipolygonWKT(int shapeStartIndex,
figureStartIndex = shapes[i].getFigureOffset();
if (i == shapes.length - 1) { // last shape
figureEndIndex = figures.length;
- }
- else {
+ } else {
// look ahead and find the next shape that doesn't have -1 as its figure offset (which signifies EMPTY)
int tempCurrentShapeIndex = i + 1;
// We need to iterate this through until the very end of the shapes list, since if the last shape
@@ -536,8 +615,7 @@ protected void constructMultipolygonWKT(int shapeStartIndex,
if (shapes[tempCurrentShapeIndex].getFigureOffset() == -1) {
tempCurrentShapeIndex++;
continue;
- }
- else {
+ } else {
figureEndIndex = shapes[tempCurrentShapeIndex].getFigureOffset();
break;
}
@@ -551,15 +629,13 @@ protected void constructMultipolygonWKT(int shapeStartIndex,
if (j == figures.length - 1) { // last figure
constructLineWKT(figures[j].getPointOffset(), numberOfPoints);
- }
- else {
+ } else {
constructLineWKT(figures[j].getPointOffset(), figures[j + 1].getPointOffset());
}
if (j == figureEndIndex - 1) { // last polygon of this multipolygon, close off the Multipolygon
appendToWKTBuffers(")");
- }
- else { // not the last polygon, followed by an interior ring
+ } else { // not the last polygon, followed by an interior ring
appendToWKTBuffers("), ");
}
}
@@ -576,17 +652,15 @@ protected void constructMultipolygonWKT(int shapeStartIndex,
* Constructs a CurvePolygon in WKT form.
*
* @param figureStartIndex
- * .
+ * .
* @param figureEndIndex
- * .
+ * .
* @param segmentStartIndex
- * .
+ * .
* @param segmentEndIndex
- * .
+ * .
*/
- protected void constructCurvepolygonWKT(int figureStartIndex,
- int figureEndIndex,
- int segmentStartIndex,
+ protected void constructCurvepolygonWKT(int figureStartIndex, int figureEndIndex, int segmentStartIndex,
int segmentEndIndex) {
for (int i = figureStartIndex; i < figureEndIndex; i++) {
switch (figures[i].getFiguresAttribute()) {
@@ -595,8 +669,7 @@ protected void constructCurvepolygonWKT(int figureStartIndex,
if (i == figures.length - 1) {
constructLineWKT(currentPointIndex, numberOfPoints);
- }
- else {
+ } else {
constructLineWKT(currentPointIndex, figures[i + 1].getPointOffset());
}
@@ -607,8 +680,7 @@ protected void constructCurvepolygonWKT(int figureStartIndex,
if (i == figures.length - 1) {
constructLineWKT(currentPointIndex, numberOfPoints);
- }
- else {
+ } else {
constructLineWKT(currentPointIndex, figures[i + 1].getPointOffset());
}
@@ -622,8 +694,7 @@ protected void constructCurvepolygonWKT(int figureStartIndex,
if (i == figures.length - 1) {
pointEndIndex = numberOfPoints;
- }
- else {
+ } else {
pointEndIndex = figures[i + 1].getPointOffset();
}
@@ -633,8 +704,7 @@ protected void constructCurvepolygonWKT(int figureStartIndex,
if (!(currentPointIndex < pointEndIndex)) {
appendToWKTBuffers("))");
- }
- else {
+ } else {
switch (segment) {
case 0:
case 2:
@@ -669,21 +739,20 @@ protected void constructCurvepolygonWKT(int figureStartIndex,
}
/**
- * Constructs a Segment in WKT form. SQL Server re-uses the last point of a segment if the following segment is of type 3 (first arc) or type 2
- * (first line). This makes sense because the last point of a segment and the first point of the next segment have to match for a valid curve.
- * This means that the code has to look ahead and decide to decrement the currentPointIndex depending on what segment comes next, since it may
- * have been reused (and it's reflected in the array of points)
+ * Constructs a Segment in WKT form. SQL Server re-uses the last point of a segment if the following segment is of
+ * type 3 (first arc) or type 2 (first line). This makes sense because the last point of a segment and the first
+ * point of the next segment have to match for a valid curve. This means that the code has to look ahead and decide
+ * to decrement the currentPointIndex depending on what segment comes next, since it may have been reused (and it's
+ * reflected in the array of points)
*
* @param currentSegment
- * .
+ * .
* @param segment
- * .
+ * .
* @param pointEndIndex
- * .
+ * .
*/
- protected void constructSegmentWKT(int currentSegment,
- byte segment,
- int pointEndIndex) {
+ protected void constructSegmentWKT(int currentSegment, byte segment, int pointEndIndex) {
switch (segment) {
case 0:
appendToWKTBuffers(", ");
@@ -691,8 +760,8 @@ protected void constructSegmentWKT(int currentSegment,
if (currentSegment == segments.length - 1) { // last segment
break;
- }
- else if (segments[currentSegment + 1].getSegmentType() != 0) { // not being followed by another line, but not the last segment
+ } else if (segments[currentSegment + 1].getSegmentType() != 0) { // not being followed by another line,
+ // but not the last segment
currentPointIndex = currentPointIndex - 1;
incrementPointNumStartIfPointNotReused(pointEndIndex);
}
@@ -704,9 +773,10 @@ else if (segments[currentSegment + 1].getSegmentType() != 0) { // not being foll
if (currentSegment == segments.length - 1) { // last segment
break;
- }
- else if (segments[currentSegment + 1].getSegmentType() != 1) { // not being followed by another arc, but not the last segment
- currentPointIndex = currentPointIndex - 1; // only increment pointNumStart by one less than what we should be, since the last
+ } else if (segments[currentSegment + 1].getSegmentType() != 1) { // not being followed by another arc,
+ // but not the last segment
+ currentPointIndex = currentPointIndex - 1; // only increment pointNumStart by one less than what we
+ // should be, since the last
// point will be reused
incrementPointNumStartIfPointNotReused(pointEndIndex);
}
@@ -718,9 +788,10 @@ else if (segments[currentSegment + 1].getSegmentType() != 1) { // not being foll
if (currentSegment == segments.length - 1) { // last segment
break;
- }
- else if (segments[currentSegment + 1].getSegmentType() != 0) { // not being followed by another line, but not the last segment
- currentPointIndex = currentPointIndex - 1; // only increment pointNumStart by one less than what we should be, since the last
+ } else if (segments[currentSegment + 1].getSegmentType() != 0) { // not being followed by another line,
+ // but not the last segment
+ currentPointIndex = currentPointIndex - 1; // only increment pointNumStart by one less than what we
+ // should be, since the last
// point will be reused
incrementPointNumStartIfPointNotReused(pointEndIndex);
}
@@ -732,9 +803,9 @@ else if (segments[currentSegment + 1].getSegmentType() != 0) { // not being foll
if (currentSegment == segments.length - 1) { // last segment
break;
- }
- else if (segments[currentSegment + 1].getSegmentType() != 1) { // not being followed by another arc
- currentPointIndex = currentPointIndex - 1; // only increment pointNumStart by one less than what we should be, since the last
+ } else if (segments[currentSegment + 1].getSegmentType() != 1) { // not being followed by another arc
+ currentPointIndex = currentPointIndex - 1; // only increment pointNumStart by one less than what we
+ // should be, since the last
// point will be reused
incrementPointNumStartIfPointNotReused(pointEndIndex);
}
@@ -749,9 +820,9 @@ else if (segments[currentSegment + 1].getSegmentType() != 1) { // not being foll
* The starting point for constructing a GeometryCollection type in WKT form.
*
* @param shapeEndIndex
- * .
+ * .
* @throws SQLServerException
- * if an exception occurs
+ * if an exception occurs
*/
protected void constructGeometryCollectionWKT(int shapeEndIndex) throws SQLServerException {
currentShapeIndex++;
@@ -759,16 +830,19 @@ protected void constructGeometryCollectionWKT(int shapeEndIndex) throws SQLServe
}
/**
- * Reads Point WKT and adds it to the list of points. This method will read up until and including the comma that may come at the end of the Point
- * WKT.
+ * Reads Point WKT and adds it to the list of points. This method will read up until and including the comma that
+ * may come at the end of the Point WKT.
*
* @throws SQLServerException
- * if an exception occurs
+ * if an exception occurs
*/
protected void readPointWkt() throws SQLServerException {
int numOfCoordinates = 0;
double sign;
double coords[] = new double[4];
+ for (int i = 0; i < coords.length; i++) {
+ coords[i] = Double.NaN;
+ }
while (numOfCoordinates < 4) {
sign = 1;
@@ -783,17 +857,30 @@ protected void readPointWkt() throws SQLServerException {
break;
}
- while (currentWktPos < wkt.length() && (Character.isDigit(wkt.charAt(currentWktPos)) || wkt.charAt(currentWktPos) == '.'
- || wkt.charAt(currentWktPos) == 'E' || wkt.charAt(currentWktPos) == 'e')) {
+ while (currentWktPos < wkt.length()
+ && (Character.isDigit(wkt.charAt(currentWktPos)) || wkt.charAt(currentWktPos) == '.'
+ || wkt.charAt(currentWktPos) == 'E' || wkt.charAt(currentWktPos) == 'e')) {
currentWktPos++;
}
try {
coords[numOfCoordinates] = sign * new BigDecimal(wkt.substring(startPos, currentWktPos)).doubleValue();
- }
- catch (Exception e) { // modify to conversion exception
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_illegalWKTposition"));
- throw new SQLServerException(form.format(new Object[] {currentWktPos}), null, 0, null);
+
+ if (numOfCoordinates == 2) {
+ hasZvalues = true;
+ } else if (numOfCoordinates == 3) {
+ hasMvalues = true;
+ }
+ } catch (Exception e) { // modify to conversion exception
+ // handle NULL case
+ // the first check ensures that there is enough space for the wkt to have NULL
+ if (wkt.length() > currentWktPos + 3
+ && wkt.substring(currentWktPos, currentWktPos + 4).equalsIgnoreCase("null")) {
+ coords[numOfCoordinates] = Double.NaN;
+ currentWktPos = currentWktPos + 4;
+ } else {
+ throwIllegalWKTPosition();
+ }
}
numOfCoordinates++;
@@ -803,17 +890,16 @@ protected void readPointWkt() throws SQLServerException {
// After skipping white space after the 4th coordinate has been read, the next
// character has to be either a , or ), or the WKT is invalid.
if (numOfCoordinates == 4) {
- if (wkt.charAt(currentWktPos) != ',' && wkt.charAt(currentWktPos) != ')') {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_illegalWKTposition"));
- throw new SQLServerException(form.format(new Object[] {currentWktPos}), null, 0, null);
+ if (checkSQLLength(currentWktPos + 1) && wkt.charAt(currentWktPos) != ','
+ && wkt.charAt(currentWktPos) != ')') {
+ throwIllegalWKTPosition();
}
}
- if (wkt.charAt(currentWktPos) == ',') {
+ if (checkSQLLength(currentWktPos + 1) && wkt.charAt(currentWktPos) == ',') {
// need at least 2 coordinates
if (numOfCoordinates == 1) {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_illegalWKTposition"));
- throw new SQLServerException(form.format(new Object[] {currentWktPos}), null, 0, null);
+ throwIllegalWKTPosition();
}
currentWktPos++;
skipWhiteSpaces();
@@ -822,14 +908,6 @@ protected void readPointWkt() throws SQLServerException {
skipWhiteSpaces();
}
- if (numOfCoordinates == 4) {
- hasZvalues = true;
- hasMvalues = true;
- }
- else if (numOfCoordinates == 3) {
- hasZvalues = true;
- }
-
pointList.add(new Point(coords[0], coords[1], coords[2], coords[3]));
}
@@ -837,7 +915,7 @@ else if (numOfCoordinates == 3) {
* Reads a series of Point types.
*
* @throws SQLServerException
- * if an exception occurs
+ * if an exception occurs
*/
protected void readLineWkt() throws SQLServerException {
while (currentWktPos < wkt.length() && wkt.charAt(currentWktPos) != ')') {
@@ -849,40 +927,39 @@ protected void readLineWkt() throws SQLServerException {
* Reads a shape (simple Geometry/Geography entities that are contained within a single bracket) WKT.
*
* @param parentShapeIndex
- * shape index of the parent shape that called this method
+ * shape index of the parent shape that called this method
* @param nextToken
- * next string token
+ * next string token
* @throws SQLServerException
- * if an exception occurs
+ * if an exception occurs
*/
- protected void readShapeWkt(int parentShapeIndex,
- String nextToken) throws SQLServerException {
+ protected void readShapeWkt(int parentShapeIndex, String nextToken) throws SQLServerException {
byte fa = FA_POINT;
while (currentWktPos < wkt.length() && wkt.charAt(currentWktPos) != ')') {
// if next keyword is empty, continue the loop.
// Do not check this for polygon.
- if (!nextToken.equals("POLYGON") && checkEmptyKeyword(parentShapeIndex, InternalSpatialDatatype.valueOf(nextToken), true)) {
+ if (!nextToken.equals("POLYGON")
+ && checkEmptyKeyword(parentShapeIndex, InternalSpatialDatatype.valueOf(nextToken), true)) {
continue;
}
if (nextToken.equals("MULTIPOINT")) {
- shapeList.add(new Shape(parentShapeIndex, figureList.size(), InternalSpatialDatatype.POINT.getTypeCode()));
- }
- else if (nextToken.equals("MULTILINESTRING")) {
- shapeList.add(new Shape(parentShapeIndex, figureList.size(), InternalSpatialDatatype.LINESTRING.getTypeCode()));
+ shapeList.add(
+ new Shape(parentShapeIndex, figureList.size(), InternalSpatialDatatype.POINT.getTypeCode()));
+ } else if (nextToken.equals("MULTILINESTRING")) {
+ shapeList.add(new Shape(parentShapeIndex, figureList.size(),
+ InternalSpatialDatatype.LINESTRING.getTypeCode()));
}
if (version == 1) {
if (nextToken.equals("MULTIPOINT")) {
fa = FA_STROKE;
- }
- else if (nextToken.equals("MULTILINESTRING") || nextToken.equals("POLYGON")) {
+ } else if (nextToken.equals("MULTILINESTRING") || nextToken.equals("POLYGON")) {
fa = FA_EXTERIOR_RING;
}
version_one_shape_indexes.add(figureList.size());
- }
- else if (version == 2) {
+ } else if (version == 2) {
if (nextToken.equals("MULTIPOINT") || nextToken.equals("MULTILINESTRING") || nextToken.equals("POLYGON")
|| nextToken.equals("MULTIPOLYGON")) {
fa = FA_LINE;
@@ -896,24 +973,21 @@ else if (version == 2) {
skipWhiteSpaces();
- if (wkt.charAt(currentWktPos) == ',') { // more rings to follow
+ if (checkSQLLength(currentWktPos + 1) && wkt.charAt(currentWktPos) == ',') { // more rings to follow
readComma();
- }
- else if (wkt.charAt(currentWktPos) == ')') { // about to exit while loop
+ } else if (wkt.charAt(currentWktPos) == ')') { // about to exit while loop
continue;
- }
- else { // unexpected input
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_illegalWKTposition"));
- throw new SQLServerException(form.format(new Object[] {currentWktPos}), null, 0, null);
+ } else { // unexpected input
+ throwIllegalWKTPosition();
}
}
}
/**
- * Reads a CurvePolygon WKT
+ * Reads a CurvePolygon WKT.
*
* @throws SQLServerException
- * if an exception occurs
+ * if an exception occurs
*/
protected void readCurvePolygon() throws SQLServerException {
while (currentWktPos < wkt.length() && wkt.charAt(currentWktPos) != ')') {
@@ -923,83 +997,72 @@ protected void readCurvePolygon() throws SQLServerException {
readOpenBracket();
readLineWkt();
readCloseBracket();
- }
- else if (nextPotentialToken.equals("COMPOUNDCURVE")) {
+ } else if (nextPotentialToken.equals("COMPOUNDCURVE")) {
figureList.add(new Figure(FA_COMPOSITE_CURVE, pointList.size()));
readOpenBracket();
readCompoundCurveWkt(true);
readCloseBracket();
- }
- else if (wkt.charAt(currentWktPos) == '(') { // LineString
+ } else if (wkt.charAt(currentWktPos) == '(') { // LineString
figureList.add(new Figure(FA_LINE, pointList.size()));
readOpenBracket();
readLineWkt();
readCloseBracket();
- }
- else {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_illegalWKTposition"));
- throw new SQLServerException(form.format(new Object[] {currentWktPos}), null, 0, null);
+ } else {
+ throwIllegalWKTPosition();
}
- if (wkt.charAt(currentWktPos) == ',') { // more polygons to follow
+ if (checkSQLLength(currentWktPos + 1) && wkt.charAt(currentWktPos) == ',') { // more polygons to follow
readComma();
- }
- else if (wkt.charAt(currentWktPos) == ')') { // about to exit while loop
+ } else if (wkt.charAt(currentWktPos) == ')') { // about to exit while loop
continue;
- }
- else { // unexpected input
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_illegalWKTposition"));
- throw new SQLServerException(form.format(new Object[] {currentWktPos}), null, 0, null);
+ } else { // unexpected input
+ throwIllegalWKTPosition();
}
}
}
/**
- * Reads a MultiPolygon WKT
+ * Reads a MultiPolygon WKT.
*
* @param thisShapeIndex
- * shape index of current shape
+ * shape index of current shape
* @param nextToken
- * next string token
+ * next string token
* @throws SQLServerException
- * if an exception occurs
+ * if an exception occurs
*/
- protected void readMultiPolygonWkt(int thisShapeIndex,
- String nextToken) throws SQLServerException {
+ protected void readMultiPolygonWkt(int thisShapeIndex, String nextToken) throws SQLServerException {
while (currentWktPos < wkt.length() && wkt.charAt(currentWktPos) != ')') {
if (checkEmptyKeyword(thisShapeIndex, InternalSpatialDatatype.valueOf(nextToken), true)) {
continue;
}
- shapeList.add(new Shape(thisShapeIndex, figureList.size(), InternalSpatialDatatype.POLYGON.getTypeCode())); // exterior polygon
+ shapeList.add(new Shape(thisShapeIndex, figureList.size(), InternalSpatialDatatype.POLYGON.getTypeCode())); // exterior
+ // polygon
readOpenBracket();
readShapeWkt(thisShapeIndex, nextToken);
readCloseBracket();
- if (wkt.charAt(currentWktPos) == ',') { // more polygons to follow
+ if (checkSQLLength(currentWktPos + 1) && wkt.charAt(currentWktPos) == ',') { // more polygons to follow
readComma();
- }
- else if (wkt.charAt(currentWktPos) == ')') { // about to exit while loop
+ } else if (wkt.charAt(currentWktPos) == ')') { // about to exit while loop
continue;
- }
- else { // unexpected input
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_illegalWKTposition"));
- throw new SQLServerException(form.format(new Object[] {currentWktPos}), null, 0, null);
+ } else { // unexpected input
+ throwIllegalWKTPosition();
}
}
}
/**
- * Reads a Segment WKT
+ * Reads a Segment WKT.
*
* @param segmentType
- * segment type
+ * segment type
* @param isFirstIteration
- * flag that indicates if this is the first iteration from the loop outside
+ * flag that indicates if this is the first iteration from the loop outside
* @throws SQLServerException
- * if an exception occurs
+ * if an exception occurs
*/
- protected void readSegmentWkt(int segmentType,
- boolean isFirstIteration) throws SQLServerException {
+ protected void readSegmentWkt(int segmentType, boolean isFirstIteration) throws SQLServerException {
segmentList.add(new Segment((byte) segmentType));
int segmentLength = segmentType;
@@ -1010,12 +1073,12 @@ protected void readSegmentWkt(int segmentType,
}
for (int i = 0; i < segmentLength; i++) {
- // If a segment type of 2 (first line) or 3 (first arc) is not from the very first iteration of the while loop,
+ // If a segment type of 2 (first line) or 3 (first arc) is not from the very first iteration of the while
+ // loop,
// then the first point has to be a duplicate point from the previous segment, so skip the first point.
if (i == 0 && !isFirstIteration && segmentType >= 2) {
skipFirstPointWkt();
- }
- else {
+ } else {
readPointWkt();
}
}
@@ -1023,20 +1086,19 @@ protected void readSegmentWkt(int segmentType,
if (currentWktPos < wkt.length() && wkt.charAt(currentWktPos) != ')') {
if (segmentType == SEGMENT_FIRST_ARC || segmentType == SEGMENT_ARC) {
readSegmentWkt(SEGMENT_ARC, false);
- }
- else if (segmentType == SEGMENT_FIRST_LINE | segmentType == SEGMENT_LINE) {
+ } else if (segmentType == SEGMENT_FIRST_LINE | segmentType == SEGMENT_LINE) {
readSegmentWkt(SEGMENT_LINE, false);
}
}
}
/**
- * Reads a CompoundCurve WKT
+ * Reads a CompoundCurve WKT.
*
* @param isFirstIteration
- * flag that indicates if this is the first iteration from the loop outside
+ * flag that indicates if this is the first iteration from the loop outside
* @throws SQLServerException
- * if an exception occurs
+ * if an exception occurs
*/
protected void readCompoundCurveWkt(boolean isFirstIteration) throws SQLServerException {
while (currentWktPos < wkt.length() && wkt.charAt(currentWktPos) != ')') {
@@ -1045,34 +1107,29 @@ protected void readCompoundCurveWkt(boolean isFirstIteration) throws SQLServerEx
readOpenBracket();
readSegmentWkt(SEGMENT_FIRST_ARC, isFirstIteration);
readCloseBracket();
- }
- else if (wkt.charAt(currentWktPos) == '(') {// LineString
+ } else if (wkt.charAt(currentWktPos) == '(') {// LineString
readOpenBracket();
readSegmentWkt(SEGMENT_FIRST_LINE, isFirstIteration);
readCloseBracket();
- }
- else {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_illegalWKTposition"));
- throw new SQLServerException(form.format(new Object[] {currentWktPos}), null, 0, null);
+ } else {
+ throwIllegalWKTPosition();
}
isFirstIteration = false;
- if (wkt.charAt(currentWktPos) == ',') { // more polygons to follow
+ if (checkSQLLength(currentWktPos + 1) && wkt.charAt(currentWktPos) == ',') { // more polygons to follow
readComma();
- }
- else if (wkt.charAt(currentWktPos) == ')') { // about to exit while loop
+ } else if (wkt.charAt(currentWktPos) == ')') { // about to exit while loop
continue;
- }
- else { // unexpected input
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_illegalWKTposition"));
- throw new SQLServerException(form.format(new Object[] {currentWktPos}), null, 0, null);
+ } else { // unexpected input
+ throwIllegalWKTPosition();
}
}
}
/**
- * Reads the next string token (usually POINT, LINESTRING, etc.). Then increments currentWktPos to the end of the string token.
+ * Reads the next string token (usually POINT, LINESTRING, etc.). Then increments currentWktPos to the end of the
+ * string token.
*
* @return the next string token
*/
@@ -1090,15 +1147,16 @@ protected String getNextStringToken() {
}
/**
- * Populates the various data structures contained within the Geometry/Geography instace.
+ * Populates the various data structures contained within the Geometry/Geography instance.
*/
protected void populateStructures() {
if (pointList.size() > 0) {
- points = new double[pointList.size() * 2];
+ xValues = new double[pointList.size()];
+ yValues = new double[pointList.size()];
for (int i = 0; i < pointList.size(); i++) {
- points[i * 2] = pointList.get(i).getX();
- points[i * 2 + 1] = pointList.get(i).getY();
+ xValues[i] = pointList.get(i).getX();
+ yValues[i] = pointList.get(i).getY();
}
if (hasZvalues) {
@@ -1134,7 +1192,8 @@ protected void populateStructures() {
}
// There is an edge case of empty GeometryCollections being inside other GeometryCollections. In this case,
- // the figure offset of the very first shape (GeometryCollections) has to be -1, but this is not possible to know until
+ // the figure offset of the very first shape (GeometryCollections) has to be -1, but this is not possible to
+ // know until
// We've parsed through the entire WKT and confirmed that there are 0 points.
// Therefore, if so, we make the figure offset of the first shape to be -1.
if (pointList.size() == 0 && shapeList.size() > 0 && shapeList.get(0).getOpenGISType() == 7) {
@@ -1168,10 +1227,8 @@ protected void readOpenBracket() throws SQLServerException {
if (wkt.charAt(currentWktPos) == '(') {
currentWktPos++;
skipWhiteSpaces();
- }
- else {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_illegalWKTposition"));
- throw new SQLServerException(form.format(new Object[] {currentWktPos}), null, 0, null);
+ } else {
+ throwIllegalWKTPosition();
}
}
@@ -1180,10 +1237,8 @@ protected void readCloseBracket() throws SQLServerException {
if (wkt.charAt(currentWktPos) == ')') {
currentWktPos++;
skipWhiteSpaces();
- }
- else {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_illegalWKTposition"));
- throw new SQLServerException(form.format(new Object[] {currentWktPos}), null, 0, null);
+ } else {
+ throwIllegalWKTPosition();
}
}
@@ -1266,7 +1321,7 @@ protected int determineWkbCapacity() {
* Append the data to both stringbuffers.
*
* @param o
- * data to append to the stringbuffers.
+ * data to append to the stringbuffers.
*/
protected void appendToWKTBuffers(Object o) {
WKTsb.append(o);
@@ -1282,73 +1337,75 @@ protected void interpretSerializationPropBytes() {
isLargerThanHemisphere = (serializationProperties & isLargerThanHemisphereMask) != 0;
}
- protected void readNumberOfPoints() {
+ protected void readNumberOfPoints() throws SQLServerException {
if (isSinglePoint) {
numberOfPoints = 1;
- }
- else if (isSingleLineSegment) {
+ } else if (isSingleLineSegment) {
numberOfPoints = 2;
- }
- else {
- numberOfPoints = buffer.getInt();
+ } else {
+ numberOfPoints = readInt();
+ checkNegSize(numberOfPoints);
}
}
- protected void readZvalues() {
+ protected void readZvalues() throws SQLServerException {
zValues = new double[numberOfPoints];
for (int i = 0; i < numberOfPoints; i++) {
- zValues[i] = buffer.getDouble();
+ zValues[i] = readDouble();
}
}
- protected void readMvalues() {
+ protected void readMvalues() throws SQLServerException {
mValues = new double[numberOfPoints];
for (int i = 0; i < numberOfPoints; i++) {
- mValues[i] = buffer.getDouble();
+ mValues[i] = readDouble();
}
}
- protected void readNumberOfFigures() {
- numberOfFigures = buffer.getInt();
+ protected void readNumberOfFigures() throws SQLServerException {
+ numberOfFigures = readInt();
+ checkNegSize(numberOfFigures);
}
- protected void readFigures() {
+ protected void readFigures() throws SQLServerException {
byte fa;
int po;
figures = new Figure[numberOfFigures];
for (int i = 0; i < numberOfFigures; i++) {
- fa = buffer.get();
- po = buffer.getInt();
+ fa = readByte();
+ po = readInt();
figures[i] = new Figure(fa, po);
}
}
- protected void readNumberOfShapes() {
- numberOfShapes = buffer.getInt();
+ protected void readNumberOfShapes() throws SQLServerException {
+ numberOfShapes = readInt();
+ checkNegSize(numberOfShapes);
}
- protected void readShapes() {
+ protected void readShapes() throws SQLServerException {
int po;
int fo;
byte ogt;
shapes = new Shape[numberOfShapes];
for (int i = 0; i < numberOfShapes; i++) {
- po = buffer.getInt();
- fo = buffer.getInt();
- ogt = buffer.get();
+ po = readInt();
+ fo = readInt();
+ ogt = readByte();
shapes[i] = new Shape(po, fo, ogt);
}
}
- protected void readNumberOfSegments() {
- numberOfSegments = buffer.getInt();
+ protected void readNumberOfSegments() throws SQLServerException {
+ numberOfSegments = readInt();
+ checkNegSize(numberOfSegments);
}
- protected void readSegments() {
+ protected void readSegments() throws SQLServerException {
byte st;
segments = new Segment[numberOfSegments];
for (int i = 0; i < numberOfSegments; i++) {
- st = buffer.get();
+ st = readByte();
segments[i] = new Segment(st);
}
}
@@ -1356,17 +1413,14 @@ protected void readSegments() {
protected void determineInternalType() {
if (isSinglePoint) {
internalType = InternalSpatialDatatype.POINT;
- }
- else if (isSingleLineSegment) {
+ } else if (isSingleLineSegment) {
internalType = InternalSpatialDatatype.LINESTRING;
- }
- else {
+ } else {
internalType = InternalSpatialDatatype.valueOf(shapes[0].getOpenGISType());
}
}
- protected boolean checkEmptyKeyword(int parentShapeIndex,
- InternalSpatialDatatype isd,
+ protected boolean checkEmptyKeyword(int parentShapeIndex, InternalSpatialDatatype isd,
boolean isInsideAnotherShape) throws SQLServerException {
String potentialEmptyKeyword = getNextStringToken().toUpperCase(Locale.US);
if (potentialEmptyKeyword.equals("EMPTY")) {
@@ -1377,22 +1431,17 @@ protected boolean checkEmptyKeyword(int parentShapeIndex,
byte parentTypeCode = isd.getTypeCode();
if (parentTypeCode == 4) { // MultiPoint
typeCode = InternalSpatialDatatype.POINT.getTypeCode();
- }
- else if (parentTypeCode == 5) { // MultiLineString
+ } else if (parentTypeCode == 5) { // MultiLineString
typeCode = InternalSpatialDatatype.LINESTRING.getTypeCode();
- }
- else if (parentTypeCode == 6) { // MultiPolygon
+ } else if (parentTypeCode == 6) { // MultiPolygon
typeCode = InternalSpatialDatatype.POLYGON.getTypeCode();
- }
- else if (parentTypeCode == 7) { // GeometryCollection
+ } else if (parentTypeCode == 7) { // GeometryCollection
typeCode = InternalSpatialDatatype.GEOMETRYCOLLECTION.getTypeCode();
- }
- else {
+ } else {
String strError = SQLServerException.getErrString("R_illegalWKT");
throw new SQLServerException(strError, null, 0, null);
}
- }
- else {
+ } else {
typeCode = isd.getTypeCode();
}
@@ -1406,12 +1455,22 @@ else if (parentTypeCode == 7) { // GeometryCollection
}
if (!potentialEmptyKeyword.equals("")) {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_illegalWKTposition"));
- throw new SQLServerException(form.format(new Object[] {currentWktPos}), null, 0, null);
+ throwIllegalWKTPosition();
}
return false;
}
+ protected void throwIllegalWKT() throws SQLServerException {
+ String strError = SQLServerException.getErrString("R_illegalWKT");
+ throw new SQLServerException(strError, null, 0, null);
+ }
+
+ protected void throwIllegalWKB() throws SQLServerException {
+ MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_ParsingError"));
+ Object[] msgArgs = {JDBCType.VARBINARY};
+ throw new SQLServerException(this, form.format(msgArgs), null, 0, false);
+ }
+
private void incrementPointNumStartIfPointNotReused(int pointEndIndex) {
// We need to increment PointNumStart if the last point was actually not re-used in the points array.
// 0 for pointNumEnd indicates that this check is not applicable.
@@ -1424,9 +1483,9 @@ private void incrementPointNumStartIfPointNotReused(int pointEndIndex) {
* Helper used for resurcive iteration for constructing GeometryCollection in WKT form.
*
* @param shapeEndIndex
- * .
+ * .
* @throws SQLServerException
- * if an exception occurs
+ * if an exception occurs
*/
private void constructGeometryCollectionWKThelper(int shapeEndIndex) throws SQLServerException {
// phase 1: assume that there is no multi - stuff and no geometrycollection
@@ -1477,12 +1536,12 @@ private void constructGeometryCollectionWKThelper(int shapeEndIndex) throws SQLS
int pointOffsetEnd;
if (i == figures.length - 1) {
pointOffsetEnd = numberOfPoints;
- }
- else {
+ } else {
pointOffsetEnd = figures[i + 1].getPointOffset();
}
- int increment = calculateSegmentIncrement(localCurrentSegmentIndex, pointOffsetEnd - figures[i].getPointOffset());
+ int increment = calculateSegmentIncrement(localCurrentSegmentIndex,
+ pointOffsetEnd - figures[i].getPointOffset());
segmentIndexIncrement = segmentIndexIncrement + increment;
localCurrentSegmentIndex = localCurrentSegmentIndex + increment;
@@ -1509,8 +1568,10 @@ private void constructGeometryCollectionWKThelper(int shapeEndIndex) throws SQLS
// Increment shapeStartIndex to account for the shape index that either Multipoint, MultiLineString
// or MultiPolygon takes up
tempShapeIndex++;
- while (tempShapeIndex < shapes.length && shapes[tempShapeIndex].getParentOffset() != thisShapesParentOffset) {
- if (!(tempShapeIndex == shapes.length - 1) && // last iteration, don't check for shapes[tempShapeIndex + 1]
+ while (tempShapeIndex < shapes.length
+ && shapes[tempShapeIndex].getParentOffset() != thisShapesParentOffset) {
+ if (!(tempShapeIndex == shapes.length - 1) && // last iteration, don't check for
+ // shapes[tempShapeIndex + 1]
!(shapes[tempShapeIndex + 1].getFigureOffset() == -1)) { // disregard EMPTY cases
figureIndexEnd = shapes[tempShapeIndex + 1].getFigureOffset();
}
@@ -1554,8 +1615,7 @@ private void constructGeometryCollectionWKThelper(int shapeEndIndex) throws SQLS
if (currentShapeIndex < shapeEndIndex) {
appendToWKTBuffers("), ");
- }
- else {
+ } else {
appendToWKTBuffers(")");
}
@@ -1563,12 +1623,12 @@ private void constructGeometryCollectionWKThelper(int shapeEndIndex) throws SQLS
case COMPOUNDCURVE:
if (currentFigureIndex == figures.length - 1) {
pointIndexEnd = numberOfPoints;
- }
- else {
+ } else {
pointIndexEnd = figures[currentFigureIndex + 1].getPointOffset();
}
- int increment = calculateSegmentIncrement(currentSegmentIndex, pointIndexEnd - figures[currentFigureIndex].getPointOffset());
+ int increment = calculateSegmentIncrement(currentSegmentIndex,
+ pointIndexEnd - figures[currentFigureIndex].getPointOffset());
segmentIndexIncrement = increment;
segmentIndexEnd = currentSegmentIndex + increment;
@@ -1594,17 +1654,17 @@ private void constructGeometryCollectionWKThelper(int shapeEndIndex) throws SQLS
}
/**
- * Calculates how many segments will be used by this shape. Needed to determine when the shape that uses segments (e.g. CompoundCurve) needs to
- * stop reading in cases where the CompoundCurve is included as part of GeometryCollection.
+ * Calculates how many segments will be used by this shape. Needed to determine when the shape that uses segments
+ * (e.g. CompoundCurve) needs to stop reading in cases where the CompoundCurve is included as part of
+ * GeometryCollection.
*
* @param segmentStart
- * .
+ * .
* @param pointDifference
- * number of points that were assigned to this segment to be used.
+ * number of points that were assigned to this segment to be used.
* @return the number of segments that will be used by this shape.
*/
- private int calculateSegmentIncrement(int segmentStart,
- int pointDifference) {
+ private int calculateSegmentIncrement(int segmentStart, int pointDifference) {
int segmentIncrement = 0;
@@ -1615,8 +1675,7 @@ private int calculateSegmentIncrement(int segmentStart,
if (segmentStart == segments.length - 1 || pointDifference < 1) { // last segment
break;
- }
- else if (segments[segmentStart + 1].getSegmentType() != 0) { // one point will be reused
+ } else if (segments[segmentStart + 1].getSegmentType() != 0) { // one point will be reused
pointDifference = pointDifference + 1;
}
break;
@@ -1625,8 +1684,7 @@ else if (segments[segmentStart + 1].getSegmentType() != 0) { // one point will b
if (segmentStart == segments.length - 1 || pointDifference < 1) { // last segment
break;
- }
- else if (segments[segmentStart + 1].getSegmentType() != 1) { // one point will be reused
+ } else if (segments[segmentStart + 1].getSegmentType() != 1) { // one point will be reused
pointDifference = pointDifference + 1;
}
break;
@@ -1635,8 +1693,7 @@ else if (segments[segmentStart + 1].getSegmentType() != 1) { // one point will b
if (segmentStart == segments.length - 1 || pointDifference < 1) { // last segment
break;
- }
- else if (segments[segmentStart + 1].getSegmentType() != 0) { // one point will be reused
+ } else if (segments[segmentStart + 1].getSegmentType() != 0) { // one point will be reused
pointDifference = pointDifference + 1;
}
break;
@@ -1645,8 +1702,7 @@ else if (segments[segmentStart + 1].getSegmentType() != 0) { // one point will b
if (segmentStart == segments.length - 1 || pointDifference < 1) { // last segment
break;
- }
- else if (segments[segmentStart + 1].getSegmentType() != 1) { // one point will be reused
+ } else if (segments[segmentStart + 1].getSegmentType() != 1) { // one point will be reused
pointDifference = pointDifference + 1;
}
break;
@@ -1672,8 +1728,9 @@ private void skipFirstPointWkt() {
break;
}
- while (currentWktPos < wkt.length() && (Character.isDigit(wkt.charAt(currentWktPos)) || wkt.charAt(currentWktPos) == '.'
- || wkt.charAt(currentWktPos) == 'E' || wkt.charAt(currentWktPos) == 'e')) {
+ while (currentWktPos < wkt.length()
+ && (Character.isDigit(wkt.charAt(currentWktPos)) || wkt.charAt(currentWktPos) == '.'
+ || wkt.charAt(currentWktPos) == 'E' || wkt.charAt(currentWktPos) == 'e')) {
currentWktPos++;
}
@@ -1695,10 +1752,8 @@ private void readComma() throws SQLServerException {
if (wkt.charAt(currentWktPos) == ',') {
currentWktPos++;
skipWhiteSpaces();
- }
- else {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_illegalWKTposition"));
- throw new SQLServerException(form.format(new Object[] {currentWktPos}), null, 0, null);
+ } else {
+ throwIllegalWKTPosition();
}
}
@@ -1707,37 +1762,110 @@ private void skipWhiteSpaces() {
currentWktPos++;
}
}
+
+ private void checkNegSize(int num) throws SQLServerException {
+ if (num < 0) {
+ throwIllegalWKB();
+ }
+ }
+
+ private void readPoints(SQLServerSpatialDatatype type) throws SQLServerException {
+ xValues = new double[numberOfPoints];
+ yValues = new double[numberOfPoints];
+
+ if (type instanceof Geometry) {
+ for (int i = 0; i < numberOfPoints; i++) {
+ xValues[i] = readDouble();
+ yValues[i] = readDouble();
+ }
+ } else { // Geography
+ for (int i = 0; i < numberOfPoints; i++) {
+ yValues[i] = readDouble();
+ xValues[i] = readDouble();
+ }
+ }
+ }
+
+ private void checkBuffer(int i) throws SQLServerException {
+ if (buffer.remaining() < i) {
+ throwIllegalWKB();
+ }
+ }
+
+ private boolean checkSQLLength(int length) throws SQLServerException {
+ if (null == wkt || wkt.length() < length) {
+ throwIllegalWKTPosition();
+ }
+ return true;
+ }
+
+ private void throwIllegalWKTPosition() throws SQLServerException {
+ MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_illegalWKTposition"));
+ throw new SQLServerException(form.format(new Object[] {currentWktPos}), null, 0, null);
+ }
+
+ protected byte readByte() throws SQLServerException {
+ checkBuffer(1);
+ return buffer.get();
+ }
+
+ protected int readInt() throws SQLServerException {
+ checkBuffer(4);
+ return buffer.getInt();
+ }
+
+ protected double readDouble() throws SQLServerException {
+ checkBuffer(8);
+ return buffer.getDouble();
+ }
}
+
/**
- * Class to hold and represent the internal makings of a Figure.
+ * Represents the internal makings of a Figure.
*
*/
class Figure {
private byte figuresAttribute;
private int pointOffset;
- Figure(byte figuresAttribute,
- int pointOffset) {
+ Figure(byte figuresAttribute, int pointOffset) {
this.figuresAttribute = figuresAttribute;
this.pointOffset = pointOffset;
}
+ /**
+ * Returns the figuresAttribute value.
+ *
+ * @return byte figuresAttribute value.
+ */
public byte getFiguresAttribute() {
return figuresAttribute;
}
+ /**
+ * Returns the pointOffset value.
+ *
+ * @return int pointOffset value.
+ */
public int getPointOffset() {
return pointOffset;
}
+ /**
+ * Sets the figuresAttribute value.
+ *
+ * @param fa
+ * figuresAttribute value.
+ */
public void setFiguresAttribute(byte fa) {
figuresAttribute = fa;
}
}
+
/**
- * Class to hold and represent the internal makings of a Shape.
+ * Represents the internal makings of a Shape.
*
*/
class Shape {
@@ -1745,34 +1873,54 @@ class Shape {
private int figureOffset;
private byte openGISType;
- Shape(int parentOffset,
- int figureOffset,
- byte openGISType) {
+ Shape(int parentOffset, int figureOffset, byte openGISType) {
this.parentOffset = parentOffset;
this.figureOffset = figureOffset;
this.openGISType = openGISType;
}
+ /**
+ * Returns the parentOffset value.
+ *
+ * @return int parentOffset value.
+ */
public int getParentOffset() {
return parentOffset;
}
+ /**
+ * Returns the figureOffset value.
+ *
+ * @return int figureOffset value.
+ */
public int getFigureOffset() {
return figureOffset;
}
+ /**
+ * Returns the openGISType value.
+ *
+ * @return byte openGISType value.
+ */
public byte getOpenGISType() {
return openGISType;
}
+ /**
+ * Sets the figureOffset value.
+ *
+ * @param fo
+ * figureOffset value.
+ */
public void setFigureOffset(int fo) {
figureOffset = fo;
}
}
+
/**
- * Class to hold and represent the internal makings of a Segment.
+ * Represents the internal makings of a Segment.
*
*/
class Segment {
@@ -1782,13 +1930,19 @@ class Segment {
this.segmentType = segmentType;
}
+ /**
+ * Returns the segmentType value.
+ *
+ * @return byte segmentType value.
+ */
public byte getSegmentType() {
return segmentType;
}
}
+
/**
- * Class to hold and represent the internal makings of a Point.
+ * Represents the internal makings of a Point.
*
*/
class Point {
@@ -1797,29 +1951,46 @@ class Point {
private final double z;
private final double m;
- Point(double x,
- double y,
- double z,
- double m) {
+ Point(double x, double y, double z, double m) {
this.x = x;
this.y = y;
this.z = z;
this.m = m;
}
+ /**
+ * Returns the x coordinate value.
+ *
+ * @return double x coordinate value.
+ */
public double getX() {
return x;
}
+ /**
+ * Returns the y coordinate value.
+ *
+ * @return double y coordinate value.
+ */
public double getY() {
return y;
}
+ /**
+ * Returns the z (elevation) value.
+ *
+ * @return double z value.
+ */
public double getZ() {
return z;
}
+ /**
+ * Returns the m (measure) value.
+ *
+ * @return double m value.
+ */
public double getM() {
return m;
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerStatement.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerStatement.java
index cd56a7b84..59fa8482b 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerStatement.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerStatement.java
@@ -1,9 +1,6 @@
/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc;
@@ -14,9 +11,9 @@
import java.sql.BatchUpdateException;
import java.sql.ResultSet;
import java.sql.SQLException;
+import java.sql.SQLTimeoutException;
import java.sql.SQLWarning;
import java.sql.Statement;
-import java.sql.SQLTimeoutException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.ListIterator;
@@ -28,27 +25,30 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import com.microsoft.sqlserver.jdbc.SQLServerConnection.Sha1HashKey;
+import com.microsoft.sqlserver.jdbc.SQLServerConnection.CityHash128Key;
+
/**
- * SQLServerStatment provides the basic implementation of JDBC statement functionality. It also provides a number of base class implementation methods
- * for the JDBC prepared statement and callable Statements. SQLServerStatement's basic role is to execute SQL statements and return update counts and
- * resultset rows to the user application.
+ * Provides an implementation of java.sql.Statement JDBC Interface to assist in creating Statements against SQL Server.
+ * It also provides a number of base class implementation methods for the JDBC prepared statement and callable
+ * Statements. SQLServerStatement's basic role is to execute SQL statements and return update counts and resultset rows
+ * to the user application.
*
- * Documentation for specific public methods that are undocumented can be found under Sun's standard JDBC documentation for class java.sql.Statement.
- * Those methods are part of Sun's standard JDBC documentation and therefore their documentation is not duplicated here.
+ * Documentation for specific public methods that are undocumented can be found under Sun's standard JDBC documentation
+ * for class java.sql.Statement. Those methods are part of Sun's standard JDBC documentation and therefore their
+ * documentation is not duplicated here.
*
* Implementation Notes
*
* Fetching Result sets
*
- * The queries first rowset is available immediately after the executeQuery. The first rs.next() does not make a server round trip. For non server
- * side resultsets the entire result set is in the rowset. For server side result sets the number of rows in the rowset is set with nFetchSize
+ * The queries first rowset is available immediately after the executeQuery. The first rs.next() does not make a server
+ * round trip. For non server side resultsets the entire result set is in the rowset. For server side result sets the
+ * number of rows in the rowset is set with nFetchSize
*
- * The API javadoc for JDBC API methods that this class implements are not repeated here. Please see Sun's JDBC API interfaces javadoc for those
- * details.
+ * The API javadoc for JDBC API methods that this class implements are not repeated here. Please see Sun's JDBC API
+ * interfaces javadoc for those details.
*/
-
public class SQLServerStatement implements ISQLServerStatement {
final static char LEFT_CURLY_BRACKET = 123;
final static char RIGHT_CURLY_BRACKET = 125;
@@ -103,7 +103,7 @@ final boolean wasExecuted() {
Parameter[] inOutParam; // Parameters for prepared stmts and stored procedures
/**
- * The statements connection.
+ * The statement's connection.
*/
final SQLServerConnection connection;
@@ -116,18 +116,19 @@ final boolean wasExecuted() {
* timeout value for canceling the query timeout
*/
int cancelQueryTimeoutSeconds;
-
+
/**
- * Is closeOnCompletion is enabled? If true statement will be closed when all of its dependent result sets are closed
+ * Is closeOnCompletion is enabled? If true statement will be closed when all of its dependent result sets are
+ * closed
*/
boolean isCloseOnCompletion = false;
/**
- * Currently executing or most recently executed TDSCommand (statement cmd, server cursor cmd, ...) subject to cancellation through
- * Statement.cancel.
+ * Currently executing or most recently executed TDSCommand (statement cmd, server cursor cmd, ...) subject to
+ * cancellation through Statement.cancel.
*
- * Note: currentCommand is declared volatile to ensure that the JVM always returns the most recently set value for currentCommand to the
- * cancelling thread.
+ * Note: currentCommand is declared volatile to ensure that the JVM always returns the most recently set value for
+ * currentCommand to the cancelling thread.
*/
private volatile TDSCommand currentCommand = null;
private TDSCommand lastStmtExecCmd = null;
@@ -140,7 +141,8 @@ final void discardLastExecutionResults() {
clearLastResult();
}
- static final java.util.logging.Logger loggerExternal = java.util.logging.Logger.getLogger("com.microsoft.sqlserver.jdbc.Statement");
+ static final java.util.logging.Logger loggerExternal = java.util.logging.Logger
+ .getLogger("com.microsoft.sqlserver.jdbc.Statement");
final private String loggingClassName;
final private String traceID;
@@ -149,16 +151,18 @@ String getClassNameLogging() {
}
/*
- * Column Encryption Override. Defaults to the connection setting, in which case it will be Enabled if columnEncryptionSetting = true in the
- * connection setting, Disabled if false. This may also be used to set other behavior which overrides connection level setting.
+ * Column Encryption Override. Defaults to the connection setting, in which case it will be Enabled if
+ * columnEncryptionSetting = true in the connection setting, Disabled if false. This may also be used to set other
+ * behavior which overrides connection level setting.
*/
protected SQLServerStatementColumnEncryptionSetting stmtColumnEncriptionSetting = SQLServerStatementColumnEncryptionSetting.UseConnectionSetting;
protected SQLServerStatementColumnEncryptionSetting getStmtColumnEncriptionSetting() {
return stmtColumnEncriptionSetting;
}
+
/**
- * ExecuteProperties encapsulates a subset of statement property values as they were set at execution time.
+ * Encapsulates a subset of statement property values as they were set at execution time.
*/
final class ExecuteProperties {
final private boolean wasResponseBufferingSet;
@@ -195,7 +199,8 @@ final ExecuteProperties getExecProps() {
/**
* Executes this Statement using TDSCommand newStmtCmd.
*
- * The TDSCommand is assumed to be a statement execution command (StmtExecCmd, PrepStmtExecCmd, PrepStmtBatchExecCmd).
+ * The TDSCommand is assumed to be a statement execution command (StmtExecCmd, PrepStmtExecCmd,
+ * PrepStmtBatchExecCmd).
*/
final void executeStatement(TDSCommand newStmtCmd) throws SQLServerException, SQLTimeoutException {
// Ensure that any response left over from a previous execution has been
@@ -212,26 +217,26 @@ final void executeStatement(TDSCommand newStmtCmd) throws SQLServerException, SQ
// (Re)execute this Statement with the new command
executeCommand(newStmtCmd);
} catch (SQLServerException e) {
- if (e.getDriverErrorCode() == SQLServerException.ERROR_QUERY_TIMEOUT)
- throw new SQLTimeoutException(e.getMessage(), e.getSQLState(), e.getErrorCode(), e.getCause());
- else
- throw e;
- }
- finally {
+ if (e.getDriverErrorCode() == SQLServerException.ERROR_QUERY_TIMEOUT)
+ throw new SQLTimeoutException(e.getMessage(), e.getSQLState(), e.getErrorCode(), e.getCause());
+ else
+ throw e;
+ } finally {
lastStmtExecCmd = newStmtCmd;
}
}
/**
- * Executes TDSCommand newCommand through this Statement object, allowing it to be cancelled through Statement.cancel().
+ * Executes TDSCommand newCommand through this Statement object, allowing it to be cancelled through
+ * Statement.cancel().
*
- * The specified command is typically the one used to execute the statement. But it could also be a server cursor command (fetch, move, close)
- * generated by a ResultSet that this statement produced.
+ * The specified command is typically the one used to execute the statement. But it could also be a server cursor
+ * command (fetch, move, close) generated by a ResultSet that this statement produced.
*
- * This method does not prevent applications from simultaneously executing commands from multiple threads. The assumption is that apps only call
- * cancel() from another thread while the command is executing.
+ * This method does not prevent applications from simultaneously executing commands from multiple threads. The
+ * assumption is that apps only call cancel() from another thread while the command is executing.
*/
- final void executeCommand(TDSCommand newCommand) throws SQLServerException{
+ final void executeCommand(TDSCommand newCommand) throws SQLServerException {
// Set the new command as the current command so that
// its execution can be cancelled from another thread
currentCommand = newCommand;
@@ -239,7 +244,8 @@ final void executeCommand(TDSCommand newCommand) throws SQLServerException{
}
/**
- * Flag to indicate that are potentially more results (ResultSets, update counts, or errors) to be processed in the response.
+ * Flag to indicate that are potentially more results (ResultSets, update counts, or errors) to be processed in the
+ * response.
*/
boolean moreResults = false;
@@ -261,7 +267,7 @@ synchronized void incrResultSetCount() {
}
/**
- * decrement opened result set counter
+ * Decrement opened result set counter.
*/
synchronized void decrResultSetCount() {
resultSetCount--;
@@ -274,7 +280,8 @@ synchronized void decrResultSetCount() {
}
/**
- * The statement execution method (executeQuery(), executeUpdate(), execute(), or executeBatch()) that was used to execute the statement.
+ * The statement execution method (executeQuery(), executeUpdate(), execute(), or executeBatch()) that was used to
+ * execute the statement.
*/
static final int EXECUTE_NOT_SET = 0;
static final int EXECUTE_QUERY = 1;
@@ -306,25 +313,27 @@ synchronized void decrResultSetCount() {
int resultSetConcurrency;
/**
- * The app result set type. This is the value passed to the statement's constructor (or inferred by default) when the statement was created.
- * ResultSet.getType() returns this value. It may differ from the SQL Server result set type (see below). Namely, an app result set type of
- * TYPE_FORWARD_ONLY will have an SQL Server result set type of TYPE_SS_DIRECT_FORWARD_ONLY or TYPE_SS_SERVER_CURSOR_FORWARD_ONLY depending on the
- * value of the selectMethod connection property.
+ * The app result set type. This is the value passed to the statement's constructor (or inferred by default) when
+ * the statement was created. ResultSet.getType() returns this value. It may differ from the SQL Server result set
+ * type (see below). Namely, an app result set type of TYPE_FORWARD_ONLY will have an SQL Server result set type of
+ * TYPE_SS_DIRECT_FORWARD_ONLY or TYPE_SS_SERVER_CURSOR_FORWARD_ONLY depending on the value of the selectMethod
+ * connection property.
*
* Possible values of the app result set type are:
*
- * TYPE_FORWARD_ONLY TYPE_SCROLL_INSENSITIVE TYPE_SCROLL_SENSITIVE TYPE_SS_DIRECT_FORWARD_ONLY TYPE_SS_SERVER_CURSOR_FORWARD_ONLY
- * TYPE_SS_SCROLL_DYNAMIC TYPE_SS_SCROLL_KEYSET TYPE_SS_SCROLL_STATIC
+ * TYPE_FORWARD_ONLY TYPE_SCROLL_INSENSITIVE TYPE_SCROLL_SENSITIVE TYPE_SS_DIRECT_FORWARD_ONLY
+ * TYPE_SS_SERVER_CURSOR_FORWARD_ONLY TYPE_SS_SCROLL_DYNAMIC TYPE_SS_SCROLL_KEYSET TYPE_SS_SCROLL_STATIC
*/
int appResultSetType;
/**
- * The SQL Server result set type. This is the value used everywhere EXCEPT ResultSet.getType(). This value may or may not be the same as the app
- * result set type (above).
+ * The SQL Server result set type. This is the value used everywhere EXCEPT ResultSet.getType(). This value may or
+ * may not be the same as the app result set type (above).
*
* Possible values of the SQL Server result set type are:
*
- * TYPE_SS_DIRECT_FORWARD_ONLY TYPE_SS_SERVER_CURSOR_FORWARD_ONLY TYPE_SS_SCROLL_DYNAMIC TYPE_SS_SCROLL_KEYSET TYPE_SS_SCROLL_STATIC
+ * TYPE_SS_DIRECT_FORWARD_ONLY TYPE_SS_SERVER_CURSOR_FORWARD_ONLY TYPE_SS_SCROLL_DYNAMIC TYPE_SS_SCROLL_KEYSET
+ * TYPE_SS_SCROLL_STATIC
*/
int resultSetType;
@@ -337,35 +346,39 @@ final int getCursorType() {
}
/**
- * Indicates whether to request a server cursor when executing this statement.
+ * Returns whether to request a server cursor when executing this statement.
*
- * Executing a statement with execute() or executeQuery() requests a server cursor in all scrollability and updatability combinations except
- * direct forward-only, read-only.
+ * Executing a statement with execute() or executeQuery() requests a server cursor in all scrollability and
+ * updatability combinations except direct forward-only, read-only.
*
- * Note that when execution requests a server cursor (i.e. this method returns true), there is no guarantee that SQL Server returns one. The
- * variable executedSqlDirectly indicates whether SQL Server executed the query with a cursor or not.
+ * Note that when execution requests a server cursor (i.e. this method returns true), there is no guarantee that SQL
+ * Server returns one. The variable executedSqlDirectly indicates whether SQL Server executed the query with a
+ * cursor or not.
*
* @return true if statement execution requests a server cursor, false otherwise.
*/
final boolean isCursorable(int executeMethod) {
- return resultSetType != SQLServerResultSet.TYPE_SS_DIRECT_FORWARD_ONLY && (EXECUTE == executeMethod || EXECUTE_QUERY == executeMethod);
+ return resultSetType != SQLServerResultSet.TYPE_SS_DIRECT_FORWARD_ONLY
+ && (EXECUTE == executeMethod || EXECUTE_QUERY == executeMethod);
}
/**
* Indicates whether SQL Server executed this statement with a cursor or not.
*
- * When trying to execute a cursor-unfriendly statement with a server cursor, SQL Server may choose to execute the statement directly (i.e. as if
- * no server cursor had been requested) rather than fail to execute the statement at all. We need to know when this happens so that if no rows are
- * returned, we can tell whether the result is an empty result set or a cursored result set with rows to be fetched later.
+ * When trying to execute a cursor-unfriendly statement with a server cursor, SQL Server may choose to execute the
+ * statement directly (i.e. as if no server cursor had been requested) rather than fail to execute the statement at
+ * all. We need to know when this happens so that if no rows are returned, we can tell whether the result is an
+ * empty result set or a cursored result set with rows to be fetched later.
*/
boolean executedSqlDirectly = false;
/**
- * Indicates whether OUT parameters (cursor ID and row count) from cursorized execution of this statement are expected in the response.
+ * Indicates whether OUT parameters (cursor ID and row count) from cursorized execution of this statement are
+ * expected in the response.
*
- * In most cases, except for severe errors, cursor OUT parameters are returned whenever a cursor is requested for statement execution. Even if SQL
- * Server does not cursorize the statement as requested, these values are still present in the response and must be processed, even though their
- * values are meaningless in that case.
+ * In most cases, except for severe errors, cursor OUT parameters are returned whenever a cursor is requested for
+ * statement execution. Even if SQL Server does not cursorize the statement as requested, these values are still
+ * present in the response and must be processed, even though their values are meaningless in that case.
*/
boolean expectCursorOutParams;
@@ -381,7 +394,8 @@ boolean onRetStatus(TDSReader tdsReader) throws SQLServerException {
boolean onRetValue(TDSReader tdsReader) throws SQLServerException {
if (expectCursorOutParams) {
- Parameter param = new Parameter(Util.shouldHonorAEForParameters(stmtColumnEncriptionSetting, connection));
+ Parameter param = new Parameter(
+ Util.shouldHonorAEForParameters(stmtColumnEncriptionSetting, connection));
// Read the cursor ID
param.skipRetValStatus(tdsReader);
@@ -440,7 +454,8 @@ boolean onDone(TDSReader tdsReader) throws SQLServerException {
private ResultSet autoGeneratedKeys;
/**
- * The array of objects in a batched call. Applicable to statements and prepared statements When the iterativeBatching property is turned on.
+ * The array of objects in a batched call. Applicable to statements and prepared statements When the
+ * iterativeBatching property is turned on.
*/
/** The buffer that accumulates batchable statements */
private final ArrayList batchStatementBuffer = new ArrayList<>();
@@ -449,7 +464,7 @@ boolean onDone(TDSReader tdsReader) throws SQLServerException {
static final private java.util.logging.Logger stmtlogger = java.util.logging.Logger
.getLogger("com.microsoft.sqlserver.jdbc.internals.SQLServerStatement");
- /** The statement's id for logging info */
+ /** Returns the statement's id for logging info */
@Override
public String toString() {
return traceID;
@@ -468,22 +483,20 @@ private static int nextStatementID() {
}
/**
- * The regular statement constructor
+ * Constructs a SQLServerStatement
*
* @param con
- * The statements connections.
+ * The statements connections.
* @param nType
- * The statement type.
+ * The statement type.
* @param nConcur
- * The statement concurrency.
+ * The statement concurrency.
* @param stmtColEncSetting
- * The statement column encryption setting.
+ * The statement column encryption setting.
* @exception SQLServerException
- * The statement could not be created.
+ * The statement could not be created.
*/
- SQLServerStatement(SQLServerConnection con,
- int nType,
- int nConcur,
+ SQLServerStatement(SQLServerConnection con, int nType, int nConcur,
SQLServerStatementColumnEncryptionSetting stmtColEncSetting)
throws SQLServerException {
@@ -500,21 +513,28 @@ private static int nextStatementID() {
bIsClosed = false;
// Validate result set type ...
- if (ResultSet.TYPE_FORWARD_ONLY != nType && ResultSet.TYPE_SCROLL_SENSITIVE != nType && ResultSet.TYPE_SCROLL_INSENSITIVE != nType
- && SQLServerResultSet.TYPE_SS_DIRECT_FORWARD_ONLY != nType && SQLServerResultSet.TYPE_SS_SERVER_CURSOR_FORWARD_ONLY != nType
- && SQLServerResultSet.TYPE_SS_SCROLL_DYNAMIC != nType && SQLServerResultSet.TYPE_SS_SCROLL_KEYSET != nType
+ if (ResultSet.TYPE_FORWARD_ONLY != nType && ResultSet.TYPE_SCROLL_SENSITIVE != nType
+ && ResultSet.TYPE_SCROLL_INSENSITIVE != nType && SQLServerResultSet.TYPE_SS_DIRECT_FORWARD_ONLY != nType
+ && SQLServerResultSet.TYPE_SS_SERVER_CURSOR_FORWARD_ONLY != nType
+ && SQLServerResultSet.TYPE_SS_SCROLL_DYNAMIC != nType
+ && SQLServerResultSet.TYPE_SS_SCROLL_KEYSET != nType
&& SQLServerResultSet.TYPE_SS_SCROLL_STATIC != nType) {
- SQLServerException.makeFromDriverError(connection, this, SQLServerException.getErrString("R_unsupportedCursor"), null, true);
+ SQLServerException.makeFromDriverError(connection, this,
+ SQLServerException.getErrString("R_unsupportedCursor"), null, true);
}
// ... and concurrency
- if (ResultSet.CONCUR_READ_ONLY != nConcur && ResultSet.CONCUR_UPDATABLE != nConcur && SQLServerResultSet.CONCUR_SS_SCROLL_LOCKS != nConcur
- && SQLServerResultSet.CONCUR_SS_OPTIMISTIC_CC != nConcur && SQLServerResultSet.CONCUR_SS_OPTIMISTIC_CCVAL != nConcur) {
- SQLServerException.makeFromDriverError(connection, this, SQLServerException.getErrString("R_unsupportedConcurrency"), null, true);
+ if (ResultSet.CONCUR_READ_ONLY != nConcur && ResultSet.CONCUR_UPDATABLE != nConcur
+ && SQLServerResultSet.CONCUR_SS_SCROLL_LOCKS != nConcur
+ && SQLServerResultSet.CONCUR_SS_OPTIMISTIC_CC != nConcur
+ && SQLServerResultSet.CONCUR_SS_OPTIMISTIC_CCVAL != nConcur) {
+ SQLServerException.makeFromDriverError(connection, this,
+ SQLServerException.getErrString("R_unsupportedConcurrency"), null, true);
}
if (null == stmtColEncSetting) {
- SQLServerException.makeFromDriverError(connection, this, SQLServerException.getErrString("R_unsupportedStmtColEncSetting"), null, true);
+ SQLServerException.makeFromDriverError(connection, this,
+ SQLServerException.getErrString("R_unsupportedStmtColEncSetting"), null, true);
}
stmtColumnEncriptionSetting = stmtColEncSetting;
@@ -533,31 +553,29 @@ private static int nextStatementID() {
// Check selectMethod and set to TYPE_SS_DIRECT_FORWARD_ONLY or
// TYPE_SS_SERVER_CURSOR_FORWARD_ONLY accordingly.
String selectMethod = con.getSelectMethod();
- resultSetType = (null == selectMethod || !selectMethod.equals("cursor")) ? SQLServerResultSet.TYPE_SS_DIRECT_FORWARD_ONLY : // Default
- // forward-only,
- // read-only
- // cursor
- // type
- SQLServerResultSet.TYPE_SS_SERVER_CURSOR_FORWARD_ONLY;
- }
- else {
+ resultSetType = (null == selectMethod
+ || !selectMethod.equals("cursor")) ? SQLServerResultSet.TYPE_SS_DIRECT_FORWARD_ONLY : // Default
+ // forward-only,
+ // read-only
+ // cursor
+ // type
+ SQLServerResultSet.TYPE_SS_SERVER_CURSOR_FORWARD_ONLY;
+ } else {
resultSetType = SQLServerResultSet.TYPE_SS_SERVER_CURSOR_FORWARD_ONLY;
}
- }
- else if (ResultSet.TYPE_SCROLL_INSENSITIVE == nType) {
+ } else if (ResultSet.TYPE_SCROLL_INSENSITIVE == nType) {
resultSetType = SQLServerResultSet.TYPE_SS_SCROLL_STATIC;
- }
- else if (ResultSet.TYPE_SCROLL_SENSITIVE == nType) {
+ } else if (ResultSet.TYPE_SCROLL_SENSITIVE == nType) {
resultSetType = SQLServerResultSet.TYPE_SS_SCROLL_KEYSET;
- }
- else // App specified one of the SQL Server types
+ } else // App specified one of the SQL Server types
{
resultSetType = nType;
}
// Figure out default fetch direction
nFetchDirection = (SQLServerResultSet.TYPE_SS_DIRECT_FORWARD_ONLY == resultSetType
- || SQLServerResultSet.TYPE_SS_SERVER_CURSOR_FORWARD_ONLY == resultSetType) ? ResultSet.FETCH_FORWARD : ResultSet.FETCH_UNKNOWN;
+ || SQLServerResultSet.TYPE_SS_SERVER_CURSOR_FORWARD_ONLY == resultSetType) ? ResultSet.FETCH_FORWARD
+ : ResultSet.FETCH_UNKNOWN;
// Figure out fetch size:
//
@@ -574,10 +592,10 @@ else if (ResultSet.TYPE_SCROLL_SENSITIVE == nType) {
// with all but read only concurrency. Against a Shiloh server, such
// combinations cause the cursor to be silently "upgraded" to one that
// works. We enforce the more restrictive behavior of the two here.
- if (ResultSet.CONCUR_READ_ONLY != nConcur
- && (SQLServerResultSet.TYPE_SS_DIRECT_FORWARD_ONLY == resultSetType || SQLServerResultSet.TYPE_SS_SCROLL_STATIC == resultSetType)) {
- SQLServerException.makeFromDriverError(connection, this, SQLServerException.getErrString("R_unsupportedCursorAndConcurrency"), null,
- true);
+ if (ResultSet.CONCUR_READ_ONLY != nConcur && (SQLServerResultSet.TYPE_SS_DIRECT_FORWARD_ONLY == resultSetType
+ || SQLServerResultSet.TYPE_SS_SCROLL_STATIC == resultSetType)) {
+ SQLServerException.makeFromDriverError(connection, this,
+ SQLServerException.getErrString("R_unsupportedCursorAndConcurrency"), null, true);
}
// All result set types other than firehose (SQL Server default) use server side cursors.
@@ -587,9 +605,9 @@ else if (ResultSet.TYPE_SCROLL_SENSITIVE == nType) {
setDefaultQueryCancelTimeout();
if (stmtlogger.isLoggable(java.util.logging.Level.FINER)) {
- stmtlogger.finer("Properties for " + toString() + ":" + " Result type:" + appResultSetType + " (" + resultSetType + ")" + " Concurrency:"
- + resultSetConcurrency + " Fetchsize:" + nFetchSize + " bIsClosed:" + bIsClosed + " useLastUpdateCount:"
- + connection.useLastUpdateCount());
+ stmtlogger.finer("Properties for " + toString() + ":" + " Result type:" + appResultSetType + " ("
+ + resultSetType + ")" + " Concurrency:" + resultSetConcurrency + " Fetchsize:" + nFetchSize
+ + " bIsClosed:" + bIsClosed + " useLastUpdateCount:" + connection.useLastUpdateCount());
}
if (stmtlogger.isLoggable(java.util.logging.Level.FINE)) {
@@ -602,9 +620,9 @@ private void setDefaultQueryCancelTimeout() {
if (cancelQueryTimeoutSeconds > 0) {
this.cancelQueryTimeoutSeconds = cancelQueryTimeoutSeconds;
}
- }
+ }
- // add query timeout to statement
+ // add query timeout to statement
private void setDefaultQueryTimeout() {
int queryTimeoutSeconds = this.connection.getQueryTimeoutSeconds();
if (queryTimeoutSeconds > 0) {
@@ -615,13 +633,14 @@ private void setDefaultQueryTimeout() {
final java.util.logging.Logger getStatementLogger() {
return stmtlogger;
}
-
+
/**
- * Close the statement.
+ * Closes the statement.
*
- * Note that the public close() method performs all of the cleanup work through this internal method which cannot throw any exceptions. This is
- * done deliberately to ensure that ALL of the object's client-side and server-side state is cleaned up as best as possible, even under conditions
- * which would normally result in exceptions being thrown.
+ * Note that the public close() method performs all of the cleanup work through this internal method which cannot
+ * throw any exceptions. This is done deliberately to ensure that ALL of the object's client-side and server-side
+ * state is cleaned up as best as possible, even under conditions which would normally result in exceptions being
+ * thrown.
*/
void closeInternal() {
// Regardless what happens when cleaning up,
@@ -666,7 +685,7 @@ public java.sql.ResultSet executeQuery(String sql) throws SQLServerException, SQ
loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString());
}
checkClosed();
- executeStatement(new StmtExecCmd(this, sql, EXECUTE_QUERY, NO_GENERATED_KEYS));
+ executeStatement(new StmtExecCmd(this, sql, EXECUTE_QUERY, NO_GENERATED_KEYS));
loggerExternal.exiting(getClassNameLogging(), "executeQuery", resultSet);
return resultSet;
}
@@ -688,7 +707,8 @@ public int executeUpdate(String sql) throws SQLServerException, SQLTimeoutExcept
// this shouldn't happen, caller probably meant to call executeLargeUpdate
if (updateCount < Integer.MIN_VALUE || updateCount > Integer.MAX_VALUE)
- SQLServerException.makeFromDriverError(connection, this, SQLServerException.getErrString("R_updateCountOutofRange"), null, true);
+ SQLServerException.makeFromDriverError(connection, this,
+ SQLServerException.getErrString("R_updateCountOutofRange"), null, true);
loggerExternal.exiting(getClassNameLogging(), "executeUpdate", updateCount);
@@ -727,10 +747,7 @@ private final class StmtExecCmd extends TDSCommand {
final int executeMethod;
final int autoGeneratedKeys;
- StmtExecCmd(SQLServerStatement stmt,
- String sql,
- int executeMethod,
- int autoGeneratedKeys) {
+ StmtExecCmd(SQLServerStatement stmt, String sql, int executeMethod, int autoGeneratedKeys) {
super(stmt.toString() + " executeXXX", stmt.queryTimeout, stmt.cancelQueryTimeoutSeconds);
this.stmt = stmt;
this.sql = sql;
@@ -752,7 +769,7 @@ final void processResponse(TDSReader tdsReader) throws SQLServerException {
private String ensureSQLSyntax(String sql) throws SQLServerException {
if (sql.indexOf(LEFT_CURLY_BRACKET) >= 0) {
- Sha1HashKey cacheKey = new Sha1HashKey(sql);
+ CityHash128Key cacheKey = new CityHash128Key(sql);
// Check for cached SQL metadata.
ParsedSQLCacheItem cacheItem = getCachedParsedSQL(cacheKey);
@@ -775,9 +792,9 @@ final void setMaxRowsAndMaxFieldSize() throws SQLServerException {
if (EXECUTE_QUERY == executeMethod || EXECUTE == executeMethod) {
connection.setMaxRows(maxRows);
connection.setMaxFieldSize(maxFieldSize);
- }
- else {
- assert EXECUTE_UPDATE == executeMethod || EXECUTE_BATCH == executeMethod || EXECUTE_QUERY_INTERNAL == executeMethod;
+ } else {
+ assert EXECUTE_UPDATE == executeMethod || EXECUTE_BATCH == executeMethod
+ || EXECUTE_QUERY_INTERNAL == executeMethod;
// If we are executing via any of the above methods then make sure any
// previous maxRows limitation on the connection is removed.
@@ -816,8 +833,7 @@ final void doExecuteStatement(StmtExecCmd execCmd) throws SQLServerException {
stmtlogger.fine(toString() + " Executing server side cursor " + sql);
doExecuteCursored(execCmd, sql);
- }
- else // Non-cursored execution (includes EXECUTE_QUERY_INTERNAL)
+ } else // Non-cursored execution (includes EXECUTE_QUERY_INTERNAL)
{
executedSqlDirectly = true;
expectCursorOutParams = false;
@@ -828,7 +844,8 @@ final void doExecuteStatement(StmtExecCmd execCmd) throws SQLServerException {
// If this is an INSERT statement and generated keys were requested
// then add on the query to return them.
- if (RETURN_GENERATED_KEYS == execCmd.autoGeneratedKeys && (EXECUTE_UPDATE == executeMethod || EXECUTE == executeMethod)
+ if (RETURN_GENERATED_KEYS == execCmd.autoGeneratedKeys
+ && (EXECUTE_UPDATE == executeMethod || EXECUTE == executeMethod)
&& sql.trim().toUpperCase().startsWith("INSERT")) {
tdsWriter.writeString(identityQuery);
}
@@ -845,15 +862,16 @@ final void doExecuteStatement(StmtExecCmd execCmd) throws SQLServerException {
// If execution produced no result set, then throw an exception if executeQuery() was used.
if (null == resultSet) {
if (EXECUTE_QUERY == executeMethod) {
- SQLServerException.makeFromDriverError(connection, this, SQLServerException.getErrString("R_noResultset"), null, true);
+ SQLServerException.makeFromDriverError(connection, this,
+ SQLServerException.getErrString("R_noResultset"), null, true);
}
}
// Otherwise, if execution produced a result set, then throw an exception
// if executeUpdate() or executeBatch() was used.
else {
if (EXECUTE_UPDATE == executeMethod || EXECUTE_BATCH == executeMethod) {
- SQLServerException.makeFromDriverError(connection, this, SQLServerException.getErrString("R_resultsetGeneratedForUpdate"), null,
- false);
+ SQLServerException.makeFromDriverError(connection, this,
+ SQLServerException.getErrString("R_resultsetGeneratedForUpdate"), null, false);
}
}
}
@@ -909,12 +927,13 @@ private void doExecuteStatementBatch(StmtBatchExecCmd execCmd) throws SQLServerE
// If execution produced a result set, then throw an exception
if (null != resultSet) {
- SQLServerException.makeFromDriverError(connection, this, SQLServerException.getErrString("R_resultsetGeneratedForUpdate"), null, false);
+ SQLServerException.makeFromDriverError(connection, this,
+ SQLServerException.getErrString("R_resultsetGeneratedForUpdate"), null, false);
}
}
/**
- * Reset the state to get the statement for reexecute callable statement overrides this.
+ * Resets the state to get the statement for reexecute callable statement overrides this.
*/
final void resetForReexecute() throws SQLServerException {
ensureExecuteResultsReader(null);
@@ -926,10 +945,10 @@ final void resetForReexecute() throws SQLServerException {
}
/**
- * Determine if the SQL is a SELECT.
+ * Determines if the SQL is a SELECT.
*
* @param sql
- * The statment SQL.
+ * The statment SQL.
* @return True if the statement is a select.
*/
final boolean isSelect(String sql) throws SQLServerException {
@@ -942,15 +961,15 @@ final boolean isSelect(String sql) throws SQLServerException {
}
return temp.substring(0, 6).equalsIgnoreCase("select");
}
-
+
/**
* Determine if the SQL is a INSERT.
*
* @param sql
- * The statment SQL.
+ * The statment SQL.
* @return True if the statement is an insert.
*/
- /* L0 */ final boolean isInsert(String sql) throws SQLServerException {
+ final boolean isInsert(String sql) throws SQLServerException {
checkClosed();
// Used to check just the first letter which would cause
// "Set" commands to return true...
@@ -966,19 +985,17 @@ final boolean isSelect(String sql) throws SQLServerException {
}
/**
- * Replace a JDBC parameter marker with the parameter's string value
+ * Replaces a JDBC parameter marker with the parameter's string value
*
* @param str
- * the parameter syntax
+ * the parameter syntax
* @param marker
- * the parameter marker
+ * the parameter marker
* @param replaceStr
- * the param value
+ * the param value
* @return String
*/
- static String replaceParameterWithString(String str,
- char marker,
- String replaceStr) {
+ static String replaceParameterWithString(String str, char marker, String replaceStr) {
int index = 0;
while ((index = str.indexOf("" + marker)) >= 0) {
str = str.substring(0, index) + replaceStr + str.substring(index + 1, str.length());
@@ -987,18 +1004,17 @@ static String replaceParameterWithString(String str,
}
/**
- * Set a JDBC parameter to null. (Used only when processing LOB column sources.)
+ * Sets a JDBC parameter to null. (Used only when processing LOB column sources.)
*
* @param sql
- * the parameter syntax
+ * the parameter syntax
* @return the result
*/
static String replaceMarkerWithNull(String sql) {
if (!sql.contains("'")) {
String retStr = replaceParameterWithString(sql, '?', "null");
return retStr;
- }
- else {
+ } else {
StringTokenizer st = new StringTokenizer(sql, "'", true);
boolean beforeColon = true;
String retSql = "";
@@ -1013,8 +1029,7 @@ static String replaceMarkerWithNull(String sql) {
String repStr = replaceParameterWithString(str, '?', "null");
retSql += repStr;
continue;
- }
- else {
+ } else {
retSql += str;
continue;
}
@@ -1030,7 +1045,8 @@ void checkClosed() throws SQLServerException {
// was closed.
connection.checkClosed();
if (bIsClosed) {
- SQLServerException.makeFromDriverError(connection, this, SQLServerException.getErrString("R_statementIsClosed"), null, false);
+ SQLServerException.makeFromDriverError(connection, this,
+ SQLServerException.getErrString("R_statementIsClosed"), null, false);
}
}
@@ -1222,7 +1238,8 @@ public final int getUpdateCount() throws SQLServerException {
// this shouldn't happen, caller probably meant to call getLargeUpdateCount
if (updateCount < Integer.MIN_VALUE || updateCount > Integer.MAX_VALUE)
- SQLServerException.makeFromDriverError(connection, this, SQLServerException.getErrString("R_updateCountOutofRange"), null, true);
+ SQLServerException.makeFromDriverError(connection, this,
+ SQLServerException.getErrString("R_updateCountOutofRange"), null, true);
loggerExternal.exiting(getClassNameLogging(), "getUpdateCount", updateCount);
@@ -1261,15 +1278,15 @@ final void processResults() throws SQLServerException {
// Get the next result
try {
getNextResult();
- }
- catch (SQLServerException e) {
+ } catch (SQLServerException e) {
// If an exception is thrown while processing the results
// then decide what to do with it:
if (moreResults) {
// Silently discard database errors and continue processing the remaining results
if (SQLServerException.DRIVER_ERROR_FROM_DATABASE == e.getDriverErrorCode()) {
if (stmtlogger.isLoggable(java.util.logging.Level.FINEST)) {
- stmtlogger.finest(this + " ignoring database error: " + e.getErrorCode() + " " + e.getMessage());
+ stmtlogger.finest(
+ this + " ignoring database error: " + e.getErrorCode() + " " + e.getMessage());
}
continue;
@@ -1277,7 +1294,8 @@ final void processResults() throws SQLServerException {
// If statement execution was canceled then continue processing the
// remaining results before throwing the "statement canceled" exception.
- if (e.getSQLState()!=null && e.getSQLState().equals(SQLState.STATEMENT_CANCELED.getSQLStateCode())) {
+ if (e.getSQLState() != null
+ && e.getSQLState().equals(SQLState.STATEMENT_CANCELED.getSQLStateCode())) {
interruptException = e;
continue;
}
@@ -1296,10 +1314,10 @@ final void processResults() throws SQLServerException {
}
/**
- * Check for more results in the TDS stream
+ * Returns more results in the TDS stream.
*
- * @return true if the next result is a ResultSet object; false if it is an integer (indicating that it is an update count or there are no more
- * results).
+ * @return true if the next result is a ResultSet object; false if it is an integer (indicating that it is an update
+ * count or there are no more results).
*/
@Override
public final boolean getMoreResults() throws SQLServerException {
@@ -1319,10 +1337,11 @@ public final boolean getMoreResults() throws SQLServerException {
*
* This method is used to clean up before moving to the next result and after processing the last result.
*
- * Note that errors closing the ResultSet (if the last result is a ResultSet) are caught, logged, and ignored. The reason for this is that this
- * method is only for cleanup for when the app fails to do the cleanup itself (for example by leaving a ResultSet open when closing the
- * statement). If the app wants to be able to handle errors from closing the current result set, then it should close that ResultSet itself before
- * closing the statement, moving to the next result, or whatever. This is the recommended practice with JDBC.
+ * Note that errors closing the ResultSet (if the last result is a ResultSet) are caught, logged, and ignored. The
+ * reason for this is that this method is only for cleanup for when the app fails to do the cleanup itself (for
+ * example by leaving a ResultSet open when closing the statement). If the app wants to be able to handle errors
+ * from closing the current result set, then it should close that ResultSet itself before closing the statement,
+ * moving to the next result, or whatever. This is the recommended practice with JDBC.
*/
final void clearLastResult() {
// Clear any update count result
@@ -1335,18 +1354,17 @@ final void clearLastResult() {
// it anyhow.
try {
resultSet.close();
- }
- catch (SQLServerException e) {
- stmtlogger.finest(this + " clearing last result; ignored error closing ResultSet: " + e.getErrorCode() + " " + e.getMessage());
- }
- finally {
+ } catch (SQLServerException e) {
+ stmtlogger.finest(this + " clearing last result; ignored error closing ResultSet: " + e.getErrorCode()
+ + " " + e.getMessage());
+ } finally {
resultSet = null;
}
}
}
/**
- * Get the next result in the TDS response token stream, which may be a result set, update count or exception.
+ * Returns the next result in the TDS response token stream, which may be a result set, update count or exception.
*
* @return true if another result (ResultSet or update count) was available; false if there were no more results.
*/
@@ -1423,8 +1441,8 @@ boolean onDone(TDSReader tdsReader) throws SQLServerException {
// status (Statement.SUCCESS_NO_INFO)
if (-1 == doneToken.getUpdateCount() && EXECUTE_BATCH != executeMethod)
return true;
-
- if ( -1 != doneToken.getUpdateCount() && EXECUTE_QUERY == executeMethod )
+
+ if (-1 != doneToken.getUpdateCount() && EXECUTE_QUERY == executeMethod)
return true;
// Otherwise, the update count is valid. Now determine whether we should
@@ -1521,7 +1539,8 @@ boolean onRetValue(TDSReader tdsReader) throws SQLServerException {
// A RETVALUE token appearing in the execution results, but before any RETSTATUS
// token, is a TEXTPTR return value that should be ignored.
if (moreResults && null == procedureRetStatToken) {
- Parameter p = new Parameter(Util.shouldHonorAEForParameters(stmtColumnEncriptionSetting, connection));
+ Parameter p = new Parameter(
+ Util.shouldHonorAEForParameters(stmtColumnEncriptionSetting, connection));
p.skipRetValStatus(tdsReader);
p.skipValue(tdsReader, true);
return true;
@@ -1549,14 +1568,14 @@ boolean onInfo(TDSReader tdsReader) throws SQLServerException {
if (16954 == infoToken.msg.getErrorNumber())
executedSqlDirectly = true;
- SQLWarning warning = new SQLWarning(infoToken.msg.getMessage(),
- SQLServerException.generateStateCode(connection, infoToken.msg.getErrorNumber(), infoToken.msg.getErrorState()),
+ SQLWarning warning = new SQLWarning(
+ infoToken.msg.getMessage(), SQLServerException.generateStateCode(connection,
+ infoToken.msg.getErrorNumber(), infoToken.msg.getErrorState()),
infoToken.msg.getErrorNumber());
if (sqlWarnings == null) {
sqlWarnings = new Vector<>();
- }
- else {
+ } else {
int n = sqlWarnings.size();
SQLWarning w = sqlWarnings.elementAt(n - 1);
w.setNextWarning(warning);
@@ -1586,8 +1605,8 @@ boolean onInfo(TDSReader tdsReader) throws SQLServerException {
// Check for errors first.
if (null != nextResult.getDatabaseError()) {
- SQLServerException.makeFromDatabaseError(connection, null, nextResult.getDatabaseError().getMessage(), nextResult.getDatabaseError(),
- false);
+ SQLServerException.makeFromDatabaseError(connection, null, nextResult.getDatabaseError().getMessage(),
+ nextResult.getDatabaseError(), false);
}
// Not an error. Is it a result set?
@@ -1627,10 +1646,10 @@ else if (nextResult.isUpdateCount()) {
}
/**
- * Consume the OUT parameter for the statement object itself.
+ * Consumes the OUT parameter for the statement object itself.
*
- * Normal Statement objects consume the server cursor OUT params when present. PreparedStatement and CallableStatement objects override this
- * method to consume the prepared statement handle as well.
+ * Normal Statement objects consume the server cursor OUT params when present. PreparedStatement and
+ * CallableStatement objects override this method to consume the prepared statement handle as well.
*/
boolean consumeExecOutParam(TDSReader tdsReader) throws SQLServerException {
if (expectCursorOutParams) {
@@ -1675,7 +1694,8 @@ public final void setFetchSize(int rows) throws SQLServerException {
loggerExternal.entering(getClassNameLogging(), "setFetchSize", rows);
checkClosed();
if (rows < 0)
- SQLServerException.makeFromDriverError(connection, this, SQLServerException.getErrString("R_invalidFetchSize"), null, false);
+ SQLServerException.makeFromDriverError(connection, this,
+ SQLServerException.getErrString("R_invalidFetchSize"), null, false);
nFetchSize = (0 == rows) ? defaultFetchSize : rows;
loggerExternal.exiting(getClassNameLogging(), "setFetchSize");
@@ -1728,7 +1748,7 @@ public void clearBatch() throws SQLServerException {
}
/**
- * Send a batch of statements to the database.
+ * Sends a batch of statements to the database.
*/
@Override
public int[] executeBatch() throws SQLServerException, BatchUpdateException, SQLTimeoutException {
@@ -1761,8 +1781,7 @@ public int[] executeBatch() throws SQLServerException, BatchUpdateException, SQL
if (0 == batchNum) {
// First time through, execute the entire set of batches and return the first result
executeStatement(new StmtBatchExecCmd(this));
- }
- else {
+ } else {
// Subsequent times through, just get the result from the next batch.
// If there are not enough results (update counts) to satisfy the number of batches,
// then bail, leaving EXECUTE_FAILED in the remaining slots of the update count array.
@@ -1772,14 +1791,13 @@ public int[] executeBatch() throws SQLServerException, BatchUpdateException, SQL
}
if (null != resultSet) {
- SQLServerException.makeFromDriverError(connection, this, SQLServerException.getErrString("R_resultsetGeneratedForUpdate"),
- null, true);
- }
- else {
- updateCounts[batchNum] = (-1 != (int) updateCount) ? (int) updateCount : Statement.SUCCESS_NO_INFO;
+ SQLServerException.makeFromDriverError(connection, this,
+ SQLServerException.getErrString("R_resultsetGeneratedForUpdate"), null, true);
+ } else {
+ updateCounts[batchNum] = (-1 != (int) updateCount) ? (int) updateCount
+ : Statement.SUCCESS_NO_INFO;
}
- }
- catch (SQLServerException e) {
+ } catch (SQLServerException e) {
// If the failure was severe enough to close the connection or roll back a
// manual transaction, then propagate the error up as a SQLServerException
// now, rather than continue with the batch.
@@ -1794,13 +1812,13 @@ public int[] executeBatch() throws SQLServerException, BatchUpdateException, SQL
// If we had any errors then throw a BatchUpdateException with the partial results.
if (null != lastError) {
- throw new BatchUpdateException(lastError.getMessage(), lastError.getSQLState(), lastError.getErrorCode(), updateCounts);
+ throw new BatchUpdateException(lastError.getMessage(), lastError.getSQLState(),
+ lastError.getErrorCode(), updateCounts);
}
loggerExternal.exiting(getClassNameLogging(), "executeBatch", updateCounts);
return updateCounts;
- }
- finally {
+ } finally {
// Regardless what happens, always clear out the batch after execution.
// Note: Don't use the clearBatch API as it checks that the statement is
// not closed, which it might be in the event of a severe error.
@@ -1840,8 +1858,7 @@ public long[] executeLargeBatch() throws SQLServerException, BatchUpdateExceptio
if (0 == batchNum) {
// First time through, execute the entire set of batches and return the first result
executeStatement(new StmtBatchExecCmd(this));
- }
- else {
+ } else {
// Subsequent times through, just get the result from the next batch.
// If there are not enough results (update counts) to satisfy the number of batches,
// then bail, leaving EXECUTE_FAILED in the remaining slots of the update count array.
@@ -1851,14 +1868,12 @@ public long[] executeLargeBatch() throws SQLServerException, BatchUpdateExceptio
}
if (null != resultSet) {
- SQLServerException.makeFromDriverError(connection, this, SQLServerException.getErrString("R_resultsetGeneratedForUpdate"),
- null, true);
- }
- else {
+ SQLServerException.makeFromDriverError(connection, this,
+ SQLServerException.getErrString("R_resultsetGeneratedForUpdate"), null, true);
+ } else {
updateCounts[batchNum] = (-1 != updateCount) ? updateCount : Statement.SUCCESS_NO_INFO;
}
- }
- catch (SQLServerException e) {
+ } catch (SQLServerException e) {
// If the failure was severe enough to close the connection or roll back a
// manual transaction, then propagate the error up as a SQLServerException
// now, rather than continue with the batch.
@@ -1878,8 +1893,7 @@ public long[] executeLargeBatch() throws SQLServerException, BatchUpdateExceptio
loggerExternal.exiting(getClassNameLogging(), "executeLargeBatch", updateCounts);
return updateCounts;
- }
- finally {
+ } finally {
// Regardless what happens, always clear out the batch after execution.
// Note: Don't use the clearBatch API as it checks that the statement is
// not closed, which it might be in the event of a severe error.
@@ -1888,17 +1902,18 @@ public long[] executeLargeBatch() throws SQLServerException, BatchUpdateExceptio
} // executeLargeBatch
/**
- * Return the statement's connection
+ * Returns the statement's connection.
*
* @throws SQLServerException
- * when an error occurs
+ * when an error occurs
* @return the connection
*/
@Override
public final java.sql.Connection getConnection() throws SQLServerException {
loggerExternal.entering(getClassNameLogging(), "getConnection");
if (bIsClosed) {
- SQLServerException.makeFromDriverError(connection, this, SQLServerException.getErrString("R_statementIsClosed"), null, false);
+ SQLServerException.makeFromDriverError(connection, this,
+ SQLServerException.getErrString("R_statementIsClosed"), null, false);
}
java.sql.Connection con = connection.getConnection();
loggerExternal.exiting(getClassNameLogging(), "getConnection", con);
@@ -1907,21 +1922,13 @@ public final java.sql.Connection getConnection() throws SQLServerException {
/* ----------------- Server side cursor support -------------------------- */
- /**
- * Open a server side cursor.
- *
- * @param sql
- * The SQL query.
- * @exception SQLServerException
- * The SQL query was invalid.
- */
-
final int getResultSetScrollOpt() {
int scrollOpt = (null == inOutParam) ? 0 : TDS.SCROLLOPT_PARAMETERIZED_STMT;
switch (resultSetType) {
case SQLServerResultSet.TYPE_SS_SERVER_CURSOR_FORWARD_ONLY:
- return scrollOpt | ((ResultSet.CONCUR_READ_ONLY == resultSetConcurrency) ? TDS.SCROLLOPT_FAST_FORWARD : TDS.SCROLLOPT_FORWARD_ONLY);
+ return scrollOpt | ((ResultSet.CONCUR_READ_ONLY == resultSetConcurrency) ? TDS.SCROLLOPT_FAST_FORWARD
+ : TDS.SCROLLOPT_FORWARD_ONLY);
case SQLServerResultSet.TYPE_SS_SCROLL_DYNAMIC:
return scrollOpt | TDS.SCROLLOPT_DYNAMIC;
@@ -1959,11 +1966,10 @@ final int getResultSetCCOpt() {
return 0;
}
- private void doExecuteCursored(StmtExecCmd execCmd,
- String sql) throws SQLServerException {
+ private void doExecuteCursored(StmtExecCmd execCmd, String sql) throws SQLServerException {
if (stmtlogger.isLoggable(java.util.logging.Level.FINER)) {
- stmtlogger.finer(toString() + " Execute for cursor open" + " SQL:" + sql + " Scrollability:" + getResultSetScrollOpt() + " Concurrency:"
- + getResultSetCCOpt());
+ stmtlogger.finer(toString() + " Execute for cursor open" + " SQL:" + sql + " Scrollability:"
+ + getResultSetScrollOpt() + " Concurrency:" + getResultSetCCOpt());
}
executedSqlDirectly = false;
@@ -1971,8 +1977,8 @@ private void doExecuteCursored(StmtExecCmd execCmd,
TDSWriter tdsWriter = execCmd.startRequest(TDS.PKT_RPC);
tdsWriter.writeShort((short) 0xFFFF); // procedure name length -> use ProcIDs
tdsWriter.writeShort(TDS.PROCID_SP_CURSOROPEN);
- tdsWriter.writeByte((byte) 0); // RPC procedure option 1
- tdsWriter.writeByte((byte) 0); // RPC procedure option 2
+ tdsWriter.writeByte((byte) 0); // RPC procedure option 1
+ tdsWriter.writeByte((byte) 0); // RPC procedure option 2
// OUT
tdsWriter.writeRPCInt(null, 0, true);
@@ -2033,7 +2039,8 @@ public final boolean execute(java.lang.String sql,
loggerExternal.entering(getClassNameLogging(), "execute", new Object[] {sql, columnIndexes});
checkClosed();
if (columnIndexes == null || columnIndexes.length != 1) {
- SQLServerException.makeFromDriverError(connection, this, SQLServerException.getErrString("R_invalidColumnArrayLength"), null, false);
+ SQLServerException.makeFromDriverError(connection, this,
+ SQLServerException.getErrString("R_invalidColumnArrayLength"), null, false);
}
boolean fSuccess = execute(sql, Statement.RETURN_GENERATED_KEYS);
loggerExternal.exiting(getClassNameLogging(), "execute", fSuccess);
@@ -2047,7 +2054,8 @@ public final boolean execute(java.lang.String sql,
loggerExternal.entering(getClassNameLogging(), "execute", new Object[] {sql, columnNames});
checkClosed();
if (columnNames == null || columnNames.length != 1) {
- SQLServerException.makeFromDriverError(connection, this, SQLServerException.getErrString("R_invalidColumnArrayLength"), null, false);
+ SQLServerException.makeFromDriverError(connection, this,
+ SQLServerException.getErrString("R_invalidColumnArrayLength"), null, false);
}
boolean fSuccess = execute(sql, Statement.RETURN_GENERATED_KEYS);
loggerExternal.exiting(getClassNameLogging(), "execute", fSuccess);
@@ -2055,8 +2063,7 @@ public final boolean execute(java.lang.String sql,
}
@Override
- public final int executeUpdate(String sql,
- int autoGeneratedKeys) throws SQLServerException, SQLTimeoutException {
+ public final int executeUpdate(String sql, int autoGeneratedKeys) throws SQLServerException, SQLTimeoutException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER)) {
loggerExternal.entering(getClassNameLogging(), "executeUpdate", new Object[] {sql, autoGeneratedKeys});
if (Util.IsActivityTraceOn()) {
@@ -2073,7 +2080,8 @@ public final int executeUpdate(String sql,
// this shouldn't happen, caller probably meant to call executeLargeUpdate
if (updateCount < Integer.MIN_VALUE || updateCount > Integer.MAX_VALUE)
- SQLServerException.makeFromDriverError(connection, this, SQLServerException.getErrString("R_updateCountOutofRange"), null, true);
+ SQLServerException.makeFromDriverError(connection, this,
+ SQLServerException.getErrString("R_updateCountOutofRange"), null, true);
loggerExternal.exiting(getClassNameLogging(), "executeUpdate", updateCount);
@@ -2108,7 +2116,8 @@ public final int executeUpdate(java.lang.String sql,
loggerExternal.entering(getClassNameLogging(), "executeUpdate", new Object[] {sql, columnIndexes});
checkClosed();
if (columnIndexes == null || columnIndexes.length != 1) {
- SQLServerException.makeFromDriverError(connection, this, SQLServerException.getErrString("R_invalidColumnArrayLength"), null, false);
+ SQLServerException.makeFromDriverError(connection, this,
+ SQLServerException.getErrString("R_invalidColumnArrayLength"), null, false);
}
int count = executeUpdate(sql, Statement.RETURN_GENERATED_KEYS);
loggerExternal.exiting(getClassNameLogging(), "executeUpdate", count);
@@ -2123,7 +2132,8 @@ public final long executeLargeUpdate(java.lang.String sql,
loggerExternal.entering(getClassNameLogging(), "executeLargeUpdate", new Object[] {sql, columnIndexes});
checkClosed();
if (columnIndexes == null || columnIndexes.length != 1) {
- SQLServerException.makeFromDriverError(connection, this, SQLServerException.getErrString("R_invalidColumnArrayLength"), null, false);
+ SQLServerException.makeFromDriverError(connection, this,
+ SQLServerException.getErrString("R_invalidColumnArrayLength"), null, false);
}
long count = executeLargeUpdate(sql, Statement.RETURN_GENERATED_KEYS);
loggerExternal.exiting(getClassNameLogging(), "executeLargeUpdate", count);
@@ -2137,7 +2147,8 @@ public final int executeUpdate(java.lang.String sql,
loggerExternal.entering(getClassNameLogging(), "executeUpdate", new Object[] {sql, columnNames});
checkClosed();
if (columnNames == null || columnNames.length != 1) {
- SQLServerException.makeFromDriverError(connection, this, SQLServerException.getErrString("R_invalidColumnArrayLength"), null, false);
+ SQLServerException.makeFromDriverError(connection, this,
+ SQLServerException.getErrString("R_invalidColumnArrayLength"), null, false);
}
int count = executeUpdate(sql, Statement.RETURN_GENERATED_KEYS);
loggerExternal.exiting(getClassNameLogging(), "executeUpdate", count);
@@ -2152,7 +2163,8 @@ public final long executeLargeUpdate(java.lang.String sql,
loggerExternal.entering(getClassNameLogging(), "executeLargeUpdate", new Object[] {sql, columnNames});
checkClosed();
if (columnNames == null || columnNames.length != 1) {
- SQLServerException.makeFromDriverError(connection, this, SQLServerException.getErrString("R_invalidColumnArrayLength"), null, false);
+ SQLServerException.makeFromDriverError(connection, this,
+ SQLServerException.getErrString("R_invalidColumnArrayLength"), null, false);
}
long count = executeLargeUpdate(sql, Statement.RETURN_GENERATED_KEYS);
loggerExternal.exiting(getClassNameLogging(), "executeLargeUpdate", count);
@@ -2171,7 +2183,8 @@ public final ResultSet getGeneratedKeys() throws SQLServerException {
// Try to get that ResultSet. If there are no more results after the update count,
// or if the next result isn't a ResultSet, then something is wrong.
if (!getNextResult() || null == resultSet) {
- SQLServerException.makeFromDriverError(connection, this, SQLServerException.getErrString("R_statementMustBeExecuted"), null, false);
+ SQLServerException.makeFromDriverError(connection, this,
+ SQLServerException.getErrString("R_statementMustBeExecuted"), null, false);
}
autoGeneratedKeys = resultSet;
@@ -2191,15 +2204,15 @@ public final boolean getMoreResults(int mode) throws SQLException {
}
if (CLOSE_CURRENT_RESULT != mode && CLOSE_ALL_RESULTS != mode)
- SQLServerException.makeFromDriverError(connection, this, SQLServerException.getErrString("R_modeSuppliedNotValid"), null, true);
+ SQLServerException.makeFromDriverError(connection, this,
+ SQLServerException.getErrString("R_modeSuppliedNotValid"), null, true);
ResultSet rsPrevious = resultSet;
boolean fResults = getMoreResults();
if (rsPrevious != null) {
try {
rsPrevious.close();
- }
- catch (SQLException e) {
+ } catch (SQLException e) {
throw new SQLServerException(e.getMessage(), null, 0, e);
}
}
@@ -2254,8 +2267,7 @@ public T unwrap(Class iface) throws SQLException {
T t;
try {
t = iface.cast(this);
- }
- catch (ClassCastException e) {
+ } catch (ClassCastException e) {
throw new SQLServerException(e.getMessage(), e);
}
loggerExternal.exiting(getClassNameLogging(), "unwrap", t);
@@ -2288,12 +2300,10 @@ public final void setResponseBuffering(String value) throws SQLServerException {
if ("full".equalsIgnoreCase(value)) {
isResponseBufferingAdaptive = false;
wasResponseBufferingSet = true;
- }
- else if ("adaptive".equalsIgnoreCase(value)) {
+ } else if ("adaptive".equalsIgnoreCase(value)) {
isResponseBufferingAdaptive = true;
wasResponseBufferingSet = true;
- }
- else {
+ } else {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidresponseBuffering"));
Object[] msgArgs = {value};
SQLServerException.makeFromDriverError(connection, this, form.format(msgArgs), null, false);
@@ -2311,8 +2321,7 @@ public final String getResponseBuffering() throws SQLServerException {
responseBuff = "adaptive";
else
responseBuff = "full";
- }
- else {
+ } else {
responseBuff = connection.getResponseBuffering();
}
loggerExternal.exiting(getClassNameLogging(), "getResponseBuffering", responseBuff);
@@ -2320,13 +2329,15 @@ public final String getResponseBuffering() throws SQLServerException {
}
}
+
/**
- * Helper class that does some basic parsing work for SQL statements that are stored procedure calls.
+ * Provides a helper class that does some basic parsing work for SQL statements that are stored procedure calls.
*
- * - Determines whether the SQL uses JDBC call syntax ("{[? =] call procedure_name...}") or T-SQL EXECUTE syntax ("EXEC [@p0 =] procedure_name...").
- * If JDBC call syntax is present, it gets rewritten as T-SQL EXECUTE syntax.
+ * - Determines whether the SQL uses JDBC call syntax ("{[? =] call procedure_name...}") or T-SQL EXECUTE syntax ("EXEC
+ * [@p0 =] procedure_name..."). If JDBC call syntax is present, it gets rewritten as T-SQL EXECUTE syntax.
*
- * - Determines whether the caller expects a return value from the stored procedure (see the optional return value syntax in [] above).
+ * - Determines whether the caller expects a return value from the stored procedure (see the optional return value
+ * syntax in [] above).
*
* - Extracts the stored procedure name from the call.
*
@@ -2346,16 +2357,17 @@ boolean hasReturnValueSyntax() {
}
/*
- * SQL Identifier regex
- *
- * Loosely follows the spec'd SQL identifier syntax: - anything between escape characters (square brackets or double quotes), including escaped
- * escape characters, OR - any contiguous string of non-whitespace characters. - including multipart identifiers
+ * SQL Identifier regex Loosely follows the spec'd SQL identifier syntax: - anything between escape characters
+ * (square brackets or double quotes), including escaped escape characters, OR - any contiguous string of
+ * non-whitespace characters. - including multipart identifiers
*/
private final static String sqlIdentifierPart = "(?:(?:\\[(?:[^\\]]|(?:\\]\\]))+?\\])|(?:\"(?:[^\"]|(?:\"\"))+?\")|(?:\\S+?))";
- private final static String sqlIdentifierWithoutGroups = "(" + sqlIdentifierPart + "(?:\\." + sqlIdentifierPart + "){0,3}?)";
+ private final static String sqlIdentifierWithoutGroups = "(" + sqlIdentifierPart + "(?:\\." + sqlIdentifierPart
+ + "){0,3}?)";
- private final static String sqlIdentifierWithGroups = "(" + sqlIdentifierPart + ")" + "(?:\\." + "(" + sqlIdentifierPart + "))?";
+ private final static String sqlIdentifierWithGroups = "(" + sqlIdentifierPart + ")" + "(?:\\." + "("
+ + sqlIdentifierPart + "))?";
// This is used in three part name matching.
static String getSQLIdentifierWithGroups() {
@@ -2363,30 +2375,23 @@ static String getSQLIdentifierWithGroups() {
}
/*
- * JDBC call syntax regex
- *
- * From the JDBC spec: {call procedure_name} {call procedure_name(?, ?, ...)} {? = call procedure_name[(?, ?, ...)]}
- *
- * allowing for arbitrary amounts of whitespace in the obvious places.
+ * JDBC call syntax regex From the JDBC spec: {call procedure_name} {call procedure_name(?, ?, ...)} {? = call
+ * procedure_name[(?, ?, ...)]} allowing for arbitrary amounts of whitespace in the obvious places.
*/
private final static Pattern jdbcCallSyntax = Pattern
- .compile("(?s)\\s*?\\{\\s*?(\\?\\s*?=)?\\s*?[cC][aA][lL][lL]\\s+?" + sqlIdentifierWithoutGroups + "(?:\\s*?\\((.*)\\))?\\s*\\}.*+");
+ .compile("(?s)\\s*?\\{\\s*?(\\?\\s*?=)?\\s*?[cC][aA][lL][lL]\\s+?" + sqlIdentifierWithoutGroups
+ + "(?:\\s*?\\((.*)\\))?\\s*\\}.*+");
/*
- * T-SQL EXECUTE syntax regex
- *
- * EXEC | EXECUTE [@return_result =] procedure_name [parameters]
- *
- * allowing for arbitrary amounts of whitespace in the obvious places.
+ * T-SQL EXECUTE syntax regex EXEC | EXECUTE [@return_result =] procedure_name [parameters] allowing for arbitrary
+ * amounts of whitespace in the obvious places.
*/
- private final static Pattern sqlExecSyntax = Pattern.compile("\\s*?[eE][xX][eE][cC](?:[uU][tT][eE])??\\s+?(" + sqlIdentifierWithoutGroups
- + "\\s*?=\\s+?)??" + sqlIdentifierWithoutGroups + "(?:$|(?:\\s+?.*+))");
+ private final static Pattern sqlExecSyntax = Pattern.compile("\\s*?[eE][xX][eE][cC](?:[uU][tT][eE])??\\s+?("
+ + sqlIdentifierWithoutGroups + "\\s*?=\\s+?)??" + sqlIdentifierWithoutGroups + "(?:$|(?:\\s+?.*+))");
/*
- * JDBC limit escape syntax
- *
- * From the JDBC spec: {LIMIT [OFFSET ]} The driver currently does not support the OFFSET part. It will throw an exception if
- * used.
+ * JDBC limit escape syntax From the JDBC spec: {LIMIT [OFFSET ]} The driver currently does not
+ * support the OFFSET part. It will throw an exception if used.
*/
enum State {
START,
@@ -2401,47 +2406,54 @@ enum State {
PROCESS
};
- // This pattern matches the LIMIT syntax with an OFFSET clause. The driver does not support OFFSET expression in the LIMIT clause.
+ // This pattern matches the LIMIT syntax with an OFFSET clause. The driver does not support OFFSET expression in the
+ // LIMIT clause.
// It will throw an exception if OFFSET is present in the LIMIT escape syntax.
private final static Pattern limitSyntaxWithOffset = Pattern
.compile("\\{\\s*[lL][iI][mM][iI][tT]\\s+(.*)\\s+[oO][fF][fF][sS][eE][tT]\\s+(.*)\\}");
- // This pattern is used to determine if the query has LIMIT escape syntax. If so, then the query is further processed to translate the syntax.
+ // This pattern is used to determine if the query has LIMIT escape syntax. If so, then the query is further
+ // processed to translate the syntax.
private final static Pattern limitSyntaxGeneric = Pattern
.compile("\\{\\s*[lL][iI][mM][iI][tT]\\s+(.*)(\\s+[oO][fF][fF][sS][eE][tT](.*)\\}|\\s*\\})");
private final static Pattern selectPattern = Pattern.compile("([sS][eE][lL][eE][cC][tT])\\s+");
// OPENQUERY ( linked_server ,'query' )
- private final static Pattern openQueryPattern = Pattern.compile("[oO][pP][eE][nN][qQ][uU][eE][rR][yY]\\s*\\(.*,\\s*'(.*)'\\s*\\)");
+ private final static Pattern openQueryPattern = Pattern
+ .compile("[oO][pP][eE][nN][qQ][uU][eE][rR][yY]\\s*\\(.*,\\s*'(.*)'\\s*\\)");
/*
- * OPENROWSET ( 'provider_name', { 'datasource' ; 'user_id' ; 'password' | 'provider_string' }, { [ catalog. ] [ schema. ] object | 'query' } )
+ * OPENROWSET ( 'provider_name', { 'datasource' ; 'user_id' ; 'password' | 'provider_string' }, { [ catalog. ] [
+ * schema. ] object | 'query' } )
*/
- private final static Pattern openRowsetPattern = Pattern.compile("[oO][pP][eE][nN][rR][oO][wW][sS][eE][tT]\\s*\\(.*,.*,\\s*'(.*)'\\s*\\)");
+ private final static Pattern openRowsetPattern = Pattern
+ .compile("[oO][pP][eE][nN][rR][oO][wW][sS][eE][tT]\\s*\\(.*,.*,\\s*'(.*)'\\s*\\)");
/*
* {limit 30} {limit ?} {limit (?)}
*/
- private final static Pattern limitOnlyPattern = Pattern.compile("\\{\\s*[lL][iI][mM][iI][tT]\\s+(((\\(|\\s)*)(\\d*|\\?)((\\)|\\s)*))\\s*\\}");
+ private final static Pattern limitOnlyPattern = Pattern
+ .compile("\\{\\s*[lL][iI][mM][iI][tT]\\s+(((\\(|\\s)*)(\\d*|\\?)((\\)|\\s)*))\\s*\\}");
/**
- * This function translates the LIMIT escape syntax, {LIMIT [OFFSET ]} SQL Server does not support LIMIT syntax, the LIMIT escape
- * syntax is thus translated to use "TOP" syntax The OFFSET clause is not supported, and will throw an exception if used.
+ * Translates the LIMIT escape syntax, {LIMIT [OFFSET ]} SQL Server does not support LIMIT syntax, the
+ * LIMIT escape syntax is thus translated to use "TOP" syntax The OFFSET clause is not supported, and will throw an
+ * exception if used.
*
- * @param sql the SQL query
+ * @param sql
+ * the SQL query
*
- * @param indx Position in the query from where to start translation
+ * @param indx
+ * Position in the query from where to start translation
*
- * @param endChar The character that marks the end of translation
+ * @param endChar
+ * The character that marks the end of translation
*
* @throws SQLServerException
*
* @return the number of characters that have been translated
*
*/
-
- int translateLimit(StringBuffer sql,
- int indx,
- char endChar) throws SQLServerException {
+ int translateLimit(StringBuffer sql, int indx, char endChar) throws SQLServerException {
Matcher selectMatcher = selectPattern.matcher(sql);
Matcher openQueryMatcher = openQueryPattern.matcher(sql);
Matcher openRowsetMatcher = openRowsetPattern.matcher(sql);
@@ -2460,39 +2472,40 @@ int translateLimit(StringBuffer sql,
nextState = State.PROCESS;
break;
case PROCESS:
- // The search for endChar should come before the search for quote (') as openquery has quote(') as the endChar
+ // The search for endChar should come before the search for quote (') as openquery has quote(') as
+ // the endChar
if (endChar == ch) {
nextState = State.END;
- }
- else if ('\'' == ch) {
+ } else if ('\'' == ch) {
nextState = State.QUOTE;
- }
- else if ('(' == ch) {
+ } else if ('(' == ch) {
nextState = State.SUBQUERY;
- }
- else if (limitMatcher.find(indx) && indx == limitMatcher.start()) {
+ } else if (limitMatcher.find(indx) && indx == limitMatcher.start()) {
nextState = State.LIMIT;
- }
- else if (offsetMatcher.find(indx) && indx == offsetMatcher.start()) {
+ } else if (offsetMatcher.find(indx) && indx == offsetMatcher.start()) {
nextState = State.OFFSET;
- }
- else if (openQueryMatcher.find(indx) && indx == openQueryMatcher.start()) {
+ } else if (openQueryMatcher.find(indx) && indx == openQueryMatcher.start()) {
nextState = State.OPENQUERY;
- }
- else if (openRowsetMatcher.find(indx) && indx == openRowsetMatcher.start()) {
+ } else if (openRowsetMatcher.find(indx) && indx == openRowsetMatcher.start()) {
nextState = State.OPENROWSET;
- }
- else if (selectMatcher.find(indx) && indx == selectMatcher.start()) {
+ } else if (selectMatcher.find(indx) && indx == selectMatcher.start()) {
nextState = State.SELECT;
- }
- else
+ } else
indx++;
break;
case OFFSET:
// throw exception as OFFSET is not supported
- throw new SQLServerException(SQLServerException.getErrString("R_limitOffsetNotSupported"), null, // SQLState is null as this error
- // is generated in the driver
- 0, // Use 0 instead of DriverError.NOT_SET to use the correct constructor
+ // SQLState is null as this error is generated in the driver
+ throw new SQLServerException(SQLServerException.getErrString("R_limitOffsetNotSupported"), null, 0, // Use
+ // 0
+ // instead
+ // of
+ // DriverError.NOT_SET
+ // to
+ // use
+ // the
+ // correct
+ // constructor
null);
case LIMIT:
// Check if the number of opening/closing parentheses surrounding the digits or "?" in LIMIT match
@@ -2509,17 +2522,17 @@ else if (selectMatcher.find(indx) && indx == selectMatcher.start()) {
closingParentheses++;
}
if (openingParentheses != closingParentheses) {
- throw new SQLServerException(SQLServerException.getErrString("R_limitEscapeSyntaxError"), null, // SQLState is null as this
- // error is generated in the
- // driver
+ // SQLState is null as this error is generated in the driver
+ throw new SQLServerException(SQLServerException.getErrString("R_limitEscapeSyntaxError"), null,
0, // Use 0 instead of DriverError.NOT_SET to use the correct constructor
null);
}
/*
- * 'topPosition' is a stack that keeps track of the positions where the next "TOP" should be inserted. The SELECT expressions are
- * matched with the closest LIMIT expressions unless in a subquery with explicit parentheses, that's why it needs to be a stack.
- * To translate, we add the clause after SELECT and delete the clause {LIMIT rows}.
+ * 'topPosition' is a stack that keeps track of the positions where the next "TOP" should be
+ * inserted. The SELECT expressions are matched with the closest LIMIT expressions unless in a
+ * subquery with explicit parentheses, that's why it needs to be a stack. To translate, we add the
+ * clause after SELECT and delete the clause {LIMIT rows}.
*/
if (!topPosition.empty()) {
Integer top = topPosition.pop();
@@ -2530,16 +2543,15 @@ else if (selectMatcher.find(indx) && indx == selectMatcher.start()) {
if ('?' == rows.charAt(0)) {
// For parameterized queries the '?' needs to wrapped in parentheses.
sql.insert(top, " TOP (" + rows + ")");
- // add the letters/spaces inserted with TOP, add the digits from LIMIT, subtract one because the
+ // add the letters/spaces inserted with TOP, add the digits from LIMIT, subtract one because
+ // the
// current letter at the index is deleted.
indx += 7 + rows.length() - 1;
- }
- else {
+ } else {
sql.insert(top, " TOP " + rows);
indx += 5 + rows.length() - 1;
}
- }
- else {
+ } else {
// Could not match LIMIT with a SELECT, should never occur.
// But if it does, just ignore
// Matcher.end() returns offset after the last character of matched string
@@ -2562,12 +2574,10 @@ else if (selectMatcher.find(indx) && indx == selectMatcher.start()) {
indx++;
if (sql.length() > indx && '\'' == sql.charAt(indx)) {
nextState = State.QUOTE;
- }
- else {
+ } else {
nextState = State.PROCESS;
}
- }
- else {
+ } else {
nextState = State.QUOTE;
}
break;
@@ -2599,7 +2609,7 @@ else if (selectMatcher.find(indx) && indx == selectMatcher.start()) {
// throw
break;
}
- }// end of while
+ } // end of while
return indx - startIndx;
}
@@ -2615,8 +2625,7 @@ String translate(String sql) throws SQLServerException {
procedureName = matcher.group(2);
String args = matcher.group(3);
sql = "EXEC " + (hasReturnValueSyntax ? "? = " : "") + procedureName + ((null != args) ? (" " + args) : "");
- }
- else {
+ } else {
matcher = sqlExecSyntax.matcher(sql);
if (matcher.matches()) {
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerStatementColumnEncryptionSetting.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerStatementColumnEncryptionSetting.java
index 078c4760c..b3bcb4a57 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerStatementColumnEncryptionSetting.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerStatementColumnEncryptionSetting.java
@@ -1,37 +1,35 @@
-/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
- */
-
-package com.microsoft.sqlserver.jdbc;
-
-/**
- * Specifies how data will be sent and received when reading and writing encrypted columns. Depending on your specific query, performance impact may
- * be reduced by bypassing the Always Encrypted driver processing when non-encrypted columns are being used. Note that these settings cannot be used
- * to bypass encryption and gain access to plaintext data.
- */
-public enum SQLServerStatementColumnEncryptionSetting {
- /**
- * if "Column Encryption Setting=Enabled" in the connection string, use Enabled. Otherwise, maps to Disabled.
- */
- UseConnectionSetting,
-
- /**
- * Enables TCE for the command. Overrides the connection level setting for this command.
- */
- Enabled,
-
- /**
- * Parameters will not be encrypted, only the ResultSet will be decrypted. This is an optimization for queries that do not pass any encrypted
- * input parameters. Overrides the connection level setting for this command.
- */
- ResultSetOnly,
-
- /**
- * Disables TCE for the command.Overrides the connection level setting for this command.
- */
- Disabled,
-}
+/*
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ */
+
+package com.microsoft.sqlserver.jdbc;
+
+/**
+ * Specifies how data will be sent and received when reading and writing encrypted columns. Depending on your specific
+ * query, performance impact may be reduced by bypassing the Always Encrypted driver processing when non-encrypted
+ * columns are being used. Note that these settings cannot be used to bypass encryption and gain access to plaintext
+ * data.
+ */
+public enum SQLServerStatementColumnEncryptionSetting {
+ /**
+ * if "Column Encryption Setting=Enabled" in the connection string, use Enabled. Otherwise, maps to Disabled.
+ */
+ UseConnectionSetting,
+
+ /**
+ * Enables TCE for the command. Overrides the connection level setting for this command.
+ */
+ Enabled,
+
+ /**
+ * Parameters will not be encrypted, only the ResultSet will be decrypted. This is an optimization for queries that
+ * do not pass any encrypted input parameters. Overrides the connection level setting for this command.
+ */
+ ResultSetOnly,
+
+ /**
+ * Disables TCE for the command.Overrides the connection level setting for this command.
+ */
+ Disabled,
+}
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerSymmetricKey.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerSymmetricKey.java
index 12e20a56c..5552e9707 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerSymmetricKey.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerSymmetricKey.java
@@ -1,42 +1,40 @@
-/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
- */
-
-package com.microsoft.sqlserver.jdbc;
-
-/**
- *
- * Base class which represents Symmetric key
- *
- */
-class SQLServerSymmetricKey {
- private byte[] rootKey;
-
- SQLServerSymmetricKey(byte[] rootKey) throws SQLServerException {
- if (null == rootKey) {
- throw new SQLServerException(this, SQLServerException.getErrString("R_NullColumnEncryptionKey"), null, 0, false);
- }
- else if (0 == rootKey.length) {
- throw new SQLServerException(this, SQLServerException.getErrString("R_EmptyColumnEncryptionKey"), null, 0, false);
- }
- this.rootKey = rootKey;
- }
-
- byte[] getRootKey() {
- return rootKey;
- }
-
- int length() {
- return rootKey.length;
- }
-
- void zeroOutKey() {
- for (int i = 0; i < rootKey.length; i++) {
- rootKey[i] = (byte) 0;
- }
- }
-}
+/*
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ */
+
+package com.microsoft.sqlserver.jdbc;
+
+/**
+ *
+ * Base class which represents Symmetric key
+ *
+ */
+class SQLServerSymmetricKey {
+ private byte[] rootKey;
+
+ SQLServerSymmetricKey(byte[] rootKey) throws SQLServerException {
+ if (null == rootKey) {
+ throw new SQLServerException(this, SQLServerException.getErrString("R_NullColumnEncryptionKey"), null, 0,
+ false);
+ } else if (0 == rootKey.length) {
+ throw new SQLServerException(this, SQLServerException.getErrString("R_EmptyColumnEncryptionKey"), null, 0,
+ false);
+ }
+ this.rootKey = rootKey;
+ }
+
+ byte[] getRootKey() {
+ return rootKey;
+ }
+
+ int length() {
+ return rootKey.length;
+ }
+
+ void zeroOutKey() {
+ for (int i = 0; i < rootKey.length; i++) {
+ rootKey[i] = (byte) 0;
+ }
+ }
+}
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerSymmetricKeyCache.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerSymmetricKeyCache.java
index 04f9335ff..80eb9a03a 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerSymmetricKeyCache.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerSymmetricKeyCache.java
@@ -1,173 +1,180 @@
-/*
- * Microsoft JDBC Driver for SQL Server
- *
- * Copyright(c) Microsoft Corporation All rights reserved.
- *
- * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
- */
-
-package com.microsoft.sqlserver.jdbc;
-
-import static java.nio.charset.StandardCharsets.UTF_8;
-import static java.util.concurrent.TimeUnit.SECONDS;
-
-import java.text.MessageFormat;
-import java.util.List;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.ThreadFactory;
-
-import java.util.Base64;;
-
-class CacheClear implements Runnable {
-
- private String keylookupValue;
- static private java.util.logging.Logger aeLogger = java.util.logging.Logger.getLogger("com.microsoft.sqlserver.jdbc.CacheClear");
-
- CacheClear(String keylookupValue) {
- this.keylookupValue = keylookupValue;
- }
-
- @Override
- public void run() {
- // remove() is a no-op if the key is not in the map.
- // It is a concurrentHashMap, update/remove operations are thread safe.
- synchronized (SQLServerSymmetricKeyCache.lock) {
- SQLServerSymmetricKeyCache instance = SQLServerSymmetricKeyCache.getInstance();
- if (instance.getCache().containsKey(keylookupValue)) {
- instance.getCache().get(keylookupValue).zeroOutKey();
- instance.getCache().remove(keylookupValue);
- if (aeLogger.isLoggable(java.util.logging.Level.FINE)) {
- aeLogger.fine("Removed encryption key from cache...");
- }
- }
- }
- }
-}
-
-/**
- *
- * Cache for the Symmetric keys
- *
- */
-final class SQLServerSymmetricKeyCache {
- static Object lock = new Object();
- private final ConcurrentHashMap cache;
- private static final SQLServerSymmetricKeyCache instance = new SQLServerSymmetricKeyCache();
- private static ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1, new ThreadFactory() {
- @Override
- public Thread newThread(Runnable r) {
- Thread t = Executors.defaultThreadFactory().newThread(r);
- t.setDaemon(true);
- return t;
- }
- });
-
- static final private java.util.logging.Logger aeLogger = java.util.logging.Logger
- .getLogger("com.microsoft.sqlserver.jdbc.SQLServerSymmetricKeyCache");
-
- private SQLServerSymmetricKeyCache() {
- cache = new ConcurrentHashMap<>();
- }
-
- static SQLServerSymmetricKeyCache getInstance() {
- return instance;
- }
-
- ConcurrentHashMap getCache() {
- return cache;
- }
-
- /**
- * Retrieves key
- *
- * @param keyInfo
- * contains encryption meta data information
- * @param connection
- * @return plain text key
- */
- SQLServerSymmetricKey getKey(EncryptionKeyInfo keyInfo,
- SQLServerConnection connection) throws SQLServerException {
- SQLServerSymmetricKey encryptionKey = null;
- synchronized (lock) {
- String serverName = connection.getTrustedServerNameAE();
- assert null != serverName : "serverName should not be null in getKey.";
-
- StringBuilder keyLookupValuebuffer = new StringBuilder(serverName);
- String keyLookupValue;
- keyLookupValuebuffer.append(":");
-
- keyLookupValuebuffer.append(Base64.getEncoder().encodeToString((new String(keyInfo.encryptedKey, UTF_8)).getBytes()));
-
- keyLookupValuebuffer.append(":");
- keyLookupValuebuffer.append(keyInfo.keyStoreName);
- keyLookupValue = keyLookupValuebuffer.toString();
- keyLookupValuebuffer.setLength(0); // Get rid of the buffer, will be garbage collected.
-
- if (aeLogger.isLoggable(java.util.logging.Level.FINE)) {
- aeLogger.fine("Checking trusted master key path...");
- }
- Boolean[] hasEntry = new Boolean[1];
- List trustedKeyPaths = SQLServerConnection.getColumnEncryptionTrustedMasterKeyPaths(serverName, hasEntry);
- if (hasEntry[0]) {
- if ((null == trustedKeyPaths) || (0 == trustedKeyPaths.size()) || (!trustedKeyPaths.contains(keyInfo.keyPath))) {
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_UntrustedKeyPath"));
- Object[] msgArgs = {keyInfo.keyPath, serverName};
- throw new SQLServerException(this, form.format(msgArgs), null, 0, false);
- }
- }
-
- if (aeLogger.isLoggable(java.util.logging.Level.FINE)) {
- aeLogger.fine("Checking Symmetric key cache...");
- }
-
- // if ColumnEncryptionKeyCacheTtl is 0 no caching at all
- if (!cache.containsKey(keyLookupValue)) {
-
- // Check for the connection provider first.
- SQLServerColumnEncryptionKeyStoreProvider provider = connection.getSystemColumnEncryptionKeyStoreProvider(keyInfo.keyStoreName);
-
- // There is no connection provider of this name, check for the global system providers.
- if (null == provider) {
- provider = SQLServerConnection.getGlobalSystemColumnEncryptionKeyStoreProvider(keyInfo.keyStoreName);
- }
-
- // There is no global system provider of this name, check for the global custom providers.
- if (null == provider) {
- provider = SQLServerConnection.getGlobalCustomColumnEncryptionKeyStoreProvider(keyInfo.keyStoreName);
- }
-
- // No provider was found of this name.
- if (null == provider) {
- String systemProviders = connection.getAllSystemColumnEncryptionKeyStoreProviders();
- String customProviders = SQLServerConnection.getAllGlobalCustomSystemColumnEncryptionKeyStoreProviders();
- MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_UnrecognizedKeyStoreProviderName"));
- Object[] msgArgs = {keyInfo.keyStoreName, systemProviders, customProviders};
- throw new SQLServerException(this, form.format(msgArgs), null, 0, false);
- }
-
- byte[] plaintextKey;
- plaintextKey = provider.decryptColumnEncryptionKey(keyInfo.keyPath, keyInfo.algorithmName, keyInfo.encryptedKey);
- encryptionKey = new SQLServerSymmetricKey(plaintextKey);
-
- /*
- * a ColumnEncryptionKeyCacheTtl value of '0' means no caching at all. The expected use case is to have the application set it once.
- * The application could set it multiple times, in which case a key gets the TTL defined at the time of its entry into the cache.
- */
- long columnEncryptionKeyCacheTtl = SQLServerConnection.getColumnEncryptionKeyCacheTtl();
- if (0 != columnEncryptionKeyCacheTtl) {
- cache.putIfAbsent(keyLookupValue, encryptionKey);
- if (aeLogger.isLoggable(java.util.logging.Level.FINE)) {
- aeLogger.fine("Adding encryption key to cache...");
- }
- scheduler.schedule(new CacheClear(keyLookupValue), columnEncryptionKeyCacheTtl, SECONDS);
- }
- }
- else {
- encryptionKey = cache.get(keyLookupValue);
- }
- }
- return encryptionKey;
- }
-}
+/*
+ * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
+ * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
+ */
+
+package com.microsoft.sqlserver.jdbc;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static java.util.concurrent.TimeUnit.SECONDS;
+
+import java.text.MessageFormat;
+import java.util.Base64;
+import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ThreadFactory;;
+
+
+class CacheClear implements Runnable {
+
+ private String keylookupValue;
+ static private java.util.logging.Logger aeLogger = java.util.logging.Logger
+ .getLogger("com.microsoft.sqlserver.jdbc.CacheClear");
+
+ CacheClear(String keylookupValue) {
+ this.keylookupValue = keylookupValue;
+ }
+
+ @Override
+ public void run() {
+ // remove() is a no-op if the key is not in the map.
+ // It is a concurrentHashMap, update/remove operations are thread safe.
+ synchronized (SQLServerSymmetricKeyCache.lock) {
+ SQLServerSymmetricKeyCache instance = SQLServerSymmetricKeyCache.getInstance();
+ if (instance.getCache().containsKey(keylookupValue)) {
+ instance.getCache().get(keylookupValue).zeroOutKey();
+ instance.getCache().remove(keylookupValue);
+ if (aeLogger.isLoggable(java.util.logging.Level.FINE)) {
+ aeLogger.fine("Removed encryption key from cache...");
+ }
+ }
+ }
+ }
+}
+
+
+/**
+ *
+ * Cache for the Symmetric keys
+ *
+ */
+final class SQLServerSymmetricKeyCache {
+ static Object lock = new Object();
+ private final ConcurrentHashMap