-/*******************************************************************************\r
- * Copyright (c) 2012 Association for Decentralized Information Management in\r
- * Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.db.layer0.adapter.impl;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Collection;\r
-\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.WriteGraph;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.adapter.Remover;\r
-import org.simantics.db.layer0.util.RemoverUtil;\r
-\r
-/**\r
- * A simple {@link Remover} implementation for removing a resource and its specified related objects using the {@link EntityRemover} logic.\r
- * \r
- * @author Tuukka Lehtonen\r
- */\r
-public class RelatedObjectRemover extends AbstractRemover {\r
-\r
- Resource[] relations;\r
-\r
- public RelatedObjectRemover(ReadGraph graph, Resource component, String relationURI) throws DatabaseException {\r
- super(component);\r
- relations = new Resource[] { graph.getResource(relationURI) };\r
- }\r
-\r
- public RelatedObjectRemover(ReadGraph graph, Resource component, String relationURI, String relationURI2) throws DatabaseException {\r
- this(graph, component, new String[] { relationURI, relationURI2 });\r
- }\r
-\r
- public RelatedObjectRemover(ReadGraph graph, Resource component, String relationURI, String relationURI2, String relationURI3) throws DatabaseException {\r
- this(graph, component, new String[] { relationURI, relationURI2, relationURI3 });\r
- }\r
-\r
- public RelatedObjectRemover(ReadGraph graph, Resource component, String... relationURIs) throws DatabaseException {\r
- super(component);\r
- if (relationURIs.length == 0) {\r
- relations = Resource.NONE;\r
- } else {\r
- relations = new Resource[relationURIs.length];\r
- for (int i = 0; i < relationURIs.length; ++i)\r
- relations[i] = graph.getResource(relationURIs[i]);\r
- }\r
- }\r
-\r
- @Override\r
- public void remove(WriteGraph graph) throws DatabaseException {\r
- Collection<Resource> objects = new ArrayList<Resource>();\r
- for (Resource relation : relations) {\r
- for (Resource object : graph.getObjects(resource, relation)) {\r
- if (object.equals(resource))\r
- continue;\r
- objects.add(object);\r
- }\r
- }\r
-\r
- // Remove self first to prevent later actions for returning to it.\r
- EntityRemover.remove(graph, resource);\r
-\r
- // Finally, remove related matter.\r
- for (Resource object : objects)\r
- RemoverUtil.remove(graph, object);\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2012 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.layer0.adapter.impl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.adapter.Remover;
+import org.simantics.db.layer0.util.RemoverUtil;
+
+/**
+ * A simple {@link Remover} implementation for removing a resource and its specified related objects using the {@link EntityRemover} logic.
+ *
+ * @author Tuukka Lehtonen
+ */
+public class RelatedObjectRemover extends AbstractRemover {
+
+ Resource[] relations;
+
+ public RelatedObjectRemover(ReadGraph graph, Resource component, String relationURI) throws DatabaseException {
+ super(component);
+ relations = new Resource[] { graph.getResource(relationURI) };
+ }
+
+ public RelatedObjectRemover(ReadGraph graph, Resource component, String relationURI, String relationURI2) throws DatabaseException {
+ this(graph, component, new String[] { relationURI, relationURI2 });
+ }
+
+ public RelatedObjectRemover(ReadGraph graph, Resource component, String relationURI, String relationURI2, String relationURI3) throws DatabaseException {
+ this(graph, component, new String[] { relationURI, relationURI2, relationURI3 });
+ }
+
+ public RelatedObjectRemover(ReadGraph graph, Resource component, String... relationURIs) throws DatabaseException {
+ super(component);
+ if (relationURIs.length == 0) {
+ relations = Resource.NONE;
+ } else {
+ relations = new Resource[relationURIs.length];
+ for (int i = 0; i < relationURIs.length; ++i)
+ relations[i] = graph.getResource(relationURIs[i]);
+ }
+ }
+
+ @Override
+ public void remove(WriteGraph graph) throws DatabaseException {
+ Collection<Resource> objects = new ArrayList<Resource>();
+ for (Resource relation : relations) {
+ for (Resource object : graph.getObjects(resource, relation)) {
+ if (object.equals(resource))
+ continue;
+ objects.add(object);
+ }
+ }
+
+ // Remove self first to prevent later actions for returning to it.
+ EntityRemover.remove(graph, resource);
+
+ // Finally, remove related matter.
+ for (Resource object : objects)
+ RemoverUtil.remove(graph, object);
+ }
+
+}