prefix = serviceAnnotation.namespace() + "_";
}
}
for (final Method method : methods) {
final SProcCall scA = method.getAnnotation(SProcCall.class);
if (scA == null) {
continue;
}
String name = scA.name();
if ("".equals(name)) {
name = getSqlNameForMethod(method.getName());
}
name = prefix + name;
VirtualShardKeyStrategy sprocStrategy = keyStrategy;
if (scA.shardStrategy() != Void.class) {
try {
sprocStrategy = (VirtualShardKeyStrategy) scA.shardStrategy().newInstance();
} catch (final InstantiationException | IllegalAccessException ex) {
LOG.error("Shard strategy for sproc can not be instantiated", ex);
return null;
}
}
RowMapper<?> resultMapper = null;
if (scA.resultMapper() != Void.class) {
try {
resultMapper = (RowMapper<?>) scA.resultMapper().newInstance();
} catch (final InstantiationException | IllegalAccessException ex) {
LOG.error("Result mapper for sproc can not be instantiated", ex);
return null;
}
}
boolean useValidation;
if (serviceAnnotation != null) {
// take validation settings from SProcService annotation:
useValidation = serviceAnnotation.validate();
} else {
useValidation = false;
}
// overwrite if explicitly set in SprocCall:
if (scA.validate() == Validate.YES) {
useValidation = true;
} else if (scA.validate() == Validate.NO) {
useValidation = false;
}
final StoredProcedure storedProcedure;
try {
WriteTransaction writeTransaction = getWriteTransactionServiceAnnotation(serviceAnnotation);
if (scA.shardedWriteTransaction()
!= de.zalando.sprocwrapper.SProcCall.WriteTransaction.USE_FROM_SERVICE) {
switch (scA.shardedWriteTransaction()) {
case NONE :
writeTransaction = WriteTransaction.NONE;
break;
case ONE_PHASE :
writeTransaction = WriteTransaction.ONE_PHASE;
break;
case TWO_PHASE :
writeTransaction = WriteTransaction.TWO_PHASE;
break;
case USE_FROM_SERVICE :
writeTransaction = getWriteTransactionServiceAnnotation(serviceAnnotation);
}
}
storedProcedure = new StoredProcedure(name, method.getGenericReturnType(), sprocStrategy,
scA.runOnAllShards(), scA.searchShards(), scA.parallel(), resultMapper,
scA.timeoutInMilliSeconds(), scA.adivsoryLockType(), useValidation, scA.readOnly(),
writeTransaction);
if (!"".equals(scA.sql())) {
storedProcedure.setQuery(scA.sql());
}
} catch (final InstantiationException | IllegalAccessException e) {
LOG.error("Could not instantiate StoredProcedure. ABORTING.", e);
return null;
}