* @param graph
* @param component
* for which the identifier is added
+ * @param add
+ * <code>true</code> to invoke addLiteral, <code>false</code> to
+ * invoke claimLiteral
* @throws DatabaseException
*/
- public static void addL0Identifier(WriteGraph graph, Resource component) throws DatabaseException {
+ public static void claimNewIdentifier(WriteGraph graph, Resource component, boolean add) throws DatabaseException {
Layer0 L0 = Layer0.getInstance(graph);
- graph.addLiteral(component, L0.identifier, L0.identifier_Inverse, L0.GUID, GUID.random(), GUID.BINDING);
+ GUID guid = GUID.random();
+ if (add)
+ graph.addLiteral(component, L0.identifier, L0.identifier_Inverse, L0.GUID, guid, GUID.BINDING);
+ else
+ graph.claimLiteral(component, L0.identifier, L0.identifier_Inverse, L0.GUID, guid, GUID.BINDING);
}
}
Layer0 L0 = Layer0.getInstance(graph);
while(!todo.isEmpty()) {
Resource resource = todo.remove(todo.size()-1);
- Layer0Utils.addL0Identifier(graph, resource);
+ Layer0Utils.claimNewIdentifier(graph, resource, false);
if(deep)
todo.addAll(graph.getObjects(resource, L0.ConsistsOf));
}
GUID existing = graph.getPossibleRelatedValue(r, L0.identifier, GUID.BINDING);
if(existing == null) {
- Layer0Utils.addL0Identifier(graph, r);
+ Layer0Utils.claimNewIdentifier(graph, r, true);
madeChanges = true;
}
import org.simantics.Simantics;
import org.simantics.databoard.Bindings;
-import org.simantics.datatypes.literal.GUID;
import org.simantics.db.Resource;
import org.simantics.db.WriteGraph;
import org.simantics.db.exception.DatabaseException;
if (graph.hasStatement(sourceContainer, L0.ConsistsOf, source))
graph.claim(targetContainer, L0.ConsistsOf, copy);
- Layer0Utils.addL0Identifier(graph, copy);
+ Layer0Utils.claimNewIdentifier(graph, copy, false);
if (context.get(SynchronizationHints.NO_RENAME) == null)
renameComponent(context, graph, source, copy, sourceContainer, targetContainer);
return copy;
import gnu.trove.map.hash.TIntIntHashMap;
import gnu.trove.set.hash.TIntHashSet;
-import org.simantics.datatypes.literal.GUID;
import org.simantics.db.Resource;
import org.simantics.db.WriteGraph;
import org.simantics.db.common.utils.CommonDBUtils;
Resource result = GraphUtils.create(g,
b.HasName, proposition
);
- Layer0Utils.addL0Identifier(g, result);
+ Layer0Utils.claimNewIdentifier(g, result, true);
return result;
} catch (NamingException e1) {
throw new DatabaseException(e1);
import java.util.Collection;
-import org.simantics.datatypes.literal.GUID;
import org.simantics.db.Resource;
import org.simantics.db.WriteGraph;
import org.simantics.db.common.CommentMetadata;
for (Resource r : ids) {
if (!graph.hasStatement(r, L0.identifier)) {
CommonDBUtils.selectClusterSet(graph, r);
- Layer0Utils.addL0Identifier(graph, r);
+ Layer0Utils.claimNewIdentifier(graph, r, true);
}
}
import java.util.Set;
import org.simantics.databoard.Bindings;
-import org.simantics.datatypes.literal.GUID;
import org.simantics.db.ReadGraph;
import org.simantics.db.RequestProcessor;
import org.simantics.db.Resource;
g.claim(component, L0.HasName, Layer0Utils.literal(g, name));
g.claim(component, L0.HasLabel, Layer0Utils.literal(g, ""));
g.claim(parent, L0.ConsistsOf, component);
- // Add identifier
- Layer0Utils.addL0Identifier(g, component);
+ Layer0Utils.claimNewIdentifier(g, component, true);
// Add comment to change set.
CommentMetadata cm = g.getMetadata(CommentMetadata.class);
g.addMetadata(cm.add("Created component " + component));