diff --git a/modules/com.dbeaver.jdbc.api/META-INF/MANIFEST.MF b/modules/com.dbeaver.jdbc.api/META-INF/MANIFEST.MF index 29ee8b8..114b8e3 100644 --- a/modules/com.dbeaver.jdbc.api/META-INF/MANIFEST.MF +++ b/modules/com.dbeaver.jdbc.api/META-INF/MANIFEST.MF @@ -5,7 +5,7 @@ Bundle-Vendor: DBeaver Corp Bundle-SymbolicName: com.dbeaver.jdbc.api Bundle-Version: 2.3.1.qualifier Bundle-Release-Date: 20240205 -Bundle-RequiredExecutionEnvironment: JavaSE-17 +Bundle-RequiredExecutionEnvironment: JavaSE-11 Require-Bundle: org.jkiss.utils Export-Package: com.dbeaver.jdbc.model Automatic-Module-Name: com.dbeaver.jdbc.api diff --git a/modules/com.dbeaver.jdbc.api/src/com/dbeaver/jdbc/model/AbstractJdbcResultSet.java b/modules/com.dbeaver.jdbc.api/src/com/dbeaver/jdbc/model/AbstractJdbcResultSet.java index 45d6a2a..77caacb 100644 --- a/modules/com.dbeaver.jdbc.api/src/com/dbeaver/jdbc/model/AbstractJdbcResultSet.java +++ b/modules/com.dbeaver.jdbc.api/src/com/dbeaver/jdbc/model/AbstractJdbcResultSet.java @@ -137,8 +137,8 @@ public double getDouble(int columnIndex) throws SQLException { public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException { Object object = getObject(columnIndex); return object == null ? null : - object instanceof BigDecimal bd ? bd : - object instanceof Long str ? BigDecimal.valueOf(str) : BigDecimal.valueOf(CommonUtils.toDouble(object)); + object instanceof BigDecimal ? (BigDecimal) object : + object instanceof Long ? BigDecimal.valueOf((Long) object) : BigDecimal.valueOf(CommonUtils.toDouble(object)); } @Override @@ -197,21 +197,21 @@ protected T parseDate(Class type, String value) th public Date getDate(int columnIndex, Calendar cal) throws SQLException { Object object = getObject(columnIndex); return object == null ? null : - object instanceof Date date ? date : parseDate(Date.class, object.toString()); + object instanceof Date ? (Date) object : parseDate(Date.class, object.toString()); } @Override public Time getTime(int columnIndex, Calendar cal) throws SQLException { Object object = getObject(columnIndex); return object == null ? null : - object instanceof Time time ? time : parseDate(Time.class, object.toString()); + object instanceof Time ? (Time) object : parseDate(Time.class, object.toString()); } @Override public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException { Object object = getObject(columnIndex); return object == null ? null : - object instanceof Timestamp timestamp ? timestamp : parseDate(Timestamp.class, object.toString()); + object instanceof Timestamp ? (Timestamp) object : parseDate(Timestamp.class, object.toString()); } @Override diff --git a/modules/com.dbeaver.rpc/META-INF/MANIFEST.MF b/modules/com.dbeaver.rpc/META-INF/MANIFEST.MF index 17f7128..d7a4dc8 100644 --- a/modules/com.dbeaver.rpc/META-INF/MANIFEST.MF +++ b/modules/com.dbeaver.rpc/META-INF/MANIFEST.MF @@ -5,7 +5,7 @@ Bundle-Vendor: DBeaver Corp Bundle-SymbolicName: com.dbeaver.rpc Bundle-Version: 2.3.1.qualifier Bundle-Release-Date: 20240205 -Bundle-RequiredExecutionEnvironment: JavaSE-17 +Bundle-RequiredExecutionEnvironment: JavaSE-11 Require-Bundle: org.jkiss.utils, com.google.gson Export-Package: com.dbeaver.rpc diff --git a/modules/org.jkiss.utils/META-INF/MANIFEST.MF b/modules/org.jkiss.utils/META-INF/MANIFEST.MF index c99a4fb..56b4593 100644 --- a/modules/org.jkiss.utils/META-INF/MANIFEST.MF +++ b/modules/org.jkiss.utils/META-INF/MANIFEST.MF @@ -5,7 +5,7 @@ Bundle-Vendor: DBeaver Corp Bundle-SymbolicName: org.jkiss.utils Bundle-Version: 2.3.1.qualifier Bundle-Release-Date: 20240205 -Bundle-RequiredExecutionEnvironment: JavaSE-17 +Bundle-RequiredExecutionEnvironment: JavaSE-11 Require-Bundle: com.google.gson Export-Package: org.jkiss.api, org.jkiss.api.verification, diff --git a/modules/org.jkiss.utils/src/org/jkiss/api/DriverReference.java b/modules/org.jkiss.utils/src/org/jkiss/api/DriverReference.java index 8934a51..12fecd3 100644 --- a/modules/org.jkiss.utils/src/org/jkiss/api/DriverReference.java +++ b/modules/org.jkiss.utils/src/org/jkiss/api/DriverReference.java @@ -18,15 +18,27 @@ import org.jkiss.code.NotNull; +import java.util.Objects; + /** * Represents a reference to a driver. Instead of storing two separate fields, * it encapsulates them into one entity that is easily searchable through the code base. - * - * @param providerId id of the provider - * @param driverId id of the driver */ -public record DriverReference(@NotNull String providerId, @NotNull String driverId) { +public final class DriverReference { public static final DriverReference UNKNOWN = new DriverReference("", ""); + @NotNull + private final String providerId; + @NotNull + private final String driverId; + + /** + * @param providerId id of the provider + * @param driverId id of the driver + */ + public DriverReference(@NotNull String providerId, @NotNull String driverId) { + this.providerId = providerId; + this.driverId = driverId; + } @NotNull public static DriverReference of(@NotNull String shortId) { @@ -51,4 +63,29 @@ public String shortId() { public String toString() { return shortId(); } + + @NotNull + public String providerId() { + return providerId; + } + + @NotNull + public String driverId() { + return driverId; + } + + @Override + public boolean equals(Object obj) { + if (obj == this) return true; + if (obj == null || obj.getClass() != this.getClass()) return false; + var that = (DriverReference) obj; + return Objects.equals(this.providerId, that.providerId) && + Objects.equals(this.driverId, that.driverId); + } + + @Override + public int hashCode() { + return Objects.hash(providerId, driverId); + } + } diff --git a/modules/org.jkiss.utils/src/org/jkiss/utils/CommonUtils.java b/modules/org.jkiss.utils/src/org/jkiss/utils/CommonUtils.java index cd71f57..8edb6b0 100644 --- a/modules/org.jkiss.utils/src/org/jkiss/utils/CommonUtils.java +++ b/modules/org.jkiss.utils/src/org/jkiss/utils/CommonUtils.java @@ -52,11 +52,21 @@ public static String escapeJavaString(@NotNull String str) { for (int i = 0; i < str.length(); i++) { char c = str.charAt(i); switch (c) { - case '"' -> res.append("\\\""); - case '\n' -> res.append("\\n"); - case '\r' -> res.append("\\r"); - case '\t' -> res.append("\\t"); - default -> res.append(c); + case '"': + res.append("\\\""); + break; + case '\n': + res.append("\\n"); + break; + case '\r': + res.append("\\r"); + break; + case '\t': + res.append("\\t"); + break; + default: + res.append(c); + break; } } return res.toString(); @@ -280,7 +290,8 @@ public static boolean getBoolean(@Nullable String value, boolean defaultValue) { public static boolean getBoolean(@Nullable Object value, boolean defaultValue) { if (value == null) { return defaultValue; - } else if (value instanceof Boolean b) { + } else if (value instanceof Boolean) { + Boolean b = (Boolean) value; return b; } else { return getBoolean(value.toString(), defaultValue); @@ -299,7 +310,8 @@ public static Throwable getRootCause(@NotNull Throwable ex) { for (; ; ) { if (rootCause.getCause() != null) { rootCause = rootCause.getCause(); - } else if (rootCause instanceof InvocationTargetException ite && ite.getTargetException() != null) { + } else if (rootCause instanceof InvocationTargetException && ((InvocationTargetException) rootCause).getTargetException() != null) { + InvocationTargetException ite = (InvocationTargetException) rootCause; rootCause = ite.getTargetException(); } else { break; @@ -317,7 +329,8 @@ public static T getCauseOfType(@NotNull Throwable ex, Clas } if (rootCause.getCause() != null) { rootCause = rootCause.getCause(); - } else if (rootCause instanceof InvocationTargetException ite && ite.getTargetException() != null) { + } else if (rootCause instanceof InvocationTargetException && ((InvocationTargetException) rootCause).getTargetException() != null) { + InvocationTargetException ite = (InvocationTargetException) rootCause; rootCause = ite.getTargetException(); } else { break; @@ -371,7 +384,8 @@ public static boolean equalsContents(@Nullable Collection c1, @Nullable Colle public static String toString(@Nullable Object object) { if (object == null) { return ""; - } else if (object instanceof String s) { + } else if (object instanceof String) { + String s = (String) object; return s; } else { String strValue = object.toString(); @@ -382,7 +396,8 @@ public static String toString(@Nullable Object object) { public static String toString(@Nullable Object object, String def) { if (object == null) { return def; - } else if (object instanceof String s) { + } else if (object instanceof String) { + String s = (String) object; return s; } else { return object.toString(); @@ -392,7 +407,8 @@ public static String toString(@Nullable Object object, String def) { public static boolean toBoolean(@Nullable Object object, boolean def) { if (object == null) { return def; - } else if (object instanceof Boolean b) { + } else if (object instanceof Boolean) { + Boolean b = (Boolean) object; return b; } else { return getBoolean(object.toString(), def); @@ -406,7 +422,8 @@ public static boolean toBoolean(@Nullable Object object) { public static int toInt(@Nullable Object object, int def) { if (object == null) { return def; - } else if (object instanceof Number n) { + } else if (object instanceof Number) { + Number n = (Number) object; return n.intValue(); } else { String strValue = toString(object); @@ -451,7 +468,8 @@ public static long toLong(@Nullable Object object) { public static long toLong(@Nullable Object object, long defValue) { if (object == null) { return defValue; - } else if (object instanceof Number n) { + } else if (object instanceof Number) { + Number n = (Number) object; return n.longValue(); } else { try { diff --git a/modules/org.jkiss.utils/src/org/jkiss/utils/rest/JsonRpcClient.java b/modules/org.jkiss.utils/src/org/jkiss/utils/rest/JsonRpcClient.java index d6f6073..04098ae 100644 --- a/modules/org.jkiss.utils/src/org/jkiss/utils/rest/JsonRpcClient.java +++ b/modules/org.jkiss.utils/src/org/jkiss/utils/rest/JsonRpcClient.java @@ -24,6 +24,7 @@ import java.lang.reflect.Method; import java.net.URI; +import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -110,7 +111,7 @@ protected String invokeRemoteMethod( ) { try { Map fullRequest = new LinkedHashMap<>(); - List paramList = values.values().stream().toList(); + List paramList = new ArrayList<>(values.values()); fullRequest.put(method.getName(), paramList); String requestString = gson.toJson(fullRequest); diff --git a/modules/org.jkiss.utils/src/org/jkiss/utils/rest/RestServer.java b/modules/org.jkiss.utils/src/org/jkiss/utils/rest/RestServer.java index 820d3d8..6980290 100644 --- a/modules/org.jkiss.utils/src/org/jkiss/utils/rest/RestServer.java +++ b/modules/org.jkiss.utils/src/org/jkiss/utils/rest/RestServer.java @@ -132,7 +132,7 @@ protected RequestHandler( @Override public void handle(HttpExchange exchange) throws IOException { - try (exchange) { + try { Response response; try { response = executeRequest(exchange); @@ -175,6 +175,8 @@ public void handle(HttpExchange exchange) throws IOException { } catch (Throwable e) { log.log(Level.SEVERE, "Internal IO error", e); throw e; + } finally { + exchange.close(); } } @@ -228,7 +230,8 @@ protected Response executeRequest(@NotNull HttpExchange exchange) throws IOEx final Type type = method.getGenericReturnType(); return createResponseContent(result, type); } catch (Throwable e) { - if (e instanceof InvocationTargetException ite) { + if (e instanceof InvocationTargetException) { + InvocationTargetException ite = (InvocationTargetException) e; e = ite.getTargetException(); } log.log(Level.SEVERE, "RPC call '" + uri + "' failed: " + e.getMessage()); diff --git a/modules/org.jkiss.utils/src/org/jkiss/utils/xml/XMLUtils.java b/modules/org.jkiss.utils/src/org/jkiss/utils/xml/XMLUtils.java index 0185a96..125b104 100644 --- a/modules/org.jkiss.utils/src/org/jkiss/utils/xml/XMLUtils.java +++ b/modules/org.jkiss.utils/src/org/jkiss/utils/xml/XMLUtils.java @@ -242,14 +242,20 @@ public static boolean isValidXMLChar(char c) { * @return XML-encoded text */ public static String encodeXMLChar(char ch) { - return switch (ch) { - case '&' -> "&"; - case '\"' -> """; - case '\'' -> "'"; - case '<' -> "<"; - case '>' -> ">"; - default -> null; - }; + switch (ch) { + case '&': + return "&"; + case '\"': + return """; + case '\'': + return "'"; + case '<': + return "<"; + case '>': + return ">"; + default: + return null; + } } public static XMLException adaptSAXException(Exception toCatch) { diff --git a/modules/pom.xml b/modules/pom.xml index 6ae262e..fed0edb 100644 --- a/modules/pom.xml +++ b/modules/pom.xml @@ -22,4 +22,21 @@ com.dbeaver.rpc + + + + + org.eclipse.tycho + tycho-compiler-plugin + ${tycho-version} + + false + ${java.version.min} + ${java.version.min} + ${java.version.min} + + + + + diff --git a/root/pom.xml b/root/pom.xml index 4151aa4..6a7a8b8 100644 --- a/root/pom.xml +++ b/root/pom.xml @@ -27,6 +27,7 @@ https://p2.dev.dbeaver.com/eclipse-repo/ 17 + 11 ${java.version} ${java.version}