Class DefaultDataSource
java.lang.Object
com.creativityfactory.swiftserver.persistence.DefaultDataSource
The DefaultDataSource class provides an API for persistence list objects of a class in JSON format, and also for reading and writing data.
It is a singleton class, and an instance can be obtained using the getInstance() method.
-
Method Summary
Modifier and TypeMethodDescriptionstatic DefaultDataSource
Returns an instance of the DefaultDataSource class.Loads the data from the JSON file corresponding to the specified model class.boolean
Saves the specified list of objects to the JSON file corresponding to the specified model class.
-
Method Details
-
getInstance
Returns an instance of the DefaultDataSource class.- Returns:
- an instance of the DefaultDataSource class
-
loadDB
Loads the data from the JSON file corresponding to the specified model class.- Parameters:
model
- the model class for which data is to be loaded- Returns:
- a list of objects of the specified model class, loaded from the corresponding JSON file
- Throws:
IOException
- if an I/O error occurs while reading the JSON file
-
saveDB
Saves the specified list of objects to the JSON file corresponding to the specified model class.- Parameters:
list
- the list of objects to be savedmodel
- the model class for which data is to be saved- Returns:
- true if the data was successfully saved to the corresponding JSON file, false otherwise
-