java.lang.Object
org.dalesbred.DatabaseSource
A factory for
DatabaseConnection instances, sharing a single configuration
(dialect and type conversions) across all connections it creates.
Use DatabaseSource when you need explicit connection lifecycle management rather
than the automatic transaction handling provided by Database. Custom type conversions
registered via getTypeConversionRegistry() apply to all connections opened by this source.
var source = new DatabaseSource(dataSource, dialect);
source.getTypeConversionRegistry().registerConverter(...);
try (DatabaseConnection conn = source.openConnection()) {
conn.findAll(MyType.class, "select ...");
}
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionDatabaseSource(@NotNull DataSource dataSource, @NotNull Dialect dialect) Creates a new DatabaseSource using the given data source and dialect. -
Method Summary
Modifier and TypeMethodDescription@NotNull TypeConversionRegistryReturns the type conversion registry, which can be used to register custom type conversions that apply to all connections opened by this source.@NotNull DatabaseConnectionOpens a new connection from the underlying data source with auto-commit disabled.
-
Constructor Details
-
DatabaseSource
Creates a new DatabaseSource using the given data source and dialect.
-
-
Method Details
-
getTypeConversionRegistry
Returns the type conversion registry, which can be used to register custom type conversions that apply to all connections opened by this source. -
openConnection
Opens a new connection from the underlying data source with auto-commit disabled. The caller is responsible for closing the connection, typically via try-with-resources. Closing commits the transaction; seeDatabaseConnection.close()for details.- Throws:
DatabaseException- if a connection cannot be obtained or configured
-