1 package org.simantics.db.tests.performance.read;
3 import java.io.IOException;
4 import java.io.UTFDataFormatException;
5 import java.nio.charset.Charset;
7 import java.util.Vector;
9 import org.simantics.databoard.Bindings;
10 import org.simantics.databoard.Datatypes;
11 import org.simantics.databoard.binding.Binding;
12 import org.simantics.databoard.binding.impl.StringBindingDefault;
13 import org.simantics.databoard.serialization.SerializationException;
14 import org.simantics.databoard.serialization.Serializer;
15 import org.simantics.databoard.serialization.impl.ModifiedUTF8StringSerializer;
16 import org.simantics.db.AsyncReadGraph;
17 import org.simantics.db.ReadGraph;
18 import org.simantics.db.RelationInfo;
19 import org.simantics.db.Resource;
20 import org.simantics.db.Session;
21 import org.simantics.db.VirtualGraph;
22 import org.simantics.db.WriteGraph;
23 import org.simantics.db.WriteOnlyGraph;
24 import org.simantics.db.common.request.AsyncReadRequest;
25 import org.simantics.db.common.request.ReadRequest;
26 import org.simantics.db.common.request.WriteOnlyResultRequest;
27 import org.simantics.db.common.request.WriteResultRequest;
28 import org.simantics.db.exception.AssumptionException;
29 import org.simantics.db.exception.DatabaseException;
30 import org.simantics.db.procedure.AsyncMultiProcedure;
31 import org.simantics.db.procedure.AsyncProcedure;
32 import org.simantics.db.procedure.SyncContextProcedure;
33 import org.simantics.db.procedure.SyncMultiProcedure;
34 import org.simantics.db.procedure.SyncProcedure;
35 import org.simantics.db.request.AsyncRead;
36 import org.simantics.db.request.Read;
37 import org.simantics.db.service.ClusterBuilder;
38 import org.simantics.db.service.ClusterBuilder.ResourceHandle;
39 import org.simantics.db.service.ClusterBuilder.StatementHandle;
40 import org.simantics.db.service.DirectQuerySupport;
41 import org.simantics.db.service.QueryControl;
42 import org.simantics.db.service.SerialisationSupport;
43 import org.simantics.db.tests.performance.read.HierarchicalNames.FastStringSerializer.FastStringSerializer2;
44 import org.simantics.layer0.Layer0;
45 import org.simantics.utils.datastructures.Pair;
53 public class HierarchicalNames {
55 public static class FastStringSerializer extends ModifiedUTF8StringSerializer {
57 public static final Charset UTF8 = Charset.forName("utf-8");
59 public static FastStringSerializer INSTANCE = new FastStringSerializer();
61 public FastStringSerializer() {
62 super(FastStringBinding.INSTANCE);
65 static byte[] writeUTF(String str) throws IOException {
67 int strlen = str.length();
71 /* use charAt instead of copying String to char array */
72 for (int i = 0; i < strlen; i++) {
74 if ((c >= 0x0001) && (c <= 0x007F)) {
76 } else if (c > 0x07FF) {
84 throw new UTFDataFormatException(
85 "encoded string too long: " + utflen + " bytes");
87 byte[] bytearr = new byte[utflen+2];
89 bytearr[count++] = (byte) ((utflen >>> 8) & 0xFF);
90 bytearr[count++] = (byte) ((utflen >>> 0) & 0xFF);
93 for (i=0; i<strlen; i++) {
95 if (!((c >= 0x0001) && (c <= 0x007F))) break;
96 bytearr[count++] = (byte) c;
99 for (;i < strlen; i++){
101 if ((c >= 0x0001) && (c <= 0x007F)) {
102 bytearr[count++] = (byte) c;
104 } else if (c > 0x07FF) {
105 bytearr[count++] = (byte) (0xE0 | ((c >> 12) & 0x0F));
106 bytearr[count++] = (byte) (0x80 | ((c >> 6) & 0x3F));
107 bytearr[count++] = (byte) (0x80 | ((c >> 0) & 0x3F));
109 bytearr[count++] = (byte) (0xC0 | ((c >> 6) & 0x1F));
110 bytearr[count++] = (byte) (0x80 | ((c >> 0) & 0x3F));
117 public static class FastStringSerializer2 extends ModifiedUTF8StringSerializer {
119 public static final Charset UTF8 = Charset.forName("utf-8");
121 public static FastStringSerializer2 INSTANCE = new FastStringSerializer2();
123 public FastStringSerializer2() {
124 super(FastStringBinding.INSTANCE);
127 static byte[] writeUTF(String str) throws IOException {
129 int strlen = str.length();
133 /* use charAt instead of copying String to char array */
134 for (int i = 0; i < strlen; i++) {
136 if ((c >= 0x0001) && (c <= 0x007F)) {
138 } else if (c > 0x07FF) {
146 throw new UTFDataFormatException(
147 "encoded string too long: " + utflen + " bytes");
153 bytearr = new byte[utflen+1];
154 bytearr[byteIndex++] = ((byte)utflen);
158 if(utflen < 0x4000) {
159 bytearr = new byte[utflen+2];
160 bytearr[byteIndex++] = (byte)( ((utflen&0x3f) | 0x80) );
161 bytearr[byteIndex++] = (byte)( (utflen>>>6) );
165 if(utflen < 0x200000) {
166 bytearr = new byte[utflen+3];
167 bytearr[byteIndex++] = (byte)( ((utflen&0x1f) | 0xc0) );
168 bytearr[byteIndex++] = (byte)( ((utflen>>>5)&0xff) );
169 bytearr[byteIndex++] = (byte)( ((utflen>>>13)&0xff) );
173 if(utflen < 0x10000000) {
174 bytearr = new byte[utflen+4];
175 bytearr[byteIndex++] = (byte)( ((utflen&0x0f) | 0xe0) );
176 bytearr[byteIndex++] = (byte)( ((utflen>>>4)&0xff) );
177 bytearr[byteIndex++] = (byte)( ((utflen>>>12)&0xff) );
178 bytearr[byteIndex++] = (byte)( ((utflen>>>20)&0xff) );
181 utflen -= 0x10000000;
182 bytearr = new byte[utflen+5];
183 bytearr[byteIndex++] = (byte)( ((utflen&0x07) | 0xf0) );
184 bytearr[byteIndex++] = (byte)( ((utflen>>>3)&0xff) );
185 bytearr[byteIndex++] = (byte)( ((utflen>>>11)&0xff) );
186 bytearr[byteIndex++] = (byte)( ((utflen>>>19)&0xff) );
187 bytearr[byteIndex++] = (byte)( ((utflen>>>27)&0xff) );
195 for (i=0; i<strlen; i++) {
197 if (!((c >= 0x0001) && (c <= 0x007F))) break;
198 bytearr[byteIndex++] = (byte)(c);
201 for (;i < strlen; i++){
203 if ((c >= 0x0001) && (c <= 0x007F)) {
204 bytearr[byteIndex++] = (byte)( c );
205 } else if (c > 0x07FF) {
206 bytearr[byteIndex++] = (byte)(0xE0 | ((c >> 12) & 0x0F));
207 bytearr[byteIndex++] = (byte)(0x80 | ((c >> 6) & 0x3F));
208 bytearr[byteIndex++] = (byte)(0x80 | ((c >> 0) & 0x3F));
210 bytearr[byteIndex++] = (byte)(0xC0 | ((c >> 6) & 0x1F));
211 bytearr[byteIndex++] = (byte)(0x80 | ((c >> 0) & 0x3F));
220 public byte[] serialize(Object obj) throws IOException {
222 return writeUTF((String)obj);
223 } catch (IOException e) {
224 throw new SerializationException();
233 public byte[] serialize(Object obj) throws IOException {
235 return writeUTF((String)obj);
236 } catch (IOException e) {
237 throw new SerializationException();
242 // private static byte bytearr[] = new byte[80];
243 // private static char chararr[] = new char[80];
245 public final static String readUTF(byte[] bytearr) throws IOException {
249 // int utflen = (bytearr[0] << 8) + bytearr[1];
251 // char[] chararr = new char[utflen*2];
253 // int c, char2, char3;
255 // int chararr_count=0;
257 //// in.readFully(bytearr, 0, utflen);
259 // while (count < utflen + 2) {
260 // c = (int) bytearr[count] & 0xff;
261 // if (c > 127) break;
263 // chararr[chararr_count++]=(char)c;
266 // while (count < utflen) {
267 // c = (int) bytearr[count] & 0xff;
269 // case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
272 // chararr[chararr_count++]=(char)c;
275 // /* 110x xxxx 10xx xxxx*/
277 // if (count > utflen)
278 // throw new UTFDataFormatException(
279 // "malformed input: partial character at end");
280 // char2 = (int) bytearr[count-1];
281 // if ((char2 & 0xC0) != 0x80)
282 // throw new UTFDataFormatException(
283 // "malformed input around byte " + count);
284 // chararr[chararr_count++]=(char)(((c & 0x1F) << 6) |
288 // /* 1110 xxxx 10xx xxxx 10xx xxxx */
290 // if (count > utflen)
291 // throw new UTFDataFormatException(
292 // "malformed input: partial character at end");
293 // char2 = (int) bytearr[count-2];
294 // char3 = (int) bytearr[count-1];
295 // if (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80))
296 // throw new UTFDataFormatException(
297 // "malformed input around byte " + (count-1));
298 // chararr[chararr_count++]=(char)(((c & 0x0F) << 12) |
299 // ((char2 & 0x3F) << 6) |
300 // ((char3 & 0x3F) << 0));
303 // /* 10xx xxxx, 1111 xxxx */
304 // throw new UTFDataFormatException(
305 // "malformed input around byte " + count);
308 // if(chararr_count == 2*utflen) {
309 // // The number of chars produced may be less than utflen
310 // return new String(chararr);
312 // // The number of chars produced may be less than utflen
313 // return new String(chararr, 0, chararr_count);
319 public Object deserialize(byte[] data) throws IOException {
320 return readUTF(data);
321 //return new String(data, UTF8);
326 public static class FastStringBinding extends StringBindingDefault {
328 public static FastStringBinding INSTANCE = new FastStringBinding();
330 public FastStringBinding() {
331 super(Datatypes.STRING);
335 public Serializer serializer() {
336 return FastStringSerializer.INSTANCE;
341 public static WriteOnlyResultRequest<Resource> writeOnly(final String name, final int[] sizes) throws DatabaseException {
342 return writeOnly(name, sizes, null);
345 public static WriteOnlyResultRequest<Resource> writeOnly(final String name, final int[] sizes, VirtualGraph graph) throws DatabaseException {
347 return new WriteOnlyResultRequest<Resource>(graph) {
350 public Resource perform(WriteOnlyGraph graph) throws DatabaseException {
352 //Binding binding = Bindings.STRING;
353 // Serializer serializer = Bindings.STRING.serializer();
354 Serializer serializer = FastStringSerializer2.INSTANCE;
355 Session session = graph.getService(Session.class);
356 Layer0 b = Layer0.getInstance(session);
358 graph.flushCluster();
360 ClusterBuilder builder = graph.getService(ClusterBuilder.class);
361 SerialisationSupport ss = graph.getService(SerialisationSupport.class);
363 ResourceHandle hasNameR = builder.resource(b.HasName);
364 ResourceHandle nameOfR = builder.resource(b.NameOf);
365 ResourceHandle consistsOfR = builder.resource(b.ConsistsOf);
366 ResourceHandle partOfR = builder.resource(b.PartOf);
367 ResourceHandle instanceOfR = builder.resource(b.InstanceOf);
368 ResourceHandle libraryR = builder.resource(b.Library);
369 ResourceHandle ontologyR = builder.resource(b.Ontology);
370 ResourceHandle stringR = builder.resource(b.String);
372 StatementHandle instanceOf = builder.newStatement(instanceOfR, libraryR);
373 StatementHandle instanceOf2 = builder.newStatement(instanceOfR, ontologyR);
374 StatementHandle instanceOfString = builder.newStatement(instanceOfR, stringR);
376 ResourceHandle root = builder.newResource();
377 root.addStatement(instanceOf);
379 ResourceHandle rootLiteral = builder.newResource();
380 rootLiteral.addStatement(instanceOfString);
381 rootLiteral.addStatement(nameOfR, root);
382 rootLiteral.addValue(name, serializer);
383 root.addStatement(hasNameR, rootLiteral);
385 // System.out.println("root: " + root.resource());
386 // System.out.println("literal: " + rootLiteral.resource());
388 // graph.addLiteral(root, b.HasName, b.NameOf, b.String, name, binding);
389 // graph.claim(root, b.InstanceOf, null, b.Library);
391 StatementHandle rootPart = builder.newStatement(partOfR, root);
393 for(int i=0;i<sizes[0];i++) {
395 // long duration2 = System.nanoTime() - start;
396 // System.err.println("Writetime: " + 1e-9*duration2);
398 builder.newCluster();
400 ResourceHandle level1 = builder.newResource();
401 ResourceHandle level1Literal = builder.newResource();
403 level1Literal.addStatement(instanceOfString);
404 level1.addStatement(hasNameR, level1Literal);
405 level1Literal.addStatement(nameOfR, level1);
406 root.addStatement(consistsOfR, level1);
407 level1Literal.addValue(name, serializer);
408 level1.addStatement(instanceOf);
409 level1.addStatement(rootPart);
411 StatementHandle level1Part = builder.newStatement(partOfR, level1);
413 // Resource level1 = graph.newResource();
414 // graph.addLiteral(level1, b.HasName, b.NameOf, b.String, name, binding);
415 // graph.claim(level1, b.InstanceOf, null, b.Library);
416 // graph.claim(level1, b.PartOf, b.ConsistsOf, root);
418 for(int j=0;j<sizes[1];j++) {
420 ResourceHandle level2 = builder.newResource();
421 ResourceHandle level2Literal = builder.newResource();
423 level2.addStatement(hasNameR, level2Literal);
424 level2.addStatement(instanceOf);
425 level2.addStatement(level1Part);
426 level1.addStatement(consistsOfR, level2);
428 level2Literal.addStatement(instanceOfString);
429 level2Literal.addStatement(nameOfR, level2);
430 level2Literal.addValue(name, serializer);
432 StatementHandle level2Part = builder.newStatement(partOfR, level2);
434 // Resource level2 = graph.newResource();
435 // graph.addLiteral(level2, b.HasName, b.NameOf, b.String, name, binding);
436 // graph.claim(level2, b.InstanceOf, null, b.Library);
437 // graph.claim(level2, b.PartOf, b.ConsistsOf, level1);
439 for(int k=0;k<sizes[2];k++) {
441 ResourceHandle level3 = builder.newResource();
442 ResourceHandle level3Literal = builder.newResource();
444 level3.addStatement(hasNameR, level3Literal);
445 level3.addStatement(instanceOf2);
446 level3.addStatement(level2Part);
447 level2.addStatement(consistsOfR, level3);
449 level3Literal.addStatement(instanceOfString);
450 level3Literal.addStatement(nameOfR, level3);
451 level3Literal.addValue(name, serializer);
459 // long duration = System.nanoTime() - start;
460 // System.err.println("Writetime: " + 1e-9*duration);
462 return root.resource(ss);
471 static int quick = 0;
473 public static WriteOnlyResultRequest<Resource> writeOnly2(final String name, final int[] sizes) throws DatabaseException {
474 return writeOnly2(name, sizes, null);
477 public static WriteOnlyResultRequest<Resource> writeOnly2(final String name, final int[] sizes, VirtualGraph graph) throws DatabaseException {
479 return new WriteOnlyResultRequest<Resource>(graph) {
482 public Resource perform(WriteOnlyGraph graph) throws DatabaseException {
484 Binding binding = Bindings.STRING;
486 Session session = graph.getService(Session.class);
487 Layer0 b = Layer0.getInstance(session);
489 Resource root = graph.newResource();
490 graph.addLiteral(root, b.HasName, b.NameOf, b.String, name, binding);
491 graph.claim(root, b.InstanceOf, null, b.Library);
493 for(int i=0;i<sizes[0];i++) {
495 Resource level1 = graph.newResource();
496 graph.addLiteral(level1, b.HasName, b.NameOf, b.String, name, binding);
497 graph.claim(level1, b.InstanceOf, null, b.Library);
498 graph.claim(level1, b.PartOf, b.ConsistsOf, root);
500 for(int j=0;j<sizes[1];j++) {
502 Resource level2 = graph.newResource();
503 graph.addLiteral(level2, b.HasName, b.NameOf, b.String, name, binding);
504 graph.claim(level2, b.InstanceOf, null, b.Library);
505 graph.claim(level2, b.PartOf, b.ConsistsOf, level1);
507 for(int k=0;k<sizes[2];k++) {
509 Resource level3 = graph.newResource();
510 graph.addLiteral(level3, b.HasName, b.NameOf, b.String, name, binding);
511 graph.claim(level3, b.InstanceOf, null, b.Library);
512 graph.claim(level3, b.PartOf, b.ConsistsOf, level2);
528 public static WriteResultRequest<Resource> write(final String name, final int[] sizes) throws DatabaseException {
529 return write(name, sizes, null);
532 public static WriteResultRequest<Resource> write(final String name, final int[] sizes, VirtualGraph graph) throws DatabaseException {
534 return new WriteResultRequest<Resource>(graph) {
537 public Resource perform(WriteGraph graph) throws DatabaseException {
539 Binding binding = Bindings.STRING;
541 Session session = graph.getService(Session.class);
542 Layer0 b = Layer0.getInstance(session);
544 Resource root = graph.newResource();
545 graph.addLiteral(root, b.HasName, b.NameOf, b.String, name, binding);
546 graph.claim(root, b.InstanceOf, null, b.Library);
548 for(int i=0;i<sizes[0];i++) {
550 Resource level1 = graph.newResource();
551 graph.addLiteral(level1, b.HasName, b.NameOf, b.String, name, binding);
552 graph.claim(level1, b.InstanceOf, null, b.Library);
553 graph.claim(level1, b.PartOf, b.ConsistsOf, root);
555 for(int j=0;j<sizes[1];j++) {
557 Resource level2 = graph.newResource();
558 graph.addLiteral(level2, b.HasName, b.NameOf, b.String, name, binding);
559 graph.claim(level2, b.InstanceOf, null, b.Library);
560 graph.claim(level2, b.PartOf, b.ConsistsOf, level1);
562 for(int k=0;k<sizes[2];k++) {
564 Resource level3 = graph.newResource();
565 graph.addLiteral(level3, b.HasName, b.NameOf, b.String, name, binding);
566 graph.claim(level3, b.InstanceOf, null, b.Library);
567 graph.claim(level3, b.PartOf, b.ConsistsOf, level2);
583 public static WriteResultRequest<Resource> write2(final String name, final int[] sizes) throws DatabaseException {
584 return write(name, sizes, null);
587 public static WriteResultRequest<Resource> write2(final String name, final int[] sizes, VirtualGraph graph) throws DatabaseException {
589 return new WriteResultRequest<Resource>(graph) {
592 public Resource perform(WriteGraph graph) throws DatabaseException {
594 Binding binding = Bindings.STRING;
596 Session session = graph.getService(Session.class);
597 Layer0 b = Layer0.getInstance(session);
599 Resource root = graph.newResource();
600 graph.claimLiteral(root, b.HasName, name, binding);
601 graph.claim(root, b.InstanceOf, null, b.Library);
603 for(int i=0;i<sizes[0];i++) {
605 Resource level1 = graph.newResource();
606 graph.claimLiteral(level1, b.HasName, name, binding);
607 graph.claim(level1, b.InstanceOf, null, b.Library);
608 graph.claim(level1, b.PartOf, root);
610 for(int j=0;j<sizes[1];j++) {
612 Resource level2 = graph.newResource();
613 graph.claimLiteral(level2, b.HasName, name, binding);
614 graph.claim(level2, b.InstanceOf, null, b.Library);
615 graph.claim(level2, b.PartOf, level1);
617 for(int k=0;k<sizes[2];k++) {
619 Resource level3 = graph.newResource();
620 graph.claimLiteral(level3, b.HasName, name, binding);
621 graph.claim(level3, b.InstanceOf, null, b.Library);
622 graph.claim(level3, b.PartOf, level2);
638 public static Read<Object> readSync(final Resource resource) throws DatabaseException {
640 return new ReadRequest() {
642 private void readChildren(ReadGraph graph, Resource resource) throws DatabaseException {
643 // System.err.println("child=" + resource);
644 Layer0 L0 = Layer0.getInstance(graph);
645 String name = graph.getPossibleRelatedValue(resource, L0.HasName, Bindings.STRING);
646 // System.err.println("name=" + name);
647 for(Resource child : graph.getObjects(resource, L0.ConsistsOf)) {
648 readChildren(graph, child);
653 public void run(ReadGraph graph) throws DatabaseException {
654 readChildren(graph, resource);
661 public static Read<Object> readSync2(final Resource resource) throws DatabaseException {
663 return new ReadRequest() {
665 private void readChildren(ReadGraph graph, Resource resource) throws DatabaseException {
666 Layer0 L0 = Layer0.getInstance(graph);
667 for(Resource child : graph.getObjects(resource, L0.ConsistsOf)) {
668 graph.getPossibleRelatedValue(child, L0.HasName);
669 readChildren(graph, child);
674 public void run(ReadGraph graph) throws DatabaseException {
675 readChildren(graph, resource);
683 final private static boolean VALIDATE = false;
685 public static Vector<String> validation = new Vector<String>();
686 public static Vector<String> criteria = new Vector<String>();
688 public static void validate() throws AssumptionException {
689 if(VALIDATE) if(!validation.equals(criteria)) {
690 for(String s : validation) System.err.println("-'" + s + "'");
691 throw new AssumptionException("");
695 public static AsyncRead<Object> readAsync(final Resource resource) {
698 for(int i=0;i<244*64*64;i++) criteria.add("name");
704 final SyncMultiProcedure<Resource> structure;
705 final SyncProcedure<String> names;
707 Process(ReadGraph graph, Resource resource) throws DatabaseException {
709 final Layer0 L0 = Layer0.getInstance(graph);
710 final DirectQuerySupport dqs = graph.getService(DirectQuerySupport.class);
711 final QueryControl control = graph.getService(QueryControl.class);
713 names = dqs.compilePossibleRelatedValue(graph, L0.HasName, new SyncProcedure<String>() {
716 public void execute(ReadGraph graph, String name) {
717 if(VALIDATE) validation.add(name);
718 // System.err.println("af=" + name);
722 public void exception(ReadGraph graph, Throwable throwable) {
723 throwable.printStackTrace();
728 structure = dqs.compileForEachObject(graph, L0.ConsistsOf, new SyncMultiProcedure<Resource>() {
731 public void execute(ReadGraph graph, Resource child) {
732 //if(control.scheduleByCluster(graph, child, this)) {
733 dqs.forEachObjectCompiled(graph, child, structure);
734 dqs.forPossibleRelatedValueCompiled(graph, child, names);
739 public void finished(ReadGraph graph) {
743 public void exception(ReadGraph graph, Throwable throwable) {
744 throwable.printStackTrace();
749 dqs.forEachObjectCompiled(graph, resource, structure);
750 dqs.forPossibleRelatedValueCompiled(graph, resource, names);
756 return new AsyncReadRequest() {
759 public void run(AsyncReadGraph graph) {
762 new Process(graph, resource);
763 } catch (DatabaseException e) {
773 public static void readAsyncLoop2(AsyncReadGraph graph, Layer0 L0, Resource resource, AsyncMultiProcedure<Resource> procedure, AsyncProcedure<String> procedure2) {
774 graph.forEachObject(resource, L0.ConsistsOf, procedure);
775 graph.forPossibleRelatedValue(resource, L0.HasName, FastStringBinding.INSTANCE, procedure2);
778 public static AsyncReadRequest readAsync2(final Resource resource) {
780 return new AsyncReadRequest() {
783 public void run(AsyncReadGraph graph) {
785 final Layer0 L0 = Layer0.getInstance(graph);
789 final AsyncProcedure<String> names = new AsyncProcedure<String>() {
792 public void execute(AsyncReadGraph graph, String name) {
796 public void exception(AsyncReadGraph graph, Throwable throwable) {
797 throwable.printStackTrace();
802 readAsyncLoop2(graph, L0, resource, new AsyncMultiProcedure<Resource>() {
805 public void execute(AsyncReadGraph graph, Resource child) {
806 readAsyncLoop2(graph, L0, child, this, names);
810 public void finished(AsyncReadGraph graph) {
814 public void exception(AsyncReadGraph graph, Throwable throwable) {
815 throwable.printStackTrace();
820 } catch (Exception e) {
832 static int names = 0;
834 public static void readAsyncTypesLoop(final DirectQuerySupport dqs, final Layer0 L0, AsyncReadGraph graph, final Resource resource, final RelationInfo consistsOf, final AsyncMultiProcedure<Resource> procedure, final RelationInfo name, final Serializer serializer, final AsyncProcedure<String> procedure2) {
836 dqs.forPossibleDirectType(graph, resource, dqs, new SyncContextProcedure<DirectQuerySupport, Resource>() {
839 public void execute(ReadGraph graph, DirectQuerySupport dqs, Resource type) {
841 // System.err.println("affa");
844 graph.syncRequest(new TypeSetAndString(type), new SyncProcedure<Pair<Set<Resource>, String>>() {
847 public void execute(ReadGraph graph, Pair<Set<Resource>, String> typeInfo) {
849 Set<Resource> types = typeInfo.first;
850 if(types.contains(L0.Ontology)) {
852 // dqs.forPossibleRelatedValue(graph, resource, name, serializer, new AsyncProcedure<String>() {
855 // public void execute(AsyncReadGraph graph, String result) {
856 //// if(names++ % 1000 == 0) System.err.println("names=" + names + "(" + result + ")");
860 // public void exception(AsyncReadGraph graph, Throwable throwable) {
865 } else if (types.contains(L0.Library)) {
866 //dqs.forEachObject(graph, resource, consistsOf, procedure);
872 public void exception(ReadGraph graph, Throwable throwable) {
876 } catch (DatabaseException e) {
883 public void exception(ReadGraph graph, Throwable throwable) {
891 public static Read<Object> readAsyncTypes(final Resource resource) {
893 return new ReadRequest() {
896 public void run(ReadGraph graph) {
898 final Layer0 L0 = Layer0.getInstance(graph);
902 // graph.syncRequest(new TypeSetAndString(L0.Library), new TransientCacheListener<Pair<Set<Resource>, String>>());
903 // graph.syncRequest(new TypeSetAndString(L0.Ontology), new TransientCacheListener<Pair<Set<Resource>, String>>());
905 final DirectQuerySupport dqs = graph.getService(DirectQuerySupport.class);
906 final RelationInfo consistsOf = graph.syncRequest(new AsyncRead<RelationInfo>() {
909 public void perform(AsyncReadGraph graph, AsyncProcedure<RelationInfo> procedure) {
911 RelationInfo ri = dqs.getRelationInfo(graph, L0.ConsistsOf);
912 procedure.execute(graph, ri);
913 } catch (DatabaseException e) {
914 procedure.exception(graph, e);
919 public int threadHash() {
924 public int getFlags() {
929 final RelationInfo name = graph.syncRequest(new AsyncRead<RelationInfo>() {
932 public void perform(AsyncReadGraph graph, AsyncProcedure<RelationInfo> procedure) {
934 RelationInfo ri = dqs.getRelationInfo(graph, L0.HasName);
935 procedure.execute(graph, ri);
936 } catch (DatabaseException e) {
937 procedure.exception(graph, e);
942 public int threadHash() {
947 public int getFlags() {
953 final Serializer serializer = FastStringSerializer.INSTANCE;//Bindings.getSerializerUnchecked( Bindings.STRING );
955 final AsyncProcedure<String> names = new AsyncProcedure<String>() {
958 public void execute(AsyncReadGraph graph, String name) {
959 // System.out.println("exec: " + name);
963 public void exception(AsyncReadGraph graph, Throwable throwable) {
964 throwable.printStackTrace();
969 // readAsyncLoop(dqs, graph, resource, new AsyncMultiProcedure<Resource>() {
972 // public void execute(AsyncReadGraph graph, Resource child) {
973 // readAsyncTypesLoop(dqs, L0, graph, child, consistsOf, this, name, serializer, names);
977 // public void finished(AsyncReadGraph graph) {
981 // public void exception(AsyncReadGraph graph, Throwable throwable) {
982 // throwable.printStackTrace();
985 // }, name, serializer, names);
987 } catch (Exception e) {