Search in sources :

Example 1 with JDBCConnectionImpl

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

the class SQLServerUtils method getTableFromQuery.

public static SQLServerTableBase getTableFromQuery(DBCSession session, SQLQuery sqlQuery, SQLServerDataSource dataSource) throws DBException, SQLException {
    DBCEntityMetaData singleSource = sqlQuery.getSingleSource();
    String catalogName = null;
    if (singleSource != null) {
        catalogName = singleSource.getCatalogName();
    }
    Connection original = null;
    if (session instanceof JDBCConnectionImpl) {
        original = ((JDBCConnectionImpl) session).getOriginal();
    }
    if (catalogName == null && original != null) {
        catalogName = original.getCatalog();
    }
    if (catalogName != null) {
        SQLServerDatabase database = dataSource.getDatabase(catalogName);
        String schemaName = null;
        if (singleSource != null) {
            schemaName = singleSource.getSchemaName();
        }
        if (schemaName == null && original != null) {
            schemaName = original.getSchema();
        }
        if (database != null && schemaName != null) {
            SQLServerSchema schema = database.getSchema(schemaName);
            if (schema != null && singleSource != null) {
                return schema.getTable(session.getProgressMonitor(), singleSource.getEntityName());
            }
        }
    }
    return null;
}
Also used : JDBCConnectionImpl(org.jkiss.dbeaver.model.impl.jdbc.exec.JDBCConnectionImpl) DBCEntityMetaData(org.jkiss.dbeaver.model.exec.DBCEntityMetaData) Connection(java.sql.Connection)

Example 2 with JDBCConnectionImpl

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

the class SQLServerUtils method getTableFromQuery.

public static SQLServerTableBase getTableFromQuery(DBCSession session, SQLQuery sqlQuery, SQLServerDataSource dataSource) throws DBException, SQLException {
    DBCEntityMetaData singleSource = sqlQuery.getSingleSource();
    String catalogName = null;
    if (singleSource != null) {
        catalogName = singleSource.getCatalogName();
    }
    Connection original = null;
    if (session instanceof JDBCConnectionImpl) {
        original = ((JDBCConnectionImpl) session).getOriginal();
    }
    if (catalogName == null && original != null) {
        catalogName = original.getCatalog();
    }
    if (catalogName != null) {
        SQLServerDatabase database = dataSource.getDatabase(catalogName);
        String schemaName = null;
        if (singleSource != null) {
            schemaName = singleSource.getSchemaName();
        }
        if (schemaName == null && original != null) {
            schemaName = original.getSchema();
        }
        if (database != null && schemaName != null) {
            SQLServerSchema schema = database.getSchema(schemaName);
            if (schema != null && singleSource != null) {
                return schema.getTable(session.getProgressMonitor(), singleSource.getEntityName());
            }
        }
    }
    return null;
}
Also used : JDBCConnectionImpl(org.jkiss.dbeaver.model.impl.jdbc.exec.JDBCConnectionImpl) DBCEntityMetaData(org.jkiss.dbeaver.model.exec.DBCEntityMetaData) Connection(java.sql.Connection)

Aggregations

Connection (java.sql.Connection)2 DBCEntityMetaData (org.jkiss.dbeaver.model.exec.DBCEntityMetaData)2 JDBCConnectionImpl (org.jkiss.dbeaver.model.impl.jdbc.exec.JDBCConnectionImpl)2