Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dbeaver/pro#4299 implement sharing of things like new String[0] #3304

Open
wants to merge 7 commits into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.jkiss.dbeaver.registry.network.NetworkHandlerRegistry;
import org.jkiss.dbeaver.runtime.DBWorkbench;
import org.jkiss.utils.CommonUtils;
import org.jkiss.utils.ZeroSizedArrays;

import java.util.*;
import java.util.function.Predicate;
Expand Down Expand Up @@ -281,7 +282,7 @@ public String[] getFeatures() {
features.add(FEATURE_MANAGEABLE);
}

return features.toArray(new String[0]);
return features.toArray(ZeroSizedArrays.OF_STRING);
}

@Property
Expand Down Expand Up @@ -343,7 +344,7 @@ public WebPropertyInfo[] getAuthProperties() {
String authModelId = getAuthModel();
DBPAuthModelDescriptor authModel = DBWorkbench.getPlatform().getDataSourceProviderRegistry().getAuthModel(authModelId);
if (authModel == null) {
return new WebPropertyInfo[0];
return WebPropertyInfo.ZERO_SIZE_ARRAY;
}

// Fill user provided credentials
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public WebPropertyInfo[] getDetails() throws DBWebException {
try {
DBPObject details = origin.getObjectDetails(session.getProgressMonitor(), session.getSessionContext(), dataSourceContainer);
if (details == null) {
return new WebPropertyInfo[0];
return WebPropertyInfo.ZERO_SIZE_ARRAY;
}
return WebCommonUtils.getObjectProperties(session, details);
} catch (DBException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.jkiss.dbeaver.registry.settings.ProductSettingDescriptor;
import org.jkiss.dbeaver.runtime.properties.ObjectPropertyDescriptor;
import org.jkiss.utils.CommonUtils;
import org.jkiss.utils.ZeroSizedArrays;

import java.lang.reflect.Array;
import java.util.*;
Expand All @@ -39,14 +40,19 @@
* Web connection info
*/
public class WebPropertyInfo {
/**
* A constant zero-sized array for sharing.
*/
public static final WebPropertyInfo[] ZERO_SIZE_ARRAY = new WebPropertyInfo[0];

private WebSession session;
private DBPPropertyDescriptor property;
private DBPPropertySource propertySource;
private boolean showProtected;

private Object[] validValues;

private String[] supportedConfigurationTypes = new String[0];
private String[] supportedConfigurationTypes = ZeroSizedArrays.OF_STRING;

private Object defaultValue;

Expand Down Expand Up @@ -168,7 +174,7 @@ public Object[] getValidValues() {
@Property
public String[] getFeatures() {
String[] features = property.getFeatures();
return features == null ? new String[0] : features;
return features == null ? ZeroSizedArrays.OF_STRING : features;
}

@Property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.cloudbeaver.registry.WebFeatureRegistry;
import org.jkiss.code.NotNull;
import org.jkiss.utils.ArrayUtils;
import org.jkiss.utils.ZeroSizedArrays;

import java.util.Collections;
import java.util.LinkedHashMap;
Expand All @@ -41,7 +42,7 @@ public BaseWebAppConfiguration() {
this.plugins = new LinkedHashMap<>();
this.resourceManagerEnabled = true;
this.enabledFeatures = null;
this.disabledBetaFeatures = new String[0];
this.disabledBetaFeatures = ZeroSizedArrays.OF_STRING;
this.showReadOnlyConnectionInfo = false;
this.secretManagerEnabled = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.utils.ZeroSizedArrays;

import java.util.Map;

Expand Down Expand Up @@ -48,7 +49,7 @@ public interface ServletAppConfiguration {

@NotNull
default String[] getEnabledFeatures() {
return new String[0];
return ZeroSizedArrays.OF_STRING;
}

default boolean isSupportsCustomConnections() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.model.navigator.DBNBrowseSettings;
import org.jkiss.dbeaver.registry.DataSourceNavigatorSettings;
import org.jkiss.utils.ZeroSizedArrays;

import java.util.Map;

Expand All @@ -34,17 +35,17 @@

boolean isPublicCredentialsSaveEnabled();

boolean isAdminCredentialsSaveEnabled();

Check warning on line 38 in server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/app/WebAppConfiguration.java

View workflow job for this annotation

GitHub Actions / Server / Lint

[checkstyle] reported by reviewdog 🐶 Missing a Javadoc comment. Raw Output: /github/workspace/./server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/app/WebAppConfiguration.java:38:5: warning: Missing a Javadoc comment. (com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocMethodCheck)

default String[] getDisabledBetaFeatures() {
return new String[0];
return ZeroSizedArrays.OF_STRING;
}

default String[] getEnabledAuthProviders() {
return new String[0];
return ZeroSizedArrays.OF_STRING;
}

@NotNull

Check warning on line 48 in server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/app/WebAppConfiguration.java

View workflow job for this annotation

GitHub Actions / Server / Lint

[checkstyle] reported by reviewdog 🐶 Missing a Javadoc comment. Raw Output: /github/workspace/./server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/app/WebAppConfiguration.java:48:5: warning: Missing a Javadoc comment. (com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocMethodCheck)
String[] getEnabledDrivers();

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.jkiss.dbeaver.registry.DataSourceNavigatorSettings;
import org.jkiss.utils.ArrayUtils;
import org.jkiss.utils.CommonUtils;
import org.jkiss.utils.ZeroSizedArrays;

import java.util.*;

Expand Down Expand Up @@ -81,8 +82,8 @@ public CBAppConfig() {
this.publicCredentialsSaveEnabled = true;
this.adminCredentialsSaveEnabled = true;
this.redirectOnFederatedAuth = false;
this.enabledDrivers = new String[0];
this.disabledDrivers = new String[0];
this.enabledDrivers = ZeroSizedArrays.OF_STRING;
this.disabledDrivers = ZeroSizedArrays.OF_STRING;
this.defaultNavigatorSettings = DEFAULT_VIEW_SETTINGS;
this.resourceQuotas = new LinkedHashMap<>();
this.enableReverseProxyAuth = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.jkiss.dbeaver.model.meta.Property;
import org.jkiss.dbeaver.runtime.properties.PropertySourceMap;
import org.jkiss.utils.CommonUtils;
import org.jkiss.utils.ZeroSizedArrays;

import java.util.Collections;
import java.util.Map;
Expand Down Expand Up @@ -88,7 +89,7 @@ public Map<String, Object> getConfiguration() {
@Override
public WebPropertyInfo[] getDetails() throws DBWebException {
if (user == null) {
return new WebPropertyInfo[0];
return WebPropertyInfo.ZERO_SIZE_ARRAY;
}
try {
SMAuthProvider<?> authProvider = this.authProviderDescriptor.getInstance();
Expand All @@ -101,7 +102,7 @@ public WebPropertyInfo[] getDetails() throws DBWebException {
} catch (Exception e) {
log.error(e);
}
return new WebPropertyInfo[0];
return WebPropertyInfo.ZERO_SIZE_ARRAY;
}

protected Map<String, Object> loadCredentials() throws DBException {
Expand All @@ -112,7 +113,7 @@ private static WebPropertyInfo[] mapCredsToProperties(
WebSession session, Map<String, Object> creds
) {
if (CommonUtils.isEmpty(creds)) {
return new WebPropertyInfo[0];
return WebPropertyInfo.ZERO_SIZE_ARRAY;
}
var propSource = new PropertySourceMap(creds);
return creds.entrySet()
Expand All @@ -125,7 +126,7 @@ private static WebPropertyInfo[] mapCredsToProperties(
true,
entry.getValue().getClass(),
null,
new Object[0]
ZeroSizedArrays.OF_OBJECT
)
)
.map(propDescriptor -> new WebPropertyInfo(session, propDescriptor, propSource))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.jkiss.dbeaver.model.security.SMSubjectType;
import org.jkiss.utils.ArrayUtils;
import org.jkiss.utils.CommonUtils;
import org.jkiss.utils.ZeroSizedArrays;

import java.util.*;

Expand Down Expand Up @@ -96,7 +97,7 @@ public WebAuthProviderDescriptor(IConfigurationElement cfg) {
requiredFeatures = CommonUtils.isEmpty(rfList) ? null : rfList.split(",");

String typesAttr = cfg.getAttribute("categories");
this.types = CommonUtils.isEmpty(typesAttr) ? new String[0] : typesAttr.split(",");
this.types = CommonUtils.isEmpty(typesAttr) ? ZeroSizedArrays.OF_STRING : typesAttr.split(",");
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.model.impl.LocalizedPropertyDescriptor;
import org.jkiss.utils.ZeroSizedArrays;

public class WebAuthProviderProperty extends LocalizedPropertyDescriptor {
private final String[] requiredFeatures;
Expand All @@ -32,7 +33,7 @@ public WebAuthProviderProperty(String category, IConfigurationElement config, St
super(category, config);
this.authProviderId = authProviderId;
String featuresAttr = config.getAttribute("requiredFeatures");
this.requiredFeatures = featuresAttr == null ? new String[0] : featuresAttr.split(",");
this.requiredFeatures = featuresAttr == null ? ZeroSizedArrays.OF_STRING : featuresAttr.split(",");
this.type = config.getAttribute("type");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
import org.jkiss.dbeaver.Log;
import org.jkiss.utils.ZeroSizedArrays;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -41,7 +42,7 @@ public synchronized static WebServerFeatureRegistry getInstance() {
return instance;
}

private String[] serverFeatures = new String[0];
private String[] serverFeatures = ZeroSizedArrays.OF_STRING;

private WebServerFeatureRegistry() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public DBSAttributeBase getAttribute(String attributeName) {
}
List<DBDAttributeBinding> nestedBindings = binding.getNestedBindings();
if (nestedBindings != null && !nestedBindings.isEmpty()) {
attrList = nestedBindings.toArray(new DBDAttributeBinding[0]);
attrList = nestedBindings.toArray(DBDAttributeBinding.ZERO_SIZE_ARRAY);
}
}
return binding == null ? null : binding.getAttribute();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import org.jkiss.dbeaver.runtime.ui.DBPPlatformUI;
import org.jkiss.utils.ArrayUtils;
import org.jkiss.utils.CommonUtils;
import org.jkiss.utils.ZeroSizedArrays;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -765,7 +766,7 @@ private void refreshDisabledDriversConfig() {
}
disabledDrivers.add(driver.getFullId());
}
config.setDisabledDrivers(disabledDrivers.toArray(new String[0]));
config.setDisabledDrivers(disabledDrivers.toArray(ZeroSizedArrays.OF_STRING));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ public static WebPropertyInfo[] getObjectFilteredProperties(
}
webProps.add(webProperty);
}
return webProps.toArray(new WebPropertyInfo[0]);
return webProps.toArray(WebPropertyInfo.ZERO_SIZE_ARRAY);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.jkiss.dbeaver.runtime.properties.PropertySourceCustom;
import org.jkiss.utils.ArrayUtils;
import org.jkiss.utils.CommonUtils;
import org.jkiss.utils.ZeroSizedArrays;

import java.util.Arrays;
import java.util.LinkedHashMap;
Expand Down Expand Up @@ -190,9 +191,9 @@
cfg.setHostPort(driver.getDefaultPort());
cfg.setDatabaseName(driver.getDefaultDatabase());
cfg.setUrl(driver.getConnectionURL(cfg));
DBPPropertyDescriptor[] properties = driver.getDataSourceProvider().getConnectionProperties(webSession.getProgressMonitor(), driver, cfg);

Check warning on line 194 in server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/model/WebDatabaseDriverInfo.java

View workflow job for this annotation

GitHub Actions / Server / Lint

[checkstyle] reported by reviewdog 🐶 Line is longer than 140 characters (found 150). Raw Output: /github/workspace/./server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/model/WebDatabaseDriverInfo.java:194:0: warning: Line is longer than 140 characters (found 150). (com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck)
if (properties == null) {
return new WebPropertyInfo[0];
return WebPropertyInfo.ZERO_SIZE_ARRAY;
}

PropertySourceCustom propertySource = new PropertySourceCustom(
Expand All @@ -203,7 +204,7 @@
.map(p -> new WebPropertyInfo(webSession, p, propertySource)).toArray(WebPropertyInfo[]::new);
} catch (DBException e) {
log.error("Error reading driver properties", e);
return new WebPropertyInfo[0];
return WebPropertyInfo.ZERO_SIZE_ARRAY;
}
}

Expand All @@ -226,7 +227,7 @@
.filter(h -> !h.isDesktopHandler())
.map(NetworkHandlerDescriptor::getId).toArray(String[]::new);
}
return new String[0];
return ZeroSizedArrays.OF_STRING;
}

@Property
Expand Down Expand Up @@ -260,7 +261,7 @@
WebPropertyInfo[] additionalWebProperty = Optional.of(WebAppUtils.getWebApplication())
.filter(app -> app.getAppConfiguration().isSecretManagerEnabled())
.map(app -> app.getConnectionController().getExternalInfo(webSession))
.orElse(new WebPropertyInfo[0]);
.orElse(WebPropertyInfo.ZERO_SIZE_ARRAY);

WebPropertyInfo[] providerProperties = Arrays.stream(driver.getProviderPropertyDescriptors())
.map(p -> new WebPropertyInfo(webSession, p, null))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import org.jkiss.dbeaver.registry.settings.ProductSettingsRegistry;
import org.jkiss.dbeaver.runtime.DBWorkbench;
import org.jkiss.utils.CommonUtils;
import org.jkiss.utils.ZeroSizedArrays;

import java.util.*;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -215,7 +216,7 @@ public String[] getSessionPermissions(@NotNull WebSession webSession) throws DBW
DBWConstants.PERMISSION_ADMIN
};
}
return webSession.getSessionPermissions().toArray(new String[0]);
return webSession.getSessionPermissions().toArray(ZeroSizedArrays.OF_STRING);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.jkiss.dbeaver.model.struct.rdb.DBSCatalog;
import org.jkiss.dbeaver.model.struct.rdb.DBSSchema;
import org.jkiss.dbeaver.model.struct.rdb.DBSTable;
import org.jkiss.utils.ZeroSizedArrays;

import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -165,7 +166,7 @@ public String[] getFeatures() {
}
}
}
return features.toArray(new String[0]);
return features.toArray(ZeroSizedArrays.OF_STRING);
}

private void getObjectFeatures(DBSObject object, List<String> features) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import org.jkiss.dbeaver.runtime.DBWorkbench;
import org.jkiss.utils.CommonUtils;
import org.jkiss.utils.IOUtils;
import org.jkiss.utils.ZeroSizedArrays;

import java.nio.file.Path;
import java.util.ArrayList;
Expand Down Expand Up @@ -250,7 +251,7 @@ public String[] getFeatures() {
}
}
if (node instanceof DBNRoot) {
return features.toArray(new String[0]);
return features.toArray(ZeroSizedArrays.OF_STRING);
}
if (node instanceof DBNResourceManagerResource && !isDistributedSpecialFolderNode()) {
if (hasNodePermission(RMProjectPermission.RESOURCE_EDIT)) {
Expand All @@ -263,7 +264,7 @@ public String[] getFeatures() {
features.add(NODE_FEATURE_CAN_CREATE_CONNECTION_FROM_NODE);
}
}
return features.toArray(new String[0]);
return features.toArray(ZeroSizedArrays.OF_STRING);
}

private boolean canCreateConnectionFromFileName(String fileName) {
Expand Down
Loading