/*******************************************************************************
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * Copyright (c) 2007, 2018 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
import org.simantics.db.Resource;
import org.simantics.db.WriteGraph;
import org.simantics.db.WriteOnlyGraph;
-import org.simantics.db.common.request.ReadRequest;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.exception.RuntimeDatabaseException;
import org.simantics.db.exception.ValidationException;
}
}
+ /**
+ * Reorders elements with a minimum number of writes. The set of elements must remain the same.
+ */
+ public static void reorder(WriteGraph g, Resource l, Iterable<Resource> order) throws DatabaseException {
+ Resource newPrev = l;
+ for (Resource r : order) {
+ Resource prev = OrderedSetUtils.prev(g, l, r);
+ if (!prev.equals(newPrev)) {
+ g.deny(prev, l, r);
+ g.claim(newPrev, l, r);
+ }
+ newPrev = r;
+ }
+ Resource newLast = newPrev;
+ Resource last = OrderedSetUtils.prev(g, l, l);
+ if (!last.equals(newLast)) {
+ g.deny(last, l, l);
+ g.claim(newLast, l, l);
+ }
+ }
+
/**
* Converts ordered set into a list.
*/
}
}
- /**
- * Converts ordered set into a list.
- */
- public static void forEach(AsyncReadGraph g, final Resource l, final AsyncMultiProcedure<Resource> procedure) {
- g.asyncRequest(new ReadRequest() {
-
- @Override
- public void run(ReadGraph graph) throws DatabaseException {
- for(Resource r : toList(graph, l))
- procedure.execute(graph, r);
- }
-
- });
- }
-
/**
* Creates an empty ordered set.
*/