Class DefaultPersistence
java.lang.Object
com.creativityfactory.swiftserver.persistence.DefaultPersistence
- All Implemented Interfaces:
Persistence<Object>
Default implementation of the
Persistence
interface that provides
default implementation for the CRUD operations using a DefaultDataSource instance.
This implementation is based on the default data source specified by the
DataSource
annotation on the model class.
The class uses a file database to store and retrieve data. It assumes that
each entity has an ID field annotated with the Id
annotation. If the
ID field is not present, the first field in the entity will be used as the ID.
-
Constructor Summary
ConstructorDescriptionDefaultPersistence
(Class<?> model, DefaultDataSource api) Constructs a new DefaultPersistence instance with the given model class and API. -
Method Summary
Modifier and TypeMethodDescriptionDelete the specified object in the data store if it already exists.getAll()
Returns a list of all objects of the specified model type.Returns the object with the specified ID of the specified model type, or null if it does not exist.Returns a list of objects of the specified model type, up to the given limit.Saves the specified object in the data store if it does not already exist.Updates the specified object in the data store if it already exists.
-
Constructor Details
-
DefaultPersistence
Constructs a new DefaultPersistence instance with the given model class and API.- Parameters:
model
- the class of the model to be persisted.api
- the API to be used for persistence operations.
-
-
Method Details
-
getAll
Returns a list of all objects of the specified model type.- Specified by:
getAll
in interfacePersistence<Object>
- Returns:
- a list of all objects of the specified model type, or null if an exception occurs.
-
getLimit
Returns a list of objects of the specified model type, up to the given limit.- Specified by:
getLimit
in interfacePersistence<Object>
- Parameters:
limit
- the maximum number of objects to return.- Returns:
- a list of up to 'limit' objects of the specified model type, or null if an exception occurs.
-
getById
Returns the object with the specified ID of the specified model type, or null if it does not exist.- Specified by:
getById
in interfacePersistence<Object>
- Parameters:
id
- the ID of the object to be returned.- Returns:
- the object with the specified ID of the specified model type, or null if it does not exist.
-
save
Saves the specified object in the data store if it does not already exist.- Specified by:
save
in interfacePersistence<Object>
- Parameters:
o
- the object to be saved.- Returns:
- the saved object if the operation is successful, or null if it already exists or an exception occurs.
-
update
Updates the specified object in the data store if it already exists.- Specified by:
update
in interfacePersistence<Object>
- Parameters:
o
- the object to be updated.- Returns:
- the updated object if the operation is successful, or null if it does not exist or an exception occurs.
-
delete
Delete the specified object in the data store if it already exists.- Specified by:
delete
in interfacePersistence<Object>
- Parameters:
o
- the object to be deleted.- Returns:
- the deleted object if the operation is successful, or null if it does not exist or an exception occurs.
-