diff options
| author | mokhan <mokhan@da190166-9cfc-4ee1-ae03-434a172be219> | 2009-02-21 21:44:27 +0000 |
|---|---|---|
| committer | mokhan <mokhan@da190166-9cfc-4ee1-ae03-434a172be219> | 2009-02-21 21:44:27 +0000 |
| commit | 1dfdccb8118aeaa3cd844ac8de2a672c93312166 (patch) | |
| tree | 4b19e7f816ab1019f180a46b68572af4b66fe4bc /slips/src/app/Marina/DataAccess/DataMappers/DockDataMapper.cs | |
| parent | 42d66bcab8262c7b8b2452615df535e694a3ec1c (diff) | |
git-svn-id: http://svn.xp-dev.com/svn/mokhan-sait@2 da190166-9cfc-4ee1-ae03-434a172be219
Diffstat (limited to 'slips/src/app/Marina/DataAccess/DataMappers/DockDataMapper.cs')
| -rw-r--r-- | slips/src/app/Marina/DataAccess/DataMappers/DockDataMapper.cs | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/slips/src/app/Marina/DataAccess/DataMappers/DockDataMapper.cs b/slips/src/app/Marina/DataAccess/DataMappers/DockDataMapper.cs new file mode 100644 index 0000000..bf2ae13 --- /dev/null +++ b/slips/src/app/Marina/DataAccess/DataMappers/DockDataMapper.cs @@ -0,0 +1,54 @@ +using Marina.DataAccess.Builders;
+using Marina.DataAccess.Schemas;
+using Marina.Domain;
+using Marina.Domain.Interfaces;
+using Marina.Infrastructure.Container;
+
+namespace Marina.DataAccess.DataMappers {
+ public class DockDataMapper : IDockDataMapper {
+ public DockDataMapper() : this( Resolve.DependencyFor< IDatabaseGateway >( ) ) {}
+
+ public DockDataMapper( IDatabaseGateway gateway ) {
+ _gateway = gateway;
+ }
+
+ public IDock FindBy( long dockId ) {
+ return Map.From( _gateway.LoadRowUsing( Queries.SelectDockBy( dockId ) ) );
+ }
+
+ private readonly IDatabaseGateway _gateway;
+
+ private static class Queries {
+ public static IQuery SelectDockBy( long dockId ) {
+ return DatabaseSelect
+ .From( DockTable.TableName )
+ .AddColumn( DockTable.DockID )
+ .AddColumn( DockTable.DockName )
+ .AddColumn( DockTable.LocationId )
+ .AddColumn( DockTable.WaterService )
+ .AddColumn( DockTable.ElectricalService )
+ .AddColumn( LocationTable.Name )
+ .InnerJoinOn( LocationTable.ID, DockTable.LocationId )
+ .Where( DockTable.DockID, dockId ).Build( );
+ }
+ }
+
+ private class Map {
+ public static IDock From( IDatabaseRow row ) {
+ return new Dock(
+ row.From< long >( DockTable.DockID ),
+ row.From< string >( DockTable.DockName ),
+ new Location( row.From< string >( LocationTable.Name ) ),
+ GetEnabledUtilities( row )
+ );
+ }
+
+ private static IUtility GetEnabledUtilities( IDatabaseRow row ) {
+ return Utilities.For(
+ row.From< bool >( DockTable.WaterService ) ? Utilities.Water : null,
+ row.From< bool >( DockTable.ElectricalService ) ? Utilities.Electrical : null
+ );
+ }
+ }
+ }
+}
\ No newline at end of file |
