1
// DatabaseProperties.cs
3
// Copyright (C) 2008 Patrick Ulbrich
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.
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.
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/>.
20
// if other VolumeDBDataType types (Volume, VolumeItem...) overwrite Dispose(),
21
// DatabaseProperties must overwrite as well!
26
public sealed class DatabaseProperties : VolumeDBDataType
28
public const int MAX_NAME_LENGTH = 64;
29
public const int MAX_DESCRIPTION_LENGTH = 4096;
31
// table info required by VolumeDBDataType
32
private const string tableName = "DatabaseProperties";
33
private static readonly string[] primarykeyFields = null;
36
private string description;
37
private DateTime created;
41
private VolumeDatabase database;
43
internal DatabaseProperties(VolumeDatabase database) : base(tableName, primarykeyFields) {
45
this.description = null;
46
this.created = DateTime.MinValue;
50
this.database = database;
53
#region read-only properties
54
public DateTime Created {
55
get { return created; }
56
internal set { created = value; }
60
get { return version; }
61
internal set { version = value; }
66
internal set { guid = value; }
70
#region editable properties
72
get { return name ?? string.Empty; }
74
EnsurePropertyLength(value, MAX_NAME_LENGTH);
79
public string Description {
80
get { return description ?? string.Empty; }
82
EnsurePropertyLength(value, MAX_DESCRIPTION_LENGTH);
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"];
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);
104
internal override void InsertIntoDB() {
105
throw new NotSupportedException("This object supports updating only");
108
public override void UpdateChanges() {
109
if (database == null)
110
throw new InvalidOperationException("No database associated");
112
database.UpdateDBProperties(this);