+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management
- * in Industry THTH ry.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * VTT Technical Research Centre of Finland - initial API and implementation
- *******************************************************************************/
-package org.simantics.db.impl.graph;
-
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Set;
-
-import org.simantics.db.Resource;
-import org.simantics.db.impl.query.IntSet;
-import org.simantics.db.impl.query.QuerySupport;
-
-public class ArraySet implements Set<Resource> {
-
- final Resource[] set;
-
- ArraySet(IntSet intSet, QuerySupport support) {
-
- if(intSet.data == null) {
- if(intSet.sizeOrData != IntSet.NO_DATA) {
- set = new Resource[] { support.getResource(intSet.sizeOrData) };
- } else {
- set = Resource.NONE;
- }
- } else {
- set = new Resource[intSet.sizeOrData];
- for(int i=0;i<intSet.sizeOrData;i++) set[i] = support.getResource(intSet.data[i]);
- }
-
- }
-
- @Override
- public boolean add(Resource e) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public boolean addAll(Collection<? extends Resource> c) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public void clear() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public boolean contains(Object o) {
- for(int i=0;i<set.length;i++) if(o.equals(set[i])) return true;
- return false;
- }
-
- @Override
- public boolean containsAll(Collection<?> c) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public boolean isEmpty() {
- return set.length == 0;
- }
-
- @Override
- public Iterator<Resource> iterator() {
-
- class ArraySetIterator implements Iterator<Resource> {
-
- int next = 0;
-
- @Override
- public boolean hasNext() {
- return next < set.length;
- }
-
- @Override
- public Resource next() {
- return set[next++];
- }
-
- @Override
- public void remove() {
- throw new UnsupportedOperationException();
- }
-
- }
-
- return new ArraySetIterator();
-
- }
-
- @Override
- public boolean remove(Object o) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public boolean removeAll(Collection<?> c) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public boolean retainAll(Collection<?> c) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public int size() {
- return set.length;
- }
-
- @Override
- public Object[] toArray() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public <T> T[] toArray(T[] a) {
- throw new UnsupportedOperationException();
- }
-
-}
});
}
-
+
+ @Override
+ public void serializeValue(QuerySerializer serializer) {
+ IntArray is = getResult();
+ is.serialize(serializer);
+ }
+
}
--- /dev/null
+package org.simantics.db.impl.query;
+
+import org.simantics.db.exception.DatabaseException;
+
+public class AssertedPredicatesFactory extends QueryFactoryBase {
+
+ @Override
+ public CacheEntryBase readKeyAndValue(QueryDeserializer deserializer) throws DatabaseException {
+ AssertedPredicates result = reference(deserializer);
+ IntArray ia = IntArray.deserialize(deserializer);
+ result.setResult(ia);
+ result.setReady();
+ return result;
+ }
+
+ @Override
+ public <T extends CacheEntryBase> T reference(QueryDeserializer deserializer) throws DatabaseException {
+ return (T)deserializer.readAssertedPredicates();
+ }
+
+}
--- /dev/null
+package org.simantics.db.impl.query;
+
+import org.simantics.db.exception.DatabaseException;
+
+public class AssertedStatementsFactory extends QueryFactoryBase {
+
+ @Override
+ public CacheEntryBase readKeyAndValue(QueryDeserializer deserializer) throws DatabaseException {
+ AssertedStatements result = reference(deserializer);
+ IntArray ia = IntArray.deserialize(deserializer);
+ result.setResult(ia);
+ result.setReady();
+ return result;
+ }
+
+ @Override
+ public <T extends CacheEntryBase> T reference(QueryDeserializer deserializer) throws DatabaseException {
+ return (T)deserializer.readAssertedStatements();
+ }
+
+}
return graph.processor.cache.performQuery(graph, id, this, procedure);
}
+ @Override
+ public String classId() {
+ return null;
+ }
+
}
}
}
+ @Override
+ public String classId() {
+ return null;
+ }
+
}
abstract public void removeEntry(QueryProcessor provider);
+ @Override
+ public long cluster(QueryProcessor processor) {
+ return processor.cluster(r1());
+ }
+
+ @Override
+ public void serializeKey(QuerySerializer serializer) {
+ serializer.addResource(r1());
+ serializer.addResource(r2());
+ }
+
}
*******************************************************************************/
package org.simantics.db.impl.query;
+import java.util.Collection;
+
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.impl.graph.ReadGraphImpl;
abstract void removeParent(CacheEntry entry);
abstract void addParent(CacheEntry entry);
abstract boolean hasParents();
- abstract Iterable<CacheEntry<?>> getParents(QueryProcessor processor);
+ abstract Collection<CacheEntry<?>> getParents(QueryProcessor processor);
abstract CacheEntry getFirstParent(QueryProcessor processor);
abstract boolean moreThanOneParent(QueryProcessor processor);
abstract int parentCount(QueryProcessor processor);
package org.simantics.db.impl.query;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Iterator;
import org.simantics.databoard.Bindings;
}
@Override
- final public Iterable<CacheEntry<?>> getParents(QueryProcessor processor) {
+ final public Collection<CacheEntry<?>> getParents(QueryProcessor processor) {
ArrayList<CacheEntry<?>> result = new ArrayList<CacheEntry<?>>();
if(p1 != null) result.add(p1);
public CacheEntryBase() {
}
+
+ public String classId() {
+ return getClass().getName();
+ }
+
+ public void serializeKey(QuerySerializer serializer) {
+ throw new IllegalStateException("Cannot serialize query key for " + this);
+ }
+
+ public void serializeValue(QuerySerializer serializer) {
+ throw new IllegalStateException("Cannot serialize query value for " + this);
+ }
+
+ public void serializeParents(QuerySerializer serializer) {
+ Collection<CacheEntry<?>> ps = getParents(serializer.getQueryProcessor());
+ int sizePos = serializer.writeUnknownSize();
+ int actual = 0;
+ for(CacheEntry<?> entry : ps) {
+ CacheEntryBase b = (CacheEntryBase)entry;
+ String cid = b.classId();
+ if(cid == null)
+ continue;
+ serializer.serializeId(b.classId());
+ b.serializeKey(serializer);
+ actual++;
+ }
+ serializer.setUnknownSize(sizePos, actual);
+ }
+
+ public long cluster(QueryProcessor processor) {
+ throw new IllegalStateException("Cannot compute query cluster for " + this);
+ }
+
+ public void serialize(QuerySerializer serializer) {
+ serializer.serializeId(classId());
+ serializeKey(serializer);
+ serializeValue(serializer);
+ serializeParents(serializer);
+ }
}
}
+ @Override
+ public void serializeValue(QuerySerializer serializer) {
+ ObjectResourceIdMap<String> is = getResult();
+ serializer.writeLE(is.size());
+ for(String s : is.keySet()) {
+ serializer.addString(s);
+ serializer.addResource(is.getId(s));
+ }
+ }
+
@Override
public String toString() {
return "ChildMap[" + id + "]";
--- /dev/null
+package org.simantics.db.impl.query;
+
+import org.simantics.db.ObjectResourceIdMap;
+import org.simantics.db.exception.DatabaseException;
+
+public class ChildMapFactory extends QueryFactoryBase {
+
+ @Override
+ public CacheEntryBase readKeyAndValue(QueryDeserializer deserializer) throws DatabaseException {
+ ChildMap result = reference(deserializer);
+ ObjectResourceIdMap<String> map = deserializer.createChildMap();
+ int size = deserializer.readLE4();
+ for(int i=0;i<size;i++) {
+ String key = deserializer.readString();
+ int r2 = deserializer.readResource();
+ map.putId(key, r2);
+ }
+ result.setResult(map);
+ result.setReady();
+ return result;
+ }
+
+ @Override
+ public <T extends CacheEntryBase> T reference(QueryDeserializer deserializer) throws DatabaseException {
+ return (T)deserializer.readChildMap();
+ }
+
+}
*******************************************************************************/
package org.simantics.db.impl.query;
-
-
-
abstract public class CollectionBinaryQuery<T> extends BinaryQuery<T> {
public CollectionBinaryQuery(final int r1, final int r2) {
if(size == 0) setResult(IntArray.EMPTY);
else v.trim();
}
-
+
+ @Override
+ public void serializeValue(QuerySerializer serializer) {
+ IntArray is = getResult();
+ is.serialize(serializer);
+ }
+
}
except(throwable);
}
+ @Override
+ public void serializeValue(QuerySerializer serializer) {
+ IntArray is = getResult();
+ is.serialize(serializer);
+ }
+
}
--- /dev/null
+package org.simantics.db.impl.query;
+
+import org.simantics.db.exception.DatabaseException;
+
+public class DirectObjectsFactory extends QueryFactoryBase {
+
+ @Override
+ public CacheEntryBase readKeyAndValue(QueryDeserializer deserializer) throws DatabaseException {
+ DirectObjects result = reference(deserializer);
+ IntArray ia = IntArray.deserialize(deserializer);
+ result.setResult(ia);
+ result.setReady();
+ return result;
+ }
+
+ @Override
+ public <T extends CacheEntryBase> T reference(QueryDeserializer deserializer) throws DatabaseException {
+ return (T)deserializer.readDirectObjects();
+ }
+
+}
import org.simantics.db.impl.graph.ReadGraphImpl;
import org.simantics.db.impl.procedure.InternalProcedure;
-public final class DirectPredicates extends UnaryQueryP<IntSet> {
+public final class DirectPredicates extends UnaryQueryPIntSet {
DirectPredicates(final int resource) {
super(resource);
--- /dev/null
+package org.simantics.db.impl.query;
+
+import org.simantics.db.exception.DatabaseException;
+
+public class DirectPredicatesFactory extends QueryFactoryBase {
+
+ @Override
+ public CacheEntryBase readKeyAndValue(QueryDeserializer deserializer) throws DatabaseException {
+ DirectPredicates result = reference(deserializer);
+ IntSet is = IntSet.deserialize(deserializer);
+ result.setResult(is);
+ result.setReady();
+ return result;
+ }
+
+ @Override
+ public <T extends CacheEntryBase> T reference(QueryDeserializer deserializer) throws DatabaseException {
+ return (T)deserializer.readDirectPredicates();
+ }
+
+}
public boolean isDisposed() {
return registered && (isDiscarded() || !graph.processor.isBound(this));
}
-
+
+ @Override
+ public String classId() {
+ return null;
+ }
+
}
import java.util.Arrays;
+import org.simantics.db.exception.DatabaseException;
+
final public class IntArray {
}
return result;
}
-
+
+ public void serialize(QuerySerializer serializer) {
+ int size = size();
+ serializer.writeLE(size);
+ if(size == 1) {
+ serializer.addResource(sizeOrData);
+ } else {
+ for(int i=0;i<size;i++)
+ serializer.addResource(data[i]);
+ }
+ }
+
+ public static IntArray deserialize(QueryDeserializer deserializer) throws DatabaseException {
+ int size = deserializer.readLE4();
+ IntArray result = new IntArray();
+ for(int i=0;i<size;i++) {
+ result.add(deserializer.readResource());
+ }
+ return result;
+ }
+
@Override
public boolean equals(Object object) {
if (this == object)
public int[] data;
- /** the index after the last entry in the list */
- public int sizeOrData;
+ private int sizeOrData;
/** the default capacity for new lists */
protected static final int DEFAULT_CAPACITY = 3;
private IntSet() {
support = null;
+ data = null;
+ sizeOrData = NO_DATA;
}
public IntSet(QuerySupport support) {
}
procedure.finished(graph);
}
+
+ public void serialize(QuerySerializer serializer) {
+ serializer.writeLE(size());
+ forEach(new TIntProcedure() {
+
+ @Override
+ public boolean execute(int value) {
+ serializer.addResource(value);
+ return true;
+ }
+ });
+ }
+
+ public static IntSet deserialize(QueryDeserializer deserializer) throws DatabaseException {
+ int size = deserializer.readLE4();
+ IntSet result = new IntSet();
+ for(int i=0;i<size;i++) {
+ result.add(deserializer.readResource());
+ }
+ return result;
+ }
}
\ No newline at end of file
except(throwable);
}
+ @Override
+ public void serializeValue(QuerySerializer serializer) {
+ IntArray is = getResult();
+ is.serialize(serializer);
+ }
+
}
--- /dev/null
+package org.simantics.db.impl.query;
+
+import org.simantics.db.exception.DatabaseException;
+
+public class ObjectsFactory extends QueryFactoryBase {
+
+ @Override
+ public CacheEntryBase readKeyAndValue(QueryDeserializer deserializer) throws DatabaseException {
+ Objects result = reference(deserializer);
+ IntArray ia = IntArray.deserialize(deserializer);
+ result.setResult(ia);
+ result.setReady();
+ return result;
+ }
+
+ @Override
+ public <T extends CacheEntryBase> T reference(QueryDeserializer deserializer) throws DatabaseException {
+ return (T)deserializer.readObjects();
+ }
+
+}
--- /dev/null
+package org.simantics.db.impl.query;
+
+import org.simantics.db.exception.DatabaseException;
+
+public class OrderedSetFactory extends QueryFactoryBase {
+
+ @Override
+ public CacheEntryBase readKeyAndValue(QueryDeserializer deserializer) throws DatabaseException {
+ OrderedSet result = reference(deserializer);
+ IntArray ia = IntArray.deserialize(deserializer);
+ result.setResult(ia);
+ result.setReady();
+ return result;
+ }
+
+ @Override
+ public <T extends CacheEntryBase> T reference(QueryDeserializer deserializer) throws DatabaseException {
+ return (T)deserializer.readOrderedSet();
+ }
+
+}
import gnu.trove.procedure.TIntProcedure;
-final public class Predicates extends UnaryQueryP<IntSet> {
+final public class Predicates extends UnaryQueryPIntSet {
Predicates(final int r) {
super(r);
--- /dev/null
+package org.simantics.db.impl.query;
+
+import org.simantics.db.exception.DatabaseException;
+
+public class PredicatesFactory extends QueryFactoryBase {
+
+ @Override
+ public CacheEntryBase readKeyAndValue(QueryDeserializer deserializer) throws DatabaseException {
+ Predicates result = reference(deserializer);
+ IntSet ia = IntSet.deserialize(deserializer);
+ result.setResult(ia);
+ result.setReady();
+ return result;
+ }
+
+ @Override
+ public <T extends CacheEntryBase> T reference(QueryDeserializer deserializer) throws DatabaseException {
+ return (T)deserializer.readPredicates();
+ }
+
+}
--- /dev/null
+package org.simantics.db.impl.query;
+
+import org.simantics.db.exception.DatabaseException;
+
+public class PrincipalTypesFactory extends QueryFactoryBase {
+
+ @Override
+ public CacheEntryBase readKeyAndValue(QueryDeserializer deserializer) throws DatabaseException {
+ PrincipalTypes result = reference(deserializer);
+ IntArray ia = IntArray.deserialize(deserializer);
+ result.setResult(ia);
+ result.setReady();
+ return result;
+ }
+
+ @Override
+ public <T extends CacheEntryBase> T reference(QueryDeserializer deserializer) throws DatabaseException {
+ return (T)deserializer.readPrincipalTypes();
+ }
+
+}
import java.util.Collection;
import java.util.concurrent.Semaphore;
-import org.simantics.databoard.Bindings;
import org.simantics.db.AsyncReadGraph;
-import org.simantics.db.DevelopmentKeys;
import org.simantics.db.ObjectResourceIdMap;
import org.simantics.db.ReadGraph;
import org.simantics.db.RelationInfo;
-import org.simantics.db.common.utils.Logger;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.impl.graph.ReadGraphImpl;
import org.simantics.db.impl.procedure.InternalProcedure;
import org.simantics.db.request.ExternalRead;
import org.simantics.db.request.MultiRead;
import org.simantics.db.request.Read;
-import org.simantics.utils.Development;
import gnu.trove.map.hash.THashMap;
import gnu.trove.map.hash.TObjectIntHashMap;
static boolean shouldCache(QueryProcessor processor, Object o) {
return false;
}
+
+ AssertedPredicates getOrCreateAssertedPredicates(int r) {
+ AssertedPredicates entry = (AssertedPredicates)assertedPredicatesMap.get(r);
+ if(entry == null) {
+ entry = new AssertedPredicates(r);
+ assertedPredicatesMap.put(keyR(r), entry);
+ }
+ return entry;
+ }
+ AssertedStatements getOrCreateAssertedStatements(int r1, int r2) {
+ AssertedStatements entry = (AssertedStatements)assertedStatementsMap.get(r1, r2);
+ if(entry == null) {
+ entry = new AssertedStatements(r1, r2);
+ assertedStatementsMap.put(keyR2(r1, r2), entry);
+ }
+ return entry;
+ }
+
+ ChildMap getOrCreateChildMap(int r) {
+ ChildMap entry = (ChildMap)childMapMap.get(r);
+ if(entry == null) {
+ entry = new ChildMap(r);
+ childMapMap.put(keyR(r), entry);
+ }
+ return entry;
+ }
+
+ DirectObjects getOrCreateDirectObjects(int r1, int r2) {
+ DirectObjects entry = (DirectObjects)directObjectsMap.get(r1, r2);
+ if(entry == null) {
+ entry = new DirectObjects(r1, r2);
+ directObjectsMap.put(keyR2(r1, r2), entry);
+ }
+ return entry;
+ }
+
+ DirectPredicates getOrCreateDirectPredicates(int r) {
+ DirectPredicates entry = (DirectPredicates)directPredicatesMap.get(r);
+ if(entry == null) {
+ entry = new DirectPredicates(r);
+ directPredicatesMap.put(keyR(r), entry);
+ }
+ return entry;
+ }
+
+ Objects getOrCreateObjects(int r1, int r2) {
+ Objects entry = (Objects)objectsMap.get(r1, r2);
+ if(entry == null) {
+ entry = new Objects(r1, r2);
+ objectsMap.put(keyR2(r1, r2), entry);
+ }
+ return entry;
+ }
+
+ OrderedSet getOrCreateOrderedSet(int r) {
+ OrderedSet entry = (OrderedSet)orderedSetMap.get(r);
+ if(entry == null) {
+ entry = new OrderedSet(r);
+ orderedSetMap.put(keyR(r), entry);
+ }
+ return entry;
+ }
+
+ Predicates getOrCreatePredicates(int r) {
+ Predicates entry = (Predicates)predicatesMap.get(r);
+ if(entry == null) {
+ entry = new Predicates(r);
+ predicatesMap.put(keyR(r), entry);
+ }
+ return entry;
+ }
+
+ PrincipalTypes getOrCreatePrincipalTypes(int r) {
+ PrincipalTypes entry = (PrincipalTypes)principalTypesMap.get(r);
+ if(entry == null) {
+ entry = new PrincipalTypes(r);
+ principalTypesMap.put(keyR(r), entry);
+ }
+ return entry;
+ }
+
+ RelationInfoQuery getOrCreateRelationInfoQuery(int r) {
+ RelationInfoQuery entry = (RelationInfoQuery)relationInfoQueryMap.get(r);
+ if(entry == null) {
+ entry = new RelationInfoQuery(r);
+ relationInfoQueryMap.put(keyR(r), entry);
+ }
+ return entry;
+ }
+
+ Statements getOrCreateStatements(int r1, int r2) {
+ Statements entry = (Statements)statementsMap.get(r1, r2);
+ if(entry == null) {
+ entry = new Statements(r1, r2);
+ statementsMap.put(keyR2(r1, r2), entry);
+ }
+ return entry;
+ }
+
+ SuperRelations getOrCreateSuperRelations(int r) {
+ SuperRelations entry = (SuperRelations)superRelationsMap.get(r);
+ if(entry == null) {
+ entry = new SuperRelations(r);
+ superRelationsMap.put(keyR(r), entry);
+ }
+ return entry;
+ }
+
+ SuperTypes getOrCreateSuperTypes(int r) {
+ SuperTypes entry = (SuperTypes)superTypesMap.get(r);
+ if(entry == null) {
+ entry = new SuperTypes(r);
+ superTypesMap.put(keyR(r), entry);
+ }
+ return entry;
+ }
+
+ TypeHierarchy getOrCreateTypeHierarchy(int r) {
+ TypeHierarchy entry = (TypeHierarchy)typeHierarchyMap.get(r);
+ if(entry == null) {
+ entry = new TypeHierarchy(r);
+ typeHierarchyMap.put(keyR(r), entry);
+ }
+ return entry;
+ }
+
+ Types getOrCreateTypes(int r) {
+ Types entry = (Types)typesMap.get(r);
+ if(entry == null) {
+ entry = new Types(r);
+ typesMap.put(keyR(r), entry);
+ }
+ return entry;
+ }
+
+ URIToResource getOrCreateURIToResource(String s) {
+ URIToResource entry = (URIToResource)uRIToResourceMap.get(s);
+ if(entry == null) {
+ entry = new URIToResource(s);
+ uRIToResourceMap.put(keyID(s), entry);
+ }
+ return entry;
+ }
+
+ ValueQuery getOrCreateValueQuery(int r) {
+ ValueQuery entry = (ValueQuery)valueQueryMap.get(r);
+ if(entry == null) {
+ entry = new ValueQuery(r);
+ valueQueryMap.put(keyR(r), entry);
+ }
+ return entry;
+ }
+
}
\ No newline at end of file
--- /dev/null
+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<Integer,QueryFactory> ids = new HashMap<Integer,QueryFactory>();
+
+ 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<idsSize;i++) {
+ int size = readLE4();
+ byte[] data = readBytes(size);
+ String id = new String(data);
+ int key = readLE4();
+ try {
+ Class<QueryFactory> clazz = (Class<QueryFactory>)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<clusterKeysSize;i++) {
+ long cluster = readLE8();
+ int key = readLE4();
+ clusterKeys.put(key, cluster);
+ }
+ }
+
+ public QueryFactory readFactory() {
+ int key = readLE4();
+ return ids.get(key);
+ }
+
+ public void readQueries() {
+ int count = readLE4();
+ for(int i=0;i<count;i++) {
+ QueryFactory qf = readFactory();
+ try {
+ qf.read(this);
+ } catch (DatabaseException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ public int readResource() throws DatabaseException {
+ int key = readLE4();
+ if(key < 0)
+ return key;
+ int clusterKey = ClusterTraitsBase.getClusterKeyFromResourceKey(key);
+ long cluster = clusterKeys.get(clusterKey);
+ ClusterBase cb = cs.getClusterByClusterId(cluster);
+ return ClusterTraitsBase.createResourceKey(cb.getClusterKey(), ClusterTraitsBase.getResourceIndexFromResourceKey(key));
+ }
+
+ public byte[] readByteArray() {
+ int len = readLE4();
+ if(len == -1)
+ return null;
+ return readBytes(len);
+ }
+
+ public String readString() {
+ return new String(readByteArray());
+ }
+
+ public ObjectResourceIdMap<String> 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);
+ }
+
+}
--- /dev/null
+package org.simantics.db.impl.query;
+
+import org.simantics.db.exception.DatabaseException;
+
+public interface QueryFactory {
+ public CacheEntryBase read(QueryDeserializer deserializer) throws DatabaseException;
+ public <T extends CacheEntryBase> T reference(QueryDeserializer deserializer) throws DatabaseException;
+}
--- /dev/null
+package org.simantics.db.impl.query;
+
+import org.simantics.db.exception.DatabaseException;
+
+abstract public class QueryFactoryBase implements QueryFactory {
+
+ abstract protected CacheEntryBase readKeyAndValue(QueryDeserializer deserializer) throws DatabaseException;
+
+ public void readParents(QueryDeserializer deserializer, CacheEntryBase entry) throws DatabaseException {
+ int ps = deserializer.readLE4();
+ for(int i=0;i<ps;i++) {
+ QueryFactory qf = deserializer.readFactory();
+ CacheEntryBase ceb = qf.reference(deserializer);
+ entry.addParent(ceb);
+ }
+ }
+
+ @Override
+ final public CacheEntryBase read(QueryDeserializer deserializer) throws DatabaseException {
+ CacheEntryBase entry = readKeyAndValue(deserializer);
+ readParents(deserializer, entry);
+ return entry;
+ }
+
+}
*******************************************************************************/
package org.simantics.db.impl.query;
-import gnu.trove.impl.hash.THash;
+import java.util.Collection;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.impl.graph.ReadGraphImpl;
+import gnu.trove.impl.hash.THash;
+
/**
* An open addressed hashing implementation for Object types.
}
@Override
- public Iterable<CacheEntry> getParents(QueryProcessor processor) {
+ public Collection<CacheEntry> getParents(QueryProcessor processor) {
// TODO Auto-generated method stub
return null;
}
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
+import org.eclipse.core.runtime.Platform;
import org.simantics.databoard.Bindings;
import org.simantics.db.AsyncReadGraph;
import org.simantics.db.DevelopmentKeys;
import org.simantics.db.Session;
import org.simantics.db.Statement;
import org.simantics.db.VirtualGraph;
+import org.simantics.db.common.ByteFileReader;
import org.simantics.db.common.procedure.adapter.AsyncMultiProcedureAdapter;
import org.simantics.db.common.utils.Logger;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.request.ExternalRead;
import org.simantics.db.request.MultiRead;
import org.simantics.db.request.RequestFlags;
+import org.simantics.db.service.Bytes;
import org.simantics.layer0.Layer0;
import org.simantics.utils.DataContainer;
import org.simantics.utils.Development;
+import org.simantics.utils.FileUtils;
import org.simantics.utils.datastructures.Pair;
import org.simantics.utils.datastructures.collections.CollectionUtils;
import org.simantics.utils.datastructures.disposable.AbstractDisposable;
}
+ public synchronized void save() throws IOException {
+
+ long start = System.nanoTime();
+
+ Collection<CacheEntryBase> caches = allCaches(new CacheCollectionResult()).toCollection();
+ Map<Long,List<CacheEntryBase>> cachesByCluster = new HashMap<>();
+ for(CacheEntryBase entry : caches) {
+ String clazz = entry.classId();
+ if(clazz == null)
+ continue;
+ long cluster = entry.cluster(this);
+ List<CacheEntryBase> queries = cachesByCluster.get(cluster);
+ if(queries == null) {
+ queries = new ArrayList<>();
+ cachesByCluster.put(cluster, queries);
+ }
+ queries.add(entry);
+ }
+
+ File workspace = Platform.getLocation().toFile();
+ File dir = new File(workspace, "queryData");
+ FileUtils.deleteAll(dir);
+
+ dir.mkdir();
+
+ for(Long cluster : cachesByCluster.keySet()) {
+
+ List<CacheEntryBase> queries = cachesByCluster.get(cluster);
+ QuerySerializer serializer = new QuerySerializer(this);
+ int count = 0;
+ int pos = serializer.writeUnknownSize();
+ for(CacheEntryBase entry : queries) {
+ String clazz = entry.classId();
+ if(clazz == null)
+ continue;
+ try {
+ entry.serialize(serializer);
+ count++;
+ } catch (IllegalStateException e) {
+ System.err.println(e.getMessage());
+ }
+ }
+ serializer.setUnknownSize(pos, count);
+
+ System.err.println(serializer.bytes().length + " bytes for cluster " + cluster);
+ FileUtils.writeFile(new File(dir, "" + cluster + ".queryData"), serializer.bytes());
+
+ }
+
+ long end = System.nanoTime();
+
+ System.err.println("saved queries in " + 1e-6*(end-start) + "ms.");
+
+ }
+
+ public void restore() throws IOException {
+
+ long start = System.nanoTime();
+
+ File workspace = Platform.getLocation().toFile();
+ File dir = new File(workspace, "queryData");
+ dir.mkdir();
+
+ for(File f : FileUtils.listFilesByExtension(dir, "queryData")) {
+ byte[] bytes = FileUtils.readFile(f);
+ QueryDeserializer qd = new QueryDeserializer(this, bytes);
+ qd.readHeaders();
+ qd.readQueries();
+ }
+
+ long end = System.nanoTime();
+
+ System.err.println("restored queries in " + 1e-6*(end-start) + "ms.");
+
+ }
+
boolean removeQuery(CacheEntry entry) {
// This entry has been removed before. No need to do anything here.
}
return result;
}
+
+ public long cluster(int resource) {
+ if(resource <= 0)
+ return 0;
+ return querySupport.getClusterId(resource);
+ }
public void assertDone() {
}
--- /dev/null
+package org.simantics.db.impl.query;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.simantics.db.impl.ClusterTraitsBase;
+
+import gnu.trove.list.array.TByteArrayList;
+import gnu.trove.map.hash.TLongIntHashMap;
+import gnu.trove.procedure.TLongIntProcedure;
+
+public class QuerySerializer {
+
+ private QueryProcessor processor;
+ private QuerySupport querySupport;
+ private TByteArrayList bytes = new TByteArrayList();
+ private TLongIntHashMap clusterKeys = new TLongIntHashMap();
+ private Map<String,Integer> ids = new HashMap<String,Integer>();
+
+ public QuerySerializer(QueryProcessor processor) {
+ this.processor = processor;
+ this.querySupport = processor.querySupport;
+ }
+
+ public int writeUnknownSize() {
+ int pos = bytes.size();
+ bytes.add((byte)0);
+ bytes.add((byte)0);
+ bytes.add((byte)0);
+ bytes.add((byte)0);
+ return pos;
+ }
+
+ public void setUnknownSize(int pos, int value) {
+ bytes.set(pos, (byte) (value & 0xFF));
+ bytes.set(pos+1, (byte) ((value >>> 8) & 0xFF));
+ bytes.set(pos+2, (byte) ((value >>> 16) & 0xFF));
+ bytes.set(pos+3, (byte) ((value >>> 24) & 0xFF));
+ }
+
+ public void serializeId(String classId) {
+ Integer id = ids.get(classId);
+ if(id == null) {
+ id = ids.size() + 1;
+ ids.put(classId, id);
+ }
+ writeLE(id);
+ }
+
+ public void addResource(int r) {
+ if(r < 0) {
+ writeLE(r);
+ } else {
+ long clusterId = querySupport.getClusterId(r);
+ int clusterKey = clusterKeys.get(clusterId);
+ if(clusterKey == 0) {
+ clusterKey = clusterKeys.size() + 1;
+ clusterKeys.put(clusterId, clusterKey);
+ }
+ int i = ClusterTraitsBase.createResourceKeyNoThrow(clusterKey, ClusterTraitsBase.getResourceIndexFromResourceKeyNoThrow(r));
+ writeLE(i);
+ }
+ }
+
+ public void addString(String s) {
+ byte[] b = s.getBytes();
+ writeLE(b.length);
+ bytes.add(b);
+ }
+
+ public void add(byte b) {
+ bytes.add(b);
+ }
+
+ public void add(byte[] bs) {
+ bytes.add(bs);
+ }
+
+ public byte[] bytes() {
+ TByteArrayList header = new TByteArrayList();
+ writeLE(header, ids.size());
+ for(Entry<String,Integer> entry : ids.entrySet()) {
+ String id = entry.getKey();
+ writeLE(header, id.length());
+ header.add(id.getBytes());
+ writeLE(header, entry.getValue());
+ }
+
+ writeLE(header, clusterKeys.size());
+ clusterKeys.forEachEntry(new TLongIntProcedure() {
+
+ @Override
+ public boolean execute(long a, int b) {
+ writeLE(header, a);
+ writeLE(header, b);
+ return true;
+ }
+
+ });
+
+ header.add(bytes.toArray());
+ return header.toArray();
+ }
+
+ public void writeLE(int value) {
+ writeLE(bytes, value);
+ }
+
+ public static void writeLE(TByteArrayList bytes, int value) {
+ bytes.add((byte) (value & 0xFF));
+ bytes.add((byte) ((value >>> 8) & 0xFF));
+ bytes.add((byte) ((value >>> 16) & 0xFF));
+ bytes.add((byte) ((value >>> 24) & 0xFF));
+ }
+
+ public void writeLE(long value) {
+ writeLE(bytes, value);
+ }
+
+ public static void writeLE(TByteArrayList bytes, long value) {
+ bytes.add((byte) (value & 0xFF));
+ bytes.add((byte) ((value >>> 8) & 0xFF));
+ bytes.add((byte) ((value >>> 16) & 0xFF));
+ bytes.add((byte) ((value >>> 24) & 0xFF));
+ bytes.add((byte) ((value >>> 32) & 0xFF));
+ bytes.add((byte) ((value >>> 40) & 0xFF));
+ bytes.add((byte) ((value >>> 48) & 0xFF));
+ bytes.add((byte) ((value >>> 56) & 0xFF));
+ }
+
+ public QueryProcessor getQueryProcessor() {
+ return processor;
+ }
+
+}
import java.io.InputStream;
+import org.simantics.db.ObjectResourceIdMap;
import org.simantics.db.Resource;
import org.simantics.db.Session;
import org.simantics.db.VirtualGraph;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.exception.ResourceNotFoundException;
+import org.simantics.db.impl.ClusterSupport;
import org.simantics.db.impl.graph.ReadGraphImpl;
public interface QuerySupport extends ResourceTranslator {
Session getSession();
-
+
+ ClusterSupport getClusterSupport();
+
+ ObjectResourceIdMap<String> createChildMap();
+
boolean isImmutable(int id);
long getClusterId(int id);
int getId(Resource resource);
except(throwable);
}
+ @Override
+ public String classId() {
+ return null;
+ }
+
}
return RequestFlags.IMMEDIATE_UPDATE;
}
+ @Override
+ public void serializeValue(QuerySerializer serializer) {
+ RelationInfo ri = getResult();
+ serializer.addResource(ri.predicate);
+ serializer.add(ri.isFunctional ? (byte)1 : 0);
+ serializer.add(ri.isFinal ? (byte)1 : 0);
+ serializer.add(ri.isAsserted ? (byte)1 : 0);
+ }
+
}
--- /dev/null
+package org.simantics.db.impl.query;
+
+import org.simantics.db.RelationInfo;
+import org.simantics.db.exception.DatabaseException;
+
+public class RelationInfoQueryFactory extends QueryFactoryBase {
+
+ @Override
+ public CacheEntryBase readKeyAndValue(QueryDeserializer deserializer) throws DatabaseException {
+ RelationInfoQuery result = reference(deserializer);
+ int r = deserializer.readResource();
+ int isFunctional = deserializer.readByte();
+ int isFinal = deserializer.readByte();
+ int isAsserted = deserializer.readByte();
+ RelationInfo ri = new RelationInfo(r, isFunctional == 1, isFinal == 1, isAsserted == 1);
+ result.setResult(ri);
+ result.setReady();
+ return result;
+ }
+
+ @Override
+ public <T extends CacheEntryBase> T reference(QueryDeserializer deserializer) throws DatabaseException {
+ return (T)deserializer.readRelationInfoQuery();
+ }
+
+}
--- /dev/null
+package org.simantics.db.impl.query;
+
+import org.simantics.db.exception.DatabaseException;
+
+public class StatementsFactory extends QueryFactoryBase {
+
+ @Override
+ public CacheEntryBase readKeyAndValue(QueryDeserializer deserializer) throws DatabaseException {
+ Statements result = reference(deserializer);
+ IntArray ia = IntArray.deserialize(deserializer);
+ result.setResult(ia);
+ result.setReady();
+ return result;
+ }
+
+ @Override
+ public <T extends CacheEntryBase> T reference(QueryDeserializer deserializer) throws DatabaseException {
+ return (T)deserializer.readStatements();
+ }
+
+}
import gnu.trove.procedure.TIntProcedure;
import gnu.trove.set.hash.TIntHashSet;
-public final class SuperRelations extends UnaryQueryP<IntSet> {
+public final class SuperRelations extends UnaryQueryPIntSet {
SuperRelations(final int resource) {
super(resource);
--- /dev/null
+package org.simantics.db.impl.query;
+
+import org.simantics.db.exception.DatabaseException;
+
+public class SuperRelationsFactory extends QueryFactoryBase {
+
+ @Override
+ public CacheEntryBase readKeyAndValue(QueryDeserializer deserializer) throws DatabaseException {
+ SuperRelations result = reference(deserializer);
+ IntSet ia = IntSet.deserialize(deserializer);
+ result.setResult(ia);
+ result.setReady();
+ return result;
+ }
+
+ @Override
+ public <T extends CacheEntryBase> T reference(QueryDeserializer deserializer) throws DatabaseException {
+ return (T)deserializer.readSuperRelations();
+ }
+
+}
import gnu.trove.procedure.TIntProcedure;
-public final class SuperTypes extends UnaryQueryP<IntSet> {
+public final class SuperTypes extends UnaryQueryPIntSet {
SuperTypes(int resource) {
super(resource);
--- /dev/null
+package org.simantics.db.impl.query;
+
+import org.simantics.db.exception.DatabaseException;
+
+public class SuperTypesFactory extends QueryFactoryBase {
+
+ @Override
+ public CacheEntryBase readKeyAndValue(QueryDeserializer deserializer) throws DatabaseException {
+ SuperTypes result = reference(deserializer);
+ IntSet ia = IntSet.deserialize(deserializer);
+ result.setResult(ia);
+ result.setReady();
+ return result;
+ }
+
+ @Override
+ public <T extends CacheEntryBase> T reference(QueryDeserializer deserializer) throws DatabaseException {
+ return (T)deserializer.readSuperTypes();
+ }
+
+}
import gnu.trove.procedure.TIntProcedure;
-public final class TypeHierarchy extends UnaryQueryP<IntSet> {
+public final class TypeHierarchy extends UnaryQueryPIntSet {
TypeHierarchy(int resource) {
super(resource);
--- /dev/null
+package org.simantics.db.impl.query;
+
+import org.simantics.db.exception.DatabaseException;
+
+public class TypeHierarchyFactory extends QueryFactoryBase {
+
+ @Override
+ public CacheEntryBase readKeyAndValue(QueryDeserializer deserializer) throws DatabaseException {
+ TypeHierarchy result = reference(deserializer);
+ IntSet ia = IntSet.deserialize(deserializer);
+ result.setResult(ia);
+ result.setReady();
+ return result;
+ }
+
+ @Override
+ public <T extends CacheEntryBase> T reference(QueryDeserializer deserializer) throws DatabaseException {
+ return (T)deserializer.readTypeHierarchy();
+ }
+
+}
import gnu.trove.procedure.TIntProcedure;
-public final class Types extends UnaryQueryP<IntSet> {
+public final class Types extends UnaryQueryPIntSet {
Types(int resource) {
super(resource);
--- /dev/null
+package org.simantics.db.impl.query;
+
+import org.simantics.db.exception.DatabaseException;
+
+public class TypesFactory extends QueryFactoryBase {
+
+ @Override
+ public CacheEntryBase readKeyAndValue(QueryDeserializer deserializer) throws DatabaseException {
+ Types result = reference(deserializer);
+ IntSet ia = IntSet.deserialize(deserializer);
+ result.setResult(ia);
+ result.setReady();
+ return result;
+ }
+
+ @Override
+ public <T extends CacheEntryBase> T reference(QueryDeserializer deserializer) throws DatabaseException {
+ return (T)deserializer.readTypes();
+ }
+
+}
except(throwable);
}
+ @Override
+ public long cluster(QueryProcessor processor) {
+ return 0;
+ }
+
+ @Override
+ public void serializeKey(QuerySerializer serializer) {
+ serializer.addString(id);
+ }
+
+ @Override
+ public void serializeValue(QuerySerializer serializer) {
+ Integer value = getResult();
+ serializer.addResource(value);
+ }
+
}
--- /dev/null
+package org.simantics.db.impl.query;
+
+import org.simantics.db.exception.DatabaseException;
+
+public class URIToResourceFactory extends QueryFactoryBase {
+
+ @Override
+ public CacheEntryBase readKeyAndValue(QueryDeserializer deserializer) throws DatabaseException {
+ URIToResource result = reference(deserializer);
+ int value = deserializer.readResource();
+ result.setResult(value);
+ result.setReady();
+ return result;
+ }
+
+ @Override
+ public <T extends CacheEntryBase> T reference(QueryDeserializer deserializer) throws DatabaseException {
+ return (T)deserializer.readURIToResource();
+ }
+
+}
import org.simantics.db.impl.graph.ReadGraphImpl;
import org.simantics.db.request.RequestFlags;
+import gnu.trove.list.array.TByteArrayList;
+
public abstract class UnaryQuery<Procedure> extends CacheEntryBase<Procedure> implements Query {
final public int id;
return graph.processor.isImmutable(id);
}
+ @Override
+ public long cluster(QueryProcessor processor) {
+ return processor.cluster(id);
+ }
+
+ @Override
+ public void serializeKey(QuerySerializer serializer) {
+ serializer.addResource(id);
+ }
+
}
--- /dev/null
+package org.simantics.db.impl.query;
+
+abstract public class UnaryQueryPIntSet extends UnaryQueryP<IntSet> {
+
+ public UnaryQueryPIntSet(int r) {
+ super(r);
+ }
+
+ @Override
+ public void serializeValue(QuerySerializer serializer) {
+ IntSet is = getResult();
+ is.serialize(serializer);
+ }
+
+}
return value;
}
+
+ @Override
+ public void serializeValue(QuerySerializer serializer) {
+ byte[] result = getResult();
+ if(result == null) {
+ serializer.writeLE(-1);
+ } else {
+ serializer.writeLE(result.length);
+ serializer.add(result);
+ }
+ }
@Override
public String toString() {
--- /dev/null
+package org.simantics.db.impl.query;
+
+import org.simantics.db.exception.DatabaseException;
+
+public class ValueQueryFactory extends QueryFactoryBase {
+
+ @Override
+ public CacheEntryBase readKeyAndValue(QueryDeserializer deserializer) throws DatabaseException {
+ ValueQuery result = reference(deserializer);
+ byte[] bytes = deserializer.readByteArray();
+ result.setResult(bytes);
+ result.setReady();
+ return result;
+ }
+
+ @Override
+ public <T extends CacheEntryBase> T reference(QueryDeserializer deserializer) throws DatabaseException {
+ return (T)deserializer.readValueQuery();
+ }
+
+}
import org.simantics.scl.runtime.function.FunctionImpl3;
import org.simantics.utils.Development;
import org.simantics.utils.FileUtils;
+import org.slf4j.LoggerFactory;
import gnu.trove.map.hash.TIntIntHashMap;
import gnu.trove.procedure.TIntIntProcedure;
public class DebugSupportImpl implements DebugSupport {
+ private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(DebugSupportImpl.class);
+
final private Map<String, Function2<WriteGraph, String, Object>> getCommands = new HashMap<String, Function2<WriteGraph, String, Object>>();
final private Map<String, Function3<WriteGraph, File, String, String>> listCommands = new HashMap<String, Function3<WriteGraph, File, String, String>>();
final private Map<String, Function2<WriteGraph, String, String>> execCommands = new HashMap<String, Function2<WriteGraph, String, String>>();
});
+ listCommands.put("queryData", new FunctionImpl3<WriteGraph, File, String, String>() {
+
+ @Override
+ public String apply(WriteGraph graph, File file, String args) {
+ try {
+ getSession(graph).queryProvider2.save();
+ return "Saved queries";
+ } catch (IOException e) {
+ LOGGER.error("Error while saving queries", e);
+ return e.getMessage();
+ }
+ }
+
+ });
+
listCommands.put("queryActivity", new FunctionImpl3<WriteGraph, File, String, String>() {
@Override
public int getId(T t) {
return backend.get(t);
}
-
+
}
\ No newline at end of file
import java.util.Collection;
import java.util.function.Consumer;
+import org.simantics.db.ObjectResourceIdMap;
import org.simantics.db.Resource;
import org.simantics.db.Session;
import org.simantics.db.Statement;
public ResourceSupport getSupport() {
return resourceSupport;
}
-
+
+ @Override
+ public ClusterSupport getClusterSupport() {
+ return clusterSupport;
+ }
+
+ @Override
+ public ObjectResourceIdMap<String> createChildMap() {
+ return new ObjectResourceMap<String>(session);
+ }
+
@Override
public Statement getStatement(int s, int p, int o) {
return getStatement(null, s, p, o);
serviceLocator.registerService(QuerySupport.class, querySupport);
queryProvider2 = new QueryProcessor(getAmountOfQueryThreads(), querySupport, sessionThreads);
+
+ if("true".equals(System.getProperty("org.simantics.db.persistQueries")))
+ queryProvider2.restore();
writeSupport = new WriteSupportImpl(this);
serviceLocator.registerService(WriteSupport.class, writeSupport);
package fi.vtt.simantics.procore.internal;
+import java.io.IOException;
+
import org.simantics.db.Database;
import org.simantics.db.Resource;
import org.simantics.db.Session;
ClusterImpl clusterImpl = session.clusterTable.getClusterByClusterUIDOrMakeProxy(clusterUID);
return clusterImpl.isLoaded();
}
-
+
+ @Override
+ public void saveQueries() throws DatabaseException {
+ try {
+ session.queryProvider2.save();
+ } catch (IOException e) {
+ throw new DatabaseException(e);
+ }
+ }
+
}
*******************************************************************************/
package org.simantics.db;
-
-
final public class RelationInfo {
public static final RelationInfo[] NONE = new RelationInfo[0];
this.isFinal = isFinal;
this.isAsserted = isAsserted;
}
-
+
@Override
public String toString() {
return "RelationInfo[predicate=" + predicate + ", isFunctional=" + isFunctional + ", isFinal=" + isFinal + ", isAsserted=" + isAsserted + "]";
public boolean rolledback();
public boolean isClusterLoaded(ClusterUID clusterUID) throws DatabaseException;
-
+
+ public void saveQueries() throws DatabaseException;
+
}
import org.simantics.db.management.SingleSessionContextProviderSource;
import org.simantics.db.request.ReadInterface;
import org.simantics.db.request.WriteInterface;
+import org.simantics.db.service.XSupport;
import org.simantics.internal.FileServiceImpl;
import org.simantics.layer0.Layer0;
import org.simantics.project.IProject;
}
}
+ public static void saveQueries(Session session) {
+ try {
+ XSupport xs = session.getService(XSupport.class);
+ xs.saveQueries();
+ } catch (Exception e) {
+ LOGGER.error("Saving database queries failed.", e);
+ }
+ }
@SuppressWarnings({ "unchecked", "rawtypes" })
public static <T> T applySCL(String module, String function, Object ... args) throws DatabaseException {
} catch (Throwable t) {
LOGGER.error("Failed to flush index caches.", t);
}
+
+ if("true".equals(System.getProperty("org.simantics.db.persistQueries"))) {
+ progress.subTask("Saving Queries");
+ Simantics.saveQueries(s);
+ }
}
progress.subTask("Close Database Session");