Skip to content

Commit

Permalink
dbeaver/pro#3793 Back to roots (11) (#62)
Browse files Browse the repository at this point in the history
* dbeaver/pro#3793 Back to roots (11)

* dbeaver/pro#3793 Back to roots (11)
  • Loading branch information
serge-rider authored Dec 9, 2024
1 parent d5cd611 commit 49001c1
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 36 deletions.
2 changes: 1 addition & 1 deletion modules/com.dbeaver.jdbc.api/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -197,21 +197,21 @@ protected <T extends java.util.Date> T parseDate(Class<T> 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
Expand Down
2 changes: 1 addition & 1 deletion modules/com.dbeaver.rpc/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion modules/org.jkiss.utils/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
45 changes: 41 additions & 4 deletions modules/org.jkiss.utils/src/org/jkiss/api/DriverReference.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}

}
44 changes: 31 additions & 13 deletions modules/org.jkiss.utils/src/org/jkiss/utils/CommonUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -317,7 +329,8 @@ public static <T extends Exception> 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;
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -110,7 +111,7 @@ protected String invokeRemoteMethod(
) {
try {
Map<String, Object> fullRequest = new LinkedHashMap<>();
List<JsonElement> paramList = values.values().stream().toList();
List<JsonElement> paramList = new ArrayList<>(values.values());
fullRequest.put(method.getName(), paramList);
String requestString = gson.toJson(fullRequest);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ protected RequestHandler(
@Override
public void handle(HttpExchange exchange) throws IOException {

try (exchange) {
try {
Response<?> response;
try {
response = executeRequest(exchange);
Expand Down Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -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());
Expand Down
22 changes: 14 additions & 8 deletions modules/org.jkiss.utils/src/org/jkiss/utils/xml/XMLUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,20 @@ public static boolean isValidXMLChar(char c) {
* @return XML-encoded text
*/
public static String encodeXMLChar(char ch) {
return switch (ch) {
case '&' -> "&amp;";
case '\"' -> "&quot;";
case '\'' -> "&#39;";
case '<' -> "&lt;";
case '>' -> "&gt;";
default -> null;
};
switch (ch) {
case '&':
return "&amp;";
case '\"':
return "&quot;";
case '\'':
return "&#39;";
case '<':
return "&lt;";
case '>':
return "&gt;";
default:
return null;
}
}

public static XMLException adaptSAXException(Exception toCatch) {
Expand Down
17 changes: 17 additions & 0 deletions modules/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,21 @@
<module>com.dbeaver.rpc</module>
</modules>

<build>
<plugins>
<!-- Use minimum supported Java -->
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-compiler-plugin</artifactId>
<version>${tycho-version}</version>
<configuration>
<useProjectSettings>false</useProjectSettings>
<source>${java.version.min}</source>
<target>${java.version.min}</target>
<compilerVersion>${java.version.min}</compilerVersion>
</configuration>
</plugin>
</plugins>
</build>

</project>
1 change: 1 addition & 0 deletions root/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<local-p2-repo.url>https://p2.dev.dbeaver.com/eclipse-repo/</local-p2-repo.url>

<java.version>17</java.version>
<java.version.min>11</java.version.min>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>

Expand Down

0 comments on commit 49001c1

Please sign in to comment.