METAMODEL-1165: Fixed - added default_table alias table
[metamodel.git] / core / src / main / java / org / apache / metamodel / schema / MutableSchema.java
1 /**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package org.apache.metamodel.schema;
20
21 import java.io.Serializable;
22 import java.util.ArrayList;
23 import java.util.Collection;
24 import java.util.Collections;
25 import java.util.List;
26
27 /**
28 * Represents a schema and it's metadata. Schemas represent a collection of
29 * tables.
30 *
31 * @see Table
32 */
33 public class MutableSchema extends AbstractSchema implements Serializable,
34 Schema {
35
36 private static final long serialVersionUID = 4465197783868238863L;
37
38 private String _name;
39 private final List<Table> _tables;
40
41 public MutableSchema() {
42 super();
43 _tables = new ArrayList<Table>();
44 }
45
46 public MutableSchema(String name) {
47 this();
48 _name = name;
49 }
50
51 public MutableSchema(String name, Table... tables) {
52 this(name);
53 setTables(tables);
54 }
55
56 @Override
57 public String getName() {
58 return _name;
59 }
60
61 public MutableSchema setName(String name) {
62 _name = name;
63 return this;
64 }
65
66 @Override
67 public List<Table> getTables() {
68 return Collections.unmodifiableList(_tables);
69 }
70
71
72 public MutableSchema setTables(Collection<? extends Table> tables) {
73 clearTables();
74 for (Table table : tables) {
75 _tables.add(table);
76 }
77 return this;
78 }
79
80 public MutableSchema setTables(Table... tables) {
81 clearTables();
82 for (Table table : tables) {
83 _tables.add(table);
84 }
85 return this;
86 }
87
88 public MutableSchema clearTables() {
89 _tables.clear();
90 return this;
91 }
92
93 public MutableSchema addTable(Table table) {
94 _tables.add(table);
95 return this;
96 }
97
98 public MutableSchema removeTable(Table table) {
99 _tables.remove(table);
100 return this;
101 }
102
103 @Override
104 public String getQuote() {
105 return null;
106 }
107 }