- java.lang.Object
-
- aeonics.template.Item<Database.Type>
-
- aeonics.entity.Database
-
public class Database extends Item<Database.Type>
This entity represents a JDBC connection to a database. It wraps the query operations with a connection pool and returns the result as aData
structure.There are two recommended ways to create your own item inline (without creating a full class). The first method allows to provide the data connection establishment function and registers automatically the template in the factory and the instance in the registry:
Database.Type item = new Database() { } // <-- note the '{ }' to create a new anonymous class .template() // <-- create the template and register it in the factory // add all your template documentation .summary("My favourite database") .create() // <-- create an instance of the entity and register it in the registry // set the processing function .connection(() -> { return new Database.PooledConnection(item, null); }); // <-- the connection establishment function
If you need more control over the behavior such as private member variables or multiple methods, then you need to declare a custom entity end register it before calling the template method:
public static class MyEntity extends Database.Type { protected Database.PooledDatabase connection() { return null; } } Database.Type action = new Database() { } // <-- note the '{ }' to create a new anonymous class // register the custom entity before calling the template .target(MyEntity.class) .creator(MyEntity::new) .template() // <-- create the template and register it in the factory // add all your template documentation .summary("My database") .create(); // <-- create an instance of the entity and register it in the registry
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Database.PooledConnection
This class is a wrapper around a java.sql.Connection class to be used with the pooledDatabase.Type
.static class
Database.Type
Superclass for all database entities.
-
Constructor Summary
Constructors Constructor Description Database()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.Class<? extends Database>
category()
Returns the target entity category.protected java.util.function.Supplier<? extends Database.Type>
defaultCreator()
Returns the default target entity creator.protected java.lang.Class<? extends Database.Type>
defaultTarget()
Returns the default target entity type.Template<? extends Database.Type>
template()
Returns the template to build the target entity.
-
-
-
Method Detail
-
defaultTarget
protected java.lang.Class<? extends Database.Type> defaultTarget()
Description copied from class:Item
Returns the default target entity type. This method should be implemented by subclasses to specify the target entity type.- Specified by:
defaultTarget
in classItem<Database.Type>
- Returns:
- the default target entity type
-
defaultCreator
protected java.util.function.Supplier<? extends Database.Type> defaultCreator()
Description copied from class:Item
Returns the default target entity creator. This method should be implemented by subclasses to specify the entity creator.- Specified by:
defaultCreator
in classItem<Database.Type>
- Returns:
- the default target entity creator
-
category
protected java.lang.Class<? extends Database> category()
Description copied from class:Item
Returns the target entity category. This method should be implemented by subclasses to specify the entity category.- Specified by:
category
in classItem<Database.Type>
- Returns:
- the target entity category
-
template
public Template<? extends Database.Type> template()
Description copied from class:Item
Returns the template to build the target entity.This method should ultimately be used to provide the final entity template. Although, it may also provide a partial template that subclassed may complement.
- Overrides:
template
in classItem<Database.Type>
- Returns:
- the matching entity template
-
-