Search in sources :

Example 1 with JDBCExecutionContext

use of org.jkiss.dbeaver.model.impl.jdbc.JDBCExecutionContext in project dbeaver by serge-rider.

the class ExasolDataSource method setDefaultObject.

@Override
public void setDefaultObject(@NotNull DBRProgressMonitor monitor, @NotNull DBSObject object) throws DBException {
    final ExasolSchema oldSelectedEntity = getDefaultObject();
    if (!(object instanceof ExasolSchema)) {
        throw new IllegalArgumentException("Invalid object type: " + object);
    }
    for (JDBCExecutionContext context : getAllContexts()) {
        setCurrentSchema(monitor, context, (ExasolSchema) object);
    }
    activeSchemaName = object.getName();
    // Send notifications
    if (oldSelectedEntity != null) {
        DBUtils.fireObjectSelect(oldSelectedEntity, false);
    }
    if (this.activeSchemaName != null) {
        DBUtils.fireObjectSelect(object, true);
    }
}
Also used : JDBCExecutionContext(org.jkiss.dbeaver.model.impl.jdbc.JDBCExecutionContext)

Example 2 with JDBCExecutionContext

use of org.jkiss.dbeaver.model.impl.jdbc.JDBCExecutionContext in project dbeaver by serge-rider.

the class PostgreDataSource method setDefaultObject.

@Override
public void setDefaultObject(@NotNull DBRProgressMonitor monitor, @NotNull DBSObject object) throws DBException {
    final PostgreDatabase oldDatabase = getDefaultObject();
    if (!(object instanceof PostgreDatabase)) {
        throw new IllegalArgumentException("Invalid object type: " + object);
    }
    final PostgreDatabase newDatabase = (PostgreDatabase) object;
    if (oldDatabase == newDatabase) {
        // The same
        return;
    }
    // FIXME: make real target database change
    // 1. Check active transactions
    // 2. Reconnect all open contexts
    // 3. Refresh datasource tree
    activeDatabaseName = object.getName();
    for (JDBCExecutionContext context : getAllContexts()) {
        context.reconnect(monitor);
    }
    getDefaultInstance().cacheDataTypes(monitor);
    if (oldDatabase != null) {
        DBUtils.fireObjectSelect(oldDatabase, false);
        DBUtils.fireObjectUpdate(oldDatabase, false);
    }
    DBUtils.fireObjectSelect(newDatabase, true);
    DBUtils.fireObjectUpdate(newDatabase, true);
}
Also used : JDBCExecutionContext(org.jkiss.dbeaver.model.impl.jdbc.JDBCExecutionContext)

Example 3 with JDBCExecutionContext

use of org.jkiss.dbeaver.model.impl.jdbc.JDBCExecutionContext in project dbeaver by serge-rider.

the class SQLServerMetaModel method getServerType.

public static ServerType getServerType(DBRProgressMonitor monitor, DBPDataSource dataSource) {
    JDBCExecutionContext context = (JDBCExecutionContext) dataSource.getDefaultContext(true);
    try {
        Connection connection = context.getConnection(monitor);
        String connectionClass = connection.getClass().getName();
        if (connectionClass.contains("jtds")) {
            try {
                Integer serverType = (Integer) connection.getClass().getMethod("getServerType").invoke(connection);
                if (serverType == 1) {
                    return ServerType.SQL_SERVER;
                } else {
                    return ServerType.SYBASE;
                }
            } catch (Throwable e) {
                log.debug("Can't determine JTDS driver type", e);
                return ServerType.SQL_SERVER;
            }
        } else if (connectionClass.contains("microsoft")) {
            return ServerType.SQL_SERVER;
        } else {
            return ServerType.SYBASE;
        }
    } catch (SQLException e) {
        return ServerType.UNKNOWN;
    }
}
Also used : JDBCExecutionContext(org.jkiss.dbeaver.model.impl.jdbc.JDBCExecutionContext) SQLException(java.sql.SQLException) Connection(java.sql.Connection)

Example 4 with JDBCExecutionContext

use of org.jkiss.dbeaver.model.impl.jdbc.JDBCExecutionContext in project dbeaver by serge-rider.

the class DB2DataSource method setDefaultObject.

@Override
public void setDefaultObject(@NotNull DBRProgressMonitor monitor, @NotNull DBSObject object) throws DBException {
    final DB2Schema oldSelectedEntity = getDefaultObject();
    if (!(object instanceof DB2Schema)) {
        throw new IllegalArgumentException("Invalid object type: " + object);
    }
    for (JDBCExecutionContext context : getAllContexts()) {
        setCurrentSchema(monitor, context, (DB2Schema) object);
    }
    activeSchemaName = object.getName();
    // Send notifications
    if (oldSelectedEntity != null) {
        DBUtils.fireObjectSelect(oldSelectedEntity, false);
    }
    if (this.activeSchemaName != null) {
        DBUtils.fireObjectSelect(object, true);
    }
}
Also used : JDBCExecutionContext(org.jkiss.dbeaver.model.impl.jdbc.JDBCExecutionContext)

Example 5 with JDBCExecutionContext

use of org.jkiss.dbeaver.model.impl.jdbc.JDBCExecutionContext in project dbeaver by serge-rider.

the class OracleDataSource method setDefaultObject.

@Override
public void setDefaultObject(@NotNull DBRProgressMonitor monitor, @NotNull DBSObject object) throws DBException {
    final OracleSchema oldSelectedEntity = getDefaultObject();
    if (!(object instanceof OracleSchema)) {
        throw new IllegalArgumentException("Invalid object type: " + object);
    }
    for (JDBCExecutionContext context : getAllContexts()) {
        setCurrentSchema(monitor, context, (OracleSchema) object);
    }
    activeSchemaName = object.getName();
    // Send notifications
    if (oldSelectedEntity != null) {
        DBUtils.fireObjectSelect(oldSelectedEntity, false);
    }
    if (this.activeSchemaName != null) {
        DBUtils.fireObjectSelect(object, true);
    }
}
Also used : JDBCExecutionContext(org.jkiss.dbeaver.model.impl.jdbc.JDBCExecutionContext)

Aggregations

JDBCExecutionContext (org.jkiss.dbeaver.model.impl.jdbc.JDBCExecutionContext)8 DBException (org.jkiss.dbeaver.DBException)2 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1