Gateways and Mappers are general patterns for hiding differences in data representation between two collaborating systems.
The idea of a table gateway is to provide a gateway class for each database table.
Here's a Java sketch of the find method in the CustomerGateway class:
class CustomerGateway extends Gateway {
CustomerRecordSet find(Customer c) {
CustomerRecordSet result = new CustomerRecordSet();
String query = "select * from customer
where ";
if (c.ID != null) {
query += ("customerID =
" + c.getID());
} else {
// use c to add conditions to
query
}
ResultSet res = execute(sql);
// for each row in res add a customer object to
result
return result;
}
// etc.
}
A JDBC Gateway can be found in Gateway.java