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.ReadRequest;
25 import org.simantics.db.common.request.WriteOnlyResultRequest;
26 import org.simantics.db.common.request.WriteResultRequest;
27 import org.simantics.db.exception.AssumptionException;
28 import org.simantics.db.exception.DatabaseException;
29 import org.simantics.db.procedure.AsyncMultiProcedure;
30 import org.simantics.db.procedure.AsyncProcedure;
31 import org.simantics.db.request.AsyncRead;
32 import org.simantics.db.request.Read;
33 import org.simantics.db.service.ClusterBuilder;
34 import org.simantics.db.service.ClusterBuilder.ResourceHandle;
35 import org.simantics.db.service.ClusterBuilder.StatementHandle;
36 import org.simantics.db.service.DirectQuerySupport;
37 import org.simantics.db.service.QueryControl;
38 import org.simantics.db.service.SerialisationSupport;
39 import org.simantics.db.tests.performance.read.HierarchicalNames.FastStringSerializer.FastStringSerializer2;
40 import org.simantics.layer0.Layer0;
41 import org.simantics.utils.datastructures.Pair;
49 public class HierarchicalNames {
51 public static class FastStringSerializer extends ModifiedUTF8StringSerializer {
53 public static final Charset UTF8 = Charset.forName("utf-8");
55 public static FastStringSerializer INSTANCE = new FastStringSerializer();
57 public FastStringSerializer() {
58 super(FastStringBinding.INSTANCE);
61 static byte[] writeUTF(String str) throws IOException {
63 int strlen = str.length();
67 /* use charAt instead of copying String to char array */
68 for (int i = 0; i < strlen; i++) {
70 if ((c >= 0x0001) && (c <= 0x007F)) {
72 } else if (c > 0x07FF) {
80 throw new UTFDataFormatException(
81 "encoded string too long: " + utflen + " bytes");
83 byte[] bytearr = new byte[utflen+2];
85 bytearr[count++] = (byte) ((utflen >>> 8) & 0xFF);
86 bytearr[count++] = (byte) ((utflen >>> 0) & 0xFF);
89 for (i=0; i<strlen; i++) {
91 if (!((c >= 0x0001) && (c <= 0x007F))) break;
92 bytearr[count++] = (byte) c;
95 for (;i < strlen; i++){
97 if ((c >= 0x0001) && (c <= 0x007F)) {
98 bytearr[count++] = (byte) c;
100 } else if (c > 0x07FF) {
101 bytearr[count++] = (byte) (0xE0 | ((c >> 12) & 0x0F));
102 bytearr[count++] = (byte) (0x80 | ((c >> 6) & 0x3F));
103 bytearr[count++] = (byte) (0x80 | ((c >> 0) & 0x3F));
105 bytearr[count++] = (byte) (0xC0 | ((c >> 6) & 0x1F));
106 bytearr[count++] = (byte) (0x80 | ((c >> 0) & 0x3F));
113 public static class FastStringSerializer2 extends ModifiedUTF8StringSerializer {
115 public static final Charset UTF8 = Charset.forName("utf-8");
117 public static FastStringSerializer2 INSTANCE = new FastStringSerializer2();
119 public FastStringSerializer2() {
120 super(FastStringBinding.INSTANCE);
123 static byte[] writeUTF(String str) throws IOException {
125 int strlen = str.length();
129 /* use charAt instead of copying String to char array */
130 for (int i = 0; i < strlen; i++) {
132 if ((c >= 0x0001) && (c <= 0x007F)) {
134 } else if (c > 0x07FF) {
142 throw new UTFDataFormatException(
143 "encoded string too long: " + utflen + " bytes");
149 bytearr = new byte[utflen+1];
150 bytearr[byteIndex++] = ((byte)utflen);
154 if(utflen < 0x4000) {
155 bytearr = new byte[utflen+2];
156 bytearr[byteIndex++] = (byte)( ((utflen&0x3f) | 0x80) );
157 bytearr[byteIndex++] = (byte)( (utflen>>>6) );
161 if(utflen < 0x200000) {
162 bytearr = new byte[utflen+3];
163 bytearr[byteIndex++] = (byte)( ((utflen&0x1f) | 0xc0) );
164 bytearr[byteIndex++] = (byte)( ((utflen>>>5)&0xff) );
165 bytearr[byteIndex++] = (byte)( ((utflen>>>13)&0xff) );
169 if(utflen < 0x10000000) {
170 bytearr = new byte[utflen+4];
171 bytearr[byteIndex++] = (byte)( ((utflen&0x0f) | 0xe0) );
172 bytearr[byteIndex++] = (byte)( ((utflen>>>4)&0xff) );
173 bytearr[byteIndex++] = (byte)( ((utflen>>>12)&0xff) );
174 bytearr[byteIndex++] = (byte)( ((utflen>>>20)&0xff) );
177 utflen -= 0x10000000;
178 bytearr = new byte[utflen+5];
179 bytearr[byteIndex++] = (byte)( ((utflen&0x07) | 0xf0) );
180 bytearr[byteIndex++] = (byte)( ((utflen>>>3)&0xff) );
181 bytearr[byteIndex++] = (byte)( ((utflen>>>11)&0xff) );
182 bytearr[byteIndex++] = (byte)( ((utflen>>>19)&0xff) );
183 bytearr[byteIndex++] = (byte)( ((utflen>>>27)&0xff) );
191 for (i=0; i<strlen; i++) {
193 if (!((c >= 0x0001) && (c <= 0x007F))) break;
194 bytearr[byteIndex++] = (byte)(c);
197 for (;i < strlen; i++){
199 if ((c >= 0x0001) && (c <= 0x007F)) {
200 bytearr[byteIndex++] = (byte)( c );
201 } else if (c > 0x07FF) {
202 bytearr[byteIndex++] = (byte)(0xE0 | ((c >> 12) & 0x0F));
203 bytearr[byteIndex++] = (byte)(0x80 | ((c >> 6) & 0x3F));
204 bytearr[byteIndex++] = (byte)(0x80 | ((c >> 0) & 0x3F));
206 bytearr[byteIndex++] = (byte)(0xC0 | ((c >> 6) & 0x1F));
207 bytearr[byteIndex++] = (byte)(0x80 | ((c >> 0) & 0x3F));
216 public byte[] serialize(Object obj) throws IOException {
218 return writeUTF((String)obj);
219 } catch (IOException e) {
220 throw new SerializationException();
229 public byte[] serialize(Object obj) throws IOException {
231 return writeUTF((String)obj);
232 } catch (IOException e) {
233 throw new SerializationException();
238 // private static byte bytearr[] = new byte[80];
239 // private static char chararr[] = new char[80];
241 public final static String readUTF(byte[] bytearr) throws IOException {
245 // int utflen = (bytearr[0] << 8) + bytearr[1];
247 // char[] chararr = new char[utflen*2];
249 // int c, char2, char3;
251 // int chararr_count=0;
253 //// in.readFully(bytearr, 0, utflen);
255 // while (count < utflen + 2) {
256 // c = (int) bytearr[count] & 0xff;
257 // if (c > 127) break;
259 // chararr[chararr_count++]=(char)c;
262 // while (count < utflen) {
263 // c = (int) bytearr[count] & 0xff;
265 // case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
268 // chararr[chararr_count++]=(char)c;
271 // /* 110x xxxx 10xx xxxx*/
273 // if (count > utflen)
274 // throw new UTFDataFormatException(
275 // "malformed input: partial character at end");
276 // char2 = (int) bytearr[count-1];
277 // if ((char2 & 0xC0) != 0x80)
278 // throw new UTFDataFormatException(
279 // "malformed input around byte " + count);
280 // chararr[chararr_count++]=(char)(((c & 0x1F) << 6) |
284 // /* 1110 xxxx 10xx xxxx 10xx xxxx */
286 // if (count > utflen)
287 // throw new UTFDataFormatException(
288 // "malformed input: partial character at end");
289 // char2 = (int) bytearr[count-2];
290 // char3 = (int) bytearr[count-1];
291 // if (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80))
292 // throw new UTFDataFormatException(
293 // "malformed input around byte " + (count-1));
294 // chararr[chararr_count++]=(char)(((c & 0x0F) << 12) |
295 // ((char2 & 0x3F) << 6) |
296 // ((char3 & 0x3F) << 0));
299 // /* 10xx xxxx, 1111 xxxx */
300 // throw new UTFDataFormatException(
301 // "malformed input around byte " + count);
304 // if(chararr_count == 2*utflen) {
305 // // The number of chars produced may be less than utflen
306 // return new String(chararr);
308 // // The number of chars produced may be less than utflen
309 // return new String(chararr, 0, chararr_count);
315 public Object deserialize(byte[] data) throws IOException {
316 return readUTF(data);
317 //return new String(data, UTF8);
322 public static class FastStringBinding extends StringBindingDefault {
324 public static FastStringBinding INSTANCE = new FastStringBinding();
326 public FastStringBinding() {
327 super(Datatypes.STRING);
331 public Serializer serializer() {
332 return FastStringSerializer.INSTANCE;
337 public static WriteOnlyResultRequest<Resource> writeOnly(final String name, final int[] sizes) throws DatabaseException {
338 return writeOnly(name, sizes, null);
341 public static WriteOnlyResultRequest<Resource> writeOnly(final String name, final int[] sizes, VirtualGraph graph) throws DatabaseException {
343 return new WriteOnlyResultRequest<Resource>(graph) {
346 public Resource perform(WriteOnlyGraph graph) throws DatabaseException {
348 //Binding binding = Bindings.STRING;
349 // Serializer serializer = Bindings.STRING.serializer();
350 Serializer serializer = FastStringSerializer2.INSTANCE;
351 Session session = graph.getService(Session.class);
352 Layer0 b = Layer0.getInstance(session);
354 graph.flushCluster();
356 ClusterBuilder builder = graph.getService(ClusterBuilder.class);
357 SerialisationSupport ss = graph.getService(SerialisationSupport.class);
359 ResourceHandle hasNameR = builder.resource(b.HasName);
360 ResourceHandle nameOfR = builder.resource(b.NameOf);
361 ResourceHandle consistsOfR = builder.resource(b.ConsistsOf);
362 ResourceHandle partOfR = builder.resource(b.PartOf);
363 ResourceHandle instanceOfR = builder.resource(b.InstanceOf);
364 ResourceHandle libraryR = builder.resource(b.Library);
365 ResourceHandle ontologyR = builder.resource(b.Ontology);
366 ResourceHandle stringR = builder.resource(b.String);
368 StatementHandle instanceOf = builder.newStatement(instanceOfR, libraryR);
369 StatementHandle instanceOf2 = builder.newStatement(instanceOfR, ontologyR);
370 StatementHandle instanceOfString = builder.newStatement(instanceOfR, stringR);
372 ResourceHandle root = builder.newResource();
373 root.addStatement(instanceOf);
375 ResourceHandle rootLiteral = builder.newResource();
376 rootLiteral.addStatement(instanceOfString);
377 rootLiteral.addStatement(nameOfR, root);
378 rootLiteral.addValue(name, serializer);
379 root.addStatement(hasNameR, rootLiteral);
381 // System.out.println("root: " + root.resource());
382 // System.out.println("literal: " + rootLiteral.resource());
384 // graph.addLiteral(root, b.HasName, b.NameOf, b.String, name, binding);
385 // graph.claim(root, b.InstanceOf, null, b.Library);
387 StatementHandle rootPart = builder.newStatement(partOfR, root);
389 for(int i=0;i<sizes[0];i++) {
391 // long duration2 = System.nanoTime() - start;
392 // System.err.println("Writetime: " + 1e-9*duration2);
394 builder.newCluster();
396 ResourceHandle level1 = builder.newResource();
397 ResourceHandle level1Literal = builder.newResource();
399 level1Literal.addStatement(instanceOfString);
400 level1.addStatement(hasNameR, level1Literal);
401 level1Literal.addStatement(nameOfR, level1);
402 root.addStatement(consistsOfR, level1);
403 level1Literal.addValue(name, serializer);
404 level1.addStatement(instanceOf);
405 level1.addStatement(rootPart);
407 StatementHandle level1Part = builder.newStatement(partOfR, level1);
409 // Resource level1 = graph.newResource();
410 // graph.addLiteral(level1, b.HasName, b.NameOf, b.String, name, binding);
411 // graph.claim(level1, b.InstanceOf, null, b.Library);
412 // graph.claim(level1, b.PartOf, b.ConsistsOf, root);
414 for(int j=0;j<sizes[1];j++) {
416 ResourceHandle level2 = builder.newResource();
417 ResourceHandle level2Literal = builder.newResource();
419 level2.addStatement(hasNameR, level2Literal);
420 level2.addStatement(instanceOf);
421 level2.addStatement(level1Part);
422 level1.addStatement(consistsOfR, level2);
424 level2Literal.addStatement(instanceOfString);
425 level2Literal.addStatement(nameOfR, level2);
426 level2Literal.addValue(name, serializer);
428 StatementHandle level2Part = builder.newStatement(partOfR, level2);
430 // Resource level2 = graph.newResource();
431 // graph.addLiteral(level2, b.HasName, b.NameOf, b.String, name, binding);
432 // graph.claim(level2, b.InstanceOf, null, b.Library);
433 // graph.claim(level2, b.PartOf, b.ConsistsOf, level1);
435 for(int k=0;k<sizes[2];k++) {
437 ResourceHandle level3 = builder.newResource();
438 ResourceHandle level3Literal = builder.newResource();
440 level3.addStatement(hasNameR, level3Literal);
441 level3.addStatement(instanceOf2);
442 level3.addStatement(level2Part);
443 level2.addStatement(consistsOfR, level3);
445 level3Literal.addStatement(instanceOfString);
446 level3Literal.addStatement(nameOfR, level3);
447 level3Literal.addValue(name, serializer);
455 // long duration = System.nanoTime() - start;
456 // System.err.println("Writetime: " + 1e-9*duration);
458 return root.resource(ss);
467 static int quick = 0;
469 public static WriteOnlyResultRequest<Resource> writeOnly2(final String name, final int[] sizes) throws DatabaseException {
470 return writeOnly2(name, sizes, null);
473 public static WriteOnlyResultRequest<Resource> writeOnly2(final String name, final int[] sizes, VirtualGraph graph) throws DatabaseException {
475 return new WriteOnlyResultRequest<Resource>(graph) {
478 public Resource perform(WriteOnlyGraph graph) throws DatabaseException {
480 Binding binding = Bindings.STRING;
482 Session session = graph.getService(Session.class);
483 Layer0 b = Layer0.getInstance(session);
485 Resource root = graph.newResource();
486 graph.addLiteral(root, b.HasName, b.NameOf, b.String, name, binding);
487 graph.claim(root, b.InstanceOf, null, b.Library);
489 for(int i=0;i<sizes[0];i++) {
491 Resource level1 = graph.newResource();
492 graph.addLiteral(level1, b.HasName, b.NameOf, b.String, name, binding);
493 graph.claim(level1, b.InstanceOf, null, b.Library);
494 graph.claim(level1, b.PartOf, b.ConsistsOf, root);
496 for(int j=0;j<sizes[1];j++) {
498 Resource level2 = graph.newResource();
499 graph.addLiteral(level2, b.HasName, b.NameOf, b.String, name, binding);
500 graph.claim(level2, b.InstanceOf, null, b.Library);
501 graph.claim(level2, b.PartOf, b.ConsistsOf, level1);
503 for(int k=0;k<sizes[2];k++) {
505 Resource level3 = graph.newResource();
506 graph.addLiteral(level3, b.HasName, b.NameOf, b.String, name, binding);
507 graph.claim(level3, b.InstanceOf, null, b.Library);
508 graph.claim(level3, b.PartOf, b.ConsistsOf, level2);
524 public static WriteResultRequest<Resource> write(final String name, final int[] sizes) throws DatabaseException {
525 return write(name, sizes, null);
528 public static WriteResultRequest<Resource> write(final String name, final int[] sizes, VirtualGraph graph) throws DatabaseException {
530 return new WriteResultRequest<Resource>(graph) {
533 public Resource perform(WriteGraph graph) throws DatabaseException {
535 Binding binding = Bindings.STRING;
537 Session session = graph.getService(Session.class);
538 Layer0 b = Layer0.getInstance(session);
540 Resource root = graph.newResource();
541 graph.addLiteral(root, b.HasName, b.NameOf, b.String, name, binding);
542 graph.claim(root, b.InstanceOf, null, b.Library);
544 for(int i=0;i<sizes[0];i++) {
546 Resource level1 = graph.newResource();
547 graph.addLiteral(level1, b.HasName, b.NameOf, b.String, name, binding);
548 graph.claim(level1, b.InstanceOf, null, b.Library);
549 graph.claim(level1, b.PartOf, b.ConsistsOf, root);
551 for(int j=0;j<sizes[1];j++) {
553 Resource level2 = graph.newResource();
554 graph.addLiteral(level2, b.HasName, b.NameOf, b.String, name, binding);
555 graph.claim(level2, b.InstanceOf, null, b.Library);
556 graph.claim(level2, b.PartOf, b.ConsistsOf, level1);
558 for(int k=0;k<sizes[2];k++) {
560 Resource level3 = graph.newResource();
561 graph.addLiteral(level3, b.HasName, b.NameOf, b.String, name, binding);
562 graph.claim(level3, b.InstanceOf, null, b.Library);
563 graph.claim(level3, b.PartOf, b.ConsistsOf, level2);
579 public static WriteResultRequest<Resource> write2(final String name, final int[] sizes) throws DatabaseException {
580 return write(name, sizes, null);
583 public static WriteResultRequest<Resource> write2(final String name, final int[] sizes, VirtualGraph graph) throws DatabaseException {
585 return new WriteResultRequest<Resource>(graph) {
588 public Resource perform(WriteGraph graph) throws DatabaseException {
590 Binding binding = Bindings.STRING;
592 Session session = graph.getService(Session.class);
593 Layer0 b = Layer0.getInstance(session);
595 Resource root = graph.newResource();
596 graph.claimLiteral(root, b.HasName, name, binding);
597 graph.claim(root, b.InstanceOf, null, b.Library);
599 for(int i=0;i<sizes[0];i++) {
601 Resource level1 = graph.newResource();
602 graph.claimLiteral(level1, b.HasName, name, binding);
603 graph.claim(level1, b.InstanceOf, null, b.Library);
604 graph.claim(level1, b.PartOf, root);
606 for(int j=0;j<sizes[1];j++) {
608 Resource level2 = graph.newResource();
609 graph.claimLiteral(level2, b.HasName, name, binding);
610 graph.claim(level2, b.InstanceOf, null, b.Library);
611 graph.claim(level2, b.PartOf, level1);
613 for(int k=0;k<sizes[2];k++) {
615 Resource level3 = graph.newResource();
616 graph.claimLiteral(level3, b.HasName, name, binding);
617 graph.claim(level3, b.InstanceOf, null, b.Library);
618 graph.claim(level3, b.PartOf, level2);
634 public static Read<Object> readSync(final Resource resource) throws DatabaseException {
636 return new ReadRequest() {
638 private void readChildren(ReadGraph graph, Resource resource) throws DatabaseException {
639 // System.err.println("child=" + resource);
640 Layer0 L0 = Layer0.getInstance(graph);
641 String name = graph.getPossibleRelatedValue(resource, L0.HasName, Bindings.STRING);
642 // System.err.println("name=" + name);
643 for(Resource child : graph.getObjects(resource, L0.ConsistsOf)) {
644 readChildren(graph, child);
649 public void run(ReadGraph graph) throws DatabaseException {
650 readChildren(graph, resource);
657 public static Read<Object> readSync2(final Resource resource) throws DatabaseException {
659 return new ReadRequest() {
661 private void readChildren(ReadGraph graph, Resource resource) throws DatabaseException {
662 Layer0 L0 = Layer0.getInstance(graph);
663 for(Resource child : graph.getObjects(resource, L0.ConsistsOf)) {
664 graph.getPossibleRelatedValue(child, L0.HasName);
665 readChildren(graph, child);
670 public void run(ReadGraph graph) throws DatabaseException {
671 readChildren(graph, resource);
679 final private static boolean VALIDATE = false;
681 public static Vector<String> validation = new Vector<String>();
682 public static Vector<String> criteria = new Vector<String>();
684 public static void validate() throws AssumptionException {
685 if(VALIDATE) if(!validation.equals(criteria)) {
686 for(String s : validation) System.err.println("-'" + s + "'");
687 throw new AssumptionException("");
691 public static Read<Object> readAsync(final Resource resource) {
694 for(int i=0;i<244*64*64;i++) criteria.add("name");
700 final AsyncMultiProcedure<Resource> structure;
701 final AsyncProcedure<String> names;
703 Process(ReadGraph graph, Resource resource) {
705 final Layer0 L0 = Layer0.getInstance(graph);
706 final DirectQuerySupport dqs = graph.getService(DirectQuerySupport.class);
707 final QueryControl control = graph.getService(QueryControl.class);
709 names = dqs.compilePossibleRelatedValue(graph, L0.HasName, new AsyncProcedure<String>() {
712 public void execute(AsyncReadGraph graph, String name) {
713 if(VALIDATE) validation.add(name);
714 // System.err.println("af=" + name);
718 public void exception(AsyncReadGraph graph, Throwable throwable) {
719 throwable.printStackTrace();
724 structure = dqs.compileForEachObject(graph, L0.ConsistsOf, new AsyncMultiProcedure<Resource>() {
727 public void execute(AsyncReadGraph graph, Resource child) {
728 if(control.scheduleByCluster(graph, child, this)) {
729 dqs.forEachObjectCompiled(graph, child, structure);
730 dqs.forPossibleRelatedValueCompiled(graph, child, names);
735 public void finished(AsyncReadGraph graph) {
739 public void exception(AsyncReadGraph graph, Throwable throwable) {
740 throwable.printStackTrace();
745 dqs.forEachObjectCompiled(graph, resource, structure);
746 dqs.forPossibleRelatedValueCompiled(graph, resource, names);
752 return new ReadRequest() {
755 public void run(ReadGraph graph) {
757 new Process(graph, resource);
765 public static void readAsyncLoop2(AsyncReadGraph graph, Layer0 L0, Resource resource, AsyncMultiProcedure<Resource> procedure, AsyncProcedure<String> procedure2) {
766 graph.forEachObject(resource, L0.ConsistsOf, procedure);
767 graph.forPossibleRelatedValue(resource, L0.HasName, FastStringBinding.INSTANCE, procedure2);
770 public static ReadRequest readAsync2(final Resource resource) {
772 return new ReadRequest() {
775 public void run(ReadGraph graph) {
777 final Layer0 L0 = Layer0.getInstance(graph);
781 final AsyncProcedure<String> names = new AsyncProcedure<String>() {
784 public void execute(AsyncReadGraph graph, String name) {
788 public void exception(AsyncReadGraph graph, Throwable throwable) {
789 throwable.printStackTrace();
794 readAsyncLoop2(graph, L0, resource, new AsyncMultiProcedure<Resource>() {
797 public void execute(AsyncReadGraph graph, Resource child) {
798 readAsyncLoop2(graph, L0, child, this, names);
802 public void finished(AsyncReadGraph graph) {
806 public void exception(AsyncReadGraph graph, Throwable throwable) {
807 throwable.printStackTrace();
812 } catch (Exception e) {
824 static int names = 0;
826 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) {
828 dqs.forPossibleType(graph, resource, new AsyncProcedure<Resource>() {
831 public void execute(AsyncReadGraph graph, Resource type) {
833 // System.err.println("affa");
835 graph.asyncRequest(new TypeSetAndString(type), new AsyncProcedure<Pair<Set<Resource>, String>>() {
838 public void execute(AsyncReadGraph graph, Pair<Set<Resource>, String> typeInfo) {
840 Set<Resource> types = typeInfo.first;
841 if(types.contains(L0.Ontology)) {
843 // dqs.forPossibleRelatedValue(graph, resource, name, serializer, new AsyncProcedure<String>() {
846 // public void execute(AsyncReadGraph graph, String result) {
847 //// if(names++ % 1000 == 0) System.err.println("names=" + names + "(" + result + ")");
851 // public void exception(AsyncReadGraph graph, Throwable throwable) {
856 } else if (types.contains(L0.Library)) {
857 //dqs.forEachObject(graph, resource, consistsOf, procedure);
863 public void exception(AsyncReadGraph graph, Throwable throwable) {
871 public void exception(AsyncReadGraph graph, Throwable throwable) {
879 public static Read<Object> readAsyncTypes(final Resource resource) {
881 return new ReadRequest() {
884 public void run(ReadGraph graph) {
886 final Layer0 L0 = Layer0.getInstance(graph);
890 // graph.syncRequest(new TypeSetAndString(L0.Library), new TransientCacheListener<Pair<Set<Resource>, String>>());
891 // graph.syncRequest(new TypeSetAndString(L0.Ontology), new TransientCacheListener<Pair<Set<Resource>, String>>());
893 final DirectQuerySupport dqs = graph.getService(DirectQuerySupport.class);
894 final RelationInfo consistsOf = graph.syncRequest(new AsyncRead<RelationInfo>() {
897 public void perform(AsyncReadGraph graph, AsyncProcedure<RelationInfo> procedure) {
898 dqs.forRelationInfo(graph, L0.ConsistsOf, procedure);
902 public int threadHash() {
907 public int getFlags() {
912 final RelationInfo name = graph.syncRequest(new AsyncRead<RelationInfo>() {
915 public void perform(AsyncReadGraph graph, AsyncProcedure<RelationInfo> procedure) {
916 dqs.forRelationInfo(graph, L0.HasName, procedure);
920 public int threadHash() {
925 public int getFlags() {
931 final Serializer serializer = FastStringSerializer.INSTANCE;//Bindings.getSerializerUnchecked( Bindings.STRING );
933 final AsyncProcedure<String> names = new AsyncProcedure<String>() {
936 public void execute(AsyncReadGraph graph, String name) {
937 // System.out.println("exec: " + name);
941 public void exception(AsyncReadGraph graph, Throwable throwable) {
942 throwable.printStackTrace();
947 // readAsyncLoop(dqs, graph, resource, new AsyncMultiProcedure<Resource>() {
950 // public void execute(AsyncReadGraph graph, Resource child) {
951 // readAsyncTypesLoop(dqs, L0, graph, child, consistsOf, this, name, serializer, names);
955 // public void finished(AsyncReadGraph graph) {
959 // public void exception(AsyncReadGraph graph, Throwable throwable) {
960 // throwable.printStackTrace();
963 // }, name, serializer, names);
965 } catch (Exception e) {