in elastic-db-tools/src/main/java/com/microsoft/azure/elasticdb/query/multishard/MultiShardStatement.java [685:740]
private MultiShardException validateResultSet(ResultSet r,
ShardLocation loc) throws SQLException {
if (r.isClosed()) {
// ResultSet is already closed. Hence adding an exception in its place.
return new MultiShardException(loc, new MultiShardResultSetClosedException(
String.format("The result set for '%1$s' was closed and could not be added.", loc.getDatabase())));
}
ResultSetMetaData m = r.getMetaData();
if (m == null || m.getColumnCount() == 0) {
// ResultSet does not have proper metadata to read.
return new MultiShardException(loc, new MultiShardResultSetInternalException(
String.format("The result set for '%1$s' does not have proper metadata to read and could not be added.", loc.getDatabase())));
}
if (this.schemaComparisonTemplate == null) {
this.schemaComparisonTemplate = r.getMetaData();
return null;
}
for (int i = 1; i <= m.getColumnCount(); i++) {
// Get the designated column's name.
String expectedName = this.schemaComparisonTemplate.getColumnName(i);
String actualName = m.getColumnName(i);
if (!Objects.equals(expectedName, actualName)) {
return new MultiShardException(loc, new MultiShardSchemaMismatchException(loc,
String.format("Expected schema column name %1$s, but encountered schema column name %2$s.", expectedName, actualName)));
}
// Retrieves the designated column's SQL type.
if (!Objects.equals(this.schemaComparisonTemplate.getColumnType(i), m.getColumnType(i))) {
return new MultiShardException(loc,
new MultiShardSchemaMismatchException(loc,
String.format("Mismatched SQL type values for column %1$s. Expected: %2$s. Actual: %3$s", actualName,
this.schemaComparisonTemplate.getColumnTypeName(i), m.getColumnTypeName(i))));
}
// Get the designated column's specified column size.
int expectedPrecision = this.schemaComparisonTemplate.getPrecision(i);
int actualPrecision = m.getPrecision(i);
if (!Objects.equals(expectedPrecision, actualPrecision)) {
return new MultiShardException(loc,
new MultiShardSchemaMismatchException(loc,
String.format("Mismatched nullability values for column %1$s. Expected: %2$s. Actual: %3$s", actualName,
expectedPrecision, actualPrecision)));
}
// Indicates the nullability of values in the designated column.
int expectedNullableValue = this.schemaComparisonTemplate.isNullable(i);
int actualNullableValue = m.isNullable(i);
if (!Objects.equals(expectedNullableValue, actualNullableValue)) {
return new MultiShardException(loc,
new MultiShardSchemaMismatchException(loc,
String.format("Mismatched nullability values for column %1$s. Expected: %2$s. Actual: %3$s", actualName,
NullableValue.forValue(expectedNullableValue), NullableValue.forValue(actualNullableValue))));
}
}
return null;
}