private TargetDatabaseMapper getTargetDBMapper() { if (targetDBMapper == null) throw new ConfigurationError("'target' is undefined. " + "Use MemKeyMapper.setTarget() to register the target database"); return targetDBMapper; }
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { try { String methodName = method.getName(); if ("close".equals(methodName)) { openResultSetCount.decrementAndGet(); if (openResultSetMonitor != null) openResultSetMonitor.unregister(this); JDBC_LOGGER.debug("closing result set {}", this); } else if ("toString".equals(methodName)) { return "ResultSet (" + statement + ")"; } else if ("getStatement".equals(methodName)) { return statement; } return BeanUtil.invoke(realResultSet, method, args); } catch (ConfigurationError e) { if (e.getCause() instanceof InvocationTargetException && e.getCause().getCause() instanceof SQLException) throw e.getCause().getCause(); else throw e; } }
@Override public Object invokeExplosively(Object target, Object... parameters) throws Throwable { throw new ConfigurationError("Error initializing test", error); }
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { try { String methodName = method.getName(); Method localMethod = BeanUtil.findMethod(this.getClass(), methodName, method.getParameterTypes()); if (localMethod != null) return BeanUtil.invoke(this, localMethod, args); else { if ("setNull".equals(methodName) && args != null && args.length >= 2) params[(Integer) args[0] - 1] = null; else if (methodName.startsWith("set") && args != null && args.length >= 2 && args[0] instanceof Integer) params[(Integer) args[0] - 1] = args[1]; Object result = BeanUtil.invoke(realStatement, method, args); if (result instanceof ResultSet) result = DBUtil.createLoggingResultSet((ResultSet) result, (PreparedStatement) proxy); return result; } } catch (ConfigurationError e) { if (e.getCause() instanceof InvocationTargetException && e.getCause().getCause() instanceof SQLException) throw e.getCause().getCause(); else throw e; } }
@Override public byte[] convert(String sourceValue) throws ConversionException { try { return sourceValue.getBytes(encoding); } catch (UnsupportedEncodingException e) { throw new ConfigurationError(e); } }
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { try { String methodName = method.getName(); Method localMethod = BeanUtil.findMethod(this.getClass(), methodName, method.getParameterTypes()); Object result; boolean profile = methodName.startsWith("execute") && "true".equals(System.getProperty("profile")); long startTime = 0; if (profile) startTime = System.nanoTime(); if (localMethod != null) result = BeanUtil.invoke(this, localMethod, args); else result = BeanUtil.invoke(realStatement, method, args); if (result instanceof ResultSet) result = DBUtil.createLoggingResultSet((ResultSet) result, (Statement) proxy); if (profile) { long duration = (System.nanoTime() - startTime) / 1000000; Profiler.defaultInstance().addSample(CollectionUtil.toList("SQL", sql), duration); } return result; } catch (ConfigurationError e) { if (e.getCause() instanceof InvocationTargetException && e.getCause().getCause() instanceof SQLException) throw e.getCause().getCause(); else throw e; } }
@Override public String convert(byte[] target) throws ConversionException { try { return new String(target, encoding); } catch (UnsupportedEncodingException e) { throw new ConfigurationError(e); } }
public static void close(Statement statement) { if (statement != null) { try { statement.close(); } catch (SQLException e) { throw new ConfigurationError("Closing statement failed", e); } } }
static ScriptFactory getFactory(String engineId, boolean required) { ScriptFactory factory = factories.get(engineId); if (factory == null && required) throw new ConfigurationError("Not a supported script engine: " + engineId); return factory; }
public static void close(ResultSet resultSet) { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { throw new ConfigurationError("Closing statement failed", e); } } }
public static Object getFieldValue(Field field, Object target, boolean strict) { try { if ((field.getModifiers() & Modifier.STATIC) == Modifier.STATIC) return field.get(null); else return field.get(target); } catch (IllegalArgumentException e) { throw new ConfigurationError(e); } catch (IllegalAccessException e) { throw new ConfigurationError(e); } }
/** * Maps attribute reflection related exceptions to ConfigurationExceptions * @param cause the exception that occurred * @param field the field that was involved in the cause * @return a ConfigurationError that maps the cause. */ public static ConfigurationError configurationException(Exception cause, Field field) { String message; if (cause instanceof IllegalAccessException) message = "No access to field: " + field; else if (cause instanceof NoSuchFieldException) message = "No such field found: " + field; else message = cause.getMessage(); return new ConfigurationError(message, cause); }
private static Method getReadMethod(PropertyDescriptor descriptor, Object bean, boolean strict) { Method readMethod = descriptor.getReadMethod(); if (readMethod == null) if (strict) throw new ConfigurationError("No reader for property '" + descriptor.getName() + "' found in class " + bean.getClass()); else return null; return readMethod; }
/** * Maps method reflection related exceptions to ConfigurationExceptions * @param cause the exception that occurred * @param method the method that was involved in the cause * @return a ConfigurationError that maps the cause. */ public static ConfigurationError configurationException(Exception cause, Method method) { String message; if (cause instanceof IllegalAccessException) message = "No access to method: " + method; else if (cause instanceof InvocationTargetException) message = "Internal exception in method: " + method; else if (cause instanceof IntrospectionException) message = "Internal exception in method: " + method; else message = cause.getMessage(); return new ConfigurationError(message, cause); }
/** * Maps exceptions to ConfigurationExceptions * @param cause the exception that occurred * @param name a characteristic identifier that was involved in the cause * @return a ConfigurationError that maps the cause. */ public static ConfigurationError configurationException(Exception cause, String name) { String message; if (cause instanceof ClassNotFoundException) message = "Class not found: '" + name + "'"; else if (cause instanceof NoSuchFieldException) message = "Field not found: '" + name + "'"; else if (cause instanceof NoSuchMethodException) message = "Method not found: '" + name + "'"; else message = cause.getMessage(); return new ConfigurationError(message, cause); } }
/** * Maps method reflection related exceptions to ConfigurationExceptions * @param cause the exception that occurred * @param constructor the constructor that was involved in the cause * @return a ConfigurationError that maps the cause. */ public static ConfigurationError configurationException(Exception cause, Constructor<?> constructor) { String message; if (cause instanceof IllegalAccessException) message = "No access to constructor: " + constructor; else if (cause instanceof InvocationTargetException) message = "Internal exception in constructor: " + constructor; else if (cause instanceof InstantiationException) message = "Error in instantiation by constructor: " + constructor; else message = cause.getMessage(); return new ConfigurationError(message, cause); }
/** * Maps class reflection related exceptions to ConfigurationExceptions * @param cause the exception that occurred * @param type the class that was involved in the cause * @return a ConfigurationError that maps the cause. */ public static ConfigurationError configurationException(Exception cause, Class<?> type) { String message; if (cause instanceof IntrospectionException) message = "Introspection failed for class " + type; else if (cause instanceof InstantiationException) message = "Instantiation failed for class '" + type + "' Possibly it is abstract, the constructor not public, or no appropriate constructor is provided."; else if (cause instanceof IllegalAccessException) message = "Constructor not accessible for class " + type; else message = cause.getMessage(); return new ConfigurationError(message, cause); }
/** * adds a line from the replacement definition file to the replacement map. * @param tokens the tokens of one line in the file. * One line contains several replacement pairs. */ private void addReplacements(String[] tokens) { if (tokens.length < 2) throw new ConfigurationError("At least two tokens needed to define a replacement"); String replacement = tokens[tokens.length - 1]; for (int i = 0; i < tokens.length - 1; i++) { String token = tokens[i]; if (token.length() != 1) throw new ConfigurationError("Source token length must be 1, wrong for token: " + token); addReplacement(token.charAt(0), replacement); } }
public static <C, I> Type[] getGenericInterfaceParams(Class<C> checkedClass, Class<I> searchedInterface) { for (Type type : checkedClass.getGenericInterfaces()) { ParameterizedType pt = (ParameterizedType) type; if (searchedInterface.equals(pt.getRawType())) return pt.getActualTypeArguments(); } if (!Object.class.equals(checkedClass.getSuperclass())) return getGenericInterfaceParams(checkedClass.getSuperclass(), searchedInterface); throw new ConfigurationError(checkedClass + " does not implement interface with generic parameters: " + searchedInterface); }
public LocalDiffType(DiffDetailType type, String locator) { if (StringUtil.isEmpty(locator) && type == null) throw new ConfigurationError("At least one of the argument 'locator' and 'type' must be not empty"); this.locator = locator; this.type = type; }