~ubuntu-branches/ubuntu/quantal/basenji/quantal

« back to all changes in this revision

Viewing changes to VolumeDB/src/DatabaseProperties.cs

  • Committer: Package Import Robot
  • Author(s): Patrick Ulbrich
  • Date: 2011-10-02 18:01:08 UTC
  • Revision ID: package-import@ubuntu.com-20111002180108-alcxkgmgv0oj7ipq
Tags: upstream-0.8.0
ImportĀ upstreamĀ versionĀ 0.8.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// DatabaseProperties.cs
 
2
// 
 
3
// Copyright (C) 2008 Patrick Ulbrich
 
4
//
 
5
// This program is free software: you can redistribute it and/or modify
 
6
// it under the terms of the GNU General Public License as published by
 
7
// the Free Software Foundation, either version 3 of the License, or
 
8
// (at your option) any later version.
 
9
//
 
10
// This program is distributed in the hope that it will be useful,
 
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
// GNU General Public License for more details.
 
14
//
 
15
// You should have received a copy of the GNU General Public License
 
16
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
17
//
 
18
 
 
19
// TODO : 
 
20
// if other VolumeDBDataType types (Volume, VolumeItem...) overwrite Dispose(),
 
21
// DatabaseProperties must overwrite as well!
 
22
using System;
 
23
 
 
24
namespace VolumeDB
 
25
{
 
26
        public sealed class DatabaseProperties : VolumeDBDataType
 
27
        {
 
28
                public const int MAX_NAME_LENGTH                = 64;
 
29
                public const int MAX_DESCRIPTION_LENGTH = 4096;
 
30
                
 
31
                // table info required by VolumeDBDataType
 
32
                private const                   string          tableName                       = "DatabaseProperties";
 
33
                private static readonly string[]        primarykeyFields        = null;
 
34
                
 
35
                private string                  name;
 
36
                private string                  description;
 
37
                private DateTime                created;
 
38
                private int                             version;
 
39
                private string                  guid;
 
40
                
 
41
                private VolumeDatabase  database;
 
42
                
 
43
                internal DatabaseProperties(VolumeDatabase database) : base(tableName, primarykeyFields) {
 
44
                        this.name                       = null;
 
45
                        this.description        = null;
 
46
                        this.created            = DateTime.MinValue;
 
47
                        this.version            = 0;
 
48
                        this.guid                       = null;
 
49
                        
 
50
                        this.database           = database;
 
51
                }
 
52
                
 
53
                #region read-only properties
 
54
                public DateTime Created {
 
55
                        get                             { return created; }
 
56
                        internal set    { created = value; }
 
57
                }
 
58
 
 
59
                public int Version {
 
60
                        get                             { return version; }
 
61
                        internal set    { version = value; }
 
62
                }
 
63
                
 
64
                public string Guid {
 
65
                        get                             { return guid; }
 
66
                        internal set    { guid = value; }
 
67
                }
 
68
                #endregion
 
69
 
 
70
                #region editable properties
 
71
                public string Name {
 
72
                        get { return name ?? string.Empty; }
 
73
                        set {
 
74
                                EnsurePropertyLength(value, MAX_NAME_LENGTH);
 
75
                                name = value;
 
76
                        }
 
77
                }
 
78
                
 
79
                public string Description {
 
80
                        get { return description ?? string.Empty; }
 
81
                        set {
 
82
                                EnsurePropertyLength(value, MAX_DESCRIPTION_LENGTH);
 
83
                                description = value;
 
84
                        }
 
85
                }
 
86
                #endregion
 
87
                
 
88
                internal override void ReadFromVolumeDBRecord(IRecordData recordData) {
 
89
                        name                    = Util.ReplaceDBNull<string>(   recordData["Name"], null);
 
90
                        description             = Util.ReplaceDBNull<string>(   recordData["Description"], null);
 
91
                        created                 = Util.ReplaceDBNull<DateTime>( recordData["Created"], DateTime.MinValue);
 
92
                        version                 = (int)(long)                                   recordData["Version"];
 
93
                        guid                    = (string)                                              recordData["GUID"];
 
94
                }
 
95
 
 
96
                internal override void WriteToVolumeDBRecord(IRecordData recordData) {
 
97
                        recordData.AddField("Name",                     name);
 
98
                        recordData.AddField("Description",      description);
 
99
                        recordData.AddField("Created",          created);
 
100
                        recordData.AddField("Version",          version);
 
101
                        recordData.AddField("GUID",                     guid);
 
102
                }
 
103
                
 
104
                internal override void InsertIntoDB() {
 
105
                        throw new NotSupportedException("This object supports updating only");
 
106
                }
 
107
 
 
108
                public override void UpdateChanges() {
 
109
                        if (database == null)
 
110
                                throw new InvalidOperationException("No database associated");
 
111
 
 
112
                        database.UpdateDBProperties(this);
 
113
                }
 
114
                
 
115
        }
 
116
}