use of org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement in project dbeaver by serge-rider.
the class OracleTablePhysical method getPartitionInfo.
@PropertyGroup
@LazyProperty(cacheValidator = PartitionInfoValidator.class)
public PartitionInfo getPartitionInfo(DBRProgressMonitor monitor) throws DBException {
if (partitionInfo == null && partitioned) {
try (final JDBCSession session = DBUtils.openMetaSession(monitor, getDataSource(), "Load partitioning info")) {
try (JDBCPreparedStatement dbStat = session.prepareStatement("SELECT * FROM ALL_PART_TABLES WHERE OWNER=? AND TABLE_NAME=?")) {
dbStat.setString(1, getContainer().getName());
dbStat.setString(2, getName());
try (JDBCResultSet dbResult = dbStat.executeQuery()) {
if (dbResult.next()) {
partitionInfo = new PartitionInfo(monitor, this.getDataSource(), dbResult);
}
}
}
} catch (SQLException e) {
throw new DBException(e, getDataSource());
}
}
return partitionInfo;
}
use of org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement in project dbeaver by serge-rider.
the class ExasolCurrentUserPrivileges method verifyPriv.
private static Boolean verifyPriv(String sql, JDBCSession session) {
JDBCPreparedStatement dbStat;
Boolean hasPriv;
try {
dbStat = session.prepareStatement(C_CONNECTIONS);
ResultSet rs = dbStat.executeQuery();
rs.close();
dbStat.close();
hasPriv = true;
} catch (SQLException e) {
hasPriv = false;
}
return hasPriv;
}
use of org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement in project dbeaver by serge-rider.
the class ExasolPlanAnalyser method explain.
public void explain(DBCSession session) throws DBCException {
rootNodes = new ArrayList<>();
JDBCSession connection = (JDBCSession) session;
boolean oldAutoCommit = false;
try {
oldAutoCommit = connection.getAutoCommit();
if (oldAutoCommit)
connection.setAutoCommit(false);
//alter session
JDBCUtils.executeSQL(connection, "ALTER SESSION SET PROFILE = 'ON'");
//execute query
JDBCUtils.executeSQL(connection, query);
//alter session
JDBCUtils.executeSQL(connection, "ALTER SESSION SET PROFILE = 'OFF'");
//rollback in case of DML
connection.rollback();
//alter session
JDBCUtils.executeSQL(connection, "FLUSH STATISTICS");
connection.commit();
//retrieve execute info
try (JDBCPreparedStatement stmt = connection.prepareStatement("SELECT * FROM EXA_USER_PROFILE_LAST_DAY WHERE SESSION_ID = CURRENT_SESSION AND STMT_ID = (select max(stmt_id) from EXA_USER_PROFILE_LAST_DAY where sql_text = ?)")) {
stmt.setString(1, query);
try (JDBCResultSet dbResult = stmt.executeQuery()) {
while (dbResult.next()) {
ExasolPlanNode node = new ExasolPlanNode(null, dbResult);
rootNodes.add(node);
}
}
}
} catch (SQLException e) {
throw new DBCException(e, session.getDataSource());
} finally {
//rollback changes because profile actually executes query and it could be INSERT/UPDATE
try {
connection.rollback();
if (oldAutoCommit)
connection.setAutoCommit(true);
} catch (SQLException e) {
LOG.error("Error closing plan analyser", e);
}
}
}
use of org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement in project dbeaver by serge-rider.
the class DB2PlanOperator method loadChildren.
// -------------
// Load children
// -------------
private void loadChildren(JDBCSession session) throws SQLException {
listArguments = new ArrayList<>();
try (JDBCPreparedStatement sqlStmt = session.prepareStatement(String.format(SEL_BASE_SELECT, planTableSchema, "EXPLAIN_ARGUMENT", "ARGUMENT_TYPE"))) {
setQueryParameters(sqlStmt);
try (JDBCResultSet res = sqlStmt.executeQuery()) {
while (res.next()) {
listArguments.add(new DB2PlanOperatorArgument(res));
}
}
}
listPredicates = new ArrayList<>();
try (JDBCPreparedStatement sqlStmt = session.prepareStatement(String.format(SEL_BASE_SELECT, planTableSchema, "EXPLAIN_PREDICATE", "PREDICATE_ID"))) {
setQueryParameters(sqlStmt);
try (JDBCResultSet res = sqlStmt.executeQuery()) {
while (res.next()) {
listPredicates.add(new DB2PlanOperatorPredicate(res, this));
}
}
}
}
use of org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement in project dbeaver by serge-rider.
the class DB2GranteeDatabaseAuthCache method prepareObjectsStatement.
@Override
protected JDBCStatement prepareObjectsStatement(@NotNull JDBCSession session, @NotNull DB2Grantee db2Grantee) throws SQLException {
final JDBCPreparedStatement dbStat = session.prepareStatement(SQL);
dbStat.setString(1, db2Grantee.getType().name());
dbStat.setString(2, db2Grantee.getName());
// dbStat.setFetchSize(1); // Only 1 row per user
return dbStat;
}
Aggregations