Search in sources :

Example 1 with DBCEntityMetaData

use of org.jkiss.dbeaver.model.exec.DBCEntityMetaData in project dbeaver by serge-rider.

the class SQLSemanticProcessor method isValidTableColumn.

private static boolean isValidTableColumn(DBRProgressMonitor monitor, DBPDataSource dataSource, Table table, DBDAttributeConstraint co) throws DBException {
    DBSAttributeBase attribute = co.getAttribute();
    if (attribute instanceof DBDAttributeBinding) {
        attribute = ((DBDAttributeBinding) attribute).getMetaAttribute();
    }
    if (table != null && attribute instanceof DBCAttributeMetaData) {
        DBSEntityAttribute entityAttribute = null;
        DBCEntityMetaData entityMetaData = ((DBCAttributeMetaData) attribute).getEntityMetaData();
        if (entityMetaData != null) {
            DBSEntity entity = DBUtils.getEntityFromMetaData(monitor, DBUtils.getDefaultContext(dataSource, true), entityMetaData);
            if (entity != null) {
                entityAttribute = entity.getAttribute(monitor, co.getAttributeName());
            }
        }
        // No such attribute in entity. Do not use table prefix (#6927)
        return entityAttribute != null;
    }
    return true;
}
Also used : DBCAttributeMetaData(org.jkiss.dbeaver.model.exec.DBCAttributeMetaData) DBSEntityAttribute(org.jkiss.dbeaver.model.struct.DBSEntityAttribute) DBCEntityMetaData(org.jkiss.dbeaver.model.exec.DBCEntityMetaData) DBSAttributeBase(org.jkiss.dbeaver.model.struct.DBSAttributeBase) DBSEntity(org.jkiss.dbeaver.model.struct.DBSEntity) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding)

Example 2 with DBCEntityMetaData

use of org.jkiss.dbeaver.model.exec.DBCEntityMetaData 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)

Aggregations

DBCEntityMetaData (org.jkiss.dbeaver.model.exec.DBCEntityMetaData)2 Connection (java.sql.Connection)1 DBDAttributeBinding (org.jkiss.dbeaver.model.data.DBDAttributeBinding)1 DBCAttributeMetaData (org.jkiss.dbeaver.model.exec.DBCAttributeMetaData)1 JDBCConnectionImpl (org.jkiss.dbeaver.model.impl.jdbc.exec.JDBCConnectionImpl)1 DBSAttributeBase (org.jkiss.dbeaver.model.struct.DBSAttributeBase)1 DBSEntity (org.jkiss.dbeaver.model.struct.DBSEntity)1 DBSEntityAttribute (org.jkiss.dbeaver.model.struct.DBSEntityAttribute)1