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.Collection;
27  import java.util.List;
28  import java.util.Map;
29  import java.util.Set;
30  import net.jcip.annotations.Immutable;
31  import org.modeshape.graph.query.model.QueryCommand;
32  import org.modeshape.graph.query.model.SelectorName;
33  
34  /**
35   * The interface used to access the structure being queried and validate a query.
36   */
37  @Immutable
38  public interface Schemata {
39  
40      /**
41       * Get the information for the table or view with the supplied name within this schema.
42       * <p>
43       * The resulting definition is immutable.
44       * </p>
45       * 
46       * @param name the table or view name; may not be null
47       * @return the table or view information, or null if there is no such table
48       */
49      Table getTable( SelectorName name );
50  
51      /**
52       * Information about a queryable table.
53       */
54      public interface Table {
55          /**
56           * Get the name for this table.
57           * 
58           * @return the table name; never null
59           */
60          SelectorName getName();
61  
62          /**
63           * Get the information for a column with the supplied name within this table.
64           * <p>
65           * The resulting column definition is immutable.
66           * </p>
67           * 
68           * @param name the column name; may not be null
69           * @return the column information, or null if there is no such column
70           */
71          Column getColumn( String name );
72  
73          /**
74           * Get the queryable columns in this table.
75           * 
76           * @return the immutable map of immutable column objects by their name; never null
77           */
78          Map<String, Column> getColumnsByName();
79  
80          /**
81           * Get the queryable columns in this table.
82           * 
83           * @return the immutable, ordered list of immutable column objects; never null
84           */
85          List<Column> getColumns();
86  
87          /**
88           * Get the collection of keys for this table.
89           * 
90           * @return the immutable collection of immutable keys; never null, but possibly empty
91           */
92          Collection<Key> getKeys();
93  
94          /**
95           * Determine whether this table has a {@link #getKeys() key} that contains exactly those columns listed.
96           * 
97           * @param columns the columns for the key
98           * @return true if this table contains a key using exactly the supplied columns, or false otherwise
99           */
100         boolean hasKey( Column... columns );
101 
102         /**
103          * Determine whether this table has a {@link #getKeys() key} that contains exactly those columns listed.
104          * 
105          * @param columns the columns for the key
106          * @return true if this table contains a key using exactly the supplied columns, or false otherwise
107          */
108         boolean hasKey( Iterable<Column> columns );
109 
110         /**
111          * Obtain this table's {@link #getKeys() key} that contains exactly those columns listed.
112          * <p>
113          * The resulting key definition is immutable.
114          * </p>
115          * 
116          * @param columns the columns for the key
117          * @return the key that uses exactly the supplied columns, or null if there is no such key
118          */
119         Key getKey( Column... columns );
120 
121         /**
122          * Obtain this table's {@link #getKeys() key} that contains exactly those columns listed.
123          * <p>
124          * The resulting key definition is immutable.
125          * </p>
126          * 
127          * @param columns the columns for the key
128          * @return the key that uses exactly the supplied columns, or null if there is no such key
129          */
130         Key getKey( Iterable<Column> columns );
131 
132         /**
133          * Determine whether this table allows has extra columns not included in the {@link #getColumns() column list}. This value
134          * is used to determine whether columns in a SELECT clause should be validated against the list of known columns.
135          * 
136          * @return true if there are extra columns, or false if the {@link #getColumns() list of columns} is complete for this
137          *         table.
138          */
139         boolean hasExtraColumns();
140     }
141 
142     /**
143      * Information about a view that is defined in terms of other views/tables.
144      */
145     public interface View extends Table {
146         /**
147          * Get the {@link QueryCommand query} that is the definition of the view.
148          * 
149          * @return the view definition; never null
150          */
151         QueryCommand getDefinition();
152     }
153 
154     /**
155      * Information about a queryable column.
156      */
157     public interface Column {
158         /**
159          * Get the name for this column.
160          * 
161          * @return the column name; never null
162          */
163         String getName();
164 
165         /**
166          * Get the property type for this column.
167          * 
168          * @return the property type; never null
169          */
170         String getPropertyType();
171 
172         /**
173          * Get whether the column can be used in a full-text search.
174          * 
175          * @return true if the column is full-text searchable, or false otherwise
176          */
177         boolean isFullTextSearchable();
178     }
179 
180     /**
181      * Information about a key for a table.
182      */
183     public interface Key {
184         /**
185          * Get the columns that make up this key.
186          * 
187          * @return the key's columns; immutable and never null
188          */
189         Set<Column> getColumns();
190 
191         /**
192          * Determine whether this key contains exactly those columns listed.
193          * 
194          * @param columns the columns for the key
195          * @return true if this key contains exactly the supplied columns, or false otherwise
196          */
197         boolean hasColumns( Column... columns );
198 
199         /**
200          * Determine whether this key contains exactly those columns listed.
201          * 
202          * @param columns the columns for the key
203          * @return true if this key contains exactly the supplied columns, or false otherwise
204          */
205         boolean hasColumns( Iterable<Column> columns );
206     }
207 
208 }