Skip to content

Commit

Permalink
Add support for using Agroal Datasources in hibernate
Browse files Browse the repository at this point in the history
If persistence.xml does not have a connection URL defined then the Agroal
datasource will be used instead.
  • Loading branch information
stuartwdouglas committed Sep 25, 2018
1 parent 5d48738 commit a41233b
Show file tree
Hide file tree
Showing 17 changed files with 91 additions and 304 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
public class RuntimePriority {

public static final int UNDERTOW_CREATE_DEPLOYMENT = 100;
public static final int JPA_DEPLOYMENT = 150;
public static final int UNDERTOW_REGISTER_SERVLET = 200;
public static final int FAULT_TOLERANCE_DEPLOYMENT = 250;
public static final int HEALTH_DEPLOYMENT = 260;
public static final int WELD_DEPLOYMENT = 300;
public static final int JAXRS_DEPLOYMENT = 350;
public static final int ARC_DEPLOYMENT = 300;
public static final int UNDERTOW_DEPLOY = 400;
public static final int JPA_DEPLOYMENT = 500;
public static final int BEAN_VALIDATION_DEPLOYMENT = 600;
public static final int TRANSACTIONS_DEPLOYMENT = 700;
public static final int DATASOURCE_DEPLOYMENT = 700;
Expand Down
5 changes: 0 additions & 5 deletions examples/strict/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,6 @@
<artifactId>shamrock-graal</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.4.0</version>
</dependency>
</dependencies>

<build>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,19 @@ public void seetup() throws Exception {

try (Connection con = dataSource.getConnection()) {
try (Statement statement = con.createStatement()) {
try {
statement.execute("drop table a");
statement.execute("drop table tx");
} catch (Exception ignored) {

}
statement.execute("create table a (b int)");
statement.execute("create table tx (b int)");
}
}
}


public void doInit() {

}
Expand Down

This file was deleted.

3 changes: 0 additions & 3 deletions examples/strict/src/main/resources/META-INF/persistence.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@

<!-- Connection specific -->
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL95Dialect"/>
<property name="hibernate.connection.url" value="${postgres.url}"/>
<property name="hibernate.connection.username" value="hibernate_orm_test"/>
<property name="hibernate.connection.password" value="hibernate_orm_test"/>

<!-- Tuning and debugging -->
<property name="hibernate.connection.pool_size" value="2"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
datasource:
url: "jdbc:hsqldb:hsql://localhost:7676/test"
driver: "org.hsqldb.jdbc.JDBCDriver"
url: ${postgres.url}
driver: "org.postgresql.Driver"
username: "hibernate_orm_test"
password: "hibernate_orm_test"
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.jboss.shamrock.example.test;

import org.jboss.shamrock.junit.GraalTest;
import org.junit.runner.RunWith;

@RunWith(GraalTest.class)
public class DataSourceTransactionITCase extends DataSourceTransactionTestCase {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.jboss.shamrock.example.test;

import org.jboss.shamrock.example.testutils.URLResponse;
import org.jboss.shamrock.example.testutils.URLTester;
import org.jboss.shamrock.junit.ShamrockTest;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(ShamrockTest.class)
public class DataSourceTransactionTestCase {

@Test
public void testTransactionalAnnotation() {
//TODO: this does not really belong here, but it saves having to set all the DB stuff up again

Assert.assertEquals("PASSED", URLTester.relative("rest/datasource/txninterceptor0").invokeURL().asString());

try {
URLResponse resp = URLTester.relative("rest/datasource/txninterceptor1").invokeURL();
Assert.fail(resp.asString());
} catch (RuntimeException expected) {

}
Assert.assertEquals("PASSED", URLTester.relative("rest/datasource/txninterceptor2").invokeURL().asString());


}

}
Original file line number Diff line number Diff line change
@@ -1,40 +1,14 @@
package org.jboss.shamrock.example.test;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

import org.hsqldb.Server;
import org.jboss.shamrock.example.testutils.URLResponse;
import org.jboss.shamrock.example.testutils.URLTester;
import org.jboss.shamrock.junit.ShamrockTest;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(ShamrockTest.class)
public class DatasourceTestCase {

static Server ws;

@BeforeClass
public static void setup() throws Exception {
Path dir = Files.createTempDirectory("shamrock-test");
ws = new Server();
ws.setPort(7676);
ws.setAddress("localhost");
ws.setDatabaseName(0, "test");
ws.setDatabasePath(0, dir.toAbsolutePath().toString() + File.separator + "tempdb");
ws.start();
}

@AfterClass
public static void tearDown() {
ws.stop();
}

@Test
public void testDataSource() {
Expand All @@ -46,21 +20,4 @@ public void testDataSourceTransactions() {
Assert.assertEquals("PASSED", URLTester.relative("rest/datasource/txn").invokeURL().asString());
}

@Test
public void testTransactionalAnnotation() {
//TODO: this does not really belong here, but it saves having to set all the DB stuff up again

Assert.assertEquals("PASSED", URLTester.relative("rest/datasource/txninterceptor0").invokeURL().asString());

try {
URLResponse resp = URLTester.relative("rest/datasource/txninterceptor1").invokeURL();
Assert.fail(resp.asString());
} catch (RuntimeException expected) {

}
Assert.assertEquals("PASSED", URLTester.relative("rest/datasource/txninterceptor2").invokeURL().asString());


}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import static org.junit.Assert.assertEquals;

import org.jboss.shamrock.example.testutils.URLTester;
import org.jboss.shamrock.junit.GraalTest;
import org.jboss.shamrock.junit.ShamrockTest;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down
Loading

0 comments on commit a41233b

Please sign in to comment.