Table data gateway pattern

From CSSEMediaWiki
(Difference between revisions)
Jump to: navigation, search
m (New page: = Table Gateway Pattern = ''' An object that acts as a Gateway to a database table. One instance handles all the rows in the table. ''' == How it works == A simple interface that directl...)
 
m
 
Line 1: Line 1:
= Table Gateway Pattern =
+
'' An object that acts as a Gateway to a database table. One instance handles all the rows in the table. ''
''' An object that acts as a Gateway to a database table. One instance handles all the rows in the table. '''
+
  
== How it works ==
+
= How it works =
 
A simple interface that directly maps onto the database. The class contains all the SQL to access the data from the database and simply return a RecordSet (or similar) of the data. The entire system is stateless, and any changes to the underlying database needs to be done with the Gateway class.
 
A simple interface that directly maps onto the database. The class contains all the SQL to access the data from the database and simply return a RecordSet (or similar) of the data. The entire system is stateless, and any changes to the underlying database needs to be done with the Gateway class.
  
== When to use it ==
+
= When to use it =
 
For very simple database access. ''Stored procedures themselves are often organized as Table Data Gateways''
 
For very simple database access. ''Stored procedures themselves are often organized as Table Data Gateways''
  
== Example ==
+
= Example =
class PersonGateway {
+
[[Image:table_data.png]]
 
+
find(id): RecordSet
+
 
+
findByLastName(String) : RecordSet
+
 
+
update(id, name, address, ...)
+
 
+
insert(name, address,...)
+
 
+
delete(id)
+
 
+
}
+

Latest revision as of 21:32, 17 October 2010

An object that acts as a Gateway to a database table. One instance handles all the rows in the table.

How it works

A simple interface that directly maps onto the database. The class contains all the SQL to access the data from the database and simply return a RecordSet (or similar) of the data. The entire system is stateless, and any changes to the underlying database needs to be done with the Gateway class.

When to use it

For very simple database access. Stored procedures themselves are often organized as Table Data Gateways

Example

Table data.png

Personal tools