DatabaseSupport.javaDatabase dialect abstraction layer. Singleton (static getInstance() + setInstance() — set during application startup). Holds the detected DatabaseDialect (PostgreSQL or HSQL) and provides dialect-specific optimizations. 101 lines.
Constructor: DatabaseSupport(DatabaseDialect dialect) — logs the detected dialect at INFO level: "Setting database dialect to: PostgreSQL". The dialect is determined by ConfigurationService from the JDBC URL at startup.
Key method — getIntervalInSeconds(fromProperty, toProperty): This is the critical performance method. For calculating duration (e.g. timesheet stopTime - startTime), instead of fetching all rows into Java and computing differences in memory (O(n) memory + CPU), it generates a database-side SUM in SQL:
PostgreSQL: "SUM(EXTRACT(EPOCH FROM toProperty) - EXTRACT(EPOCH FROM fromProperty))"
This returns the total seconds as a single database aggregate — O(1) result size regardless of row count. Critical for installations with many timesheet entries. The commented-out alternative EXTRACT(EPOCH FROM SUM(to - from)) was considered but the per-row calculation was chosen for precision.
Fallback: If the database is not PostgreSQL (i.e. HSQL for testing), returns null. The caller must then fetch all rows and compute the sum in Java. A one-time warning is logged (guarded by static boolean errorMessageShown) asking to contact the developer if the installation has >10,000 timesheet entries — the Java-side aggregation becomes slow at scale.
getShutdownDatabaseStatement(): Called by WicketApplication on shutdown. For HSQL (embedded test database), returns "SHUTDOWN COMPACT" — safely closes the embedded database and compacts the data file. For PostgreSQL, returns null — the connection pool handles shutdown.
Design note: This is the only place in the codebase where database-specific SQL is generated. All other SQL is generated by Hibernate/HQL which is database-agnostic. This class exists specifically for the interval optimization which HQL cannot express portably.