use of org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement in project dbeaver by serge-rider.
the class DB2IndexColumn method getDependentView.
// -----------------
// Helpers
// -----------------
private DB2View getDependentView(DBRProgressMonitor monitor, DB2DataSource db2DataSource, String indexSchema, String indexName) throws DBException {
try (JDBCSession session = DBUtils.openMetaSession(monitor, db2DataSource, "Read Index view dependency")) {
try (JDBCPreparedStatement stmtSel = session.prepareStatement(I_DEP)) {
stmtSel.setString(1, indexSchema);
stmtSel.setString(2, indexName);
JDBCResultSet dbResult = stmtSel.executeQuery();
if (dbResult.next()) {
String viewSchema = dbResult.getString("BSCHEMA").trim();
String viewName = dbResult.getString("BNAME");
return DB2Utils.findViewBySchemaNameAndName(monitor, db2DataSource, viewSchema, viewName);
} else {
return null;
}
}
} catch (SQLException e) {
throw new DBException(e, db2DataSource);
}
}
use of org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement in project dbeaver by serge-rider.
the class DB2Utils method generateDDLforTable.
// ------------------------
// Generate DDL
// ------------------------
// DF: Use "Undocumented" SYSPROC.DB2LK_GENERATE_DDL stored proc
// Ref to db2look :
// http://pic.dhe.ibm.com/infocenter/db2luw/v10r5/topic/com.ibm.db2.luw.admin.cmd.doc/doc/r0002051.html
//
// Options of db2look that do not seem to work: -dp . "-a" seems to work on v10.1+, "-l" seems OK in all versions
//
// TODO DF: Tables in SYSTOOLS tables must exist first
public static String generateDDLforTable(DBRProgressMonitor monitor, String statementDelimiter, DB2DataSource dataSource, DB2Table db2Table) throws DBException {
LOG.debug("Generate DDL for " + db2Table.getFullyQualifiedName(DBPEvaluationContext.DDL));
// As a workaround, display a message to the end-user
if (db2Table.getSchema().isSystem()) {
return DB2Messages.no_ddl_for_system_tables;
}
// and the db2look command looks for an uppercase table name (for example, MY TABLE).
if (db2Table.getFullyQualifiedName(DBPEvaluationContext.DDL).contains(" ")) {
return DB2Messages.no_ddl_for_spaces_in_name;
}
monitor.beginTask("Generating DDL", 3);
int token;
StringBuilder sb = new StringBuilder(2048);
String command = String.format(DB2LK_COMMAND, statementDelimiter, db2Table.getFullyQualifiedName(DBPEvaluationContext.DDL));
try (JDBCSession session = DBUtils.openMetaSession(monitor, dataSource, "Generate DDL")) {
LOG.debug("Calling DB2LK_GENERATE_DDL with command : " + command);
try (JDBCCallableStatement stmtSP = session.prepareCall(CALL_DB2LK_GEN)) {
stmtSP.registerOutParameter(2, java.sql.Types.INTEGER);
stmtSP.setString(1, command);
stmtSP.executeUpdate();
token = stmtSP.getInt(2);
}
LOG.debug("Token = " + token);
monitor.worked(1);
// Read result
try (JDBCPreparedStatement stmtSel = session.prepareStatement(SEL_DB2LK)) {
stmtSel.setInt(1, token);
try (JDBCResultSet dbResult = stmtSel.executeQuery()) {
Clob ddlStmt;
Long ddlLength;
Long ddlStart = 1L;
while (dbResult.next()) {
ddlStmt = dbResult.getClob(1);
try {
ddlLength = ddlStmt.length() + 1L;
sb.append(ddlStmt.getSubString(ddlStart, ddlLength.intValue()));
sb.append(LINE_SEP);
} finally {
try {
ddlStmt.free();
} catch (Throwable e) {
LOG.debug("Error freeing CLOB: " + e.getMessage());
}
}
}
}
}
monitor.worked(2);
// Clean
try (JDBCCallableStatement stmtSPClean = session.prepareCall(CALL_DB2LK_CLEAN)) {
stmtSPClean.setInt(1, token);
stmtSPClean.executeUpdate();
}
monitor.worked(3);
LOG.debug("Terminated OK");
return sb.toString();
} catch (SQLException e) {
throw new DBException(e, dataSource);
} finally {
monitor.done();
}
}
use of org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement in project dbeaver by serge-rider.
the class DB2Utils method readDBMCfg.
public static List<DB2Parameter> readDBMCfg(DBRProgressMonitor monitor, JDBCSession session) throws SQLException {
LOG.debug("readDBMCfg");
List<DB2Parameter> listDBMParameters = new ArrayList<>();
try (JDBCPreparedStatement dbStat = session.prepareStatement(SEL_DBMCFG)) {
try (JDBCResultSet dbResult = dbStat.executeQuery()) {
while (dbResult.next()) {
listDBMParameters.add(new DB2Parameter((DB2DataSource) session.getDataSource(), dbResult));
}
}
}
return listDBMParameters;
}
use of org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement in project dbeaver by serge-rider.
the class DB2IndexCache method prepareLookupStatement.
@NotNull
@Override
public JDBCStatement prepareLookupStatement(@NotNull JDBCSession session, @NotNull DB2Schema db2Schema, DB2Index db2Index, String db2IndexName) throws SQLException {
if (db2Index != null || db2IndexName != null) {
final JDBCPreparedStatement dbStat = session.prepareStatement(SQL_IND);
dbStat.setString(1, db2Schema.getName());
dbStat.setString(2, db2Index != null ? db2Index.getName() : db2IndexName);
return dbStat;
} else {
final JDBCPreparedStatement dbStat = session.prepareStatement(SQL_IND_ALL);
dbStat.setString(1, db2Schema.getName());
return dbStat;
}
}
use of org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement in project dbeaver by serge-rider.
the class DB2MaterializedQueryTableCache method prepareLookupStatement.
@NotNull
@Override
public JDBCStatement prepareLookupStatement(@NotNull JDBCSession session, @NotNull DB2Schema db2Schema, DB2MaterializedQueryTable db2MaterializedQueryTable, String db2MaterializedQueryTableName) throws SQLException {
if (db2MaterializedQueryTable != null || db2MaterializedQueryTableName != null) {
final JDBCPreparedStatement dbStat = session.prepareStatement(SQL_MQT);
dbStat.setString(1, db2Schema.getName());
dbStat.setString(2, db2MaterializedQueryTable != null ? db2MaterializedQueryTable.getName() : db2MaterializedQueryTableName);
return dbStat;
} else {
final JDBCPreparedStatement dbStat = session.prepareStatement(SQL_MQT_ALL);
dbStat.setString(1, db2Schema.getName());
return dbStat;
}
}
Aggregations