Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.DataImporter/HeuristicLab.DataImporter.DataProcessor/Command/LoadColumnGroupsFromDBCommand.cs @ 12725

Last change on this file since 12725 was 9615, checked in by mkommend, 11 years ago

#1734: Updated copyright information in all DataImporter classes.

File size: 2.6 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System.Collections.Generic;
23using HeuristicLab.DataImporter.Data.CommandBase;
24using HeuristicLab.DataImporter.Data.Model;
25using HeuristicLab.DataImporter.DbExplorer.Interfaces;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27
28namespace HeuristicLab.DataImporter.DataProcessor.Command {
29  [StorableClass]
30  public class LoadColumnGroupsFromDBCommand : DatabaseCommandBase {
31    [Storable]
32    private List<DbTable> tables;
33
34    private List<ColumnGroup> newColumnGroups;
35
36    [StorableConstructor]
37    protected LoadColumnGroupsFromDBCommand(bool deserializing)
38      : base(deserializing) {
39      this.newColumnGroups = new List<ColumnGroup>();
40    }
41
42    public LoadColumnGroupsFromDBCommand(DataSet dataSet, IDbExplorer dbExplorer, IEnumerable<DbTable> tables)
43      : base(dataSet, dbExplorer) {
44      this.tables = new List<DbTable>(tables);
45      this.newColumnGroups = new List<ColumnGroup>();
46    }
47
48    public override string Description {
49      get { return "Load ColumnGroups from database"; }
50    }
51
52    public override void Execute() {
53      base.Execute();
54      if (DbExplorer == null || !DbExplorer.IsConnected)
55        throw new CommandExecutionException("Could not load data because no connection to the database exists", this);
56      ColumnGroup columnGroup;
57      foreach (DbTable table in tables) {
58        columnGroup = DbExplorer.CreateColumnGroup(table);
59        this.DataSet.AddColumnGroup(columnGroup);
60        newColumnGroups.Add(columnGroup);
61      }
62      this.DataSet.FireChanged();
63    }
64
65    public override void UndoExecute() {
66      base.UndoExecute();
67      foreach (ColumnGroup columnGroup in newColumnGroups)
68        this.DataSet.RemoveColumnGroup(columnGroup);
69      newColumnGroups.Clear();
70      this.DataSet.FireChanged();
71    }
72  }
73}
Note: See TracBrowser for help on using the repository browser.