Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Hive.Server.ADODataAccess/3.2/TableAdapterWrapper/JobResultsAdapterWrapper.cs @ 3099

Last change on this file since 3099 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
RevLine 
[1580]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;
[2117]9using System.IO;
[1580]10
11namespace HeuristicLab.Hive.Server.ADODataAccess.TableAdapterWrapper {
12  class JobResultsAdapterWrapper :
13    TableAdapterWrapperBase<dsHiveServerTableAdapters.JobResultTableAdapter,
14                    JobResult,
15                    dsHiveServer.JobResultRow> {
16    public override void UpdateRow(dsHiveServer.JobResultRow row) {
17      TransactionalAdapter.Update(row);
18    }
19
20    public override dsHiveServer.JobResultRow InsertNewRow(JobResult obj) {
21      dsHiveServer.JobResultDataTable data =
22        new dsHiveServer.JobResultDataTable();
23
24      dsHiveServer.JobResultRow row = data.NewJobResultRow();
25      row.JobResultId = obj.Id;
26      data.AddJobResultRow(row);
27
28      return row;
29    }
30
31    public override IEnumerable<dsHiveServer.JobResultRow> FindById(Guid id) {
32      return TransactionalAdapter.GetDataById(id);
33    }
34
35    public override IEnumerable<dsHiveServer.JobResultRow> FindAll() {
36      return TransactionalAdapter.GetData();
37    }
38
[2117]39    public Stream GetSerializedJobResultStream(Guid jobResultId,
40      bool useExistingConnection) {
41      SqlConnection connection = null;
42      SqlTransaction transaction = null;
[2099]43
[2117]44      if (useExistingConnection) {
45        connection =
46          base.Session.Connection as SqlConnection;
47
48        transaction =
49          adapter.Transaction;
50      } else {
51        connection =
52         ((SessionFactory)
53           (base.Session.Factory)).CreateConnection()
54           as SqlConnection;
55      }
56
57      VarBinarySource source =
58        new VarBinarySource(
59          connection, transaction,
60          "JobResult", "JobResult", "JobResultId", jobResultId);
61
62      return new VarBinaryStream(source);
[2099]63    }
64
[1580]65    protected override void SetConnection(DbConnection connection) {
66      adapter.Connection = connection as SqlConnection;
67    }
68
69    protected override void SetTransaction(DbTransaction transaction) {
70      adapter.Transaction = transaction as SqlTransaction;
71    }
72  }
73}
Note: See TracBrowser for help on using the repository browser.