Class DefaultDataSource

java.lang.Object
com.creativityfactory.swiftserver.persistence.DefaultDataSource

public class DefaultDataSource extends Object
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 Details

    • getInstance

      public static DefaultDataSource getInstance()
      Returns an instance of the DefaultDataSource class.
      Returns:
      an instance of the DefaultDataSource class
    • loadDB

      public List<Object> loadDB(Class<?> model) throws IOException
      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

      public boolean saveDB(List<Object> list, Class<?> model)
      Saves the specified list of objects to the JSON file corresponding to the specified model class.
      Parameters:
      list - the list of objects to be saved
      model - 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