Migration Deep Dive für 24 · MongoDB öffnen →
⌂ ÜbersichtAlle Vergleiche
Modul 24 · 100 % Codeabdeckung

MongoDB

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.

5Legacy-Dateien
4Modern-Dateien
97 → 68Codezeilen
10/10vollständig erfasst

Fachliche Einordnung

Legacy

Mongo Driver, BSON Document und manuelles Mapping

Filter, Upsert, Cursor-Iteration und Document-Mapping werden manuell implementiert.

Modern

Spring Data MongoDB Repository

Spring Data leitet die Query aus dem Repository-Methodennamen ab und mappt ein @Document-Record.

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-Konfiguration11343942%
Dokumentmodell, Mapping und Test32321933%
Repository1131106%

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>24mongodb-pair</artifactId>
    <packaging>pom</packaging>
    <name>MongoDB: Legacy und Modern</name>
    <modules>
        <module>legacy</module>
        <module>modern</module>
    </modules>
</project>

Alle semantischen Codevergleiche

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

MongoDB-Treiber/Mapping-Abhängigkeiten werden verglichen.

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

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>24mongodb-pair</artifactId>
                <version>1.0.0</version>
                <relativePath>../pom.xml</relativePath>
            </parent>
            <artifactId>mongodb-driver-legacy</artifactId>
            <packaging>jar</packaging>
            <name>MongoDB Driver Legacy</name>

            <dependencies>
                <dependency><groupId>org.mongodb</groupId><artifactId>mongodb-driver-sync</artifactId></dependency>
<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter</artifactId>
    <scope>test</scope>
</dependency>

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

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

Modern

Modern · 39 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>24mongodb-pair</artifactId>
                <version>1.0.0</version>
                <relativePath>../pom.xml</relativePath>
            </parent>
            <artifactId>spring-data-mongodb-modern</artifactId>
            <packaging>jar</packaging>
            <name>Spring Data MongoDB Modern</name>

            <dependencies>
                <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-mongodb</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>
02Dokumentmodell, Mapping und TestDirektvergleich · Legacy 32 / Modern 19 Zeilen · Ähnlichkeit 33%

Manuelles Mapping wird durch annotiertes Dokumentmodell ersetzt.

Legacy-DateienModern-DateienEinordnung
LegacyBook.java
LegacyBookMapper.java
LegacyBookMapperTest.java
BookDocument.java
BookDocumentTest.java
Direktvergleich
Semantische Ähnlichkeit: 33%

Legacy

package at.aydin.lab.mongodb.legacy;

import org.bson.Document;

// Design Pattern: Data Mapper
// Zweck: Übersetzt manuell zwischen Fachobjekt und MongoDB Document.
public final class LegacyBookMapper {
    public Document toDocument(LegacyBook b) {
        return new Document("_id", b.id()).append("title", b.title()).append("year", b.year());
    }

    public LegacyBook fromDocument(Document d) {
        return new LegacyBook(d.getString("_id"), d.getString("title"), d.getInteger("year"));
    }
}
package at.aydin.lab.mongodb.legacy;

import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;

class LegacyBookMapperTest {
    @Test
    void mapsDocument() {
        var m = new LegacyBookMapper();
        var b = new LegacyBook("1", "Java", 2026);
        assertEquals(b, m.fromDocument(m.toDocument(b)));
    }
}

Modern

package at.aydin.lab.mongodb.modern;

import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;

@Document("books")
public record BookDocument(@Id String id, String title, int year) {
}
package at.aydin.lab.mongodb.modern;

import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;

class BookDocumentTest {
    @Test
    void isImmutableDocument() {
        assertEquals("Java", new BookDocument("1", "Java", 2026).title());
    }
}
03RepositoryDirektvergleich · Legacy 31 / Modern 10 Zeilen · Ähnlichkeit 6%

Eigene Repository-Implementierung wird deklarativem Spring-Data-Repository gegenübergestellt.

Legacy-DateienModern-DateienEinordnung
LegacyBookRepository.javaBookRepository.javaDirektvergleich
Semantische Ähnlichkeit: 6%

Legacy

package at.aydin.lab.mongodb.legacy;

import com.mongodb.client.MongoCollection;
import com.mongodb.client.model.ReplaceOptions;
import org.bson.Document;
import java.util.ArrayList;
import java.util.List;
import static com.mongodb.client.model.Filters.gte;

// Design Pattern: Repository
// Zweck: Mongo-Driver, BSON-Filter und manuelles Mapping werden hinter einer fachlichen API gekapselt.
public final class LegacyBookRepository {
    private final MongoCollection<Document> collection;
    private final LegacyBookMapper mapper;
    public LegacyBookRepository(MongoCollection<Document> collection, LegacyBookMapper mapper) {
        this.collection = collection;
        this.mapper = mapper;
    }

    public void save(LegacyBook book) {
        collection.replaceOne(new Document("_id", book.id()), mapper.toDocument(book), new ReplaceOptions().upsert(true));
    }

    public List<LegacyBook> findByYearGreaterThanEqual(int year) {
        List<LegacyBook> result = new ArrayList<>();
        for (Document document : collection.find(gte("year", year))) {
            result.add(mapper.fromDocument(document));
        }
        return List.copyOf(result);
    }
}

Modern

package at.aydin.lab.mongodb.modern;

import org.springframework.data.mongodb.repository.MongoRepository;
import java.util.*;

// Design Pattern: Repository
// Zweck: Query-Ableitung ersetzt manuelle Document-/Cursor-Verarbeitung.
public interface BookRepository extends MongoRepository<BookDocument, String> {
    List<BookDocument> findByYearGreaterThanEqual(int year);
}
⌂ Cockpit