Source Code Cross Referenced for TargetTableImpl.java in  » IDE-Netbeans » etl.project » org » netbeans » modules » sql » framework » model » impl » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » etl.project » org.netbeans.modules.sql.framework.model.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0003:         *
0004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
0005:         *
0006:         * The contents of this file are subject to the terms of either the GNU
0007:         * General Public License Version 2 only ("GPL") or the Common
0008:         * Development and Distribution License("CDDL") (collectively, the
0009:         * "License"). You may not use this file except in compliance with the
0010:         * License. You can obtain a copy of the License at
0011:         * http://www.netbeans.org/cddl-gplv2.html
0012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
0013:         * specific language governing permissions and limitations under the
0014:         * License.  When distributing the software, include this License Header
0015:         * Notice in each file and include the License file at
0016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
0017:         * particular file as subject to the "Classpath" exception as provided
0018:         * by Sun in the GPL Version 2 section of the License file that
0019:         * accompanied this code. If applicable, add the following below the
0020:         * License Header, with the fields enclosed by brackets [] replaced by
0021:         * your own identifying information:
0022:         * "Portions Copyrighted [year] [name of copyright owner]"
0023:         *
0024:         * Contributor(s):
0025:         *
0026:         * The Original Software is NetBeans. The Initial Developer of the Original
0027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
0028:         * Microsystems, Inc. All Rights Reserved.
0029:         *
0030:         * If you wish your version of this file to be governed by only the CDDL
0031:         * or only the GPL Version 2, indicate your decision by adding
0032:         * "[Contributor] elects to include this software in this distribution
0033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
0034:         * single choice of license, a recipient has the option to distribute
0035:         * your version of this file under either the CDDL, the GPL Version 2 or
0036:         * to extend the choice of license to its licensees as provided above.
0037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
0038:         * Version 2 license, then the option applies only if the new code is
0039:         * made subject to such option by the copyright holder.
0040:         */
0041:        package org.netbeans.modules.sql.framework.model.impl;
0042:
0043:        import java.util.ArrayList;
0044:        import java.util.Collection;
0045:        import java.util.Collections;
0046:        import java.util.Comparator;
0047:        import java.util.Iterator;
0048:        import java.util.LinkedHashMap;
0049:        import java.util.List;
0050:        import java.util.Map;
0051:
0052:        import org.netbeans.modules.sql.framework.model.DBColumn;
0053:        import org.netbeans.modules.sql.framework.common.utils.TagParserUtility;
0054:        import org.netbeans.modules.sql.framework.codegen.AbstractGeneratorFactory;
0055:        import org.netbeans.modules.sql.framework.codegen.DB;
0056:        import org.netbeans.modules.sql.framework.codegen.DBFactory;
0057:        import org.netbeans.modules.sql.framework.codegen.SQLOperatorFactory;
0058:        import org.netbeans.modules.sql.framework.codegen.StatementContext;
0059:        import org.netbeans.modules.sql.framework.model.GUIInfo;
0060:        import org.netbeans.modules.sql.framework.model.SQLCaseOperator;
0061:        import org.netbeans.modules.sql.framework.model.SQLCondition;
0062:        import org.netbeans.modules.sql.framework.model.SQLConnectableObject;
0063:        import org.netbeans.modules.sql.framework.model.SQLConstants;
0064:        import org.netbeans.modules.sql.framework.model.SQLDBColumn;
0065:        import org.netbeans.modules.sql.framework.model.SQLDBModel;
0066:        import org.netbeans.modules.sql.framework.model.SQLDefinition;
0067:        import org.netbeans.modules.sql.framework.model.SQLGroupBy;
0068:        import org.netbeans.modules.sql.framework.model.SQLInputObject;
0069:        import org.netbeans.modules.sql.framework.model.SQLJoinView;
0070:        import org.netbeans.modules.sql.framework.model.SQLModelObjectFactory;
0071:        import org.netbeans.modules.sql.framework.model.SQLObject;
0072:        import org.netbeans.modules.sql.framework.model.SQLPredicate;
0073:        import org.netbeans.modules.sql.framework.model.SourceColumn;
0074:        import org.netbeans.modules.sql.framework.model.SourceTable;
0075:        import org.netbeans.modules.sql.framework.model.TargetColumn;
0076:        import org.netbeans.modules.sql.framework.model.TargetTable;
0077:        import org.netbeans.modules.sql.framework.model.utils.ConditionUtil;
0078:        import org.netbeans.modules.sql.framework.model.utils.SQLObjectUtil;
0079:        import org.netbeans.modules.sql.framework.model.visitors.SQLVisitor;
0080:        import org.w3c.dom.Element;
0081:        import org.w3c.dom.Node;
0082:        import org.w3c.dom.NodeList;
0083:        import net.java.hulp.i18n.Logger;
0084:        import com.sun.sql.framework.exception.BaseException;
0085:        import org.netbeans.modules.etl.logger.Localizer;
0086:        import org.netbeans.modules.etl.logger.LogUtil;
0087:        import org.netbeans.modules.sql.framework.model.DBTable;
0088:
0089:        /**
0090:         * Concrete implementation of TargetTable and SQLConnectableObject classes / interfaces,
0091:         * representing table metadata and linking information for a target table.
0092:         * 
0093:         * @author Jonathan Giron
0094:         * @version $Revision$
0095:         */
0096:        public class TargetTableImpl extends AbstractDBTable implements 
0097:                TargetTable {
0098:
0099:            /**
0100:             * type of statement to generate while loading target table
0101:             * 
0102:             */
0103:            public static final String ATTR_STATEMENT_TYPE = "statementType";
0104:            private static final String ATTR_BATCHSIZE = "batchSize";
0105:            private static final String ATTR_FULLY_QUALIFIED_NAME = "fullyQualifiedName";
0106:            private static final String ATTR_CREATE_TARGET_TABLE = "createTargetTable";
0107:            private static final String ATTR_TRUNCATE_BEFORE_LOAD = "truncateBeforeLoad";
0108:            private static transient final Logger mLogger = LogUtil
0109:                    .getLogger(TargetTableImpl.class.getName());
0110:            private static transient final Localizer mLoc = Localizer.get();
0111:            private SQLCondition joinCondition;
0112:            private SQLCondition filterCondition;
0113:            private SQLCondition havingCondition;
0114:            /** having condition tag */
0115:            public static final String HAVING_CONDITION = "havingCondition";
0116:            private SQLGroupBy groupBy;
0117:
0118:            /** Constructs a new default instance of TargetTableImpl. */
0119:            public TargetTableImpl() {
0120:                super ();
0121:                init();
0122:            }
0123:
0124:            /**
0125:             * Constructs a new instance of TargetTable, cloning the contents of the given DBTable
0126:             * implementation instance.
0127:             * 
0128:             * @param src DBTable instance to be cloned
0129:             */
0130:            public TargetTableImpl(DBTable src) {
0131:                this ();
0132:
0133:                if (src == null) {
0134:                    throw new IllegalArgumentException(
0135:                            "Must supply non-null DBTable instance for src param.");
0136:                }
0137:                copyFrom(src);
0138:            }
0139:
0140:            /**
0141:             * Constructs a new instance of TargetTable with the given name.
0142:             * 
0143:             * @param aName name of new DBTable instance
0144:             * @param aSchema schema of new DBTable instance; may be null
0145:             * @param aCatalog catalog of new DBTable instance; may be null
0146:             */
0147:            public TargetTableImpl(String aName, String aSchema, String aCatalog) {
0148:                super (aName, aSchema, aCatalog);
0149:                init();
0150:            }
0151:
0152:            /*
0153:             * Implementation of DBTable interface.
0154:             */
0155:            /**
0156:             * Adds a TargetColumn instance to this table.
0157:             * 
0158:             * @param aColumn column to be added.
0159:             * @return true if successful. false if failed.
0160:             */
0161:            public boolean addColumn(TargetColumn aColumn) {
0162:                if (aColumn != null) {
0163:                    aColumn.setParent(this );
0164:                    columns.put(aColumn.getName(), aColumn);
0165:
0166:                    return true;
0167:                }
0168:
0169:                return false;
0170:            }
0171:
0172:            /**
0173:             * @see SQLConnectableObject#addInput
0174:             */
0175:            public void addInput(String argName, SQLObject newInput)
0176:                    throws BaseException {
0177:                if (argName == null || argName.trim().length() == 0) {
0178:                    throw new IllegalArgumentException(
0179:                            "Must supply non-empty String ref for parameter argName.");
0180:                }
0181:
0182:                if (newInput == null) {
0183:                    throw new IllegalArgumentException(
0184:                            "Must supply non-null SQLObject ref for parameter newInput.");
0185:                }
0186:
0187:                int newType = newInput.getObjectType();
0188:                String objType = TagParserUtility.getStringType(newType);
0189:
0190:                if (!isInputValid(argName, newInput)) {
0191:                    throw new BaseException("Cannot link " + objType + " '"
0192:                            + newInput.getDisplayName() + "' as input to '"
0193:                            + argName + "' in "
0194:                            + TagParserUtility.getDisplayStringFor(this .type)
0195:                            + " '" + this .getDisplayName() + "'");
0196:                }
0197:
0198:                // Now locate associated column and set newInput as its value.
0199:                TargetColumn col = (TargetColumn) columns.get(argName);
0200:                if (col != null) {
0201:                    col.setValue(newInput);
0202:                } else {
0203:                    throw new BaseException(
0204:                            "Could not locate column associated with argName: "
0205:                                    + argName);
0206:                }
0207:
0208:                // Now if the target column where we added input is primary key or unique
0209:                // then we need to add a constraint check filter  by default
0210:                if (col != null && col.isPrimaryKey()
0211:                        && newInput instanceof  SQLDBColumn) {
0212:                    try {
0213:                        SQLCondition cond = this .getJoinCondition();
0214:                        if (cond == null) {
0215:                            cond = SQLModelObjectFactory.getInstance()
0216:                                    .createSQLCondition(JOIN_CONDITION);
0217:                        }
0218:                        cond.addEqualityPredicate(newInput, col);
0219:                    } catch (BaseException ex) {
0220:                        // we should not throw this exception; this is just fail to
0221:                        // create an automatic filter so we can ignore now.
0222:                        mLogger
0223:                                .errorNoloc(
0224:                                        mLoc
0225:                                                .t(
0226:                                                        "PRSR120: Could not create auto joinCondition for target table.{0}",
0227:                                                        TargetTableImpl.class
0228:                                                                .getName()), ex);
0229:                    }
0230:                }
0231:            }
0232:
0233:            /**
0234:             * Clone a copy of TargetTableImpl.
0235:             * 
0236:             * @return a copy of TargetTableImpl.
0237:             */
0238:            public Object clone() {
0239:                try {
0240:                    TargetTableImpl aClone = new TargetTableImpl(this );
0241:                    return aClone;
0242:                } catch (Exception e) {
0243:                    throw new InternalError(e.toString());
0244:                }
0245:            }
0246:
0247:            /**
0248:             * Sets the various member variables and collections using the given DBTable instance
0249:             * as a source object. Concrete implementations should override this method, call
0250:             * super.copyFrom(DBColumn) to pick up member variables defined in this class and then
0251:             * implement its own logic for copying member variables defined within itself.
0252:             * 
0253:             * @param source DBTable from which to obtain values for member variables and
0254:             *        collections
0255:             */
0256:            public void copyFrom(DBTable source) {
0257:                super .copyFrom(source);
0258:
0259:                List sourceColumns = source.getColumnList();
0260:                if (sourceColumns != null) {
0261:                    Iterator iter = sourceColumns.iterator();
0262:
0263:                    // Must do deep copy to ensure correct parent-child relationship.
0264:                    while (iter.hasNext()) {
0265:                        addColumn(SQLModelObjectFactory.getInstance()
0266:                                .createTargetColumn((DBColumn) iter.next()));
0267:                    }
0268:                }
0269:
0270:                if (source instanceof  TargetTable) {
0271:                    TargetTable tgtSource = (TargetTable) source;
0272:                    SQLCondition srcJoinCondition = tgtSource
0273:                            .getJoinCondition();
0274:                    if (srcJoinCondition != null) {
0275:                        try {
0276:                            joinCondition = (SQLCondition) srcJoinCondition
0277:                                    .cloneSQLObject();
0278:                        } catch (CloneNotSupportedException ignore) {
0279:                            // ignore
0280:                        }
0281:                    }
0282:
0283:                    SQLCondition srcFilterCondition = tgtSource
0284:                            .getFilterCondition();
0285:                    if (srcFilterCondition != null) {
0286:                        try {
0287:                            filterCondition = (SQLCondition) srcFilterCondition
0288:                                    .cloneSQLObject();
0289:                        } catch (CloneNotSupportedException ignore) {
0290:                            // ignore
0291:                        }
0292:                    }
0293:
0294:                    SQLGroupBy grpBy = tgtSource.getSQLGroupBy();
0295:                    if (grpBy != null) {
0296:                        groupBy = new SQLGroupByImpl(grpBy);
0297:                    }
0298:                }
0299:            }
0300:
0301:            /**
0302:             * Convenience class to create DBColumnImpl instance (with the given column name, data
0303:             * source name, JDBC type, scale, precision, and nullable), and add it to this
0304:             * TargetTable instance.
0305:             * 
0306:             * @param columnName Column name
0307:             * @param jdbcType JDBC type defined in SQL.Types
0308:             * @param scale Scale
0309:             * @param precision Precision
0310:             * @param isPK true if part of primary key, false otherwise
0311:             * @param isFK true if part of foreign key, false otherwise
0312:             * @param isIndexed true if indexed, false otherwise
0313:             * @param nullable Nullable
0314:             * @return new DBColumnImpl instance
0315:             */
0316:            public TargetColumn createColumn(String columnName, int jdbcType,
0317:                    int scale, int precision, boolean isPK, boolean isFK,
0318:                    boolean isIndexed, boolean nullable) {
0319:                TargetColumn impl = SQLModelObjectFactory.getInstance()
0320:                        .createTargetColumn(columnName, jdbcType, scale,
0321:                                precision, isPK, isFK, isIndexed, nullable);
0322:                addColumn(impl);
0323:                return impl;
0324:            }
0325:
0326:            /**
0327:             * @see org.netbeans.modules.sql.framework.model.impl.AbstractDBColumn#equals(java.lang.Object)
0328:             */
0329:            public boolean equals(Object obj) {
0330:                // Check for reflexivity first.
0331:                if (this  == obj) {
0332:                    return true;
0333:                } else if (!(obj instanceof  TargetTable)) {
0334:                    return false;
0335:                }
0336:
0337:                boolean result = super .equals(obj);
0338:                TargetTable src = (TargetTable) obj;
0339:
0340:                result &= (joinCondition != null) ? joinCondition.equals(src
0341:                        .getJoinCondition()) : (src.getJoinCondition() == null);
0342:                result &= (filterCondition != null) ? filterCondition
0343:                        .equals(src.getFilterCondition()) : (src
0344:                        .getFilterCondition() == null);
0345:
0346:                return result;
0347:            }
0348:
0349:            /**
0350:             * Gets list of child sql objects.
0351:             * 
0352:             * @return child sql objects
0353:             */
0354:            public List getChildSQLObjects() {
0355:                return this .getColumnList();
0356:            }
0357:
0358:            /**
0359:             * Gets the target table joinCondition.
0360:             * 
0361:             * @return target table conidiotn
0362:             */
0363:            public SQLCondition getJoinCondition() {
0364:                // if there are no objects in graph then populate graph with the objects
0365:                // obtained from sql text
0366:                Collection objC = joinCondition.getAllObjects();
0367:                if (objC == null || objC.size() == 0) {
0368:                    SQLDefinition def = SQLObjectUtil
0369:                            .getAncestralSQLDefinition(this );
0370:                    try {
0371:                        ConditionUtil.populateCondition(joinCondition, def,
0372:                                this .getJoinConditionText());
0373:                    } catch (Exception ex) {
0374:                        // ignore this if joinCondition typed by user is invalid
0375:                    }
0376:                }
0377:
0378:                return joinCondition;
0379:            }
0380:
0381:            /**
0382:             * Gets joinCondition text.
0383:             * 
0384:             * @return sql joinCondition
0385:             */
0386:            public String getJoinConditionText() {
0387:                return joinCondition.getConditionText();
0388:            }
0389:
0390:            /**
0391:             * @see SQLConnectableObject#addInput
0392:             */
0393:            public SQLInputObject getInput(String argName) {
0394:                if (argName == null || argName.trim().length() == 0) {
0395:                    throw new IllegalArgumentException(
0396:                            "Must supply non-empty String ref for parameter argName.");
0397:                }
0398:
0399:                TargetColumn col = (TargetColumn) columns.get(argName);
0400:                return (col != null) ? new SQLInputObjectImpl(argName, argName,
0401:                        col) : null;
0402:            }
0403:
0404:            /**
0405:             * @see SQLConnectableObject#getInputObjectMap
0406:             */
0407:            public Map getInputObjectMap() {
0408:                Map inputMap = Collections.EMPTY_MAP;
0409:
0410:                if (columns.size() != 0) {
0411:                    inputMap = new LinkedHashMap(columns.size());
0412:
0413:                    Iterator iter = columns.values().iterator();
0414:                    while (iter.hasNext()) {
0415:                        TargetColumn col = (TargetColumn) iter.next();
0416:                        SQLInputObject input = new SQLInputObjectImpl(col
0417:                                .getName(), col.getDisplayName(), col
0418:                                .getValue());
0419:                        inputMap.put(col.getName(), input);
0420:                    }
0421:                }
0422:
0423:                return inputMap;
0424:            }
0425:
0426:            /**
0427:             * Gets the single join view which is mapped to this target table in case of multiple
0428:             * source table mapping to this target table.
0429:             * 
0430:             * @return associated SQLJoinView, if any.
0431:             */
0432:            public SQLJoinView getJoinView() {
0433:                SQLJoinView joinView = null;
0434:
0435:                try {
0436:                    List cols = this .getColumnList();
0437:                    Iterator it = cols.iterator();
0438:                    while (it.hasNext()) {
0439:                        TargetColumn tc = (TargetColumn) it.next();
0440:                        SQLObject sqlObj = tc.getValue();
0441:                        // we only need to search for first mapped target column
0442:                        if (sqlObj != null) {
0443:                            joinView = discoverJoinView(sqlObj);
0444:                            if (joinView != null) {
0445:                                break;
0446:                            }
0447:                        }
0448:                    }
0449:                } catch (BaseException ex) {
0450:                    mLogger
0451:                            .errorNoloc(
0452:                                    mLoc
0453:                                            .t(
0454:                                                    "PRSR121: Could not find a join view for this target table{0}",
0455:                                                    this .getName()), ex);
0456:                    // Logger.printThrowable(Logger.ERROR, TargetTableImpl.class.getName(), "getJoinView", "Could not find a join view for this target table "
0457:                    //    + this.getName(), ex);
0458:                }
0459:
0460:                return joinView;
0461:            }
0462:
0463:            public List getMappedColumns() {
0464:                ArrayList mappedColumns = new ArrayList();
0465:
0466:                Iterator it = this .getColumnList().iterator();
0467:                while (it.hasNext()) {
0468:                    TargetColumn column = (TargetColumn) it.next();
0469:                    if (column.getValue() != null) {
0470:                        mappedColumns.add(column);
0471:                    }
0472:                }
0473:
0474:                return mappedColumns;
0475:            }
0476:
0477:            /**
0478:             * @see SQLObject#getOutput(java.lang.String)
0479:             */
0480:            public SQLObject getOutput(String argName) throws BaseException {
0481:                throw new BaseException(
0482:                        "TargetTable cannot supply an output SQLObject.");
0483:            }
0484:
0485:            public List getSourceColumnsUsed() {
0486:                return new ArrayList();
0487:            }
0488:
0489:            /**
0490:             * Gets the source table list.
0491:             * 
0492:             * @return List of all source tables
0493:             * @throws BaseException if error occurs while getting Source Table List
0494:             */
0495:            public List getSourceTableList() throws BaseException {
0496:
0497:                if (this .getJoinView() != null) {
0498:                    return this .getJoinView().getSourceTables();
0499:                }
0500:
0501:                List cols = this .getColumnList();
0502:                List tables = new ArrayList();
0503:                Iterator it = cols.iterator();
0504:                while (it.hasNext()) {
0505:                    TargetColumn tc = (TargetColumn) it.next();
0506:                    SQLObject sqlObj = tc.getValue();
0507:                    if (sqlObj != null) {
0508:                        discoverTables(sqlObj, tables);
0509:                    }
0510:                }
0511:                return tables;
0512:            }
0513:
0514:            /**
0515:             * @see org.netbeans.modules.sql.framework.model.SourceTable#getSQLGroupBy()
0516:             */
0517:            public SQLGroupBy getSQLGroupBy() {
0518:                return groupBy;
0519:            }
0520:
0521:            /**
0522:             * @see SQLConnectableObject#getSQLObject
0523:             */
0524:            public SQLObject getSQLObject(String argName) {
0525:                TargetColumn col = (TargetColumn) columns.get(argName);
0526:                return (col != null) ? col.getValue() : null;
0527:            }
0528:
0529:            /**
0530:             * @see SQLConnectableObject#getSQLObjectMap
0531:             */
0532:            public Map getSQLObjectMap() {
0533:                Map objectMap = new LinkedHashMap(10);
0534:                Iterator iter = columns.entrySet().iterator();
0535:
0536:                while (iter.hasNext()) {
0537:                    Map.Entry entry = (Map.Entry) iter.next();
0538:
0539:                    String argName = (String) entry.getKey();
0540:                    TargetColumn col = (TargetColumn) entry.getValue();
0541:
0542:                    if (argName != null && col.getValue() != null) {
0543:                        objectMap.put(argName, col.getValue());
0544:                    }
0545:                }
0546:
0547:                return objectMap;
0548:            }
0549:
0550:            /**
0551:             * Gets the type of statement type for this table.
0552:             * 
0553:             * @return statement type
0554:             */
0555:            public int getStatementType() {
0556:                Integer sType = (Integer) this 
0557:                        .getAttributeObject(ATTR_STATEMENT_TYPE);
0558:                if (sType != null) {
0559:                    return sType.intValue();
0560:                }
0561:
0562:                return SQLConstants.INSERT_STATEMENT;
0563:            }
0564:
0565:            /**
0566:             * Gets string representation of statement type.
0567:             * 
0568:             * @return statement type
0569:             */
0570:            public String getStrStatementType() {
0571:                if (this .getStatementType() == SQLConstants.INSERT_STATEMENT) {
0572:                    return SQLConstants.STR_INSERT_STATEMENT;
0573:                } else if (this .getStatementType() == SQLConstants.INSERT_UPDATE_STATEMENT) {
0574:                    return SQLConstants.STR_INSERT_UPDATE_STATEMENT;
0575:                } else if (this .getStatementType() == SQLConstants.UPDATE_STATEMENT) {
0576:                    return SQLConstants.STR_UPDATE_STATEMENT;
0577:                } else if (this .getStatementType() == SQLConstants.DELETE_STATEMENT) {
0578:                    return SQLConstants.STR_DELETE_STATEMENT;
0579:                }
0580:
0581:                return null;
0582:            }
0583:
0584:            /**
0585:             * Gets the TargetColumn, if any, associated with the given name
0586:             * 
0587:             * @param columnName column name
0588:             * @return TargetColumn associated with columnName, or null if none exists
0589:             */
0590:            public TargetColumn getTargetColumn(String columnName) {
0591:                return (TargetColumn) columns.get(columnName);
0592:            }
0593:
0594:            public List getTargetColumnsUsed() {
0595:                return getMappedColumns();
0596:            }
0597:
0598:            /**
0599:             * Overrides default implementation to compute hashCode value for those members used
0600:             * in equals() for comparison.
0601:             * 
0602:             * @return hash code for this object
0603:             * @see java.lang.Object#hashCode
0604:             */
0605:            public int hashCode() {
0606:                return super .hashCode()
0607:                        + ((joinCondition != null) ? joinCondition.hashCode()
0608:                                : 0)
0609:                        + ((getJoinConditionText() != null) ? getJoinConditionText()
0610:                                .hashCode()
0611:                                : 0)
0612:                        + ((filterCondition != null) ? filterCondition
0613:                                .hashCode() : 0)
0614:                        + ((getFilterConditionText() != null) ? getFilterConditionText()
0615:                                .hashCode()
0616:                                : 0);
0617:            }
0618:
0619:            public boolean hasSourceColumn() {
0620:                return false;
0621:            }
0622:
0623:            public boolean hasTargetColumn() {
0624:                return true;
0625:            }
0626:
0627:            /**
0628:             * Indicates whether to create target table if it does not already exist.
0629:             * 
0630:             * @return whether to create target table
0631:             */
0632:            public boolean isCreateTargetTable() {
0633:                Boolean create = (Boolean) this 
0634:                        .getAttributeObject(ATTR_CREATE_TARGET_TABLE);
0635:                if (create != null) {
0636:                    return create.booleanValue();
0637:                }
0638:
0639:                return true;
0640:            }
0641:
0642:            /**
0643:             * Indicates whether this is an expression object.
0644:             * 
0645:             * @return true if the object is a Expression Object
0646:             */
0647:            public boolean isExpressionObject() {
0648:                return true;
0649:            }
0650:
0651:            /**
0652:             * @see SQLConnectableObject#isInputCompatible
0653:             */
0654:            public int isInputCompatible(String argName, SQLObject input) {
0655:                int srcType = SQLConstants.JDBCSQL_TYPE_UNDEFINED;
0656:
0657:                TargetColumn targetCol = (TargetColumn) columns.get(argName);
0658:                if (targetCol != null) {
0659:                    switch (input.getObjectType()) {
0660:                    case SQLConstants.GENERIC_OPERATOR:
0661:                    case SQLConstants.CAST_OPERATOR:
0662:                    case SQLConstants.DATE_DIFF_OPERATOR:
0663:                    case SQLConstants.DATE_ADD_OPERATOR:
0664:                    case SQLConstants.SOURCE_COLUMN:
0665:                    case SQLConstants.VISIBLE_LITERAL:
0666:                    case SQLConstants.CASE:
0667:                        srcType = input.getJdbcType();
0668:                        break;
0669:                    case SQLConstants.CUSTOM_OPERATOR:
0670:                        srcType = ((SQLCustomOperatorImpl) input)
0671:                                .getOutputJdbcType();
0672:                        break;
0673:                    case SQLConstants.LITERAL:
0674:                        return SQLConstants.TYPE_CHECK_SAME;
0675:
0676:                    default:
0677:                        return SQLConstants.TYPE_CHECK_INCOMPATIBLE;
0678:                    }
0679:
0680:                    return SQLOperatorFactory.getDefault().getCastingRuleFor(
0681:                            srcType, targetCol.getJdbcType());
0682:                }
0683:                return SQLConstants.TYPE_CHECK_INCOMPATIBLE;
0684:            }
0685:
0686:            /**
0687:             * @see SQLConnectableObject#isInputValid
0688:             */
0689:            public boolean isInputValid(String argName, SQLObject input) {
0690:                if (input == null) {
0691:                    return false;
0692:                }
0693:
0694:                switch (input.getObjectType()) {
0695:                case SQLConstants.GENERIC_OPERATOR:
0696:                case SQLConstants.CAST_OPERATOR:
0697:                case SQLConstants.CUSTOM_OPERATOR:
0698:                case SQLConstants.DATE_DIFF_OPERATOR:
0699:                case SQLConstants.DATE_ADD_OPERATOR:
0700:                case SQLConstants.LITERAL:
0701:                case SQLConstants.VISIBLE_LITERAL:
0702:                case SQLConstants.CASE:
0703:                case SQLConstants.SOURCE_COLUMN:
0704:                    TargetColumn col = (TargetColumn) columns.get(argName);
0705:                    return (col != null && col.getValue() == null);
0706:
0707:                default:
0708:                    return false;
0709:                }
0710:            }
0711:
0712:            /**
0713:             * @see org.netbeans.modules.sql.framework.model.TargetTable#isTruncateBeforeLoad()
0714:             */
0715:            public boolean isTruncateBeforeLoad() {
0716:                Boolean shouldTruncate = (Boolean) this 
0717:                        .getAttributeObject(ATTR_TRUNCATE_BEFORE_LOAD);
0718:                return (shouldTruncate != null) ? shouldTruncate.booleanValue()
0719:                        : false;
0720:            }
0721:
0722:            public boolean isUsingFullyQualifiedName() {
0723:                Boolean fullName = (Boolean) this 
0724:                        .getAttributeObject(ATTR_FULLY_QUALIFIED_NAME);
0725:                if (fullName != null) {
0726:                    return fullName.booleanValue();
0727:                }
0728:                return true;
0729:            }
0730:
0731:            /**
0732:             * @see SQLConnectableObject#removeInputByArgName
0733:             */
0734:            public SQLObject removeInputByArgName(String argName,
0735:                    SQLObject sqlObj) throws BaseException {
0736:                if (argName == null) {
0737:                    throw new BaseException(
0738:                            "Must supply non-null SQLObject ref for argName.");
0739:                }
0740:
0741:                SQLObject victim = null;
0742:                TargetColumn col = (TargetColumn) columns.get(argName);
0743:
0744:                if (col != null) {
0745:                    victim = col.getValue();
0746:                    col.setValue(null);
0747:                }
0748:
0749:                // Now if the target column where we removed input is primary key or unique
0750:                // then we need to remove a filter.
0751:                try {
0752:                    if (col != null && col.isPrimaryKey()
0753:                            && victim instanceof  SQLDBColumn) {
0754:                        SQLCondition cond = this .getJoinCondition();
0755:
0756:                        if (cond != null) {
0757:                            cond.removeEqualsPredicate(col, victim);
0758:                        }
0759:
0760:                        // Now get the joinCondition text and set it
0761:                        int currentMode = cond.getGuiMode();
0762:                        // As SQLCondition mode may be text or graphical depending on whether this
0763:                        // method is invoked from main eTL canvas or Condition editor canvas.
0764:                        cond.setGuiMode(SQLCondition.GUIMODE_GRAPHICAL);
0765:                        SQLPredicate pred = cond.getRootPredicate();
0766:                        cond.setGuiMode(currentMode);
0767:
0768:                        if (pred != null) {
0769:                            DB db = DBFactory.getInstance().getDatabase(
0770:                                    DB.BASEDB);
0771:                            AbstractGeneratorFactory genFactory = db
0772:                                    .getGeneratorFactory();
0773:                            StatementContext stmtContext = new StatementContext();
0774:                            stmtContext.setUseSourceTableAliasName(true);
0775:                            stmtContext.setUseTargetTableAliasName(true);
0776:                            this .setJoinConditionText(genFactory.generate(pred,
0777:                                    stmtContext));
0778:                        } else {
0779:                            this .setJoinConditionText("");
0780:                        }
0781:                    }
0782:
0783:                } catch (BaseException ex) {
0784:                    // we should not throw this exception; this is just fail to
0785:                    // create an automatic filter so we can ignore now.
0786:                    //Logger.printThrowable(Logger.ERROR, TargetTableImpl.class.getName(), "addInput", "Could not create auto joinCondition for target table.", ex);
0787:                    mLogger
0788:                            .errorNoloc(
0789:                                    mLoc
0790:                                            .t(
0791:                                                    "PRSR122: Could not create auto joinCondition for target table.{0}",
0792:                                                    TargetTableImpl.class
0793:                                                            .getName()), ex);
0794:                }
0795:
0796:                return victim;
0797:            }
0798:
0799:            /**
0800:             * Clear all column references
0801:             */
0802:            public void reset() {
0803:                super .reset();
0804:                Iterator it = getColumns().values().iterator();
0805:                while (it.hasNext()) {
0806:                    TargetColumn column = (TargetColumn) it.next();
0807:                    column.setValue(null);
0808:                }
0809:            }
0810:
0811:            /**
0812:             * Parses elements which require a second pass to resolve their values.
0813:             * 
0814:             * @param element DOM element containing XML marshalled version of this SQLObject
0815:             *        instance
0816:             * @throws BaseException if element is null or error occurs during parsing
0817:             */
0818:            public void secondPassParse(Element element) throws BaseException {
0819:                SQLDBModel parentDbModel = (SQLDBModel) parentObject;
0820:                SQLDefinition definition = (SQLDefinition) parentDbModel
0821:                        .getParentObject();
0822:
0823:                SQLObject obj = TagParserUtility.parseXMLObjectRefTag(
0824:                        definition, element);
0825:
0826:                // if obj is null it may not be parsed yet so
0827:                // do a second parse... This will take for any second parse for SQL objects
0828:                if (obj == null) {
0829:                    definition.addSecondPassSQLObject(this , element);
0830:                }
0831:            }
0832:
0833:            /**
0834:             * Sets the target table joinCondition.
0835:             * 
0836:             * @param cond target table joinCondition
0837:             */
0838:            public void setJoinCondition(SQLCondition cond) {
0839:                this .joinCondition = cond;
0840:                if (this .joinCondition != null) {
0841:                    this .joinCondition.setParent(this );
0842:                    this .joinCondition
0843:                            .setDisplayName(TargetTable.JOIN_CONDITION);
0844:                }
0845:            }
0846:
0847:            /**
0848:             * Sets the joinCondition text.
0849:             * 
0850:             * @param cond sql joinCondition
0851:             */
0852:            public void setJoinConditionText(String cond) {
0853:                joinCondition.setConditionText(cond);
0854:            }
0855:
0856:            /**
0857:             * Sets whether to create target table if it does not already exist.
0858:             * 
0859:             * @param create whether to create target table
0860:             */
0861:            public void setCreateTargetTable(boolean create) {
0862:                this 
0863:                        .setAttribute(ATTR_CREATE_TARGET_TABLE, new Boolean(
0864:                                create));
0865:            }
0866:
0867:            /**
0868:             * Sets whether to create target table if it does not already exist.
0869:             * 
0870:             * @param create whether to create target table
0871:             */
0872:            public void setCreateTargetTable(Boolean create) {
0873:                this .setAttribute(ATTR_CREATE_TARGET_TABLE, create);
0874:            }
0875:
0876:            /**
0877:             * @see org.netbeans.modules.sql.framework.model.SourceTable#setSQLGroupBy(org.netbeans.modules.sql.framework.model.SQLGroupBy)
0878:             */
0879:            public void setSQLGroupBy(SQLGroupBy groupBy) {
0880:                this .groupBy = groupBy;
0881:            }
0882:
0883:            /**
0884:             * Sets the type of statement type for this table.
0885:             * 
0886:             * @param sType statement type
0887:             */
0888:            public void setStatementType(int sType) {
0889:                this .setAttribute(ATTR_STATEMENT_TYPE, new Integer(sType));
0890:            }
0891:
0892:            /**
0893:             * Sets string representation of statement type.
0894:             * 
0895:             * @param stType statement type
0896:             */
0897:            public void setStrStatementType(String stType) {
0898:                if (stType.equals(SQLConstants.STR_INSERT_STATEMENT)) {
0899:                    this .setStatementType(SQLConstants.INSERT_STATEMENT);
0900:                } else if (stType
0901:                        .equals(SQLConstants.STR_INSERT_UPDATE_STATEMENT)) {
0902:                    this .setStatementType(SQLConstants.INSERT_UPDATE_STATEMENT);
0903:                } else if (stType.equals(SQLConstants.STR_UPDATE_STATEMENT)) {
0904:                    this .setStatementType(SQLConstants.UPDATE_STATEMENT);
0905:                } else if (stType.equals(SQLConstants.STR_DELETE_STATEMENT)) {
0906:                    this .setStatementType(SQLConstants.DELETE_STATEMENT);
0907:                }
0908:            }
0909:
0910:            /**
0911:             * @see org.netbeans.modules.sql.framework.model.TargetTable#setTruncateBeforeLoad(boolean)
0912:             */
0913:            public void setTruncateBeforeLoad(boolean flag) {
0914:                this .setAttribute(ATTR_TRUNCATE_BEFORE_LOAD,
0915:                        (flag ? Boolean.TRUE : Boolean.FALSE));
0916:            }
0917:
0918:            public void setTruncateBeforeLoad(Boolean flag) {
0919:                this .setAttribute(ATTR_TRUNCATE_BEFORE_LOAD,
0920:                        (flag ? Boolean.TRUE : Boolean.FALSE));
0921:            }
0922:
0923:            /**
0924:             * Returns XML representation of table metadata.
0925:             * 
0926:             * @param prefix prefix for the xml.
0927:             * @param tableOnly flag for generating table only metadata.
0928:             * @return XML representation of the table metadata.
0929:             * @throws BaseException if error occurs
0930:             */
0931:            public String toXMLString(String prefix, boolean tableOnly)
0932:                    throws BaseException {
0933:                StringBuilder xml = new StringBuilder(INIT_XMLBUF_SIZE);
0934:
0935:                xml.append(prefix).append("<").append(TABLE_TAG);
0936:                xml.append(" ").append(TABLE_NAME_ATTR).append("=\"").append(
0937:                        name).append("\"");
0938:
0939:                xml.append(" ").append(ID_ATTR).append("=\"").append(id)
0940:                        .append("\"");
0941:
0942:                if (displayName != null && displayName.trim().length() != 0) {
0943:                    xml.append(" ").append(DISPLAY_NAME_ATTR).append("=\"")
0944:                            .append(displayName).append("\"");
0945:                }
0946:
0947:                if (schema != null && schema.trim().length() != 0) {
0948:                    xml.append(" ").append(SCHEMA_NAME_ATTR).append("=\"")
0949:                            .append(schema).append("\"");
0950:                }
0951:
0952:                if (catalog != null && catalog.trim().length() != 0) {
0953:                    xml.append(" ").append(CATALOG_NAME_ATTR).append("=\"")
0954:                            .append(catalog).append("\"");
0955:                }
0956:
0957:                xml.append(">\n");
0958:
0959:                xml.append(toXMLAttributeTags(prefix)).append("\n");
0960:
0961:                if (!tableOnly) {
0962:                    writeColumns(prefix, xml);
0963:                    writePrimaryKey(prefix, xml);
0964:                    writeForeignKeys(prefix, xml);
0965:                    writeIndices(prefix, xml);
0966:                }
0967:
0968:                // write out joinCondition
0969:                if (joinCondition != null) {
0970:                    xml.append(joinCondition.toXMLString(prefix + INDENT));
0971:                }
0972:
0973:                // write out filterCondition
0974:                if (filterCondition != null) {
0975:                    xml.append(filterCondition.toXMLString(prefix + INDENT));
0976:                }
0977:
0978:                if (groupBy != null) {
0979:                    xml.append(groupBy.toXMLString(prefix + INDENT));
0980:                }
0981:
0982:                if (guiInfo != null) {
0983:                    xml.append(guiInfo.toXMLString(prefix + INDENT));
0984:                }
0985:
0986:                xml.append(prefix).append("</").append(TABLE_TAG).append(">\n");
0987:
0988:                return xml.toString();
0989:            }
0990:
0991:            public void visit(SQLVisitor visitor) {
0992:                visitor.visit(this );
0993:            }
0994:
0995:            /**
0996:             * @see org.netbeans.modules.sql.framework.model.impl.AbstractDBTable#getElementTagName
0997:             */
0998:            protected String getElementTagName() {
0999:                return TABLE_TAG;
1000:            }
1001:
1002:            /**
1003:             * Parses node elements to extract child components to various collections (columns,
1004:             * PK, FK, indexes).
1005:             * 
1006:             * @param childNodeList Nodes to be unmarshalled
1007:             * @throws BaseException if error occurs while parsing
1008:             */
1009:            protected void parseChildren(NodeList childNodeList)
1010:                    throws BaseException {
1011:                for (int i = 0; i < childNodeList.getLength(); i++) {
1012:                    if (childNodeList.item(i).getNodeType() == Node.ELEMENT_NODE) {
1013:                        Element childElement = (Element) childNodeList.item(i);
1014:                        String tagName = childElement.getTagName();
1015:
1016:                        if (AbstractDBColumn.ELEMENT_TAG.equals(tagName)) {
1017:                            TargetColumn columnInstance = new TargetColumnImpl();
1018:
1019:                            columnInstance.setParentObject(this );
1020:                            columnInstance.parseXML(childElement);
1021:
1022:                            addColumn(columnInstance);
1023:                        } else if (PrimaryKeyImpl.ELEMENT_TAG.equals(tagName)) {
1024:                            PrimaryKeyImpl pkInstance = new PrimaryKeyImpl(
1025:                                    childElement);
1026:                            pkInstance.parseXML();
1027:                            setPrimaryKey(pkInstance);
1028:                        } else if (ForeignKeyImpl.ELEMENT_TAG.equals(tagName)) {
1029:                            ForeignKeyImpl fkInstance = new ForeignKeyImpl(
1030:                                    childElement);
1031:                            fkInstance.parseXML();
1032:                            addForeignKey(fkInstance);
1033:                        } else if (IndexImpl.ELEMENT_TAG.equals(tagName)) {
1034:                            IndexImpl indexInstance = new IndexImpl(
1035:                                    childElement);
1036:                            indexInstance.parseXML();
1037:                            addIndex(indexInstance);
1038:                        } else if (TagParserUtility.TAG_OBJECTREF
1039:                                .equals(tagName)) {
1040:                            secondPassParse(childElement);
1041:                        } else if (GUIInfo.TAG_GUIINFO.equals(tagName)) {
1042:                            guiInfo = new GUIInfo(childElement);
1043:                        } else if (SQLCondition.TAG_CONDITION.equals(tagName)) {
1044:                            String conditionName = childElement
1045:                                    .getAttribute(SQLCondition.DISPLAY_NAME);
1046:                            if (conditionName != null
1047:                                    && conditionName
1048:                                            .equals(TargetTableImpl.JOIN_CONDITION)) {
1049:                                SQLCondition cond1 = SQLModelObjectFactory
1050:                                        .getInstance().createSQLCondition(
1051:                                                JOIN_CONDITION);
1052:                                SQLDBModel parentDbModel = (SQLDBModel) this 
1053:                                        .getParentObject();
1054:                                if (parentDbModel != null) {
1055:                                    cond1.setParent(this );
1056:                                    cond1.parseXML(childElement);
1057:                                    this .setJoinCondition(cond1);
1058:                                }
1059:                            } else if (conditionName != null
1060:                                    && conditionName
1061:                                            .equals(TargetTableImpl.FILTER_CONDITION)) {
1062:                                SQLCondition cond1 = SQLModelObjectFactory
1063:                                        .getInstance().createSQLCondition(
1064:                                                FILTER_CONDITION);
1065:                                SQLDBModel parentDbModel = (SQLDBModel) this 
1066:                                        .getParentObject();
1067:                                if (parentDbModel != null) {
1068:                                    cond1.setParent(this );
1069:                                    cond1.parseXML(childElement);
1070:                                    this .setFilterCondition(cond1);
1071:                                }
1072:                            }
1073:                        } else if (SQLGroupByImpl.ELEMENT_TAG.equals(tagName)) {
1074:                            groupBy = new SQLGroupByImpl();
1075:                            groupBy.setParentObject(this );
1076:                            groupBy.parseXML(childElement);
1077:                        }
1078:                    }
1079:                }
1080:            }
1081:
1082:            /**
1083:             * Overrides parent implementation to also initialize locally-defined attributes.
1084:             */
1085:            protected void setDefaultAttributes() {
1086:                super .setDefaultAttributes();
1087:
1088:                if (this .getAttributeObject(ATTR_STATEMENT_TYPE) == null) {
1089:                    setStatementType(SQLConstants.INSERT_STATEMENT);
1090:                }
1091:
1092:                if (this .getAttributeObject(ATTR_CREATE_TARGET_TABLE) == null) {
1093:                    setCreateTargetTable(true);
1094:                }
1095:
1096:                if (this .getAttributeObject(ATTR_COMMIT_BATCH_SIZE) == null) {
1097:                    setBatchSize(-1);
1098:                }
1099:            }
1100:
1101:            /**
1102:             * Writes out column information to the given StringBuilder.
1103:             * 
1104:             * @param prefix String to prepend to each column element or child node
1105:             * @param xml StringBuilder in which to write column information
1106:             * @throws BaseException if error occurs during writing
1107:             */
1108:            protected void writeColumns(String prefix, StringBuilder xml)
1109:                    throws BaseException {
1110:                Comparator cmp = new StringComparator();
1111:                // Ensure columns are written out in ascending name order.
1112:                List colList = new ArrayList(columns.keySet());
1113:                Collections.sort(colList, cmp);
1114:
1115:                Iterator iter = colList.listIterator();
1116:                while (iter.hasNext()) {
1117:                    String key = (String) iter.next();
1118:                    TargetColumn column = (TargetColumn) columns.get(key);
1119:                    xml.append(column.toXMLString(prefix + INDENT));
1120:                }
1121:            }
1122:
1123:            /**
1124:             * Writes out foreign key information to the given StringBuilder.
1125:             * 
1126:             * @param prefix String to prepend to each foreign key element or child node
1127:             * @param xml StringBuilder in which to write foreign key information
1128:             */
1129:            protected void writeForeignKeys(String prefix, StringBuilder xml) {
1130:                Comparator cmp = new StringComparator();
1131:                List fkNames = new ArrayList(foreignKeys.keySet());
1132:                Collections.sort(fkNames, cmp);
1133:                Iterator iter = fkNames.iterator();
1134:                while (iter.hasNext()) {
1135:                    String key = (String) iter.next();
1136:                    ForeignKeyImpl fk = (ForeignKeyImpl) foreignKeys.get(key);
1137:                    xml.append(fk.toXMLString(prefix + INDENT));
1138:                }
1139:            }
1140:
1141:            /**
1142:             * Writes out index information to the given StringBuilder.
1143:             * 
1144:             * @param prefix String to prepend to each index element or child node
1145:             * @param xml StringBuilder in which to write index information
1146:             */
1147:            protected void writeIndices(String prefix, StringBuilder xml) {
1148:                Comparator cmp = new StringComparator();
1149:                List indexNames = new ArrayList(indexes.keySet());
1150:                Collections.sort(indexNames, cmp);
1151:                Iterator iter = indexNames.iterator();
1152:                while (iter.hasNext()) {
1153:                    String key = (String) iter.next();
1154:                    IndexImpl index = (IndexImpl) indexes.get(key);
1155:                    xml.append(index.toXMLString(prefix + INDENT));
1156:                }
1157:            }
1158:
1159:            /**
1160:             * Writes out primary key information to the given StringBuilder.
1161:             * 
1162:             * @param prefix String to prepend to each primary key element or child node
1163:             * @param xml StringBuilder in which to write primary key information
1164:             */
1165:            protected void writePrimaryKey(String prefix, StringBuilder xml) {
1166:                if (primaryKey != null) {
1167:                    xml.append(primaryKey.toXMLString(prefix + INDENT));
1168:                }
1169:            }
1170:
1171:            private SQLJoinView discoverJoinView(SQLObject obj)
1172:                    throws BaseException {
1173:                if (obj.getObjectType() == SQLConstants.SOURCE_COLUMN) {
1174:                    SourceColumn column = (SourceColumn) obj;
1175:                    SourceTable table = (SourceTable) column.getParent();
1176:
1177:                    SQLDefinition def = TagParserUtility
1178:                            .getAncestralSQLDefinition(column);
1179:
1180:                    if (def != null) {
1181:                        Collection jViews = def
1182:                                .getObjectsOfType(SQLConstants.JOIN_VIEW);
1183:                        Iterator it = jViews.iterator();
1184:                        while (it.hasNext()) {
1185:                            SQLJoinView jView = (SQLJoinView) it.next();
1186:                            if (jView.containsSourceTable(table)) {
1187:                                return jView;
1188:                            }
1189:                        }
1190:                    }
1191:                } else if (obj instanceof  SQLConnectableObject) {
1192:                    SQLConnectableObject expObj = (SQLConnectableObject) obj;
1193:
1194:                    Map inputs = expObj.getInputObjectMap();
1195:                    Iterator it = inputs.values().iterator();
1196:
1197:                    while (it.hasNext()) {
1198:                        SQLInputObject inObj = (SQLInputObject) it.next();
1199:                        SQLObject sqlObj = inObj.getSQLObject();
1200:                        if (sqlObj != null) {
1201:                            SQLJoinView jView = discoverJoinView(sqlObj);
1202:                            if (jView != null) {
1203:                                return jView;
1204:                            }
1205:                        }
1206:                    }
1207:                    // go through children
1208:                    Iterator cIt = expObj.getChildSQLObjects().iterator();
1209:                    while (cIt.hasNext()) {
1210:                        SQLObject child = (SQLObject) cIt.next();
1211:                        SQLJoinView jView = discoverJoinView(child);
1212:                        if (jView != null) {
1213:                            return jView;
1214:                        }
1215:                    }
1216:                }
1217:
1218:                return null;
1219:            }
1220:
1221:            private void discoverTables(SQLObject sqlObj, List sourceTables)
1222:                    throws BaseException {
1223:                int objType = sqlObj.getObjectType();
1224:                switch (objType) {
1225:                case SQLConstants.PREDICATE:
1226:                case SQLConstants.VISIBLE_PREDICATE:
1227:                case SQLConstants.GENERIC_OPERATOR:
1228:                case SQLConstants.CUSTOM_OPERATOR:
1229:                case SQLConstants.CAST_OPERATOR:
1230:                case SQLConstants.DATE_DIFF_OPERATOR:
1231:                case SQLConstants.DATE_ADD_OPERATOR:
1232:                case SQLConstants.CASE:
1233:                case SQLConstants.JOIN:
1234:                    SQLConnectableObject expressionObj = (SQLConnectableObject) sqlObj;
1235:                    Map inputs = expressionObj.getSQLObjectMap();
1236:                    if (objType == SQLConstants.CASE) {
1237:                        SQLCaseOperator myCase = (SQLCaseOperator) sqlObj;
1238:                        List whenList = myCase.getChildSQLObjects();
1239:                        Iterator whenItr = whenList.iterator();
1240:                        while (whenItr.hasNext()) {
1241:                            SQLConnectableObject whenExprObj = (SQLConnectableObject) whenItr
1242:                                    .next();
1243:                            inputs.putAll(whenExprObj.getSQLObjectMap());
1244:                        }
1245:                    }
1246:                    Iterator it = inputs.values().iterator();
1247:                    while (it.hasNext()) {
1248:                        SQLObject obj = (SQLObject) it.next();
1249:                        discoverTables(obj, sourceTables);
1250:                    }
1251:                    break;
1252:
1253:                case SQLConstants.SOURCE_COLUMN:
1254:                    SQLObject parent = (SQLObject) sqlObj.getParentObject();
1255:                    discoverTables(parent, sourceTables);
1256:
1257:                    break;
1258:
1259:                case SQLConstants.SOURCE_TABLE:
1260:                    // I am adding parent here if column, How to get the column's parent here
1261:                    // ????
1262:                    if (!sourceTables.contains(sqlObj)) {
1263:                        sourceTables.add(sqlObj);
1264:
1265:                        // find the root join if any for this table and find other tables
1266:                        SQLDBModel parentDbModel = (SQLDBModel) parentObject;
1267:                        SQLDefinition definition = (SQLDefinition) parentDbModel
1268:                                .getParentObject();
1269:
1270:                        if (definition != null) {
1271:                            SQLObject rootJoin = definition
1272:                                    .getRootJoin(sourceTables);
1273:                            if (rootJoin != null) {
1274:                                discoverTables(rootJoin, sourceTables);
1275:                            }
1276:                        }
1277:                    }
1278:
1279:                    break;
1280:
1281:                default:
1282:                }
1283:            }
1284:
1285:            /*
1286:             * Performs sql framework initialization functions for constructors which cannot first
1287:             * call this().
1288:             */
1289:            private void init() {
1290:                type = SQLConstants.TARGET_TABLE;
1291:                setDefaultAttributes();
1292:                groupBy = new SQLGroupByImpl();
1293:
1294:                joinCondition = SQLModelObjectFactory.getInstance()
1295:                        .createSQLCondition(JOIN_CONDITION);
1296:                setJoinCondition(joinCondition);
1297:
1298:                filterCondition = SQLModelObjectFactory.getInstance()
1299:                        .createSQLCondition(FILTER_CONDITION);
1300:                setFilterCondition(filterCondition);
1301:            }
1302:
1303:            public SQLCondition getFilterCondition() {
1304:                // if there are no objects in graph then populate graph with the objects
1305:                // obtained from sql text
1306:                Collection objC = filterCondition.getAllObjects();
1307:                if (objC == null || objC.size() == 0) {
1308:                    SQLDefinition def = SQLObjectUtil
1309:                            .getAncestralSQLDefinition(this );
1310:                    try {
1311:                        ConditionUtil.populateCondition(filterCondition, def,
1312:                                this .getFilterConditionText());
1313:                    } catch (Exception ex) {
1314:                        // ignore this if filterCondition typed by user is invalid
1315:                    }
1316:                }
1317:
1318:                return filterCondition;
1319:            }
1320:
1321:            public String getFilterConditionText() {
1322:                return filterCondition.getConditionText();
1323:            }
1324:
1325:            public void setFilterCondition(SQLCondition cond) {
1326:                this .filterCondition = cond;
1327:                if (this .filterCondition != null) {
1328:                    this .filterCondition.setParent(this );
1329:                    this .filterCondition
1330:                            .setDisplayName(TargetTable.FILTER_CONDITION);
1331:                }
1332:
1333:            }
1334:
1335:            public void setFilterConditionText(String cond) {
1336:                filterCondition.setConditionText(cond);
1337:            }
1338:
1339:            public SQLCondition getHavingCondition() {
1340:                return havingCondition;
1341:            }
1342:
1343:            public void setHavingCondition(SQLCondition having) {
1344:                this .havingCondition = having;
1345:                if (this .havingCondition != null) {
1346:                    this .havingCondition.setParent(this );
1347:                    this .havingCondition.setDisplayName(HAVING_CONDITION);
1348:                }
1349:            }
1350:
1351:            public void setBatchSize(int newsize) {
1352:                this .setAttribute(ATTR_BATCHSIZE, new Integer(newsize));
1353:            }
1354:
1355:            public void setBatchSize(Integer newsize) {
1356:                this .setAttribute(ATTR_BATCHSIZE, newsize);
1357:            }
1358:
1359:            public void setUsingFullyQualifiedName(boolean usesFullName) {
1360:                this .setAttribute(ATTR_FULLY_QUALIFIED_NAME, new Boolean(
1361:                        usesFullName));
1362:            }
1363:
1364:            public void setUsingFullyQualifiedName(Boolean usesFullName) {
1365:                this.setAttribute(ATTR_FULLY_QUALIFIED_NAME, usesFullName);
1366:            }
1367:        }
w__w__w_.__j_a___v___a___2_s___.___c___o_m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.