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

Merge dev to master for 6.3.4-preview release #529

Merged
merged 38 commits into from
Oct 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
4213afc
TimeoutTimer: Check for destroyed TheadGroup
mnhubspot Sep 1, 2017
9da95c5
TimeoutTimer: Forgot reference
mnhubspot Sep 1, 2017
6789eb6
recognize CallableStatement parameter names with leading '@'
gordthompson Sep 20, 2017
0b410f0
Replace manual array copy
JamieMagee Sep 22, 2017
16bd589
Remove redundant String.toString()
JamieMagee Sep 22, 2017
d94cccc
Replace bare literals
JamieMagee Sep 22, 2017
6f262f8
cleanup tables after test
AfsanehR-zz Sep 25, 2017
328feec
more cleaning of tables and procedures
AfsanehR-zz Sep 25, 2017
e77a046
Implement checkDuplicateColumnName to check duplicate columns
peterbae Sep 26, 2017
8f69956
Revert "Implement checkDuplicateColumnName to check duplicate columns"
peterbae Sep 27, 2017
f8e89df
Revert "Revert "Implement checkDuplicateColumnName to check duplicate…
peterbae Sep 27, 2017
91a3eea
Apply same logic for TVP
peterbae Sep 27, 2017
fe83139
use try with resources
AfsanehR-zz Oct 2, 2017
7f18810
add another try-with-resource
AfsanehR-zz Oct 2, 2017
d778a6f
drop a not needed method
AfsanehR-zz Oct 2, 2017
ada51de
try-with-resources implementation commit 1
cheenamalhotra Oct 2, 2017
5b2657c
Update .travis.yml
cheenamalhotra Oct 2, 2017
7efd39f
Update .travis.yml
cheenamalhotra Oct 2, 2017
052b4b5
Fix AESetup issue with dropCEK
cheenamalhotra Oct 3, 2017
a94cb96
Merge branch 'dev' of https://github.com/Microsoft/mssql-jdbc into cl…
AfsanehR-zz Oct 3, 2017
5ef8dea
try-with-resources implementation commit 2
cheenamalhotra Oct 3, 2017
889f160
Merge branch 'dev' into JavaImprovements
cheenamalhotra Oct 3, 2017
55641c8
avoid creating connection for termination
AfsanehR-zz Oct 5, 2017
8c0ebf2
remove null check and change Set object name
peterbae Oct 5, 2017
b00b377
Merge pull request #509 from v-afrafi/cleanupTables
AfsanehR-zz Oct 5, 2017
e2ec02e
tweak to preserve original parameter name for exception message
gordthompson Oct 6, 2017
adf10ea
Refactoring the logic for checking duplicate column into Util class a…
peterbae Oct 6, 2017
e5f7c6c
Merge pull request #501 from JamieMagee/redundant-String-toString
AfsanehR-zz Oct 7, 2017
b8daa42
Merge pull request #495 from gordthompson/allow-at-sign-prefixed-para…
AfsanehR-zz Oct 7, 2017
4b93851
Remove explicit interface reference
JamieMagee Oct 10, 2017
de471e7
Merge branch 'dev' into JavaImprovements
cheenamalhotra Oct 10, 2017
eb7efe3
Modified bvtTests to be able to test resultSet closing explicitly.
cheenamalhotra Oct 10, 2017
e7b68fd
Merge pull request #520 from cheenamalhotra/JavaImprovements
cheenamalhotra Oct 10, 2017
7a0fe66
Merge pull request #514 from peterbae/SQLServerDataTableImprovement-497
peterbae Oct 11, 2017
06cb754
Merge pull request #474 from maiken2051/master
cheenamalhotra Oct 12, 2017
e51ea73
Merge pull request #502 from JamieMagee/replace-bare-literals
AfsanehR-zz Oct 17, 2017
fba39c8
Merge pull request #500 from JamieMagee/manual-array-copy
peterbae Oct 17, 2017
94ae4bf
6.3.4 release (#528)
ulvii Oct 18, 2017
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
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@ All notable changes to this project will be documented in this file.

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

## [6.3.4] Preview Release
### Added
- Added new ThreadGroup creation to prevent IllegalThreadStateException if the underlying ThreadGroup has been destroyed. [#474](https://github.com/Microsoft/mssql-jdbc/pull/474)
- Added try-with-resources to JUnit tests [#520](https://github.com/Microsoft/mssql-jdbc/pull/520)

### Fixed Issues
- Fixed the issue with passing parameters names that start with '@' to a CallableStatement [#495](https://github.com/Microsoft/mssql-jdbc/pull/495)
- Fixed SQLServerDataTable creation being O(n^2) issue [#514](https://github.com/Microsoft/mssql-jdbc/pull/514)

### Changed
- Changed some manual array copying to System.arraycopy() [#500](https://github.com/Microsoft/mssql-jdbc/pull/500)
- Removed redundant toString() on String objects [#501](https://github.com/Microsoft/mssql-jdbc/pull/501)
- Replaced literals with constants [#502](https://github.com/Microsoft/mssql-jdbc/pull/502)

## [6.3.3] Preview Release
### Added
- Added connection properties for specifying custom TrustManager [#74](https://github.com/Microsoft/mssql-jdbc/pull/74)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,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>6.3.3.jre8-preview</version>
<version>6.3.4.jre8-preview</version>
</dependency>
```

Expand Down Expand Up @@ -120,7 +120,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>6.3.3.jre8-preview</version>
<version>6.3.4.jre8-preview</version>
<scope>compile</scope>
</dependency>

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.3.4-SNAPSHOT</version>
<version>6.3.4</version>

<packaging>jar</packaging>

Expand Down
4 changes: 1 addition & 3 deletions src/main/java/com/microsoft/sqlserver/jdbc/DDC.java
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,7 @@ private static byte[] convertToBytes(BigDecimal value,
}
}
int offset = numBytes - unscaledBytes.length;
for (int i = offset; i < numBytes; ++i) {
ret[i] = unscaledBytes[i - offset];
}
System.arraycopy(unscaledBytes, offset - offset, ret, offset, numBytes - offset);
return ret;
}

Expand Down
21 changes: 15 additions & 6 deletions src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down Expand Up @@ -498,7 +499,7 @@ class GregorianChange {

GregorianCalendar cal = new GregorianCalendar(Locale.US);
cal.clear();
cal.set(1, 1, 577738, 0, 0, 0);// 577738 = 1+577737(no of days since epoch that brings us to oct 15th 1582)
cal.set(1, Calendar.FEBRUARY, 577738, 0, 0, 0);// 577738 = 1+577737(no of days since epoch that brings us to oct 15th 1582)
if (cal.get(Calendar.DAY_OF_MONTH) == 15) {
// If the date calculation is correct(the above bug is fixed),
// post the default gregorian cut over date, the pure gregorian date
Expand Down Expand Up @@ -4828,7 +4829,7 @@ private void writeInternalTVPRowValues(JDBCType jdbcType,
else {
if (isSqlVariant) {
writeTVPSqlVariantHeader(10, TDSType.FLOAT8.byteValue(), (byte) 0);
writeDouble(Double.valueOf(currentColumnStringValue.toString()));
writeDouble(Double.valueOf(currentColumnStringValue));
break;
}
writeByte((byte) 8); // len of data bytes
Expand Down Expand Up @@ -7119,13 +7120,21 @@ final class TimeoutTimer implements Runnable {
private volatile Future<?> task;

private static final ExecutorService executor = Executors.newCachedThreadPool(new ThreadFactory() {
private final ThreadGroup tg = new ThreadGroup(threadGroupName);
private final String threadNamePrefix = tg.getName() + "-";
private final AtomicReference<ThreadGroup> tgr = new AtomicReference<>();
private final AtomicInteger threadNumber = new AtomicInteger(0);

@Override
public Thread newThread(Runnable r) {
Thread t = new Thread(tg, r, threadNamePrefix + threadNumber.incrementAndGet());
public Thread newThread(Runnable r)
{
ThreadGroup tg = tgr.get();

if (tg == null || tg.isDestroyed())
{
tg = new ThreadGroup(threadGroupName);
tgr.set(tg);
}

Thread t = new Thread(tg, r, tg.getName() + "-" + threadNumber.incrementAndGet());
t.setDaemon(true);
return t;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
final class SQLJdbcVersion {
static final int major = 6;
static final int minor = 3;
static final int patch = 3;
static final int patch = 4;
static final int build = 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -1521,7 +1521,7 @@ private String createInsertBulkCommand(TDSWriter tdsWriter) throws SQLServerExce
if (it.hasNext()) {
bulkCmd.append(" with (");
while (it.hasNext()) {
bulkCmd.append(it.next().toString());
bulkCmd.append(it.next());
if (it.hasNext()) {
bulkCmd.append(", ");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ static Object getTemporalObjectFromCSVWithFormatter(String valueStrUntrimmed,
return ts;
case java.sql.Types.TIME:
// Time is returned as Timestamp to preserve nano seconds.
cal.set(connection.baseYear(), 00, 01);
cal.set(connection.baseYear(), Calendar.JANUARY, 01);
ts = new java.sql.Timestamp(cal.getTimeInMillis());
ts.setNanos(taNano);
return new java.sql.Timestamp(ts.getTime());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1451,6 +1451,15 @@ public NClob getNClob(String parameterName) throws SQLException {
if (paramNames != null)
l = paramNames.size();

// handle `@name` as well as `name`, since `@name` is what's returned
// by DatabaseMetaData#getProcedureColumns
String columnNameWithoutAtSign = null;
if (columnName.startsWith("@")) {
columnNameWithoutAtSign = columnName.substring(1, columnName.length());
} else {
columnNameWithoutAtSign = columnName;
}

// In order to be as accurate as possible when locating parameter name
// indexes, as well as be deterministic when running on various client
// locales, we search for parameter names using the following scheme:
Expand All @@ -1465,7 +1474,7 @@ public NClob getNClob(String parameterName) throws SQLException {
for (i = 0; i < l; i++) {
String sParam = paramNames.get(i);
sParam = sParam.substring(1, sParam.length());
if (sParam.equals(columnName)) {
if (sParam.equals(columnNameWithoutAtSign)) {
matchPos = i;
break;
}
Expand All @@ -1477,7 +1486,7 @@ public NClob getNClob(String parameterName) throws SQLException {
for (i = 0; i < l; i++) {
String sParam = paramNames.get(i);
sParam = sParam.substring(1, sParam.length());
if (sParam.equalsIgnoreCase(columnName)) {
if (sParam.equalsIgnoreCase(columnNameWithoutAtSign)) {
matchPos = i;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1717,7 +1717,7 @@ else if (0 == requestedPacketSize)
sPropKey = SQLServerDriverStringProperty.SSL_PROTOCOL.toString();
sPropValue = activeConnectionProperties.getProperty(sPropKey);
if (null == sPropValue) {
sPropValue = SQLServerDriverStringProperty.SSL_PROTOCOL.getDefaultValue().toString();
sPropValue = SQLServerDriverStringProperty.SSL_PROTOCOL.getDefaultValue();
activeConnectionProperties.setProperty(sPropKey, sPropValue);
}
else {
Expand Down Expand Up @@ -5430,7 +5430,7 @@ String getInstancePort(String server,
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().toString());
toString() + " Received SSRP UDP response from IP address: " + udpResponse.getAddress().getHostAddress());
}
catch (IOException ioException) {
// Warn and retry
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,20 @@
import java.time.OffsetDateTime;
import java.time.OffsetTime;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;

public final class SQLServerDataTable {

int rowCount = 0;
int columnCount = 0;
Map<Integer, SQLServerDataColumn> columnMetadata = null;
Set<String> columnNames = null;
Map<Integer, Object[]> rows = null;

private String tvpName = null;
Expand All @@ -37,6 +40,7 @@ public final class SQLServerDataTable {
// Name used in CREATE TYPE
public SQLServerDataTable() throws SQLServerException {
columnMetadata = new LinkedHashMap<>();
columnNames = new HashSet<>();
rows = new HashMap<>();
}

Expand Down Expand Up @@ -75,7 +79,7 @@ public synchronized Iterator<Entry<Integer, Object[]>> getIterator() {
public synchronized void addColumnMetadata(String columnName,
int sqlType) throws SQLServerException {
// column names must be unique
Util.checkDuplicateColumnName(columnName, columnMetadata);
Util.checkDuplicateColumnName(columnName, columnNames);
columnMetadata.put(columnCount++, new SQLServerDataColumn(columnName, sqlType));
}

Expand All @@ -89,10 +93,11 @@ public synchronized void addColumnMetadata(String columnName,
*/
public synchronized void addColumnMetadata(SQLServerDataColumn column) throws SQLServerException {
// column names must be unique
Util.checkDuplicateColumnName(column.columnName, columnMetadata);
Util.checkDuplicateColumnName(column.columnName, columnNames);
columnMetadata.put(columnCount++, column);
}


/**
* Adds one row of data to the data table.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ public <T> T unwrap(Class<T> iface) throws SQLException {
}
catch (SQLException e) {
SQLServerException.makeFromDriverError(con, stmtParent, e.toString(), null, false);
return 0;
return parameterModeUnknown;
}
}

Expand Down Expand Up @@ -913,7 +913,7 @@ public <T> T unwrap(Class<T> iface) throws SQLException {
}
catch (SQLException e) {
SQLServerException.makeFromDriverError(con, stmtParent, e.toString(), null, false);
return 0;
return parameterNoNulls;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2503,8 +2503,7 @@ public long[] executeLargeBatch() throws SQLServerException, BatchUpdateExceptio

updateCounts = new long[batchCommand.updateCounts.length];

for (int i = 0; i < batchCommand.updateCounts.length; ++i)
updateCounts[i] = batchCommand.updateCounts[i];
System.arraycopy(batchCommand.updateCounts, 0, updateCounts, 0, batchCommand.updateCounts.length);

// Transform the SQLException into a BatchUpdateException with the update counts.
if (null != batchCommand.batchException) {
Expand Down Expand Up @@ -2571,8 +2570,7 @@ final void doExecutePreparedStatementBatch(PrepStmtBatchExecCmd batchCommand) th
// Fill in the parameter values for this batch
Parameter paramValues[] = batchParamValues.get(numBatchesPrepared);
assert paramValues.length == batchParam.length;
for (int i = 0; i < paramValues.length; i++)
batchParam[i] = paramValues[i];
System.arraycopy(paramValues, 0, batchParam, 0, paramValues.length);

boolean hasExistingTypeDefinitions = preparedTypeDefinitions != null;
boolean hasNewTypeDefinitions = buildPreparedStrings(batchParam, false);
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/com/microsoft/sqlserver/jdbc/TVP.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.text.MessageFormat;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

enum TVPType {
ResultSet,
Expand Down Expand Up @@ -48,6 +50,7 @@ class TVP {
Iterator<Entry<Integer, Object[]>> sourceDataTableRowIterator = null;
ISQLServerDataRecord sourceRecord = null;
TVPType tvpType = null;
Set<String> columnNames = null;

// MultiPartIdentifierState
enum MPIState {
Expand Down Expand Up @@ -94,6 +97,7 @@ void initTVP(TVPType type,
ISQLServerDataRecord tvpRecord) throws SQLServerException {
initTVP(TVPType.ISQLServerDataRecord, tvpPartName);
sourceRecord = tvpRecord;
columnNames = new HashSet<>();
// Populate TVP metdata from ISQLServerDataRecord.
populateMetadataFromDataRecord();

Expand Down Expand Up @@ -185,8 +189,9 @@ void populateMetadataFromDataRecord() throws SQLServerException {
throw new SQLServerException(SQLServerException.getErrString("R_TVPEmptyMetadata"), null);
}
for (int i = 0; i < sourceRecord.getColumnCount(); i++) {
Util.checkDuplicateColumnName(sourceRecord.getColumnMetaData(i + 1).columnName, columnNames);

// Make a copy here as we do not want to change user's metadata.
Util.checkDuplicateColumnName(sourceRecord.getColumnMetaData(i + 1).columnName, columnMetadata);
SQLServerMetaData metaData = new SQLServerMetaData(sourceRecord.getColumnMetaData(i + 1));
columnMetadata.put(i, metaData);
}
Expand Down
37 changes: 16 additions & 21 deletions src/main/java/com/microsoft/sqlserver/jdbc/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
import java.util.UUID;
import java.util.logging.Level;
import java.util.logging.LogManager;
Expand Down Expand Up @@ -557,28 +558,22 @@ static String escapeSQLId(String inID) {
outID.append(']');
return outID.toString();
}


/**
* Checks if duplicate columns exists, in O(n) time.
*
* @param columnName
* the name of the column
* @throws SQLServerException
* when a duplicate column exists
*/
static void checkDuplicateColumnName(String columnName,
Map<Integer, ?> columnMetadata) throws SQLServerException {
if (columnMetadata.get(0) instanceof SQLServerMetaData) {
for (Entry<Integer, ?> entry : columnMetadata.entrySet()) {
SQLServerMetaData value = (SQLServerMetaData) entry.getValue();
if (value.columnName.equals(columnName)) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_TVPDuplicateColumnName"));
Object[] msgArgs = {columnName};
throw new SQLServerException(null, form.format(msgArgs), null, 0, false);
}
}
}
else if (columnMetadata.get(0) instanceof SQLServerDataColumn) {
for (Entry<Integer, ?> entry : columnMetadata.entrySet()) {
SQLServerDataColumn value = (SQLServerDataColumn) entry.getValue();
if (value.columnName.equals(columnName)) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_TVPDuplicateColumnName"));
Object[] msgArgs = {columnName};
throw new SQLServerException(null, form.format(msgArgs), null, 0, false);
}
}
Set<String> columnNames) throws SQLServerException {
//columnList.add will return false if the same column name already exists
if (!columnNames.add(columnName)) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_TVPDuplicateColumnName"));
Object[] msgArgs = {columnName};
throw new SQLServerException(null, form.format(msgArgs), null, 0, false);
}
}

Expand Down
Loading