Search in sources :

Example 21 with DBException

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

the class SQLConstraintManager method appendConstraintDefinition.

protected void appendConstraintDefinition(StringBuilder decl, DBECommandAbstract<OBJECT_TYPE> command) {
    //$NON-NLS-1$
    decl.append(" (");
    // Get columns using void monitor
    try {
        List<? extends DBSEntityAttributeRef> attrs = command.getObject().getAttributeReferences(VoidProgressMonitor.INSTANCE);
        if (attrs != null) {
            boolean firstColumn = true;
            for (DBSEntityAttributeRef constraintColumn : attrs) {
                final DBSEntityAttribute attribute = constraintColumn.getAttribute();
                if (attribute == null) {
                    continue;
                }
                //$NON-NLS-1$
                if (!firstColumn)
                    decl.append(",");
                firstColumn = false;
                decl.append(DBUtils.getQuotedIdentifier(attribute));
            }
        }
    } catch (DBException e) {
        log.warn("Can't obtain attribute references", e);
    }
    //$NON-NLS-1$
    decl.append(")");
}
Also used : DBSEntityAttributeRef(org.jkiss.dbeaver.model.struct.DBSEntityAttributeRef) DBException(org.jkiss.dbeaver.DBException) DBSEntityAttribute(org.jkiss.dbeaver.model.struct.DBSEntityAttribute)

Example 22 with DBException

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

the class SQLIndexManager method addObjectCreateActions.

@Override
protected void addObjectCreateActions(List<DBEPersistAction> actions, ObjectCreateCommand command) {
    final TABLE_TYPE table = command.getObject().getTable();
    final OBJECT_TYPE index = command.getObject();
    // Create index
    final String indexName = DBUtils.getQuotedIdentifier(index.getDataSource(), index.getName());
    index.setName(indexName);
    StringBuilder decl = new StringBuilder(40);
    decl.append("CREATE ");
    if (index.isUnique()) {
        decl.append("UNIQUE ");
    }
    //$NON-NLS-1$
    decl.append("INDEX ").append(indexName).append(" ON ").append(//$NON-NLS-1$
    table.getFullyQualifiedName(DBPEvaluationContext.DDL)).append(//$NON-NLS-1$
    " (");
    try {
        // Get columns using void monitor
        boolean firstColumn = true;
        for (DBSTableIndexColumn indexColumn : CommonUtils.safeCollection(command.getObject().getAttributeReferences(VoidProgressMonitor.INSTANCE))) {
            //$NON-NLS-1$
            if (!firstColumn)
                decl.append(",");
            firstColumn = false;
            decl.append(indexColumn.getName());
            appendIndexColumnModifiers(decl, indexColumn);
        }
    } catch (DBException e) {
        log.error(e);
    }
    //$NON-NLS-1$
    decl.append(")");
    actions.add(new SQLDatabasePersistAction(ModelMessages.model_jdbc_create_new_index, decl.toString()));
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBSTableIndexColumn(org.jkiss.dbeaver.model.struct.rdb.DBSTableIndexColumn) SQLDatabasePersistAction(org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)

Example 23 with DBException

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

the class DBNProject method rename.

@Override
public void rename(DBRProgressMonitor monitor, String newName) throws DBException {
    try {
        final IProjectDescription description = getProject().getDescription();
        description.setName(newName);
        getProject().move(description, true, monitor.getNestedMonitor());
    } catch (CoreException e) {
        throw new DBException("Can't rename project", e);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) CoreException(org.eclipse.core.runtime.CoreException)

Example 24 with DBException

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

the class DBNProject method readChildNodes.

@Override
protected DBNNode[] readChildNodes(DBRProgressMonitor monitor) throws DBException {
    IProject project = getProject();
    if (!project.isOpen()) {
        try {
            project.open(monitor.getNestedMonitor());
            project.refreshLocal(IFile.DEPTH_ONE, monitor.getNestedMonitor());
        } catch (CoreException e) {
            throw new DBException("Can't open project '" + project.getName() + "'", e);
        }
    }
    DBPDataSourceRegistry dataSourceRegistry = getModel().getPlatform().getProjectManager().getDataSourceRegistry(project);
    DBNNode[] children = super.readChildNodes(monitor);
    if (dataSourceRegistry != null) {
        children = ArrayUtils.insertArea(DBNNode.class, children, 0, new Object[] { new DBNProjectDatabases(this, dataSourceRegistry) });
    }
    return children;
}
Also used : DBException(org.jkiss.dbeaver.DBException) CoreException(org.eclipse.core.runtime.CoreException) DBPDataSourceRegistry(org.jkiss.dbeaver.model.app.DBPDataSourceRegistry)

Example 25 with DBException

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

the class DBNResource method refreshNode.

@Override
public DBNNode refreshNode(DBRProgressMonitor monitor, Object source) throws DBException {
    try {
        resource.refreshLocal(IResource.DEPTH_INFINITE, monitor.getNestedMonitor());
        // FIXME: The only workaround is to check real file and drop resource by force
        if (!resource.getLocation().toFile().exists()) {
            log.warn("Resource '" + resource.getName() + "' doesn't exists on file system: deleted in workspace");
            resource.delete(true, monitor.getNestedMonitor());
        }
    } catch (CoreException e) {
        throw new DBException("Can't refresh resource", e);
    }
    return this;
}
Also used : DBException(org.jkiss.dbeaver.DBException) CoreException(org.eclipse.core.runtime.CoreException)

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