Menu

[r4295]: / branches / parsnip / Src / Main / CS.Database.IO.Factory.pas  Maximize  Restore  History

Download this file

89 lines (69 with data), 2.5 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
{
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/
*
* Copyright (C) 2008-2013, Peter Johnson (www.delphidabbler.com).
*
* $Rev$
* $Date$
*
* Implements objects that can load data into the Database object from both the
* user and main databases. Also provides a class that can write the user
* database to storage.
*
* Uses file I/O interface implementations to read / write the physical files.
}
unit CS.Database.IO.Factory;
interface
uses
// Project
CS.Database.IO.Types,
UBaseObjects;
type
{
TDatabaseIOFactory:
Factory class that can create instances of writer and loader objects for the
Database object.
}
/// <summary>Factory class used to create database loader and writer objects
/// for use in loading and saving the snippets database.</summary>
TDatabaseIOFactory = class(TNoConstructObject)
public
/// <summary>Creates and returns an instance of a database loader object
/// that can be used to load the database.</summary>
/// <remarks>If a database in native format is present a loader for that
/// database is returned. If there is no native database then any legacy
/// XML format database is looked for and a loader for that is returned if
/// found. If there is no database present at all then a special "empty
/// database" loader is returned.</remarks>
class function CreateLoader: IDatabaseLoader;
/// <summary>Creates and returns an instance of a an object that can be
/// used to save the database.</summary>
/// <remarks>This method always returns an writer object that saves in
/// native format. No other output formats are supported.</remarks>
class function CreateWriter: IDatabaseWriter;
end;
implementation
uses
// Project
CS.Database.IO.Empty,
CS.Database.IO.Legacy,
CS.Database.IO.Native,
UAppInfo;
{ TDatabaseIOFactory }
class function TDatabaseIOFactory.CreateLoader: IDatabaseLoader;
begin
Result := TDBNativeReader.Create(TAppInfo.UserDataDir);
if Result.DatabaseExists then
Exit;
Result := TDBLegacyUserDBReader.Create(TAppInfo.UserDataDir);
if Result.DatabaseExists then
Exit;
Result := TEmptyDBReader.Create;
end;
class function TDatabaseIOFactory.CreateWriter: IDatabaseWriter;
begin
Result := TDBNativeWriter.Create(TAppInfo.UserDataDir);
end;
end.
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.