Search in sources :

Example 61 with DBException

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

the class DB2ServerApplicationManager method alterSession.

@Override
public void alterSession(DBCSession session, DB2ServerApplication sessionType, Map<String, Object> options) throws DBException {
    try {
        String cmd = String.format(FORCE_APP_CMD, sessionType.getAgentId());
        DB2Utils.callAdminCmd(session.getProgressMonitor(), dataSource, cmd);
    } catch (SQLException e) {
        throw new DBException(e, session.getDataSource());
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) SQLException(java.sql.SQLException)

Example 62 with DBException

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

the class ConfigImportWizardPageSqlDeveloper method loadConnections.

@Override
protected void loadConnections(ImportData importData) throws DBException {
    importData.addDriver(oraDriver);
    File homeFolder = RuntimeUtils.getUserHomeDir();
    File sqlDevHome = new File(homeFolder, "AppData/Roaming/" + SQLD_HOME_FOLDER);
    if (!sqlDevHome.exists()) {
        sqlDevHome = new File(homeFolder, "Application Data/" + SQLD_HOME_FOLDER);
        if (!sqlDevHome.exists()) {
            throw new DBException("SQL Developer installation not found");
        }
    }
    final File[] sysConfFolders = sqlDevHome.listFiles(new FilenameFilter() {

        @Override
        public boolean accept(File dir, String name) {
            return name.contains(SQLD_SYSCONFIG_FOLDER);
        }
    });
    if (sysConfFolders == null || sysConfFolders.length == 0) {
        throw new DBException("SQL Developer config not found");
    }
    for (File sysConfFolder : sysConfFolders) {
        final File[] connectionFolders = sysConfFolder.listFiles(new FilenameFilter() {

            @Override
            public boolean accept(File dir, String name) {
                return name.contains(SQLD_CONNECTIONS_FOLDER);
            }
        });
        if (connectionFolders == null || connectionFolders.length != 1) {
            continue;
        }
        final File connectionFolder = connectionFolders[0];
        final File connectionsFile = new File(connectionFolder, SQLD_CONFIG_FILE);
        if (!connectionsFile.exists()) {
            continue;
        }
        parseConnections(connectionsFile, importData);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) FilenameFilter(java.io.FilenameFilter) File(java.io.File)

Example 63 with DBException

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

the class PostgreTableManager method appendTableModifiers.

@Override
protected void appendTableModifiers(PostgreTableBase tableBase, NestedObjectCommand tableProps, StringBuilder ddl) {
    if (tableBase instanceof PostgreTableRegular) {
        final VoidProgressMonitor monitor = VoidProgressMonitor.INSTANCE;
        PostgreTableRegular table = (PostgreTableRegular) tableBase;
        try {
            final List<PostgreTableInheritance> superTables = table.getSuperInheritance(monitor);
            if (!CommonUtils.isEmpty(superTables)) {
                ddl.append("\nINHERITS (");
                for (int i = 0; i < superTables.size(); i++) {
                    if (i > 0)
                        ddl.append(",");
                    ddl.append(superTables.get(i).getAssociatedEntity().getFullyQualifiedName(DBPEvaluationContext.DDL));
                }
                ddl.append(")");
            }
            ddl.append("\nWITH (\n\tOIDS=").append(table.isHasOids() ? "TRUE" : "FALSE").append("\n)");
        } catch (DBException e) {
            log.error(e);
        }
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) VoidProgressMonitor(org.jkiss.dbeaver.model.runtime.VoidProgressMonitor)

Example 64 with DBException

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

the class PostgreAttribute method loadInfo.

private void loadInfo(JDBCResultSet dbResult) throws DBException {
    setName(JDBCUtils.safeGetString(dbResult, "attname"));
    setOrdinalPosition(JDBCUtils.safeGetInt(dbResult, "attnum"));
    setRequired(JDBCUtils.safeGetBoolean(dbResult, "attnotnull"));
    final long typeId = JDBCUtils.safeGetLong(dbResult, "atttypid");
    dataType = getTable().getDatabase().getDataType(typeId);
    if (dataType == null) {
        throw new DBException("Attribute data type '" + typeId + "' not found");
    }
    setTypeName(dataType.getTypeName());
    setValueType(dataType.getTypeID());
    setDefaultValue(JDBCUtils.safeGetString(dbResult, "def_value"));
    int typeMod = JDBCUtils.safeGetInt(dbResult, "atttypmod");
    int maxLength = PostgreUtils.getAttributePrecision(typeId, typeMod);
    DBPDataKind dataKind = dataType.getDataKind();
    if (dataKind == DBPDataKind.NUMERIC || dataKind == DBPDataKind.DATETIME) {
        setMaxLength(0);
    } else {
        if (maxLength <= 0) {
            maxLength = PostgreUtils.getDisplaySize(typeId, typeMod);
        }
        if (maxLength >= 0) {
            setMaxLength(maxLength);
        } else {
        // TypeMod can be anything.
        // It is often used in packed format and has no numeric meaning at all
        //setMaxLength(typeMod);
        }
    }
    setPrecision(maxLength);
    setScale(PostgreUtils.getScale(typeId, typeMod));
    this.description = JDBCUtils.safeGetString(dbResult, "description");
    this.arrayDim = JDBCUtils.safeGetInt(dbResult, "attndims");
    this.inheritorsCount = JDBCUtils.safeGetInt(dbResult, "attinhcount");
    setPersisted(true);
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBPDataKind(org.jkiss.dbeaver.model.DBPDataKind)

Example 65 with DBException

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

the class PostgreDataSource method refreshDefaultObject.

@Override
public boolean refreshDefaultObject(@NotNull DBCSession session) throws DBException {
    // Check only for schema change. Database cannot be changed by any SQL query
    final PostgreDatabase activeDatabase = getDefaultObject();
    if (activeDatabase == null) {
        return false;
    }
    try {
        String oldDefSchema = activeSchemaName;
        determineDefaultObjects((JDBCSession) session);
        if (activeSchemaName != null && !CommonUtils.equalObjects(oldDefSchema, activeSchemaName)) {
            final PostgreSchema newSchema = activeDatabase.getSchema(session.getProgressMonitor(), activeSchemaName);
            if (newSchema != null) {
                activeDatabase.setDefaultObject(session.getProgressMonitor(), newSchema);
                return true;
            }
        }
        return false;
    } catch (SQLException e) {
        throw new DBException(e, this);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) SQLException(java.sql.SQLException)

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