reset preparedTypedefinition is handle not found error occured
@@ -936,7 +936,6 @@ public class SQLServerPreparedStatement extends SQLServerStatement implements IS
if (null != cachedHandle) {
if ((!connection.isColumnEncryptionSettingEnabled())
|| (connection.isColumnEncryptionSettingEnabled() && encryptionMetadataIsRetrieved)) {
- if (reuseCacheHandleCheck(hasNewTypeDefinitions)) {
if (cachedHandle.tryAddReference()) {
setPreparedStatementHandle(cachedHandle.getHandle());
cachedPreparedStatementHandle = cachedHandle;
@@ -945,23 +944,6 @@ public class SQLServerPreparedStatement extends SQLServerStatement implements IS
}
}
}
- }
- return false;
- }
-
- /**
- * Check reusing cache handle for batch queries
- *
- * @param hasNewTypeDefinitions
- * is set to true if new query
- * @return
- */
- private boolean reuseCacheHandleCheck(boolean hasNewTypeDefinitions) {
- if (!hasNewTypeDefinitions && null != batchParamValues) // If it is a batch query, make sure it does not have newTypeDefinitions
- return true;
- if (null == batchParamValues) // if it is being called from prepared statement query, it should always reuse cache handle
- return true;
- else
return false;
}
@@ -2605,7 +2587,6 @@ public class SQLServerPreparedStatement extends SQLServerStatement implements IS
// Retry execution if existing handle could not be re-used.
for(int attempt = 1; attempt <= 2; ++attempt) {
-
try {
// Re-use handle if available, requires parameter definitions which are not available until here.
@@ -2667,8 +2648,12 @@ public class SQLServerPreparedStatement extends SQLServerStatement implements IS
// Retry if invalid handle exception.
if (retryBasedOnFailedReuseOfCachedHandle(e, attempt)) {
- // Reset number of batches prepared.
+ // Reset number of batches prepare and reset the prepared type definitions
numBatchesPrepared = numBatchesExecuted;
+ paramValues = batchParamValues.get(numBatchesPrepared);
+ for (int i = 0; i < paramValues.length; i++)
+ batchParam[i] = paramValues[i];
+ buildPreparedStrings(batchParam, false);
retry = true;
break;
}
