]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/domain/LinkedListAccessor.java
Use trace level debug messages with ObjMap
[simantics/platform.git] / bundles / org.simantics.objmap2 / src / org / simantics / objmap / graph / rules / domain / LinkedListAccessor.java
1 /*******************************************************************************
2  * Copyright (c) 2019 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     Semantum oy - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.objmap.graph.rules.domain;
13
14 import java.util.ArrayList;
15 import java.util.Collection;
16
17 import org.simantics.db.ReadGraph;
18 import org.simantics.db.Resource;
19 import org.simantics.db.WriteGraph;
20 import org.simantics.db.common.utils.ListUtils;
21 import org.simantics.db.exception.DatabaseException;
22 import org.simantics.objmap.exceptions.MappingException;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25
26 /**
27  * Accesses the set of objects attached to the element by the given relation.
28  * @author Hannu Niemistö
29  */
30 public class LinkedListAccessor implements IDomainAccessor<Resource,Collection<Resource>> {
31
32         static Logger LOGGER = LoggerFactory.getLogger(LinkedListAccessor.class);
33
34         Resource relation;
35         Resource listType;
36         boolean deleteExtraObjects;
37
38         public LinkedListAccessor(Resource relation, Resource listType, boolean deleteExtraObjects) {
39                 super();
40                 this.relation = relation;
41                 this.listType = listType;
42                 this.deleteExtraObjects = deleteExtraObjects;
43         }
44
45         @Override
46         public Collection<Resource> get(ReadGraph g, Resource element) throws MappingException {
47                 try {
48                         LOGGER.trace("        LinkdedListAccessor.get");
49                         return ListUtils.toList(g, g.getPossibleObject(element, relation));
50                 } catch (DatabaseException e) {
51                         throw new MappingException(e);
52                 }
53         }
54
55         @Override
56         public boolean set(WriteGraph g, Resource element, Collection<Resource> value)
57                         throws MappingException {
58                 try {
59                         LOGGER.trace("        LinkdedListAccessor.set");
60                         return MappingUtils.synchronizeList(g, element, relation, listType, new ArrayList<Resource>(value), deleteExtraObjects);
61                 } catch (DatabaseException e) {
62                         throw new MappingException(e);
63                 }
64
65         }
66
67 }