private static void close(Connection con) { if (con != null) { try { con.close(); } catch (SQLException e) { ManagedException.forward(e); } } }
@Override public Object clone() { try { return super.clone(); } catch (CloneNotSupportedException e) { ManagedException.forward(e); 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; } }
/** * materializes a {@link Method} through the given arguments. * * @param declaringClass methods declaring class * @param name method name * @param pars method parameters * @return instance of {@link Method} */ static Method getMethod(Class declaringClass, String name, Class... pars) { try { return declaringClass.getMethod(name, pars); } catch (Exception e) { ManagedException.forward(e); return null; } }
/** * convenience for {@link #fromFlatFile(Reader, Class, String...)}. */ public static <T> Collection<T> fromFlatFile(String fileName, Class<T> rootType, String... attributeNames) { try { return fromFlatFile(new BufferedReader(new FileReader(new File(fileName))), rootType, null, attributeNames); } catch (final FileNotFoundException e) { ManagedException.forward(e); return null; } }
/** * see {@link #registeredExtensions}, {@link #getImplementation(String)} and {@link #getBeanValue(Object, String)}. * * @param attributeRegEx regular expression, defining a specialized attribute * @param extension type to handle the specialized attribute. */ public static final void registerExpression(Class<? extends AbstractExpression> extension) { try { String pattern = extension.newInstance().getExpressionPattern(); LOG.info("registering expression class " + extension + " for pattern: " + pattern); registeredExtensions.put(pattern, extension); } catch (Exception e) { ManagedException.forward(e); } }
/** * printImageDescription */ protected String printImageDescription(int height) { StringWriter stream = new StringWriter(); try { new AsciiImage().convertToAscii(description, new PrintWriter(stream), Util.get(SIShell.KEY_WIDTH, 80) - 2, height); //remove windows returns return stream.toString().replaceAll("\r", ""); } catch (Exception e) { ManagedException.forward(e); return null; } }
/** * {@inheritDoc} */ @Override public void close() { try { checkManagedConnection(); managedCon.detachConnection(this); } catch (IOException e) { ManagedException.forward(e); } }
/** * for local access {@inheritDoc} */ @Override public BufferedReader getFileReader(String fileName) { try { final FsConnection con = getConnection(); return new BufferedReader(new InputStreamReader(con.getInputStream(fileName))); } catch (final Exception e) { closeConnection(); ManagedException.forward(e); } return null; }
@SuppressWarnings("rawtypes") public static Net create(String vnetFile) { try { return (Net) FileUtil.loadXml(FileUtil.getFile(vnetFile)); } catch (Exception e) { ManagedException.forward(e); return null; } }
/** * for local access {@inheritDoc} */ @Override public void writeFile(String destFileName, InputStream data, boolean overwrite) throws IOException { try { final FsConnection con = getConnection(); LOG.debug("writing " + data.available() + " bytes to file " + destFileName); con.writeFile(destFileName, data, overwrite); } catch (final Exception e) { ManagedException.forward(e); } finally { closeConnection(); } }
/** * @see de.tsl2.nano.service.util.GenericServiceBean#remove(java.lang.Object) */ @Override public void remove(Object bean) { requireTransaction(); try { super.remove(bean); connection().getTransaction().commit(); } catch (Exception ex) { connection().getTransaction().rollback(); ManagedException.forward(ex); } }
/** * @see de.tsl2.nano.service.util.GenericServiceBean#persist(java.lang.Object, boolean, boolean) */ @Override public <T> T persist(T bean, boolean refreshBean, boolean flush, Class... lazyRelations) { requireTransaction(); try { T refreshObject = super.persist(bean, refreshBean, flush); connection().getTransaction().commit(); return refreshObject; } catch (Exception ex) { connection().getTransaction().rollback(); ManagedException.forward(ex); return null; } }
public Connection getConnection() { Connection con = null; try { Class.forName(persistence.getConnectionDriverClass()); con = DriverManager.getConnection(persistence.getConnectionUrl(), persistence.getConnectionUserName(), persistence.getConnectionPassword()); } catch (Exception e) { ManagedException.forward(e); } return con; }
/** * {@inheritDoc} */ @Override public void rename(String sourceName, String destinationName) throws IOException { try { final FsConnection con = getConnection(); LOG.debug("renaming " + sourceName + " to file " + destinationName); con.rename(sourceName, destinationName); } catch (final Exception e) { ManagedException.forward(e); } finally { closeConnection(); } }
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); } }
/** * {@inheritDoc} */ @Override public boolean isDirectory(String fileName) { try { return getConnection().isDirectory(fileName); } catch (final Exception e) { closeConnection(); ManagedException.forward(e); return false; } }
/** * {@inheritDoc} */ @Override public String[] getDirectoryEntries(String dirName) { try { return getConnection().getDirectoryEntries(dirName); } catch (final Exception e) { closeConnection(); ManagedException.forward(e); return null; } }
/** * {@inheritDoc} */ @Override public void delete(String fileName) { try { final FsConnection con = getConnection(); con.delete(fileName); } catch (final Exception e) { ManagedException.forward(e); } finally { closeConnection(); } }
/** * {@inheritDoc} */ @Override public boolean exists(String fileName) { try { final FsConnection con = getConnection(); return con.exists(fileName); } catch (final Exception e) { closeConnection(); ManagedException.forward(e); } return false; }