Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #44 to support hibernate orm #59

Merged
merged 1 commit into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-orm</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jsonb</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
package io.quarkiverse.shardingsphere.jdbc.it;

import javax.enterprise.context.ApplicationScoped;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

import io.quarkus.runtime.annotations.RegisterForReflection;

@Entity
@Table(name = "t_account")
@ApplicationScoped
@RegisterForReflection
public class Account {
@Id
private int account_id;
private int user_id;
private String status;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.quarkiverse.shardingsphere.jdbc.it;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
Expand All @@ -11,7 +10,9 @@
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.literal.NamedLiteral;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.sql.DataSource;
import javax.transaction.Transactional;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
Expand All @@ -27,15 +28,17 @@
public class ShardingTablesResource {
@Inject
DataSource dataSource;
@Inject
EntityManager entityManager;

@PostConstruct
void onStart() throws Exception {
createAccountTable();
//createAccountTable();
}

@PreDestroy
void onStop() throws Exception {
dropAccountTable();
//dropAccountTable();
}

private void createAccountTable() throws SQLException {
Expand All @@ -59,21 +62,9 @@ private void dropAccountTable() throws SQLException {
@Path("/account")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.TEXT_PLAIN)
public Integer createAccount(Account account) throws Exception {
int result = 0;

String sql = "INSERT INTO t_account (account_id, user_id, status) VALUES (?, ?, ?)";
try (Connection connection = dataSource.getConnection();
PreparedStatement statement = connection.prepareStatement(sql)) {
statement.setInt(1, account.getAccount_id());
statement.setInt(2, account.getUser_id());
statement.setString(3, account.getStatus());
result = statement.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
}

return result;
@Transactional
public void createAccount(Account account) {
entityManager.persist(account);
}

@GET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ quarkus.datasource.devservices.enabled=false
quarkus.datasource.ds_0.db-kind=h2
quarkus.datasource.ds_0.username=sa
quarkus.datasource.ds_0.jdbc.url=jdbc:h2:mem:ds_0
quarkus.datasource.ds_0.jdbc.transactions=DISABLED

quarkus.datasource.ds_1.db-kind=h2
quarkus.datasource.ds_1.username=sa
quarkus.datasource.ds_1.jdbc.url=jdbc:h2:mem:ds_1
quarkus.datasource.ds_1.jdbc.transactions=DISABLED

quarkus.datasource.db-kind=shardingsphere
quarkus.datasource.jdbc.url=jdbc:shardingsphere:classpath:config.yaml
#quarkus.datasource.jdbc.acquisition-timeout=2H

quarkus.hibernate-orm.dialect=io.quarkus.hibernate.orm.runtime.dialect.QuarkusH2Dialect
quarkus.hibernate-orm.database.generation=drop-and-create
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ public void test() {
.body("{\"account_id\":1, \"user_id\":1, \"status\":\"true\"}").contentType(ContentType.JSON)
.post("/shardingsphere-jdbc/account")
.then()
.statusCode(200)
.body(is("1"));
.statusCode(204);

given().get("/shardingsphere-jdbc/account/ds_0/t_account_0")
.then()
Expand Down