/
PersistenceAction.cs
212 lines (193 loc) · 6.49 KB
/
PersistenceAction.cs
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/*
// <copyright>
// dotNetRDF is free and open source software licensed under the MIT License
// -------------------------------------------------------------------------
//
// Copyright (c) 2009-2023 dotNetRDF Project (http://dotnetrdf.org/)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is furnished
// to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
*/
using System;
namespace VDS.RDF
{
/// <summary>
/// Represents a Triple that is queued for persistence (either insertion/deletion).
/// </summary>
public class TriplePersistenceAction
{
/// <summary>
/// Creates a new Triple Persistence Action (an insertion/deletion).
/// </summary>
/// <param name="t">Triple to persist.</param>
/// <param name="graphName">The name of the modified graph.</param>
/// <param name="toDelete">Whether the Triple is to be deleted.</param>
public TriplePersistenceAction(Triple t, IRefNode graphName, bool toDelete)
{
Triple = t ?? throw new ArgumentNullException(nameof(t));
Graph = graphName;
IsDelete = toDelete;
}
/// <summary>
/// Creates a new Triple Persistence Action (an insertion).
/// </summary>
/// <param name="t">Triple to persist.</param>
/// <param name="graphName">The name of the modified graph.</param>
public TriplePersistenceAction(Triple t, IRefNode graphName)
: this(t, graphName, false) { }
/// <summary>
/// Gets the Triple to persist.
/// </summary>
public Triple Triple { get; }
/// <summary>
/// Gets the name of the graph modified by this action.
/// </summary>
public IRefNode Graph { get; }
/// <summary>
/// Gets whether the action is a Delete Action.
/// </summary>
public bool IsDelete { get; }
}
/// <summary>
/// Possible Types of Graph Persistence Actions.
/// </summary>
public enum GraphPersistenceActionType
{
/// <summary>
/// Graph was Added
/// </summary>
Added,
/// <summary>
/// Graph was Deleted
/// </summary>
Deleted,
/// <summary>
/// Graph was Modified
/// </summary>
Modified,
}
/// <summary>
/// Represents a Graph that is queued for persistence (added/modified/removed).
/// </summary>
public class GraphPersistenceAction
{
private ITransactionalGraph _g;
private GraphPersistenceActionType _action;
/// <summary>
/// Creates a new Graph Persistence action.
/// </summary>
/// <param name="g">Graph.</param>
/// <param name="action">Action Type.</param>
public GraphPersistenceAction(IGraph g, GraphPersistenceActionType action)
: this(new GraphPersistenceWrapper(g), action) { }
/// <summary>
/// Creates a new Graph Persistence action.
/// </summary>
/// <param name="g">Graph.</param>
/// <param name="action">Action Type.</param>
public GraphPersistenceAction(ITransactionalGraph g, GraphPersistenceActionType action)
{
_g = g;
_action = action;
}
/// <summary>
/// Gets the Graph to be persisted.
/// </summary>
public ITransactionalGraph Graph
{
get
{
return _g;
}
}
/// <summary>
/// Gets the Action Type.
/// </summary>
public GraphPersistenceActionType Action
{
get
{
return _action;
}
}
}
/// <summary>
/// Represents an action on a Triple Store that is queued for persistence.
/// </summary>
public class TripleStorePersistenceAction
{
private GraphPersistenceAction _graphAction;
private TriplePersistenceAction _tripleAction;
/// <summary>
/// Creates a new persistence action that pertains to a Graph.
/// </summary>
/// <param name="graphAction">Graph Action.</param>
public TripleStorePersistenceAction(GraphPersistenceAction graphAction)
{
_graphAction = graphAction;
}
/// <summary>
/// Creates a new persistence action that pertains to a Triple.
/// </summary>
/// <param name="tripleAction">Triple Action.</param>
public TripleStorePersistenceAction(TriplePersistenceAction tripleAction)
{
_tripleAction = tripleAction;
}
/// <summary>
/// Gets whether this action pertains to a Graph.
/// </summary>
public bool IsGraphAction
{
get
{
return _graphAction != null;
}
}
/// <summary>
/// Gets whether this action peratins to a Triple.
/// </summary>
public bool IsTripleAction
{
get
{
return _tripleAction != null;
}
}
/// <summary>
/// Gets the Graph Action (if any).
/// </summary>
public GraphPersistenceAction GraphAction
{
get
{
return _graphAction;
}
}
/// <summary>
/// Gets the Triple Action (if any).
/// </summary>
public TriplePersistenceAction TripleAction
{
get
{
return _tripleAction;
}
}
}
}