Search in sources :

Example 36 with DBException

use of org.jkiss.dbeaver.DBException in project dbeaver by serge-rider.

the class DBDDocumentXML method serializeDocument.

@Override
public void serializeDocument(@NotNull DBRProgressMonitor monitor, @NotNull OutputStream stream, String encoding) throws DBException {
    try {
        Transformer transformer = TransformerFactory.newInstance().newTransformer();
        Result output = new StreamResult(new OutputStreamWriter(stream, encoding));
        transformer.transform(new DOMSource(document), output);
    } catch (Exception e) {
        throw new DBException("Error serializing XML document", e);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) DOMSource(javax.xml.transform.dom.DOMSource) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) DBException(org.jkiss.dbeaver.DBException) StreamResult(javax.xml.transform.stream.StreamResult) Result(javax.xml.transform.Result) DOMResult(javax.xml.transform.dom.DOMResult)

Example 37 with DBException

use of org.jkiss.dbeaver.DBException in project dbeaver by serge-rider.

the class WMIDataSource method initialize.

@Override
public void initialize(@NotNull DBRProgressMonitor monitor) throws DBException {
    final DBPConnectionConfiguration connectionInfo = container.getActualConnectionConfiguration();
    try {
        WMIService service = WMIService.connect(connectionInfo.getServerName(), connectionInfo.getHostName(), connectionInfo.getUserName(), connectionInfo.getUserPassword(), null, connectionInfo.getDatabaseName());
        this.rootNamespace = new WMINamespace(null, this, connectionInfo.getDatabaseName(), service);
    } catch (UnsatisfiedLinkError e) {
        throw new DBException("Can't link with WMI native library", e);
    } catch (Throwable e) {
        throw new DBException("Can't connect to WMI service", e);
    }
}
Also used : DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration) DBException(org.jkiss.dbeaver.DBException) WMIService(org.jkiss.wmi.service.WMIService)

Example 38 with DBException

use of org.jkiss.dbeaver.DBException in project dbeaver by serge-rider.

the class WMINamespace method loadNamespaces.

List<WMINamespace> loadNamespaces(DBRProgressMonitor monitor) throws DBException {
    try {
        WMIObjectCollectorSink sink = new WMIObjectCollectorSink(monitor, getService());
        getService().enumInstances("__NAMESPACE", sink, WMIConstants.WBEM_FLAG_SHALLOW);
        sink.waitForFinish();
        List<WMINamespace> children = new ArrayList<>();
        for (WMIObject object : sink.getObjectList()) {
            String nsName = CommonUtils.toString(object.getValue("Name"));
            children.add(new WMINamespace(this, dataSource, nsName, null));
            object.release();
        }
        DBUtils.orderObjects(children);
        return children;
    } catch (WMIException e) {
        throw new DBException(e, getDataSource());
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) ArrayList(java.util.ArrayList)

Example 39 with DBException

use of org.jkiss.dbeaver.DBException in project dbeaver by serge-rider.

the class JDBCCallableStatementImpl method getResultSet.

@Nullable
@Override
public JDBCResultSet getResultSet() throws SQLException {
    JDBCResultSet resultSet = makeResultSet(getOriginal().getResultSet());
    if (resultSet == null && procedure != null) {
        JDBCResultSetCallable procResults = new JDBCResultSetCallable(getConnection(), this);
        try {
            Collection<? extends DBSProcedureParameter> params = procedure.getParameters(getConnection().getProgressMonitor());
            if (!CommonUtils.isEmpty(params)) {
                for (DBSProcedureParameter param : params) {
                    if (param.getParameterKind() == DBSProcedureParameterKind.OUT || param.getParameterKind() == DBSProcedureParameterKind.INOUT) {
                        procResults.addColumn(param.getName(), param.getParameterType());
                    }
                }
            }
        } catch (DBException e) {
            log.warn("Error extracting callable results", e);
        }
        procResults.addRow();
        return procResults;
    }
    return resultSet;
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBSProcedureParameter(org.jkiss.dbeaver.model.struct.rdb.DBSProcedureParameter) JDBCResultSet(org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet) Nullable(org.jkiss.code.Nullable)

Example 40 with DBException

use of org.jkiss.dbeaver.DBException in project dbeaver by serge-rider.

the class JDBCDataSource method initialize.

@Override
public void initialize(@NotNull DBRProgressMonitor monitor) throws DBException {
    if (!container.getDriver().isEmbedded() && container.getPreferenceStore().getBoolean(ModelPreferences.META_SEPARATE_CONNECTION)) {
        synchronized (allContexts) {
            this.metaContext = new JDBCExecutionContext(this, "Metadata");
            this.metaContext.connect(monitor, true, null, false);
        }
    }
    try (JDBCSession session = DBUtils.openMetaSession(monitor, this, ModelMessages.model_jdbc_read_database_meta_data)) {
        JDBCDatabaseMetaData metaData = session.getMetaData();
        if (this.sqlDialect instanceof JDBCSQLDialect) {
            try {
                ((JDBCSQLDialect) this.sqlDialect).initDriverSettings(this, metaData);
            } catch (Throwable e) {
                log.error("Error initializing dialect driver settings", e);
            }
        }
        try {
            databaseMajorVersion = metaData.getDatabaseMajorVersion();
            databaseMinorVersion = metaData.getDatabaseMinorVersion();
        } catch (Throwable e) {
            log.error("Error determining server version", e);
        }
        try {
            dataSourceInfo = createDataSourceInfo(metaData);
        } catch (Throwable e) {
            log.error("Error obtaining database info");
        }
    } catch (SQLException ex) {
        throw new DBException("Error getting JDBC meta data", ex, this);
    } finally {
        if (dataSourceInfo == null) {
            log.warn("NULL datasource info was created");
            dataSourceInfo = new JDBCDataSourceInfo(container);
        }
    }
}
Also used : JDBCSession(org.jkiss.dbeaver.model.exec.jdbc.JDBCSession) DBException(org.jkiss.dbeaver.DBException) JDBCDatabaseMetaData(org.jkiss.dbeaver.model.exec.jdbc.JDBCDatabaseMetaData)

Aggregations

DBException (org.jkiss.dbeaver.DBException)232 SQLException (java.sql.SQLException)58 JDBCSession (org.jkiss.dbeaver.model.exec.jdbc.JDBCSession)51 JDBCResultSet (org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet)50 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)43 JDBCPreparedStatement (org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement)42 ArrayList (java.util.ArrayList)37 InvocationTargetException (java.lang.reflect.InvocationTargetException)23 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)23 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)16 DBRRunnableWithProgress (org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress)14 DBPDataSource (org.jkiss.dbeaver.model.DBPDataSource)13 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)13 GridData (org.eclipse.swt.layout.GridData)12 DBCException (org.jkiss.dbeaver.model.exec.DBCException)12 CoreException (org.eclipse.core.runtime.CoreException)11 AbstractObjectReference (org.jkiss.dbeaver.model.impl.struct.AbstractObjectReference)10 IStatus (org.eclipse.core.runtime.IStatus)9 DBSEntityAttribute (org.jkiss.dbeaver.model.struct.DBSEntityAttribute)8 XMLException (org.jkiss.utils.xml.XMLException)8