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 boolean extraColumns,
48 QueryCommand definition ) {
49 super(name, columns, extraColumns);
50 this.definition = definition;
51 }
52
53 protected ImmutableView( SelectorName name,
54 Iterable<Column> columns,
55 boolean extraColumns,
56 QueryCommand definition,
57 Iterable<Column>... keyColumns ) {
58 super(name, columns, extraColumns, keyColumns);
59 this.definition = definition;
60 }
61
62 protected ImmutableView( SelectorName name,
63 Map<String, Column> columnsByName,
64 List<Column> columns,
65 boolean extraColumns,
66 QueryCommand definition,
67 Set<Key> keys ) {
68 super(name, columnsByName, columns, keys, extraColumns, columnsByName, columns);
69 this.definition = definition;
70 }
71
72 protected ImmutableView( SelectorName name,
73 Map<String, Column> columnsByName,
74 List<Column> columns,
75 boolean extraColumns,
76 QueryCommand definition,
77 Set<Key> keys,
78 Map<String, Column> selectStarColumnsByName,
79 List<Column> selectStarColumns ) {
80 super(name, columnsByName, columns, keys, extraColumns, selectStarColumnsByName, selectStarColumns);
81 this.definition = definition;
82 }
83
84
85
86
87
88
89 public QueryCommand getDefinition() {
90 return definition;
91 }
92
93
94
95
96
97
98 @Override
99 public ImmutableView withColumnNotInSelectStar( String name ) {
100 ImmutableTable result = super.withColumnNotInSelectStar(name);
101 if (result == this) return this;
102 return new ImmutableView(result.getName(), result.getColumnsByName(), result.getColumns(), result.hasExtraColumns(),
103 definition, result.getKeySet(), result.getSelectAllColumnsByName(), result.getSelectAllColumns());
104 }
105
106
107
108
109
110
111 @Override
112 public String toString() {
113 StringBuilder sb = new StringBuilder(getName().name());
114 sb.append('(');
115 boolean first = true;
116 for (Column column : getColumns()) {
117 if (first) first = false;
118 else sb.append(", ");
119 sb.append(column);
120 }
121 sb.append(") AS '");
122 sb.append(Visitors.readable(definition));
123 sb.append('\'');
124 if (!getKeys().isEmpty()) {
125 sb.append(" with keys ");
126 first = true;
127 for (Key key : getKeys()) {
128 if (first) first = false;
129 else sb.append(", ");
130 sb.append(key);
131 }
132 }
133 return sb.toString();
134 }
135 }