001: /*
002: * (c) Copyright 2006 by Volker Bergmann. All rights reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, is permitted under the terms of the
006: * GNU General Public License.
007: *
008: * For redistributing this software or a derivative work under a license other
009: * than the GPL-compatible Free Software License as defined by the Free
010: * Software Foundation or approved by OSI, you must first obtain a commercial
011: * license to this software product from Volker Bergmann.
012: *
013: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
014: * WITHOUT A WARRANTY OF ANY KIND. ALL EXPRESS OR IMPLIED CONDITIONS,
015: * REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF
016: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE
017: * HEREBY EXCLUDED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
018: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
019: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
020: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
021: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
022: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
023: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
024: * POSSIBILITY OF SUCH DAMAGE.
025: */
026:
027: package org.databene.platform.db.model;
028:
029: import org.databene.commons.OrderedMap;
030:
031: import java.util.List;
032:
033: /**
034: * Created: 06.01.2007 08:57:57
035: */
036: public class DBSchema {
037:
038: private Database database;
039: private String name;
040: private DBCatalog catalog;
041: private OrderedMap<String, DBTable> tables;
042:
043: // constructors ----------------------------------------------------------------------------------------------------
044:
045: public DBSchema() {
046: this (null);
047: }
048:
049: public DBSchema(String name) {
050: this (null, name);
051: }
052:
053: public DBSchema(Database database, String name) {
054: this .name = name;
055: this .database = database;
056: this .catalog = null;
057: this .tables = new OrderedMap<String, DBTable>();
058: }
059:
060: // properties ------------------------------------------------------------------------------------------------------
061:
062: public Database getDatabase() {
063: return database;
064: }
065:
066: public void setDatabase(Database database) {
067: this .database = database;
068: }
069:
070: public String getName() {
071: return name;
072: }
073:
074: // catalog operations ----------------------------------------------------------------------------------------------
075:
076: public DBCatalog getCatalog() {
077: return catalog;
078: }
079:
080: public void setCatalog(DBCatalog catalog) {
081: this .catalog = catalog;
082: }
083:
084: // table operations ------------------------------------------------------------------------------------------------
085:
086: public List<DBTable> getTables() {
087: return tables.values();
088: }
089:
090: public DBTable getTable(String tableName) {
091: return tables.get(tableName.toUpperCase());
092: }
093:
094: public void addTable(DBTable table) {
095: tables.put(table.getName().toUpperCase(), table);
096: }
097:
098: public void removeTable(DBTable table) {
099: tables.remove(table.getName());
100: }
101:
102: // java.lang.Object overrides --------------------------------------------------------------------------------------
103:
104: @Override
105: public boolean equals(Object o) {
106: if (this == o)
107: return true;
108: if (o == null || getClass() != o.getClass())
109: return false;
110: final DBSchema that = (DBSchema) o;
111: return name.equals(that.name);
112: }
113:
114: @Override
115: public int hashCode() {
116: return name.hashCode();
117: }
118:
119: @Override
120: public String toString() {
121: return name;
122: }
123: }
|