*
* @param params A map holding all values that should be specified. See the Multiverse documentation for possible values
* @return The newly created instance of TxnExecutor
*/
public static TxnExecutor createTxnExecutor(final Map<String, Object> params) {
TxnFactoryBuilder localFactory = transactionFactory;
final Set<Map.Entry<String, Object>> entries = params.entrySet();
for (final Map.Entry<String, Object> entry : entries) {
if (entry.getValue() == null)
throw new IllegalArgumentException("Cannot create an atomic block. The value for " + entry.getKey() + " is null.");
if (entry.getKey() == null || "".equals(entry.getKey().trim()))
throw new IllegalArgumentException("Cannot create an atomic block. Found an empty key.");
final String key = "set" + Character.toUpperCase(entry.getKey().charAt(0)) + entry.getKey().substring(1);
try {
final Method method;
if (entry.getValue().getClass().equals(Long.class)) {
method = TxnFactoryBuilder.class.getDeclaredMethod(key, Long.TYPE);
} else if (entry.getValue().getClass().equals(Integer.class)) {
method = TxnFactoryBuilder.class.getDeclaredMethod(key, Integer.TYPE);
} else if (entry.getValue().getClass().equals(Boolean.class)) {
method = TxnFactoryBuilder.class.getDeclaredMethod(key, Boolean.TYPE);
} else {
method = TxnFactoryBuilder.class.getDeclaredMethod(key, entry.getValue().getClass());
}
localFactory = (TxnFactoryBuilder) method.invoke(localFactory, entry.getValue());
} catch (NoSuchMethodException e) {
throw new IllegalArgumentException(CANNOT_CREATE_AN_ATOMIC_BLOCK_SOME_OF_THE_SPECIFIED_PARAMETERS_ARE_NOT_SUPPORTED + entry.getKey(), e);
} catch (InvocationTargetException e) {
throw new IllegalArgumentException(CANNOT_CREATE_AN_ATOMIC_BLOCK_SOME_OF_THE_SPECIFIED_PARAMETERS_ARE_NOT_SUPPORTED + entry.getKey(), e);
} catch (IllegalAccessException e) {
throw new IllegalArgumentException(CANNOT_CREATE_AN_ATOMIC_BLOCK_SOME_OF_THE_SPECIFIED_PARAMETERS_ARE_NOT_SUPPORTED + entry.getKey(), e);
}
}
return localFactory.newTxnExecutor();
}