001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019: package org.netbeans.modules.etl.codegen;
020:
021: import org.netbeans.modules.etl.codegen.impl.DefaultProcessFlowGenerator;
022: import org.netbeans.modules.etl.codegen.impl.PipelinedFlowGenerator;
023: import org.netbeans.modules.etl.codegen.impl.PipelinedStrategyBuilderImpl;
024: import org.netbeans.modules.etl.codegen.impl.ValidatingStrategyBuilderImpl;
025: import org.netbeans.modules.sql.framework.model.SQLDefinition;
026: import org.netbeans.modules.sql.framework.model.TargetTable;
027: import com.sun.sql.framework.exception.BaseException;
028: import net.java.hulp.i18n.Logger;
029: import org.netbeans.modules.etl.logger.Localizer;
030: import org.netbeans.modules.etl.logger.LogUtil;
031:
032: /**
033: * Builds ETL process flow and delegates to appropriate ETLStrategyBuilder as required.
034: *
035: * @author Ahimanikya Satapathy
036: * @version $Revision$
037: */
038: public class ETLProcessFlowGeneratorFactory {
039:
040: private static transient final Logger mLogger = LogUtil
041: .getLogger(ETLProcessFlowGeneratorFactory.class.getName());
042: private static transient final Localizer mLoc = Localizer.get();
043:
044: public static ETLProcessFlowGenerator getCollabFlowGenerator(
045: SQLDefinition sqlDefinition, boolean overridingConnDefs)
046: throws BaseException {
047: ETLProcessFlowGenerator generator = null;
048: validateExecutionMode(sqlDefinition);
049:
050: if (usePipelineFlowGenerator(sqlDefinition, overridingConnDefs)) {
051: generator = new PipelinedFlowGenerator(sqlDefinition);
052: } else {
053: generator = new DefaultProcessFlowGenerator(sqlDefinition);
054: }
055:
056: return generator;
057: }
058:
059: public static PipelinedStrategyBuilderImpl getPipelinedTargetTableScriptBuilder(
060: ETLScriptBuilderModel model) throws BaseException {
061: return new PipelinedStrategyBuilderImpl(model);
062: }
063:
064: public static ETLStrategyBuilder getTargetTableScriptBuilder(
065: ETLStrategyBuilderContext context) throws BaseException {
066: return PatternFinder.createETLStrategyBuilder(context
067: .getTargetTable(), context.getModel());
068: }
069:
070: public static ETLStrategyBuilder getTargetTableScriptBuilder(
071: ETLScriptBuilderModel model, TargetTable tt)
072: throws BaseException {
073: return PatternFinder.createETLStrategyBuilder(tt, model);
074: }
075:
076: public static ValidatingStrategyBuilderImpl getValidatingTargetTableScriptBuilder(
077: ETLScriptBuilderModel model) throws BaseException {
078: return new ValidatingStrategyBuilderImpl(model);
079: }
080:
081: /**
082: * @param sqlDefintion
083: * @param connDefsOverrideAvailable i.e Run Time, where Connection definition's
084: * needs to be overridden.
085: * @return
086: * @throws BaseException
087: */
088: private static boolean usePipelineFlowGenerator(
089: SQLDefinition sqlDefintion,
090: boolean connDefsOverrideAvailable) throws BaseException {
091: boolean ret = false;
092: if ((sqlDefintion.requiresPipelineProcess())
093: || (sqlDefintion.getExecutionStrategyCode().intValue() == SQLDefinition.EXECUTION_STRATEGY_PIPELINE)) {
094: ret = true;
095: } else if ((sqlDefintion.getExecutionStrategyCode().intValue() == SQLDefinition.EXECUTION_STRATEGY_BEST_FIT)
096: && (PatternFinder
097: .isSourceAndTargetAreInternalButDifferent(sqlDefintion))) {
098: ret = true;
099: }
100: return ret;
101: }
102:
103: public static void validateExecutionMode(SQLDefinition sqlDef)
104: throws BaseException {
105: if (sqlDef.getExecutionStrategyCode().intValue() == SQLDefinition.EXECUTION_STRATEGY_STAGING) {
106:
107: if (sqlDef.requiresPipelineProcess()) {
108: String nbBundle1 = mLoc
109: .t("PRSR001: Cannot execute in Staging mode, choose Best-fit or Pipeline.");
110: String desc = Localizer.parse(nbBundle1);
111: throw new BaseException(desc);
112: }
113:
114: if (PatternFinder
115: .isSourceAndTargetAreInternalButDifferent(sqlDef)) {
116: String nbBundle2 = mLoc
117: .t("PRSR001: Cannot execute in Staging mode, choose Best-fit or Pipeline.");
118: String desc = Localizer.parse(nbBundle2);
119: throw new BaseException(desc);
120: }
121: }
122: }
123:
124: private ETLProcessFlowGeneratorFactory() {
125: }
126: }
|