Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update changes from dev #992

Merged
merged 8 commits into from
Mar 18, 2019
22 changes: 11 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,16 @@ dependencies {
'com.microsoft.azure:azure-keyvault-webkey:1.2.0',
'com.microsoft.rest:client-runtime:1.6.5',
'com.microsoft.azure:adal4j:1.6.3'
testCompile 'org.junit.platform:junit-platform-console:1.3.2',
'org.junit.platform:junit-platform-commons:1.3.2',
'org.junit.platform:junit-platform-engine:1.3.2',
'org.junit.platform:junit-platform-launcher:1.3.2',
'org.junit.platform:junit-platform-runner:1.3.2',
testCompile 'org.junit.platform:junit-platform-console:1.4.0',
'org.junit.platform:junit-platform-commons:1.4.0',
'org.junit.platform:junit-platform-engine:1.4.0',
'org.junit.platform:junit-platform-launcher:1.4.0',
'org.junit.platform:junit-platform-runner:1.4.0',
'org.junit.platform:junit-platform-surefire-provider:1.3.2',
'org.junit.jupiter:junit-jupiter-api:5.3.2',
'org.junit.jupiter:junit-jupiter-engine:5.3.2',
'com.zaxxer:HikariCP:3.2.0',
'org.apache.commons:commons-dbcp2:2.5.0',
'org.slf4j:slf4j-nop:1.7.25',
'org.eclipse.gemini.blueprint:gemini-blueprint-mock:2.0.0.RELEASE'
'org.junit.jupiter:junit-jupiter-api:5.4.0',
'org.junit.jupiter:junit-jupiter-engine:5.4.0',
'com.zaxxer:HikariCP:3.3.1',
'org.apache.commons:commons-dbcp2:2.6.0',
'org.slf4j:slf4j-nop:1.7.26',
'org.eclipse.gemini.blueprint:gemini-blueprint-mock:2.1.0.RELEASE'
}
30 changes: 20 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,35 +39,44 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.platform.version>1.3.2</junit.platform.version>
<junit.jupiter.version>5.3.2</junit.jupiter.version>
<testGroup></testGroup>
<!-- Driver Dependencies -->
<azure.keyvault.version>1.2.0</azure.keyvault.version>
<azure.adal4j.version>1.6.3</azure.adal4j.version>
<rest.client.version>1.6.5</rest.client.version>
<osgi.version>4.3.1</osgi.version>
<!-- JUnit Test Dependencies -->
<junit.platform.version>[1.3.2,1.4.0]</junit.platform.version>
<junit.jupiter.version>5.4.0</junit.jupiter.version>
<hikaricp.version>3.3.1</hikaricp.version>
<dbcp2.version>2.6.0</dbcp2.version>
<slf4j.nop.version>1.7.26</slf4j.nop.version>
<gemini.mock.version>2.1.0.RELEASE</gemini.mock.version>
</properties>

<dependencies>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-keyvault</artifactId>
<version>1.2.0</version>
<version>${azure.keyvault.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-keyvault-webkey</artifactId>
<version>1.2.0</version>
<version>${azure.keyvault.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>adal4j</artifactId>
<version>1.6.3</version>
<version>${azure.adal4j.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.microsoft.rest</groupId>
<artifactId>client-runtime</artifactId>
<version>1.6.5</version>
<version>${rest.client.version}</version>
<optional>true</optional>
</dependency>

Expand Down Expand Up @@ -137,25 +146,25 @@
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>3.2.0</version>
<version>${hikaricp.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2 </artifactId>
<version>2.5.0</version>
<version>${dbcp2.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
<version>1.7.25</version>
<version>${slf4j.nop.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.gemini.blueprint</groupId>
<artifactId>gemini-blueprint-mock</artifactId>
<version>2.0.0.RELEASE</version>
<version>${gemini.mock.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down Expand Up @@ -407,6 +416,7 @@
<version>3.0.0</version>
<configuration>
<failOnError>true</failOnError>
<excludePackageNames>mssql.googlecode.*</excludePackageNames>
</configuration>
<executions>
<execution>
Expand Down
21 changes: 17 additions & 4 deletions src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkCopy.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import java.util.logging.Level;

import javax.sql.RowSet;
import javax.sql.XAConnection;

import microsoft.sql.DateTimeOffset;

Expand Down Expand Up @@ -888,6 +887,7 @@ private void writeTypeInfo(TDSWriter tdsWriter, int srcJdbcType, int srcScale, i
}
break;

case java.sql.Types.FLOAT:
case java.sql.Types.DOUBLE: // (FLT8TYPE) 0x3E
if (!srcNullable) {
tdsWriter.writeByte(TDSType.FLOAT8.byteValue());
Expand Down Expand Up @@ -1244,6 +1244,7 @@ private String getDestTypeFromSrcType(int srcColIndx, int destColIndx,
case java.sql.Types.TINYINT:
return "tinyint";

case java.sql.Types.FLOAT:
case java.sql.Types.DOUBLE:
return "float";

Expand Down Expand Up @@ -1929,6 +1930,7 @@ private void writeNullToTdsWriter(TDSWriter tdsWriter, int srcJdbcType,
case java.sql.Types.BIGINT:
case java.sql.Types.REAL:
case java.sql.Types.DOUBLE:
case java.sql.Types.FLOAT:
case java.sql.Types.DECIMAL:
case java.sql.Types.NUMERIC:
case java.sql.Types.TIMESTAMP:
Expand Down Expand Up @@ -2051,6 +2053,17 @@ else if (null != sourceCryptoMeta) {
}
break;

case java.sql.Types.FLOAT:
if (null == colValue) {
writeNullToTdsWriter(tdsWriter, bulkJdbcType, isStreaming);
} else {
if (bulkNullable) {
tdsWriter.writeByte((byte) 0x08);
}
tdsWriter.writeDouble((float) colValue);
}
break;

case java.sql.Types.DOUBLE:
if (null == colValue) {
writeNullToTdsWriter(tdsWriter, bulkJdbcType, isStreaming);
Expand Down Expand Up @@ -2701,6 +2714,7 @@ private Object readColumnFromResultSet(int srcColOrdinal, int srcJdbcType, boole
case java.sql.Types.TINYINT:
case java.sql.Types.DOUBLE:
case java.sql.Types.REAL:
case java.sql.Types.FLOAT:
return sourceResultSet.getObject(srcColOrdinal);

case microsoft.sql.Types.MONEY:
Expand Down Expand Up @@ -3334,12 +3348,11 @@ private byte[] normalizedValue(JDBCType destJdbcType, Object value, JDBCType src
return ((String) value).getBytes(UTF_16LE);

case REAL:
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();


case FLOAT:
case DOUBLE:
Double doubleValue = (value instanceof String) ? Double.parseDouble((String) value)
: (Double) value;
Expand Down
118 changes: 77 additions & 41 deletions src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,12 @@ public class SQLServerConnection implements ISQLServerConnection, java.io.Serial

private String originalHostNameInCertificate = null;

final int ENGINE_EDITION_FOR_SQL_AZURE = 5;
final int ENGINE_EDITION_FOR_SQL_AZURE_DW = 6;
final int ENGINE_EDITION_FOR_SQL_AZURE_MI = 8;
private Boolean isAzure = null;
private Boolean isAzureDW = null;
private Boolean isAzureMI = null;

private SharedTimer sharedTimer;

Expand Down Expand Up @@ -3164,16 +3169,10 @@ public void rollback() throws SQLServerException {
public void abort(Executor executor) throws SQLException {
loggerExternal.entering(getClassNameLogging(), "abort", executor);

// nop if connection is closed
// no-op if connection is closed
if (isClosed())
return;

if (null == executor) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidArgument"));
Object[] msgArgs = {"executor"};
SQLServerException.makeFromDriverError(null, null, form.format(msgArgs), null, false);
}

// check for callAbort permission
SecurityManager secMgr = System.getSecurityManager();
if (secMgr != null) {
Expand All @@ -3186,11 +3185,20 @@ public void abort(Executor executor) throws SQLException {
SQLServerException.makeFromDriverError(this, this, form.format(msgArgs), null, true);
}
}
if (null == executor) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidArgument"));
Object[] msgArgs = {"executor"};
SQLServerException.makeFromDriverError(null, null, form.format(msgArgs), null, false);
} else {

setState(State.Closed);
/*
* Always report the connection as closed for any further use, no matter what happens when we try to clean
* up the physical resources associated with the connection using executor.
*/
setState(State.Closed);

if (null != tdsChannel && null != executor)
executor.execute(() -> tdsChannel.close());
executor.execute(() -> clearConnectionResources());
}

loggerExternal.exiting(getClassNameLogging(), "abort");
}
Expand All @@ -3199,19 +3207,27 @@ public void abort(Executor executor) throws SQLException {
public void close() throws SQLServerException {
loggerExternal.entering(getClassNameLogging(), "close");

// Always report the connection as closed for any further use, no matter
// what happens when we try to clean up the physical resources associated
// with the connection.
/*
* Always report the connection as closed for any further use, no matter what happens when we try to clean up
* the physical resources associated with the connection.
*/
setState(State.Closed);

clearConnectionResources();

loggerExternal.exiting(getClassNameLogging(), "close");
}

private void clearConnectionResources() {
if (sharedTimer != null) {
sharedTimer.removeRef();
sharedTimer = null;
}

// Close the TDS channel. When the channel is closed, the server automatically
// rolls back any pending transactions and closes associated resources like
// prepared handles.
/*
* Close the TDS channel. When the channel is closed, the server automatically rolls back any pending
* transactions and closes associated resources like prepared handles.
*/
if (null != tdsChannel) {
tdsChannel.close();
}
Expand All @@ -3227,8 +3243,6 @@ public void close() throws SQLServerException {
cleanupPreparedStatementDiscardActions();

ActivityCorrelator.cleanupActivityId();

loggerExternal.exiting(getClassNameLogging(), "close");
}

// This function is used by the proxy for notifying the pool manager that this connection proxy is closed
Expand Down Expand Up @@ -6227,35 +6241,57 @@ public void onEviction(CityHash128Key key, PreparedStatementHandle handle) {
}
}
}

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
// 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.)
// 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
// 6 = SQL Azure DW
// Base data type: int
final int ENGINE_EDITION_FOR_SQL_AZURE_DW = 6;

/*
* 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.)
* 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
* 6 = SQL Azure DW
* 8 = Managed Instance
* Base data type: int
*/
boolean isAzure() {
if (null == isAzure) {
try (Statement stmt = this.createStatement(); ResultSet rs = stmt.executeQuery("SELECT CAST(SERVERPROPERTY('EngineEdition') as INT)")) {
rs.next();
isAzureDW = rs.getInt(1) == ENGINE_EDITION_FOR_SQL_AZURE_DW;

int engineEdition = rs.getInt(1);
isAzure = (engineEdition == ENGINE_EDITION_FOR_SQL_AZURE || engineEdition == ENGINE_EDITION_FOR_SQL_AZURE_DW || engineEdition == ENGINE_EDITION_FOR_SQL_AZURE_MI);
isAzureDW = (engineEdition == ENGINE_EDITION_FOR_SQL_AZURE_DW);
isAzureMI = (engineEdition == ENGINE_EDITION_FOR_SQL_AZURE_MI);

} catch (SQLException e) {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.log(Level.FINER, this + ": Error retrieving server type", e);
isAzure = false;
isAzureDW = false;
isAzureMI = false;
}
return isAzureDW;
return isAzure;
} else {
return isAzureDW;
return isAzure;
}
}

boolean isAzureDW() {
isAzure();
return isAzureDW;
}

boolean isAzureMI() {
isAzure();
return isAzureMI;
}

/**
* Adds statement to openStatements
*
Expand Down
Loading