Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: e7645da345b69c982233a57c3affcd806b50b3a5 (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
/*
 * Copyright (c) 2011, 2012, 2015, 2016 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.spi.server;

import org.eclipse.emf.cdo.common.branch.CDOBranch;
import org.eclipse.emf.cdo.common.lock.IDurableLockingManager.LockArea;
import org.eclipse.emf.cdo.common.lock.IDurableLockingManager.LockAreaNotFoundException;

import org.eclipse.net4j.util.CheckUtil;

/**
 * Static methods that may help with classes related to repository synchronization.
 *
 * @author Eike Stepper
 * @since 4.1
 */
public final class SyncingUtil
{
  private SyncingUtil()
  {
  }

  public static InternalView openViewWithLockArea(InternalSession session, InternalLockManager lockManager, CDOBranch viewedBranch, String lockAreaID)
  {
    LockArea lockArea;
    InternalView view;

    try
    {
      lockArea = lockManager.getLockArea(lockAreaID);

      // If we get here, the lockArea already exists.
      view = (InternalView)lockManager.openView(session, InternalSession.TEMP_VIEW_ID, true, lockAreaID);
    }
    catch (LockAreaNotFoundException e)
    {
      // If we get here, the lockArea does not yet exist, so we open
      // a view without a lockArea first, then create a lockArea with the given ID,
      // and associate it with the view.
      view = session.openView(InternalSession.TEMP_VIEW_ID, viewedBranch.getHead());
      lockArea = lockManager.createLockArea(view, lockAreaID);
      view.setDurableLockingID(lockAreaID);
    }

    CheckUtil.checkNull(lockAreaID, "lockAreaID");
    CheckUtil.checkNull(lockArea, "lockArea");
    CheckUtil.checkState(lockAreaID.equals(lockArea.getDurableLockingID()), "lockAreaID has incorrect value");

    return view;
  }
}

Back to the top