1 package fi.vtt.simantics.procore.internal;
3 import org.simantics.db.AsyncReadGraph;
4 import org.simantics.db.DirectStatements;
5 import org.simantics.db.ReadGraph;
6 import org.simantics.db.RelationInfo;
7 import org.simantics.db.Resource;
8 import org.simantics.db.common.procedure.wrapper.NoneToAsyncProcedure;
9 import org.simantics.db.common.procedure.wrapper.SyncToAsyncProcedure;
10 import org.simantics.db.exception.DatabaseException;
11 import org.simantics.db.exception.NoSingleResultException;
12 import org.simantics.db.impl.ClusterI;
13 import org.simantics.db.impl.ClusterI.ClusterTypeEnum;
14 import org.simantics.db.impl.ForEachObjectContextProcedure;
15 import org.simantics.db.impl.ForEachObjectProcedure;
16 import org.simantics.db.impl.ForPossibleRelatedValueContextProcedure;
17 import org.simantics.db.impl.ForPossibleRelatedValueProcedure;
18 import org.simantics.db.impl.ResourceImpl;
19 import org.simantics.db.impl.TransientGraph;
20 import org.simantics.db.impl.graph.ReadGraphImpl;
21 import org.simantics.db.procedure.AsyncContextMultiProcedure;
22 import org.simantics.db.procedure.AsyncContextProcedure;
23 import org.simantics.db.procedure.AsyncMultiProcedure;
24 import org.simantics.db.procedure.AsyncProcedure;
25 import org.simantics.db.procedure.Procedure;
26 import org.simantics.db.procedure.SyncProcedure;
27 import org.simantics.db.procore.cluster.ClusterBig;
28 import org.simantics.db.procore.cluster.ClusterImpl;
29 import org.simantics.db.procore.cluster.ClusterSmall;
30 import org.simantics.db.procore.cluster.ResourceTableSmall;
31 import org.simantics.db.procore.cluster.ValueTableSmall;
32 import org.simantics.db.request.AsyncRead;
33 import org.simantics.db.service.DirectQuerySupport;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
37 public class DirectQuerySupportImpl implements DirectQuerySupport {
39 private static final Logger LOGGER = LoggerFactory.getLogger(DirectQuerySupportImpl.class);
41 final private SessionImplSocket session;
43 DirectQuerySupportImpl(SessionImplSocket session) {
44 this.session = session;
48 final public void forEachDirectPersistentStatement(AsyncReadGraph graph, final Resource subject, final AsyncProcedure<DirectStatements> procedure) {
49 ReadGraphImpl impl = (ReadGraphImpl)graph;
50 impl.processor.forEachDirectStatement(impl, subject, procedure, true);
54 final public void forEachDirectStatement(AsyncReadGraph graph, final Resource subject, final AsyncProcedure<DirectStatements> procedure) {
55 ReadGraphImpl impl = (ReadGraphImpl)graph;
56 impl.processor.forEachDirectStatement(impl, subject, procedure, false);
60 public void forEachDirectStatement(AsyncReadGraph graph, Resource subject, SyncProcedure<DirectStatements> procedure) {
61 forEachDirectStatement(graph, subject, new SyncToAsyncProcedure<DirectStatements>(procedure));
65 public void forEachDirectStatement(AsyncReadGraph graph, Resource subject, Procedure<DirectStatements> procedure) {
66 ReadGraphImpl impl = (ReadGraphImpl)graph;
67 impl.processor.forEachDirectStatement(impl, subject, procedure);
71 public void forRelationInfo(AsyncReadGraph graph, Resource subject, AsyncProcedure<RelationInfo> procedure) {
72 ReadGraphImpl impl = (ReadGraphImpl)graph;
73 impl.processor.forRelationInfo(impl, subject, procedure);
77 public void forRelationInfo(AsyncReadGraph graph, Resource subject, SyncProcedure<RelationInfo> procedure) {
78 forRelationInfo(graph, subject, new SyncToAsyncProcedure<RelationInfo>(procedure));
82 public void forRelationInfo(AsyncReadGraph graph, Resource subject, Procedure<RelationInfo> procedure) {
83 forRelationInfo(graph, subject, new NoneToAsyncProcedure<RelationInfo>(procedure));
87 public AsyncMultiProcedure<Resource> compileForEachObject(ReadGraph graph, final Resource relation, AsyncMultiProcedure<Resource> user) {
90 RelationInfo info = graph.syncRequest(new AsyncRead<RelationInfo>() {
93 public void perform(AsyncReadGraph graph, AsyncProcedure<RelationInfo> procedure) {
94 forRelationInfo(graph, relation, procedure);
98 public int threadHash() {
103 public int getFlags() {
108 final int predicateKey = ((ResourceImpl)relation).id;
109 return new ForEachObjectProcedure(predicateKey, info, session.queryProvider2, user);
110 } catch (DatabaseException e) {
117 public <C> AsyncContextMultiProcedure<C, Resource> compileForEachObject(ReadGraph graph, final Resource relation, AsyncContextMultiProcedure<C, Resource> user) {
120 RelationInfo info = graph.syncRequest(new AsyncRead<RelationInfo>() {
123 public void perform(AsyncReadGraph graph, AsyncProcedure<RelationInfo> procedure) {
124 forRelationInfo(graph, relation, procedure);
128 public int threadHash() {
133 public int getFlags() {
138 final int predicateKey = ((ResourceImpl)relation).id;
139 return new ForEachObjectContextProcedure<C>(predicateKey, info, session.queryProvider2, user);
140 } catch (DatabaseException e) {
147 public <T> AsyncProcedure<T> compilePossibleRelatedValue(ReadGraph graph, final Resource relation, AsyncProcedure<T> user) {
150 RelationInfo info = graph.syncRequest(new AsyncRead<RelationInfo>() {
153 public void perform(AsyncReadGraph graph, AsyncProcedure<RelationInfo> procedure) {
154 forRelationInfo(graph, relation, procedure);
158 public int threadHash() {
163 public int getFlags() {
168 final int predicateKey = ((ResourceImpl)relation).id;
169 return new ForPossibleRelatedValueProcedure<T>(predicateKey, info, user);
170 } catch (DatabaseException e) {
177 public <C, T> AsyncContextProcedure<C, T> compilePossibleRelatedValue(ReadGraph graph, final Resource relation, AsyncContextProcedure<C, T> user) {
180 RelationInfo info = graph.syncRequest(new AsyncRead<RelationInfo>() {
183 public void perform(AsyncReadGraph graph, AsyncProcedure<RelationInfo> procedure) {
184 forRelationInfo(graph, relation, procedure);
188 public int threadHash() {
193 public int getFlags() {
198 final int predicateKey = ((ResourceImpl)relation).id;
199 return new ForPossibleRelatedValueContextProcedure<C, T>(predicateKey, info, user);
200 } catch (DatabaseException e) {
207 public void forEachObjectCompiled(AsyncReadGraph graph, Resource subject, final AsyncMultiProcedure<Resource> procedure) {
209 assert(subject != null);
211 final ForEachObjectProcedure proc = (ForEachObjectProcedure)procedure;
212 // final RelationInfo info = proc.info;
214 final ReadGraphImpl impl = (ReadGraphImpl)graph;
215 final int subjectId = ((ResourceImpl)subject).id;
217 // int callerThread = impl.callerThread;
218 // int suggestSchedule = (subjectId>>16) & queryProvider2.THREAD_MASK;
222 // if(callerThread == suggestSchedule) {
224 // if(info.isFunctional) {
225 // querySupport.getObjects4(impl, subjectId, proc);
227 session.querySupport.getObjects4(impl, subjectId, proc);
232 // impl.state.barrier.inc();
233 // impl.state.barrier.dec(callerThread);
235 // queryProvider2.schedule(callerThread, new SessionTask(suggestSchedule) {
238 // public void run(int thread) {
240 // impl.state.barrier.inc(thread);
241 // impl.state.barrier.dec();
243 // if(info.isFunctional) {
244 // querySupport.getObjects4(impl.newAsync(thread), subjectId, proc);
246 // querySupport.getObjects4(impl.newAsync(thread), subjectId, proc);
252 // public String toString() {
263 public <C> void forEachObjectCompiled(AsyncReadGraph graph, Resource subject, C context, final AsyncContextMultiProcedure<C, Resource> procedure) {
265 assert(subject != null);
267 final ForEachObjectContextProcedure<C> proc = (ForEachObjectContextProcedure<C>)procedure;
268 final RelationInfo info = proc.info;
270 final ReadGraphImpl impl = (ReadGraphImpl)graph;
271 final int subjectId = ((ResourceImpl)subject).id;
273 // int callerThread = impl.callerThread;
274 // int suggestSchedule = (subjectId>>16) & queryProvider2.THREAD_MASK;
278 if(info.isFunctional) {
279 session.querySupport.getObjects4(impl, subjectId, context, proc);
281 session.querySupport.getObjects4(impl, subjectId, context, proc);
287 public <T> void forPossibleRelatedValueCompiled(AsyncReadGraph graph, Resource subject, final AsyncProcedure<T> procedure) {
289 assert(subject != null);
291 final ForPossibleRelatedValueProcedure<T> proc = (ForPossibleRelatedValueProcedure<T>)procedure;
292 final RelationInfo info = proc.info;
294 final ReadGraphImpl impl = (ReadGraphImpl)graph;
295 final int subjectId = ((ResourceImpl)subject).id;
297 // int callerThread = impl.callerThread;
298 // int suggestSchedule = (subjectId>>16) & session.queryProvider2.THREAD_MASK;
302 // if(callerThread == suggestSchedule) {
304 if(info.isFunctional) {
305 getRelatedValue4(impl, subjectId, proc);
307 getRelatedValue4(impl, subjectId, proc);
312 // impl.state.barrier.inc();
313 // impl.state.barrier.dec(callerThread);
315 // queryProvider2.schedule(callerThread, new SessionTask(suggestSchedule) {
318 // public void run(int thread) {
320 // impl.state.barrier.inc(thread);
321 // impl.state.barrier.dec();
323 // if(info.isFunctional) {
324 // getRelatedValue4(impl.newAsync(thread), subjectId, proc);
326 // getRelatedValue4(impl.newAsync(thread), subjectId, proc);
332 // public String toString() {
343 public <C, T> void forPossibleRelatedValueCompiled(AsyncReadGraph graph, Resource subject, C context, final AsyncContextProcedure<C, T> procedure) {
345 assert(subject != null);
347 final ForPossibleRelatedValueContextProcedure<C, T> proc = (ForPossibleRelatedValueContextProcedure<C, T>)procedure;
348 final RelationInfo info = proc.info;
350 final ReadGraphImpl impl = (ReadGraphImpl)graph;
351 final int subjectId = ((ResourceImpl)subject).id;
353 // int callerThread = impl.callerThread;
354 // int suggestSchedule = (subjectId>>16) & session.queryProvider2.THREAD_MASK;
358 if(info.isFunctional) {
359 getRelatedValue4(impl, subjectId, context, proc);
361 getRelatedValue4(impl, subjectId, context, proc);
367 public <T> void forPossibleType(final AsyncReadGraph graph, Resource subject, final AsyncProcedure<Resource> procedure) {
369 assert(subject != null);
371 final ReadGraphImpl impl = (ReadGraphImpl)graph;
372 final int subjectId = ((ResourceImpl)subject).id;
376 final ClusterI cluster = session.clusterTable.getClusterByResourceKey(subjectId);
377 if(!cluster.isLoaded()) {
379 // impl.state.inc(0);
381 session.queryProvider2.requestCluster(impl, cluster.getClusterId(), new Runnable() {
388 int result = cluster.getCompleteObjectKey(subjectId, session.clusterTranslator);
389 procedure.execute(graph, new ResourceImpl(session.resourceSupport, result));
391 // impl.state.dec(0);
393 } catch (DatabaseException e) {
403 int result = cluster.getCompleteObjectKey(subjectId, session.clusterTranslator);
404 procedure.execute(graph, new ResourceImpl(session.resourceSupport, result));
408 } catch (DatabaseException e) {
417 public <C> void forPossibleDirectType(final AsyncReadGraph graph, Resource subject, final C context, final AsyncContextProcedure<C, Resource> procedure) {
419 assert(subject != null);
421 final ReadGraphImpl impl = (ReadGraphImpl)graph;
422 final int subjectId = ((ResourceImpl)subject).id;
426 final ClusterI cluster = session.clusterTable.getClusterByResourceKey(subjectId);
427 if(!cluster.isLoaded()) {
429 // impl.state.inc(0);
431 session.queryProvider2.requestCluster(impl, cluster.getClusterId(), new Runnable() {
438 ClusterI.CompleteTypeEnum type = cluster.getCompleteType(subjectId, session.clusterTranslator);
439 if(ClusterI.CompleteTypeEnum.InstanceOf == type) {
440 int result = cluster.getCompleteObjectKey(subjectId, session.clusterTranslator);
441 procedure.execute(graph, context, new ResourceImpl(session.resourceSupport, result));
443 procedure.execute(graph, context, null);
446 // impl.state.dec(0);
448 } catch (DatabaseException e) {
458 ClusterI.CompleteTypeEnum type = cluster.getCompleteType(subjectId, session.clusterTranslator);
459 if(ClusterI.CompleteTypeEnum.InstanceOf == type) {
460 int result = cluster.getCompleteObjectKey(subjectId, session.clusterTranslator);
461 procedure.execute(graph, context, new ResourceImpl(session.resourceSupport, result));
463 procedure.execute(graph, context, null);
468 } catch (DatabaseException e) {
470 procedure.execute(graph, context, null);
472 } catch (Throwable t) {
475 procedure.execute(graph, context, null);
482 private <C, T> void getRelatedValue4(final ReadGraphImpl graph, final int subject, final C context, final ForPossibleRelatedValueContextProcedure<C, T> procedure) {
486 final int predicate = procedure.predicateKey;
490 if(!SessionImplSocket.areVirtualStatementsLoaded(session.virtualGraphServerSupport, subject, predicate)) {
491 SessionImplSocket.loadVirtualStatements(session.virtualGraphServerSupport, graph, subject, predicate,
492 g -> getRelatedValue4(g, subject, context, procedure)
497 for(TransientGraph g : session.virtualGraphServerSupport.providers) {
498 for (int id : g.getObjects(subject, predicate)) {
500 procedure.exception(graph, new DatabaseException("Multiple objects"));
511 procedure.exception(graph, new DatabaseException("No objects for " + subject ));
517 getValue4(graph, null, result, context, procedure);
524 final org.simantics.db.procore.cluster.ClusterImpl cluster = session.clusterTable.getClusterByResourceKey(subject);
525 if(!cluster.isLoaded()) {
526 cluster.load(session.clusterTranslator, () -> getRelatedValue4(graph, subject, context, procedure));
530 if(cluster.hasVirtual() && session.virtualGraphServerSupport.virtuals.contains(subject)) {
532 if(!SessionImplSocket.areVirtualStatementsLoaded(session.virtualGraphServerSupport, subject, predicate)) {
533 SessionImplSocket.loadVirtualStatements(session.virtualGraphServerSupport, graph, subject, predicate,
534 g -> getRelatedValue4(g, subject, context, procedure)
539 for(TransientGraph g : session.virtualGraphServerSupport.providers) {
540 for (int id : g.getObjects(subject, predicate)) {
542 procedure.exception(graph, new DatabaseException("Multiple objects"));
551 getRelatedDirectValue4(graph, cluster, subject, result, context, procedure);
555 getRelatedDirectValue4(graph, cluster, subject, 0, context, procedure);
561 private <T> void getValue4(final ReadGraphImpl graph, final ClusterImpl containerCluster, final int subject, final ForPossibleRelatedValueProcedure<T> procedure) {
563 Object result = null;
567 if(!SessionImplSocket.areVirtualStatementsLoaded(session.virtualGraphServerSupport, subject)) {
568 SessionImplSocket.loadVirtualStatements(session.virtualGraphServerSupport, graph, subject,
569 g -> getValue4(g, containerCluster, subject, procedure)
574 for(TransientGraph g : session.virtualGraphServerSupport.providers) {
575 Object value = g.getValue(subject);
578 procedure.exception(graph, new DatabaseException("Multiple values"));
587 procedure.execute(graph, (T)"name");
593 ClusterImpl cluster = containerCluster;
594 if(!containerCluster.contains(subject)) {
595 cluster = session.clusterTable.getClusterByResourceKey(subject);
596 if(!cluster.isLoaded()) {
597 cluster.load(session.clusterTranslator, new Runnable() {
601 getValue4(graph, containerCluster, subject, procedure);
609 if(cluster.hasVirtual() && session.virtualGraphServerSupport.virtuals.contains(subject)) {
611 if(!SessionImplSocket.areVirtualStatementsLoaded(session.virtualGraphServerSupport, subject)) {
612 SessionImplSocket.loadVirtualStatements(session.virtualGraphServerSupport, graph, subject,
613 g -> getValue4(g, containerCluster, subject, procedure)
618 for(TransientGraph g : session.virtualGraphServerSupport.providers) {
619 Object value = g.getValue(subject);
622 procedure.exception(graph, new DatabaseException("Multiple values"));
633 procedure.execute(graph, (T)result);
634 // graph.state.barrier.dec();
638 if(ClusterTypeEnum.SMALL == cluster.getType())
639 getDirectValue4(graph, (ClusterSmall)cluster, subject, procedure);
641 getDirectValue4(graph, (ClusterBig)cluster, subject, procedure);
646 if(ClusterTypeEnum.SMALL == cluster.getType())
647 getDirectValue4(graph, (ClusterSmall)cluster, subject, procedure);
649 getDirectValue4(graph, (ClusterBig)cluster, subject, procedure);
655 private <C, T> void getValue4(final ReadGraphImpl graph, final ClusterImpl containerCluster, final int subject, final C context, final ForPossibleRelatedValueContextProcedure<C, T> procedure) {
657 Object result = null;
661 if(!SessionImplSocket.areVirtualStatementsLoaded(session.virtualGraphServerSupport, subject)) {
662 SessionImplSocket.loadVirtualStatements(session.virtualGraphServerSupport, graph, subject,
663 g -> getValue4(g, containerCluster, subject, context, procedure)
668 for(TransientGraph g : session.virtualGraphServerSupport.providers) {
669 Object value = g.getValue(subject);
672 procedure.exception(graph, new DatabaseException("Multiple values"));
681 procedure.execute(graph, context, (T)"name");
687 ClusterImpl cluster = containerCluster;
688 if(!containerCluster.contains(subject)) {
689 cluster = session.clusterTable.getClusterByResourceKey(subject);
690 if(!cluster.isLoaded()) {
691 cluster.load(session.clusterTranslator, new Runnable() {
695 getValue4(graph, containerCluster, subject, context, procedure);
703 if(cluster.hasVirtual() && session.virtualGraphServerSupport.virtuals.contains(subject)) {
705 if(!SessionImplSocket.areVirtualStatementsLoaded(session.virtualGraphServerSupport, subject)) {
706 SessionImplSocket.loadVirtualStatements(session.virtualGraphServerSupport, graph, subject,
707 g -> getValue4(g, containerCluster, subject, context, procedure)
712 for(TransientGraph g : session.virtualGraphServerSupport.providers) {
713 Object value = g.getValue(subject);
716 procedure.exception(graph, new DatabaseException("Multiple values"));
727 procedure.execute(graph, context, (T)result);
728 // graph.state.barrier.dec();
732 if(ClusterTypeEnum.SMALL == cluster.getType())
733 getDirectValue4(graph, (ClusterSmall)cluster, subject, context, procedure);
735 getDirectValue4(graph, (ClusterBig)cluster, subject, context, procedure);
740 if(ClusterTypeEnum.SMALL == cluster.getType())
741 getDirectValue4(graph, (ClusterSmall)cluster, subject, context, procedure);
743 getDirectValue4(graph, (ClusterBig)cluster, subject, context, procedure);
749 private <T> void getRelatedDirectValue4(final ReadGraphImpl graph, final ClusterImpl cluster, final int subject, final int result, final ForPossibleRelatedValueProcedure<T> procedure) {
753 int so = cluster.getSingleObject(subject, procedure, session.clusterTranslator);
756 procedure.exception(graph, new DatabaseException("No objects " + subject + " " + procedure.predicateKey));
759 getValue4(graph, cluster, result, procedure);
763 getValue4(graph, cluster, so, procedure);
765 procedure.exception(graph, new DatabaseException("Multiple objects"));
770 } catch (DatabaseException e) {
776 private <C, T> void getRelatedDirectValue4(final ReadGraphImpl graph, final ClusterImpl cluster, final int subject, final int result, final C context, final ForPossibleRelatedValueContextProcedure<C, T> procedure) {
780 int so = cluster.getSingleObject(subject, procedure, session.clusterTranslator);
783 procedure.exception(graph, new NoSingleResultException("No objects " + subject + " " + procedure.predicateKey, result));
786 getValue4(graph, cluster, result, context, procedure);
790 getValue4(graph, cluster, so, context, procedure);
792 procedure.exception(graph, new NoSingleResultException("Multiple objects for " + subject + " " + procedure.predicateKey, result));
797 } catch (DatabaseException e) {
798 LOGGER.error("Could not compute related value for subject {} with predicate {}", subject, procedure.predicateKey);
803 public <T> void getRelatedValue4(final ReadGraphImpl graph, final int subject, final ForPossibleRelatedValueProcedure<T> procedure) {
807 final int predicate = procedure.predicateKey;
811 if(!SessionImplSocket.areVirtualStatementsLoaded(session.virtualGraphServerSupport, subject, predicate)) {
812 SessionImplSocket.loadVirtualStatements(session.virtualGraphServerSupport, graph, subject, predicate,
813 g -> getRelatedValue4(g, subject, procedure)
818 for(TransientGraph g : session.virtualGraphServerSupport.providers) {
819 for (int id : g.getObjects(subject, predicate)) {
821 procedure.exception(graph, new DatabaseException("Multiple objects"));
832 procedure.exception(graph, new DatabaseException("No objects for " + subject ));
838 getValue4(graph, null, result, procedure);
845 final org.simantics.db.procore.cluster.ClusterImpl cluster = session.clusterTable.getClusterByResourceKey(subject);
846 if(!cluster.isLoaded()) {
847 cluster.load(session.clusterTranslator, new Runnable() {
851 getRelatedValue4(graph, subject, procedure);
858 if(cluster.hasVirtual() && session.virtualGraphServerSupport.virtuals.contains(subject)) {
860 if(!SessionImplSocket.areVirtualStatementsLoaded(session.virtualGraphServerSupport, subject, predicate)) {
861 SessionImplSocket.loadVirtualStatements(session.virtualGraphServerSupport, graph, subject, predicate,
862 g -> getRelatedValue4(graph, subject, procedure)
867 for(TransientGraph g : session.virtualGraphServerSupport.providers) {
868 for (int id : g.getObjects(subject, predicate)) {
870 procedure.exception(graph, new DatabaseException("Multiple objects"));
879 getRelatedDirectValue4(graph, cluster, subject, result, procedure);
883 getRelatedDirectValue4(graph, cluster, subject, 0, procedure);
889 private <C, T> void getDirectValue4(final ReadGraphImpl graph, final ClusterSmall cluster, final int subject, final C context, final ForPossibleRelatedValueContextProcedure<C, T> procedure) {
892 byte[] bytes = cluster.getValue(subject, session.clusterTranslator);
893 T value = (T)utf(bytes);
894 procedure.execute(graph, context, value);
895 } catch (DatabaseException e) {
896 procedure.execute(graph, context, null);
903 private <T> void getDirectValue4(final ReadGraphImpl graph, final ClusterBig cluster, final int subject, final ForPossibleRelatedValueProcedure<T> procedure) {
906 byte[] bytes = cluster.getValue(subject, session.clusterTranslator);
907 T value = (T)utf(bytes);
908 procedure.execute(graph, value);
909 } catch (DatabaseException e) {
910 procedure.execute(graph, null);
917 private <C, T> void getDirectValue4(final ReadGraphImpl graph, final ClusterBig cluster, final int subject, final C context, final ForPossibleRelatedValueContextProcedure<C, T> procedure) {
920 byte[] bytes = cluster.getValue(subject, session.clusterTranslator);
922 procedure.execute(graph, context, null);
924 T value = (T)utf(bytes);
925 procedure.execute(graph, context, value);
927 } catch (DatabaseException e) {
928 procedure.execute(graph, context, null);
935 private final char[] chars = new char[1024];
937 private <T> void getDirectValue4(final ReadGraphImpl graph, final ClusterSmall cluster, final int subject, final ForPossibleRelatedValueProcedure<T> procedure) {
939 ResourceTableSmall rt = cluster.resourceTable;
940 ValueTableSmall vt = cluster.valueTable;
942 byte[] bs = vt.table;
943 long[] ls = rt.table;
945 int index = ((subject&0xFFFF) << 1) - 1 + rt.offset;
947 int valueIndex = (int)(ls[index] >>> 24) & 0x3FFFFF + vt.offset;
949 int size = (int)bs[valueIndex++]-1;
951 for(int i=0;i<size;i++) {
952 chars[i] = (char)bs[valueIndex++];
955 T value = (T)new String(chars, 0, size);
957 procedure.execute(graph, value);
962 final private String utf(byte[] bytes) {
964 if(bytes == null) return null;
967 int length = bytes[index++]&0xff;
973 length += ((bytes[index++]&0xff)<<3);
974 length += ((bytes[index++]&0xff)<<11);
975 length += ((bytes[index++]&0xff)<<19);
976 length += 0x10204080;
980 length += ((bytes[index++]&0xff)<<4);
981 length += ((bytes[index++]&0xff)<<12);
982 length += ((bytes[index++]&0xff)<<20);
988 length += ((bytes[index++]&0xff)<<5);
989 length += ((bytes[index++]&0xff)<<13);
995 length += ((bytes[index++]&0xff)<<6);
1001 int target = length+index;
1002 while(index < target) {
1003 int c = bytes[index++]&0xff;
1005 chars[i++] = (char)(c&0x7F);
1006 } else if (c > 0x07FF) {
1007 int c2 = bytes[index++]&0xff;
1008 int c3 = bytes[index++]&0xff;
1009 chars[i++] = (char)(((c&0xf)<<12) + ((c2&0x3f)<<6) + (c3&0x3f));
1011 int c2 = bytes[index++]&0xff;
1012 chars[i++] = (char)(((c&0x1f)<<6) + (c2&0x3f));
1016 // if (!((c >= 0x0001) && (c <= 0x007F))) {
1020 // if ((c >= 0x0001) && (c <= 0x007F)) {
1021 // bytearr[byteIndex++] = (byte)( c );
1022 // } else if (c > 0x07FF) {
1023 // bytearr[byteIndex++] = (byte)(0xE0 | ((c >> 12) & 0x0F));
1024 // bytearr[byteIndex++] = (byte)(0x80 | ((c >> 6) & 0x3F));
1025 // bytearr[byteIndex++] = (byte)(0x80 | ((c >> 0) & 0x3F));
1027 // bytearr[byteIndex++] = (byte)(0xC0 | ((c >> 6) & 0x1F));
1028 // bytearr[byteIndex++] = (byte)(0x80 | ((c >> 0) & 0x3F));
1034 return new String(chars, 0, i);