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(deps): update dependency org.apache.tomcat:tomcat-jdbc to v10.1.28 #1391

Merged
merged 2 commits into from
Aug 8, 2024
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
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ managed-mysql-connector-j = "8.4.0"

managed-hikari = "5.1.0"
managed-commons-dbcp = "2.12.0"
managed-tomcat-jdbc = "10.1.26"
managed-tomcat-jdbc = "10.1.28"

# JPA

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"interfaces": [
"java.sql.ResultSet"
]
}
]
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,4 @@ include 'tests:jooq-tests:jooq-r2dbc-postgres'

include 'tests:jdbc-ucp-tests:jdbc-ucp-oracle'
include 'tests:jdbc-dbcp-tests:jdbc-dbcp-postgres'
include 'tests:jdbc-tomcat-tests:jdbc-tomcat-mysql'
19 changes: 19 additions & 0 deletions tests/jdbc-tomcat-tests/jdbc-tomcat-mysql/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
plugins {
id 'io.micronaut.build.internal.test-application'
}

dependencies {
implementation projects.micronautJdbcTomcat
implementation projects.micronautTests.micronautCommonSync

runtimeOnly libs.managed.mysql.connector.j

testImplementation projects.micronautTests.micronautCommonTests
testImplementation(mnData.micronaut.data.tx.jdbc)
}

micronaut {
testResources {
additionalModules.add(JDBC_MYSQL)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package example.jdbc.tomcat.sync;

import example.domain.IOwner;
import io.micronaut.core.annotation.Creator;
import io.micronaut.serde.annotation.Serdeable;

@Serdeable
public class Owner implements IOwner {

private Long id;
private String name;
private int age;

Owner() {
}

@Creator
public Owner(Long id, String name, int age) {
this.id = id;
this.name = name;
this.age = age;
}

@Override
public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

@Override
public String getName() {
return name;
}

@Override
public void setName(String name) {
this.name = name;
}

@Override
public int getAge() {
return age;
}

@Override
public void setAge(int age) {
this.age = age;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
package example.jdbc.tomcat.sync;

import example.domain.IOwner;
import example.sync.IOwnerRepository;
import jakarta.annotation.PostConstruct;
import jakarta.inject.Singleton;

import jakarta.transaction.Transactional;

import javax.sql.DataSource;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Optional;

@Singleton
public class OwnerRepository implements IOwnerRepository {

private final DataSource dataSource;

public OwnerRepository(DataSource dataSource) {
this.dataSource = dataSource;
}

@PostConstruct
public void init() throws SQLException {
runInit();
}

@Transactional
public void runInit() throws SQLException {
PreparedStatement stmt = dataSource.getConnection().prepareStatement("""
CREATE TABLE owners (id INTEGER NOT NULL AUTO_INCREMENT,
name VARCHAR(200) NOT NULL,
age INTEGER NOT NULL,
PRIMARY KEY (id))""");
stmt.executeUpdate();
}

@Override
public Owner create() {
return new Owner();
}

@Transactional(Transactional.TxType.MANDATORY)
@Override
public void save(IOwner owner) {
try {
PreparedStatement stmt = dataSource.getConnection().prepareStatement("INSERT INTO owners (name, age) VALUES (?, ?)",
new String[]{"id"});
stmt.setString(1, owner.getName());
stmt.setInt(2, owner.getAge());
stmt.executeUpdate();
ResultSet rs = stmt.getGeneratedKeys();
if (rs.next()) {
owner.setId(rs.getLong(1));
}
} catch (SQLException e) {
throw new RuntimeException("Failed to insert owner", e);
}
}

@Transactional(Transactional.TxType.MANDATORY)
@Override
public void delete(IOwner owner) {
try {
PreparedStatement stmt = dataSource.getConnection().prepareStatement("DELETE FROM owners WHERE id = ?");
stmt.setLong(1, owner.getId());
stmt.executeUpdate();
} catch (SQLException e) {
throw new RuntimeException("Failed to delete owner", e);
}
}

@Override
public IOwner findById(Long id) {
try {
PreparedStatement stmt = dataSource.getConnection().prepareStatement("SELECT * FROM owners WHERE id = ?");
stmt.setLong(1, id);
ResultSet rs = stmt.executeQuery();
if (rs.next()) {
return map(rs);
}
return null;
} catch (SQLException e) {
throw new RuntimeException("Failed to find owner by id", e);
}
}

@Override
public Collection<IOwner> findAll() {
try {
PreparedStatement stmt = dataSource.getConnection().prepareStatement("SELECT * FROM owners");
ResultSet rs = stmt.executeQuery();
List<IOwner> resultList = new ArrayList<>();
while (rs.next()) {
resultList.add(map(rs));
}
return resultList;
} catch (SQLException e) {
throw new RuntimeException("Failed to find all owners", e);
}
}

@Override
public Optional<IOwner> findByName(String name) {
try {
PreparedStatement stmt = dataSource.getConnection().prepareStatement("SELECT * FROM owners WHERE name = ?");
stmt.setString(1, name);
ResultSet rs = stmt.executeQuery();
if (rs.next()) {
return Optional.of(map(rs));
}
return Optional.empty();
} catch (SQLException e) {
throw new RuntimeException("Failed to find owner by name", e);
}
}

private IOwner map(ResultSet rs) throws SQLException {
return new Owner(rs.getLong("id"),
rs.getString("name"),
rs.getInt("age"));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package example.jdbc.tomcat.sync;

import example.domain.IOwner;
import example.domain.IPet;
import io.micronaut.core.annotation.Creator;
import io.micronaut.core.annotation.Nullable;
import io.micronaut.serde.annotation.Serdeable;

@Serdeable
public class Pet implements IPet {

private Long id;
private String name;
private PetType type;
private Owner owner;

Pet() {
}

@Creator
public Pet(Long id, String name, @Nullable PetType type, Owner owner) {
this.id = id;
this.name = name;
this.type = type;
this.owner = owner;
}

@Override
public Long getId() {
return id;
}

@Override
public void setId(Long id) {
this.id = id;
}

@Override
public String getName() {
return name;
}

@Override
public void setName(String name) {
this.name = name;
}

@Override
public Owner getOwner() {
return owner;
}

@Override
public void setOwner(IOwner owner) {
this.owner = (Owner) owner;
}

@Override
public PetType getType() {
return type;
}

@Override
public void setType(PetType type) {
this.type = type;
}
}
Loading
Loading