Skip to content

Commit

Permalink
MariaDB jdbc connector missing codec
Browse files Browse the repository at this point in the history
Added test to reproduce issue
Registered missing codec

Signed-off-by: Theodor Mihalache <[email protected]>
  • Loading branch information
tmihalac committed Jun 23, 2022
1 parent 76af64d commit b0fbcd7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ void registerAuthenticationPlugins(BuildProducer<ServiceProviderBuildItem> servi
.produce(ServiceProviderBuildItem.allProvidersFromClassPath("org.mariadb.jdbc.plugin.AuthenticationPlugin"));
}

@BuildStep
void registerCodecs(BuildProducer<ServiceProviderBuildItem> serviceProvider) {
serviceProvider
.produce(ServiceProviderBuildItem.allProvidersFromClassPath("org.mariadb.jdbc.plugin.Codec"));
}

@BuildStep(onlyIf = NativeOrNativeSourcesBuild.class)
void addNativeImageResources(BuildProducer<NativeImageResourceBuildItem> resources) {
// mariadb.properties is used by org.mariadb.jdbc.util.VersionFactory and is small enough.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.UUID;

import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
Expand All @@ -17,6 +21,7 @@
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;

/**
* Basic test running JPA with the MariaDB database.
Expand All @@ -28,10 +33,13 @@ public class JPAFunctionalityTestEndpoint extends HttpServlet {
@PersistenceUnit(unitName = "templatePU")
EntityManagerFactory entityManagerFactory;

@Inject
DataSource ds;

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
try {
doStuffWithHibernate(entityManagerFactory);
doStuffWithHibernate(entityManagerFactory, ds);
} catch (Exception e) {
reportException("An error occurred while performing Hibernate operations", e, resp);
}
Expand All @@ -41,7 +49,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IO
/**
* Lists the various operations we want to test for:
*/
private static void doStuffWithHibernate(EntityManagerFactory entityManagerFactory) {
private static void doStuffWithHibernate(EntityManagerFactory entityManagerFactory, DataSource ds) throws SQLException {

//Cleanup any existing data:
deleteAllPerson(entityManagerFactory);
Expand All @@ -52,6 +60,9 @@ private static void doStuffWithHibernate(EntityManagerFactory entityManagerFacto
//Load all persons and run some checks on the query results:
verifyListOfExistingPersons(entityManagerFactory);

//Try to use prepared statement with setObject:
verifyGetPersonUsingSetObject(ds);

//Try a JPA named query:
verifyJPANamedQuery(entityManagerFactory);

Expand Down Expand Up @@ -150,4 +161,18 @@ private void reportException(String errorMessage, final Exception e, final HttpS
writer.append("\n\t");
}

private static void verifyGetPersonUsingSetObject(final DataSource ds) throws SQLException {
getExistingPersonUsingSetObject(ds);
}

private static void getExistingPersonUsingSetObject(DataSource ds) throws SQLException {
try (PreparedStatement ps = ds.getConnection().prepareStatement("select * from Person as p where p.name = ?")) {
ps.setObject(1, "Quarkus");
final ResultSet resultSet = ps.executeQuery();

if (!resultSet.next()) {
throw new RuntimeException("Person Quarkus doesn't exist when it should");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ quarkus.datasource.db-kind=mariadb
quarkus.datasource.username=hibernate_orm_test
quarkus.datasource.password=hibernate_orm_test
quarkus.datasource.jdbc.url=${mariadb.url}
quarkus.datasource.jdbc.max-size=1
quarkus.datasource.jdbc.max-size=2

0 comments on commit b0fbcd7

Please sign in to comment.