Class Record

java.lang.Object
com.jbstrap.core.dao.Record
All Implemented Interfaces:
Serializable

public class Record extends Object implements Serializable

A class representing a data record for the JBStrap framework

The Record class is a standard data record handling class, used by the JBStrap framework. The records can come from a database query, or they can be created through code. Any data can be stored, it could be relayed as a class, even as a parameter. Any entity or POJO class can be made into a record, or a new, empty one can be created that can be filled through code.

In the JBStrap framework every query gives a Record or a list of Records, and every database operation, or data handling component needs a Record as it's input. This means that there is a full compatibility between certain databases and data handling components

Since:
4.0
Author:
JBStrap
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a record
    Record(Class<?> sourceClass)
    Creates a record with sourceClass type
    Record(Class<?> sourceClass, Map<String,Object> data)
    Creates a record, based on the specified map
    If any of the fields contain a map, it will be converted into a record and inserted as a sub-record into the attribute.
    Record(Object dataObject)
    Creates a record based on an entity
  • Method Summary

    Modifier and Type
    Method
    Description
    Creates a copy of the record
    boolean
    Determines if the record is equal with the specified object.
    fillDataObject(Object dataObject)
    Fills the class with the Record's data
    fillDataObject(Object dataObject, Map<String,Object> parents)
     
    Gets a collection of the names of every attribute
    Gets the Record contents in a Map format
    Sub-records are inserted as maps in the map.
    Creates and returns the previously specified source class, according to the data contents of the Record.
    Creates and returns the previously specified source class, according to the data contents of the Record.
    Gets a collection of the original names of every attribute
    Gets the original value of an attribute.
    Gets the record attribute's value as aBoolean
    Gets the record attribute's value as a Date
    Gets the record's original value of an attribute as a Date.
    Gets the record's original value of an attribute as a Double
    If the attribute name contains one or more dot characters, records preceding the dots will be recursively retrieved from the current record until the attribute name contains a dot.
    Gets the record's original value of an attribute as a Float
    If the attribute name contains one or more dot characters, records preceding the dots will be recursively retrieved from the current record until the attribute name contains a dot.
    Gets the record's original value of an attribute as an Integer
    If the attribute name contains one or more dot characters, records preceding the dots will be recursively retrieved from the current record until the attribute name contains a dot.
    Gets the record's original value of an attribute as a Long
    If the attribute name contains one or more dot characters, records preceding the dots will be recursively retrieved from the current record until the attribute name contains a dot.
    Gets original value of one of the record's attribute's as a Record
    If the attribute name contains one or more dot characters, records preceding the dots will be recursively retrieved from the current record until the attribute name contains a dot.
    Gets the record's original value of an attribute as a String
    If the attribute name contains one or more dot characters, records preceding the dots will be recursively retrieved from the current record until the attribute name contains a dot.
    Gets the Record's source class
    getValue(String attrName)
    Gets record's value, using the attribute's name.
    If the attribute name contains one or more dot characters, records preceding the dots will be recursively retrieved from the current record until the attribute name contains a dot.
    Gets the record attribute's value as a Boolean
    Gets the record attribute's value as a Date
    getValueAsDate(String attrName, String format)
    Gets the record attribute's value as a Date
    Gets the record attribute's value as a Double
    If the attribute name contains one or more dot characters, records preceding the dots will be recursively retrieved from the current record until the attribute name contains a dot.
    Gets the record attribute's value as a Float
    If the attribute name contains one or more dot characters, records preceding the dots will be recursively retrieved from the current record until the attribute name contains a dot.
    Gets the record attribute's value as anInteger
    If the attribute name contains one or more dot characters, records preceding the dots will be recursively retrieved from the current record until the attribute name contains a dot.
    Gets the record attribute's value as a Long
    If the attribute name contains one or more dot characters, records preceding the dots will be recursively retrieved from the current record until the attribute name contains a dot.
    Gets the record attribute's value as a Number
    If the attribute name contains one or more dot characters, records preceding the dots will be recursively retrieved from the current record until the attribute name contains a dot.
    Gets one of the record's attribute value as a Record
    If the attribute name contains one or more dot characters, records preceding the dots will be recursively retrieved from the current record until the attribute name contains a dot.
    Gets the record attribute's value as a String
    If the attribute name contains one or more dot characters, records preceding the dots will be recursively retrieved from the current record until the attribute name contains a dot.
    boolean
    isNull(String attrName)
    Determines if the specified attribute's value is null.
    boolean
    Determines if the specified attribute's original value is null.
    setValue(String attrName, Object value)
    Sets the value of a record attribute.
    void
    Sets multiple values, using a Map
    Returns a String representation of the Record

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Record

      public Record()
      Creates a record
    • Record

      public Record(Class<?> sourceClass)
      Creates a record with sourceClass type
      Parameters:
      sourceClass - The class, where the data comes from
    • Record

      public Record(Class<?> sourceClass, Map<String,Object> data)
      Creates a record, based on the specified map
      If any of the fields contain a map, it will be converted into a record and inserted as a sub-record into the attribute.
      Parameters:
      sourceClass - The class, where the data comes from
      data - The map containing the data. The map key is the field name, the value is the field value.
    • Record

      public Record(Object dataObject)
      Creates a record based on an entity
      Parameters:
      dataObject - An instance of the class that contains the data. In the record, every value in the class will be moved to a field, that has the same type (ie, the values will keep their type). If the specified class, has sub-classes, those values will also be put in the Record as a sub-record. These values can be referenced in the record by using the '.' character (ie class.subclass). The entire sub-record can be by using the getValueAsRecord or getOriginalValueAsRecord methods.
  • Method Details

    • getDataObject

      public Object getDataObject()

      Creates and returns the previously specified source class, according to the data contents of the Record.

      The method fills out every field in the class, that also appears in the record. The field values, that do not exist in the record will be null.If there's a field in the record, that does not exist in the class, then those classes will be ignored during the operation.

      Fields containing a sub-record will be inserted as an entity into the new entity.
      Returns:
      The created class, filled with the record's data
      Throws:
      IllegalArgumentException - If the class fields couldn't set their value
      NullPointerException - If the record didn't have a source class set
    • getDataObject

      public Object getDataObject(Map<String,Object> parents)

      Creates and returns the previously specified source class, according to the data contents of the Record.

      The method fills out every field in the class, that also appears in the record. The field values, that do not exist in the record will be null.If there's a field in the record, that does not exist in the class, then those classes will be ignored during the operation.

      Fields containing a sub-record will be inserted as an entity into the new entity.
      Parameters:
      parents - Parent entities already created when creating the new entity.
      Returns:
      The created class, filled with the record's data
      Throws:
      IllegalArgumentException - If the class fields couldn't set their value
      NullPointerException - If the record didn't have a source class set
    • fillDataObject

      public Object fillDataObject(Object dataObject)

      Fills the class with the Record's data

      The process overwrites every field, that exists in the Record. Those that do not, will be ignored. If the record has a field, that doesn't exist in the specified class, then the field will be ignored during the process.

      Fields containing a sub-record will be inserted as an entity into the new entity.
      Parameters:
      dataObject - The instance of the class, that will be filled with the record data
      Returns:
      The filled class
    • fillDataObject

      public Object fillDataObject(Object dataObject, Map<String,Object> parents)
      Parameters:
      dataObject - The instance of the class, that will be filled with the record data
      parents - Parent entities already created when creating the new entity.
      Returns:
      The filled class
    • getValue

      public Object getValue(String attrName)
      Gets record's value, using the attribute's name.
      If the attribute name contains one or more dot characters, records preceding the dots will be recursively retrieved from the current record until the attribute name contains a dot. The value corresponding to the attribute name after the last dot is returned from the internal records. If any of the sub-records cannot be found, the value corresponding the attribute name will be retrieved.
      Parameters:
      attrName - Attribute name
      Returns:
      Attribute value with its original type intact
      Throws:
      ParseException - No internal record found identified by the attribute name containing a dot
    • getOriginalValue

      public Object getOriginalValue(String attrName)
      Gets the original value of an attribute. An original value is the value that the attribute got when the record was created (meaning it got the value from the original class, or map, and wasn't set by hand).
      If the attribute name contains one or more dot characters, records preceding the dots will be recursively retrieved from the current record until the attribute name contains a dot. The value corresponding to the attribute name after the last dot is returned from the internal records. If any of the sub-records cannot be found, the value corresponding the attribute name will be retrieved.
      Parameters:
      attrName - Attribute name
      Returns:
      Original attribute value with its original type intact
    • getValueAsInteger

      public Integer getValueAsInteger(String attrName)
      Gets the record attribute's value as anInteger
      If the attribute name contains one or more dot characters, records preceding the dots will be recursively retrieved from the current record until the attribute name contains a dot. The value corresponding to the attribute name after the last dot is returned from the internal records. If any of the sub-records cannot be found, the value corresponding the attribute name will be retrieved.
      Parameters:
      attrName - Attribute name
      Returns:
      The value in integer or null if the value is null or not found
      Throws:
      NumberFormatException - If the attribute's value couldn't be converted to Integer
    • getOriginalValueAsInteger

      public Integer getOriginalValueAsInteger(String attrName)
      Gets the record's original value of an attribute as an Integer
      If the attribute name contains one or more dot characters, records preceding the dots will be recursively retrieved from the current record until the attribute name contains a dot. The value corresponding to the attribute name after the last dot is returned from the internal records. If any of the sub-records cannot be found, the value corresponding the attribute name will be retrieved.
      Parameters:
      attrName - Attribute name
      Returns:
      The original value as an integer or null if the original value is null or not found
      Throws:
      NumberFormatException - If the attribute's value couldn't be converted
    • getValueAsLong

      public Long getValueAsLong(String attrName)
      Gets the record attribute's value as a Long
      If the attribute name contains one or more dot characters, records preceding the dots will be recursively retrieved from the current record until the attribute name contains a dot. The value corresponding to the attribute name after the last dot is returned from the internal records. If any of the sub-records cannot be found, the value corresponding the attribute name will be retrieved.
      Parameters:
      attrName - Attribute name
      Returns:
      The value as a link or null if the value is null or not found
      Throws:
      NumberFormatException - If the attribute's value couldn't be converted
    • getValueAsNumber

      public Number getValueAsNumber(String attrName) throws ParseException
      Gets the record attribute's value as a Number
      If the attribute name contains one or more dot characters, records preceding the dots will be recursively retrieved from the current record until the attribute name contains a dot. The value corresponding to the attribute name after the last dot is returned from the internal records. If any of the sub-records cannot be found, the value corresponding the attribute name will be retrieved.
      Parameters:
      attrName - Attribute name
      Returns:
      The value as a link or null if the value is null or not found
      Throws:
      ParseException - If the attribute's value couldn't be converted
      NumberFormatException - If the attribute's value couldn't be converted
    • getOriginalValueAsLong

      public Long getOriginalValueAsLong(String attrName)
      Gets the record's original value of an attribute as a Long
      If the attribute name contains one or more dot characters, records preceding the dots will be recursively retrieved from the current record until the attribute name contains a dot. The value corresponding to the attribute name after the last dot is returned from the internal records. If any of the sub-records cannot be found, the value corresponding the attribute name will be retrieved.
      Parameters:
      attrName - Attribute name
      Returns:
      The original value as a Long or null if the original value is null or not found
      Throws:
      NumberFormatException - If the attribute's value couldn't be converted
    • getValueAsFloat

      public Float getValueAsFloat(String attrName)
      Gets the record attribute's value as a Float
      If the attribute name contains one or more dot characters, records preceding the dots will be recursively retrieved from the current record until the attribute name contains a dot. The value corresponding to the attribute name after the last dot is returned from the internal records. If any of the sub-records cannot be found, the value corresponding the attribute name will be retrieved.
      Parameters:
      attrName - Attribute name
      Returns:
      The value as a Float or null if the value is null or not found
      Throws:
      NumberFormatException - If the attribute's value couldn't be converted
    • getOriginalValueAsFloat

      public Float getOriginalValueAsFloat(String attrName)
      Gets the record's original value of an attribute as a Float
      If the attribute name contains one or more dot characters, records preceding the dots will be recursively retrieved from the current record until the attribute name contains a dot. The value corresponding to the attribute name after the last dot is returned from the internal records. If any of the sub-records cannot be found, the value corresponding the attribute name will be retrieved.
      Parameters:
      attrName - Attribute name
      Returns:
      The original value as a Float or null if the original value is null or not found
      Throws:
      NumberFormatException - If the attribute's value couldn't be converted
    • getValueAsDouble

      public Double getValueAsDouble(String attrName)
      Gets the record attribute's value as a Double
      If the attribute name contains one or more dot characters, records preceding the dots will be recursively retrieved from the current record until the attribute name contains a dot. The value corresponding to the attribute name after the last dot is returned from the internal records. If any of the sub-records cannot be found, the value corresponding the attribute name will be retrieved.
      Parameters:
      attrName - Attribute name
      Returns:
      The value as a Double or null if the value is null or not found
      Throws:
      NumberFormatException - If the attribute's value couldn't be converted
    • getOriginalValueAsDouble

      public Double getOriginalValueAsDouble(String attrName)
      Gets the record's original value of an attribute as a Double
      If the attribute name contains one or more dot characters, records preceding the dots will be recursively retrieved from the current record until the attribute name contains a dot. The value corresponding to the attribute name after the last dot is returned from the internal records. If any of the sub-records cannot be found, the value corresponding the attribute name will be retrieved.
      Parameters:
      attrName - Attribute name
      Returns:
      The original value as a Double or null if the original value is null or not found
      Throws:
      NumberFormatException - If the attribute's value couldn't be converted
    • getValueAsDate

      public Date getValueAsDate(String attrName) throws ParseException

      Gets the record attribute's value as a Date

      If the value's formatting isn't in a Date format, then the method will try to interpret it, according to the DATETIME_FORMAT JBStrap parameter. If it's not applicable it will return with a ParseException.


      If the attribute name contains one or more dot characters, records preceding the dots will be recursively retrieved from the current record until the attribute name contains a dot. The value corresponding to the attribute name after the last dot is returned from the internal records. If any of the sub-records cannot be found, the value corresponding the attribute name will be retrieved.
      Parameters:
      attrName - Attribute name
      Returns:
      The value as a Date or null if the value is null or not found
      Throws:
      ParseException - If the attribute value couldn't be interpreted as a Date
    • getOriginalValueAsDate

      public Date getOriginalValueAsDate(String attrName) throws ParseException

      Gets the record attribute's value as a Date

      If the value's formatting isn't in a Date format, then the method will try to interpret it, according to the DATETIME_FORMAT JBStrap parameter. If it's not applicable it will return with a ParseException.


      If the attribute name contains one or more dot characters, records preceding the dots will be recursively retrieved from the current record until the attribute name contains a dot. The value corresponding to the attribute name after the last dot is returned from the internal records. If any of the sub-records cannot be found, the value corresponding the attribute name will be retrieved.
      Parameters:
      attrName - Attribute name
      Returns:
      The original value as a Date or null if the value is null or not found
      Throws:
      ParseException - If the attribute value couldn't be interpreted as a Date
    • getValueAsDate

      public Date getValueAsDate(String attrName, String format) throws ParseException

      Gets the record attribute's value as a Date

      If the value's formatting isn't in a Date format, then the formatting can be specified in the format parameter. If it's not applicable it will return with a ParseException error.


      If the attribute name contains one or more dot characters, records preceding the dots will be recursively retrieved from the current record until the attribute name contains a dot. The value corresponding to the attribute name after the last dot is returned from the internal records. If any of the sub-records cannot be found, the value corresponding the attribute name will be retrieved.
      Parameters:
      attrName - Attribute name
      format - The format, that the value will be interpreted in, if the value wasn't set in a Date format
      Returns:
      The value as a Date or null if the value is null or not found
      Throws:
      ParseException - If the attribute value couldn't be interpreted as a Date
    • getOriginalValueAsDate

      public Date getOriginalValueAsDate(String attrName, String format) throws ParseException

      Gets the record's original value of an attribute as a Date.

      If the value's formatting isn't in a Date format, then the formatting can be specified in the format parameter. If it's not applicable it will return with a ParseException error.


      If the attribute name contains one or more dot characters, records preceding the dots will be recursively retrieved from the current record until the attribute name contains a dot. The value corresponding to the attribute name after the last dot is returned from the internal records. If any of the sub-records cannot be found, the value corresponding the attribute name will be retrieved.
      Parameters:
      attrName - Attribute name
      format - The format, that the value will be interpreted in, if the value wasn't set in a Date format
      Returns:
      The original value as a Date or null if the value is null or not found
      Throws:
      ParseException - If the attribute value couldn't be interpreted as a Date
    • getValueAsString

      public String getValueAsString(String attrName)
      Gets the record attribute's value as a String
      If the attribute name contains one or more dot characters, records preceding the dots will be recursively retrieved from the current record until the attribute name contains a dot. The value corresponding to the attribute name after the last dot is returned from the internal records. If any of the sub-records cannot be found, the value corresponding the attribute name will be retrieved.
      Parameters:
      attrName - Attribute name
      Returns:
      The value as a String or null if the value is null or not found
    • getOriginalValueAsString

      public String getOriginalValueAsString(String attrName)
      Gets the record's original value of an attribute as a String
      If the attribute name contains one or more dot characters, records preceding the dots will be recursively retrieved from the current record until the attribute name contains a dot. The value corresponding to the attribute name after the last dot is returned from the internal records. If any of the sub-records cannot be found, the value corresponding the attribute name will be retrieved.
      Parameters:
      attrName - Attribute name
      Returns:
      The original value as a String or null if the original value is null or not found
    • getValueAsBoolean

      public Boolean getValueAsBoolean(String attrName)

      Gets the record attribute's value as a Boolean

      If the value is not a Boolean type, the method will try to convert it. The method will use the BooleanConverter class


      If the attribute name contains one or more dot characters, records preceding the dots will be recursively retrieved from the current record until the attribute name contains a dot. The value corresponding to the attribute name after the last dot is returned from the internal records. If any of the sub-records cannot be found, the value corresponding the attribute name will be retrieved.
      Parameters:
      attrName - Attribute name
      Returns:
      The value as a Boolean or null if the value is null or not found
      See Also:
    • getOriginalValueAsBoolean

      public Boolean getOriginalValueAsBoolean(String attrName)

      Gets the record attribute's value as aBoolean

      If the value is not a Boolean type, the method will try to convert it. The method will use the BooleanConverter class


      If the attribute name contains one or more dot characters, records preceding the dots will be recursively retrieved from the current record until the attribute name contains a dot. The value corresponding to the attribute name after the last dot is returned from the internal records. If any of the sub-records cannot be found, the value corresponding the attribute name will be retrieved.
      Parameters:
      attrName - Attribute name
      Returns:
      The original value as a Boolean or null if the original value is null or not found
      See Also:
    • getValueAsRecord

      public Record getValueAsRecord(String attrName) throws ParseException
      Gets one of the record's attribute value as a Record
      If the attribute name contains one or more dot characters, records preceding the dots will be recursively retrieved from the current record until the attribute name contains a dot. The value corresponding to the attribute name after the last dot is returned from the internal records. If any of the sub-records cannot be found, the value corresponding the attribute name will be retrieved.
      Parameters:
      attrName - Attribute name
      Returns:
      The value as a Record or null if the value is null or not found
      Throws:
      ParseException - If the attribute value was not set as a Record type
    • getOriginalValueAsRecord

      public Record getOriginalValueAsRecord(String attrName) throws ParseException
      Gets original value of one of the record's attribute's as a Record
      If the attribute name contains one or more dot characters, records preceding the dots will be recursively retrieved from the current record until the attribute name contains a dot. The value corresponding to the attribute name after the last dot is returned from the internal records. If any of the sub-records cannot be found, the value corresponding the attribute name will be retrieved.
      Parameters:
      attrName - Attribute name
      Returns:
      The original value as a Record or null if the original value is null or not found
      Throws:
      ParseException - If the attribute original value was not set as a Record type
    • setValue

      public Record setValue(String attrName, Object value)
      Sets the value of a record attribute. If it has been previously set, it will be overwritten. If the record didn't include the specified attribute, it will be added to the Record.
      If the attribute name contains a dot, the value is set in the specific sub-record based on the sub-records separated by dots. If any of the sub-records cannot be found, the attribute name containing the dots will be used to set the value in the record until which sub-records were successfully retrieved.
      Parameters:
      attrName - Attribute name
      value - The new value of the attribute
      Returns:
      The record
    • getAttributes

      public Collection<String> getAttributes()
      Gets a collection of the names of every attribute
      Returns:
      The name of every attribute. If the record doesn't contain any (ie the record is empty), it will return with an empty collection
    • getOriginalAttributes

      public Collection<String> getOriginalAttributes()
      Gets a collection of the original names of every attribute
      Returns:
      The name of every attribute. If the record doesn't contain any (ie the record is empty or it was created using a Map), it will return with an empty collection
    • isNull

      public boolean isNull(String attrName)
      Determines if the specified attribute's value is null. An empty String is also considered null
      Parameters:
      attrName - The name of the attribute
      Returns:
      true if the specified attribute is not found, or if it is found, but is null or an empty String.
    • isOriginalNull

      public boolean isOriginalNull(String attrName)
      Determines if the specified attribute's original value is null. An empty String is also considered null
      Parameters:
      attrName - The name of the attribute
      Returns:
      true if the specified attribute is not found, or if it is found, but is null or an empty String.
    • getDataMap

      public Map<String,Object> getDataMap()
      Gets the Record contents in a Map format
      Sub-records are inserted as maps in the map.
      Returns:
      The record in a Map format. The map key is the attribute name, the value will be the attribute value If the record doesn't contain any values, it will return with an empty map
    • toString

      public String toString()
      Returns a String representation of the Record
      Overrides:
      toString in class Object
    • getSourceClass

      public Class<?> getSourceClass()
      Gets the Record's source class
      Returns:
      The source class or null, if not found
    • setValues

      public void setValues(Map<String,Object> dataMap)

      Sets multiple values, using a Map

      If the specified Map contains an attribute, that already exists in the record, then the already existing value will be overwritten. If it contains an attribute, which didn't exist in the record, it will be added to it.

      If there is a map within the map, it will be inserted as a sub-record into the record.
      Parameters:
      dataMap - The map of values to be added. The Map is the attribute name, the value is the new value.
    • equals

      public boolean equals(Object obj)

      Determines if the record is equal with the specified object.

      They are considered equal if:

      • The object value is not null
      • The object is a Record, or a descendant of one
      • The specified record's attributes have the same cardinality as the Record
      • Every one of the specified record's attribute values are the same, as the Record's values of the attributes that have the same name

      Overrides:
      equals in class Object
    • copy

      public Record copy()
      Creates a copy of the record
      Returns:
      A copy, which is a copy of the current Record