Package org.javalite.activejdbc
Class MetaModel
java.lang.Object
org.javalite.activejdbc.MetaModel
- All Implemented Interfaces:
Serializable
- See Also:
- Serialized Form
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
addAssociation(Association association)
boolean
cached()
protected void
checkAttribute(String attribute)
Checks if this model has a named attribute that has the same name as argument.void
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>
getAssociationsForTarget(Class<? extends Model> targetModelClass)
Returns associations of this table with the target table.Retrieves all attribute names.getAttributeNamesSkip(String... names)
Finds all attribute names except those provided as arguments.Convenience method.getAttributeNamesSkipGenerated(boolean managed)
Finds all attribute names except managed likeid
,created_at
,updated_at
andrecord_version
, depending on argument.Finds all attribute names except for id.Provides column metadata map, keyed by attribute names.String[]
Returns optional composite primary key classprotected static String
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).protected List<Many2ManyAssociation>
getManyToManyAssociations(Association... excludedAssociations)
protected List<OneToManyAssociation>
getOneToManyAssociations(Association... excludedAssociations)
String[]
protected List<OneToManyPolymorphicAssociation>
getPolymorphicAssociations(Association... excludedAssociations)
Returns table name currently associated with this model.protected boolean
hasAssociation(Class<? extends Model> targetClass, Class<? extends Association> associationClass)
boolean
boolean
isAssociatedTo(Class<? extends Model> targetModelClass)
Checks if there is association to the target model class.,boolean
Returns true if this model supports optimistic locking, false if notvoid
removeAssociationForTarget(Class<? extends Model> modelClass)
void
void
setShardTableName(String tableName)
This feature is for sharding!
Do not use it to set table names willy-nilly!protected boolean
toString()
-
Constructor Details
-
MetaModel
-
-
Method Details
-
hasPartitionIDs
public boolean hasPartitionIDs() -
getPartitionIDs
-
setShardTableName
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 thisMetaModel
was initialized with during teh bootstrap phase. -
getVersionColumn
- Returns:
- name of the column for optimistic locking record version
-
getIdGeneratorCode
-
getDbName
-
cached
public boolean cached() -
getModelClass
-
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
Finds all attribute names except for id.- Returns:
- all attribute names except for id.
-
getAttributeNamesSkipGenerated
Convenience method. CallsgetAttributeNamesSkipGenerated(boolean)
and passestrue
as argument.- Returns:
- list of all attributes except id, created_at, updated_at and record_version.
-
getAttributeNamesSkipGenerated
Finds all attribute names except managed likeid
,created_at
,updated_at
andrecord_version
, depending on argument.- Parameters:
managed
- if true, time managed attributescreated_at
andupdated_at
will not be included (they are managed automatically). If false (not managed)created_at
andupdated_at
will be included in output.- Returns:
- list of all attributes except
id
,created_at
,updated_at
andrecord_version
, depending on argument.
-
getAttributeNamesSkip
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
Retrieves all attribute names.- Returns:
- all attribute names.
-
getIdName
-
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
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
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
-
hasAssociation
protected boolean hasAssociation(Class<? extends Model> targetClass, Class<? extends Association> associationClass) -
toString
-
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
-
getPolymorphicAssociations
protected List<OneToManyPolymorphicAssociation> getPolymorphicAssociations(Association... excludedAssociations) -
getManyToManyAssociations
protected List<Many2ManyAssociation> getManyToManyAssociations(Association... excludedAssociations) -
getDbType
-
getDialect
-
getAssociations
-
checkAttribute
Checks if this model has a named attribute that has the same name as argument. ThrowsIllegalArgumentException
in case it does not find it.- Parameters:
attribute
- name of attribute or association target.
-
getDbName
-
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
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
-
setFKName
-