private static void createAndCollectClassLoadAction(String className, Class<?> clazz) { try { actions.add((ClassLoadAction) clazz.getDeclaredConstructor().newInstance()); } catch (Exception e) { Exceptions.handle() .error(e) .to(LOG) .withSystemErrorMessage("Failed to instantiate ClassLoadAction: %s - %s (%s)", className) .handle(); } }
private static void stopLifecycle(Stoppable lifecycle) { LOG.INFO("Stopping: %s", lifecycle.getClass().getName()); try { lifecycle.stopped(); } catch (Exception e) { Exceptions.handle() .error(e) .to(LOG) .withSystemErrorMessage("Stop of: %s failed!", lifecycle.getClass().getName()) .handle(); } }
private static void startLifecycle(Startable lifecycle) { LOG.INFO("Starting: %s", lifecycle.getClass().getName()); try { lifecycle.started(); } catch (Exception e) { Exceptions.handle() .error(e) .to(LOG) .withSystemErrorMessage("Startup of: %s failed!", lifecycle.getClass().getName()) .handle(); } }
protected SafeMap<?, ?> getMap(Object entity) { try { return (SafeMap<?, ?>) super.getValueFromField(entity); } catch (Exception e) { throw Exceptions.handle() .to(Mixing.LOG) .error(e) .withSystemErrorMessage( "Unable to obtain EntityRef object from entity ref field ('%s' in '%s'): %s (%s)", getName(), descriptor.getType().getName()) .handle(); } }
protected BaseEntityRefList<?, ?> getEntityRefList(Object entity) { try { return (BaseEntityRefList<?, ?>) super.getValueFromField(entity); } catch (Exception e) { throw Exceptions.handle() .to(Mixing.LOG) .error(e) .withSystemErrorMessage( "Unable to obtain EntityRef object from entity ref field ('%s' in '%s'): %s (%s)", getName(), descriptor.getType().getName()) .handle(); } }
/** * Creates an exception which represents an illegal value for this property * * @param value the illegal value itself * @return an exception filled with an appropriate message */ protected HandledException illegalFieldValue(Value value) { return Exceptions.createHandled() .withNLSKey("Property.illegalValue") .set("property", getLabel()) .set("value", NLS.toUserString(value.get())) .handle(); }
private void executeInitialStatement(Database database, String initSql, Connection connection) { try (Statement stmt = connection.createStatement()) { stmt.execute(initSql); } catch (SQLException e) { Exceptions.handle() .to(OMA.LOG) .error(e) .withSystemErrorMessage( "An error occured while executing the initial SQL statement for: %s (%s) - %s (%s)", database.getUrl(), initSql) .handle(); } }
protected JSONObject extractErrorJSON(ResponseException e) { try { JSONObject response = JSON.parseObject(EntityUtils.toString(e.getResponse().getEntity())); return response.getJSONObject(PARAM_ERROR); } catch (IOException ex) { Exceptions.handle(Elastic.LOG, ex); throw Exceptions.handle() .to(Elastic.LOG) .error(e) .withSystemErrorMessage("Elasticsearch (%s) reported an error which cannot be unpacked: %s", e.getResponse().getHost()) .handle(); } }
private void rejectDeleteIfNecessary(Entity entity) { if (index.select(getLocalClass()) .eq(getName(), entity.getId()) .autoRoute(field.getName(), entity.getId()) .exists()) { throw Exceptions.createHandled() .withNLSKey(Strings.isFilled(refType.onDeleteErrorMsg()) ? refType.onDeleteErrorMsg() : "ForeignKey.restricted") .handle(); } }
private void safeCloseConnection(Connection connection) { try { connection.close(); } catch (SQLException e) { Exceptions.handle() .to(OMA.LOG) .error(e) .withSystemErrorMessage("An exception occured while closing a database connection: %s (%s)") .handle(); } }
protected RequestBuilder execute(String uri) { try { return tryExecute(uri); } catch (OptimisticLockException e) { throw Exceptions.handle() .to(Elastic.LOG) .error(e) .withSystemErrorMessage("An unexpected optimitic locking error ocurred: %s") .handle(); } }
@Override protected void checkNullability(Object propertyValue) { super.checkNullability(propertyValue); if (!isNullable() && ((Amount) propertyValue).isEmpty()) { throw Exceptions.createHandled().withNLSKey("Property.fieldNotNullable").set("field", getLabel()).handle(); } }
protected HandledException queryError(Compiler compiler, Exception e) { return Exceptions.handle() .to(OMA.LOG) .error(e) .withSystemErrorMessage("Error executing query '%s' for type '%s': %s (%s)", compiler, descriptor.getType().getName()) .handle(); }
protected void failOnOverflow(List<E> result) { if (result.size() > MAX_LIST_SIZE) { throw Exceptions.handle() .to(Mixing.LOG) .withSystemErrorMessage("More than %s results were loaded into a list by executing: %s", MAX_LIST_SIZE, this) .handle(); } }
private void ensureReady() { if (!ready) { throw Exceptions.handle().to(LOG).withSystemErrorMessage("Index is not ready yet.").handle(); } }
protected Connection createConnection(String realm) { try { return oma.getDatabase(realm).getConnection(); } catch (SQLException e) { throw Exceptions.handle() .to(OMA.LOG) .error(e) .withSystemErrorMessage("Failed to open a database connection for realm '%s': %s (%s)", realm) .handle(); } }
/** * Checks if the value is non-null or the property accepts null values. * * @param propertyValue the value to check */ protected void checkNullability(Object propertyValue) { if (!isNullable() && propertyValue == null) { throw Exceptions.createHandled().withNLSKey("Property.fieldNotNullable").set("field", getLabel()).handle(); } }
/** * Boilerplate method the directly handle the given exception without a special message * * @param log the logger used to log the exception * @param e the exception to handle * @return a <tt>HandledException</tt> which notifies surrounding calls that an error occurred, which has * already been taken care of. */ public static HandledException handle(Log log, Throwable e) { return handle().error(e).to(log).handle(); }
/** * Boilerplate method the directly handle the given exception without a special message or logger * * @param e the exception to handle * @return a <tt>HandledException</tt> which notifies surrounding calls that an error occurred, which has * already been taken care of. */ public static HandledException handle(Throwable e) { return handle().error(e).handle(); }
private static void verifyUniquenessOfName(String name) { if (caches.containsKey(name)) { throw Exceptions.handle() .to(LOG) .withSystemErrorMessage("A cache named '%s' has already been created!", name) .handle(); } }