Package org.javalite.activejdbc
Class MetaModel
- java.lang.Object
-
- org.javalite.activejdbc.MetaModel
-
- All Implemented Interfaces:
Serializable
public class MetaModel extends Object implements Serializable
- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddAssociation(Association association)booleancached()protected voidcheckAttribute(String attribute)Checks if this model has a named attribute that has the same name as argument.voidclearShardTableName()Clears sharding name of table attached to current thread.<A extends Association>
AgetAssociationForTarget(Class<? extends Model> targetClass)Returns association of this table with the target table.<A extends Association>
AgetAssociationForTarget(Class<? extends Model> targetModelClass, Class<A> associationClass)Returns association of this table with the target table.protected List<Association>getAssociations()List<Association>getAssociationsForTarget(Class<? extends Model> targetModelClass)Returns associations of this table with the target table.protected Set<String>getAttributeNames()Retrieves all attribute names.Set<String>getAttributeNamesSkip(String... names)Finds all attribute names except those provided as arguments.Set<String>getAttributeNamesSkipGenerated()Convenience method.Set<String>getAttributeNamesSkipGenerated(boolean managed)Finds all attribute names except managed likeid,created_at,updated_atandrecord_version, depending on argument.Set<String>getAttributeNamesSkipId()Finds all attribute names except for id.Map<String,ColumnMetadata>getColumnMetadata()Provides column metadata map, keyed by attribute names.String[]getCompositeKeys()Returns optional composite primary key classStringgetDbName()protected static StringgetDbName(Class<? extends Model> modelClass)StringgetDbType()DialectgetDialect()StringgetFKName()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).StringgetIdGeneratorCode()StringgetIdName()protected List<Many2ManyAssociation>getManyToManyAssociations(Association... excludedAssociations)Class<? extends Model>getModelClass()protected List<OneToManyAssociation>getOneToManyAssociations(Association... excludedAssociations)String[]getPartitionIDs()protected List<OneToManyPolymorphicAssociation>getPolymorphicAssociations(Association... excludedAssociations)StringgetTableName()Returns table name currently associated with this model.StringgetVersionColumn()protected booleanhasAssociation(Class<? extends Model> targetClass, Class<? extends Association> associationClass)booleanhasPartitionIDs()booleanisAssociatedTo(Class<? extends Model> targetModelClass)Checks if there is association to the target model class.,booleanisVersioned()Returns true if this model supports optimistic locking, false if notvoidremoveAssociationForTarget(Class<? extends Model> modelClass)voidsetFKName(String fkName)voidsetShardTableName(String tableName)This feature is for sharding!
Do not use it to set table names willy-nilly!protected booleantableExists()StringtoString()
-
-
-
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 thesetShardTableName(String)method. After execution of this class, the methodgetTableName()will be returning the value thisMetaModelwas 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()
-
getTableName
public String getTableName()
Returns table name currently associated with this model. Table name can be modified for sharding usingsetShardTableName(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. CallsgetAttributeNamesSkipGenerated(boolean)and passestrueas 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 likeid,created_at,updated_atandrecord_version, depending on argument.- Parameters:
managed- if true, time managed attributescreated_atandupdated_atwill not be included (they are managed automatically). If false (not managed)created_atandupdated_atwill be included in output.- Returns:
- list of all attributes except
id,created_at,updated_atandrecord_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 usingInflector: 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.
-
getOneToManyAssociations
protected List<OneToManyAssociation> getOneToManyAssociations(Association... excludedAssociations)
-
getPolymorphicAssociations
protected List<OneToManyPolymorphicAssociation> getPolymorphicAssociations(Association... excludedAssociations)
-
getManyToManyAssociations
protected List<Many2ManyAssociation> getManyToManyAssociations(Association... excludedAssociations)
-
getDbType
public String getDbType()
-
getDialect
public Dialect getDialect()
-
getAssociations
protected List<Association> getAssociations()
-
checkAttribute
protected void checkAttribute(String attribute)
Checks if this model has a named attribute that has the same name as argument. ThrowsIllegalArgumentExceptionin case it does not find it.- Parameters:
attribute- name of attribute or association target.
-
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)
-
-