Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/)

## [9.1.1] Preview Release
### Added
- Added maxResultBuffer connection property [1431](https://github.com/microsoft/mssql-jdbc/pull/1431)
- Added support for Service Principal Authentication [1456](https://github.com/microsoft/mssql-jdbc/pull/1456)
- Added support for Azure Active Directory Interactive Authentication [1464](https://github.com/microsoft/mssql-jdbc/pull/1464)

### Changed
- Enabled useBulkCopyForBatchInsert against non Azure SQL Data Warehouse servers [#1465](https://github.com/microsoft/mssql-jdbc/pull/1465)

## [9.1.0] Preview Release
### Added
- Added support for already connected sockets when using custom socket factory [1420](https://github.com/microsoft/mssql-jdbc/pull/1420)
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ To get the latest preview version of the driver, add the following to your POM f
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>9.1.0.jre15-preview</version>
<version>9.1.1.jre15-preview</version>
</dependency>
```

Expand Down Expand Up @@ -127,7 +127,7 @@ Projects that require either of the two features need to explicitly declare the
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>9.1.0.jre15-preview</version>
<version>9.1.1.jre15-preview</version>
<scope>compile</scope>
</dependency>

Expand All @@ -145,7 +145,7 @@ Projects that require either of the two features need to explicitly declare the
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>9.1.0.jre15-preview</version>
<version>9.1.1.jre15-preview</version>
<scope>compile</scope>
</dependency>

Expand All @@ -172,7 +172,7 @@ When setting 'useFmtOnly' property to 'true' for establishing a connection or cr
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>9.1.0.jre15-preview</version>
<version>9.1.1.jre15-preview</version>
</dependency>

<dependency>
Expand Down
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
name: authDLL
displayName: 'Download mssql-jdbc_auth DLL'
inputs:
secureFile: 'mssql-jdbc_auth-9.1.0.x64-preview.dll'
secureFile: 'mssql-jdbc_auth-9.1.1.x64-preview.dll'
- task: Maven@3
displayName: 'Maven build jre15'
inputs:
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

apply plugin: 'java'

version = '9.1.0'
version = '9.1.1'
def jreVersion = ""
def testOutputDir = file("build/classes/java/test")
def archivesBaseName = 'mssql-jdbc'
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>9.1.0</version>
<version>9.1.1</version>
<packaging>jar</packaging>

<name>Microsoft JDBC Driver for SQL Server</name>
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/com/microsoft/sqlserver/jdbc/ICounter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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;

/**
* Interface for MaxResultBufferCounter
*/
interface ICounter {

/**
* Increases the state of Counter
*
* @param bytes
* Number of bytes to increase state
* @throws SQLServerException
* Exception is thrown, when limit of Counter is exceeded
*/
void increaseCounter(long bytes) throws SQLServerException;

/**
* Resets the state of Counter
*/
void resetCounter();
}
40 changes: 40 additions & 0 deletions src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
import java.util.SimpleTimeZone;
import java.util.TimeZone;
Expand Down Expand Up @@ -109,6 +110,9 @@ final class TDS {
static final byte ADALWORKFLOW_ACTIVEDIRECTORYPASSWORD = 0x01;
static final byte ADALWORKFLOW_ACTIVEDIRECTORYINTEGRATED = 0x02;
static final byte ADALWORKFLOW_ACTIVEDIRECTORYMSI = 0x03;
static final byte ADALWORKFLOW_ACTIVEDIRECTORYINTERACTIVE = 0x03;
static final byte ADALWORKFLOW_ACTIVEDIRECTORYSERVICEPRINCIPAL = 0x01; // Using the Password byte as that is the
// closest we have.
static final byte FEDAUTH_INFO_ID_STSURL = 0x01; // FedAuthInfoData is token endpoint URL from which to acquire fed
// auth token
static final byte FEDAUTH_INFO_ID_SPN = 0x02; // FedAuthInfoData is the SPN to use for acquiring fed auth token
Expand Down Expand Up @@ -3155,6 +3159,15 @@ boolean isEOMSent() {
traceID = "TDSWriter@" + Integer.toHexString(hashCode()) + " (" + con.toString() + ")";
}

/**
* Checks If tdsMessageType is RPC or QUERY
*
* @return boolean
*/
boolean checkIfTdsMessageTypeIsBatchOrRPC() {
return tdsMessageType == TDS.PKT_QUERY || tdsMessageType == TDS.PKT_RPC;
}

// TDS message start/end operations

void preparePacket() throws SQLServerException {
Expand Down Expand Up @@ -6545,6 +6558,11 @@ private boolean nextPacket() throws SQLServerException {
// This action must be synchronized against against another thread calling
// readAllPackets() to read in ALL of the remaining packets of the current response.
if (null == consumedPacket.next) {
// if the read comes from getNext() and responseBuffering is Adaptive (in this place is), then reset Counter
// State
if (null != command && command.getTDSWriter().checkIfTdsMessageTypeIsBatchOrRPC()) {
command.getCounter().resetCounter();
}
readPacket();

if (null == consumedPacket.next)
Expand Down Expand Up @@ -6640,6 +6658,11 @@ synchronized final boolean readPacket() throws SQLServerException {
System.arraycopy(newPacket.header, 0, logBuffer, 0, TDS.PACKET_HEADER_SIZE);
}

// if messageType is RPC or QUERY, then increment Counter's state
if (tdsChannel.getWriter().checkIfTdsMessageTypeIsBatchOrRPC()) {
command.getCounter().increaseCounter(packetLength);
}

// Now for the payload...
for (int payloadBytesRead = 0; payloadBytesRead < newPacket.payloadLength;) {
int bytesRead = tdsChannel.read(newPacket.payload, payloadBytesRead,
Expand Down Expand Up @@ -7344,6 +7367,23 @@ final boolean readingResponse() {

protected ArrayList<byte[]> enclaveCEKs;

// Counter reference, so maxResultBuffer property can by acknowledged
private ICounter counter;

ICounter getCounter() {
return counter;
}

void createCounter(ICounter previousCounter, Properties activeConnectionProperties) {
if (null == previousCounter) {
String maxResultBuffer = activeConnectionProperties
.getProperty(SQLServerDriverStringProperty.MAX_RESULT_BUFFER.toString());
counter = new MaxResultBufferCounter(Long.parseLong(maxResultBuffer));
} else {
counter = previousCounter;
}
}

/**
* Creates this command with an optional timeout.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1021,4 +1021,49 @@ public interface ISQLServerDataSource extends javax.sql.CommonDataSource {
*/
void setSendTemporalDataTypesAsStringForBulkCopy(boolean sendTemporalDataTypesAsStringForBulkCopy);

/**
* Returns the value for the connection property 'AADSecurePrincipalId'.
*
* @return 'AADSecurePrincipalId' property value.
*/
String getAADSecurePrincipalId();

/**
* Sets the 'AADSecurePrincipalId' connection property used for Active Directory Service Principal authentication.
*
* @param AADSecurePrincipalId
* Active Directory Service Principal Id.
*/
void setAADSecurePrincipalId(String AADSecurePrincipalId);

/**
* Returns the value for the connection property 'AADSecurePrincipalSecret'.
*
* @return 'AADSecurePrincipalSecret' property value.
*/
String getAADSecurePrincipalSecret();

/**
* Sets the 'AADSecurePrincipalSecret' connection property used for Active Directory Service Principal
* authentication.
*
* @param AADSecurePrincipalSecret
* Active Directory Service Principal secret.
*/
void setAADSecurePrincipalSecret(String AADSecurePrincipalSecret);

/**
* Returns value of 'maxResultBuffer' from Connection String.
*
* @return 'maxResultBuffer' property.
*/
String getMaxResultBuffer();

/**
* Specifies value for 'maxResultBuffer' property
*
* @param maxResultBuffer
* String value for 'maxResultBuffer'
*/
void setMaxResultBuffer(String maxResultBuffer);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* 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.logging.Level;
import java.util.logging.Logger;


/**
* Implementation of ICounter for 'maxResultBuffer' property.
*/
public class MaxResultBufferCounter implements ICounter {

private final Logger logger = Logger.getLogger("com.microsoft.sqlserver.jdbc.MaxResultBufferCounter");

private long counter = 0;
private final long maxResultBuffer;

public MaxResultBufferCounter(long maxResultBuffer) {
this.maxResultBuffer = maxResultBuffer;
}

public void increaseCounter(long bytes) throws SQLServerException {
if (maxResultBuffer > 0) {
counter += bytes;
checkForMaxResultBufferOverflow(counter);
}
}

public void resetCounter() {
counter = 0;
}

private void checkForMaxResultBufferOverflow(long number) throws SQLServerException {
if (number > maxResultBuffer) {
if (logger.isLoggable(Level.SEVERE)) {
logger.log(Level.SEVERE, SQLServerException.getErrString("R_maxResultBufferPropertyExceeded"),
new Object[] {number, maxResultBuffer});
}
throwExceededMaxResultBufferException(counter, maxResultBuffer);
}
}

private void throwExceededMaxResultBufferException(Object... arguments) throws SQLServerException {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_maxResultBufferPropertyExceeded"));
throw new SQLServerException(form.format(arguments), null);
}
}
Loading