Migration Deep Dive für 22 · Spring JDBC öffnen →
⌂ ÜbersichtAlle Vergleiche
Modul 22 · 100 % Codeabdeckung

Spring JDBC

Vollständiger Legacy-Modern-Vergleich aller Java-Klassen, Tests, Maven-POMs und relevanten Ressourcen dieses Moduls. Jede Datei ist genau einmal einer fachlich passenden Vergleichsgruppe zugeordnet.

3Legacy-Dateien
4Modern-Dateien
87 → 91Codezeilen
8/8vollständig erfasst

Fachliche Einordnung

Legacy

JdbcTemplate DAO

Die DAO-API und positionsbasierte Parameter sind stärker technisch geprägt.

Modern

NamedParameterJdbcTemplate Repository

Das Repository verwendet benannte Parameter und ein typisiertes Mapping.

Vergleichsfokus: Alle Dateien werden nach technischer Rolle und fachlicher Verantwortung gruppiert.
Wichtige Abgrenzung: One-to-many-Änderungen werden als Gruppe dargestellt; eine künstliche 1:1-Zuordnung wird vermieden.

Vollständige Abdeckungsmatrix

Die Ähnlichkeit ist eine technische Orientierung auf normalisiertem Quelltext. Sie ersetzt keine fachliche Bewertung.

VergleichsgruppeLegacy-DateienModern-DateienLegacy-ZeilenModern-ZeilenÄhnlichkeit
Build-Konfiguration11344271%
Datenzugriff, Modell und Test23534929%

Gemeinsame Modulstruktur

Das Pair-POM bindet die Legacy- und Modern-Submodule zusammen und gehört deshalb ebenfalls zur vollständigen Codeabdeckung.

Gemeinsam · 19 Zeilenpom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>at.aydin.academy</groupId>
        <artifactId>java-modernization-deep-dive</artifactId>
        <version>1.0.0</version>
        <relativePath>../../pom.xml</relativePath>
    </parent>
    <artifactId>22springjdbc-pair</artifactId>
    <packaging>pom</packaging>
    <name>Spring JDBC: Legacy und Modern</name>
    <modules>
        <module>legacy</module>
        <module>modern</module>
    </modules>
</project>

Alle semantischen Codevergleiche

01Build-KonfigurationDirektvergleich · Legacy 34 / Modern 42 Zeilen · Ähnlichkeit 71%

Manuelles JDBC und Spring JDBC werden verglichen.

Legacy-DateienModern-DateienEinordnung
pom.xmlpom.xmlDirektvergleich
Semantische Ähnlichkeit: 71%

Legacy

Legacy · 34 Zeilenlegacy/pom.xml
<?xml version="1.0" encoding="UTF-8"?>
        <project xmlns="http://maven.apache.org/POM/4.0.0"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
            <modelVersion>4.0.0</modelVersion>
            <parent>
                <groupId>at.aydin.academy</groupId>
                <artifactId>22springjdbc-pair</artifactId>
                <version>1.0.0</version>
                <relativePath>../pom.xml</relativePath>
            </parent>
            <artifactId>spring-jdbc-legacy</artifactId>
            <packaging>jar</packaging>
            <name>Raw JDBC Legacy</name>

            <dependencies>

<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter</artifactId>
    <scope>test</scope>
</dependency>
<dependency><groupId>com.h2database</groupId><artifactId>h2</artifactId></dependency>
            </dependencies>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                    </plugin>

                </plugins>
            </build>
        </project>

Modern

Modern · 42 Zeilenmodern/pom.xml
<?xml version="1.0" encoding="UTF-8"?>
        <project xmlns="http://maven.apache.org/POM/4.0.0"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
            <modelVersion>4.0.0</modelVersion>
            <parent>
                <groupId>at.aydin.academy</groupId>
                <artifactId>22springjdbc-pair</artifactId>
                <version>1.0.0</version>
                <relativePath>../pom.xml</relativePath>
            </parent>
            <artifactId>spring-jdbc-modern</artifactId>
            <packaging>jar</packaging>
            <name>Spring JdbcClient Modern</name>

            <dependencies>

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-jdbc</artifactId></dependency>
<dependency><groupId>com.h2database</groupId><artifactId>h2</artifactId></dependency>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
</dependency>

            </dependencies>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                    </plugin>

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
</plugin>

                </plugins>
            </build>
        </project>
02Datenzugriff, Modell und TestDirektvergleich · Legacy 53 / Modern 49 Zeilen · Ähnlichkeit 29%

JDBC-Boilerplate wird in Modell, Row-Mapping und Repository-Verantwortung getrennt.

Legacy-DateienModern-DateienEinordnung
CustomerDao.java
CustomerDaoTest.java
Customer.java
CustomerRepository.java
CustomerRepositoryTest.java
Direktvergleich
Semantische Ähnlichkeit: 29%

Legacy

package at.aydin.lab.jdbc.legacy;

import java.sql.*;
import java.util.*;

// Design Pattern: DAO
// Zweck: Kapselt Statement-, ResultSet- und Mapping-Boilerplate.
public final class CustomerDao {
    private final Connection connection;
    public CustomerDao(Connection connection) {
        this.connection = connection;
    }

    public void init() throws SQLException {
        try (Statement s = connection.createStatement()) {
            s.execute("create table if not exists customer(id bigint primary key,name varchar(100))");
        }
    }

    public void save(long id, String name) throws SQLException {
        try (PreparedStatement p = connection.prepareStatement("merge into customer key(id) values(?,?)")) {
            p.setLong(1, id);
            p.setString(2, name);
            p.executeUpdate();
        }
    }

    public Optional<String> findName(long id) throws SQLException {
        try (PreparedStatement p = connection.prepareStatement("select name from customer where id=?")) {
            p.setLong(1, id);
            try (ResultSet r = p.executeQuery()) {
                return r.next() ? Optional.of(r.getString(1)) : Optional.empty();
            }
        }
    }
}
package at.aydin.lab.jdbc.legacy;

import org.junit.jupiter.api.Test;
import java.sql.*;
import static org.junit.jupiter.api.Assertions.assertEquals;

class CustomerDaoTest {
    @Test
    void persistsWithJdbc() throws Exception {
        try (Connection c = DriverManager.getConnection("jdbc:h2:mem:legacyjdbc")) {
            var d = new CustomerDao(c);
            d.init();
            d.save(1, "Aydin");
            assertEquals("Aydin", d.findName(1).orElseThrow());
        }
    }
}

Modern

package at.aydin.lab.jdbc.modern;

import org.springframework.jdbc.core.simple.JdbcClient;
import java.util.*;

// Design Pattern: Repository + Row Mapper
// Zweck: SQL bleibt explizit, Infrastruktur-Boilerplate wird vom JdbcClient übernommen.
public final class CustomerRepository {
    private final JdbcClient jdbc;
    public CustomerRepository(JdbcClient jdbc) {
        this.jdbc = jdbc;
    }

    public void init() {
        jdbc.sql("create table if not exists customer(id bigint primary key,name varchar(100))").update();
    }

    public void save(Customer c) {
        jdbc.sql("merge into customer key(id) values(:id,:name)").param("id", c.id()).param("name", c.name())
                .update();
    }

    public Optional<Customer> find(long id) {
        return jdbc.sql("select id,name from customer where id=:id").param("id", id).query((rs, row) -> new Customer(rs.getLong("id"),
            rs.getString("name"))).optional();
    }
}
package at.aydin.lab.jdbc.modern;

import org.h2.jdbcx.JdbcDataSource;
import org.junit.jupiter.api.Test;
import org.springframework.jdbc.core.simple.JdbcClient;
import static org.junit.jupiter.api.Assertions.assertEquals;

class CustomerRepositoryTest {
    @Test
    void persistsWithJdbcClient() {
        JdbcDataSource ds = new JdbcDataSource();
        ds.setURL("jdbc:h2:mem:modernjdbc");
        var r = new CustomerRepository(JdbcClient.create(ds));
        r.init();
        r.save(new Customer(1, "Aydin"));
        assertEquals("Aydin", r.find(1).orElseThrow().name());
    }
}
⌂ Cockpit