use of org.jkiss.dbeaver.model.exec.DBCException in project dbeaver by serge-rider.
the class PostgreTableForeign method readForeignInfo.
private void readForeignInfo(DBRProgressMonitor monitor) throws DBException {
if (foreignServerId > 0) {
return;
}
try (JDBCSession session = DBUtils.openMetaSession(monitor, getDataSource(), "Read foreign table info")) {
try (JDBCPreparedStatement stat = session.prepareStatement("SELECT * FROM pg_catalog.pg_foreign_table WHERE ftrelid=?")) {
stat.setLong(1, getObjectId());
try (JDBCResultSet result = stat.executeQuery()) {
if (result.next()) {
foreignServerId = JDBCUtils.safeGetLong(result, "ftserver");
foreignOptions = JDBCUtils.safeGetArray(result, "ftoptions");
}
}
}
} catch (SQLException e) {
throw new DBCException(e, getDataSource());
}
}
use of org.jkiss.dbeaver.model.exec.DBCException in project dbeaver by serge-rider.
the class DataSourceTransactionModeContributor method fillContributionItems.
@Override
protected void fillContributionItems(final List<IContributionItem> menuItems) {
IWorkbenchWindow window = DBeaverUI.getActiveWorkbenchWindow();
if (window == null) {
return;
}
IEditorPart activePart = window.getActivePage().getActiveEditor();
DBPDataSourceContainer container = AbstractDataSourceHandler.getDataSourceContainer(activePart);
DBPDataSource dataSource = null;
if (container != null) {
dataSource = container.getDataSource();
}
if (dataSource == null) {
return;
}
final DBPDataSourceInfo dsInfo = dataSource.getInfo();
DBCTransactionManager txnManager = DBUtils.getTransactionManager(dataSource.getDefaultContext(false));
if (txnManager != null) {
menuItems.add(ActionUtils.makeCommandContribution(window, CoreCommands.CMD_TOGGLE_AUTOCOMMIT, CommandContributionItem.STYLE_CHECK));
menuItems.add(new Separator());
// Transactions
DBPTransactionIsolation txnLevelCurrent = null;
try {
txnLevelCurrent = txnManager.getTransactionIsolation();
} catch (DBCException ex) {
log.warn("Can't determine current transaction isolation level", ex);
}
for (DBPTransactionIsolation txi : CommonUtils.safeCollection(dsInfo.getSupportedTransactionsIsolation())) {
if (!txi.isEnabled()) {
continue;
}
menuItems.add(ActionUtils.makeActionContribution(new TransactionIsolationAction(dataSource, txi, txi.equals(txnLevelCurrent)), true));
}
}
}
use of org.jkiss.dbeaver.model.exec.DBCException in project dbeaver by serge-rider.
the class StreamTransferConsumer method fetchStart.
@Override
public void fetchStart(DBCSession session, DBCResultSet resultSet, long offset, long maxRows) throws DBCException {
if (!initialized) {
// Can be invoked multiple times in case of per-segment transfer
initExporter(session);
}
// Prepare columns
metaColumns = new ArrayList<>();
List<DBCAttributeMetaData> attributes = resultSet.getMeta().getAttributes();
for (DBCAttributeMetaData attribute : attributes) {
DBDAttributeBinding columnBinding = DBUtils.getAttributeBinding(session, attribute);
metaColumns.add(columnBinding);
}
row = new Object[metaColumns.size()];
if (!initialized) {
try {
processor.exportHeader(session);
} catch (DBException e) {
log.warn("Error while exporting table header", e);
} catch (IOException e) {
throw new DBCException("IO error", e);
}
}
initialized = true;
}
use of org.jkiss.dbeaver.model.exec.DBCException in project dbeaver by serge-rider.
the class StreamTransferConsumer method fetchRow.
@Override
public void fetchRow(DBCSession session, DBCResultSet resultSet) throws DBCException {
try {
// Get values
for (int i = 0; i < metaColumns.size(); i++) {
DBDAttributeBinding column = metaColumns.get(i);
Object value = column.getValueHandler().fetchValueObject(session, resultSet, column.getAttribute(), column.getOrdinalPosition());
if (value instanceof DBDContent && !settings.isOutputClipboard()) {
// Check for binary type export
if (!ContentUtils.isTextContent((DBDContent) value)) {
switch(settings.getLobExtractType()) {
case SKIP:
// Set it it null
value = null;
break;
case INLINE:
// Just pass content to exporter
break;
case FILES:
// Save content to file and pass file reference to exporter
value = saveContentToFile(session.getProgressMonitor(), (DBDContent) value);
break;
}
}
}
row[i] = value;
}
// Export row
processor.exportRow(session, row);
} catch (DBException e) {
throw new DBCException("Error while exporting table row", e);
} catch (IOException e) {
throw new DBCException("IO error", e);
}
}
use of org.jkiss.dbeaver.model.exec.DBCException 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);
}
}
Aggregations