~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric

« back to all changes in this revision

Viewing changes to contrib/NGit/NGit/ObjectDatabase.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2011-06-27 17:03:13 UTC
  • mto: (1.8.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 54.
  • Revision ID: james.westby@ubuntu.com-20110627170313-6cvz3s19x6e9hqe9
ImportĀ upstreamĀ versionĀ 2.5.92+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
This code is derived from jgit (http://eclipse.org/jgit).
 
3
Copyright owners are documented in jgit's IP log.
 
4
 
 
5
This program and the accompanying materials are made available
 
6
under the terms of the Eclipse Distribution License v1.0 which
 
7
accompanies this distribution, is reproduced below, and is
 
8
available at http://www.eclipse.org/org/documents/edl-v10.php
 
9
 
 
10
All rights reserved.
 
11
 
 
12
Redistribution and use in source and binary forms, with or
 
13
without modification, are permitted provided that the following
 
14
conditions are met:
 
15
 
 
16
- Redistributions of source code must retain the above copyright
 
17
  notice, this list of conditions and the following disclaimer.
 
18
 
 
19
- Redistributions in binary form must reproduce the above
 
20
  copyright notice, this list of conditions and the following
 
21
  disclaimer in the documentation and/or other materials provided
 
22
  with the distribution.
 
23
 
 
24
- Neither the name of the Eclipse Foundation, Inc. nor the
 
25
  names of its contributors may be used to endorse or promote
 
26
  products derived from this software without specific prior
 
27
  written permission.
 
28
 
 
29
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
 
30
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
 
31
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 
32
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 
33
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 
34
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 
35
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 
36
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 
37
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 
38
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 
39
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 
40
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 
41
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
42
*/
 
43
 
 
44
using NGit;
 
45
using Sharpen;
 
46
 
 
47
namespace NGit
 
48
{
 
49
        /// <summary>Abstraction of arbitrary object storage.</summary>
 
50
        /// <remarks>
 
51
        /// Abstraction of arbitrary object storage.
 
52
        /// <p>
 
53
        /// An object database stores one or more Git objects, indexed by their unique
 
54
        /// <see cref="ObjectId">ObjectId</see>
 
55
        /// .
 
56
        /// </remarks>
 
57
        public abstract class ObjectDatabase
 
58
        {
 
59
                /// <summary>Initialize a new database instance for access.</summary>
 
60
                /// <remarks>Initialize a new database instance for access.</remarks>
 
61
                public ObjectDatabase()
 
62
                {
 
63
                }
 
64
 
 
65
                // Protected to force extension.
 
66
                /// <summary>Does this database exist yet?</summary>
 
67
                /// <returns>
 
68
                /// true if this database is already created; false if the caller
 
69
                /// should invoke
 
70
                /// <see cref="Create()">Create()</see>
 
71
                /// to create this database location.
 
72
                /// </returns>
 
73
                public virtual bool Exists()
 
74
                {
 
75
                        return true;
 
76
                }
 
77
 
 
78
                /// <summary>Initialize a new object database at this location.</summary>
 
79
                /// <remarks>Initialize a new object database at this location.</remarks>
 
80
                /// <exception cref="System.IO.IOException">the database could not be created.</exception>
 
81
                public virtual void Create()
 
82
                {
 
83
                }
 
84
 
 
85
                // Assume no action is required.
 
86
                /// <summary>
 
87
                /// Create a new
 
88
                /// <code>ObjectInserter</code>
 
89
                /// to insert new objects.
 
90
                /// <p>
 
91
                /// The returned inserter is not itself thread-safe, but multiple concurrent
 
92
                /// inserter instances created from the same
 
93
                /// <code>ObjectDatabase</code>
 
94
                /// must be
 
95
                /// thread-safe.
 
96
                /// </summary>
 
97
                /// <returns>writer the caller can use to create objects in this database.</returns>
 
98
                public abstract ObjectInserter NewInserter();
 
99
 
 
100
                /// <summary>
 
101
                /// Create a new
 
102
                /// <code>ObjectReader</code>
 
103
                /// to read existing objects.
 
104
                /// <p>
 
105
                /// The returned reader is not itself thread-safe, but multiple concurrent
 
106
                /// reader instances created from the same
 
107
                /// <code>ObjectDatabase</code>
 
108
                /// must be
 
109
                /// thread-safe.
 
110
                /// </summary>
 
111
                /// <returns>reader the caller can use to load objects from this database.</returns>
 
112
                public abstract ObjectReader NewReader();
 
113
 
 
114
                /// <summary>Close any resources held by this database.</summary>
 
115
                /// <remarks>Close any resources held by this database.</remarks>
 
116
                public abstract void Close();
 
117
 
 
118
                /// <summary>
 
119
                /// Does the requested object exist in this database?
 
120
                /// <p>
 
121
                /// This is a one-shot call interface which may be faster than allocating a
 
122
                /// <see cref="NewReader()">NewReader()</see>
 
123
                /// to perform the lookup.
 
124
                /// </summary>
 
125
                /// <param name="objectId">identity of the object to test for existence of.</param>
 
126
                /// <returns>true if the specified object is stored in this database.</returns>
 
127
                /// <exception cref="System.IO.IOException">the object store cannot be accessed.</exception>
 
128
                public virtual bool Has(AnyObjectId objectId)
 
129
                {
 
130
                        ObjectReader or = NewReader();
 
131
                        try
 
132
                        {
 
133
                                return or.Has(objectId);
 
134
                        }
 
135
                        finally
 
136
                        {
 
137
                                or.Release();
 
138
                        }
 
139
                }
 
140
 
 
141
                /// <summary>Open an object from this database.</summary>
 
142
                /// <remarks>
 
143
                /// Open an object from this database.
 
144
                /// <p>
 
145
                /// This is a one-shot call interface which may be faster than allocating a
 
146
                /// <see cref="NewReader()">NewReader()</see>
 
147
                /// to perform the lookup.
 
148
                /// </remarks>
 
149
                /// <param name="objectId">identity of the object to open.</param>
 
150
                /// <returns>
 
151
                /// a
 
152
                /// <see cref="ObjectLoader">ObjectLoader</see>
 
153
                /// for accessing the object.
 
154
                /// </returns>
 
155
                /// <exception cref="NGit.Errors.MissingObjectException">the object does not exist.</exception>
 
156
                /// <exception cref="System.IO.IOException">the object store cannot be accessed.</exception>
 
157
                public virtual ObjectLoader Open(AnyObjectId objectId)
 
158
                {
 
159
                        return Open(objectId, ObjectReader.OBJ_ANY);
 
160
                }
 
161
 
 
162
                /// <summary>Open an object from this database.</summary>
 
163
                /// <remarks>
 
164
                /// Open an object from this database.
 
165
                /// <p>
 
166
                /// This is a one-shot call interface which may be faster than allocating a
 
167
                /// <see cref="NewReader()">NewReader()</see>
 
168
                /// to perform the lookup.
 
169
                /// </remarks>
 
170
                /// <param name="objectId">identity of the object to open.</param>
 
171
                /// <param name="typeHint">
 
172
                /// hint about the type of object being requested;
 
173
                /// <see cref="ObjectReader.OBJ_ANY">ObjectReader.OBJ_ANY</see>
 
174
                /// if the object type is not known,
 
175
                /// or does not matter to the caller.
 
176
                /// </param>
 
177
                /// <returns>
 
178
                /// a
 
179
                /// <see cref="ObjectLoader">ObjectLoader</see>
 
180
                /// for accessing the object.
 
181
                /// </returns>
 
182
                /// <exception cref="NGit.Errors.MissingObjectException">the object does not exist.</exception>
 
183
                /// <exception cref="NGit.Errors.IncorrectObjectTypeException">
 
184
                /// typeHint was not OBJ_ANY, and the object's actual type does
 
185
                /// not match typeHint.
 
186
                /// </exception>
 
187
                /// <exception cref="System.IO.IOException">the object store cannot be accessed.</exception>
 
188
                public virtual ObjectLoader Open(AnyObjectId objectId, int typeHint)
 
189
                {
 
190
                        ObjectReader or = NewReader();
 
191
                        try
 
192
                        {
 
193
                                return or.Open(objectId, typeHint);
 
194
                        }
 
195
                        finally
 
196
                        {
 
197
                                or.Release();
 
198
                        }
 
199
                }
 
200
 
 
201
                /// <summary>Create a new cached database instance over this database.</summary>
 
202
                /// <remarks>
 
203
                /// Create a new cached database instance over this database. This instance might
 
204
                /// optimize queries by caching some information about database. So some modifications
 
205
                /// done after instance creation might fail to be noticed.
 
206
                /// </remarks>
 
207
                /// <returns>new cached database instance</returns>
 
208
                public virtual NGit.ObjectDatabase NewCachedDatabase()
 
209
                {
 
210
                        return this;
 
211
                }
 
212
        }
 
213
}