use of org.jkiss.dbeaver.model.exec.DBCException in project dbeaver by serge-rider.
the class JDBCContentBytes method updateContents.
@Override
public boolean updateContents(DBRProgressMonitor monitor, DBDContentStorage storage) throws DBException {
if (storage == null) {
data = null;
} else {
try {
InputStream is = storage.getContentStream();
try {
data = new byte[(int) storage.getContentLength()];
int count = is.read(data);
if (count != data.length) {
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
log.warn("Actual content length (" + count + ") is less than declared (" + data.length + ")");
}
} finally {
ContentUtils.close(is);
}
} catch (IOException e) {
throw new DBCException("IO error while reading content", e);
}
}
this.modified = true;
return false;
}
use of org.jkiss.dbeaver.model.exec.DBCException 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;
}
use of org.jkiss.dbeaver.model.exec.DBCException in project dbeaver by serge-rider.
the class JDBCContentCLOB method bindParameter.
@Override
public void bindParameter(JDBCSession session, JDBCPreparedStatement preparedStatement, DBSTypedObject columnType, int paramIndex) throws DBCException {
try {
if (storage != null) {
// String stringValue = ContentUtils.getContentStringValue(session.getProgressMonitor(), this);
// preparedStatement.setString(paramIndex, stringValue);
// Try 3 jdbc methods to set character stream
releaseTempStream();
tmpReader = storage.getContentReader();
try {
preparedStatement.setNCharacterStream(paramIndex, tmpReader);
} catch (Throwable e) {
if (e instanceof SQLException && !(e instanceof SQLFeatureNotSupportedException)) {
throw (SQLException) e;
} else {
long streamLength = ContentUtils.calculateContentLength(storage.getContentReader());
try {
preparedStatement.setCharacterStream(paramIndex, tmpReader, streamLength);
} catch (Throwable e1) {
if (e1 instanceof SQLException && !(e instanceof SQLFeatureNotSupportedException)) {
throw (SQLException) e1;
} else {
preparedStatement.setCharacterStream(paramIndex, tmpReader, (int) streamLength);
}
}
}
}
} else if (clob != null) {
preparedStatement.setClob(paramIndex, clob);
} else {
preparedStatement.setNull(paramIndex, java.sql.Types.CLOB);
}
} catch (SQLException e) {
throw new DBCException(e, dataSource);
} catch (Throwable e) {
throw new DBCException("IO error while binding content", e);
}
}
use of org.jkiss.dbeaver.model.exec.DBCException in project dbeaver by serge-rider.
the class JDBCContentChars method updateContents.
@Override
public boolean updateContents(DBRProgressMonitor monitor, DBDContentStorage storage) throws DBException {
if (storage == null) {
data = null;
} else {
try {
Reader reader = storage.getContentReader();
try {
StringWriter sw = new StringWriter((int) storage.getContentLength());
ContentUtils.copyStreams(reader, storage.getContentLength(), sw, monitor);
data = sw.toString();
} finally {
ContentUtils.close(reader);
}
} catch (IOException e) {
throw new DBCException("IO error while reading content", e);
}
}
this.modified = true;
return false;
}
use of org.jkiss.dbeaver.model.exec.DBCException in project dbeaver by serge-rider.
the class JDBCContentLOB method cloneValue.
@Override
public DBDValueCloneable cloneValue(DBRProgressMonitor monitor) throws DBCException {
JDBCContentLOB copy = createNewContent();
DBDContentStorage storage = getContents(monitor);
if (storage != null) {
try {
copy.updateContents(monitor, storage.cloneStorage(monitor));
} catch (IOException e) {
throw new DBCException("IO error while clone content", e);
}
}
return copy;
}
Aggregations