Class StringHashLookupPojo<POJO extends StringHashLookupPojo<POJO>>

java.lang.Object
tenapull.data.entity.template.StringHashLookupPojo<POJO>
Type Parameters:
POJO - the type implementing StringHashLookupPojo
All Implemented Interfaces:
java.lang.Comparable<POJO>, DbPojo, HashLookupPojo<POJO>, StringLookupPojo<POJO>
Direct Known Subclasses:
Cpe, OperatingSystem, PluginDescription, PluginScriptCopyright, PluginSolution, PluginSynopsis, Remediation, ScanTargets

@MappedSuperclass
public abstract class StringHashLookupPojo<POJO extends StringHashLookupPojo<POJO>>
extends java.lang.Object
implements HashLookupPojo<POJO>, StringLookupPojo<POJO>
Abstract super class of all StringHashLookups. This is used for lookup tables that may have a string longer than 255 characters. Because longtext fields cannot be indexed by MySQL, we instead use a SHA-512 hash to index it with a 'unique' constraint.
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static java.lang.String FIELD_NAME
    The name of the field containing the lookup string
  • Constructor Summary

    Constructors 
    Constructor Description
    StringHashLookupPojo()  
  • Method Summary

    Modifier and Type Method Description
    boolean _isHashCalculated()
    Shortcut for the StringHashLookupDao to determine what approach to most efficiently use to find a matching value for this lookup.
    boolean _match​(POJO o)
    Determine if this pojo represents the same DB record as another POJO of the same type.
    void _prepare()
    Prepares this entity for saving/inserting into the DB
    void _set​(POJO other)
    Synchronize the values of two matching POJOs which represent the same DB record
    boolean equals​(java.lang.Object o)
    Returns true if and only if the compared object is of the same class and they share the same lookup value
    Hash get_hash()
    Generates the SHA-512 hash of the lookup value if it does not exist, or returns the already-existing hash if it does.
    int getId()
    Get the surrogate primary key id for the lookup
    java.lang.String getValue()
    Get the string lookup value this record represents
    int hashCode()
    Creates a java hashCode for use in a HashMap or HashSet
    void set_hash​(Hash hash)
    Sets the hash of the lookup after doing an immutability check.
    void setId​(int id)
    Set the surrogate primary key id for the lookup
    void setValue​(java.lang.String value)
    Sets the string lookup value this record represents, after doing an immutability check
    com.fasterxml.jackson.databind.JsonNode toJsonNode()
    Converts this lookup entity into a JSON TextNode
    java.lang.String toJsonString()
    Converts this lookup entity's value into a JSON-escaped String
    java.lang.String toString()  

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface tenapull.data.entity.template.HashLookupPojo

    compareTo
  • Field Details

  • Constructor Details

  • Method Details

    • getId

      public int getId()
      Get the surrogate primary key id for the lookup
      Specified by:
      getId in interface DbPojo
      Returns:
      the id
    • setId

      public void setId​(int id)
      Set the surrogate primary key id for the lookup
      Specified by:
      setId in interface DbPojo
      Parameters:
      id - the id
    • getValue

      public java.lang.String getValue()
      Get the string lookup value this record represents
      Specified by:
      getValue in interface StringLookupPojo<POJO extends StringHashLookupPojo<POJO>>
      Returns:
      the string lookup value
    • setValue

      public void setValue​(java.lang.String value) throws java.lang.IllegalStateException
      Sets the string lookup value this record represents, after doing an immutability check
      Specified by:
      setValue in interface StringLookupPojo<POJO extends StringHashLookupPojo<POJO>>
      Parameters:
      value - the string lookup value to set
      Throws:
      java.lang.IllegalStateException - if the _hash field has already been set and the value being set does not match a pre-existing value. These record are meant to be immutable in the DB once created, and the hash should always accurately reflect the hash of the string value
    • toJsonNode

      public com.fasterxml.jackson.databind.JsonNode toJsonNode()
      Converts this lookup entity into a JSON TextNode
      Specified by:
      toJsonNode in interface DbPojo
      Returns:
      a JSON TextNode representing the string value of this entity
    • toJsonString

      public java.lang.String toJsonString() throws com.fasterxml.jackson.core.JsonProcessingException
      Converts this lookup entity's value into a JSON-escaped String
      Specified by:
      toJsonString in interface DbPojo
      Returns:
      the lookup string value as a JSON-escaped String
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object
      Returns:
      the lookup value of this entity
    • equals

      public boolean equals​(java.lang.Object o)
      Returns true if and only if the compared object is of the same class and they share the same lookup value
      Overrides:
      equals in class java.lang.Object
      Parameters:
      o -
      Returns:
    • _prepare

      public void _prepare()
      Prepares this entity for saving/inserting into the DB
      Specified by:
      _prepare in interface DbPojo
    • hashCode

      public int hashCode()
      Creates a java hashCode for use in a HashMap or HashSet
      Overrides:
      hashCode in class java.lang.Object
      Returns:
    • get_hash

      public Hash get_hash()
      Generates the SHA-512 hash of the lookup value if it does not exist, or returns the already-existing hash if it does.
      Specified by:
      get_hash in interface HashLookupPojo<POJO extends StringHashLookupPojo<POJO>>
      Returns:
    • set_hash

      public void set_hash​(Hash hash) throws java.lang.IllegalStateException
      Sets the hash of the lookup after doing an immutability check.
      Specified by:
      set_hash in interface HashLookupPojo<POJO extends StringHashLookupPojo<POJO>>
      Parameters:
      hash -
      Throws:
      java.lang.IllegalStateException - if the _hash field has already been set and the hash being set does not match the pre-existing hash. These record are meant to be immutable in the DB once created, and the hash should always accurately reflect the hash of the string value
    • _isHashCalculated

      public boolean _isHashCalculated()
      Description copied from interface: HashLookupPojo
      Shortcut for the StringHashLookupDao to determine what approach to most efficiently use to find a matching value for this lookup. If the hash is already calculated, it is most efficient to use the hash. If it is not, it may be more efficient to use the _match method
      Specified by:
      _isHashCalculated in interface HashLookupPojo<POJO extends StringHashLookupPojo<POJO>>
      Returns:
      true if the hash has already been calculated, false if not
    • _set

      public void _set​(POJO other)
      Description copied from interface: HashLookupPojo
      Synchronize the values of two matching POJOs which represent the same DB record
      Specified by:
      _set in interface HashLookupPojo<POJO extends StringHashLookupPojo<POJO>>
      Parameters:
      other - the other pojo representing the same DB record, which the values should be taken from
    • _match

      public boolean _match​(POJO o)
      Description copied from interface: HashLookupPojo
      Determine if this pojo represents the same DB record as another POJO of the same type. Note that this is NOT the same as the equals() method (though it may be in certain cases). Equals may be used to determine if two pojos of the same type contain all of the same values, regardless of whether they represent the same DB record (depending on implementation) while _match determines only if they represent the same DB record even if some of the values may not be equivalent. In many cases the two methods may be the same, but their purpose is different.
      Specified by:
      _match in interface HashLookupPojo<POJO extends StringHashLookupPojo<POJO>>
      Parameters:
      o - other pojo to match
      Returns:
      true if the two pojos represent the same DB record, false if not