use of org.jkiss.dbeaver.DBException 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.DBException 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.DBException in project dbeaver by serge-rider.
the class DB2StructureAssistant method findObjectsByMask.
@NotNull
@Override
public List<DBSObjectReference> findObjectsByMask(DBRProgressMonitor monitor, DBSObject parentObject, DBSObjectType[] objectTypes, String objectNameMask, boolean caseSensitive, boolean globalSearch, int maxResults) throws DBException {
LOG.debug(objectNameMask);
List<DB2ObjectType> db2ObjectTypes = new ArrayList<>(objectTypes.length);
for (DBSObjectType dbsObjectType : objectTypes) {
db2ObjectTypes.add((DB2ObjectType) dbsObjectType);
}
DB2Schema schema = parentObject instanceof DB2Schema ? (DB2Schema) parentObject : null;
if (schema == null && !globalSearch) {
schema = dataSource.getDefaultObject();
}
try (JDBCSession session = DBUtils.openMetaSession(monitor, dataSource, "Find objects by name")) {
return searchAllObjects(session, schema, objectNameMask, db2ObjectTypes, caseSensitive, maxResults);
} catch (SQLException ex) {
throw new DBException(ex, dataSource);
}
}
use of org.jkiss.dbeaver.DBException in project dbeaver by serge-rider.
the class BookmarksHandlerImpl method createBookmark.
public static void createBookmark(final DBNDatabaseNode node, String title, IFolder folder) throws DBException {
if (folder == null) {
final IProject project = node.getOwnerProject();
if (project != null) {
folder = getBookmarksFolder(project, true);
}
}
if (folder == null) {
throw new DBException("Can't detect folder for bookmark");
}
IFile file = ContentUtils.getUniqueFile(folder, CommonUtils.escapeFileName(title), BOOKMARK_EXT);
updateBookmark(node, title, file);
}
use of org.jkiss.dbeaver.DBException in project dbeaver by serge-rider.
the class DBNBookmark method rename.
@Override
public void rename(DBRProgressMonitor monitor, String newName) throws DBException {
IFile file = (IFile) getResource();
if (file != null) {
try {
storage.setTitle(newName);
InputStream data = storage.serialize();
file.setContents(data, true, false, RuntimeUtils.getNestedMonitor(monitor));
} catch (Exception e) {
throw new DBException("Can't rename bookmark", e);
}
}
}
Aggregations