Skip to content

Commit 74e4d36

Browse files
committed
proof of concept to avoid EMF pooling
1 parent a97e8d5 commit 74e4d36

File tree

2 files changed

+388
-0
lines changed

2 files changed

+388
-0
lines changed

com.avaloq.tools.ddk.xtext/src/com/avaloq/tools/ddk/xtext/resource/persistence/DirectLinkingResourceStorageLoadable.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,28 @@ public InternalEObject loadEObject() throws IOException {
314314
return result;
315315
}
316316

317+
@Override
318+
public URI readURI() throws IOException {
319+
int id = readCompressedInt();
320+
if (id == -1) {
321+
return null;
322+
} else {
323+
URI uri;
324+
if (uriList.size() <= id) {
325+
String value = readSegmentedString();
326+
uri = resolve(new DirectLinkingURI(value));
327+
uriList.add(uri);
328+
} else {
329+
uri = uriList.get(id);
330+
}
331+
String fragment = readSegmentedString();
332+
if (fragment != null) {
333+
uri = uri.appendFragment(fragment);
334+
}
335+
return uri;
336+
}
337+
}
338+
317339
@Override
318340
protected void loadFeatureValue(final InternalEObject internalEObject, final EStructuralFeatureData eStructuralFeatureData) throws IOException {
319341
try {
Lines changed: 366 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,366 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2016 Avaloq Group AG and others.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Avaloq Evolution AG - initial API and implementation
10+
*******************************************************************************/
11+
12+
package com.avaloq.tools.ddk.xtext.resource.persistence;
13+
14+
import java.util.Arrays;
15+
import java.util.List;
16+
import java.util.Objects;
17+
18+
import org.eclipse.emf.common.util.URI;
19+
20+
21+
public class DirectLinkingURI extends URI {
22+
23+
private final String uri;
24+
25+
protected DirectLinkingURI(final String uri) {
26+
super(uri.hashCode());
27+
this.uri = uri;
28+
}
29+
30+
@Override
31+
public String scheme() {
32+
int indexOf = uri.indexOf(':');
33+
if (indexOf == -1) {
34+
return null;
35+
}
36+
return uri.substring(0, indexOf);
37+
}
38+
39+
@Override
40+
public String fileExtension() {
41+
int indexOf = uri.lastIndexOf('.');
42+
if (indexOf == -1) {
43+
return null;
44+
}
45+
return uri.substring(indexOf + 1);
46+
}
47+
48+
@Override
49+
public String[] segments() {
50+
int indexOf = uri.indexOf(':');
51+
if (indexOf != -1) {
52+
return uri.substring(indexOf + 2).split("/"); //$NON-NLS-1$
53+
}
54+
return uri.split("/"); //$NON-NLS-1$
55+
}
56+
57+
@Override
58+
public URI appendFragment(final String fragment) {
59+
return new DirectLinkingURI(uri + FRAGMENT_SEPARATOR + fragment);
60+
}
61+
62+
@Override
63+
public URI trimFragment() {
64+
int indexOf = uri.indexOf('#');
65+
if (indexOf == -1) {
66+
return this;
67+
}
68+
return new DirectLinkingURI(uri.substring(0, indexOf));
69+
}
70+
71+
@Override
72+
public String fragment() {
73+
int indexOf = uri.indexOf('#');
74+
if (indexOf == -1) {
75+
return null;
76+
}
77+
return uri.substring(indexOf + 1);
78+
}
79+
80+
//
81+
@Override
82+
public boolean isRelative() {
83+
return scheme() == null;
84+
}
85+
86+
@Override
87+
protected boolean isBase() {
88+
return true;
89+
}
90+
91+
@Override
92+
public boolean isHierarchical() {
93+
return true;
94+
}
95+
96+
@Override
97+
public boolean hasAuthority() {
98+
return false;
99+
}
100+
101+
@Override
102+
public boolean hasOpaquePart() {
103+
return false;
104+
}
105+
106+
@Override
107+
public boolean hasDevice() {
108+
return false;
109+
}
110+
111+
@Override
112+
public boolean hasPath() {
113+
return false;
114+
}
115+
116+
@Override
117+
protected boolean hasDeviceOrPath() {
118+
return false;
119+
}
120+
121+
@Override
122+
public boolean hasAbsolutePath() {
123+
return true;
124+
}
125+
126+
@Override
127+
public boolean hasRelativePath() {
128+
return isRelative();
129+
}
130+
131+
@Override
132+
public boolean hasEmptyPath() {
133+
return false;
134+
}
135+
136+
@Override
137+
public boolean hasQuery() {
138+
return false;
139+
}
140+
141+
@Override
142+
public boolean hasFragment() {
143+
return uri.indexOf('#') != -1;
144+
}
145+
146+
@Override
147+
public boolean isCurrentDocumentReference() {
148+
return false;
149+
}
150+
151+
@Override
152+
public boolean isEmpty() {
153+
return false;
154+
}
155+
156+
@Override
157+
public boolean isFile() {
158+
return false;
159+
}
160+
161+
@Override
162+
public boolean isPlatform() {
163+
return "platform".equals(scheme()); //$NON-NLS-1$
164+
}
165+
166+
@Override
167+
public boolean isPlatformResource() {
168+
return uri.startsWith("platform://resource"); //$NON-NLS-1$
169+
}
170+
171+
@Override
172+
public boolean isPlatformPlugin() {
173+
return uri.startsWith("platform://plugin"); //$NON-NLS-1$
174+
}
175+
176+
@Override
177+
public boolean isArchive() {
178+
return false;
179+
}
180+
181+
@Override
182+
protected boolean segmentsEqual(final URI uri) {
183+
throw new UnsupportedOperationException();
184+
}
185+
186+
@Override
187+
public String opaquePart() {
188+
return null;
189+
}
190+
191+
@Override
192+
public String authority() {
193+
return null;
194+
}
195+
196+
@Override
197+
public String userInfo() {
198+
return null;
199+
}
200+
201+
@Override
202+
public String host() {
203+
return null;
204+
}
205+
206+
@Override
207+
public String port() {
208+
return null;
209+
}
210+
211+
@Override
212+
public String device() {
213+
return null;
214+
}
215+
216+
@Override
217+
protected String[] rawSegments() {
218+
return segments();
219+
}
220+
221+
@Override
222+
public List<String> segmentsList() {
223+
return Arrays.asList(segments());
224+
}
225+
226+
@Override
227+
public int segmentCount() {
228+
return segments().length;
229+
}
230+
231+
@Override
232+
public String segment(final int i) {
233+
return segments()[i];
234+
}
235+
236+
@Override
237+
public String lastSegment() {
238+
String[] array = segments();
239+
return array[array.length - 1];
240+
}
241+
242+
@Override
243+
public String path() {
244+
return null;
245+
}
246+
247+
@Override
248+
public String devicePath() {
249+
return null;
250+
}
251+
252+
@Override
253+
public String query() {
254+
return null;
255+
}
256+
257+
@Override
258+
public URI appendQuery(final String query) {
259+
throw new UnsupportedOperationException();
260+
}
261+
262+
@Override
263+
public URI trimQuery() {
264+
return this;
265+
}
266+
267+
@Override
268+
public URI resolve(final URI base, final boolean preserveRootParents) {
269+
if (uri.startsWith("../../")) {
270+
return new DirectLinkingURI("ctx:/src/" + uri.substring(6));
271+
}
272+
if (uri.startsWith("../")) {
273+
return new DirectLinkingURI("ctx:/src/AAA/" + uri.substring(3));
274+
}
275+
int lastIndexOf = base.toString().lastIndexOf("/"); //$NON-NLS-1$
276+
return new DirectLinkingURI(base.toString().substring(0, lastIndexOf + 1) + uri);
277+
}
278+
279+
@Override
280+
public URI deresolve(final URI base, final boolean preserveRootParents, final boolean anyRelPath, final boolean shorterRelPath) {
281+
throw new UnsupportedOperationException();
282+
}
283+
284+
@Override
285+
protected String[] collapseSegments(final boolean preserveRootParents) {
286+
throw new UnsupportedOperationException();
287+
}
288+
289+
@Override
290+
public String toString() {
291+
return uri;
292+
}
293+
294+
/**
295+
* If the hash code is <code>0</code> then most likely we've got a pending lazy {@link LazyFragmentInitializer}.
296+
*/
297+
@Override
298+
public int hashCode() {
299+
return hashCode;
300+
}
301+
302+
@Override
303+
public boolean equals(final Object object) {
304+
if (object == this) {
305+
return true;
306+
}
307+
308+
if (object instanceof DirectLinkingURI directLinkingUri) {
309+
return directLinkingUri.uri == this.uri;
310+
}
311+
312+
if (object instanceof URI emfURI) {
313+
return Objects.equals(this.uri, emfURI.toString());
314+
}
315+
return false;
316+
}
317+
318+
@Override
319+
public String toFileString() {
320+
throw new UnsupportedOperationException();
321+
}
322+
323+
@Override
324+
public String toPlatformString(final boolean decode) {
325+
throw new UnsupportedOperationException();
326+
}
327+
328+
@Override
329+
public URI appendSegment(final String segment) {
330+
throw new UnsupportedOperationException();
331+
332+
}
333+
334+
@Override
335+
public URI appendSegments(final String[] segments) {
336+
throw new UnsupportedOperationException();
337+
}
338+
339+
@Override
340+
public URI trimSegments(final int i) {
341+
throw new UnsupportedOperationException();
342+
}
343+
344+
@Override
345+
public boolean hasTrailingPathSeparator() {
346+
return false;
347+
}
348+
349+
@Override
350+
public URI appendFileExtension(final String fileExtension) {
351+
throw new UnsupportedOperationException();
352+
353+
}
354+
355+
@Override
356+
public URI trimFileExtension() {
357+
throw new UnsupportedOperationException();
358+
359+
}
360+
361+
@Override
362+
public URI replacePrefix(final URI oldPrefix, final URI newPrefix) {
363+
throw new UnsupportedOperationException();
364+
365+
}
366+
}

0 commit comments

Comments
 (0)