Class Record
- All Implemented Interfaces:
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
ConstructorDescriptionRecord()
Creates a recordCreates a record with sourceClass typeCreates 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.Creates a record based on an entity -
Method Summary
Modifier and TypeMethodDescriptioncopy()
Creates a copy of the recordboolean
Determines if the record is equal with the specified object.fillDataObject
(Object dataObject) Fills the class with the Record's datafillDataObject
(Object dataObject, Map<String, Object> parents) Gets a collection of the names of every attributeGets 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.getDataObject
(Map<String, Object> parents) 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 attributegetOriginalValue
(String attrName) Gets the original value of an attribute.getOriginalValueAsBoolean
(String attrName) Gets the record attribute's value as aBoolean
getOriginalValueAsDate
(String attrName) Gets the record attribute's value as aDate
getOriginalValueAsDate
(String attrName, String format) Gets the record's original value of an attribute as aDate
.getOriginalValueAsDouble
(String attrName) Gets the record's original value of an attribute as aDouble
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.getOriginalValueAsFloat
(String attrName) Gets the record's original value of an attribute as aFloat
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.getOriginalValueAsInteger
(String attrName) Gets the record's original value of an attribute 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.getOriginalValueAsLong
(String attrName) Gets the record's original value of an attribute as aLong
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.getOriginalValueAsRecord
(String attrName) 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.getOriginalValueAsString
(String attrName) Gets the record's original value of an attribute as aString
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.Class<?>
Gets the Record's source classGets 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.getValueAsBoolean
(String attrName) Gets the record attribute's value as aBoolean
getValueAsDate
(String attrName) Gets the record attribute's value as aDate
getValueAsDate
(String attrName, String format) Gets the record attribute's value as aDate
getValueAsDouble
(String attrName) Gets the record attribute's value as aDouble
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.getValueAsFloat
(String attrName) Gets the record attribute's value as aFloat
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.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.getValueAsLong
(String attrName) Gets the record attribute's value as aLong
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.getValueAsNumber
(String attrName) Gets the record attribute's value as aNumber
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.getValueAsRecord
(String attrName) 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.getValueAsString
(String attrName) Gets the record attribute's value as aString
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
Determines if the specified attribute's value isnull
.boolean
isOriginalNull
(String attrName) Determines if the specified attribute's original value isnull
.Sets the value of a record attribute.void
Sets multiple values, using a MaptoString()
Returns a String representation of the Record
-
Constructor Details
-
Record
public Record()Creates a record -
Record
Creates a record with sourceClass type- Parameters:
sourceClass
- The class, where the data comes from
-
Record
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 fromdata
- The map containing the data. The map key is the field name, the value is the field value.
-
Record
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 thegetValueAsRecord
orgetOriginalValueAsRecord
methods.
-
-
Method Details
-
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
Fields containing a sub-record will be inserted as an entity into the new entity.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.- Returns:
- The created class, filled with the record's data
- Throws:
IllegalArgumentException
- If the class fields couldn't set their valueNullPointerException
- If the record didn't have a source class set
-
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
Fields containing a sub-record will be inserted as an entity into the new entity.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.- 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 valueNullPointerException
- If the record didn't have a source class set
-
fillDataObject
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
- Parameters:
dataObject
- The instance of the class, that will be filled with the record dataparents
- Parent entities already created when creating the new entity.- Returns:
- The filled class
-
getValue
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
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
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 isnull
or not found - Throws:
NumberFormatException
- If the attribute's value couldn't be converted to Integer
-
getOriginalValueAsInteger
Gets the record's original value of an attribute 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 original value as an integer or
null
if the original value isnull
or not found - Throws:
NumberFormatException
- If the attribute's value couldn't be converted
-
getValueAsLong
Gets the record attribute's value as aLong
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 isnull
or not found - Throws:
NumberFormatException
- If the attribute's value couldn't be converted
-
getValueAsNumber
Gets the record attribute's value as aNumber
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 isnull
or not found - Throws:
ParseException
- If the attribute's value couldn't be convertedNumberFormatException
- If the attribute's value couldn't be converted
-
getOriginalValueAsLong
Gets the record's original value of an attribute as aLong
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 isnull
or not found - Throws:
NumberFormatException
- If the attribute's value couldn't be converted
-
getValueAsFloat
Gets the record attribute's value as aFloat
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 isnull
or not found - Throws:
NumberFormatException
- If the attribute's value couldn't be converted
-
getOriginalValueAsFloat
Gets the record's original value of an attribute as aFloat
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 isnull
or not found - Throws:
NumberFormatException
- If the attribute's value couldn't be converted
-
getValueAsDouble
Gets the record attribute's value as aDouble
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 isnull
or not found - Throws:
NumberFormatException
- If the attribute's value couldn't be converted
-
getOriginalValueAsDouble
Gets the record's original value of an attribute as aDouble
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 isnull
or not found - Throws:
NumberFormatException
- If the attribute's value couldn't be converted
-
getValueAsDate
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 aParseException
.
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 isnull
or not found - Throws:
ParseException
- If the attribute value couldn't be interpreted as a Date
-
getOriginalValueAsDate
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 aParseException
.
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 isnull
or not found - Throws:
ParseException
- If the attribute value couldn't be interpreted as a Date
-
getValueAsDate
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 nameformat
- 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 isnull
or not found - Throws:
ParseException
- If the attribute value couldn't be interpreted as a Date
-
getOriginalValueAsDate
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 nameformat
- 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 isnull
or not found - Throws:
ParseException
- If the attribute value couldn't be interpreted as a Date
-
getValueAsString
Gets the record attribute's value as aString
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 isnull
or not found
-
getOriginalValueAsString
Gets the record's original value of an attribute as aString
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 isnull
or not found
-
getValueAsBoolean
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 isnull
or not found - See Also:
-
getOriginalValueAsBoolean
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 original value as a Boolean or
null
if the original value isnull
or not found - See Also:
-
getValueAsRecord
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 isnull
or not found - Throws:
ParseException
- If the attribute value was not set as a Record type
-
getOriginalValueAsRecord
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 isnull
or not found - Throws:
ParseException
- If the attribute original value was not set as a Record type
-
setValue
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 namevalue
- The new value of the attribute- Returns:
- The record
-
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
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
Determines if the specified attribute's value isnull
. An empty String is also considerednull
- Parameters:
attrName
- The name of the attribute- Returns:
true
if the specified attribute is not found, or if it is found, but isnull
or an empty String.
-
isOriginalNull
Determines if the specified attribute's original value isnull
. An empty String is also considerednull
- Parameters:
attrName
- The name of the attribute- Returns:
true
if the specified attribute is not found, or if it is found, but isnull
or an empty String.
-
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
Returns a String representation of the Record -
getSourceClass
Gets the Record's source class- Returns:
- The source class or
null
, if not found
-
setValues
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
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
- The object value is not
-
copy
Creates a copy of the record- Returns:
- A copy, which is a copy of the current Record
-