1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.modeshape.graph.query.validate;
25
26 import java.util.List;
27 import java.util.Map;
28 import java.util.Set;
29 import net.jcip.annotations.Immutable;
30 import org.modeshape.graph.query.model.QueryCommand;
31 import org.modeshape.graph.query.model.SelectorName;
32 import org.modeshape.graph.query.model.Visitors;
33 import org.modeshape.graph.query.validate.Schemata.Column;
34 import org.modeshape.graph.query.validate.Schemata.Key;
35 import org.modeshape.graph.query.validate.Schemata.View;
36
37
38
39
40 @Immutable
41 class ImmutableView extends ImmutableTable implements View {
42
43 private final QueryCommand definition;
44
45 protected ImmutableView( SelectorName name,
46 Iterable<Column> columns,
47 QueryCommand definition ) {
48 super(name, columns);
49 this.definition = definition;
50 }
51
52 protected ImmutableView( SelectorName name,
53 Iterable<Column> columns,
54 QueryCommand definition,
55 Iterable<Column>... keyColumns ) {
56 super(name, columns, keyColumns);
57 this.definition = definition;
58 }
59
60 protected ImmutableView( SelectorName name,
61 Map<String, Column> columnsByName,
62 List<Column> columns,
63 QueryCommand definition,
64 Set<Key> keys ) {
65 super(name, columnsByName, columns, keys);
66 this.definition = definition;
67 }
68
69
70
71
72
73
74 public QueryCommand getDefinition() {
75 return definition;
76 }
77
78
79
80
81
82
83 @Override
84 public String toString() {
85 StringBuilder sb = new StringBuilder(getName().getName());
86 sb.append('(');
87 boolean first = true;
88 for (Column column : getColumns()) {
89 if (first) first = false;
90 else sb.append(", ");
91 sb.append(column);
92 }
93 sb.append(") AS '");
94 sb.append(Visitors.readable(definition));
95 sb.append('\'');
96 if (!getKeys().isEmpty()) {
97 sb.append(" with keys ");
98 first = true;
99 for (Key key : getKeys()) {
100 if (first) first = false;
101 else sb.append(", ");
102 sb.append(key);
103 }
104 }
105 return sb.toString();
106 }
107 }