Package com.github.perdia.queries
Class Instance
java.lang.Object
com.github.perdia.queries.Instance
Class for handling the creation, editing, querying, deletion and saving of instances
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptioncopyInstance
(Instance qo) Creates an instance in the database using an already existing instance.createInstance
(Template tmp) Creates an instance in the database using a template.Returns a PANG query for deleting the respective instance in the database.getData()
Returns the data entries of the respective instance all stored in a hashmap.getDataEntry
(String key) Returns the data entry with the given key of the respective instance.getName()
Returns the name of the respective instance.Returns the template of the respective instance.static String
queryAll()
Returns a PANG query for querying all currently existing instances in the databaseMethod used for writing a single value to an entry of an instance.Method used for writing values to the entries of an instance using a hashmap.void
Sets the name of the respective instance.void
setTemplate
(Template tmp) Sets the template of the respective instance.toQuery()
Returns a PANG query for querying the respective instance in the databasestatic String
Returns a PANG query for querying the given instance based on its name in the database
-
Constructor Details
-
Instance
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
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 instancetmp
- The template the instance is utilising
-
Instance
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 instanceqo
- The instance to be copied from
-
-
Method Details
-
createInstance
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
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
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
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 matchedde
- DataEntry to be written to the data entry with the corresponding key- Returns:
- String containing PANG query setting the changed value
-
toQuery
Returns a PANG query for querying the respective instance in the database- Returns:
- String containing PANG query for querying the respective instance
-
toQuery
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
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
Returns the name of the respective instance.- Returns:
- The name of the instance
-
setName
Sets the name of the respective instance.- Parameters:
name
- The name of the instance to be set
-
getTemplate
Returns the template of the respective instance.- Returns:
- The template of the instance
-
setTemplate
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
Returns the data entries of the respective instance all stored in a hashmap.- Returns:
- Hashmap containing all the data entries of the instance
-
getDataEntry
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
Returns a PANG query for deleting the respective instance in the database.- Returns:
- String containing a PANG query for deleting the respective instance
-