]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/impl/EntityStringModifierFactory.java
Fixed index query regression in L0.Entity instance queries
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / adapter / impl / EntityStringModifierFactory.java
1 /*******************************************************************************
2  * Copyright (c) 2013 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.db.layer0.adapter.impl;
13
14 import org.simantics.db.ReadGraph;
15 import org.simantics.db.Resource;
16 import org.simantics.db.exception.DatabaseException;
17 import org.simantics.db.layer0.adapter.StringModifier;
18 import org.simantics.db.layer0.adapter.StringModifierFactory;
19 import org.simantics.db.layer0.variable.Variable;
20 import org.simantics.layer0.Layer0;
21
22 /**
23  * Makes sure that two things apply for L0.HasName of any entity:
24  * <ol>
25  * <li>An entity must not have the same name as any of its
26  * L0.PartOf/L0.ConsistsOf related siblings</li>
27  * <li>An entity's name must not begin with one or more dots ('.'). Due to
28  * limitations imposed by the Variable specification no resources in the
29  * simantics database should be named beginning with one or more dots. '.' is
30  * variable browsing syntax for "parent" (see
31  * {@link Variable#browse(ReadGraph, String)}). This is comparable to file
32  * systems and the use of '.' and '..' therein.</li>
33  * </ol>
34  * 
35  * @author Tuukka Lehtonen
36  */
37 public final class EntityStringModifierFactory implements StringModifierFactory {
38
39     private Resource subject;
40
41     public EntityStringModifierFactory(Resource subject) throws DatabaseException {
42         this.subject = subject;
43     }
44
45     @Override
46     public StringModifier createModifier(ReadGraph graph, Resource relation, Resource property) throws DatabaseException {
47         Layer0 L0 = Layer0.getInstance(graph);
48
49         // Names require special care in validation.
50         if (L0.HasName.equals(relation)) {
51             return new EntityNameModifier(graph, subject, property);
52         }
53
54         return null;
55     }
56
57 }