use of org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement in project dbeaver by serge-rider.
the class ExasolStructureAssistant method findProceduresByMask.
private void findProceduresByMask(JDBCSession session, ExasolSchema schema, String objectNameMask, int maxResults, List<DBSObjectReference> references) throws SQLException, DBException {
DBRProgressMonitor monitor = session.getProgressMonitor();
// don't use parameter marks because of performance
String sql = "";
if (schema == null) {
sql = String.format(sqlProceduresAll, ExasolUtils.quoteString(objectNameMask));
} else {
sql = String.format(sqlProcedureSchema, ExasolUtils.quoteString(schema.getName()), 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, "SCRIPT_SCHEMA");
final String scriptName = JDBCUtils.safeGetString(dbResult, "SCRIPT_NAME");
references.add(new AbstractObjectReference(scriptName, dataSource.getSchema(monitor, schemaName), null, ExasolScript.class, RelationalObjectType.TYPE_PROCEDURE) {
@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");
}
ExasolScript script = tableSchema.scriptCache.getObject(monitor, tableSchema, scriptName);
if (script == null) {
throw new DBException("Script '" + script + "' not found in schema '" + schemaName + "'");
}
return script;
}
});
}
}
}
}
use of org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement in project dbeaver by serge-rider.
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 serge-rider.
the class DB2DataSource method collectObjectStatistics.
@Override
public void collectObjectStatistics(DBRProgressMonitor monitor, boolean totalSizeOnly, boolean forceRefresh) throws DBException {
if (hasStatistics && !forceRefresh) {
return;
}
try (JDBCSession session = DBUtils.openMetaSession(monitor, this, "Load schema statistics")) {
try (JDBCStatement dbStat = session.createStatement()) {
try (JDBCResultSet dbResult = dbStat.executeQuery("SELECT\n" + " TABSCHEMA,\n" + " SUM(DATA_OBJECT_P_SIZE + INDEX_OBJECT_P_SIZE + LONG_OBJECT_P_SIZE + LOB_OBJECT_P_SIZE + XML_OBJECT_P_SIZE) AS TOTAL_SIZE_IN_KB\n" + "FROM SYSIBMADM.ADMINTABINFO\n" + "GROUP BY TABSCHEMA")) {
while (dbResult.next()) {
String schemaName = JDBCUtils.safeGetStringTrimmed(dbResult, 1);
long bytes = dbResult.getLong(2) * 1024;
DB2Schema schema = getSchema(monitor, schemaName);
if (schema != null) {
schema.setSchemaTotalSize(bytes);
}
}
for (DB2Schema schema : getSchemas(monitor)) {
if (!schema.hasStatistics()) {
schema.setSchemaTotalSize(0);
}
}
}
}
} catch (SQLException e) {
throw new DBCException("Error reading table statistics", e);
} finally {
hasStatistics = true;
}
}
use of org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement in project dbeaver by serge-rider.
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 serge-rider.
the class ExasolTableForeignKeyCache method prepareObjectsStatement.
@NotNull
@Override
protected JDBCStatement prepareObjectsStatement(JDBCSession session, ExasolSchema exasolSchema, ExasolTable forTable) throws SQLException {
String sql;
if (forTable != null) {
sql = String.format(SQL_FK_TAB, ExasolUtils.quoteString(exasolSchema.getName()), ExasolUtils.quoteString(forTable.getName()), ExasolUtils.quoteString(exasolSchema.getName()), ExasolUtils.quoteString(forTable.getName()), ExasolUtils.quoteString(exasolSchema.getName()), ExasolUtils.quoteString(forTable.getName()));
} else {
sql = String.format(SQL_FK_ALL, ExasolUtils.quoteString(exasolSchema.getName()), ExasolUtils.quoteString(exasolSchema.getName()), ExasolUtils.quoteString(exasolSchema.getName()));
}
JDBCStatement dbStat = session.createStatement();
dbStat.setQueryString(sql);
return dbStat;
}
Aggregations