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.impl;
020:
021: import java.util.Map;
022:
023: import org.netbeans.modules.etl.codegen.ETLProcessFlowGenerator;
024: import org.netbeans.modules.etl.codegen.ETLScriptBuilderModel;
025: import org.netbeans.modules.etl.utils.MessageManager;
026: import org.netbeans.modules.sql.framework.model.SQLDefinition;
027: import net.java.hulp.i18n.Logger;
028: import com.sun.etl.engine.ETLEngine;
029: import com.sun.etl.engine.ETLEngineContext;
030: import com.sun.etl.engine.ETLTask;
031: import com.sun.etl.engine.ETLTaskNode;
032: import com.sun.sql.framework.exception.BaseException;
033: import com.sun.sql.framework.jdbc.SQLPart;
034: import org.netbeans.modules.etl.logger.Localizer;
035: import org.netbeans.modules.etl.logger.LogUtil;
036:
037: /**
038: * @author Girish Patil
039: * @version $Revision$
040: */
041: public abstract class BaseFlowGenerator implements
042: ETLProcessFlowGenerator {
043:
044: private static final String LOG_CATEGORY = BaseFlowGenerator.class
045: .getName();
046: protected ETLScriptBuilderModel builderModel = new ETLScriptBuilderModel();
047: protected ETLTaskNode endTask = null;
048: protected ETLTaskNode globalCleanupTask = null;
049: protected ETLTaskNode initTask = null;
050: protected ETLTaskNode startTask = null;
051: protected ETLTaskNode statsUpdateTask = null;
052: protected ETLTaskNode threadCollectorWaitNode = null;
053: private static transient final Logger mLogger = LogUtil
054: .getLogger(BaseFlowGenerator.class.getName());
055: private static transient final Localizer mLoc = Localizer.get();
056:
057: public BaseFlowGenerator(SQLDefinition sqlD) throws BaseException {
058: init(sqlD);
059: }
060:
061: public void applyConnectionDefinitions() throws BaseException {
062: this .builderModel.applyConnectionDefinitions();
063: this .builderModel.buildRuntimeDatabaseModel();
064: }
065:
066: public void applyConnectionDefinitions(Map name2connectionDefMap,
067: Map connDefNameMap, Map intDbConfigParams)
068: throws BaseException {
069: if ((intDbConfigParams != null)
070: && (intDbConfigParams.size() > 0)) {
071: this .builderModel.setUseInstanceDB(true);
072: }
073: this .builderModel.setMemoryMonitorDB(false);
074: //this.builderModel.setShutdownMonitorDB(true); //103130
075: this .builderModel.applyConnectionDefinitions(
076: name2connectionDefMap, connDefNameMap,
077: intDbConfigParams);
078: this .builderModel.buildRuntimeDatabaseModel();
079: }
080:
081: public String getInstanceDBFolder() {
082: return this .builderModel.getInstanceDBFolder();
083: }
084:
085: public String getInstanceDBName() {
086: return this .builderModel.getInstanceDBName();
087: }
088:
089: public String getMonitorDBFolder() {
090: return this .builderModel.getMonitorDBFolder();
091: }
092:
093: public String getMonitorDBName() {
094: return this .builderModel.getMonitorDBName();
095: }
096:
097: public String getWorkingFolder() {
098: return this .builderModel.getWorkingFolder();
099: }
100:
101: public void setInstanceDBFolder(String instanceDBFolder) {
102: this .builderModel.setInstanceDBFolder(instanceDBFolder);
103: }
104:
105: public void setInstanceDBName(String instanceDBName) {
106: this .builderModel.setInstanceDBName(instanceDBName);
107: }
108:
109: public void setMonitorDBFolder(String monitorDBFolder) {
110: this .builderModel.setMonitorDBFolder(monitorDBFolder);
111: }
112:
113: public void setMonitorDBName(String monitorDBName) {
114: this .builderModel.setMonitorDBName(monitorDBName);
115: }
116:
117: public void setWorkingFolder(String workingFolder) {
118: this .builderModel.setWorkingFolder(workingFolder);
119: }
120:
121: protected void createInitTask() throws BaseException {
122: final MessageManager dnLabelMgr = MessageManager
123: .getManager(ETLTaskNode.class);
124: mLogger.infoNoloc(mLoc.t("PRSR001: createInitTask():{0}",
125: LOG_CATEGORY));
126: // START task
127: startTask = builderModel.getEngine().getStartETLTaskNode();
128:
129: // INIT task
130: initTask = builderModel.getEngine().createETLTaskNode(
131: ETLEngine.INIT);
132: initTask.setDisplayName(dnLabelMgr.getString("LBL_dn_init"));
133:
134: startTask.addNextETLTaskNode(ETLTask.SUCCESS, initTask.getId());
135:
136: // Global CLEANUP task
137: globalCleanupTask = builderModel.getEngine().createETLTaskNode(
138: ETLEngine.CLEANUP);
139: globalCleanupTask.setDisplayName(dnLabelMgr
140: .getString("LBL_dn_cleanup"));
141:
142: // WT #67938: Ensure cleanup is called if init task chokes.
143: initTask.addNextETLTaskNode(ETLTask.EXCEPTION,
144: globalCleanupTask.getId());
145:
146: SQLPart shutdownDB = null;
147:
148: // Always shut down instance DB
149: if (this .builderModel.isUseInstanceDB()) {
150: shutdownDB = new SQLPart("SHUTDOWN", SQLPart.STMT_DEFRAG,
151: ETLScriptBuilderModel.ETL_INSTANCE_DB_CONN_DEF_NAME);
152: globalCleanupTask.addStatement(shutdownDB);
153: }
154:
155: /** HotFix #103130 :
156: // Commented to resolve problem that occur while mulitple threads attempt to modify Summary table in mutlithread environment.
157: // if (this.builderModel.isShutdownMonitorDB()) {
158: // shutdownDB = new SQLPart("SHUTDOWN", SQLPart.STMT_DEFRAG, ETLScriptBuilderModel.ETL_MONITOR_DB_CONN_DEF_NAME);
159: // globalCleanupTask.addOptionalTask(shutdownDB);
160: // }
161: */
162:
163: // Final WAIT task
164: // Create a wait task node to collect thread of each transformer chain.
165: threadCollectorWaitNode = builderModel.getEngine()
166: .createETLTaskNode(ETLEngine.WAIT);
167:
168: // UPDATE_STATS Task
169: // Create update statistics node.
170: statsUpdateTask = builderModel.getEngine().createETLTaskNode(
171: ETLEngine.UPDATE_STATS);
172: statsUpdateTask.setDisplayName(dnLabelMgr
173: .getString("LBL_dn_updatestats"));
174: }
175:
176: protected void init(SQLDefinition sqlD) throws BaseException {
177: if (sqlD == null) {
178: throw new BaseException("SQLDefinition is null");
179: }
180: builderModel.setSqlDefinition(sqlD);
181: initEngine();
182: }
183:
184: protected void initEngine() {
185: mLogger.infoNoloc(mLoc.t("PRSR002: initEngine():{0}",
186: LOG_CATEGORY));
187: // Create an empty engine.
188: ETLEngineContext engineContext = new ETLEngineContext();
189: ETLEngine engine = this .builderModel.getEngine();
190: engine.setContext(engineContext);
191: engine.createStartETLTaskNode();
192: engine.createEndETLTaskNode();
193: engine.setDisplayName(builderModel.getSqlDefinition()
194: .getDisplayName());
195:
196: startTask = engine.getStartETLTaskNode();
197: endTask = engine.getEndETLTaskNode();
198:
199: MessageManager dnLabelMgr = MessageManager
200: .getManager(ETLTaskNode.class);
201: startTask.setDisplayName(dnLabelMgr.getString("LBL_dn_start"));
202: endTask.setDisplayName(dnLabelMgr.getString("LBL_dn_end"));
203: }
204:
205: public void applyConnectionDefinitions(boolean isMemoryDb)
206: throws BaseException {
207: this .builderModel.setMemoryMonitorDB(false);
208: applyConnectionDefinitions();
209: }
210: }
|