X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.db.impl%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fimpl%2Fquery%2FQueryDeserializer.java;fp=bundles%2Forg.simantics.db.impl%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fimpl%2Fquery%2FQueryDeserializer.java;h=0fe9b9c1e83855dab46929fea8bf1704952ff11b;hp=0000000000000000000000000000000000000000;hb=e460fd6f0af60314e2ca28391ef7ff2043016d97;hpb=fe29fd8956c3881e261ec4eee1cdd2ac27bc0554 diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryDeserializer.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryDeserializer.java new file mode 100644 index 000000000..0fe9b9c1e --- /dev/null +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryDeserializer.java @@ -0,0 +1,227 @@ +package org.simantics.db.impl.query; + +import java.lang.reflect.InvocationTargetException; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; + +import org.simantics.db.ObjectResourceIdMap; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.impl.ClusterBase; +import org.simantics.db.impl.ClusterSupport; +import org.simantics.db.impl.ClusterTraitsBase; +import org.simantics.db.service.Bytes; +import org.slf4j.LoggerFactory; + +import gnu.trove.map.hash.TIntLongHashMap; + +public class QueryDeserializer { + + private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(QueryDeserializer.class); + + QueryCache qc; + QuerySupport qs; + ClusterSupport cs; + + private byte[] bytes; + private int byteIndex; + + private TIntLongHashMap clusterKeys = new TIntLongHashMap(); + private Map ids = new HashMap(); + + public QueryDeserializer(QueryProcessor qp, byte[] bytes) { + this.qc = qp.cache; + this.qs = qp.querySupport; + this.cs = qs.getClusterSupport();; + this.bytes = bytes; + } + + public byte readByte() { + return bytes[byteIndex++]; + } + + public int readLE4() { + int result = Bytes.readLE4(bytes, byteIndex); + byteIndex += 4; + return result; + } + + public long readLE8() { + long result = Bytes.readLE8(bytes, byteIndex); + byteIndex += 8; + return result; + } + + public byte[] readBytes(int len) { + byte[] result = Arrays.copyOfRange(bytes, byteIndex, byteIndex+len); + byteIndex += len; + return result; + } + + public void readHeaders() { + int idsSize = readLE4(); + for(int i=0;i clazz = (Class)getClass().getClassLoader().loadClass(id + "Factory"); + QueryFactory qf = clazz.getDeclaredConstructor().newInstance(); + ids.put(key, qf); + } catch (ClassNotFoundException e) { + LOGGER.error("Error while resolving QueryFactory", e); + } catch (InstantiationException e) { + LOGGER.error("Error while resolving QueryFactory", e); + } catch (IllegalAccessException e) { + LOGGER.error("Error while resolving QueryFactory", e); + } catch (IllegalArgumentException e) { + LOGGER.error("Error while resolving QueryFactory", e); + } catch (InvocationTargetException e) { + LOGGER.error("Error while resolving QueryFactory", e); + } catch (NoSuchMethodException e) { + LOGGER.error("Error while resolving QueryFactory", e); + } catch (SecurityException e) { + LOGGER.error("Error while resolving QueryFactory", e); + } + } + int clusterKeysSize = readLE4(); + for(int i=0;i createChildMap() { + return qs.createChildMap(); + } + + AssertedPredicates readAssertedPredicates() throws DatabaseException { + int r = readResource(); + return qc.getOrCreateAssertedPredicates(r); + } + + AssertedStatements readAssertedStatements() throws DatabaseException { + int r1 = readResource(); + int r2 = readResource(); + return qc.getOrCreateAssertedStatements(r1, r2); + } + + ChildMap readChildMap() throws DatabaseException { + int r = readResource(); + return qc.getOrCreateChildMap(r); + } + + DirectObjects readDirectObjects() throws DatabaseException { + int r1 = readResource(); + int r2 = readResource(); + return qc.getOrCreateDirectObjects(r1, r2); + } + + DirectPredicates readDirectPredicates() throws DatabaseException { + int r = readResource(); + return qc.getOrCreateDirectPredicates(r); + } + + Objects readObjects() throws DatabaseException { + int r1 = readResource(); + int r2 = readResource(); + return qc.getOrCreateObjects(r1, r2); + } + + OrderedSet readOrderedSet() throws DatabaseException { + int r = readResource(); + return qc.getOrCreateOrderedSet(r); + } + + Predicates readPredicates() throws DatabaseException { + int r = readResource(); + return qc.getOrCreatePredicates(r); + } + + PrincipalTypes readPrincipalTypes() throws DatabaseException { + int r = readResource(); + return qc.getOrCreatePrincipalTypes(r); + } + + RelationInfoQuery readRelationInfoQuery() throws DatabaseException { + int r = readResource(); + return qc.getOrCreateRelationInfoQuery(r); + } + + Statements readStatements() throws DatabaseException { + int r1 = readResource(); + int r2 = readResource(); + return qc.getOrCreateStatements(r1, r2); + } + + SuperRelations readSuperRelations() throws DatabaseException { + int r = readResource(); + return qc.getOrCreateSuperRelations(r); + } + + SuperTypes readSuperTypes() throws DatabaseException { + int r = readResource(); + return qc.getOrCreateSuperTypes(r); + } + + TypeHierarchy readTypeHierarchy() throws DatabaseException { + int r = readResource(); + return qc.getOrCreateTypeHierarchy(r); + } + + Types readTypes() throws DatabaseException { + int r = readResource(); + return qc.getOrCreateTypes(r); + } + + URIToResource readURIToResource() throws DatabaseException { + String s = readString(); + return qc.getOrCreateURIToResource(s); + } + + ValueQuery readValueQuery() throws DatabaseException { + int r = readResource(); + return qc.getOrCreateValueQuery(r); + } + +}