Search in sources :

Example 1 with DBPPlatform

use of org.jkiss.dbeaver.model.app.DBPPlatform in project dbeaver by serge-rider.

the class OracleContentBFILE method getContents.

@Override
public DBDContentStorage getContents(DBRProgressMonitor monitor) throws DBCException {
    if (storage == null && bfile != null) {
        try {
            openFile();
            long contentLength = getContentLength();
            DBPPlatform platform = dataSource.getContainer().getPlatform();
            if (contentLength < platform.getPreferenceStore().getInt(ModelPreferences.MEMORY_CONTENT_MAX_SIZE)) {
                try {
                    try (InputStream bs = getInputStream()) {
                        storage = BytesContentStorage.createFromStream(bs, contentLength, getDefaultEncoding());
                    }
                } catch (IOException e) {
                    throw new DBCException("IO error while reading content", e);
                }
            } else {
                // Create new local storage
                File tempFile;
                try {
                    tempFile = ContentUtils.createTempContentFile(monitor, platform, "blob" + bfile.hashCode());
                } catch (IOException e) {
                    throw new DBCException("Can't create temporary file", e);
                }
                try (OutputStream os = new FileOutputStream(tempFile)) {
                    try (InputStream bs = getInputStream()) {
                        ContentUtils.copyStreams(bs, contentLength, os, monitor);
                    }
                } catch (IOException e) {
                    ContentUtils.deleteTempFile(tempFile);
                    throw new DBCException("IO error while copying stream", e);
                } catch (Throwable e) {
                    ContentUtils.deleteTempFile(tempFile);
                    throw new DBCException(e, dataSource);
                }
                this.storage = new TemporaryContentStorage(platform, tempFile, getDefaultEncoding());
            }
            // Free blob - we don't need it anymore
            releaseBlob();
        } finally {
            closeFile();
        }
    }
    return storage;
}
Also used : DBCException(org.jkiss.dbeaver.model.exec.DBCException) TemporaryContentStorage(org.jkiss.dbeaver.model.impl.TemporaryContentStorage) DBPPlatform(org.jkiss.dbeaver.model.app.DBPPlatform)

Example 2 with DBPPlatform

use of org.jkiss.dbeaver.model.app.DBPPlatform in project dbeaver by serge-rider.

the class JDBCContentBLOB method getContents.

@Override
public DBDContentStorage getContents(DBRProgressMonitor monitor) throws DBCException {
    if (storage == null && blob != null) {
        long contentLength = getContentLength();
        DBPPlatform platform = dataSource.getContainer().getPlatform();
        if (contentLength < platform.getPreferenceStore().getInt(ModelPreferences.MEMORY_CONTENT_MAX_SIZE)) {
            try {
                try (InputStream bs = blob.getBinaryStream()) {
                    storage = BytesContentStorage.createFromStream(bs, contentLength, getDefaultEncoding());
                }
            } catch (IOException e) {
                throw new DBCException("IO error while reading content", e);
            } catch (Throwable e) {
                throw new DBCException(e, dataSource);
            }
        } else {
            // Create new local storage
            File tempFile;
            try {
                tempFile = ContentUtils.createTempContentFile(monitor, platform, "blob" + blob.hashCode());
            } catch (IOException e) {
                throw new DBCException("Can't create temporary file", e);
            }
            try (OutputStream os = new FileOutputStream(tempFile)) {
                try (InputStream bs = blob.getBinaryStream()) {
                    ContentUtils.copyStreams(bs, contentLength, os, monitor);
                }
            } catch (IOException e) {
                ContentUtils.deleteTempFile(tempFile);
                throw new DBCException("IO error while copying stream", e);
            } catch (Throwable e) {
                ContentUtils.deleteTempFile(tempFile);
                throw new DBCException(e, dataSource);
            }
            this.storage = new TemporaryContentStorage(platform, tempFile, getDefaultEncoding());
        }
        // Free blob - we don't need it anymore
        releaseBlob();
    }
    return storage;
}
Also used : DBCException(org.jkiss.dbeaver.model.exec.DBCException) TemporaryContentStorage(org.jkiss.dbeaver.model.impl.TemporaryContentStorage) DBPPlatform(org.jkiss.dbeaver.model.app.DBPPlatform)

Example 3 with DBPPlatform

use of org.jkiss.dbeaver.model.app.DBPPlatform in project dbeaver by serge-rider.

the class JDBCContentCLOB method getContents.

@Override
public DBDContentStorage getContents(DBRProgressMonitor monitor) throws DBCException {
    if (storage == null && clob != null) {
        long contentLength = getContentLength();
        DBPPlatform platform = dataSource.getContainer().getPlatform();
        if (contentLength < platform.getPreferenceStore().getInt(ModelPreferences.MEMORY_CONTENT_MAX_SIZE)) {
            try {
                storage = StringContentStorage.createFromReader(clob.getCharacterStream(), contentLength);
            } catch (IOException e) {
                throw new DBCException("IO error while reading content", e);
            } catch (Throwable e) {
                throw new DBCException(e, dataSource);
            }
        } else {
            // Create new local storage
            File tempFile;
            try {
                tempFile = ContentUtils.createTempContentFile(monitor, platform, "clob" + clob.hashCode());
            } catch (IOException e) {
                throw new DBCException("Can't create temp file", e);
            }
            try (Writer os = new OutputStreamWriter(new FileOutputStream(tempFile), getDefaultEncoding())) {
                ContentUtils.copyStreams(clob.getCharacterStream(), contentLength, os, monitor);
            } catch (IOException e) {
                ContentUtils.deleteTempFile(tempFile);
                throw new DBCException("IO error while copying content", e);
            } catch (Throwable e) {
                ContentUtils.deleteTempFile(tempFile);
                throw new DBCException(e, dataSource);
            }
            this.storage = new TemporaryContentStorage(platform, tempFile, getDefaultEncoding());
        }
        // Free lob - we don't need it anymore
        releaseClob();
    }
    return storage;
}
Also used : DBCException(org.jkiss.dbeaver.model.exec.DBCException) TemporaryContentStorage(org.jkiss.dbeaver.model.impl.TemporaryContentStorage) DBPPlatform(org.jkiss.dbeaver.model.app.DBPPlatform)

Aggregations

DBPPlatform (org.jkiss.dbeaver.model.app.DBPPlatform)3 DBCException (org.jkiss.dbeaver.model.exec.DBCException)3 TemporaryContentStorage (org.jkiss.dbeaver.model.impl.TemporaryContentStorage)3