/** * Handle an {@link Exception} thrown by a remote call. This means try to "extract and rethrow" the wrapped * exception. * * @param e the Exception * @return cause of exception (only to have a return value) * @throws RuntimeException always */ private Exception handleException(Exception e) { return (Exception) ManagedException.forward(e); // Throwable cause = e.getCause(); // if (cause == null) { // cause = e; // } // if (cause instanceof RuntimeException) { // throw (RuntimeException) cause; // } // throw new ManagedException("tsl2nano.client.servererror", null, // cause); }
public void checkJDBCConnection() { Connection con = null; try { con = getConnection(); ResultSet tables = getTableNames(con); if (!tables.next()) { LOG.info("Available tables are:\n" + getTablesAsString(con.getMetaData().getTables(null, null, null, null))); throw new ManagedException("The desired jdbc connection provides no tables to work on!"); } } catch (Exception e) { ManagedException.forward(e); } finally { close(con); } }
/** * resets the cached data * * @param partIds parts to reset - if no parts are given, all parts will be reset. */ public void reset(String... partIds) { nextBatchParts.clear(); if (partIds.length == 0) { partIds = (String[]) cache.keySet().toArray(); } for (int i = 0; i < partIds.length; i++) { if (cache.remove(partIds[i]) == null) { throw ManagedException.implementationError("cache item couldn't be removed!", partIds[i], cache.keySet()); } } } }
/** * override this method, if you work on entity beans with generic ids. you should assign the parent object. * * @param selectedSourceItems items to move to the destination list. */ public void moveToDest(Collection<T> selectedSourceItems) { assert sourceItems.containsAll(selectedSourceItems); if (!(sourceItems.removeAll(selectedSourceItems))) { throw new ManagedException("tsl2nano.unexpectederror", null); } destItems.addAll(selectedSourceItems); }
throw ManagedException.implementationError("give at least one attribute-name to be filled!", null); .implementationError( "if you don't give a separation-character, you should give at least one column-index in your attribute-names", null); ManagedException.forward(e); throw new ManagedException(StringUtil.toFormattedString(errors, 80, true));
throw ManagedException.illegalArgument(source, getConstraint().getAllowedValues()); ManagedException.forward(ex);
/** * creates the query for the given finders * * @param <FINDER> finder-type * @param <T> result bean type * @param parameter parameter collection to be filled by this method * @param lazyRelations relation types to be filled by this method * @param finder at least one finder * @return query string */ public static <FINDER extends AbstractFinder<T>, T> String createQuery(Collection<Object> parameter, Collection<Class<Object>> lazyRelations, FINDER... finder) { if (finder.length == 0) { throw ManagedException.illegalState("at least one finder must be defined!", parameter); } else if (finder[0].getResultType() == null) { throw ManagedException.illegalArgument(finder[0], "the first finder must define a resultType!"); } StringBuffer qStr = new StringBuffer();//createStatement(finder[0].getResultType()); for (int i = 0; i < finder.length; i++) { finder[i].addToQuery(i, qStr, parameter, lazyRelations); finder[i].getMaxResult(); } LOG.debug(getLogInfo(qStr, parameter)); return qStr.toString(); }
public static final <C extends Collection<I>, I/* extends Serializable*/> BeanCollector<C, I> getBeanCollector( Collection<I> collection, int workingMode) { ManagedException.assertion(collection != null && collection.size() > 0, "collection is empty but must contain at least one item"); return getBeanCollector((Class<I>) BeanClass.getDefiningClass(collection.iterator().next().getClass()), collection, workingMode, null); }
/** * override this method, if you work on entity beans with generic ids. you should remove the ids. * * @param destItem items to move to the source list. */ public void moveToSource(Collection<T> selectedDestItems) { assert destItems.containsAll(selectedDestItems); if (!(destItems.removeAll(selectedDestItems))) { throw new ManagedException("tsl2nano.unexpectederror", null); } sourceItems.addAll(selectedDestItems); }
private static void close(Connection con) { if (con != null) { try { con.close(); } catch (SQLException e) { ManagedException.forward(e); } } }
/** * getParsedValue. throws a runtime exception on parsing error. * * @param source text to parse * @return parsed value */ public T getParsedValue(String source) { T value = null; if (getFormat() != null) { try { if (Util.isEmpty(source) && nullable()) return null; //the parser will decide, how to handle empty/null values value = (T) getFormat().parseObject(source); } catch (ParseException e) { ManagedException.forward(e); } } else if (String.class.isAssignableFrom(getType())) { value = (T) source; } else { throw new ManagedException("no format/parser available for field " + getName()); } return value; }
/** * if servicefactory is not initialized, an exception will be thrown */ public static void checkConnection() { if (!ServiceFactory.isInitialized()) { LOG.error("Server-Connection Lost! May be caused by Server-Restart or Instruction-Error (no previously call of ServiceFactory.createInstance(..))"); throw new ManagedException("tsl2nano.login.noconnection"); } }
/** * evaluates the query name by arguments * * @param <T> type of bean * @param beanType bean type * @param args query arguments * @return named query name (like 'MyBeanClassPath.findById') */ protected String getNamedQueryByArguments(Class<?> beanType, Object... args) { final String prefix = getNamedQueryPrefix(beanType); final int alength = args.length; switch (alength) { case 0: return prefix + NAMEDQUERY_ALL; case 1: return prefix + NAMEDQUERY_ID; case 2: return prefix + NAMEDQUERY_BETWEEN; default: throw ManagedException.implementationError("evaluation of named queries only available for zero or one argument (findAll and findById)", args); } }
@Override public Object clone() { try { return super.clone(); } catch (CloneNotSupportedException e) { ManagedException.forward(e); return null; } }
+ instantiatedEntities.size()); if (recurseLevel++ > getMaxRecursionLevel()) { throw new ManagedException("instantiateLazyRelationship: max recurs level " + MAX_RECURSLEVEL + " exceeded evaluating attribute " ManagedException.forward(e);
/** * checkDelegate * @param interfaze * @param delegate */ static <T> void checkDelegate(Class<T> interfaze, T delegate) { if (delegate == null || !interfaze.isAssignableFrom(delegate.getClass())) { throw new ManagedException("the delegate instance must implement the service interface!\ninterface: " + interfaze + "\ndelegate: " + Messages.stripParameterBrackets(String.valueOf(delegate)) + "\n\nmostly the reason are missing appserver-client-libraries to your client."); } }
/** * get cached result as single object. use {@link #get(Class, String)} to obtain a list of elements. * * @param <T> result type * @param type result type * @param partId part id, identifying the data * @return data or null */ public <T> T getSingle(Class<T> type, String partId) { Collection<T> result = get(type, partId); if (result != null) { if (result.size() == 1) { return result.iterator().next(); } else { throw ManagedException.implementationError("the cache for " + type + "|" + partId + " is not a single result. the cache contains" + result.size() + " elements for that!", "getSingle()", "get()"); } } return null; }
/** * default readaccessmethod if default constructor was invoked */ private static final Method UNDEFINEDMETHOD() { try { //get yourself return AttributeDefinition.class.getDeclaredMethod("UNDEFINEDMETHOD", new Class[0]); } catch (Exception e) { ManagedException.forward(e); return null; } }
/** * checks the given interface package path to start with defined feature interface path. * * @param <T> * @param interfaze interface package to check */ protected <T> void checkInterfacePath(Class<T> interfaze) { String featurePathConstraint = properties.getProperty(KEY_INTERF_PACKAGE_PREFIX); if (featurePathConstraint != null) { if (!interfaze.getPackage().getName().startsWith(featurePathConstraint)) { throw new ManagedException("tsl2nano.implementationerror", new Object[] { "Feature-Interface: " + interfaze.getName(), "Please use only feature interfaces in packages starting with '" + featurePathConstraint + "'!" }); } } else { //not defined? ==> default mechansim featurePathConstraint = "feature"; if (!interfaze.getPackage().getName().contains(featurePathConstraint)) { throw new ManagedException("tsl2nano.implementationerror", new Object[] { "Feature-Interface: " + interfaze.getName(), "Please use only feature interfaces in packages containing the substring '" + featurePathConstraint + "'!" }); } } }
/** * removes the given standard-attributes from bean (given names must be contained in standard-bean-definition. not * performance-optimized, because standard names have to be evaluated first!) * * @param attributeNamesToRemove attributes to remove */ public void removeAttributes(String... attributeNamesToRemove) { ArrayList<String> names = new ArrayList<String>(Arrays.asList(getAttributeNames())); int currentSize = names.size(); names.removeAll(Arrays.asList(attributeNamesToRemove)); if (names.size() + attributeNamesToRemove.length != currentSize) { throw ManagedException.implementationError("not all of given attributes were removed!", attributeNamesToRemove, getAttributeNames()); } setAttributeFilter(names.toArray(new String[0])); }