#4317: SchemaExpService.java

tools/org.projectforge.tools.schemaexp/src/main/java/org/projectforge/tools/schemaexp/SchemaExpService.java

Path: tools/org.projectforge.tools.schemaexp/src/main/java/org/projectforge/tools/schemaexp/SchemaExpService.java

Type: Spring @Service · Lines: 95

Purpose: Core business logic for the SchemaExp developer tool — database XML export, XML import (with dual-engine support), and database clearing. The central service that all other SchemaExp components delegate to.

Source: GitHub

95 lines · 80 code · 0 comments · 15 blank
CommitDateMessage
a5bbdca6a2017-12-04Change logger to slf4j
9ebb885222016-07-18Initial commit

Architecture: Dual-engine import system

The class's most notable architectural feature is its dual-engine import system, controlled by useJpaXmlDumpService = true (line 47):

EngineFlagLibraryFeatures
Genome JPAtrue (default)de.micromata.genome.db.jpa.xmldumpJPA-aware parsing, entity type resolution, relationship handling, RestoreMode support (InsertNew/OverWrite/InsertAll), primary key allocation via sequence generators
Legacy XStreamfalseThoughtWorks XStream via XmlDumpRaw XStream serialization, manual verification via verifyDump(), post-import integrity checks via ConfigurationDao

The Genome engine is preferred because it understands JPA entity metadata — it correctly handles @OneToMany cascades, @Inheritance strategies, and foreign key relationships during import. The legacy engine is retained for backward compatibility.

Key methods

clearDb() (lines 49-52): Calls emfac.getJpaSchemaService().clearDatabase() — drops all tables in reverse dependency order. This is a destructive operation with no undo. Used both standalone (-cleardb flag) and as a prerequisite for imports (-cleardb -imp).

doImport(boolean clearDb, String clientFileName, RestoreMode modus) (lines 54-87): The main import pipeline: (1) optionally clear the database, (2) validate file existence, (3) detect file format (.xml vs .xml.gz) and decompress if needed, (4) delegate to the selected engine, (5) handle cleanup in finally block. The RestoreMode enum controls conflict resolution: InsertNew skips existing records, OverWrite updates them, InsertAll inserts everything (fails on duplicates).

doExport(String fileName) (lines 89-94): Delegates to jpaXmlDumpService.dumpToXml(emfac, file). Unlike import, export always uses the Genome library — there's no legacy XStream export path. Queries all entity types from JPA metadata, loads all records (full table scans), and serializes to XML with JPA-aware marshalling.

Code quality notes