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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
|
/***************************************************************************
* Copyright (c) 2004 - 2008 Eike Stepper, Germany.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Eike Stepper - initial API and implementation
* Simon McDuff - http://bugs.eclipse.org/201266
* Simon McDuff - http://bugs.eclipse.org/210868
**************************************************************************/
package org.eclipse.emf.cdo.internal.server;
import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.id.CDOIDObjectFactory;
import org.eclipse.emf.cdo.common.model.CDOClass;
import org.eclipse.emf.cdo.common.model.CDOFeature;
import org.eclipse.emf.cdo.internal.common.revision.CDORevisionResolverImpl;
import org.eclipse.emf.cdo.server.IRepository;
import org.eclipse.emf.cdo.server.IRevisionManager;
import org.eclipse.emf.cdo.server.IStoreChunkReader;
import org.eclipse.emf.cdo.server.IStoreReader;
import org.eclipse.emf.cdo.server.StoreThreadLocal;
import org.eclipse.emf.cdo.server.IStoreChunkReader.Chunk;
import org.eclipse.emf.cdo.spi.common.InternalCDORevision;
import org.eclipse.net4j.util.collection.MoveableList;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
* @author Eike Stepper
*/
public class RevisionManager extends CDORevisionResolverImpl implements IRevisionManager
{
private IRepository repository;
/**
* @since 2.0
*/
public RevisionManager()
{
}
/**
* @since 2.0
*/
public IRepository getRepository()
{
return repository;
}
/**
* @since 2.0
*/
public void setRepository(IRepository repository)
{
this.repository = repository;
}
public CDOIDObjectFactory getCDOIDObjectFactory()
{
return repository.getStore().getCDOIDObjectFactory();
}
@Override
protected InternalCDORevision verifyRevision(InternalCDORevision revision, int referenceChunk)
{
IStoreReader storeReader = null;
revision = super.verifyRevision(revision, referenceChunk);
if (repository.isVerifyingRevisions())
{
storeReader = StoreThreadLocal.getStoreReader();
revision = (InternalCDORevision)storeReader.verifyRevision(revision);
}
ensureChunks(revision, referenceChunk, storeReader);
return revision;
}
protected void ensureChunks(InternalCDORevision revision, int referenceChunk, IStoreReader storeReader)
{
CDOClass cdoClass = revision.getCDOClass();
CDOFeature[] features = cdoClass.getAllFeatures();
for (int i = 0; i < features.length; i++)
{
CDOFeature feature = features[i];
if (feature.isReference() && feature.isMany())
{
MoveableList<Object> list = revision.getList(feature);
int chunkEnd = Math.min(referenceChunk, list.size());
storeReader = ensureChunk(revision, feature, storeReader, list, 0, chunkEnd);
}
}
}
public IStoreReader ensureChunk(InternalCDORevision revision, CDOFeature feature, int chunkStart, int chunkEnd)
{
MoveableList<Object> list = revision.getList(feature);
chunkEnd = Math.min(chunkEnd, list.size());
return ensureChunk(revision, feature, StoreThreadLocal.getStoreReader(), list, chunkStart, chunkEnd);
}
protected IStoreReader ensureChunk(InternalCDORevision revision, CDOFeature feature, IStoreReader storeReader,
MoveableList<Object> list, int chunkStart, int chunkEnd)
{
IStoreChunkReader chunkReader = null;
int fromIndex = -1;
for (int j = chunkStart; j < chunkEnd; j++)
{
if (list.get(j) == InternalCDORevision.UNINITIALIZED)
{
if (fromIndex == -1)
{
fromIndex = j;
}
}
else
{
if (fromIndex != -1)
{
if (chunkReader == null)
{
if (storeReader == null)
{
storeReader = StoreThreadLocal.getStoreReader();
}
chunkReader = storeReader.createChunkReader(revision, feature);
}
int toIndex = j;
if (fromIndex == toIndex - 1)
{
chunkReader.addSimpleChunk(fromIndex);
}
else
{
chunkReader.addRangedChunk(fromIndex, toIndex);
}
fromIndex = -1;
}
}
}
// Add last chunk
if (fromIndex != -1)
{
if (chunkReader == null)
{
if (storeReader == null)
{
storeReader = StoreThreadLocal.getStoreReader();
}
chunkReader = storeReader.createChunkReader(revision, feature);
}
int toIndex = chunkEnd;
if (fromIndex == toIndex - 1)
{
chunkReader.addSimpleChunk(fromIndex);
}
else
{
chunkReader.addRangedChunk(fromIndex, toIndex);
}
}
if (chunkReader != null)
{
List<Chunk> chunks = chunkReader.executeRead();
for (Chunk chunk : chunks)
{
int startIndex = chunk.getStartIndex();
for (int indexInChunk = 0; indexInChunk < chunk.size(); indexInChunk++)
{
CDOID id = chunk.getID(indexInChunk);
list.set(startIndex + indexInChunk, id);
}
}
}
return storeReader;
}
@Override
protected InternalCDORevision loadRevision(CDOID id, int referenceChunk)
{
IStoreReader storeReader = StoreThreadLocal.getStoreReader();
return (InternalCDORevision)storeReader.readRevision(id, referenceChunk);
}
@Override
protected InternalCDORevision loadRevisionByTime(CDOID id, int referenceChunk, long timeStamp)
{
if (getRepository().isSupportingAudits())
{
IStoreReader storeReader = StoreThreadLocal.getStoreReader();
return (InternalCDORevision)storeReader.readRevisionByTime(id, referenceChunk, timeStamp);
}
// TODO Simon*: Is this check necessary here?
// TODO Eike: To have better exception message.
// By knowing if the back-end supports it, it let know the user that it could be achieved by changing its
// configuration file at the server.
// if (getRepository().getStore().hasAuditingSupport())
// {
// throw new UnsupportedOperationException(
// "Auditing supports isn't activated (see IRepository.Props.PROP_SUPPORTING_AUDITS).");
// }
throw new UnsupportedOperationException("No support for auditing mode");
}
@Override
protected InternalCDORevision loadRevisionByVersion(CDOID id, int referenceChunk, int version)
{
IStoreReader storeReader = StoreThreadLocal.getStoreReader();
if (getRepository().isSupportingAudits())
{
return (InternalCDORevision)storeReader.readRevisionByVersion(id, referenceChunk, version);
}
InternalCDORevision revision = loadRevision(id, referenceChunk);
if (revision.getVersion() == version)
{
return revision;
}
throw new IllegalStateException("Cannot access object with id " + id + " and version " + version);
}
@Override
protected List<InternalCDORevision> loadRevisions(Collection<CDOID> ids, int referenceChunk)
{
IStoreReader storeReader = StoreThreadLocal.getStoreReader();
List<InternalCDORevision> revisions = new ArrayList<InternalCDORevision>();
for (CDOID id : ids)
{
InternalCDORevision revision = (InternalCDORevision)storeReader.readRevision(id, referenceChunk);
revisions.add(revision);
}
return revisions;
}
@Override
protected List<InternalCDORevision> loadRevisionsByTime(Collection<CDOID> ids, int referenceChunk, long timeStamp)
{
List<InternalCDORevision> revisions = new ArrayList<InternalCDORevision>();
for (CDOID id : ids)
{
InternalCDORevision revision = loadRevisionByTime(id, referenceChunk, timeStamp);
revisions.add(revision);
}
return revisions;
}
/**
* @since 2.0
*/
@Override
protected CDOFeature getResourcePathFeature()
{
return repository.getPackageManager().getCDOResourcePackage().getCDOResourceClass().getCDOPathFeature();
}
/**
* TODO Move this to the cache(s)
*/
protected int getLRUCapacity(String prop)
{
String capacity = repository.getProperties().get(prop);
return capacity == null ? 0 : Integer.valueOf(capacity);
}
}
|