Skip to content

Commit

Permalink
Merge pull request #566 from v-afrafi/Java9
Browse files Browse the repository at this point in the history
Java 9 Updates for JDBC4.3 branch only
  • Loading branch information
AfsanehR-zz authored Nov 29, 2017
2 parents 6f9fec6 + 778d3ee commit 8c7f465
Show file tree
Hide file tree
Showing 19 changed files with 422 additions and 96 deletions.
10 changes: 8 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
sudo: required

language: java
jdk:
- oraclejdk8
sudo: false
dist: trusty
jdk: oraclejdk9

addons:
apt:
packages:
- oracle-java9-installer

services:
- docker

Expand Down
10 changes: 5 additions & 5 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ build_script:
- keytool -importkeystore -srckeystore cert.pfx -srcstoretype pkcs12 -destkeystore clientcert.jks -deststoretype JKS -srcstorepass password -deststorepass password
- keytool -list -v -keystore clientcert.jks -storepass "password" > JavaKeyStore.txt
- cd..
- mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V -Pbuild41
- mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V -Pbuild42
# - mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V -Pbuild41
# - mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V -Pbuild42

test_script:
- mvn test -B -Pbuild41
- mvn test -B -Pbuild42
#test_script:
# - mvn test -B -Pbuild41
# - mvn test -B -Pbuild42
36 changes: 17 additions & 19 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.platform.version>1.0.0-M3</junit.platform.version>
<junit.platform.version>1.1.0-M1</junit.platform.version>
<junit.jupiter.version>5.0.0-M3</junit.jupiter.version>
</properties>

Expand All @@ -54,7 +54,7 @@
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>adal4j</artifactId>
<version>1.2.0</version>
<version>1.3.0</version>
<optional>true</optional>
</dependency>

Expand Down Expand Up @@ -117,7 +117,7 @@
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>2.6.1</version>
<version>2.7.4</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -138,10 +138,10 @@

<profiles>
<profile>
<id>build41</id>
<id>build42</id>

<properties>
<jreVersion>jre7</jreVersion>
<jreVersion>jre8</jreVersion>
</properties>

<build>
Expand All @@ -151,10 +151,10 @@
<version>3.6.0</version>
<configuration>
<excludes>
<exclude>**/com/microsoft/sqlserver/jdbc/SQLServerJdbc42.java</exclude>
<exclude>**/com/microsoft/sqlserver/jdbc/SQLServerJdbc43.java</exclude>
</excludes>
<source>1.7</source>
<target>1.7</target>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
Expand All @@ -166,21 +166,19 @@
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>

</plugin>
</plugins>
</build>
</profile>

<profile>
<id>build42</id>

<id>build43</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>

<properties>
<jreVersion>jre8</jreVersion>
<jreVersion>jre9</jreVersion>
</properties>

<build>
Expand All @@ -190,10 +188,10 @@
<version>3.6.0</version>
<configuration>
<excludes>
<exclude>**/com/microsoft/sqlserver/jdbc/SQLServerJdbc41.java</exclude>
<exclude>**/com/microsoft/sqlserver/jdbc/SQLServerJdbc42.java</exclude>
</excludes>
<source>1.8</source>
<target>1.8</target>
<source>9</source>
<target>9</target>
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -278,7 +276,7 @@
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>3.2.0</version>
<version>3.3.0</version>
<extensions>true</extensions>
<configuration>
<instructions>
Expand All @@ -300,7 +298,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.4</version>
<version>3.0.0-M1</version>

<configuration>
<failOnError>true</failOnError>
Expand Down
63 changes: 30 additions & 33 deletions src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;
import javax.xml.bind.DatatypeConverter;
import java.nio.Buffer;

final class TDS {
// TDS protocol versions
Expand Down Expand Up @@ -3112,7 +3112,7 @@ boolean isEOMSent() {
void preparePacket() throws SQLServerException {
if (tdsChannel.isLoggingPackets()) {
Arrays.fill(logBuffer.array(), (byte) 0xFE);
logBuffer.clear();
((Buffer)logBuffer).clear();
}

// Write a placeholder packet header. This will be replaced
Expand Down Expand Up @@ -3188,8 +3188,8 @@ void startMessage(TDSCommand command,
currentPacketSize = negotiatedPacketSize;
}

socketBuffer.position(socketBuffer.limit());
stagingBuffer.clear();
((Buffer) socketBuffer).position(((Buffer) socketBuffer).limit());
((Buffer)stagingBuffer).clear();

preparePacket();
writeMessageHeader();
Expand Down Expand Up @@ -3231,7 +3231,7 @@ void writeByte(byte value) throws SQLServerException {
if (dataIsLoggable)
logBuffer.put(value);
else
logBuffer.position(logBuffer.position() + 1);
((Buffer)logBuffer).position(((Buffer)logBuffer).position() + 1);
}
}
else {
Expand All @@ -3258,7 +3258,7 @@ void writeChar(char value) throws SQLServerException {
if (dataIsLoggable)
logBuffer.putChar(value);
else
logBuffer.position(logBuffer.position() + 2);
((Buffer)logBuffer).position( ((Buffer)logBuffer).position() + 2);
}
}
else {
Expand All @@ -3274,7 +3274,7 @@ void writeShort(short value) throws SQLServerException {
if (dataIsLoggable)
logBuffer.putShort(value);
else
logBuffer.position(logBuffer.position() + 2);
((Buffer)logBuffer).position( ((Buffer)logBuffer).position() + 2);
}
}
else {
Expand All @@ -3290,7 +3290,7 @@ void writeInt(int value) throws SQLServerException {
if (dataIsLoggable)
logBuffer.putInt(value);
else
logBuffer.position(logBuffer.position() + 4);
((Buffer)logBuffer).position( ((Buffer)logBuffer).position() + 4);
}
}
else {
Expand Down Expand Up @@ -3322,7 +3322,7 @@ void writeDouble(double value) throws SQLServerException {
if (dataIsLoggable)
logBuffer.putDouble(value);
else
logBuffer.position(logBuffer.position() + 8);
((Buffer)logBuffer).position( ((Buffer)logBuffer).position() + 8);
}
}
else {
Expand Down Expand Up @@ -3700,7 +3700,7 @@ void writeLong(long value) throws SQLServerException {
if (dataIsLoggable)
logBuffer.putLong(value);
else
logBuffer.position(logBuffer.position() + 8);
((Buffer)logBuffer).position( ((Buffer)logBuffer).position() + 8);
}
}
else {
Expand Down Expand Up @@ -3743,7 +3743,7 @@ void writeBytes(byte[] value,
if (dataIsLoggable)
logBuffer.put(value, offset + bytesWritten, bytesToWrite);
else
logBuffer.position(logBuffer.position() + bytesToWrite);
((Buffer)logBuffer).position( ((Buffer)logBuffer).position() + bytesToWrite);
}

bytesWritten += bytesToWrite;
Expand All @@ -3770,7 +3770,7 @@ void writeWrappedBytes(byte value[],
if (dataIsLoggable)
logBuffer.put(value, 0, remaining);
else
logBuffer.position(logBuffer.position() + remaining);
((Buffer)logBuffer).position( ((Buffer)logBuffer).position() + remaining);
}
}

Expand All @@ -3783,7 +3783,7 @@ void writeWrappedBytes(byte value[],
if (dataIsLoggable)
logBuffer.put(value, remaining, valueLength - remaining);
else
logBuffer.position(logBuffer.position() + remaining);
((Buffer)logBuffer).position( ((Buffer)logBuffer).position() + remaining);
}
}

Expand Down Expand Up @@ -4105,7 +4105,7 @@ private void writePacket(int tdsMessageStatus) throws SQLServerException {
}

private void writePacketHeader(int tdsMessageStatus) {
int tdsMessageLength = stagingBuffer.position();
int tdsMessageLength = ((Buffer)stagingBuffer).position();
++packetNum;

// Write the TDS packet header back at the start of the staging buffer
Expand Down Expand Up @@ -4133,13 +4133,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(), socketBuffer.position(), socketBuffer.remaining());
socketBuffer.position(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 (stagingBuffer.position() >= TDS_PACKET_HEADER_SIZE) {
if (((Buffer)stagingBuffer).position() >= TDS_PACKET_HEADER_SIZE) {
// Swap the packet buffers ...
ByteBuffer swapBuffer = stagingBuffer;
stagingBuffer = socketBuffer;
Expand All @@ -4151,23 +4151,23 @@ 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.
socketBuffer.flip();
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.
if (tdsChannel.isLoggingPackets()) {
tdsChannel.logPacket(logBuffer.array(), 0, socketBuffer.limit(),
this.toString() + " sending packet (" + socketBuffer.limit() + " bytes)");
tdsChannel.logPacket(logBuffer.array(), 0, ((Buffer) socketBuffer).limit(),
this.toString() + " sending packet (" + ((Buffer) socketBuffer).limit() + " bytes)");
}

// Prepare for the next packet
if (!atEOM)
preparePacket();

// Finally, start sending data from the new socket buffer.
tdsChannel.write(socketBuffer.array(), socketBuffer.position(), socketBuffer.remaining());
socketBuffer.position(socketBuffer.limit());
tdsChannel.write(socketBuffer.array(), ((Buffer)socketBuffer).position(), socketBuffer.remaining());
((Buffer)socketBuffer).position( ((Buffer)socketBuffer).limit());
}
}

Expand Down Expand Up @@ -4630,7 +4630,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, stagingBuffer.position());
cachedTVPHeaders.put(stagingBuffer.array(), 0, ((Buffer)stagingBuffer).position());

cachedCommand = this.command;

Expand All @@ -4656,9 +4656,9 @@ void writeTVPRows(TVP value) throws SQLServerException {
if (tdsWritterCached) {
command = cachedCommand;

stagingBuffer.clear();
logBuffer.clear();
writeBytes(cachedTVPHeaders.array(), 0, cachedTVPHeaders.position());
((Buffer)stagingBuffer).clear();
((Buffer)logBuffer).clear();
writeBytes(cachedTVPHeaders.array(), 0, ((Buffer)cachedTVPHeaders).position());
}

Object[] rowData = value.getRowData();
Expand Down Expand Up @@ -4957,7 +4957,7 @@ else if (DataTypes.UNKNOWN_STREAM_LENGTH == dataLength)
isShortValue = columnPair.getValue().precision <= DataTypes.SHORT_VARTYPE_MAX_BYTES;
isNull = (null == currentObject);
if (currentObject instanceof String)
dataLength = isNull ? 0 : (toByteArray(currentObject.toString())).length;
dataLength = isNull ? 0 : (ParameterUtils.HexToBin(currentObject.toString())).length;
else
dataLength = isNull ? 0 : ((byte[]) currentObject).length;
if (!isShortValue) {
Expand All @@ -4976,7 +4976,7 @@ else if (DataTypes.UNKNOWN_STREAM_LENGTH == dataLength)
if (dataLength > 0) {
writeInt(dataLength);
if (currentObject instanceof String)
writeBytes(toByteArray(currentObject.toString()));
writeBytes(ParameterUtils.HexToBin(currentObject.toString()));
else
writeBytes((byte[]) currentObject);
}
Expand All @@ -4990,7 +4990,7 @@ else if (DataTypes.UNKNOWN_STREAM_LENGTH == dataLength)
else {
writeShort((short) dataLength);
if (currentObject instanceof String)
writeBytes(toByteArray(currentObject.toString()));
writeBytes(ParameterUtils.HexToBin(currentObject.toString()));
else
writeBytes((byte[]) currentObject);
}
Expand Down Expand Up @@ -5027,9 +5027,6 @@ private void writeTVPSqlVariantHeader(int length,
writeByte(probBytes);
}

private static byte[] toByteArray(String s) {
return DatatypeConverter.parseHexBinary(s);
}

void writeTVPColumnMetaData(TVP value) throws SQLServerException {
boolean isShortValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@

import java.text.MessageFormat;
import java.util.concurrent.ConcurrentHashMap;

import javax.xml.bind.DatatypeConverter;
import java.util.Base64;

/**
* Factory for SQLServerAeadAes256CbcHmac256Algorithm
Expand All @@ -38,7 +37,7 @@ SQLServerEncryptionAlgorithm create(SQLServerSymmetricKey columnEncryptionKey,
}

StringBuilder factoryKeyBuilder = new StringBuilder();
factoryKeyBuilder.append(DatatypeConverter.printBase64Binary(new String(columnEncryptionKey.getRootKey(), UTF_8).getBytes()));
factoryKeyBuilder.append(Base64.getEncoder().encode(new String(columnEncryptionKey.getRootKey(), UTF_8).getBytes()));

factoryKeyBuilder.append(":");
factoryKeyBuilder.append(encryptionType);
Expand Down
Loading

0 comments on commit 8c7f465

Please sign in to comment.