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;
}
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;
}
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;
}
}
});
}
}
}
}
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;
}
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);
}
Aggregations