001: /*
002: * argun 1.0
003: * Web 2.0 delivery framework
004: * Copyright (C) 2007 Hammurapi Group
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2 of the License, or (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: * URL: http://www.hammurapi.biz
021: * e-Mail: support@hammurapi.biz
022: */
023:
024: package biz.hammurapi.web.mda.db.model;
025:
026: import java.sql.DatabaseMetaData;
027: import java.sql.ResultSet;
028: import java.sql.SQLException;
029: import java.util.ArrayList;
030: import java.util.Collection;
031: import java.util.Iterator;
032: import java.util.Properties;
033:
034: import org.apache.xpath.CachedXPathAPI;
035: import org.w3c.dom.Element;
036:
037: import biz.hammurapi.config.ConfigurationException;
038: import biz.hammurapi.sql.DataAccessObject;
039: import biz.hammurapi.sql.SQLProcessor;
040: import biz.hammurapi.util.CollectionVisitable;
041: import biz.hammurapi.util.Visitable;
042: import biz.hammurapi.util.Visitor;
043: import biz.hammurapi.web.ActionsBase;
044: import biz.hammurapi.web.metadata.DbmSchemaImpl;
045: import biz.hammurapi.web.metadata.MetadataEngine;
046: import biz.hammurapi.xml.dom.AbstractDomObject;
047: import biz.hammurapi.xml.dom.CompositeDomSerializer;
048:
049: /**
050: * Schema
051: * @author Pavel
052: *
053: */
054: public class Schema extends DbmSchemaImpl implements Visitable,
055: DataAccessObject {
056:
057: private Collection tables = new ArrayList();
058:
059: public Schema() {
060: }
061:
062: public Schema(boolean force) {
063: super (force);
064: }
065:
066: public Schema(ResultSet rs) throws SQLException {
067: super (rs);
068: }
069:
070: public Schema(Element holder, boolean force)
071: throws ConfigurationException {
072: super (holder, force);
073: }
074:
075: public Schema(Element holder, Properties nameMap,
076: CachedXPathAPI cxpa, boolean force)
077: throws ConfigurationException {
078: super (holder, nameMap, cxpa, force);
079: }
080:
081: public boolean accept(Visitor visitor) {
082: if (!visitor.visit(this )) {
083: return false;
084: }
085:
086: new CollectionVisitable(tables, false).accept(visitor);
087: return true;
088: }
089:
090: public void setSQLProcessor(SQLProcessor processor)
091: throws SQLException {
092: MetadataEngine engine = new MetadataEngine(processor);
093: engine.getDbmTableBySchema(getId(), tables, Table.class);
094: Iterator it = tables.iterator();
095: while (it.hasNext()) {
096: Table table = (Table) it.next();
097: table.setOwner(this );
098: }
099: }
100:
101: private Catalog owner;
102:
103: public Catalog getOwner() {
104: return owner;
105: }
106:
107: void setOwner(Catalog owner) {
108: this .owner = owner;
109: }
110:
111: void loadMetaData(DatabaseMetaData metaData) throws SQLException {
112: Iterator it = tables.iterator();
113: while (it.hasNext()) {
114: ((Table) it.next()).loadMetaData(metaData);
115: }
116: }
117:
118: public void toDom(Element holder) {
119: super .toDom(holder);
120: CompositeDomSerializer.getThreadInstance().toDomSerializable(
121: tables).toDom(
122: AbstractDomObject.addElement(holder, "tables"));
123: }
124:
125: public String getFullName() {
126: String ownerName = getOwner() == null ? null : owner.getName();
127: return ActionsBase.isBlank(ownerName) ? getName() : ownerName
128: + "." + getName();
129: }
130: }
|