X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.procore%2Fsrc%2Ffi%2Fvtt%2Fsimantics%2Fprocore%2Finternal%2FDirectQuerySupportImpl.java;h=5f6c722acfdffa0d721b71b600cb8be99d51533e;hb=f7eeabfa90e5ac105c0abc192669d6d05d90fb8a;hp=0b640861e1d6af93255b25114c429b2f374ce54f;hpb=d9d9949910e7e7b2917d41e2cd2e64d00055bd23;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/DirectQuerySupportImpl.java b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/DirectQuerySupportImpl.java index 0b640861e..5f6c722ac 100644 --- a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/DirectQuerySupportImpl.java +++ b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/DirectQuerySupportImpl.java @@ -35,6 +35,13 @@ import org.simantics.db.service.DirectQuerySupport; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +/** + * Note that the direct value retrieval in this implementation only supports + * String-type literals - nothing else! + * + * This implementation is mainly intended for optimizing database indexing + * performance. + */ public class DirectQuerySupportImpl implements DirectQuerySupport { private static final Logger LOGGER = LoggerFactory.getLogger(DirectQuerySupportImpl.class); @@ -559,6 +566,7 @@ public class DirectQuerySupportImpl implements DirectQuerySupport { } + @SuppressWarnings("unchecked") private void getValue4(final ReadGraphImpl graph, final ClusterImpl containerCluster, final int subject, final ForPossibleRelatedValueProcedure procedure) { Object result = null; @@ -653,6 +661,7 @@ public class DirectQuerySupportImpl implements DirectQuerySupport { } + @SuppressWarnings("unchecked") private void getValue4(final ReadGraphImpl graph, final ClusterImpl containerCluster, final int subject, final C context, final ForPossibleRelatedValueContextProcedure procedure) { Object result = null; @@ -891,7 +900,8 @@ public class DirectQuerySupportImpl implements DirectQuerySupport { try { byte[] bytes = cluster.getValue(subject, session.clusterTranslator); - T value = (T)utf(bytes); + @SuppressWarnings("unchecked") + T value = (T)utf(bytes, 0); procedure.execute(graph, context, value); } catch (DatabaseException e) { procedure.execute(graph, context, null); @@ -905,7 +915,8 @@ public class DirectQuerySupportImpl implements DirectQuerySupport { try { byte[] bytes = cluster.getValue(subject, session.clusterTranslator); - T value = (T)utf(bytes); + @SuppressWarnings("unchecked") + T value = (T)utf(bytes, 0); procedure.execute(graph, value); } catch (DatabaseException e) { procedure.execute(graph, null); @@ -922,7 +933,8 @@ public class DirectQuerySupportImpl implements DirectQuerySupport { if(bytes == null) { procedure.execute(graph, context, null); } else { - T value = (T)utf(bytes); + @SuppressWarnings("unchecked") + T value = (T)utf(bytes, 0); procedure.execute(graph, context, value); } } catch (DatabaseException e) { @@ -934,38 +946,42 @@ public class DirectQuerySupportImpl implements DirectQuerySupport { } private void getDirectValue4(final ReadGraphImpl graph, final ClusterSmall cluster, final int subject, final ForPossibleRelatedValueProcedure procedure) { + try { + // Note: this code avoids creating an intermediate byte[] + // to store the encoded string bytes and reads the UTF string + // from the value table byte[] directly into String instead. - ResourceTableSmall rt = cluster.resourceTable; - ValueTableSmall vt = cluster.valueTable; - - byte[] bs = vt.table; - long[] ls = rt.table; + ResourceTableSmall rt = cluster.resourceTable; + ValueTableSmall vt = cluster.valueTable; - int index = ((subject&0xFFFF) << 1) - 1 + rt.offset; + byte[] bs = vt.table; + long[] ls = rt.table; - int valueIndex = (int)(ls[index] >>> 24) & 0x3FFFFF + vt.offset; + int index = ((subject&0xFFF) << 1) - 1 + rt.offset; + int valueIndex = ((int)(ls[index] >>> 24) & 0x3FFFFF) + vt.offset; - int size = (int)bs[valueIndex++]-1; - char[] chars = new char[size]; - valueIndex++; - for(int i=0;i= 0x80) { if(length >= 0xc0) {