in elastic-db-tools/src/main/java/com/microsoft/azure/elasticdb/shard/base/ValidationUtils.java [56:125]
public static void validateMapping(Connection conn,
ShardMapManager shardMapManager,
StoreShardMap shardMap,
StoreMapping storeMapping) {
Stopwatch stopwatch = Stopwatch.createStarted();
StoreResults lsmResult = new StoreResults();
JAXBElement jaxbElement = StoreOperationRequestBuilder.validateShardMappingLocal(shardMap.getId(), storeMapping.getId());
try (CallableStatement cstmt = conn
.prepareCall(String.format("{call %s(?,?)}", StoreOperationRequestBuilder.SP_VALIDATE_SHARD_MAPPING_LOCAL))) {
SQLXML sqlxml = conn.createSQLXML();
JAXBContext context = JAXBContext.newInstance(StoreOperationInput.class, StoreShard.class, StoreShardMap.class);
// Set the result value from SAX events.
SAXResult sxResult = sqlxml.setResult(SAXResult.class);
context.createMarshaller().marshal(jaxbElement, sxResult);
/*
* log.info("Xml:{}\n{}", "ValidateShardMappingLocal", SqlStoreTransactionScope.asString(context, jaxbElement));//
*/
cstmt.setSQLXML("input", sqlxml);
cstmt.registerOutParameter("result", Types.INTEGER);
Boolean hasResults = cstmt.execute();
StoreResults storeResults = SqlResults.newInstance(cstmt);
// After iterating resultSet's, get result integer.
int result = cstmt.getInt("result");
lsmResult.setResult(StoreResult.forValue(result));
}
catch (SQLException | JAXBException e) {
e.printStackTrace();
}
stopwatch.stop();
try {
log.info("Shard ValidateMapping Complete; Shard: {}; Connection: {}; Result:{}; Duration: {}", storeMapping.getStoreShard().getLocation(),
conn.getMetaData().getURL(), lsmResult.getResult(), stopwatch.elapsed(TimeUnit.MILLISECONDS));
}
catch (SQLException e) {
e.printStackTrace();
}
if (lsmResult.getResult() != StoreResult.Success) {
if (lsmResult.getResult() == StoreResult.ShardMapDoesNotExist) {
shardMapManager.getCache().deleteShardMap(shardMap);
}
else {
if (lsmResult.getResult() == StoreResult.MappingDoesNotExist) {
// Only evict from cache is mapping is no longer present,
// for Offline mappings, we don't even retry, so same request
// will continue to go to the LSM.
shardMapManager.getCache().deleteMapping(storeMapping);
}
}
// Possible errors are:
// StoreResult.ShardMapDoesNotExist
// StoreResult.MappingDoesNotExist
// StoreResult.MappingIsOffline
// StoreResult.ShardVersionMismatch
// StoreResult.StoreVersionMismatch
// StoreResult.MissingParametersForStoredProcedure
throw StoreOperationErrorHandler.onValidationErrorLocal(lsmResult, shardMap, storeMapping.getStoreShard().getLocation(),
"ValidateMapping", StoreOperationRequestBuilder.SP_VALIDATE_SHARD_LOCAL);
}
assert lsmResult.getResult() == StoreResult.Success;
}