$Id: dataset_mapper.html,v 1.4 2004/12/16 06:02:30 george Exp $
To Be Continued...
Abstract: Using dataset as data holder and implement data mapper pattern.
I have to appologize first whether this pattern will be implement or not is still unknown. I have no idea that How to implement UoW and session level cache using DataSet.
Data Mapper pattern is important in Martin Fowler's greatest book. In his book, he mentioned that implementing Data Mapper pattern using DataSet( ADO.NET ).Key consideration
- How to store data in the mapper?
We need to cache the domain object which get from the database, so next time we want to get the same object, we dont need to get it from database and we can use the same object in the system which won't be .
Where to put the cache?
- a. in mapper's data member?
-
will be shared in all threads in the same process.
- b. in application session cache?
- Using DataSet in Mapper as the dataset holder
- a. How to select data into the dataset holder?
- b. How to update, delete and insert data into database for persistence.
8 namespace com.ds.mapper 9 { 10 /// <summary> 11 /// from martin's excellent work. 12 /// </summary> 13 public class DataSetHolder 14 { 15 public DataSet Data = new DataSet(); 16 17 private Hashtable DataAdapters = new Hashtable(); 18 19 public void FillData( string query, string tableName ) 20 { 21 if ( DataAdapters.Contains( tableName ) ) 22 { 23 throw new MutlipleLoadException(); 24 } 25 26 OleDbDataAdapter da = new OleDbDataAdapter( query, DB.connection ); 27 OleDbCommandBuilder builder = new OleDbCommandBuilder( da ); 28 da.Fill( Data, tableName ); 29 DataAdapters.Add( tableName, da ); 30 } 31 32 /// <summary> 33 /// UNDO: dont need delete method in DataSet??? 34 /// </summary> 35 public void Update() 36 { 37 foreach ( string table in DataAdapters.Keys ) 38 { 39 ( ( OleDbDataAdapter )DataAdapters[ table ] ).Update( Data, table ); 40 } 41 } 42 43 /// <summary> 44 /// Index for tables. 45 /// </summary> 46 public DataTable this[ string tableName ] 47 { 48 get{return Data.Tables[ tableName ];} 49 } 50 } 51 }
- Table must has primary key and the prmiary key must be in the select clause.
- use Select clause to select each table at a time, should not select multiple table in one select clause, then we cann't join table in sql which would cause some performance issue.
-
- Unit of Work