private Connection checkConnectivity( DataSource ds ) { try { return ds.getConnection(); } catch ( Exception e ) { String msg = "Error connecting to database: " + e.getLocalizedMessage(); throw new ResourceException( msg, e ); } }
@Override public void setContent( InputStream in ) { try { bytes = IOUtils.toByteArray( in ); } catch ( IOException e ) { throw new ResourceException( e.getLocalizedMessage(), e ); } }
@Override public void setContent( InputStream in ) { try { file.getParentFile().mkdirs(); FileUtils.copyInputStreamToFile( in, file ); } catch ( IOException e ) { throw new ResourceException( e.getLocalizedMessage(), e ); } }
@Override public Connection getConnection() { try { return ds.getConnection(); } catch ( SQLException e ) { String msg = "Unable to retrieve JDBC connection from DataSource: " + e.getLocalizedMessage(); LOG.error( msg ); throw new ResourceException( msg, e ); } }
@Override public void destroy() { try { pool.destroy(); } catch ( Exception e ) { throw new ResourceException( e.getLocalizedMessage(), e ); } }
@Override public Connection getConnection() { try { return pool.getConnection(); } catch ( SQLException e ) { throw new ResourceException( e.getLocalizedMessage(), e ); } }
@Override public <T extends Resource> ResourceLocation<T> persist( ResourceLocation<T> location ) { ResourceManager<?> mgr = managers.get( location.getIdentifier().getProvider() ); File file = new File( directory, mgr.getMetadata().getWorkspacePath() ); file = new File( file, location.getIdentifier().getId() + ".xml" ); file.getParentFile().mkdirs(); try { // copy to avoid persisting from same file File tmp = File.createTempFile( "config", ".xml" ); FileUtils.copyInputStreamToFile( location.getAsStream(), tmp ); tmp.renameTo( file ); return new DefaultResourceLocation<T>( file, location.getIdentifier() ); } catch ( Exception e ) { throw new ResourceException( "Could not persist resource location: " + e.getLocalizedMessage(), e ); } }
private DataSource initializeDataSourceInstance() { try { final DataSourceInitializer initializer = new DataSourceInitializer( workspace.getModuleClassLoader() ); return initializer.getConfiguredDataSource( config ); } catch ( Exception e ) { String msg = getMessageOrCauseMessage( e ); LOG.error( msg, e ); throw new ResourceException( msg, e ); } }
changed = false; } else { throw new ResourceException( "There are inconsistent dependency chains." );