List of usage examples for java.sql ResultSet getBinaryStream
java.io.InputStream getBinaryStream(String columnLabel) throws SQLException;
ResultSet
object as a stream of uninterpreted byte
s. From source file:at.ac.tuwien.dsg.depic.dataassetbuffer.store.DataAssetFunctionStore.java
public DBType gEDaaSTypeFromEDaaSName(String eDaaSName) { String sql = "SELECT * FROM ElasticDaaS WHERE name='" + eDaaSName + "'"; DBType eDaaSType = null;//from w ww . jav a 2 s .c o m ResultSet rs = connectionManager.ExecuteQuery(sql); try { while (rs.next()) { InputStream inputStream = rs.getBinaryStream("type"); StringWriter writer = new StringWriter(); String encoding = StandardCharsets.UTF_8.name(); IOUtils.copy(inputStream, writer, encoding); String type = writer.toString(); eDaaSType = DBType.valueOf(type); } rs.close(); } catch (Exception ex) { System.err.println(ex); } return eDaaSType; }
From source file:at.ac.tuwien.dsg.depic.dataassetfunctionmanagement.store.MySqlDataAssetStore.java
public String getDataPartition(String dataAssetID, String dataPartitionID) { String daXML = ""; String sql = "SELECT * FROM DataAsset WHERE dataAssetID='" + dataAssetID + "' AND dataPartitionID='" + dataPartitionID + "'"; ResultSet rs = connectionManager.ExecuteQuery(sql); try {/*from w ww .j av a 2s . c om*/ while (rs.next()) { InputStream inputStream = rs.getBinaryStream("data"); StringWriter writer = new StringWriter(); String encoding = StandardCharsets.UTF_8.name(); IOUtils.copy(inputStream, writer, encoding); daXML = writer.toString(); } rs.close(); } catch (Exception ex) { Logger.getLogger(MySqlDataAssetStore.class.getName()).log(Level.SEVERE, ex.toString()); } return daXML; }
From source file:org.sonar.server.computation.db.AnalysisReportDao.java
@CheckForNull public File getDecompressedReport(DbSession session, long id) { Connection connection = session.getConnection(); InputStream reportDataStream = null; PreparedStatement ps = null;//from w w w . j a va 2 s . co m File directory = null; try { ps = connection.prepareStatement(SELECT_REPORT_DATA); ps.setLong(1, id); ResultSet rs = ps.executeQuery(); if (rs.next()) { reportDataStream = rs.getBinaryStream(1); if (reportDataStream != null) { directory = tempFolder.newDir(); ZipUtils.unzip(reportDataStream, directory); } } } catch (SQLException e) { throw new IllegalStateException(String.format("Failed to read report '%d' in the database", id), e); } catch (IOException e) { throw new IllegalStateException(String.format("Failed to decompress report '%d'", id), e); } finally { IOUtils.closeQuietly(reportDataStream); DatabaseUtils.closeQuietly(ps); } return directory; }
From source file:at.ac.tuwien.dsg.depic.dataassetfunctionmanagement.taskservice.Sampling.java
private void samplingData(double samplingPercentage, String dawID) { MySqlDataAssetStore das = new MySqlDataAssetStore(); ResultSet rs = das.getDataAssetByID(dawID); try {/* w w w .java 2 s .co m*/ while (rs.next()) { String dataPartitionID = rs.getString("dataPartitionID"); InputStream inputStream = rs.getBinaryStream("data"); StringWriter writer = new StringWriter(); String encoding = StandardCharsets.UTF_8.name(); // org.apache.commons.io.IOUtils.copy(inputStream, writer, encoding); String daXML = writer.toString(); DataAsset da = JAXBUtils.unmarshal(daXML, DataAsset.class); daXML = samplingDataAsset(da, samplingPercentage); das.updateDataAsset(dawID, dataPartitionID, daXML); } rs.close(); } catch (Exception ex) { Logger.getLogger(Sampling.class.getName()).log(Level.SEVERE, ex.toString()); } }
From source file:at.ac.tuwien.dsg.dataassetloader.store.DataAssetFunctionStore.java
public String getDataAssetFunction(String dataAssetID) { String dafXML = ""; try {/*from w w w . ja va 2s . com*/ InputStream inputStream = null; String sql = "select * from DataAssetFunction WHERE dataAssetID='" + dataAssetID + "'"; ResultSet rs = connectionManager.ExecuteQuery(sql); try { while (rs.next()) { inputStream = rs.getBinaryStream("dataAssetFunction"); } rs.close(); } catch (SQLException ex) { Logger.getLogger(DataAssetFunctionStore.class.getName()).log(Level.SEVERE, null, ex); } StringWriter writer = new StringWriter(); String encoding = StandardCharsets.UTF_8.name(); IOUtils.copy(inputStream, writer, encoding); dafXML = writer.toString(); Logger.getLogger(DataAssetFunctionStore.class.getName()).log(Level.INFO, null, "DAF XML: " + dafXML); } catch (IOException ex) { Logger.getLogger(DataAssetFunctionStore.class.getName()).log(Level.SEVERE, null, ex); } return dafXML; }
From source file:org.artifactory.storage.db.fs.dao.ConfigsDao.java
public String loadConfig(String name) throws SQLException { ResultSet resultSet = null; try {//from ww w . j a v a 2s .c o m resultSet = jdbcHelper.executeSelect("SELECT data FROM configs WHERE config_name = ?", name); if (resultSet.next()) { InputStream binaryStream = resultSet.getBinaryStream(1); return IOUtils.toString(binaryStream, Charsets.UTF_8.name()); } return null; } catch (IOException e) { throw new SQLException("Failed to read config '" + name + "' due to: " + e.getMessage(), e); } finally { DbUtils.close(resultSet); } }
From source file:at.ac.tuwien.dsg.depic.dataassetfunctionmanagement.taskservice.Output.java
private void outputWithFormat(String formOfData, String dafID) { if (formOfData.equals(DataAssetForm.CSV.getDataAssetForm())) { MySqlDataAssetStore das = new MySqlDataAssetStore(); ResultSet rs = das.getDataAssetByID(dafID); try {/*from w w w . ja v a 2 s . com*/ while (rs.next()) { String dataPartitionID = rs.getString("dataPartitionID"); InputStream inputStream = rs.getBinaryStream("data"); StringWriter writer = new StringWriter(); String encoding = StandardCharsets.UTF_8.name(); // org.apache.commons.io.IOUtils.copy(inputStream, writer, encoding); String daXML = writer.toString(); DataAsset da = JAXBUtils.unmarshal(daXML, DataAsset.class); daXML = convertToCSV(da); System.out.println("CONVERT CSV: " + daXML); das.updateDataAsset(dafID, dataPartitionID, daXML); } rs.close(); } catch (Exception ex) { Logger.getLogger(Sampling.class.getName()).log(Level.SEVERE, ex.toString()); } } else if (formOfData.equals(DataAssetForm.XML.getDataAssetForm())) { // data in xml by default } else if (formOfData.equals(DataAssetForm.FIGURE.getDataAssetForm())) { // not implemented yet } }
From source file:org.tsm.concharto.model.geometry.GeometryUserType.java
/** * Retrieve an instance of the mapped class from a JDBC resultset. * Implementors should handle possibility of null values. * /*from ww w. j a v a 2 s. c o m*/ * @param rs a JDBC result set * @param names the column names * @param owner the containing entity * @return Object * @throws HibernateException * @throws SQLException */ @SuppressWarnings("deprecation") public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException { try { InputStream is = rs.getBinaryStream(names[0]); if (is == null) return null; byte[] buf = new byte[4]; is.read(buf); int SRID = ByteOrderValues.getInt(buf, ByteOrderValues.LITTLE_ENDIAN); WKBReader reader = new WKBReader(); Geometry ret = reader.read(new InputStreamInStream(is)); ret.setSRID(SRID); return ret; } catch (ParseException e) { throw new IllegalStateException(e); } catch (IOException e) { throw new UnhandledException(e); } }
From source file:at.ac.tuwien.dsg.dataassetloader.store.DataAssetFunctionStore.java
public DataAnalyticsFunction getDAFFromEDaaSName(String eDaaSName) { String sql = "SELECT * FROM InputSpecification WHERE name='" + eDaaSName + "'"; DataAnalyticsFunction dataAnalyticsFunction = null; ResultSet rs = connectionManager.ExecuteQuery(sql); InputStream inputStream = null; try {//from www . j a v a2 s . c om while (rs.next()) { inputStream = rs.getBinaryStream("daf"); } rs.close(); } catch (SQLException ex) { Logger.getLogger(DataAssetFunctionStore.class.getName()).log(Level.SEVERE, null, ex); } StringWriter writer = new StringWriter(); String encoding = StandardCharsets.UTF_8.name(); try { IOUtils.copy(inputStream, writer, encoding); String dafXML = writer.toString(); dataAnalyticsFunction = JAXBUtils.unmarshal(dafXML, DataAnalyticsFunction.class); } catch (IOException ex) { Logger.getLogger(DataAssetFunctionStore.class.getName()).log(Level.SEVERE, null, ex); } catch (JAXBException ex) { Logger.getLogger(DataAssetFunctionStore.class.getName()).log(Level.SEVERE, null, ex); } return dataAnalyticsFunction; }
From source file:org.artifactory.storage.db.binstore.service.BlobBinaryProviderImpl.java
@Nonnull @Override//from w ww . ja va2 s.com public InputStream getStream(String sha1) throws BinaryNotFoundException { try { /*if (TransactionSynchronizationManager.isSynchronizationActive()) { throw new StorageException("Cannot retrieve binary data of " + sha1 + " since the datasource is in transaction!"); }*/ ResultSet rs = jdbcHelper.executeSelect("SELECT data FROM binary_blobs where sha1 = ?", sha1); if (rs.next()) { return new BlobStream(rs.getBinaryStream(1), rs); } else { DbUtils.close(rs); } } catch (SQLException e) { throw new StorageException("Could not select content for " + sha1, e); } return next().getStream(sha1); }