View Javadoc

1   /*
2    * ModeShape (http://www.modeshape.org)
3    * See the COPYRIGHT.txt file distributed with this work for information
4    * regarding copyright ownership.  Some portions may be licensed
5    * to Red Hat, Inc. under one or more contributor license agreements.
6    * See the AUTHORS.txt file in the distribution for a full listing of 
7    * individual contributors.
8    *
9    * ModeShape is free software. Unless otherwise indicated, all code in ModeShape
10   * is licensed to you under the terms of the GNU Lesser General Public License as
11   * published by the Free Software Foundation; either version 2.1 of
12   * the License, or (at your option) any later version.
13   * 
14   * ModeShape is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17   * Lesser General Public License for more details.
18   *
19   * You should have received a copy of the GNU Lesser General Public
20   * License along with this software; if not, write to the Free
21   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
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);
69          this.definition = definition;
70      }
71  
72      /**
73       * {@inheritDoc}
74       * 
75       * @see org.modeshape.graph.query.validate.Schemata.View#getDefinition()
76       */
77      public QueryCommand getDefinition() {
78          return definition;
79      }
80  
81      /**
82       * {@inheritDoc}
83       * 
84       * @see java.lang.Object#toString()
85       */
86      @Override
87      public String toString() {
88          StringBuilder sb = new StringBuilder(getName().name());
89          sb.append('(');
90          boolean first = true;
91          for (Column column : getColumns()) {
92              if (first) first = false;
93              else sb.append(", ");
94              sb.append(column);
95          }
96          sb.append(") AS '");
97          sb.append(Visitors.readable(definition));
98          sb.append('\'');
99          if (!getKeys().isEmpty()) {
100             sb.append(" with keys ");
101             first = true;
102             for (Key key : getKeys()) {
103                 if (first) first = false;
104                 else sb.append(", ");
105                 sb.append(key);
106             }
107         }
108         return sb.toString();
109     }
110 }