Search in sources :

Example 6 with JDBCExecutionContext

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

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);
    // Update database name and URL in connection settings and save datasources
    DBPConnectionConfiguration conConfig = getContainer().getConnectionConfiguration();
    conConfig.setDatabaseName(activeDatabaseName);
    conConfig.setUrl(getContainer().getDriver().getDataSourceProvider().getConnectionURL(getContainer().getDriver(), conConfig));
    getContainer().getRegistry().flushConfig();
    // Notify UI
    if (oldDatabase != null) {
        DBUtils.fireObjectSelect(oldDatabase, false);
        DBUtils.fireObjectUpdate(oldDatabase, false);
    }
    DBUtils.fireObjectSelect(newDatabase, true);
    DBUtils.fireObjectUpdate(newDatabase, true);
}
Also used : DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration) JDBCExecutionContext(org.jkiss.dbeaver.model.impl.jdbc.JDBCExecutionContext)

Example 7 with JDBCExecutionContext

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

the class PostgreDatabase method setDefaultObject.

@Override
public void setDefaultObject(@NotNull DBRProgressMonitor monitor, @NotNull DBSObject object) throws DBException {
    if (object instanceof PostgreSchema) {
        PostgreSchema oldActive = getDefaultObject();
        if (oldActive == object) {
            return;
        }
        for (JDBCExecutionContext context : dataSource.getAllContexts()) {
            setSearchPath(monitor, (PostgreSchema) object, context);
        }
        dataSource.setActiveSchemaName(object.getName());
        dataSource.setSearchPath(object.getName());
        if (oldActive != null) {
            DBUtils.fireObjectSelect(oldActive, false);
        }
        DBUtils.fireObjectSelect(object, true);
    }
}
Also used : JDBCExecutionContext(org.jkiss.dbeaver.model.impl.jdbc.JDBCExecutionContext)

Example 8 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 9 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)

Example 10 with JDBCExecutionContext

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

the class PostgreDatabase method setDefaultObject.

@Override
public void setDefaultObject(@NotNull DBRProgressMonitor monitor, @NotNull DBSObject object) throws DBException {
    if (object instanceof PostgreSchema) {
        PostgreSchema oldActive = getDefaultObject();
        if (oldActive == object) {
            return;
        }
        for (JDBCExecutionContext context : dataSource.getAllContexts()) {
            setSearchPath(monitor, (PostgreSchema) object, context);
        }
        dataSource.setActiveSchemaName(object.getName());
        dataSource.setSearchPath(object.getName());
        if (oldActive != null) {
            DBUtils.fireObjectSelect(oldActive, false);
        }
        DBUtils.fireObjectSelect(object, true);
    }
}
Also used : JDBCExecutionContext(org.jkiss.dbeaver.model.impl.jdbc.JDBCExecutionContext)

Aggregations

JDBCExecutionContext (org.jkiss.dbeaver.model.impl.jdbc.JDBCExecutionContext)17 DBException (org.jkiss.dbeaver.DBException)5 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 DBPConnectionConfiguration (org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration)1