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 18:34:20
035: */
036: public class Database {
037:
038: private String name;
039: private OrderedMap<String, DBCatalog> catalogs;
040: private OrderedMap<String, DBSchema> schemas;
041:
042: // constructors ----------------------------------------------------------------------------------------------------
043:
044: public Database() {
045: this (null, null);
046: }
047:
048: public Database(String name, OrderedMap<String, DBCatalog> catalogs) {
049: this .name = name;
050: this .catalogs = new OrderedMap<String, DBCatalog>();
051: if (catalogs != null)
052: this .catalogs.putAll(catalogs);
053: this .schemas = new OrderedMap<String, DBSchema>();
054: }
055:
056: // properties ------------------------------------------------------------------------------------------------------
057:
058: public String getName() {
059: return name;
060: }
061:
062: // catalog operations ----------------------------------------------------------------------------------------------
063:
064: public List<DBCatalog> getCatalogs() {
065: return catalogs.values();
066: }
067:
068: public DBCatalog getCatalog(String catalogName) {
069: return catalogs.get(catalogName);
070: }
071:
072: public void addCatalog(DBCatalog catalog) {
073: catalog.setDatabase(this );
074: catalogs.put(catalog.getName(), catalog);
075: }
076:
077: public void removeCatalog(DBCatalog catalog) {
078: catalogs.remove(catalog.getName());
079: catalog.setDatabase(null);
080: }
081:
082: // schema operations -----------------------------------------------------------------------------------------------
083:
084: public List<DBSchema> getSchemas() {
085: return schemas.values();
086: }
087:
088: public DBSchema getSchema(String schemaName) {
089: return schemas.get(schemaName);
090: }
091:
092: public void addSchema(DBSchema schema) {
093: schema.setDatabase(this );
094: schemas.put(schema.getName(), schema);
095: }
096:
097: public void removeSchema(DBSchema schema) {
098: schemas.remove(schema.getName());
099: schema.setDatabase(null);
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 Database that = (Database) 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:
124: }
|