]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/impl/DefaultInstanceFactory.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 / DefaultInstanceFactory.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 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  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.db.layer0.adapter.impl;
13
14 import java.util.Map;
15
16 import org.simantics.db.ReadGraph;
17 import org.simantics.db.Resource;
18 import org.simantics.db.layer0.adapter.InstanceFactory;
19 import org.simantics.db.layer0.request.DefaultInstanceFactoryRequest;
20 import org.simantics.db.request.WriteResult;
21
22 public class DefaultInstanceFactory implements InstanceFactory {
23
24         final Resource resource;
25         
26         public DefaultInstanceFactory(Resource resource) {
27                 this.resource = resource;
28         }
29         
30         public WriteResult<Map<String, Object>> create(ReadGraph graph, Map<String, Object> attachment, Resource ... templates) {
31                 return new DefaultInstanceFactoryRequest(resource, attachment, templates);
32         }
33         
34 //    @Override
35 //    public Resource create(WriteGraph graph) throws DatabaseException {
36 //        
37 //        Builtins b = graph.getBuiltins();
38 //        SpreadsheetResource sr = SpreadsheetResource.getInstance(graph);
39 //
40 //        InstanceFactory sheetElementFactory = graph.adapt(sr.SpreadsheetElement, InstanceFactory.class);
41 //        Map<String, Object> sheetElement = graph.syncRequest(sheetElementFactory.create(ArrayMap.keys("").values(""), sr.ForCompositeTemplate));
42 //
43 ////        InstanceFactory sheetFactory = w.adapt(ssr.Spreadsheet, InstanceFactory.class);
44 ////        w.syncRequest(sheetFactory.create(ArrayMap.keys("composite").values(model), ssr.ForCompositeTemplate));
45 //        
46 //        Resource result = OrderedSetUtils.create(graph, sr.Spreadsheet, (Resource)sheetElement.get("resource"));
47 //
48 //        graph.claim((Resource)sheetElement.get("resource"), sr.HasSheet, result);
49 //
50 //            Resource rowResource0 = graph.newResource();
51 //            graph.claim(rowResource0, b.InstanceOf, null, sr.Row);
52 //            Resource rowResource1 = graph.newResource();
53 //            graph.claim(rowResource1, b.InstanceOf, null, sr.Row);
54 //            Resource columnResource0 = graph.newResource();
55 //            graph.claim(columnResource0, b.InstanceOf, null, sr.Column);
56 //            Resource columnResource1 = graph.newResource();
57 //            graph.claim(columnResource1, b.InstanceOf, null, sr.Column);
58 //            Resource columnResource2 = graph.newResource();
59 //            graph.claim(columnResource2, b.InstanceOf, null, sr.Column);
60 //            Resource columnResource3 = graph.newResource();
61 //            graph.claim(columnResource3, b.InstanceOf, null, sr.Column);
62 //        
63 //            graph.claim(result, sr.HasRows, OrderedSetUtils.create(graph, sr.Rows, rowResource0, rowResource1));
64 //            graph.claim(result, sr.HasColumns, OrderedSetUtils.create(graph, sr.Columns, columnResource0, columnResource1, columnResource2, columnResource3));
65 //
66 ////        RowsColumnsIndex rowIndex = graph.syncRequest(new Rows(result));
67 ////        RowsColumnsIndex columnIndex = graph.syncRequest(new Columns(result));
68 ////        Resource rowResource0 = rowIndex.ensureIndex(graph, 0);
69 ////        Resource rowResource1 = rowIndex.ensureIndex(graph, 1);
70 ////        Resource columnResource0 = columnIndex.ensureIndex(graph, 0);
71 ////        Resource columnResource1 = columnIndex.ensureIndex(graph, 1);
72 ////        Resource columnResource2 = columnIndex.ensureIndex(graph, 2);
73 ////        Resource columnResource3 = columnIndex.ensureIndex(graph, 3);
74 ////        
75 //        {
76 //              Resource newCell = graph.newResource();
77 //              graph.claim(newCell, b.InstanceOf, null, sr.TextCell);
78 //              String label = "Pipe name";
79 //              graph.claim(newCell, sr.HasRow, sr.RowOf, rowResource0);
80 //              graph.claim(newCell, sr.HasColumn, sr.ColumnOf, columnResource0);
81 //              graph.addValue(newCell, sr.HasLabel, sr.LabelOf, b.String, label, StringJavaBinding.INSTANCE);
82 //              graph.claim(result, b.ConsistsOf, b.PartOf, newCell);
83 //        }
84 //
85 //        {
86 //              Resource newCell = graph.newResource();
87 //              graph.claim(newCell, b.InstanceOf, null, sr.TextCell);
88 //              String label = "Pipe length";
89 //              graph.claim(newCell, sr.HasRow, sr.RowOf, rowResource0);
90 //              graph.claim(newCell, sr.HasColumn, sr.ColumnOf, columnResource1);
91 //              graph.addValue(newCell, sr.HasLabel, sr.LabelOf, b.String, label, StringJavaBinding.INSTANCE);
92 //              graph.claim(result, b.ConsistsOf, b.PartOf, newCell);
93 //        }
94 //
95 //        {
96 //              Resource newCell = graph.newResource();
97 //              graph.claim(newCell, b.InstanceOf, null, sr.TextCell);
98 //              String label = "Flow area";
99 //              graph.claim(newCell, sr.HasRow, sr.RowOf, rowResource0);
100 //              graph.claim(newCell, sr.HasColumn, sr.ColumnOf, columnResource2);
101 //              graph.addValue(newCell, sr.HasLabel, sr.LabelOf, b.String, label, StringJavaBinding.INSTANCE);
102 //              graph.claim(result, b.ConsistsOf, b.PartOf, newCell);
103 //        }
104 //
105 //        {
106 //              Resource newCell = graph.newResource();
107 //              graph.claim(newCell, b.InstanceOf, null, sr.TextCell);
108 //              String label = "In simulation";
109 //              graph.claim(newCell, sr.HasRow, sr.RowOf, rowResource0);
110 //              graph.claim(newCell, sr.HasColumn, sr.ColumnOf, columnResource3);
111 //              graph.addValue(newCell, sr.HasLabel, sr.LabelOf, b.String, label, StringJavaBinding.INSTANCE);
112 //              graph.claim(result, b.ConsistsOf, b.PartOf, newCell);
113 //        }
114 //
115 //        {
116 //              Resource newCell = graph.newResource();
117 //              graph.claim(newCell, b.InstanceOf, null, sr.ExpressionCell);
118 //              String label = "Attributes(Components('Pipe*'), 'Name', 'Pi12 Length', 'Pi12 Area', 'Included In Simulation')";
119 //              graph.claim(newCell, sr.HasRow, sr.RowOf, rowResource1);
120 //              graph.claim(newCell, sr.HasColumn, sr.ColumnOf, columnResource0);
121 //              graph.addValue(newCell, sr.HasExpression, sr.ExpressionOf, b.String, label, StringJavaBinding.INSTANCE);
122 //              graph.claim(result, b.ConsistsOf, b.PartOf, newCell);
123 //        }
124 //
125 //        return result;
126 //        
127 //    }
128
129 //    @Override
130 //    public Resource create(WriteGraph graph, Resource container, Resource relation) throws DatabaseException {
131 //
132 //        Builtins b = graph.getBuiltins();
133 //        Resource sheet = create(graph);
134 //        String name = GraphUtils.findFreshName(graph, "Sheet", container, relation);
135 //        graph.addValue(sheet, b.HasName, b.NameOf, b.String, name, StringJavaBinding.INSTANCE);
136 //        graph.claim(container, relation, sheet);
137 //        return sheet;
138 //        
139 //    }
140 //
141 //      @Override
142 //      public Resource create(WriteGraph graph, Map<String, Resource> attachment,
143 //                      Collection<Resource> templates) throws DatabaseException {
144 //              throw new Error("Not implemented");
145 //      }
146
147
148 }