use of org.jkiss.dbeaver.model.struct.DBSObject in project dbeaver by dbeaver.
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.struct.DBSObject in project dbeaver by dbeaver.
the class DataSourceManagementToolbar method changeDataBaseSelection.
private void changeDataBaseSelection(DBNDatabaseNode node) {
DBPDataSourceContainer dsContainer = getDataSourceContainer();
final String newName = node.getNodeName();
if (dsContainer != null && dsContainer.isConnected()) {
final DBPDataSource dataSource = dsContainer.getDataSource();
new AbstractJob("Change active database") {
@Override
protected IStatus run(DBRProgressMonitor monitor) {
try {
DBSObjectContainer oc = DBUtils.getAdapter(DBSObjectContainer.class, dataSource);
DBSObjectSelector os = DBUtils.getAdapter(DBSObjectSelector.class, dataSource);
if (os != null) {
final DBSObject defObject = os.getDefaultObject();
if (defObject instanceof DBSObjectContainer) {
// USe seconds level of active object
DBSObjectSelector os2 = DBUtils.getAdapter(DBSObjectSelector.class, defObject);
if (os2 != null && os2.supportsDefaultChange()) {
oc = (DBSObjectContainer) defObject;
os = os2;
}
}
}
if (oc != null && os != null && os.supportsDefaultChange()) {
DBSObject newChild = oc.getChild(monitor, newName);
if (newChild != null) {
os.setDefaultObject(monitor, newChild);
} else {
throw new DBException(MessageFormat.format(CoreMessages.toolbar_datasource_selector_error_database_not_found, newName));
}
} else {
throw new DBException(CoreMessages.toolbar_datasource_selector_error_database_change_not_supported);
}
} catch (DBException e) {
return GeneralUtils.makeExceptionStatus(e);
}
return Status.OK_STATUS;
}
}.schedule();
}
}
use of org.jkiss.dbeaver.model.struct.DBSObject in project dbeaver by dbeaver.
the class OpenHandler method getDataSourceContainers.
private static List<DBPDataSourceContainer> getDataSourceContainers(ExecutionEvent event) {
List<DBPDataSourceContainer> containers = new ArrayList<>();
ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection instanceof IStructuredSelection) {
for (Object obj : ((IStructuredSelection) selection).toArray()) {
if (obj instanceof DBNLocalFolder) {
for (DBNDataSource ds : ((DBNLocalFolder) obj).getDataSources()) {
containers.add(ds.getDataSourceContainer());
}
} else {
DBSObject selectedObject = DBUtils.getFromObject(obj);
if (selectedObject != null) {
if (selectedObject instanceof DBPDataSourceContainer) {
containers.add((DBPDataSourceContainer) selectedObject);
} else {
containers.add(selectedObject.getDataSource().getContainer());
}
}
}
}
}
if (containers.isEmpty()) {
IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
DBPDataSourceContainer partContainer = getDataSourceContainers(activePart);
if (partContainer != null) {
containers.add(partContainer);
}
}
return containers;
}
use of org.jkiss.dbeaver.model.struct.DBSObject in project dbeaver by dbeaver.
the class AbstractDataSourceHandler method getDataSourceContainer.
protected static DBPDataSourceContainer getDataSourceContainer(ExecutionEvent event, boolean useEditor) {
if (useEditor) {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (editor != null) {
DBPDataSourceContainer container = getDataSourceContainer(editor);
if (container != null) {
return container;
}
}
return null;
}
IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
DBPDataSourceContainer container = getDataSourceContainer(activePart);
if (container != null) {
return container;
}
ISelection selection = HandlerUtil.getCurrentSelection(event);
DBSObject selectedObject = NavigatorUtils.getSelectedObject(selection);
if (selectedObject instanceof DBPDataSourceContainer) {
return (DBPDataSourceContainer) selectedObject;
} else if (selectedObject != null) {
DBPDataSource dataSource = selectedObject.getDataSource();
return dataSource == null ? null : dataSource.getContainer();
}
return null;
}
use of org.jkiss.dbeaver.model.struct.DBSObject in project dbeaver by dbeaver.
the class NavigatorHandlerFilterConfig method configureFilters.
public static void configureFilters(Shell shell, DBNNode node) {
final DBNDatabaseFolder folder = (DBNDatabaseFolder) node;
DBXTreeItem itemsMeta = folder.getItemsMeta();
if (itemsMeta != null) {
DBSObjectFilter objectFilter = folder.getNodeFilter(itemsMeta, true);
if (objectFilter == null) {
objectFilter = new DBSObjectFilter();
}
final DBPDataSourceRegistry dsRegistry = DBeaverCore.getInstance().getProjectManager().getDataSourceRegistry(folder.getOwnerProject());
final boolean globalFilter = folder.getValueObject() instanceof DBPDataSource;
String parentName = "?";
if (folder.getValueObject() instanceof DBSObject) {
parentName = ((DBSObject) folder.getValueObject()).getName();
}
EditObjectFilterDialog dialog = new EditObjectFilterDialog(shell, dsRegistry, globalFilter ? "All " + node.getNodeType() : node.getNodeType() + " of " + parentName, objectFilter, globalFilter);
switch(dialog.open()) {
case IDialogConstants.OK_ID:
folder.setNodeFilter(itemsMeta, dialog.getFilter());
NavigatorHandlerRefresh.refreshNavigator(Collections.singletonList(folder));
break;
case EditObjectFilterDialog.SHOW_GLOBAL_FILTERS_ID:
objectFilter = folder.getDataSource().getContainer().getObjectFilter(folder.getChildrenClass(), null, false);
dialog = new EditObjectFilterDialog(shell, dsRegistry, "All " + node.getNodeType(), objectFilter != null ? objectFilter : new DBSObjectFilter(), true);
if (dialog.open() == IDialogConstants.OK_ID) {
// Set global filter
folder.getDataSource().getContainer().setObjectFilter(folder.getChildrenClass(), null, dialog.getFilter());
folder.getDataSource().getContainer().persistConfiguration();
NavigatorHandlerRefresh.refreshNavigator(Collections.singletonList(folder));
}
break;
}
}
}
Aggregations