Index: trunk/sources/HeuristicLab.Hive.Server.ADODataAccess/JobAdapter.cs
===================================================================
--- trunk/sources/HeuristicLab.Hive.Server.ADODataAccess/JobAdapter.cs	(revision 1449)
+++ trunk/sources/HeuristicLab.Hive.Server.ADODataAccess/JobAdapter.cs	(revision 1468)
@@ -28,16 +28,53 @@
 using System.Linq.Expressions;
 using HeuristicLab.DataAccess.ADOHelper;
+using HeuristicLab.Hive.Server.ADODataAccess.dsHiveServerTableAdapters;
+using System.Data.Common;
+using System.Data.SqlClient;
 
 namespace HeuristicLab.Hive.Server.ADODataAccess {
+  class JobAdapterWrapper :
+    DataAdapterWrapperBase<dsHiveServerTableAdapters.JobTableAdapter,
+                      Job,
+                      dsHiveServer.JobRow> {    
+    public override void UpdateRow(dsHiveServer.JobRow row) {
+      TransactionalAdapter.Update(row);
+    }
+
+    public override dsHiveServer.JobRow
+      InsertNewRow(Job job) {
+      dsHiveServer.JobDataTable data =
+        new dsHiveServer.JobDataTable();
+
+      dsHiveServer.JobRow row = data.NewJobRow();
+      row.JobId = job.Id;
+      data.AddJobRow(row);
+
+      return row;
+    }
+
+    public override IEnumerable<dsHiveServer.JobRow>
+      FindById(Guid id) {
+      return TransactionalAdapter.GetDataById(id);
+    }
+
+    public override IEnumerable<dsHiveServer.JobRow>
+      FindAll() {
+      return TransactionalAdapter.GetData();
+    }
+
+    protected override void SetConnection(DbConnection connection) {
+      adapter.Connection = connection as SqlConnection;
+    }
+
+    protected override void SetTransaction(DbTransaction transaction) {
+      adapter.Transaction = transaction as SqlTransaction;
+    }
+  }
+  
   class JobAdapter :
-    CachedDataAdapter<dsHiveServerTableAdapters.JobTableAdapter,
+    DataAdapterBase<dsHiveServerTableAdapters.JobTableAdapter,
                       Job, 
-                      dsHiveServer.JobRow, 
-                      dsHiveServer.JobDataTable>, 
+                      dsHiveServer.JobRow>, 
     IJobAdapter {
-    public JobAdapter() : 
-      base(ServiceLocator.GetDBSynchronizer()) {
-    }
-
     #region Fields
     private IClientAdapter clientAdapter = null;
@@ -46,5 +83,6 @@
       get {
         if (clientAdapter == null)
-          clientAdapter = ServiceLocator.GetClientAdapter();
+          clientAdapter = 
+            this.Session.GetDataAdapter<ClientInfo, IClientAdapter>();
 
         return clientAdapter;
@@ -57,5 +95,6 @@
       get {
         if (resultsAdapter == null) {
-          resultsAdapter = ServiceLocator.GetJobResultsAdapter();
+          resultsAdapter =
+            this.Session.GetDataAdapter<JobResult, IJobResultsAdapter>();
         }
 
@@ -64,4 +103,7 @@
     }
     #endregion
+
+    public JobAdapter(): base(new JobAdapterWrapper()) {
+    }
 
     #region Overrides
@@ -176,61 +218,4 @@
       return row;
     }
-
-    protected override void UpdateRow(dsHiveServer.JobRow row) {
-      Adapter.Update(row);
-    }
-
-    protected override dsHiveServer.JobRow 
-      InsertNewRow(Job job) {
-      dsHiveServer.JobDataTable data =
-        new dsHiveServer.JobDataTable();
-
-      dsHiveServer.JobRow row = data.NewJobRow();
-      row.JobId = job.Id;
-      data.AddJobRow(row);
-
-      return row;
-    }
-
-    protected override dsHiveServer.JobRow 
-      InsertNewRowInCache(Job job) {
-      dsHiveServer.JobRow row = cache.NewJobRow();
-      row.JobId = job.Id;
-      cache.AddJobRow(row);
-
-      return row;
-    }
-
-    protected override void FillCache() {
-      Adapter.FillByActive(cache);
-    }
-
-    protected override void SynchronizeWithDb() { 
-      this.Adapter.Update(cache);
-    }
-
-    protected override bool PutInCache(Job job) {
-      return job != null
-        && (job.State == State.calculating
-            || job.State == State.idle);
-    }
-
-    protected override IEnumerable<dsHiveServer.JobRow>
-      FindById(Guid id) {
-      return Adapter.GetDataById(id);
-    }
-
-    protected override dsHiveServer.JobRow
-      FindCachedById(Guid id) {
-      return cache.FindByJobId(id);
-    }
-
-    protected override IEnumerable<dsHiveServer.JobRow>
-      FindAll() {
-      return FindMultipleRows(
-        new Selector(Adapter.GetData),
-        new Selector(cache.AsEnumerable<dsHiveServer.JobRow>));
-    }
-
     #endregion
 
@@ -242,11 +227,4 @@
             delegate() {
               return Adapter.GetDataByParentJob(job.Id);
-            },
-            delegate() {
-              return from j in
-                   cache.AsEnumerable<dsHiveServer.JobRow>()
-                 where  !j.IsParentJobIdNull() && 
-                        j.ParentJobId == job.Id
-                 select j;
             });
       }
@@ -260,11 +238,4 @@
            delegate() {
              return Adapter.GetDataByState(state.ToString());
-           },
-           delegate() {
-             return from job in
-                      cache.AsEnumerable<dsHiveServer.JobRow>()
-                    where !job.IsJobStateNull() &&
-                           job.JobState == state.ToString()
-                    select job;
            });
     }
@@ -276,11 +247,4 @@
             delegate() {
               return Adapter.GetDataByClient(client.Id);
-            },
-            delegate() {
-              return from job in
-                 cache.AsEnumerable<dsHiveServer.JobRow>()
-               where !job.IsResourceIdNull() && 
-                      job.ResourceId == client.Id
-               select job;
             });
       }
@@ -296,13 +260,4 @@
             delegate() {
               return Adapter.GetDataByCalculatingClient(client.Id);
-            },
-            delegate() {
-              return from job in
-                       cache.AsEnumerable<dsHiveServer.JobRow>()
-                     where !job.IsResourceIdNull() &&
-                            job.ResourceId == client.Id && 
-                           !job.IsJobStateNull() && 
-                            job.JobState == "calculating"
-                     select job;
             });
       }
@@ -311,22 +266,13 @@
     }
 
-    public ICollection<Job> GetJobsOf(Guid userId) {
-      throw new NotImplementedException();  
-      
+    public ICollection<Job> GetJobsOf(Guid userId) {      
       return 
           base.FindMultiple(
             delegate() {
               return Adapter.GetDataByUser(userId);
-            },
-            delegate() {
-              return from job in
-                cache.AsEnumerable<dsHiveServer.JobRow>()
-              where !job.IsUserIdNull() &&
-                job.UserId == Guid.Empty
-              select job;
-            });
-    }
-
-    public override bool Delete(Job job) {
+            });
+    }
+
+    protected override bool doDelete(Job job) {
       if (job != null) {
         dsHiveServer.JobRow row =
@@ -342,5 +288,5 @@
           }
 
-          return base.Delete(job);
+          return base.doDelete(job);
         }
       }
