Class Entity

All Implemented Interfaces:
Archivable, RMJSONArchiver.GetKeys, RMKey.Get, RMPropertyChanger, PropertyChangeListener, Cloneable, EventListener

This class represents an entity for a data source. It has a list of properties, some of which are simple attributes and some of which are relationships.
  • Field Details

  • Constructor Details

    • Entity

      public Entity()
      Creates an empty entity.
    • Entity

      public Entity(String aName)
      Creates an entity with the given name.
  • Method Details

    • getSchema

      public Schema getSchema()
      Returns the schema that owns this entity.
    • setSchema

      public void setSchema(Schema aSchema)
      Sets the schema that owns this entity.
    • getEntity

      public Entity getEntity(String aName)
      Returns a named entity using entity resolver.
    • getName

      public String getName()
      Returns the name of the entity.
    • setName

      public void setName(String aName)
      Sets the name of the entity.
    • getExists

      public boolean getExists()
      Returns whether entity exists in data source (has been saved and, if so, not deleted).
    • setExists

      public void setExists(boolean aFlag)
      Sets whether entity exists in data source (has been saved and, if so, not deleted).
    • getPropertyCount

      public int getPropertyCount()
      Returns the number of properties.
    • getProperty

      public Property getProperty(int anIndex)
      Returns the property at the given index.
    • getProperties

      public List<Property> getProperties()
      Returns the list of properties.
    • setProperties

      public void setProperties(List<Property> theProps)
      Sets a list of properties.
    • addProperty

      public void addProperty(Property aProperty)
      Adds a given property.
    • addProperty

      public void addProperty(Property aProperty, int anIndex)
      Adds a given property at given index.
    • addProperty

      public void addProperty(Property... theProperties)
      Adds given properties.
    • removeProperty

      public Object removeProperty(int anIndex)
      Removes a property at given index.
    • removeProperty

      public int removeProperty(Property aProperty)
      Removes the given property.
    • getProperty

      public Property getProperty(String aName)
      Returns the property with the given name.
    • getAttributeCount

      public int getAttributeCount()
      Returns the number of attributes.
    • getAttribute

      public Property getAttribute(int anIndex)
      Returns the attribute at the given index.
    • getAttribute

      public Property getAttribute(String aName)
      Returns the attribute with the given name.
    • getRelationCount

      public int getRelationCount()
      Returns the number of relations in the entity.
    • getRelation

      public Property getRelation(int anIndex)
      Returns the relation at the given index.
    • getRelations

      public List<Property> getRelations()
      Returns the list of relations in the entity.
    • getRelation

      public Property getRelation(String aName)
      Returns the relation for the given key path.
    • getAttributeSorted

      public Property getAttributeSorted(int anIndex)
      Returns the attribute at the given index in a sorted attributes list.
    • getRelationSorted

      public Property getRelationSorted(int anIndex)
      Returns the relation at the given index in the sorted list of relations.
    • getPrimary

      public Property getPrimary()
      Returns the primary key property.
    • getPrimaries

      public List<Property> getPrimaries()
      Returns the list of primary attributes for this entity.
    • getEntityClass

      public Class getEntityClass()
      Returns the class that this entity represents.
    • setEntityClass

      public void setEntityClass(Class aClass)
      Sets the class that this entity represents.
    • getKeyPathProperty

      public Property getKeyPathProperty(String aKeyPath)
      Returns the property with the given name.
    • getKeyValue

      public Object getKeyValue(String aKey)
      RMKey.Get implementation to return Property for key.
      Specified by:
      getKeyValue in interface RMKey.Get
    • getDescriptorKey

      public String getDescriptorKey()
      Returns the key/key-chain to the property(s) that returns best string description of an entity instance.
    • setDescriptorKey

      public void setDescriptorKey(String aValue)
      Sets the key/key-chain to the property(s) that returns best string description of an entity instance.
    • getDescriptorKeyGuess

      public String getDescriptorKeyGuess()
      Returns a guess of descriptor key (or the actual one, if set).
    • propertyChange

      public void propertyChange(PropertyChangeEvent anEvent)
      PropertyChangeListener implementation to forward property changes to entity property change listener.
      Specified by:
      propertyChange in interface PropertyChangeListener
    • equals

      public boolean equals(Object anObj)
      Standard equals method.
      Overrides:
      equals in class Object
    • clone

      public Entity clone()
      Standard clone implementation.
      Overrides:
      clone in class RMListenerList
    • toXML

      public RXElement toXML(RXArchiver anArchiver)
      XML archival.
      Specified by:
      toXML in interface Archivable
    • fromXML

      public Entity fromXML(RXArchiver anArchiver, RXElement anElement)
      XML unarchival.
      Specified by:
      fromXML in interface Archivable
    • toBytes

      @Nullable public byte[] toBytes()
      Returns bytes for this entity.
    • fromBytes

      public Entity fromBytes(byte[] theBytes) throws RMJSONReader.RMJSONException
      Returns entity from bytes.
      Throws:
      RMJSONReader.RMJSONException
    • save

      public void save() throws Exception
      Saves the entity to its source.
      Throws:
      Exception
    • delete

      public void delete() throws Exception
      Saves this entity from its source.
      Throws:
      Exception
    • getJSONKeys

      public List<String> getJSONKeys()
      Returns keys to archive JSON.
      Specified by:
      getJSONKeys in interface RMJSONArchiver.GetKeys
    • toString

      public String toString()
      Returns a string representation of entity (its name).
      Overrides:
      toString in class RMObject