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

pull #24

Merged
merged 28 commits into from
Mar 1, 2018
Merged

pull #24

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
a6eee22
change back to retryLogic and change the default of prepared statemen…
AfsanehR-zz Jan 29, 2018
69edc7b
check if statementPooling is enabled for all retry logics
AfsanehR-zz Jan 30, 2018
b8e9ff9
add the setter and getter methods for disableStatementPooling property
AfsanehR-zz Jan 31, 2018
af76bfc
move same code in a function.
AfsanehR-zz Jan 31, 2018
fee85b2
Merge branch 'dev' of https://github.com/Microsoft/mssql-jdbc into re…
AfsanehR-zz Jan 31, 2018
d6d8310
update for jdk9
AfsanehR-zz Jan 31, 2018
a237ebe
prepare cache in setDisableStatementPooling()
AfsanehR-zz Jan 31, 2018
63ab78f
a small fix
AfsanehR-zz Jan 31, 2018
dbefa1c
fixed the double insertion issue with retry
AfsanehR-zz Jan 31, 2018
870e853
fixed some review comments and updated test to use raiseError
AfsanehR-zz Feb 1, 2018
f523ca9
added a fix with connection property
AfsanehR-zz Feb 1, 2018
6ed48e2
added unit Tests
AfsanehR-zz Feb 1, 2018
12d5eae
Merge pull request #619 from v-afrafi/appveyor
cheenamalhotra Feb 9, 2018
e221b32
Revert back needsPrepare check in retryBasedOnFailedReuseOfCachedHandle
cheenamalhotra Feb 14, 2018
9ae0843
Remove unwanted method parameter
cheenamalhotra Feb 14, 2018
a64b9ef
Merge pull request #618 from AfsanehR/retryLogic
cheenamalhotra Feb 15, 2018
74dd4c2
Update changelog and driver version for RTW release
cheenamalhotra Feb 15, 2018
89c552b
Minor Fix
cheenamalhotra Feb 15, 2018
77ff9de
Minor change to update to jre9
cheenamalhotra Feb 15, 2018
ff1f049
Added needsPrepare Check and removed error code 99586 check
cheenamalhotra Feb 15, 2018
ba2460c
Added check for needsPrepare and removed 99586 check + Moved NeedsPre…
cheenamalhotra Feb 15, 2018
0eb0a61
Moved 'needsPrepare' to local variable.
cheenamalhotra Feb 15, 2018
ea723f6
Defaulting needsPrepare to true.
cheenamalhotra Feb 16, 2018
782dd1b
Merge pull request #629 from cheenamalhotra/retry-fix
cheenamalhotra Feb 16, 2018
d6a4d35
Moving JDK9 support to added section
cheenamalhotra Feb 16, 2018
9277451
Merge pull request #626 from cheenamalhotra/dev
cheenamalhotra Feb 16, 2018
c73f5ba
Update SNAPSHOT for upcoming preview release.
cheenamalhotra Feb 28, 2018
066b3c3
Merge pull request #639 from cheenamalhotra/dev
cheenamalhotra Feb 28, 2018
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
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@ All notable changes to this project will be documented in this file.

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

## [6.4.0] Stable Release
### Added
- Support added for AAD Integrated Authentication with ADAL4J on Windows/Linux/Mac OS [#603](https://github.com/Microsoft/mssql-jdbc/pull/603)
- Enable Recover after MSDTC is restarted [#581](https://github.com/Microsoft/mssql-jdbc/pull/581)
- Added Version Update configuration rules to project [#541](https://github.com/Microsoft/mssql-jdbc/pull/541)
- JDK 9 Compatibility + JDBC 4.3 API support added to the driver [#601 (https://github.com/Microsoft/mssql-jdbc/pull/601)

### Fixed Issues
- Re-introduced Retry Logic for Prepared Statement Caching implementation and remove detect change context function [#618](https://github.com/Microsoft/mssql-jdbc/pull/618) and [#620](https://github.com/Microsoft/mssql-jdbc/pull/620)
- Fixes for SonarQube Reported issues [#599](https://github.com/Microsoft/mssql-jdbc/pull/599)
- Fixes for Random Assertion Errors [#597](https://github.com/Microsoft/mssql-jdbc/pull/597)

### Changed
- Updated Appveyor to use JDK9 building driver and running tests [#619](https://github.com/Microsoft/mssql-jdbc/pull/619)
- JDK 7 compilation support removed from the driver [#601](https://github.com/Microsoft/mssql-jdbc/pull/601)

## [6.3.6] Preview Release
### Added
- Added support for using database name as part of the key for handle cache [#561](https://github.com/Microsoft/mssql-jdbc/pull/561)
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ We're now on the Maven Central Repository. Add the following to your POM file to
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.2.2.jre8</version>
<version>6.4.0.jre9</version>
</dependency>
```
The driver can be downloaded from the [Microsoft Download Center](https://go.microsoft.com/fwlink/?linkid=852460).
Expand Down Expand Up @@ -120,14 +120,14 @@ Projects that require either of the two features need to explicitly declare the
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.3.6.jre8-preview</version>
<version>6.4.0.jre9</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>adal4j</artifactId>
<version>1.3.0</version>
<version>1.4.0</version>
</dependency>
```

Expand All @@ -136,14 +136,14 @@ Projects that require either of the two features need to explicitly declare the
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.3.6.jre8-preview</version>
<version>6.4.0.jre9</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>adal4j</artifactId>
<version>1.3.0</version>
<version>1.4.0</version>
</dependency>

<dependency>
Expand All @@ -160,7 +160,7 @@ We love contributions from the community. To help improve the quality of our co
Thank you!

## Guidelines for Reporting Issues
We appreciate you taking the time to test the driver, provide feedback and report any issues. It would be extremely helpful if you:
We appreciate you taking the time to test the driver, provide feedback and report any issues. It would be extremely helpful if you:

- Report each issue as a new issue (but check first if it's already been reported)
- Try to be detailed in your report. Useful information for good bug reports include:
Expand Down
12 changes: 6 additions & 6 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ init:
- cmd: net start MSSQL$%SQL_Instance%

environment:
JAVA_HOME: C:\Program Files\Java\jdk1.8.0
JAVA_HOME: C:\Program Files\Java\jdk9
mssql_jdbc_test_connection_properties: jdbc:sqlserver://localhost:1433;instanceName=%SQL_Instance%;databaseName=master;username=sa;password=Password12!;

matrix:
Expand Down Expand Up @@ -32,9 +32,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 -Pbuild43
- 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 -Pbuild43
- mvn test -B -Pbuild42
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.4.0-SNAPSHOT.${jreVersion}</version>
<version>6.5.0-SNAPSHOT.${jreVersion}-preview</version>
<packaging>jar</packaging>

<name>Microsoft JDBC Driver for SQL Server</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

final class SQLJdbcVersion {
static final int major = 6;
static final int minor = 3;
static final int patch = 6;
static final int minor = 4;
static final int patch = 0;
static final int build = 0;
}
99 changes: 60 additions & 39 deletions src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@

// Note all the public functions in this class also need to be defined in SQLServerConnectionPoolProxy.
public class SQLServerConnection implements ISQLServerConnection {
boolean contextIsAlreadyChanged = false;
boolean contextChanged = false;

long timerExpire;
boolean attemptRefreshTokenLocked = false;
Expand Down Expand Up @@ -276,15 +274,20 @@ static ParsedSQLCacheItem parseAndCacheSQL(Sha1HashKey key, String sql) throws
return cacheItem;
}

/** Default size for prepared statement caches */
static final int DEFAULT_STATEMENT_POOLING_CACHE_SIZE = 0;

/** Size of the prepared statement handle cache */
private int statementPoolingCacheSize = 10;
private int statementPoolingCacheSize = DEFAULT_STATEMENT_POOLING_CACHE_SIZE;

/** Default size for prepared statement caches */
static final int DEFAULT_STATEMENT_POOLING_CACHE_SIZE = 10;
/** Cache of prepared statement handles */
private ConcurrentLinkedHashMap<Sha1HashKey, PreparedStatementHandle> preparedStatementHandleCache;
/** Cache of prepared statement parameter metadata */
private ConcurrentLinkedHashMap<Sha1HashKey, SQLServerParameterMetaData> parameterMetadataCache;
/**
* Checks whether statement pooling is enabled or disabled. The default is set to true;
*/
private boolean disableStatementPooling = true;

/**
* Find statement parameters.
Expand Down Expand Up @@ -925,17 +928,10 @@ final boolean attachConnId() {
connectionlogger.severe(message);
throw new UnsupportedOperationException(message);
}

// Caching turned on?
if (0 < this.getStatementPoolingCacheSize()) {
preparedStatementHandleCache = new Builder<Sha1HashKey, PreparedStatementHandle>()
.maximumWeightedCapacity(getStatementPoolingCacheSize())
.listener(new PreparedStatementCacheEvictionListener())
.build();

parameterMetadataCache = new Builder<Sha1HashKey, SQLServerParameterMetaData>()
.maximumWeightedCapacity(getStatementPoolingCacheSize())
.build();
if (!this.getDisableStatementPooling() && 0 < this.getStatementPoolingCacheSize()) {
prepareCache();
}
}

Expand Down Expand Up @@ -1437,10 +1433,8 @@ Connection connectInternal(Properties propsIn,
sPropKey = SQLServerDriverBooleanProperty.DISABLE_STATEMENT_POOLING.toString();
sPropValue = activeConnectionProperties.getProperty(sPropKey);
if (null != sPropValue) {
// If disabled set cache size to 0 if disabled.
if(booleanPropertyOn(sPropKey, sPropValue))
this.setStatementPoolingCacheSize(0);
}
setDisableStatementPooling(booleanPropertyOn(sPropKey, sPropValue));
}

sPropKey = SQLServerDriverBooleanProperty.INTEGRATED_SECURITY.toString();
sPropValue = activeConnectionProperties.getProperty(sPropKey);
Expand Down Expand Up @@ -3080,8 +3074,6 @@ final void poolCloseEventNotify() throws SQLServerException {
checkClosed();
if (catalog != null) {
connectionCommand("use " + Util.escapeSQLId(catalog), "setCatalog");
contextIsAlreadyChanged = true;
contextChanged = true;
sCatalog = catalog;
}
loggerExternal.exiting(getClassNameLogging(), "setCatalog");
Expand Down Expand Up @@ -5692,14 +5684,34 @@ final void unprepareUnreferencedPreparedStatementHandles(boolean force) {
}
}

/**
* Returns true if statement pooling is disabled.
*
* @return
*/
public boolean getDisableStatementPooling() {
return this.disableStatementPooling;
}

/**
* Sets statement pooling to true or false;
*
* @param value
*/
public void setDisableStatementPooling(boolean value) {
this.disableStatementPooling = value;
if (!value && 0 < this.getStatementPoolingCacheSize()) {
prepareCache();
}
}

/**
* Returns the size of the prepared statement cache for this connection. A value less than 1 means no cache.
* @return Returns the current setting per the description.
*/
public int getStatementPoolingCacheSize() {
return statementPoolingCacheSize;
}
}

/**
* Returns the current number of pooled prepared statement handles.
Expand All @@ -5717,25 +5729,40 @@ public int getStatementHandleCacheEntryCount() {
* @return Returns the current setting per the description.
*/
public boolean isStatementPoolingEnabled() {
return null != preparedStatementHandleCache && 0 < this.getStatementPoolingCacheSize();
return null != preparedStatementHandleCache && 0 < this.getStatementPoolingCacheSize() && !this.getDisableStatementPooling();
}

/**
* Specifies the size of the prepared statement cache for this conection. A value less than 1 means no cache.
* @param value The new cache size.
* Specifies the size of the prepared statement cache for this connection. A value less than 1 means no cache.
*
* @param value
* The new cache size.
*
*/
public void setStatementPoolingCacheSize(int value) {
if (value != this.statementPoolingCacheSize) {
value = Math.max(0, value);
statementPoolingCacheSize = value;

if (null != preparedStatementHandleCache)
preparedStatementHandleCache.setCapacity(value);
value = Math.max(0, value);
statementPoolingCacheSize = value;

if (null != parameterMetadataCache)
parameterMetadataCache.setCapacity(value);
if (!this.disableStatementPooling && value > 0) {
prepareCache();
}
if (null != preparedStatementHandleCache)
preparedStatementHandleCache.setCapacity(value);

if (null != parameterMetadataCache)
parameterMetadataCache.setCapacity(value);
}

/**
* Internal method to prepare the cache handle
* @param value
*/
private void prepareCache() {
preparedStatementHandleCache = new Builder<Sha1HashKey, PreparedStatementHandle>().maximumWeightedCapacity(getStatementPoolingCacheSize())
.listener(new PreparedStatementCacheEvictionListener()).build();

parameterMetadataCache = new Builder<Sha1HashKey, SQLServerParameterMetaData>().maximumWeightedCapacity(getStatementPoolingCacheSize())
.build();
}

/** Get a parameter metadata cache entry if statement pooling is enabled */
Expand Down Expand Up @@ -5788,12 +5815,6 @@ final void evictCachedPreparedStatementHandle(PreparedStatementHandle handle) {
preparedStatementHandleCache.remove(handle.getKey());
}

final void clearCachedPreparedStatementHandle() {
if (null != preparedStatementHandleCache) {
preparedStatementHandleCache.clear();
}
}

// Handle closing handles when removed from cache.
final class PreparedStatementCacheEvictionListener implements EvictionListener<Sha1HashKey, PreparedStatementHandle> {
public void onEviction(Sha1HashKey key, PreparedStatementHandle handle) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,6 @@ public void run() {
if (wrappedConnection.getConnectionLogger().isLoggable(Level.FINER))
wrappedConnection.getConnectionLogger().finer(toString() + " Connection proxy closed ");

// clear cached prepared statement handle on this connection
wrappedConnection.clearCachedPreparedStatementHandle();
wrappedConnection.poolCloseEventNotify();
wrappedConnection = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ public int getServerPreparedStatementDiscardThreshold() {
}

/**
* Specifies the size of the prepared statement cache for this conection. A value less than 1 means no cache.
* Specifies 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.
Expand All @@ -754,14 +754,32 @@ public void setStatementPoolingCacheSize(int statementPoolingCacheSize) {
}

/**
* Returns the size of the prepared statement cache for this conection. A value less than 1 means no cache.
* Returns the size of the prepared statement cache for this connection. A value less than 1 means no cache.
*
* @return Returns the current setting per the description.
*/
public int getStatementPoolingCacheSize() {
int defaultSize = SQLServerDriverIntProperty.STATEMENT_POOLING_CACHE_SIZE.getDefaultValue();
return getIntProperty(connectionProps, SQLServerDriverIntProperty.STATEMENT_POOLING_CACHE_SIZE.toString(), defaultSize);
}

/**
* Sets the statement pooling to true or false
* @param disableStatementPooling
*/
public void setDisableStatementPooling(boolean disableStatementPooling) {
setBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.DISABLE_STATEMENT_POOLING.toString(), disableStatementPooling);
}

/**
* Returns true if statement pooling is disabled.
* @return
*/
public boolean getDisableStatementPooling() {
boolean defaultValue = SQLServerDriverBooleanProperty.DISABLE_STATEMENT_POOLING.getDefaultValue();
return getBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.DISABLE_STATEMENT_POOLING.toString(),
defaultValue);
}

/**
* Setting the socket timeout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ public String toString() {

enum SQLServerDriverBooleanProperty
{
DISABLE_STATEMENT_POOLING ("disableStatementPooling", false),
DISABLE_STATEMENT_POOLING ("disableStatementPooling", true),
ENCRYPT ("encrypt", false),
INTEGRATED_SECURITY ("integratedSecurity", false),
LAST_UPDATE_COUNT ("lastUpdateCount", true),
Expand Down
Loading