001: /* Copyright (c) 2001-2005, The HSQL Development Group
002: * All rights reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * Redistributions of source code must retain the above copyright notice, this
008: * list of conditions and the following disclaimer.
009: *
010: * Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * Neither the name of the HSQL Development Group nor the names of its
015: * contributors may be used to endorse or promote products derived from this
016: * software without specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
020: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
021: * ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG,
022: * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
023: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
025: * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
026: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
027: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
028: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029: */
030:
031: package org.hsqldb;
032:
033: import org.hsqldb.HsqlNameManager.HsqlName;
034: import org.hsqldb.lib.HashMap;
035: import org.hsqldb.lib.Iterator;
036:
037: /**
038: * Transitional container for object names that are unique across the
039: * DB instance but are owned by different DB objects. Currently names for
040: * Index and Trigger objects.<p>
041: *
042: * @author fredt@users
043: * @version 1.7.2
044: * @since 1.7.2
045: */
046: class DatabaseObjectNames {
047:
048: HashMap nameList = new HashMap();
049:
050: DatabaseObjectNames() {
051: }
052:
053: boolean containsName(String name) {
054: return nameList.containsKey(name);
055: }
056:
057: HsqlName getOwner(String name) {
058: return (HsqlName) nameList.get(name);
059: }
060:
061: void addName(String name, HsqlName owner, int errorcode)
062: throws HsqlException {
063:
064: // should not contain name
065: if (containsName(name)) {
066: throw Trace.error(errorcode, name);
067: }
068:
069: nameList.put(name, owner);
070: }
071:
072: void rename(String name, String newname, int errorcode)
073: throws HsqlException {
074:
075: HsqlName owner = (HsqlName) nameList.get(name);
076:
077: addName(newname, owner, errorcode);
078: nameList.remove(name);
079: }
080:
081: Object removeName(String name) throws HsqlException {
082:
083: Object owner = nameList.remove(name);
084:
085: if (owner == null) {
086:
087: // should contain name
088: throw Trace.error(Trace.GENERAL_ERROR);
089: }
090:
091: return owner;
092: }
093:
094: void removeOwner(HsqlName owner) {
095:
096: Iterator it = nameList.values().iterator();
097:
098: while (it.hasNext()) {
099: Object currentvalue = it.next();
100:
101: if (owner.equals(currentvalue)) {
102: it.remove();
103: }
104: }
105: }
106: }
|