use of au.gov.asd.tac.constellation.graph.DuplicateKeyException in project constellation by constellation-app.
the class CompositeUtilities method destroyComposite.
/**
* Destroys a single composite node which the specified node either is, or
* is a constituent of.
*
* @param graph The graph.
* @param compositeStateAttr The graph ID of the composite state attribute
* for nodes.
* @param uniqueIdAttr The graph ID of the uniqueId attribute for
* transactions.
* @param vxId The ID of the specified node.
* @return A list of IDs of any newly expanded nodes. This will be an empty
* list if no composite was destroyed, or if the destroyed composite was
* already expanded.
*/
public static List<Integer> destroyComposite(final GraphWriteMethods graph, final int compositeStateAttr, final int uniqueIdAttr, final int vxId) {
final List<Integer> resultingNodes = new ArrayList<>();
final CompositeNodeState compositeState = (CompositeNodeState) graph.getObjectValue(compositeStateAttr, vxId);
if (compositeState != null) {
if (compositeState.isComposite()) {
final ContractedCompositeNodeState contractedState = compositeState.contractedState;
resultingNodes.addAll(contractedState.expand(graph, vxId));
while (true) {
try {
graph.validateKey(GraphElementType.VERTEX, false);
break;
} catch (final DuplicateKeyException ex) {
LOGGER.log(Level.INFO, "Duplicate Key has been found. Merging duplicate nodes");
final GraphElementMerger merger = new PrioritySurvivingGraphElementMerger();
merger.mergeElement(graph, GraphElementType.VERTEX, ex.getNewId(), ex.getExistingId());
}
}
resultingNodes.forEach(id -> {
simplifyCompositeTransactions(graph, uniqueIdAttr, id);
graph.setObjectValue(compositeStateAttr, id, null);
});
} else {
final int vertexCount = graph.getVertexCount();
for (int i = 0; i < vertexCount; i++) {
final int nxId = graph.getVertex(i);
final CompositeNodeState cns = ((CompositeNodeState) graph.getObjectValue(compositeStateAttr, nxId));
if (cns != null && cns.expandedState != null && cns.expandedState.getCompositeId().equals(compositeState.expandedState.getCompositeId())) {
simplifyCompositeTransactions(graph, uniqueIdAttr, nxId);
graph.setObjectValue(compositeStateAttr, nxId, null);
}
}
}
}
return resultingNodes;
}
use of au.gov.asd.tac.constellation.graph.DuplicateKeyException in project constellation by constellation-app.
the class PrimaryKeyUnitNGTest method rollbackTest.
@Test
public void rollbackTest() {
try {
Graph graph = new DualGraph(null);
int vName, tName;
int source, destination;
int transaction1, transaction2, transaction3;
WritableGraph wg = graph.getWritableGraph("Set Up Graph", true);
try {
vName = wg.addAttribute(GraphElementType.VERTEX, StringAttributeDescription.ATTRIBUTE_NAME, "name", "name", null, null);
tName = wg.addAttribute(GraphElementType.TRANSACTION, StringAttributeDescription.ATTRIBUTE_NAME, "name", "name", null, null);
wg.setPrimaryKey(GraphElementType.VERTEX, vName);
wg.setPrimaryKey(GraphElementType.TRANSACTION, tName);
source = wg.addVertex();
wg.setStringValue(vName, source, "Source");
destination = wg.addVertex();
wg.setStringValue(vName, destination, "Destination");
transaction1 = wg.addTransaction(source, destination, true);
wg.setStringValue(tName, transaction1, "transaction");
} finally {
wg.commit();
}
try {
wg = graph.getWritableGraph("Add Duplicate Transactions", true);
try {
transaction2 = wg.addTransaction(source, destination, true);
wg.setStringValue(transaction2, tName, "transaction");
transaction3 = wg.addTransaction(source, destination, true);
wg.setStringValue(transaction3, tName, "transaction");
} finally {
wg.commit();
}
} catch (DuplicateKeyException ex) {
}
wg = graph.getWritableGraph("Add Unique Transaction", true);
try {
transaction2 = wg.addTransaction(source, destination, true);
wg.setStringValue(transaction2, tName, "transaction2");
} finally {
wg.commit();
}
ReadableGraph rg = graph.getReadableGraph();
try {
assert rg.getTransactionCount() == 2;
} finally {
rg.release();
}
} catch (InterruptedException ex) {
Exceptions.printStackTrace(ex);
}
}
use of au.gov.asd.tac.constellation.graph.DuplicateKeyException in project constellation by constellation-app.
the class CompositeUtilities method expandComposite.
/**
* Expands a single composite node.
*
* @param graph The graph.
* @param compositeStateAttr The graph ID of the composite state attribute
* for nodes.
* @param vxId The id of the specified node.
* @return A list of the id's of the expanded constituent nodes. This will
* be empty if the specified node was not a composite.
*/
public static List<Integer> expandComposite(final GraphWriteMethods graph, final int compositeStateAttr, final int vxId) {
final List<Integer> expandedNodes = new ArrayList<>();
final CompositeNodeState compositeState = (CompositeNodeState) graph.getObjectValue(compositeStateAttr, vxId);
if (compositeState != null && compositeState.isComposite()) {
final ContractedCompositeNodeState contractedState = compositeState.contractedState;
expandedNodes.addAll(contractedState.expand(graph, vxId));
while (true) {
try {
graph.validateKey(GraphElementType.VERTEX, false);
break;
} catch (final DuplicateKeyException ex) {
LOGGER.log(Level.INFO, "Duplicate Key has been found. Merging duplicate nodes");
final GraphElementMerger merger = new PrioritySurvivingGraphElementMerger();
merger.mergeElement(graph, GraphElementType.VERTEX, ex.getNewId(), ex.getExistingId());
}
}
}
return expandedNodes;
}
use of au.gov.asd.tac.constellation.graph.DuplicateKeyException in project constellation by constellation-app.
the class PrimaryKeyUnitNGTest method nestedRollbackTest.
@Test
public void nestedRollbackTest() {
try {
Graph graph = new DualGraph(null);
int vName, tName;
int source, destination;
int transaction1, transaction2, transaction3;
WritableGraph wg = graph.getWritableGraph("Set Up Graph", true);
try {
vName = wg.addAttribute(GraphElementType.VERTEX, StringAttributeDescription.ATTRIBUTE_NAME, "name", "name", null, null);
tName = wg.addAttribute(GraphElementType.TRANSACTION, StringAttributeDescription.ATTRIBUTE_NAME, "name", "name", null, null);
wg.setPrimaryKey(GraphElementType.VERTEX, vName);
wg.setPrimaryKey(GraphElementType.TRANSACTION, tName);
source = wg.addVertex();
wg.setStringValue(vName, source, "Source");
destination = wg.addVertex();
wg.setStringValue(vName, destination, "Destination");
transaction1 = wg.addTransaction(source, destination, true);
wg.setStringValue(tName, transaction1, "transaction");
} finally {
wg.commit();
}
try {
wg = graph.getWritableGraph("Add Duplicate Transactions", true);
try {
transaction2 = wg.addTransaction(source, destination, true);
wg.setStringValue(tName, transaction2, "transaction");
transaction3 = wg.addTransaction(source, destination, true);
wg.setStringValue(tName, transaction3, "transaction");
WritableGraph wg2 = graph.getWritableGraph("Not doing anything wrong", true);
try {
} finally {
wg2.commit();
}
} finally {
wg.commit();
}
} catch (DuplicateKeyException ex) {
ex.printStackTrace();
}
wg = graph.getWritableGraph("Add Unique Transaction", true);
try {
transaction2 = wg.addTransaction(source, destination, true);
wg.setStringValue(tName, transaction2, "transaction2");
} finally {
wg.commit();
}
ReadableGraph rg = graph.getReadableGraph();
try {
assert rg.getTransactionCount() == 2;
} finally {
rg.release();
}
} catch (InterruptedException ex) {
Exceptions.printStackTrace(ex);
}
}
use of au.gov.asd.tac.constellation.graph.DuplicateKeyException in project constellation by constellation-app.
the class CascadingQueryPlugin method run.
@Override
public final void run(final PluginGraphs graphs, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
final Graph graph = graphs.getGraph();
// If the graph no longer exists
if (graph == null) {
return;
}
// Make the graph appear busy
interaction.setBusy(graph.getId(), true);
try {
// Make the progress bar appear nondeterminent
try {
interaction.setProgress(0, 0, "Executing child plugins", true);
Map<Plugin, PluginParameters> childPlugins = getChildPlugins(parameters);
PluginSynchronizer pluginSynchronizer = new PluginSynchronizer(childPlugins.size() + 1);
for (final Entry<Plugin, PluginParameters> entry : childPlugins.entrySet()) {
PluginExecution.withPlugin(entry.getKey()).withParameters(entry.getValue()).synchronizingOn(pluginSynchronizer).executeLater(graph);
}
// Wait at gate 0 for CascadingQueryPlugin to finish reading
graphs.waitAtGate(0);
// Wait for child plugins at gate 1 to finish reading
pluginSynchronizer.waitForGate(1);
// Wait for all plugins to finish reading and querying
interaction.setProgress(0, 0, "Waiting For Other Plugins...", true);
// Wait at gate 1 for any SimpleQueryPlugins to finish reading
graphs.waitAtGate(1);
} catch (DuplicateKeyException ex) {
interaction.notify(PluginNotificationLevel.ERROR, ex.getMessage());
} finally {
interaction.setProgress(2, 1, "Finished", true);
}
} finally {
interaction.setBusy(graph.getId(), false);
}
}
Aggregations