use of org.jkiss.dbeaver.model.data.DBDContentStorageLocal in project dbeaver by serge-rider.
the class ContentEditorInput method updateContentFromFile.
public void updateContentFromFile(IProgressMonitor monitor) throws DBException {
if (valueController.isReadOnly()) {
throw new DBCException("Can't update read-only value");
}
DBRProgressMonitor localMonitor = RuntimeUtils.makeMonitor(monitor);
DBDContent content = getContent();
DBDContentStorage storage = content.getContents(localMonitor);
if (storage instanceof DBDContentStorageLocal) {
// Nothing to update - we user content's storage
contentDetached = true;
} else if (storage instanceof DBDContentCached) {
// Create new storage and pass it to content
try (FileInputStream is = new FileInputStream(contentFile)) {
if (storage instanceof StringContentStorage) {
try (Reader reader = new InputStreamReader(is, fileCharset)) {
storage = StringContentStorage.createFromReader(reader);
}
} else {
storage = BytesContentStorage.createFromStream(is, contentFile.length(), fileCharset);
}
//StringContentStorage.
contentDetached = content.updateContents(localMonitor, storage);
} catch (IOException e) {
throw new DBException("Error reading content from file", e);
}
} else {
// Create new storage and pass it to content
storage = new TemporaryContentStorage(DBeaverCore.getInstance(), contentFile, fileCharset);
contentDetached = content.updateContents(localMonitor, storage);
}
}
use of org.jkiss.dbeaver.model.data.DBDContentStorageLocal in project dbeaver by serge-rider.
the class ContentEditorInput method prepareContent.
private void prepareContent(DBRProgressMonitor monitor) throws DBException {
DBDContent content = getContent();
DBDContentStorage storage = content.getContents(monitor);
if (contentDetached) {
release(monitor);
contentDetached = false;
}
if (storage instanceof DBDContentStorageLocal) {
// User content's storage directly
contentFile = ((DBDContentStorageLocal) storage).getDataFile();
contentDetached = true;
} else {
// Copy content to local file
try {
// Create file
if (contentFile == null) {
String valueId;
if (valueController instanceof IAttributeController) {
valueId = ((IAttributeController) valueController).getColumnId();
} else {
valueId = valueController.getValueName();
}
contentFile = ContentUtils.createTempContentFile(monitor, DBeaverCore.getInstance(), valueId);
}
// Write value to file
copyContentToFile(content, monitor);
} catch (IOException e) {
// Delete temp file
if (contentFile != null && contentFile.exists()) {
if (!contentFile.delete()) {
log.warn("Can't delete temporary content file '" + contentFile.getAbsolutePath() + "'");
}
}
throw new DBException("Can't delete content file", e);
}
}
// Mark file as readonly
if (valueController.isReadOnly()) {
markReadOnly(true);
}
}
Aggregations