use of org.jkiss.dbeaver.model.struct.DBSObjectFilter in project dbeaver by dbeaver.
the class SQLServerMetaModel method loadSchemas.
@Override
public List<GenericSchema> loadSchemas(JDBCSession session, GenericDataSource dataSource, GenericCatalog catalog) throws DBException {
boolean showAllSchemas = SQLServerUtils.isShowAllSchemas(dataSource);
final DBSObjectFilter schemaFilters = dataSource.getContainer().getObjectFilter(GenericSchema.class, catalog, false);
String sysSchema = SQLServerUtils.getSystemSchemaFQN(dataSource, catalog.getName(), getSystemSchema());
String sql;
if (showAllSchemas) {
if (getServerType() == ServerType.SQL_SERVER && dataSource.isServerVersionAtLeast(SQLServerConstants.SQL_SERVER_2005_VERSION_MAJOR, 0)) {
sql = "SELECT * FROM " + sysSchema + ".schemas";
} else {
sql = "SELECT * FROM " + sysSchema + ".sysusers";
}
} else {
if (getServerType() == ServerType.SQL_SERVER) {
sql = "SELECT DISTINCT s.*\n" + "FROM " + sysSchema + ".schemas s, " + sysSchema + ".sysobjects o\n" + "WHERE s.schema_id=o.uid\n" + "ORDER BY 1";
} else {
sql = "SELECT DISTINCT u.name,u.uid\n" + "FROM " + sysSchema + ".sysusers u, " + sysSchema + ".sysobjects o\n" + "WHERE u.uid=o.uid\n" + "ORDER BY 1";
}
}
boolean schemaReadFailed = false;
List<GenericSchema> result = new ArrayList<>();
try (JDBCPreparedStatement dbStat = session.prepareStatement(sql)) {
try (JDBCResultSet dbResult = dbStat.executeQuery()) {
while (dbResult.next()) {
String name = JDBCUtils.safeGetString(dbResult, "name");
if (name == null) {
continue;
}
name = name.trim();
if (schemaFilters != null && !schemaFilters.matches(name)) {
// Doesn't match filter
continue;
}
long schemaId = JDBCUtils.safeGetLong(dbResult, "schema_id");
SQLServerGenericSchema schema = new SQLServerGenericSchema(dataSource, catalog, name, schemaId);
result.add(schema);
}
}
} catch (SQLException e) {
if (dataSource.discoverErrorType(e) == DBPErrorAssistant.ErrorType.CONNECTION_LOST) {
throw new DBException(e, dataSource);
} else {
log.warn("Schema read failed: empty list returned. Try generic method.", e);
schemaReadFailed = true;
}
}
if (result.isEmpty()) {
if (!schemaReadFailed && !showAllSchemas) {
// Perhaps all schemas were filtered out
result.add(new GenericSchema(dataSource, catalog, SQLServerConstants.DEFAULT_SCHEMA_NAME));
} else {
// Maybe something went wrong. LEt's try to use native function
return super.loadSchemas(session, dataSource, catalog);
}
}
return result;
}
use of org.jkiss.dbeaver.model.struct.DBSObjectFilter in project dbeaver by dbeaver.
the class NavigatorHandlerFilterClear method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final ISelection selection = HandlerUtil.getCurrentSelection(event);
DBNNode node = NavigatorUtils.getSelectedNode(selection);
if (node instanceof DBNDatabaseItem) {
node = node.getParentNode();
}
if (node instanceof DBNDatabaseFolder) {
final DBNDatabaseFolder folder = (DBNDatabaseFolder) node;
DBXTreeItem itemsMeta = folder.getItemsMeta();
if (itemsMeta != null) {
folder.setNodeFilter(itemsMeta, new DBSObjectFilter());
NavigatorHandlerRefresh.refreshNavigator(Collections.singleton(folder));
}
}
return null;
}
use of org.jkiss.dbeaver.model.struct.DBSObjectFilter in project dbeaver by dbeaver.
the class FilterMapping method getFilter.
@Nullable
DBSObjectFilter getFilter(@Nullable DBSObject parentObject, boolean firstMatch) {
if (parentObject == null) {
return defaultFilter;
}
if (!customFilters.isEmpty()) {
String objectID = getFilterContainerUniqueID(parentObject);
DBSObjectFilter filter = customFilters.get(objectID);
if ((filter != null && !filter.isNotApplicable()) || firstMatch) {
return filter;
}
}
return firstMatch ? null : defaultFilter;
}
use of org.jkiss.dbeaver.model.struct.DBSObjectFilter in project dbeaver by dbeaver.
the class DataSourceRegistry method updateSavedFilter.
@Override
public void updateSavedFilter(DBSObjectFilter filter) {
DBSObjectFilter filterCopy = new DBSObjectFilter(filter);
for (int i = 0; i < savedFilters.size(); i++) {
if (CommonUtils.equalObjects(savedFilters.get(i).getName(), filter.getName())) {
savedFilters.set(i, filterCopy);
return;
}
}
savedFilters.add(filterCopy);
}
Aggregations