| Package: machii_info_sample.model.category |
| I abstract data access for Categories |
| Method Summary | |
|---|---|
| public categorydao | init(string dsn) |
| public void |
create()
CRUD method |
| public void |
delete(category category)
CRUD method |
| public void |
read(category category, numeric categoryID)
CRUD method |
| public void |
update(category category)
CRUD method |
| Method Detail |
|---|
| create |
|---|
public void create( )
CRUD method
Parameters:
Code:
<cffunction name="create" returntype="void" output="false" hint="CRUD method"> <cfabort showerror="categoryDAO.create - This Method is Abstract and needs to be overridden"> </cffunction>
| delete |
|---|
public void delete( category category )
CRUD method
Parameters:
| category category |
Code:
<cffunction name="delete" returntype="void" output="false" hint="CRUD method"> <cfargument name="category" type="category" required="true" /> <cfset categoryDelete = 0 > <cfquery name="categoryDelete" datasource="#variables.dsn#" > DELETE FROM categories WHERE categoryID = <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#arguments.category.getCategoryID()#" > </cfquery> </cffunction>
| init |
|---|
public categorydao init( string dsn )
Parameters:
| string dsn |
Code:
<cffunction name="init" access="public" returntype="machii_info_sample.model.category.categorydao" output="false" > <cfargument name="dsn" type="string" required="true" /> <cfset variables.dsn = arguments.dsn /> <cfreturn this /> </cffunction>
| read |
|---|
public void read( category category, numeric categoryID )
CRUD method
Parameters:
| category category |
| numeric categoryID |
Code:
<cffunction name="read" access="public" returntype="void" output="false" hint="CRUD method"> <cfargument name="category" type="machii_info_sample.model.category.category" required="yes" displayname="read" hint="I am the category object into which data is read." /> <cfargument name="categoryID" type="numeric" required="true" hint="I am the ID of the database record to read." /> <cfset var categorySelect = 0 /> <cfset var memento = structNew() /> <cfquery name="categorySelect" datasource="#variables.dsn#"> SELECT * FROM categories WHERE categoryid = <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#arguments.categoryid#" > </cfquery> <cfif categorySelect.recordCount > <cfscript> arguments.category.setCategoryID(categorySelect.categoryID); arguments.category.setName(categorySelect.name); arguments.category.setSortOrder(categorySelect.sortOrder); </cfscript> <cfelse> <cfthrow message="categoryID #arguments.categoryID# not found" type="category" detail="" errorcode="category.categoryNotFound" extendedinfo="" > </cfif> </cffunction>
| update |
|---|
public void update( category category )
CRUD method
Parameters:
| category category |
Code:
<cffunction name="update" returntype="void" output="false" hint="CRUD method"> <cfargument name="category" type="category" required="true" /> <cfset categoryUpdate = 0 > <cfquery name="categoryUpdate" datasource="#variables.dsn#" > UPDATE categories SET name = '#trim(arguments.category.getName())#', sortOrder = <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#arguments.category.getSortOrder()#" > WHERE categoryID = <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#arguments.category.getCategoryID()#" > </cfquery> </cffunction>