use of org.jkiss.dbeaver.model.runtime.DBRProgressMonitor in project dbeaver by serge-rider.
the class PostgreStructureAssistant method findProceduresByMask.
private void findProceduresByMask(JDBCSession session, @Nullable final List<PostgreSchema> schema, String procNameMask, boolean caseSensitive, int maxResults, List<DBSObjectReference> objects) throws SQLException, DBException {
DBRProgressMonitor monitor = session.getProgressMonitor();
// Load procedures
try (JDBCPreparedStatement dbStat = session.prepareStatement("SELECT DISTINCT x.oid,x.proname,x.pronamespace FROM pg_catalog.pg_proc x " + "WHERE x.proname " + (caseSensitive ? "LIKE" : "ILIKE") + " ? " + (CommonUtils.isEmpty(schema) ? "" : " AND x.pronamespace IN (" + SQLUtils.generateParamList(schema.size()) + ")") + " ORDER BY x.proname LIMIT " + maxResults)) {
dbStat.setString(1, procNameMask);
if (!CommonUtils.isEmpty(schema)) {
PostgreUtils.setArrayParameter(dbStat, 2, schema);
}
try (JDBCResultSet dbResult = dbStat.executeQuery()) {
int tableNum = maxResults;
while (dbResult.next() && tableNum-- > 0) {
if (monitor.isCanceled()) {
break;
}
final long schemaId = JDBCUtils.safeGetLong(dbResult, "pronamespace");
final String procName = JDBCUtils.safeGetString(dbResult, "proname");
final long procId = JDBCUtils.safeGetLong(dbResult, "oid");
final PostgreSchema procSchema = dataSource.getDefaultInstance().getSchema(session.getProgressMonitor(), schemaId);
objects.add(new AbstractObjectReference(procName, procSchema, null, PostgreProcedure.class, RelationalObjectType.TYPE_PROCEDURE) {
@Override
public DBSObject resolveObject(DBRProgressMonitor monitor) throws DBException {
PostgreProcedure procedure = procSchema.getProcedure(monitor, procId);
if (procedure == null) {
throw new DBException("Procedure '" + procName + "' not found in schema '" + procSchema.getName() + "'");
}
return procedure;
}
});
}
}
}
}
use of org.jkiss.dbeaver.model.runtime.DBRProgressMonitor in project dbeaver by serge-rider.
the class PostgreBackupWizardPageObjects method loadTables.
private void loadTables(final PostgreSchema catalog) {
if (catalog != null) {
curSchema = catalog;
}
if (curSchema == null) {
return;
}
final boolean isCatalogChecked = isChecked(curSchema);
final Set<PostgreTableBase> checkedObjects = this.checkedObjects.get(curSchema);
new AbstractJob("Load '" + curSchema.getName() + "' tables") {
{
setUser(true);
}
@Override
protected IStatus run(DBRProgressMonitor monitor) {
try {
final List<PostgreTableBase> objects = new ArrayList<>();
objects.addAll(curSchema.getTables(monitor));
if (wizard.showViews) {
objects.addAll(curSchema.getViews(monitor));
}
Collections.sort(objects, DBUtils.nameComparator());
DBeaverUI.syncExec(new Runnable() {
@Override
public void run() {
tablesTable.removeAll();
for (PostgreTableBase table : objects) {
TableItem item = new TableItem(tablesTable, SWT.NONE);
item.setImage(DBeaverIcons.getImage(table.isView() ? DBIcon.TREE_VIEW : DBIcon.TREE_TABLE));
item.setText(0, table.getName());
item.setData(table);
item.setChecked(isCatalogChecked && (checkedObjects == null || checkedObjects.contains(table)));
}
}
});
} catch (DBException e) {
UIUtils.showErrorDialog(null, "Table list", "Can't read table list", e);
}
return Status.OK_STATUS;
}
}.schedule();
}
use of org.jkiss.dbeaver.model.runtime.DBRProgressMonitor in project dbeaver by serge-rider.
the class SSHTunnelImpl method closeTunnel.
@Override
public void closeTunnel(DBRProgressMonitor monitor) throws DBException, IOException {
if (session != null) {
RuntimeUtils.runTask(new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
session.disconnect();
} catch (Exception e) {
throw new InvocationTargetException(e);
}
}
}, "Close SSH session", 1000);
session = null;
}
}
use of org.jkiss.dbeaver.model.runtime.DBRProgressMonitor in project dbeaver by serge-rider.
the class SQLUtils method convertStreamToSQL.
public static String convertStreamToSQL(DBSAttributeBase attribute, DBDContent content, DBDValueHandler valueHandler, SQLDataSource dataSource) {
try {
DBRProgressMonitor monitor = VoidProgressMonitor.INSTANCE;
if (valueHandler instanceof DBDContentValueHandler) {
StringWriter buffer = new StringWriter();
((DBDContentValueHandler) valueHandler).writeStreamValue(monitor, dataSource, attribute, content, buffer);
return buffer.toString();
} else {
if (ContentUtils.isTextContent(content)) {
String strValue = ContentUtils.getContentStringValue(monitor, content);
strValue = dataSource.getSQLDialect().escapeString(strValue);
return "'" + strValue + "'";
} else {
byte[] binValue = ContentUtils.getContentBinaryValue(monitor, content);
return dataSource.getSQLDialect().getNativeBinaryFormatter().toString(binValue, 0, binValue.length);
}
}
} catch (Throwable e) {
log.warn(e);
return SQLConstants.NULL_VALUE;
}
}
use of org.jkiss.dbeaver.model.runtime.DBRProgressMonitor in project dbeaver by serge-rider.
the class CompareObjectsWizard method performFinish.
@Override
public boolean performFinish() {
// Save settings
getSettings().saveTo(getDialogSettings());
showError(null);
// Compare
final CompareObjectsExecutor executor = new CompareObjectsExecutor(settings);
try {
DBeaverUI.run(getContainer(), true, true, new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
CompareReport report = generateReport(monitor, executor);
renderReport(monitor, report);
} catch (DBException e) {
throw new InvocationTargetException(e);
}
}
});
UIUtils.showMessageBox(getShell(), "Objects compare", "Objects compare finished", SWT.ICON_INFORMATION);
} catch (InvocationTargetException e) {
if (executor.getInitializeError() != null) {
showError(executor.getInitializeError().getMessage());
} else {
log.error(e.getTargetException());
showError(e.getTargetException().getMessage());
}
return false;
} catch (InterruptedException e) {
showError("Compare interrupted");
return false;
} finally {
executor.dispose();
}
// Done
return true;
}
Aggregations