org.javalite.activejdbc
Class MetaModel<T extends Model,E extends Association>

java.lang.Object
  extended by org.javalite.activejdbc.MetaModel<T,E>
All Implemented Interfaces:
Serializable

public class MetaModel<T extends Model,E extends Association>
extends Object
implements Serializable

See Also:
Serialized Form

Constructor Summary
protected MetaModel(String dbName, String tableName, String idName, Class<T> modelClass, String dbType, boolean cached, String idGeneratorCode)
           
 
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.
 E getAssociationForTarget(String target)
          Returns association of this table with the target table.
 E getAssociationForTarget(String target, Class<? extends Association> associationClass)
          Returns association of this table with the target table.
protected  List<Association> getAssociations()
           
 ArrayList<Association> getAssociationsForTarget(String target)
          Returns associations of this table with the target table.
protected  List<String> getAttributeNames()
          Retrieves all attribute names.
 List<String> getAttributeNamesSkip(String... names)
          Finds all attribute names except those provided as arguments.
 List<String> getAttributeNamesSkipGenerated()
          Finds all attribute names except generated like id, created_at, updated_at and record_version.
 List<String> getAttributeNamesSkipId()
          Finds all attribute names except for id.
 Map<String,ColumnMetadata> getColumnMetadata()
          Provides column metadata map, keyed by attribute names.
 String getDbName()
           
protected static String getDbName(Class<? extends Model> modelClass)
           
 String getDbType()
           
 DefaultDialect 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<T> getModelClass()
           
protected  List<OneToManyAssociation> getOneToManyAssociations(List<Association> exclusions)
           
protected  List<OneToManyPolymorphicAssociation> getPolymorphicAssociations(List<Association> exclusions)
           
 String getTableName()
           
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,
                    String tableName,
                    String idName,
                    Class<T> modelClass,
                    String dbType,
                    boolean cached,
                    String idGeneratorCode)
Method Detail

getIdGeneratorCode

public String getIdGeneratorCode()

getDbName

public String getDbName()

cached

public boolean cached()

getModelClass

public Class<T> getModelClass()

getTableName

public String getTableName()

tableExists

protected boolean tableExists()

getAttributeNamesSkipId

public List<String> getAttributeNamesSkipId()
Finds all attribute names except for id.

Returns:
all attribute names except for id.

getAttributeNamesSkipGenerated

public List<String> getAttributeNamesSkipGenerated()
Finds all attribute names except generated like id, created_at, updated_at and record_version.

Returns:
list of all attributes except id, created_at, updated_at and record_version.

getAttributeNamesSkip

public List<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 List<String> getAttributeNames()
Retrieves all attribute names.

Returns:
all attribute names.

getIdName

public String getIdName()

getAssociationForTarget

public E getAssociationForTarget(String target,
                                 Class<? extends Association> 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 E 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 ArrayList<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 DefaultDialect 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 © 2013. All Rights Reserved.