DAOFactory
recommended to create a directory that will be used only to place the DAO components.As mentioned before, all DAOs must extend dao.cfc; however they are required to override thefunction “initTableParams”. This function is used to programmatically describe the particularentity. That is, it describes the field names, their data types, the name of the entity in the storagemedium (i.e the table name), and the entity’s identity field.See the following sample code of a dao named PersonDAO.cfc
<cfcomponent extends="DAOFactory.dao.DAO">
<cffunction name="initTableParams" access="package" returntype="void">
<cfsetsetTableName("users")>
<cfsetsetPrimaryKey("userID","cf_sql_varchar")>
<cfsetaddColumn("firstName","cf_sql_varchar")>
<cfsetaddColumn("lastName","cf_sql_varchar")>
<cfsetaddColumn("email","cf_sql_varchar")>
</cffunction></cfcomponent>
The following table describes the methods used to describe the entity:
Method Description
setTableName Defines the name of the entity on the storage medium. For examplewhen storing the entity on the database, this would be the table name; orif using XML documents for storage, then this would be the file name ofthe XML document. Calling this method is required.
Arguments:Name:
(string, required) The name to use.setPrimaryKey Defines the field that is the identity field for the entity. DAOFactoryrequires that all entities have a unique identity field. Calling this methodis required.
Arguments:Name:
(string, required) the name of the field
Type:
(string, required) the datatype of the field using standard “cf_sql_*”naming convention.setLabelField Defines a field as being the “label” field for the entity. The use of this iscompletely optional and is only used when calling the getByLabel()method on the DAO. This is only provided as a quick way of locatingrecords for entities in which there is a field (other than the primary key)that can unique identify a record but in a human readable way (i.e. name,code, etc)
Arguments:
Page 2 of 6
Leave a Comment