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); } }