Skip to content

Commit c67568f

Browse files
authored
Merge pull request #8788 from geoand/#8785
Fix case where MongoDB and MariaDB extensions fail in native
2 parents 255726f + aa89e92 commit c67568f

File tree

5 files changed

+80
-0
lines changed

5 files changed

+80
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package io.quarkus.jdbc.mariadb.runtime.graal;
2+
3+
import com.oracle.svm.core.annotate.Delete;
4+
import com.oracle.svm.core.annotate.TargetClass;
5+
6+
@TargetClass(className = "org.mariadb.jdbc.internal.io.socket.SharedMemorySocket")
7+
@Delete
8+
public final class SharedMemorySocket_Removal {
9+
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package io.quarkus.jdbc.mariadb.runtime.graal;
2+
3+
import java.io.IOException;
4+
import java.net.Socket;
5+
6+
import org.mariadb.jdbc.internal.io.socket.SocketHandlerFunction;
7+
import org.mariadb.jdbc.internal.util.Utils;
8+
import org.mariadb.jdbc.util.Options;
9+
10+
public class SimpleSocketHandlerFunction implements SocketHandlerFunction {
11+
@Override
12+
public Socket apply(Options options, String host) throws IOException {
13+
if (options.pipe != null) {
14+
throw new IllegalArgumentException(getErrorMessage("pipe"));
15+
} else if (options.localSocket != null) {
16+
throw new IllegalArgumentException(getErrorMessage("localSocket"));
17+
} else if (options.sharedMemory != null) {
18+
throw new IllegalArgumentException(getErrorMessage("sharedMemory"));
19+
}
20+
21+
return Utils.standardSocket(options, host);
22+
}
23+
24+
private String getErrorMessage(String option) {
25+
return "Option '" + option + "' is not available for MariaDB in native mode";
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package io.quarkus.jdbc.mariadb.runtime.graal;
2+
3+
import org.mariadb.jdbc.internal.io.socket.SocketHandlerFunction;
4+
5+
import com.oracle.svm.core.annotate.Substitute;
6+
import com.oracle.svm.core.annotate.TargetClass;
7+
8+
@TargetClass(org.mariadb.jdbc.internal.io.socket.SocketUtility.class)
9+
public final class SocketUtility_Substitutions {
10+
11+
// Ensure that JNA is never used
12+
@Substitute
13+
public static SocketHandlerFunction getSocketHandler() {
14+
return new SimpleSocketHandlerFunction();
15+
}
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package io.quarkus.jdbc.mariadb.runtime.graal;
2+
3+
import org.mariadb.jdbc.internal.io.socket.SocketHandlerFunction;
4+
import org.mariadb.jdbc.internal.util.Utils;
5+
6+
import com.oracle.svm.core.annotate.Alias;
7+
import com.oracle.svm.core.annotate.RecomputeFieldValue;
8+
import com.oracle.svm.core.annotate.TargetClass;
9+
10+
@TargetClass(org.mariadb.jdbc.internal.util.Utils.class)
11+
public final class Utils_socketHandler {
12+
13+
@Alias
14+
@RecomputeFieldValue(kind = RecomputeFieldValue.Kind.FromAlias)
15+
private static SocketHandlerFunction socketHandler = new SimpleSocketHandlerFunction();
16+
}

extensions/mongodb-client/runtime/src/main/java/io/quarkus/mongodb/runtime/graal/MongoClientSubstitutions.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,14 @@ public String resolveAdditionalQueryParametersFromTxtRecords(final String host)
173173
throw new UnsupportedOperationException("mongo+srv:// not supported in native mode");
174174
}
175175
}
176+
177+
//TODO: move to a dedicated jna extension that will simply collect JNA substitutions
178+
@TargetClass(com.sun.jna.Native.class)
179+
final class JnaNativeSubstitutions {
180+
181+
// This method can trick GraalVM into thinking that Classloader#findLibrary is getting called
182+
@Substitute
183+
public static String getWebStartLibraryPath(final String libName) {
184+
return null;
185+
}
186+
}

0 commit comments

Comments
 (0)