Search in sources :

Example 41 with DBCException

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());
    }
}
Also used : JDBCPreparedStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement) JDBCSession(org.jkiss.dbeaver.model.exec.jdbc.JDBCSession) SQLException(java.sql.SQLException) JDBCResultSet(org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet) DBCException(org.jkiss.dbeaver.model.exec.DBCException)

Example 42 with DBCException

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));
        }
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) DBPTransactionIsolation(org.jkiss.dbeaver.model.DBPTransactionIsolation) DBCException(org.jkiss.dbeaver.model.exec.DBCException) IEditorPart(org.eclipse.ui.IEditorPart) DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource) DBPDataSourceInfo(org.jkiss.dbeaver.model.DBPDataSourceInfo) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) Separator(org.eclipse.jface.action.Separator) DBCTransactionManager(org.jkiss.dbeaver.model.exec.DBCTransactionManager)

Example 43 with DBCException

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;
}
Also used : DBCAttributeMetaData(org.jkiss.dbeaver.model.exec.DBCAttributeMetaData) DBException(org.jkiss.dbeaver.DBException) DBCException(org.jkiss.dbeaver.model.exec.DBCException) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding)

Example 44 with DBCException

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);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBDContent(org.jkiss.dbeaver.model.data.DBDContent) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBPNamedObject(org.jkiss.dbeaver.model.DBPNamedObject) DBCException(org.jkiss.dbeaver.model.exec.DBCException) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding)

Example 45 with DBCException

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);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBCException(org.jkiss.dbeaver.model.exec.DBCException) TemporaryContentStorage(org.jkiss.dbeaver.model.impl.TemporaryContentStorage) DBDContentStorage(org.jkiss.dbeaver.model.data.DBDContentStorage) DBDContentCached(org.jkiss.dbeaver.model.data.DBDContentCached) DBDContent(org.jkiss.dbeaver.model.data.DBDContent) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) DBDContentStorageLocal(org.jkiss.dbeaver.model.data.DBDContentStorageLocal) StringContentStorage(org.jkiss.dbeaver.model.impl.StringContentStorage)

Aggregations

DBCException (org.jkiss.dbeaver.model.exec.DBCException)60 SQLException (java.sql.SQLException)28 JDBCSession (org.jkiss.dbeaver.model.exec.jdbc.JDBCSession)16 JDBCResultSet (org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet)14 JDBCPreparedStatement (org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement)13 DBException (org.jkiss.dbeaver.DBException)11 NotNull (org.jkiss.code.NotNull)9 DBCStatement (org.jkiss.dbeaver.model.exec.DBCStatement)5 DBSDataType (org.jkiss.dbeaver.model.struct.DBSDataType)5 DBCResultSet (org.jkiss.dbeaver.model.exec.DBCResultSet)4 DBSTypedObject (org.jkiss.dbeaver.model.struct.DBSTypedObject)4 IOException (java.io.IOException)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 Tree (org.eclipse.swt.widgets.Tree)3 TreeColumn (org.eclipse.swt.widgets.TreeColumn)3 TreeItem (org.eclipse.swt.widgets.TreeItem)3 Nullable (org.jkiss.code.Nullable)3 DBPPlatform (org.jkiss.dbeaver.model.app.DBPPlatform)3 TemporaryContentStorage (org.jkiss.dbeaver.model.impl.TemporaryContentStorage)3 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)3