Search in sources :

Example 46 with JDBCStatement

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

the class ExasolUtils method readSessions.

public static Collection<ExasolServerSession> readSessions(DBRProgressMonitor progressMonitor, JDBCSession session) throws SQLException {
    LOG.debug("read sessions");
    List<ExasolServerSession> listSessions = new ArrayList<>();
    // check dba view
    try {
        try (JDBCStatement dbStat = session.createStatement()) {
            try (JDBCResultSet dbResult = dbStat.executeQuery(SESS_DBA_QUERY)) {
                while (dbResult.next()) {
                    listSessions.add(new ExasolServerSession(dbResult));
                }
            }
        }
    // now try all view
    } catch (SQLException e) {
        try (JDBCStatement dbStat = session.createStatement()) {
            try (JDBCResultSet dbResult = dbStat.executeQuery(SESS_ALL_QUERY)) {
                while (dbResult.next()) {
                    listSessions.add(new ExasolServerSession(dbResult));
                }
            }
        }
    }
    return listSessions;
}
Also used : JDBCStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement) SQLException(java.sql.SQLException) JDBCResultSet(org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet) ArrayList(java.util.ArrayList) ExasolServerSession(org.jkiss.dbeaver.ext.exasol.model.app.ExasolServerSession)

Example 47 with JDBCStatement

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

the class ExasolViewCache method prepareChildrenStatement.

@Override
protected JDBCStatement prepareChildrenStatement(@NotNull JDBCSession session, @NotNull ExasolSchema exasolSchema, @Nullable ExasolView forView) throws SQLException {
    String sql;
    String tablePrefix = exasolSchema.getDataSource().getTablePrefix(ExasolSysTablePrefix.ALL);
    if (exasolSchema.getName().equals("SYS") || exasolSchema.getName().equals("EXA_STATISTICS")) {
        if (forView != null) {
            sql = String.format(SQL_COLS_SYS_VIEW, ExasolUtils.quoteString(exasolSchema.getName()), ExasolUtils.quoteString(forView.getName()));
        } else {
            sql = String.format(SQL_COLS_SYS_ALL, ExasolUtils.quoteString(exasolSchema.getName()));
        }
    } else {
        if (forView != null) {
            sql = String.format(SQL_COLS_VIEW, tablePrefix, ExasolUtils.quoteString(exasolSchema.getName()), ExasolUtils.quoteString(forView.getName()));
        } else {
            sql = String.format(SQL_COLS_ALL, tablePrefix, ExasolUtils.quoteString(exasolSchema.getName()));
        }
    }
    JDBCStatement dbStat = session.createStatement();
    dbStat.setQueryString(sql);
    return dbStat;
}
Also used : JDBCStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement)

Example 48 with JDBCStatement

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

the class ExasolStructureAssistant method findConstraintsByMask.

private void findConstraintsByMask(JDBCSession session, ExasolSchema schema, String objectNameMask, int maxResults, List<DBSObjectReference> references, String constType) throws SQLException, DBException {
    DBRProgressMonitor monitor = session.getProgressMonitor();
    // don't use parameter marks because of performance
    String sql = "";
    if (schema == null) {
        sql = String.format(sqlConstraintsAll, ExasolUtils.quoteString(objectNameMask), constType);
    } else {
        sql = String.format(sqlConstraintsSchema, ExasolUtils.quoteString(schema.getName()), constType, ExasolUtils.quoteString(objectNameMask));
    }
    try (JDBCStatement dbstat = session.createStatement()) {
        try (JDBCResultSet dbResult = dbstat.executeQuery(sql)) {
            int num = maxResults;
            while (dbResult.next() && num-- > 0) {
                if (monitor.isCanceled()) {
                    break;
                }
                final String schemaName = JDBCUtils.safeGetString(dbResult, "CONSTRAINT_SCHEMA");
                final String tableName = JDBCUtils.safeGetString(dbResult, "CONSTRAINT_TABLE");
                final String constName = JDBCUtils.safeGetString(dbResult, "CONSTRAINT_NAME");
                final Class<?> classType;
                if (constType.equals("PRIMARY KEY")) {
                    classType = ExasolTableUniqueKey.class;
                } else if (constType.equals("FOREIGN KEY")) {
                    classType = ExasolTableForeignKey.class;
                } else {
                    throw new DBException("Unkown constraint type" + constType);
                }
                references.add(new AbstractObjectReference(constName, dataSource.getSchema(monitor, schemaName), null, classType, RelationalObjectType.TYPE_CONSTRAINT) {

                    @Override
                    public DBSObject resolveObject(DBRProgressMonitor monitor) throws DBException {
                        ExasolSchema tableSchema = schema != null ? schema : dataSource.getSchema(monitor, schemaName);
                        if (tableSchema == null) {
                            throw new DBException("Table schema '" + schemaName + "' not found");
                        }
                        ExasolTable table = tableSchema.getTable(monitor, tableName);
                        if (table == null) {
                            throw new DBException("Table '" + tableName + "' not found in schema  '" + schemaName + "' not found");
                        }
                        if (classType.equals(ExasolTableForeignKey.class)) {
                            ExasolTableForeignKey foreignKey = (ExasolTableForeignKey) table.getAssociation(monitor, constName);
                            if (foreignKey == null)
                                throw new DBException("Foreign Key  '" + constName + "' for Table '" + tableName + "' not found in schema '" + schemaName + "'");
                            return foreignKey;
                        } else {
                            ExasolTableUniqueKey primaryKey = table.getConstraint(monitor, constName);
                            if (primaryKey == null)
                                throw new DBException("Primary Key '" + constName + "' for Table '" + tableName + "' not found in schema '" + schemaName + "'");
                            return primaryKey;
                        }
                    }
                });
            }
        }
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) JDBCStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement) AbstractObjectReference(org.jkiss.dbeaver.model.impl.struct.AbstractObjectReference) JDBCResultSet(org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)

Example 49 with JDBCStatement

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

the class ExasolDataTypeCache method prepareObjectsStatement.

@NotNull
@Override
protected JDBCStatement prepareObjectsStatement(@NotNull JDBCSession session, @NotNull ExasolDataSource owner) throws SQLException {
    JDBCStatement dbstat = session.createStatement();
    dbstat.setQueryString(SQL_TYPE_CACHE);
    return dbstat;
}
Also used : JDBCStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement) NotNull(org.jkiss.code.NotNull)

Example 50 with JDBCStatement

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

the class ExasolSQLDialect method initDriverSettings.

public void initDriverSettings(JDBCDataSource dataSource, JDBCDatabaseMetaData metaData) {
    super.initDriverSettings(dataSource, metaData);
    Collections.addAll(tableQueryWords, "DESC");
    try {
        JDBCSession session = DBUtils.openMetaSession(new VoidProgressMonitor(), dataSource, "");
        try (JDBCStatement stmt = session.createStatement()) {
            try (JDBCResultSet dbResult = stmt.executeQuery("/*snapshot execution*/ SELECT \"VALUE\" FROM \"$ODBCJDBC\".DB_METADATA WHERE name = 'aggregateFunctions'")) {
                if (dbResult.next()) {
                    String keyWord = dbResult.getString(1);
                    String[] aggregateFunctions = keyWord.split(",");
                    this.addExtraFunctions(aggregateFunctions);
                }
            }
            try (JDBCResultSet dbResult = stmt.executeQuery("/*snapshot execution*/ SELECT keyword FROM sys.EXA_SQL_KEYWORDS esk WHERE RESERVED")) {
                while (dbResult.next()) {
                    String keyWord = dbResult.getString("KEYWORD");
                    super.addSQLKeyword(keyWord);
                }
            }
        }
    } catch (SQLException e) {
        LOG.warn("Could not retrieve functions list from Exasol dictionary");
    }
    @SuppressWarnings("serial") ArrayList<String> value = new ArrayList<String>() {

        {
            add("KERBEROS");
            add("JDBC");
            add("BYTE");
            add("BIT");
            add("PRECEDENCE");
            add("GROUP_TEMP_DB_RAM_LIMIT");
            add("USER_TEMP_DB_RAM_LIMIT");
            add("SESSION_TEMP_DB_RAM_LIMIT");
            add("CPU_WEIGHT");
        }
    };
    this.addKeywords(value, DBPKeywordType.KEYWORD);
}
Also used : JDBCSession(org.jkiss.dbeaver.model.exec.jdbc.JDBCSession) JDBCStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement) SQLException(java.sql.SQLException) JDBCResultSet(org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet) ArrayList(java.util.ArrayList) VoidProgressMonitor(org.jkiss.dbeaver.model.runtime.VoidProgressMonitor)

Aggregations

JDBCStatement (org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement)70 JDBCResultSet (org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet)40 SQLException (java.sql.SQLException)32 JDBCSession (org.jkiss.dbeaver.model.exec.jdbc.JDBCSession)26 DBException (org.jkiss.dbeaver.DBException)24 NotNull (org.jkiss.code.NotNull)18 ArrayList (java.util.ArrayList)16 DBPDataSource (org.jkiss.dbeaver.model.DBPDataSource)12 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)12 DBCException (org.jkiss.dbeaver.model.exec.DBCException)10 SQLWarning (java.sql.SQLWarning)8 AbstractObjectReference (org.jkiss.dbeaver.model.impl.struct.AbstractObjectReference)8 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)8 JDBCStatementImpl (org.jkiss.dbeaver.model.impl.jdbc.exec.JDBCStatementImpl)6 VoidProgressMonitor (org.jkiss.dbeaver.model.runtime.VoidProgressMonitor)4 BigDecimal (java.math.BigDecimal)2 SQLFeatureNotSupportedException (java.sql.SQLFeatureNotSupportedException)2 SQLXML (java.sql.SQLXML)2 Tree (org.eclipse.swt.widgets.Tree)2 TreeColumn (org.eclipse.swt.widgets.TreeColumn)2