|
Lines 10-21
Link Here
|
| 10 |
**************************************************************************/ |
10 |
**************************************************************************/ |
| 11 |
package org.eclipse.emf.cdo.internal.server.protocol; |
11 |
package org.eclipse.emf.cdo.internal.server.protocol; |
| 12 |
|
12 |
|
|
|
13 |
import org.eclipse.emf.cdo.internal.analyzer.CDOFetchRule; |
| 13 |
import org.eclipse.emf.cdo.internal.protocol.CDOIDImpl; |
14 |
import org.eclipse.emf.cdo.internal.protocol.CDOIDImpl; |
|
|
15 |
import org.eclipse.emf.cdo.internal.protocol.CDOIDNull; |
| 14 |
import org.eclipse.emf.cdo.internal.protocol.revision.CDORevisionImpl; |
16 |
import org.eclipse.emf.cdo.internal.protocol.revision.CDORevisionImpl; |
|
|
17 |
import org.eclipse.emf.cdo.internal.protocol.revision.CDORevisionImpl.MoveableList; |
| 15 |
import org.eclipse.emf.cdo.internal.server.Session; |
18 |
import org.eclipse.emf.cdo.internal.server.Session; |
| 16 |
import org.eclipse.emf.cdo.internal.server.bundle.OM; |
19 |
import org.eclipse.emf.cdo.internal.server.bundle.OM; |
| 17 |
import org.eclipse.emf.cdo.protocol.CDOID; |
20 |
import org.eclipse.emf.cdo.protocol.CDOID; |
| 18 |
import org.eclipse.emf.cdo.protocol.CDOProtocolConstants; |
21 |
import org.eclipse.emf.cdo.protocol.CDOProtocolConstants; |
|
|
22 |
import org.eclipse.emf.cdo.protocol.model.CDOClass; |
| 23 |
import org.eclipse.emf.cdo.protocol.model.CDOFeature; |
| 19 |
|
24 |
|
| 20 |
import org.eclipse.net4j.internal.util.om.trace.ContextTracer; |
25 |
import org.eclipse.net4j.internal.util.om.trace.ContextTracer; |
| 21 |
import org.eclipse.net4j.util.io.ExtendedDataInputStream; |
26 |
import org.eclipse.net4j.util.io.ExtendedDataInputStream; |
|
Lines 23-29
Link Here
|
| 23 |
|
28 |
|
| 24 |
import java.io.IOException; |
29 |
import java.io.IOException; |
| 25 |
import java.util.ArrayList; |
30 |
import java.util.ArrayList; |
|
|
31 |
import java.util.HashMap; |
| 32 |
import java.util.HashSet; |
| 26 |
import java.util.List; |
33 |
import java.util.List; |
|
|
34 |
import java.util.Set; |
| 27 |
|
35 |
|
| 28 |
/** |
36 |
/** |
| 29 |
* @author Eike Stepper |
37 |
* @author Eike Stepper |
|
Lines 36-41
Link Here
|
| 36 |
|
44 |
|
| 37 |
protected int referenceChunk; |
45 |
protected int referenceChunk; |
| 38 |
|
46 |
|
|
|
47 |
protected HashMap<CDOClass, CDOFetchRule> fetchRules = new HashMap<CDOClass, CDOFetchRule>(); |
| 48 |
|
| 49 |
protected CDOID contextId = CDOIDNull.NULL; |
| 50 |
|
| 39 |
public LoadRevisionIndication() |
51 |
public LoadRevisionIndication() |
| 40 |
{ |
52 |
{ |
| 41 |
} |
53 |
} |
|
Lines 62-86
Link Here
|
| 62 |
if (PROTOCOL.isEnabled()) PROTOCOL.format("Read ID: {0}", id); |
74 |
if (PROTOCOL.isEnabled()) PROTOCOL.format("Read ID: {0}", id); |
| 63 |
ids[i] = id; |
75 |
ids[i] = id; |
| 64 |
} |
76 |
} |
|
|
77 |
|
| 78 |
int fetchSize = in.readInt(); |
| 79 |
if (fetchSize > 0) |
| 80 |
{ |
| 81 |
contextId = CDOIDImpl.read(in); |
| 82 |
for (int i =0; i< fetchSize; i++) |
| 83 |
{ |
| 84 |
CDOFetchRule fetchRule = new CDOFetchRule(in, getPackageManager()); |
| 85 |
for (CDOFeature cdoFeature : fetchRule.getCdoFeatures()) |
| 86 |
fetchRules.put(fetchRule.getCdoClass(), fetchRule); |
| 87 |
} |
| 88 |
} |
| 65 |
} |
89 |
} |
| 66 |
|
90 |
|
|
|
91 |
private void collectRevisionsByRule(CDORevisionImpl revision, int referenceChunk, HashMap<CDOID, CDORevisionImpl> attachedObjects, Set<CDOFetchRule> workingFetchRule) |
| 92 |
{ |
| 93 |
CDOFetchRule fetchRule = fetchRules.get(revision.getCDOClass()); |
| 94 |
|
| 95 |
if (fetchRule == null || workingFetchRule.contains(fetchRule)) |
| 96 |
return; |
| 97 |
|
| 98 |
workingFetchRule.add(fetchRule); |
| 99 |
|
| 100 |
for (CDOFeature feature : fetchRule.getCdoFeatures()) |
| 101 |
{ |
| 102 |
if (!feature.isMany()) |
| 103 |
{ |
| 104 |
Object object = revision.get(feature, 0); |
| 105 |
if (object != null && object instanceof CDOID) |
| 106 |
{ |
| 107 |
CDOID cdoId = (CDOID)object; |
| 108 |
if (!cdoId.isNull() && attachedObjects.get(cdoId) == null) |
| 109 |
{ |
| 110 |
CDORevisionImpl containedRevision = (CDORevisionImpl)getSessionManager().getRepository().getRevisionManager().getRevision(cdoId, referenceChunk); |
| 111 |
attachedObjects.put(containedRevision.getID(), containedRevision); |
| 112 |
collectRevisionsByRule(containedRevision, referenceChunk, attachedObjects, workingFetchRule); |
| 113 |
} |
| 114 |
} |
| 115 |
} |
| 116 |
else if (feature.isMany()) |
| 117 |
{ |
| 118 |
MoveableList list = revision.getList(feature); |
| 119 |
int toIndex = Math.min(referenceChunk, list.size()); |
| 120 |
for (int i = 0; i < toIndex; i++) |
| 121 |
{ |
| 122 |
Object object = list.get(i); |
| 123 |
if (object instanceof CDOID) |
| 124 |
{ |
| 125 |
|
| 126 |
CDOID cdoId = (CDOID)object; |
| 127 |
CDORevisionImpl containedRevision = (CDORevisionImpl)getSessionManager().getRepository().getRevisionManager().getRevision(cdoId, referenceChunk); |
| 128 |
attachedObjects.put(containedRevision.getID(), containedRevision); |
| 129 |
|
| 130 |
collectRevisionsByRule(containedRevision, referenceChunk, attachedObjects, workingFetchRule); |
| 131 |
} |
| 132 |
} |
| 133 |
} |
| 134 |
} |
| 135 |
workingFetchRule.remove(fetchRule); |
| 136 |
} |
| 137 |
|
| 67 |
@Override |
138 |
@Override |
| 68 |
protected void responding(ExtendedDataOutputStream out) throws IOException |
139 |
protected void responding(ExtendedDataOutputStream out) throws IOException |
| 69 |
{ |
140 |
{ |
| 70 |
Session session = getSession(); |
141 |
Session session = getSession(); |
| 71 |
List<CDORevisionImpl> containedRevisions = new ArrayList<CDORevisionImpl>(0); |
142 |
HashMap<CDOID, CDORevisionImpl> containedRevisions = new HashMap<CDOID, CDORevisionImpl>(0); |
| 72 |
|
143 |
|
| 73 |
if (PROTOCOL.isEnabled()) PROTOCOL.format("Writing {0} revisions", ids.length); |
144 |
if (PROTOCOL.isEnabled()) PROTOCOL.format("Writing {0} revisions", ids.length); |
|
|
145 |
|
| 74 |
for (CDOID id : ids) |
146 |
for (CDOID id : ids) |
| 75 |
{ |
147 |
{ |
| 76 |
CDORevisionImpl revision = getRevision(id); |
148 |
CDORevisionImpl revision = getRevision(id); |
| 77 |
revision.write(out, session, referenceChunk); |
149 |
revision.write(out, session, referenceChunk); |
| 78 |
session.collectContainedRevisions(revision, referenceChunk, containedRevisions); |
150 |
session.collectContainedRevisions(revision, referenceChunk, containedRevisions); |
| 79 |
} |
151 |
} |
| 80 |
|
152 |
|
|
|
153 |
if (!contextId.isNull() && fetchRules.size() > 0 ) |
| 154 |
{ |
| 155 |
int newReferenceChunk = Math.max(referenceChunk, 1000); |
| 156 |
CDORevisionImpl revisionContext = getRevision(contextId); |
| 157 |
this.collectRevisionsByRule(revisionContext, newReferenceChunk, containedRevisions, new HashSet<CDOFetchRule>()); |
| 158 |
} |
| 159 |
|
| 81 |
out.writeInt(containedRevisions.size()); |
160 |
out.writeInt(containedRevisions.size()); |
| 82 |
if (PROTOCOL.isEnabled()) PROTOCOL.format("Writing {0} additional revisions", containedRevisions.size()); |
161 |
if (PROTOCOL.isEnabled()) PROTOCOL.format("Writing {0} additional revisions", containedRevisions.size()); |
| 83 |
for (CDORevisionImpl revision : containedRevisions) |
162 |
for (CDORevisionImpl revision : containedRevisions.values()) |
| 84 |
{ |
163 |
{ |
| 85 |
revision.write(out, session, referenceChunk); |
164 |
revision.write(out, session, referenceChunk); |
| 86 |
} |
165 |
} |