Class MetaModel

    • Constructor Detail

    • Method Detail

      • hasPartitionIDs

        public boolean hasPartitionIDs()
      • getPartitionIDs

        public String[] getPartitionIDs()
      • setShardTableName

        public void setShardTableName​(String tableName)

        This feature is for sharding!
        Do not use it to set table names willy-nilly!

        Sets a table name for this model. The table name is attached to a current thread and will remain there until it is set with a different value or cleared with clearShardTableName() method. Table name set with this method overrides a table name naturally mapped to this model.

        Method getTableName() will return this value for all operations related to this table.

        Parameters:
        tableName - name of a table this model will read from current thread.
      • clearShardTableName

        public void clearShardTableName()
        Clears sharding name of table attached to current thread. The name was supposedly attached by the setShardTableName(String) method. After execution of this class, the method getTableName() will be returning the value this MetaModel was initialized with during teh bootstrap phase.
      • getVersionColumn

        public String getVersionColumn()
        Returns:
        name of the column for optimistic locking record version
      • getIdGeneratorCode

        public String getIdGeneratorCode()
      • getDbName

        public String getDbName()
      • cached

        public boolean cached()
      • getModelClass

        public Class<? extends Model> getModelClass()
      • getTableName

        public String getTableName()
        Returns table name currently associated with this model. Table name can be modified for sharding using setShardTableName(String)
        Returns:
        table name currently associated with this model.
      • tableExists

        protected boolean tableExists()
      • getAttributeNamesSkipId

        public Set<String> getAttributeNamesSkipId()
        Finds all attribute names except for id.
        Returns:
        all attribute names except for id.
      • getAttributeNamesSkipGenerated

        public Set<String> getAttributeNamesSkipGenerated()
        Convenience method. Calls getAttributeNamesSkipGenerated(boolean) and passes true as argument.
        Returns:
        list of all attributes except id, created_at, updated_at and record_version.
      • getAttributeNamesSkipGenerated

        public Set<String> getAttributeNamesSkipGenerated​(boolean managed)
        Finds all attribute names except managed like id, created_at, updated_at and record_version, depending on argument.
        Parameters:
        managed - if true, time managed attributes created_at and updated_at will not be included (they are managed automatically). If false (not managed) created_at and updated_at will be included in output.
        Returns:
        list of all attributes except id, created_at, updated_at and record_version, depending on argument.
      • getAttributeNamesSkip

        public Set<String> getAttributeNamesSkip​(String... names)
        Finds all attribute names except those provided as arguments.
        Returns:
        list of all attributes except those provided as arguments.
      • isVersioned

        public boolean isVersioned()
        Returns true if this model supports optimistic locking, false if not
        Returns:
        true if this model supports optimistic locking, false if not
      • getAttributeNames

        protected Set<String> getAttributeNames()
        Retrieves all attribute names.
        Returns:
        all attribute names.
      • getIdName

        public String getIdName()
      • getCompositeKeys

        public String[] getCompositeKeys()
        Returns optional composite primary key class
        Returns:
        composite primary key class
      • getAssociationForTarget

        public <A extends Association> A getAssociationForTarget​(Class<? extends Model> targetModelClass,
                                                                 Class<A> associationClass)
        Returns association of this table with the target table. Will return null if there is no association.
        Parameters:
        targetModelClass - association of this model and the target model.
        associationClass - class of association in requested.
        Returns:
        association of this table with the target table. Will return null if there is no association with target table and specified type.
      • getAssociationForTarget

        public <A extends Association> A getAssociationForTarget​(Class<? extends Model> targetClass)
        Returns association of this table with the target table. Will return null if there is no association.
        Parameters:
        targetClass - association of this model and the target model.
        Returns:
        association of this table with the target table. Will return null if there is no association with target table and specified type.
      • getAssociationsForTarget

        public List<Association> getAssociationsForTarget​(Class<? extends Model> targetModelClass)
        Returns associations of this table with the target table. It is possible to have more than one association to a target table if a target table is the same as source. Usually this happens when tree structures are stored in the same table (category has many categories).
        Parameters:
        targetModelClass - association of this model and the target model.
        Returns:
        list of associations of this table with the target table. Will return empty list if none found. table and specified type.
      • addAssociation

        protected void addAssociation​(Association association)
      • hasAssociation

        protected boolean hasAssociation​(Class<? extends Model> targetClass,
                                         Class<? extends Association> associationClass)
      • getFKName

        public String getFKName()
        FK name is a foreign key name used in relationships as a foreign key column in a child table (table represented by this instance is a parent table). The FK name is derived using Inflector: It is a singular version of this table name plus "_id".
        Returns:
        foreign key name used in relationships as a foreign key column in a child table.
      • getDbType

        public String getDbType()
      • getDialect

        public Dialect getDialect()
      • checkAttribute

        protected void checkAttribute​(String attribute)
        Checks if this model has a named attribute that has the same name as argument. Throws IllegalArgumentException in case it does not find it.
        Parameters:
        attribute - name of attribute or association target.
      • getDbName

        protected static String getDbName​(Class<? extends Model> modelClass)
      • getColumnMetadata

        public Map<String,​ColumnMetadata> getColumnMetadata()
        Provides column metadata map, keyed by attribute names. Table columns correspond to ActiveJDBC model attributes.
        Returns:
        Provides column metadata map, keyed by attribute names.
      • isAssociatedTo

        public boolean isAssociatedTo​(Class<? extends Model> targetModelClass)
        Checks if there is association to the target model class.,
        Parameters:
        targetModelClass - class of a model that will be checked for association from current model.
        Returns:
        true if any association exists such that the current model is a source and targetModelClass is a target.
      • removeAssociationForTarget

        public void removeAssociationForTarget​(Class<? extends Model> modelClass)
      • setFKName

        public void setFKName​(String fkName)