blob: 21795fffb9a8af103bc727500144078b8ef50b8a (
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
|
/*
* Copyright (c) 2004 - 2012 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.internal.server.syncing;
import org.eclipse.emf.cdo.common.branch.CDOBranch;
import org.eclipse.emf.cdo.internal.server.TransactionCommitContext;
import org.eclipse.emf.cdo.server.StoreThreadLocal;
import org.eclipse.emf.cdo.spi.common.branch.InternalCDOBranch;
import org.eclipse.emf.cdo.spi.common.branch.InternalCDOBranchManager;
import org.eclipse.emf.cdo.spi.server.InternalCommitContext;
import org.eclipse.emf.cdo.spi.server.InternalTransaction;
import org.eclipse.net4j.util.om.monitor.Monitor;
import org.eclipse.net4j.util.om.monitor.OMMonitor;
/**
* @author Eike Stepper
*/
public class OfflineClone extends SynchronizableRepository
{
public OfflineClone()
{
setState(OFFLINE);
}
@Override
public final Type getType()
{
return CLONE;
}
@Override
public final void setType(Type type)
{
throw new UnsupportedOperationException();
}
@Override
public InternalCommitContext createCommitContext(InternalTransaction transaction)
{
CDOBranch branch = transaction.getBranch();
if (branch.isLocal())
{
return createNormalCommitContext(transaction);
}
if (getState() != ONLINE)
{
return createBranchingCommitContext(transaction, branch);
}
return createWriteThroughCommitContext(transaction);
}
protected InternalCommitContext createBranchingCommitContext(InternalTransaction transaction, CDOBranch branch)
{
long[] times = createCommitTimeStamp(new Monitor());
CDOBranch offlineBranch = createOfflineBranch(branch, times[0] - 1L);
transaction.setBranchPoint(offlineBranch.getHead());
return new BranchingCommitContext(transaction, times);
}
protected CDOBranch createOfflineBranch(CDOBranch baseBranch, long baseTimeStamp)
{
try
{
StoreThreadLocal.setSession(getReplicatorSession());
InternalCDOBranchManager branchManager = getBranchManager();
return branchManager.createBranch(NEW_LOCAL_BRANCH,
"Offline-" + baseTimeStamp, (InternalCDOBranch)baseBranch, baseTimeStamp); //$NON-NLS-1$
}
finally
{
StoreThreadLocal.release();
}
}
/**
* @author Eike Stepper
*/
protected final class BranchingCommitContext extends TransactionCommitContext
{
private long[] times;
public BranchingCommitContext(InternalTransaction transaction, long[] times)
{
super(transaction);
this.times = times;
}
@Override
protected void lockObjects() throws InterruptedException
{
// Do nothing
}
@Override
protected long[] createTimeStamp(OMMonitor monitor)
{
return times;
}
}
}
|