org.javalite.activejdbc
Class MetaModel

java.lang.Object
  extended by org.javalite.activejdbc.MetaModel
All Implemented Interfaces:
Serializable

public class MetaModel
extends Object
implements Serializable

See Also:
Serialized Form

Constructor Summary
protected MetaModel(String dbName, Class<? extends Model> modelClass, String dbType)
           
 
Method Summary
protected  void addAssociation(Association association)
           
 boolean cached()
           
protected  void checkAttributeOrAssociation(String attributeOrAssociation)
          Checks if this model has a named attribute or association whose target has the same name as argument.
<A extends Association>
A
getAssociationForTarget(String target)
          Returns association of this table with the target table.
<A extends Association>
A
getAssociationForTarget(String target, Class<A> associationClass)
          Returns association of this table with the target table.
protected  List<Association> getAssociations()
           
 List<Association> getAssociationsForTarget(String target)
          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 like id, created_at, updated_at and record_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 class
 String getDbName()
           
protected static String getDbName(Class<? extends Model> modelClass)
           
 String getDbType()
           
 Dialect getDialect()
           
 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).
 String getIdGeneratorCode()
           
 String getIdName()
           
protected  List<Many2ManyAssociation> getManyToManyAssociations(List<Association> excludedAssociations)
           
 Class<? extends Model> getModelClass()
           
protected  List<OneToManyAssociation> getOneToManyAssociations(List<Association> exclusions)
           
protected  List<OneToManyPolymorphicAssociation> getPolymorphicAssociations(List<Association> exclusions)
           
 String getTableName()
           
 String getVersionColumn()
           
protected  boolean hasAssociation(String table, Class<? extends Association> associationClass)
           
 boolean isAssociatedTo(Class<? extends Model> targetModelClass)
          Checks if there is association to the target model class.,
 boolean isVersioned()
          Returns true if this model supports optimistic locking, false if not
protected  boolean tableExists()
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MetaModel

protected MetaModel(String dbName,
                    Class<? extends Model> modelClass,
                    String dbType)
Method Detail

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()

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(String target,
                                                         Class<A> associationClass)
Returns association of this table with the target table. Will return null if there is no association.

Parameters:
target - association of this table and the target table.
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(String target)
Returns association of this table with the target table. Will return null if there is no association.

Parameters:
target - association of this table and the target table.
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(String target)
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:
target - association of this table and the target table.
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(String table,
                                 Class<? extends Association> associationClass)

toString

public String toString()
Overrides:
toString in class Object

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.

getOneToManyAssociations

protected List<OneToManyAssociation> getOneToManyAssociations(List<Association> exclusions)

getPolymorphicAssociations

protected List<OneToManyPolymorphicAssociation> getPolymorphicAssociations(List<Association> exclusions)

getManyToManyAssociations

protected List<Many2ManyAssociation> getManyToManyAssociations(List<Association> excludedAssociations)

getDbType

public String getDbType()

getDialect

public Dialect getDialect()

getAssociations

protected List<Association> getAssociations()

checkAttributeOrAssociation

protected void checkAttributeOrAssociation(String attributeOrAssociation)
Checks if this model has a named attribute or association whose target has the same name as argument. Throws IllegalArgumentException in case it does not find either one.

Parameters:
attributeOrAssociation - 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.


Copyright © 2015 JavaLite. All rights reserved.