Free cookie consent management tool by TermsFeed Policy Generator

source: branches/CEDMA-Exporter-715/sources/HeuristicLab.Hive.Server.ADODataAccess/3.2/TableAdapterWrapper/JobAdapterWrapper.cs @ 2716

Last change on this file since 2716 was 2117, checked in by svonolfe, 15 years ago

Streaming of Jobs and JobsResults directly from/to the DB (#680)

File size: 2.2 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.DataAccess.ADOHelper;
6using System.Data.SqlClient;
7using HeuristicLab.Hive.Contracts.BusinessObjects;
8using System.Data.Common;
9using System.IO;
10using System.Data.SqlTypes;
11using System.Data;
12
13namespace HeuristicLab.Hive.Server.ADODataAccess.TableAdapterWrapper {
14  class JobAdapterWrapper :
15    TableAdapterWrapperBase<dsHiveServerTableAdapters.JobTableAdapter,
16                      Job,
17                      dsHiveServer.JobRow> {
18    public override void UpdateRow(dsHiveServer.JobRow row) {
19      TransactionalAdapter.Update(row);
20    }
21
22    public override dsHiveServer.JobRow
23      InsertNewRow(Job job) {
24      dsHiveServer.JobDataTable data =
25        new dsHiveServer.JobDataTable();
26
27      dsHiveServer.JobRow row = data.NewJobRow();
28      row.JobId = job.Id;
29      data.AddJobRow(row);
30
31      return row;
32    }
33
34    public override IEnumerable<dsHiveServer.JobRow>
35      FindById(Guid id) {
36      return TransactionalAdapter.GetDataById(id);
37    }
38
39    public override IEnumerable<dsHiveServer.JobRow>
40      FindAll() {
41      return TransactionalAdapter.GetData();
42    }
43
44    public Stream GetSerializedJobStream(Guid jobId,
45      bool useExistingConnection) {
46      SqlConnection connection = null;
47      SqlTransaction transaction = null;
48
49      if (useExistingConnection) {
50        connection =
51          base.Session.Connection as SqlConnection;
52
53        transaction =
54          adapter.Transaction;
55      } else {
56        connection =
57         ((SessionFactory)
58           (base.Session.Factory)).CreateConnection()
59           as SqlConnection;
60      }
61
62      VarBinarySource source =
63        new VarBinarySource(
64          connection, transaction,
65          "Job", "SerializedJob", "JobId", jobId);
66
67      return new VarBinaryStream(source);
68    }
69
70    protected override void SetConnection(DbConnection connection) {
71      adapter.Connection = connection as SqlConnection;
72    }
73
74    protected override void SetTransaction(DbTransaction transaction) {
75      adapter.Transaction = transaction as SqlTransaction;
76    }
77  }
78}
Note: See TracBrowser for help on using the repository browser.