use of org.jkiss.dbeaver.model.exec.jdbc.JDBCSession 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.JDBCSession in project dbeaver by serge-rider.
the class HSQLMetaModel method getProcedureDDL.
@Override
public String getProcedureDDL(DBRProgressMonitor monitor, GenericProcedure sourceObject) throws DBException {
GenericDataSource dataSource = sourceObject.getDataSource();
try (JDBCSession session = DBUtils.openMetaSession(monitor, dataSource, "Read HSQLDB procedure source")) {
try (JDBCPreparedStatement dbStat = session.prepareStatement("SELECT ROUTINE_DEFINITION FROM INFORMATION_SCHEMA.ROUTINES " + "WHERE ROUTINE_SCHEMA=? AND ROUTINE_NAME=?")) {
dbStat.setString(1, sourceObject.getContainer().getName());
dbStat.setString(2, sourceObject.getName());
try (JDBCResultSet dbResult = dbStat.executeQuery()) {
if (dbResult.nextRow()) {
String definition = dbResult.getString(1);
if (definition != null) {
definition = SQLUtils.formatSQL(dataSource, definition);
}
return definition;
}
return "-- HSQLDB procedure definition not found";
}
}
} catch (SQLException e) {
throw new DBException(e, dataSource);
}
}
use of org.jkiss.dbeaver.model.exec.jdbc.JDBCSession in project dbeaver by serge-rider.
the class NetezzaMetaModel method getProcedureDDL.
@Override
public String getProcedureDDL(DBRProgressMonitor monitor, GenericProcedure sourceObject) throws DBException {
GenericDataSource dataSource = sourceObject.getDataSource();
try (JDBCSession session = DBUtils.openMetaSession(monitor, dataSource, "Read Netezza procedure source")) {
try (JDBCPreparedStatement dbStat = session.prepareStatement("SELECT p.proceduresignature,p.returns,p.proceduresource " + "FROM _v_procedure p " + "WHERE p.owner=? AND p.procedure=?")) {
dbStat.setString(1, sourceObject.getContainer().getName());
dbStat.setString(2, sourceObject.getName());
try (JDBCResultSet dbResult = dbStat.executeQuery()) {
if (dbResult.nextRow()) {
return "CREATE OR REPLACE PROCEDURE " + dbResult.getString(1) + " RETURNS " + dbResult.getString(2) + "LANGUAGE NZPLSQL AS BEGIN_PROC\n" + dbResult.getString(3) + "\nEND_PROC;";
}
return "-- Netezza procedure source not found";
}
}
} catch (SQLException e) {
throw new DBException(e, dataSource);
}
}
use of org.jkiss.dbeaver.model.exec.jdbc.JDBCSession in project dbeaver by serge-rider.
the class MySQLHelpProvider method loadTopics.
private void loadTopics(DBRProgressMonitor monitor) {
try (final JDBCSession session = DBUtils.openMetaSession(monitor, dataSource, "Read MySQL help topicc")) {
try (JDBCPreparedStatement dbStat = session.prepareStatement("SELECT name, description, example, url FROM mysql.help_topic")) {
try (JDBCResultSet dbResult = dbStat.executeQuery()) {
while (dbResult.next()) {
String topicName = dbResult.getString(1);
SQLHelpTopic helpTopic = new SQLHelpTopic();
helpTopic.setContents("<pre>" + dbResult.getString(2) + "</pre>");
helpTopic.setExample(dbResult.getString(3));
helpTopic.setUrl(dbResult.getString(4));
if (topicName != null) {
synchronized (topicCache) {
topicCache.put(topicName.toUpperCase(Locale.ENGLISH), helpTopic);
}
}
}
}
} catch (SQLException e) {
log.error("Error reading help topics", e);
}
} finally {
isLoaded = true;
}
}
use of org.jkiss.dbeaver.model.exec.jdbc.JDBCSession in project dbeaver by serge-rider.
the class MySQLUser method getGrants.
public List<MySQLGrant> getGrants(DBRProgressMonitor monitor) throws DBException {
if (this.grants != null) {
return this.grants;
}
if (!isPersisted()) {
this.grants = new ArrayList<>();
return this.grants;
}
try (JDBCSession session = DBUtils.openMetaSession(monitor, getDataSource(), "Read catalog privileges")) {
try (JDBCPreparedStatement dbStat = session.prepareStatement("SHOW GRANTS FOR " + getFullName())) {
try (JDBCResultSet dbResult = dbStat.executeQuery()) {
List<MySQLGrant> grants = new ArrayList<>();
while (dbResult.next()) {
List<MySQLPrivilege> privileges = new ArrayList<>();
boolean allPrivilegesFlag = false;
boolean grantOption = false;
String catalog = null;
String table = null;
String grantString = CommonUtils.notEmpty(JDBCUtils.safeGetString(dbResult, 1)).trim().toUpperCase(Locale.ENGLISH);
if (grantString.endsWith(" WITH GRANT OPTION")) {
//privileges.add(getDataSource().getPrivilege(monitor, MySQLPrivilege.GRANT_PRIVILEGE));
grantOption = true;
}
String privString;
Matcher matcher = MySQLGrant.TABLE_GRANT_PATTERN.matcher(grantString);
if (matcher.find()) {
privString = matcher.group(1);
catalog = matcher.group(2);
table = matcher.group(3);
} else {
matcher = MySQLGrant.GLOBAL_GRANT_PATTERN.matcher(grantString);
if (matcher.find()) {
privString = matcher.group(1);
} else {
log.warn("Can't parse GRANT string: " + grantString);
continue;
}
}
StringTokenizer st = new StringTokenizer(privString, ",");
while (st.hasMoreTokens()) {
String privName = st.nextToken().trim();
if (privName.equalsIgnoreCase(MySQLPrivilege.ALL_PRIVILEGES)) {
allPrivilegesFlag = true;
continue;
}
MySQLPrivilege priv = getDataSource().getPrivilege(monitor, privName);
if (priv == null) {
log.warn("Can't find privilege '" + privName + "'");
} else {
privileges.add(priv);
}
}
grants.add(new MySQLGrant(this, privileges, catalog, table, allPrivilegesFlag, grantOption));
}
this.grants = grants;
return this.grants;
}
}
} catch (SQLException e) {
throw new DBException(e, getDataSource());
}
}
Aggregations