Skip to main content
summaryrefslogtreecommitdiffstats
blob: 455c3259429185528a214b702ec6f554e08b43ce (plain) (blame)
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
/*
 * Copyright (c) 2012, 2013 Eike Stepper (Berlin, Germany) and others.
 * 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
 */
package org.eclipse.emf.cdo.server.internal.lissome;

import org.eclipse.emf.cdo.common.branch.CDOBranch;
import org.eclipse.emf.cdo.common.branch.CDOBranchManager;
import org.eclipse.emf.cdo.common.branch.CDOBranchPoint;
import org.eclipse.emf.cdo.common.branch.CDOBranchVersion;
import org.eclipse.emf.cdo.common.commit.CDOChangeSetData;
import org.eclipse.emf.cdo.common.commit.CDOCommitData;
import org.eclipse.emf.cdo.common.commit.CDOCommitInfo;
import org.eclipse.emf.cdo.common.commit.CDOCommitInfoManager;
import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.id.CDOIDProvider;
import org.eclipse.emf.cdo.common.id.CDOIDReference;
import org.eclipse.emf.cdo.common.lob.CDOLobStore;
import org.eclipse.emf.cdo.common.lock.CDOLockChangeInfo;
import org.eclipse.emf.cdo.common.lock.CDOLockOwner;
import org.eclipse.emf.cdo.common.lock.CDOLockState;
import org.eclipse.emf.cdo.common.lock.IDurableLockingManager.LockArea;
import org.eclipse.emf.cdo.common.model.CDOClassifierRef;
import org.eclipse.emf.cdo.common.model.CDOPackageInfo;
import org.eclipse.emf.cdo.common.model.CDOPackageRegistry;
import org.eclipse.emf.cdo.common.model.CDOPackageUnit;
import org.eclipse.emf.cdo.common.model.CDOPackageUnit.Type;
import org.eclipse.emf.cdo.common.model.CDOType;
import org.eclipse.emf.cdo.common.protocol.CDODataInput;
import org.eclipse.emf.cdo.common.protocol.CDODataOutput;
import org.eclipse.emf.cdo.common.revision.CDOIDAndBranch;
import org.eclipse.emf.cdo.common.revision.CDOIDAndVersion;
import org.eclipse.emf.cdo.common.revision.CDOList;
import org.eclipse.emf.cdo.common.revision.CDOListFactory;
import org.eclipse.emf.cdo.common.revision.CDORevisable;
import org.eclipse.emf.cdo.common.revision.CDORevision;
import org.eclipse.emf.cdo.common.revision.CDORevisionFactory;
import org.eclipse.emf.cdo.common.revision.CDORevisionKey;
import org.eclipse.emf.cdo.common.revision.delta.CDOFeatureDelta;
import org.eclipse.emf.cdo.common.revision.delta.CDORevisionDelta;
import org.eclipse.emf.cdo.common.security.CDOPermissionProvider;
import org.eclipse.emf.cdo.spi.common.protocol.CDODataInputImpl;
import org.eclipse.emf.cdo.spi.common.protocol.CDODataOutputImpl;
import org.eclipse.emf.cdo.spi.common.revision.CDORevisionUnchunker;
import org.eclipse.emf.cdo.spi.common.revision.DetachedCDORevision;

import org.eclipse.net4j.util.concurrent.IRWLockManager.LockType;
import org.eclipse.net4j.util.io.DataInputExtender;
import org.eclipse.net4j.util.io.DataInputOutputFile;
import org.eclipse.net4j.util.io.DataOutputExtender;
import org.eclipse.net4j.util.io.ExtendedDataInput;
import org.eclipse.net4j.util.io.ExtendedDataOutput;
import org.eclipse.net4j.util.io.ExtendedIOUtil.ClassResolver;
import org.eclipse.net4j.util.io.IORuntimeException;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.resource.ResourceSet;

import java.io.FileNotFoundException;
import java.io.IOException;

/**
 * @author Eike Stepper
 */
public class LissomeFileHandle extends DataInputOutputFile implements CDODataInput, CDODataOutput,
    LissomeFile.RevisionProvider
{
  private LissomeFile file;

  private CDODataInput in;

  private CDODataOutput out;

  public LissomeFileHandle(LissomeFile file, String mode) throws FileNotFoundException
  {
    super(file, mode);
    this.file = file;
  }

  public LissomeFile getFile()
  {
    return file;
  }

  public LissomeStore getStore()
  {
    return file.getStore();
  }

  public CDOPackageRegistry getPackageRegistry()
  {
    return getStore().getRepository().getPackageRegistry();
  }

  public CDOBranchManager getBranchManager()
  {
    return getStore().getRepository().getBranchManager();
  }

  public CDOCommitInfoManager getCommitInfoManager()
  {
    return getStore().getRepository().getCommitInfoManager();
  }

  public CDORevisionUnchunker getRevisionUnchunker()
  {
    return null;
  }

  public CDORevisionFactory getRevisionFactory()
  {
    return CDORevisionFactory.DEFAULT;
  }

  public CDOListFactory getListFactory()
  {
    return CDOListFactory.DEFAULT;
  }

  public CDOLobStore getLobStore()
  {
    return null;
  }

  public CDOIDProvider getIDProvider()
  {
    return CDOIDProvider.NOOP;
  }

  public CDOPermissionProvider getPermissionProvider()
  {
    return out().getPermissionProvider();
  }

  public CDORevision getRevision(long pointer)
  {
    try
    {
      seek(pointer);
      return readCDORevision();
    }
    catch (IOException ex)
    {
      throw new IORuntimeException(ex);
    }
  }

  private CDODataInput in()
  {
    if (in == null)
    {
      in = createDataInput();
    }

    return in;
  }

  protected CDODataInput createDataInput()
  {
    ExtendedDataInput extendedDataInput = new DataInputExtender(this);
    return new CDODataInputImpl(extendedDataInput)
    {
      @Override
      public CDORevision readCDORevision(boolean freeze) throws IOException
      {
        boolean detached = readBoolean();
        if (detached)
        {
          int cid = readInt();
          EClass eClass = (EClass)file.getStore().getMetaObject(cid);

          CDOID id = readCDOID();
          CDOBranch branch = readCDOBranch();
          int version = readInt();
          long timeStamp = readLong();
          long revised = readLong();

          return new DetachedCDORevision(eClass, id, branch, version, timeStamp, revised);
        }

        return super.readCDORevision(freeze);
      }

      public CDOPackageRegistry getPackageRegistry()
      {
        return LissomeFileHandle.this.getPackageRegistry();
      }

      @Override
      protected CDOBranchManager getBranchManager()
      {
        return LissomeFileHandle.this.getBranchManager();
      }

      @Override
      protected CDOCommitInfoManager getCommitInfoManager()
      {
        return LissomeFileHandle.this.getCommitInfoManager();
      }

      @Override
      protected CDORevisionFactory getRevisionFactory()
      {
        return LissomeFileHandle.this.getRevisionFactory();
      }

      @Override
      protected CDOListFactory getListFactory()
      {
        return LissomeFileHandle.this.getListFactory();
      }

      @Override
      protected CDOLobStore getLobStore()
      {
        return LissomeFileHandle.this.getLobStore();
      }
    };
  }

  public byte[] readByteArray() throws IOException
  {
    return in().readByteArray();
  }

  public Object readObject() throws IOException
  {
    return in().readObject();
  }

  public Object readObject(ClassLoader classLoader) throws IOException
  {
    return in().readObject(classLoader);
  }

  public Object readObject(ClassResolver classResolver) throws IOException
  {
    return in().readObject(classResolver);
  }

  public String readString() throws IOException
  {
    return in().readString();
  }

  public <T extends Enum<?>> T readEnum(Class<T> type) throws IOException
  {
    return in().readEnum(type);
  }

  public Throwable readException() throws IOException
  {
    return in().readException();
  }

  public CDOPackageUnit readCDOPackageUnit(ResourceSet resourceSet) throws IOException
  {
    return in().readCDOPackageUnit(resourceSet);
  }

  public CDOPackageUnit[] readCDOPackageUnits(ResourceSet resourceSet) throws IOException
  {
    return in().readCDOPackageUnits(resourceSet);
  }

  public Type readCDOPackageUnitType() throws IOException
  {
    return in().readCDOPackageUnitType();
  }

  public CDOPackageInfo readCDOPackageInfo() throws IOException
  {
    return in().readCDOPackageInfo();
  }

  public CDOClassifierRef readCDOClassifierRef() throws IOException
  {
    return in().readCDOClassifierRef();
  }

  public EClassifier readCDOClassifierRefAndResolve() throws IOException
  {
    return in().readCDOClassifierRefAndResolve();
  }

  public String readCDOPackageURI() throws IOException
  {
    return in().readCDOPackageURI();
  }

  public CDOType readCDOType() throws IOException
  {
    return in().readCDOType();
  }

  public CDOBranch readCDOBranch() throws IOException
  {
    return in().readCDOBranch();
  }

  public CDOBranchPoint readCDOBranchPoint() throws IOException
  {
    return in().readCDOBranchPoint();
  }

  public CDOBranchVersion readCDOBranchVersion() throws IOException
  {
    return in().readCDOBranchVersion();
  }

  public CDOChangeSetData readCDOChangeSetData() throws IOException
  {
    return in().readCDOChangeSetData();
  }

  public CDOCommitData readCDOCommitData() throws IOException
  {
    return in().readCDOCommitData();
  }

  public CDOCommitInfo readCDOCommitInfo() throws IOException
  {
    return in().readCDOCommitInfo();
  }

  public CDOID readCDOID() throws IOException
  {
    return in().readCDOID();
  }

  public CDOIDReference readCDOIDReference() throws IOException
  {
    return in().readCDOIDReference();
  }

  public CDOIDAndVersion readCDOIDAndVersion() throws IOException
  {
    return in().readCDOIDAndVersion();
  }

  public CDOIDAndBranch readCDOIDAndBranch() throws IOException
  {
    return in().readCDOIDAndBranch();
  }

  public CDORevisionKey readCDORevisionKey() throws IOException
  {
    return in().readCDORevisionKey();
  }

  public CDORevision readCDORevision() throws IOException
  {
    return in().readCDORevision();
  }

  public CDORevision readCDORevision(boolean freeze) throws IOException
  {
    return in().readCDORevision(freeze);
  }

  public CDORevisable readCDORevisable() throws IOException
  {
    return in().readCDORevisable();
  }

  public CDOList readCDOList(EClass owner, EStructuralFeature feature) throws IOException
  {
    return in().readCDOList(owner, feature);
  }

  public Object readCDOFeatureValue(EStructuralFeature feature) throws IOException
  {
    return in().readCDOFeatureValue(feature);
  }

  public CDORevisionDelta readCDORevisionDelta() throws IOException
  {
    return in().readCDORevisionDelta();
  }

  public CDOFeatureDelta readCDOFeatureDelta(EClass owner) throws IOException
  {
    return in().readCDOFeatureDelta(owner);
  }

  public Object readCDORevisionOrPrimitive() throws IOException
  {
    return in().readCDORevisionOrPrimitive();
  }

  public Object readCDORevisionOrPrimitiveOrClassifier() throws IOException
  {
    return in().readCDORevisionOrPrimitiveOrClassifier();
  }

  public LockType readCDOLockType() throws IOException
  {
    return in().readCDOLockType();
  }

  public CDOLockChangeInfo readCDOLockChangeInfo() throws IOException
  {
    return in().readCDOLockChangeInfo();
  }

  public CDOLockOwner readCDOLockOwner() throws IOException
  {
    return in().readCDOLockOwner();
  }

  public CDOLockState readCDOLockState() throws IOException
  {
    return in().readCDOLockState();
  }

  public LockArea readCDOLockArea() throws IOException
  {
    return in().readCDOLockArea();
  }

  private CDODataOutput out()
  {
    if (out == null)
    {
      out = createDataOutput();
    }

    return out;
  }

  protected CDODataOutput createDataOutput()
  {
    ExtendedDataOutput extendedDataOutput = new DataOutputExtender(this);
    return new CDODataOutputImpl(extendedDataOutput)
    {
      @Override
      public void writeCDORevision(CDORevision revision, int referenceChunk, CDOBranchPoint securityContext)
          throws IOException
      {
        boolean detached = revision instanceof DetachedCDORevision;
        writeBoolean(detached);
        if (detached)
        {
          int cid = file.getStore().getMetaID(revision.getEClass());
          writeInt(cid);

          writeCDOID(revision.getID());
          writeCDOBranch(revision.getBranch());
          writeInt(revision.getVersion());
          writeLong(revision.getTimeStamp());
          writeLong(revision.getRevised());
        }
        else
        {
          super.writeCDORevision(revision, referenceChunk, securityContext);
        }
      }

      @Override
      public CDOPackageRegistry getPackageRegistry()
      {
        return LissomeFileHandle.this.getPackageRegistry();
      }

      @Override
      public CDOIDProvider getIDProvider()
      {
        return LissomeFileHandle.this.getIDProvider();
      }
    };
  }

  public void writeByteArray(byte[] b) throws IOException
  {
    out().writeByteArray(b);
  }

  public void writeObject(Object object) throws IOException
  {
    out().writeObject(object);
  }

  public void writeString(String str) throws IOException
  {
    out().writeString(str);
  }

  public void writeEnum(Enum<?> literal) throws IOException
  {
    out().writeEnum(literal);
  }

  public void writeException(Throwable t) throws IOException
  {
    out().writeException(t);
  }

  public void writeCDOPackageUnit(CDOPackageUnit packageUnit, boolean withPackages) throws IOException
  {
    out().writeCDOPackageUnit(packageUnit, withPackages);
  }

  public void writeCDOPackageUnits(CDOPackageUnit... packageUnit) throws IOException
  {
    out().writeCDOPackageUnits(packageUnit);
  }

  public void writeCDOPackageUnitType(Type type) throws IOException
  {
    out().writeCDOPackageUnitType(type);
  }

  public void writeCDOPackageInfo(CDOPackageInfo packageInfo) throws IOException
  {
    out().writeCDOPackageInfo(packageInfo);
  }

  public void writeCDOClassifierRef(CDOClassifierRef eClassifierRef) throws IOException
  {
    out().writeCDOClassifierRef(eClassifierRef);
  }

  public void writeCDOClassifierRef(EClassifier eClassifier) throws IOException
  {
    out().writeCDOClassifierRef(eClassifier);
  }

  public void writeCDOPackageURI(String uri) throws IOException
  {
    out().writeCDOPackageURI(uri);
  }

  public void writeCDOType(CDOType cdoType) throws IOException
  {
    out().writeCDOType(cdoType);
  }

  public void writeCDOBranch(CDOBranch branch) throws IOException
  {
    out().writeCDOBranch(branch);
  }

  public void writeCDOBranchPoint(CDOBranchPoint branchPoint) throws IOException
  {
    out().writeCDOBranchPoint(branchPoint);
  }

  public void writeCDOBranchVersion(CDOBranchVersion branchVersion) throws IOException
  {
    out().writeCDOBranchVersion(branchVersion);
  }

  public void writeCDOChangeSetData(CDOChangeSetData changeSetData) throws IOException
  {
    out().writeCDOChangeSetData(changeSetData);
  }

  public void writeCDOCommitData(CDOCommitData commitData) throws IOException
  {
    out().writeCDOCommitData(commitData);
  }

  public void writeCDOCommitInfo(CDOCommitInfo commitInfo) throws IOException
  {
    out().writeCDOCommitInfo(commitInfo);
  }

  public void writeCDOID(CDOID id) throws IOException
  {
    out().writeCDOID(id);
  }

  public void writeCDOIDReference(CDOIDReference idReference) throws IOException
  {
    out().writeCDOIDReference(idReference);
  }

  public void writeCDOIDAndVersion(CDOIDAndVersion idAndVersion) throws IOException
  {
    out().writeCDOIDAndVersion(idAndVersion);
  }

  public void writeCDOIDAndBranch(CDOIDAndBranch idAndBranch) throws IOException
  {
    out().writeCDOIDAndBranch(idAndBranch);
  }

  public void writeCDORevisionKey(CDORevisionKey revisionKey) throws IOException
  {
    out().writeCDORevisionKey(revisionKey);
  }

  public void writeCDORevision(CDORevision revision, int referenceChunk) throws IOException
  {
    out().writeCDORevision(revision, referenceChunk);
  }

  public void writeCDORevision(CDORevision revision, int referenceChunk, CDOBranchPoint securityContext)
      throws IOException
  {
    out().writeCDORevision(revision, referenceChunk, securityContext);
  }

  public void writeCDORevisable(CDORevisable revisable) throws IOException
  {
    out().writeCDORevisable(revisable);
  }

  public void writeCDOList(EClass owner, EStructuralFeature feature, CDOList list, int referenceChunk)
      throws IOException
  {
    out().writeCDOList(owner, feature, list, referenceChunk);
  }

  public void writeCDOFeatureValue(EStructuralFeature feature, Object value) throws IOException
  {
    out().writeCDOFeatureValue(feature, value);
  }

  public void writeCDORevisionDelta(CDORevisionDelta revisionDelta) throws IOException
  {
    out().writeCDORevisionDelta(revisionDelta);
  }

  public void writeCDOFeatureDelta(EClass owner, CDOFeatureDelta featureDelta) throws IOException
  {
    out().writeCDOFeatureDelta(owner, featureDelta);
  }

  public void writeCDORevisionOrPrimitive(Object value) throws IOException
  {
    out().writeCDORevisionOrPrimitive(value);
  }

  public void writeCDORevisionOrPrimitiveOrClassifier(Object value) throws IOException
  {
    out().writeCDORevisionOrPrimitiveOrClassifier(value);
  }

  public void writeCDOLockType(LockType lockType) throws IOException
  {
    out().writeCDOLockType(lockType);
  }

  public void writeCDOLockChangeInfo(CDOLockChangeInfo lockChangeInfo) throws IOException
  {
    out().writeCDOLockChangeInfo(lockChangeInfo);
  }

  public void writeCDOLockState(CDOLockState lockState) throws IOException
  {
    out().writeCDOLockState(lockState);
  }

  public void writeCDOLockOwner(CDOLockOwner lockOwner) throws IOException
  {
    out().writeCDOLockOwner(lockOwner);
  }

  public void writeCDOLockArea(LockArea lockArea) throws IOException
  {
    out().writeCDOLockArea(lockArea);
  }

  public int write(long startPointer, LissomeFileOperation operation)
  {
    try
    {
      seek(startPointer);
      operation.execute(this);
      flush();

      long endPointer = getFilePointer();
      return (int)(endPointer - startPointer);
    }
    catch (IOException ex)
    {
      throw new IORuntimeException(ex);
    }
  }

  public long append(LissomeFileOperation operation)
  {
    try
    {
      long startPointer = length();
      write(startPointer, operation);
      return startPointer;
    }
    catch (IOException ex)
    {
      throw new IORuntimeException(ex);
    }
  }
}

Back to the top