001: /*
002: * transformica 2
003: * Code generator
004: * Copyright (C) 2004 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.pavelvlasov.com/pv/content/menu.show@id=products.transformica.html
021: * e-Mail: support@hammurapi.biz
022: */
023: package biz.hammurapi.transformica.jdbc;
024:
025: import biz.hammurapi.sql.metadata.TableDescriptor;
026: import biz.hammurapi.transformica.Channel;
027: import biz.hammurapi.transformica.TransformSession;
028: import biz.hammurapi.util.Acceptor;
029: import biz.hammurapi.util.CompositeAcceptor;
030:
031: /**
032: * Transformation channel.
033: * @ant.element name="channel"
034: * @author Pavel Vlasov
035: * @version $Revision: 1.1 $
036: */
037: public class TableChannel extends Channel {
038:
039: private String catalog;
040: private String schema;
041: private String table;
042:
043: /**
044: * @return Returns the catalog.
045: * @ant.ignore
046: */
047: public String getCatalog() {
048: return catalog;
049: }
050:
051: /**
052: * Process tables only from this catalog.
053: * @param catalog The catalog to set.
054: * @ant.non-required
055: */
056: public void setCatalog(String catalog) {
057: this .catalog = catalog;
058: }
059:
060: /**
061: * @return Returns the schema.
062: * @ant.ignore
063: */
064: public String getSchema() {
065: return schema;
066: }
067:
068: /**
069: * Process tables only from this schema
070: * @param schema The schema to set.
071: * @ant.non-required
072: */
073: public void setSchema(String schema) {
074: this .schema = schema;
075: }
076:
077: /**
078: * @return Returns the table.
079: * @ant.ignore
080: */
081: public String getTable() {
082: return table;
083: }
084:
085: /**
086: * Defines transformation channel.
087: * @ant.required
088: * @return
089: */
090: public TableChannel createTableChannel() {
091: TableChannel ret = new TableChannel(session);
092: channels.add(ret);
093: return ret;
094: }
095:
096: /**
097: * Process only tables with this name.
098: * @param table The table to set.
099: * @ant.non-required
100: */
101: public void setTable(String table) {
102: this .table = table;
103: }
104:
105: /**
106: * @param task
107: */
108: public TableChannel(TransformSession session) {
109: super (session);
110: }
111:
112: private boolean compositeAcceptorConfigured = false;
113:
114: public CompositeAcceptor getCompositeAcceptor() {
115: CompositeAcceptor ca = super .getCompositeAcceptor();
116: if (!compositeAcceptorConfigured) {
117: ca.addAcceptor(new Acceptor() {
118: public boolean accept(Object element) {
119: if (element instanceof TableDescriptor) {
120: TableDescriptor td = (TableDescriptor) element;
121: return (catalog == null || catalog.equals(td
122: .getCatalog()))
123: && (schema == null || schema.equals(td
124: .getSchema()))
125: && (table == null || table.equals(td
126: .getTableName()));
127: } else {
128: return false;
129: }
130: }
131: });
132: compositeAcceptorConfigured = true;
133: }
134: return ca;
135: }
136: }
|