Search in sources :

Example 96 with DBException

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

the class DataExporterHTML method writeImageCell.

private void writeImageCell(File file) throws DBException {
    out.write("<td>");
    if (file == null || !file.exists()) {
        out.write("&nbsp;");
    } else {
        Image image = null;
        try {
            image = ImageIO.read(file);
        } catch (IOException e) {
            throw new DBException("Can't read an exported image " + image, e);
        }
        if (image != null) {
            String imagePath = file.getAbsolutePath();
            imagePath = "files/" + imagePath.substring(imagePath.lastIndexOf(File.separator));
            int width = ((BufferedImage) image).getWidth();
            int height = ((BufferedImage) image).getHeight();
            int rwidth = width;
            int rheight = height;
            if (width > IMAGE_FRAME_SIZE || height > IMAGE_FRAME_SIZE) {
                float scale = 1;
                if (width > height) {
                    scale = IMAGE_FRAME_SIZE / (float) width;
                } else {
                    scale = IMAGE_FRAME_SIZE / (float) height;
                }
                rwidth = (int) (rwidth * scale);
                rheight = (int) (rheight * scale);
            }
            out.write("<a href=\"" + imagePath + "\">");
            out.write("<img src=\"" + imagePath + "\" width=\"" + rwidth + "\" height=\"" + rheight + "\" />");
            out.write("</a>");
        } else {
            out.write("&nbsp;");
        }
    }
    out.write("</td>");
}
Also used : DBException(org.jkiss.dbeaver.DBException) IOException(java.io.IOException) BufferedImage(java.awt.image.BufferedImage) BufferedImage(java.awt.image.BufferedImage)

Example 97 with DBException

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

the class DataExporterSQL method exportHeader.

@Override
public void exportHeader(DBCSession session) throws DBException, IOException {
    columns = getSite().getAttributes();
    DBPNamedObject source = getSite().getSource();
    if (source instanceof DBSObject) {
        tableName = omitSchema ? DBUtils.getQuotedIdentifier((DBSObject) source) : DBUtils.getObjectFullName(source, DBPEvaluationContext.UI);
    } else {
        throw new DBException("SQL export may be done only from table object");
    }
    rowCount = 0;
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBException(org.jkiss.dbeaver.DBException) DBPNamedObject(org.jkiss.dbeaver.model.DBPNamedObject)

Example 98 with DBException

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

the class DataExporterXML method writeImageCell.

private void writeImageCell(File file) throws DBException {
    if (file != null && file.exists()) {
        Image image = null;
        try {
            image = ImageIO.read(file);
        } catch (IOException e) {
            throw new DBException("Can't read an exported image " + image, e);
        }
        if (image != null) {
            String imagePath = file.getAbsolutePath();
            imagePath = "files/" + imagePath.substring(imagePath.lastIndexOf(File.separator));
            out.write(imagePath);
        }
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) IOException(java.io.IOException)

Example 99 with DBException

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

the class SQLEditor method processQueries.

private void processQueries(@NotNull final List<SQLQuery> queries, final boolean newTab, final boolean export, final boolean checkSession) {
    if (queries.isEmpty()) {
        // Nothing to process
        return;
    }
    final DBPDataSourceContainer container = getDataSourceContainer();
    if (checkSession) {
        try {
            DBRProgressListener connectListener = new DBRProgressListener() {

                @Override
                public void onTaskFinished(IStatus status) {
                    if (!status.isOK() || container == null || !container.isConnected()) {
                        UIUtils.showErrorDialog(getSite().getShell(), CoreMessages.editors_sql_error_cant_obtain_session, null, status);
                        return;
                    }
                    // Make a small pause to let all UI connection listeners to finish
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                    // it's ok
                    }
                    DBeaverUI.syncExec(new Runnable() {

                        @Override
                        public void run() {
                            processQueries(queries, newTab, export, false);
                        }
                    });
                }
            };
            if (!checkSession(connectListener)) {
                return;
            }
        } catch (DBException ex) {
            ResultSetViewer viewer = getActiveResultSetViewer();
            if (viewer != null) {
                viewer.setStatus(ex.getMessage(), DBPMessageType.ERROR);
            }
            UIUtils.showErrorDialog(getSite().getShell(), CoreMessages.editors_sql_error_cant_obtain_session, ex.getMessage());
            return;
        }
    }
    if (sashForm.getMaximizedControl() != null) {
        sashForm.setMaximizedControl(null);
    }
    // Save editor
    if (getActivePreferenceStore().getBoolean(SQLPreferenceConstants.AUTO_SAVE_ON_EXECUTE) && isDirty()) {
        doSave(new NullProgressMonitor());
    }
    final boolean isSingleQuery = (queries.size() == 1);
    if (!newTab || !isSingleQuery) {
        // We don't need new tab or we are executing a script - so close all extra tabs
        closeExtraResultTabs(null);
    }
    if (newTab) {
        // Execute each query in a new tab
        for (int i = 0; i < queries.size(); i++) {
            SQLQuery query = queries.get(i);
            QueryProcessor queryProcessor = (i == 0 && !isSingleQuery ? curQueryProcessor : createQueryProcessor(queries.size() == 1));
            queryProcessor.processQueries(Collections.singletonList(query), true, export);
        }
    } else {
        // Use current tab.
        // If current tab was pinned then use first tab
        final QueryResultsContainer firstResults = curQueryProcessor.getFirstResults();
        if (firstResults.isPinned()) {
            curQueryProcessor = queryProcessors.get(0);
        }
        closeExtraResultTabs(curQueryProcessor);
        if (firstResults.tabItem != null) {
            resultTabs.setSelection(firstResults.tabItem);
        }
        curQueryProcessor.processQueries(queries, false, export);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBRProgressListener(org.jkiss.dbeaver.model.runtime.DBRProgressListener) SQLQuery(org.jkiss.dbeaver.model.sql.SQLQuery) Point(org.eclipse.swt.graphics.Point) ResultSetViewer(org.jkiss.dbeaver.ui.controls.resultset.ResultSetViewer)

Example 100 with DBException

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

the class NavigatorHandlerObjectOpen method refreshDatabaseNode.

private static void refreshDatabaseNode(@NotNull DBNDatabaseNode selectedNode) throws InvocationTargetException, InterruptedException {
    final DBNDatabaseNode nodeToRefresh = selectedNode;
    DBeaverUI.runInProgressService(new DBRRunnableWithProgress() {

        @Override
        public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            try {
                nodeToRefresh.refreshNode(monitor, nodeToRefresh);
            } catch (DBException e) {
                log.error("Error refreshing database object", e);
            }
        }
    });
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) InvocationTargetException(java.lang.reflect.InvocationTargetException)

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