Class Instance

java.lang.Object
com.github.perdia.queries.Instance

public class Instance extends Object
Class for handling the creation, editing, querying, deletion and saving of instances
  • Constructor Details

    • Instance

      public Instance(String name)
      One of the constructors for the Instance class. This constructor creates a new instance with only the name defined. An empty instance created by this constructor has to be fully initialized by using either the createInstance or copyInstance methods later on.
      Parameters:
      name - The name of the instance
    • Instance

      public Instance(String name, Template tmp)
      One of the constructors for the Instance class. This constructor creates a new instance with a predefined template. The instance now has all the entries the template has and is ready to be read from or written to. This constructor essentially does the same as creating an empty instance with the other constructor which only requires a name and then also runs the createInstance method afterwards as well.
      Parameters:
      name - The name of the instance
      tmp - The template the instance is utilising
    • Instance

      public Instance(String name, Instance qo)
      One of the constructors for the Instance class. This constructor creates a new instance based on an already existing instance, copying it. The instance now has all the entries with their corresponding values and is ready to be read from or written to. This constructor essentially does the same as creating an empty instance with the other constructor which only requires a name and then also runs the copyInstance method afterwards as well.
      Parameters:
      name - The name of the instance
      qo - The instance to be copied from
  • Method Details

    • createInstance

      public String createInstance(Template tmp)
      Creates an instance in the database using a template. It returns a PANG query for creating an instance using a template.
      Parameters:
      tmp - The template to be used for the instance
      Returns:
      String containing PANG query for creating an instance using a template
    • copyInstance

      public String copyInstance(Instance qo)
      Creates an instance in the database using an already existing instance. It returns a PANG query for creating an instance using another instance, essentially copying it.
      Parameters:
      qo - The instance to be copied from
      Returns:
      String containing PANG query for creating an instance using another instance
    • setData

      public String setData(HashMap<String,DataEntry> hm)
      Method used for writing values to the entries of an instance using a hashmap. The hashmap gets checked for corresponding entries and the value assigned to them, replacing the value of the entry currently stored in the Instance object with the value from the given hashmap. If the given keys don't exist in the data entries of the Instance, nothing changes. It returns a PANG query for setting all the values that have been changed in the Instance object by this method to what they actually are.
      Parameters:
      hm - Hashmap the values are supposed to be copied form
      Returns:
      String containing PANG query setting all the changed values
    • setData

      public String setData(String key, DataEntry de)
      Method used for writing a single value to an entry of an instance. The data entries get checked for the corresponding key, replacing the value of the entry currently stored in the Instance object with the value from the given DataEntry. If the given key doesn't exist in the data entries of the Instance, nothing changes. It returns a PANG query for setting the value that has been changed in the Instance object by this method to what it actually is.
      Parameters:
      key - Key that is getting matched
      de - DataEntry to be written to the data entry with the corresponding key
      Returns:
      String containing PANG query setting the changed value
    • toQuery

      public String toQuery()
      Returns a PANG query for querying the respective instance in the database
      Returns:
      String containing PANG query for querying the respective instance
    • toQuery

      public static String toQuery(String name)
      Returns a PANG query for querying the given instance based on its name in the database
      Parameters:
      name - Name of the instance to be queried from the database
      Returns:
      String containing PANG query for querying the given instance based on its name
    • queryAll

      public static String queryAll()
      Returns a PANG query for querying all currently existing instances in the database
      Returns:
      String containing a PANG query for querying all existing instances
    • getName

      public String getName()
      Returns the name of the respective instance.
      Returns:
      The name of the instance
    • setName

      public void setName(String name)
      Sets the name of the respective instance.
      Parameters:
      name - The name of the instance to be set
    • getTemplate

      public Template getTemplate()
      Returns the template of the respective instance.
      Returns:
      The template of the instance
    • setTemplate

      public void setTemplate(Template tmp)
      Sets the template of the respective instance. WARNING: This deletes all the currently stored data, as it's dependent on what entries the template has.
      Parameters:
      tmp - The template of the instance to be set
    • getData

      public HashMap<String,DataEntry> getData()
      Returns the data entries of the respective instance all stored in a hashmap.
      Returns:
      Hashmap containing all the data entries of the instance
    • getDataEntry

      public DataEntry getDataEntry(String key)
      Returns the data entry with the given key of the respective instance.
      Parameters:
      key - Key of the DataEntry in the Instance object to be returned
      Returns:
      DataEntry corresponding to the key in the data Hashmap
    • deleteQuery

      public String deleteQuery()
      Returns a PANG query for deleting the respective instance in the database.
      Returns:
      String containing a PANG query for deleting the respective instance