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 com.sun.jbi.ui.devtool.codegen.framework.model.CodeGenException;
022: //import com.sun.jbi.ui.devtool.configuration.IConfiguration;
023: //import com.sun.jbi.ui.devtool.configuration.IParameter;
024: //import com.sun.jbi.ui.devtool.configuration.ISection;
025: //import com.sun.jbi.ui.devtool.deployment.repository.ProjectDeployment;
026: //import org.netbeans.modules.etl.codegen.ETLProcessFlowGenerator;
027: //import org.netbeans.modules.etl.codegen.ETLProcessFlowGeneratorFactory;
028: //import org.netbeans.modules.etl.engine.ETLEngine;
029: //import org.netbeans.modules.etl.model.ETLDefinition;
030: //import org.netbeans.modules.etl.model.ETLDefinitionProjectElement;
031: //import org.netbeans.modules.etl.utils.ETLDeploymentConstants;
032: //import org.netbeans.modules.mashup.db.model.FlatfileDefinition;
033: //import com.sun.jbi.ui.devtool.model.common.cme.CMLink;
034: //import com.sun.jbi.ui.devtool.model.common.cme.CMNode;
035: //import com.sun.jbi.ui.devtool.model.common.cme.Port;
036: //import com.sun.jbi.ui.devtool.model.common.cme.PortType;
037: //import com.sun.jbi.ui.devtool.model.common.cme.ProcessingDefinition;
038: //import org.netbeans.modules.model.database.DBRuntimeEnvAccessor;
039: //import com.sun.jbi.ui.devtool.repository.RepositoryException;
040: //import com.sun.jbi.ui.devtool.sql.framework.exception.BaseException;
041: //import com.sun.jbi.ui.devtool.sql.framework.jdbc.SQLDBConnectionDefinition;
042: //import org.netbeans.modules.sql.framework.model.SQLDefinition;
043: //import com.sun.jbi.ui.devtool.sql.framework.utils.DBConnectionDefinitionTemplate;
044: //import com.sun.jbi.ui.devtool.sql.framework.utils.Logger;
045: //import com.sun.jbi.ui.devtool.sql.framework.utils.StringUtil;
046:
047: /**
048: * @author Ahimanikya Satapathy
049: * @author Jonathan Giron
050: * @version $Revision$
051: */
052: public class GenerateEngineFile {
053: // private static final String LOCAL_PATTERN_DELIMITER = "#";
054: // private static final String LOG_CATEGORY = GenerateEngineFile.class.getName();
055: // private static final LocalMessageManager MESSAGE_MGR = new LocalMessageManager();
056: // private static final String SETPARAM_PATTERN = "set([^#]*?)#([^#]*?)##";
057: // private static final String SETURL_PATTERN = "setURL#([^#]*?)##";
058: //
059: // private final ETLCodelet codelet;
060: // private DBConnectionDefinitionTemplate connectionDefnTemplate;
061: // private ETLEngine engine = null;
062: // private ETLDefinitionProjectElement etlDefnPE = null;
063: //
064: // // Holds a map of unique IDs (DB OID + port type [either "-Source" or "-Target"]) to
065: // // InternalDBMetadata instances which hold CME-level parameters such as directory
066: // // location of flatfiles and whether dynamic file name resolution is in effect.
067: // private Map internalDBConfigParams = new HashMap();
068: //
069: // // Holds a map of DB OIDs to corresponding connection pool names.
070: // private Map dbNamePoolNameMap = new HashMap(2);
071: //
072: //
073: // /**
074: // * Local implementation of a resource bundle manager. This class is necessary because
075: // * neither the eTL nor the SQLFramework flavors of MessageManager can be used within
076: // * the codegen thread - neither is able to resolve the LocalStrings.properties file
077: // * with the classloader associated with the codegen thread.
078: // */
079: // static class LocalMessageManager {
080: // ResourceBundle rb;
081: //
082: // public LocalMessageManager() {
083: // rb = ResourceBundle.getBundle(GenerateEngineFile.class.getPackage().getName().concat(".LocalStrings"), Locale.getDefault(),
084: // GenerateEngineFile.class.getClassLoader());
085: // }
086: //
087: // /**
088: // * Get a string from the underlying resource bundle.
089: // *
090: // * @param key for which msg needs to retrieved from HashMap
091: // * @return String The MessageFormat for given Key
092: // */
093: //
094: // public synchronized String getString(String key) {
095: // if (key == null) {
096: // String msg = "key is null";
097: // throw new NullPointerException(msg);
098: // }
099: //
100: // if (rb == null) {
101: // String message = "Could not load resource bundle.";
102: // throw new NullPointerException(message);
103: // }
104: //
105: // String str;
106: //
107: // try {
108: // str = rb.getString(key);
109: // } catch (MissingResourceException mre) {
110: // str = "Cannot find message associated with key '" + key + "'";
111: // }
112: //
113: // return str;
114: // }
115: //
116: // /**
117: // * Get a string from the underlying resource bundle and format it with the given
118: // * object argument. This argument can of course be a String object.
119: // *
120: // * @param key For which String needs to be displayed
121: // * @param arg That is the result for Info, ERR or Exception
122: // * @return String MessageString for given Key
123: // */
124: //
125: // public synchronized String getString(String key, Object arg) {
126: // Object[] args = new Object[] { arg};
127: // return getString(key, args);
128: // }
129: //
130: // /**
131: // * Get a string from the underlying resource bundle and format it with the given
132: // * object arguments. These arguments can of course be String objects.
133: // *
134: // * @param key For which Message needs to be constructed
135: // * @param arg1 used for message construction
136: // * @param arg2 used for message construction
137: // * @return String Message String for the given key
138: // */
139: //
140: // public String getString(String key, Object arg1, Object arg2) {
141: // Object[] args = new Object[] { arg1, arg2};
142: // return getString(key, args);
143: // }
144: //
145: // /**
146: // * Get a string from the underlying resource bundle and format it with the given
147: // * set of arguments.
148: // *
149: // * @param key For which MessageFormat needs to be picked for a key
150: // * @param args This contains the arguments
151: // * @return String Message Format for given key and arguments
152: // */
153: // public String getString(String key, Object[] args) {
154: // String iString;
155: // String value = getString(key);
156: //
157: // try {
158: // Object nonNullArgs[] = args;
159: // for (int i = 0; i < args.length; i++) {
160: // if (args[i] == null) {
161: // if (nonNullArgs == args) {
162: // nonNullArgs = (Object[]) args.clone();
163: // }
164: // nonNullArgs[i] = "null";
165: // }
166: // }
167: //
168: // iString = MessageFormat.format(value, nonNullArgs);
169: // } catch (IllegalArgumentException iae) {
170: // StringBuffer buf = new StringBuffer();
171: // buf.append(value);
172: // for (int i = 0; i < args.length; i++) {
173: // buf.append(" arg[" + i + "]=" + args[i]);
174: // }
175: // iString = buf.toString();
176: // }
177: //
178: // return iString;
179: // }
180: // }
181: //
182: // static String convertDriverPropertiesToURL(ISection section, boolean includeParams) throws CodeGenException {
183: // String driverProps = getStringParameter(section, ETLDeploymentConstants.DRIVER_PROPERTIES, false);
184: // String delimiter = getStringParameter(section, ETLDeploymentConstants.EWAYS_PROP_DELIMITER, driverProps != null);
185: //
186: // StringBuffer buf = new StringBuffer(50);
187: // extractURLFrom(driverProps, buf, delimiter);
188: //
189: // return (buf.length() != 0) ? buf.toString() : "";
190: // }
191: //
192: //
193: // static String getOptionalDriverProperties(ISection section) throws CodeGenException {
194: // String driverProps = getStringParameter(section, ETLDeploymentConstants.DRIVER_PROPERTIES, false);
195: // String delimiter = getStringParameter(section, ETLDeploymentConstants.EWAYS_PROP_DELIMITER, driverProps != null);
196: //
197: // StringBuffer buf = new StringBuffer(50);
198: // int ct = extractPropertiesFrom(driverProps, buf, delimiter);
199: // return (ct != 0) ? buf.toString() : "";
200: // }
201: //
202: // /**
203: // * Parses property key-value pairs from substring of eWays DriverProperties value (assuming
204: // * the setURL property has been removed), appending them in canonical "key=value[;]" form
205: // * into the given StringBuffer.
206: // *
207: // * @param propsString String to be parsed for driver parameters
208: // * @param buf StringBuffer which will accept property key-value pairs
209: // * @param delimiter delimiter specified by user in eWays configuration dialog
210: // * @return count of parameters written to <code>buf</code>
211: // */
212: // static int extractPropertiesFrom(String propsString, StringBuffer buf, String delimiter) {
213: // if (StringUtil.isNullString(propsString)) {
214: // return 0;
215: // }
216: //
217: // Pattern pattern = Pattern.compile(SETPARAM_PATTERN.replaceAll(LOCAL_PATTERN_DELIMITER,
218: // StringUtil.escapeJavaRegexpChars(delimiter)));
219: // Matcher match = pattern.matcher(propsString);
220: // int i = 0;
221: //
222: // while (match.find()) {
223: // String key = match.group(1);
224: //
225: // // Skip the setURL group, if any.
226: // if ("URL".equals(key.toUpperCase())) {
227: // continue;
228: // }
229: //
230: // //
231: // // Handle SpyAttributes property - for now, ignore it.
232: // //
233: // // If we support the use of the DataDirect Spy driver, then we will need to modify
234: // // convertDriverPropertiesToURL(...) to wrap the generated URL in "jdbc:spy:{[URL goes here]}"
235: // // and append the value of the SpyAttributes property to the wrapped URL.
236: // //
237: // // See http://media.datadirect.com/download/docs/jdbc/jdbcref/usejdbc.html#wp1014509
238: // // and eWays team for details on how/whether the various eWays support the Spy driver.
239: // //
240: // if ("SPYATTRIBUTES".equals(key.toUpperCase())) {
241: // continue;
242: // }
243: //
244: // if (i++ != 0) {
245: // buf.append(";");
246: // }
247: // buf.append(key).append("=").append(match.group(2));
248: // }
249: //
250: // return i;
251: // }
252: //
253: // /**
254: // * Parses URL information, if any, from an eWays DriverProperties value and appends it into the
255: // * given StringBuffer.
256: // *
257: // * @param driverPropStr String to be parsed for URL information
258: // * @param buf StringBuffer which will accept URL information
259: // * @param delimiter delimiter specified by user in eWays configuration dialog
260: // * @return position (in driverPropStr) of next character immediately following the setURL
261: // * parameter group, or 0 if no setURL parameter group was found.
262: // */
263: // static int extractURLFrom(String driverPropStr, StringBuffer buf, String delimiter) {
264: // if (StringUtil.isNullString(driverPropStr) || StringUtil.isNullString(delimiter)) {
265: // return 0;
266: // }
267: //
268: // Pattern pattern = Pattern.compile(SETURL_PATTERN.replaceAll(LOCAL_PATTERN_DELIMITER,
269: // StringUtil.escapeJavaRegexpChars(delimiter)));
270: // Matcher matcher = pattern.matcher(driverPropStr);
271: // if (matcher.find()) {
272: // buf.append(matcher.group(1));
273: // return matcher.end();
274: // }
275: // return 0;
276: // }
277: //
278: // static IParameter getIParameter(ISection section, String parameterName) throws Exception {
279: // return section.getParameter(parameterName);
280: // }
281: //
282: // static String getStringParameter(ISection section, String parameterName) throws CodeGenException {
283: // return getStringParameter(section, parameterName, true);
284: // }
285: //
286: // static String getStringParameter(ISection section, String parameterName, boolean failIfMissing) throws CodeGenException {
287: // String sParameter = null;
288: // try {
289: // IParameter param = getIParameter(section, parameterName);
290: // if (param != null) {
291: // Object value = param.getValue();
292: // if (value != null) {
293: // sParameter = value.toString();
294: // } else if (failIfMissing) {
295: // String msg = MESSAGE_MGR.getString("ERR_EXTSYS_MISSING_PARAMETER", parameterName);
296: // Logger.print(Logger.ERROR, LOG_CATEGORY, msg);
297: // throw new CodeGenException(msg);
298: // } else {
299: // Logger.print(Logger.WARN, LOG_CATEGORY, "Could not obtain parameter value for " + parameterName + "; continuing.");
300: // }
301: // }
302: // } catch (Exception e) {
303: // Logger.print(Logger.ERROR, LOG_CATEGORY, "Caught exception while getting parameter value for " + parameterName, e);
304: // throw new CodeGenException(e);
305: // }
306: // return sParameter;
307: // }
308: //
309: // static boolean isAnyParamNull(String dbName, String host, String portNumber) {
310: // return StringUtil.isNullString(dbName) || StringUtil.isNullString(host) || StringUtil.isNullString(portNumber);
311: // }
312: //
313: // static boolean isDynamicFilePath(ISection section, String parameter) throws Exception {
314: // Object obj = getIParameter(section, parameter).getValue();
315: // return ((Boolean) obj).booleanValue();
316: // }
317: //
318: // public GenerateEngineFile(ETLCodelet codelet, Collection pnLinks, ProcessingDefinition processDefn, ProjectDeployment deploy)
319: // throws RepositoryException, BaseException, CodeGenException {
320: // Iterator it = pnLinks.iterator();
321: // String qualdbId = null;
322: // String externalSystemType = null;
323: // String externalSystemSubType = null;
324: // IConfiguration iExtSubSysCfg = null;
325: // IConfiguration iExtSysCommonCfg = null;
326: // Map connDefs = new HashMap(); // Connection pool names --> resolved
327: // Map dbCatalogOverrideMapMap = new HashMap();
328: // Map dbSchemaOverrideMapMap = new HashMap();
329: //
330: // this.codelet = codelet;
331: // this.connectionDefnTemplate = new DBConnectionDefinitionTemplate();
332: // // DBConnectionDefinitions
333: // this.etlDefnPE = (ETLDefinitionProjectElement) processDefn;
334: // ETLDefinition etldefn = this.codelet.getETLDefinition(this.etlDefnPE);
335: //
336: // while (it.hasNext()) {
337: // Object objRef = it.next();
338: // if (objRef != null && objRef instanceof CMLink) {
339: // CMLink link = (CMLink) objRef;
340: // String portName = link.getSourcePort();
341: // String suffix = null;
342: // Port port = null;
343: // if (portName != null) {
344: // int index = portName.lastIndexOf("-");
345: // suffix = portName.substring(index, portName.length());
346: // port = processDefn.getDestination(portName);
347: // }
348: // if (port != null) {
349: // PortType portType = port.getPortType();
350: //
351: // String poolName = this.codelet.getDeployedName().getLocalPart() + "_" + link.getDestinationNode().getName();
352: //
353: // if (portType != null) {
354: // qualdbId = portType.getOID() + suffix ;
355: // this.dbNamePoolNameMap.put(qualdbId, poolName);
356: // externalSystemType = this.codelet.getExternalSystemType(link);
357: // externalSystemSubType = this.codelet.getExternalSystemTypeName(link);
358: // iExtSubSysCfg = ETLCodegenHelper.getExternalSystemConfiguration(link, deploy, externalSystemSubType);
359: // populateConnectionDefinitions(link, iExtSubSysCfg, connDefs, poolName, portType, suffix);
360: // iExtSysCommonCfg = ETLCodegenHelper.getExternalSystemCommonConfiguration(link, deploy);
361: // DBRuntimeEnvAccessor runtimeEnv = ETLCodegenHelper.getDBRuntimeEnvAccessor(externalSystemType, iExtSubSysCfg, iExtSysCommonCfg);
362: // if (runtimeEnv != null){
363: // if (runtimeEnv.isCatalogNameOverwritten()){
364: // Map map = new TreeMap(String.CASE_INSENSITIVE_ORDER);
365: // map.putAll(runtimeEnv.getOverwrittenCatalogNameMap());
366: //
367: // dbCatalogOverrideMapMap.put(qualdbId, map);
368: // }
369: //
370: // if (runtimeEnv.isSchemaNameOverwritten()){
371: // Map map = new TreeMap(String.CASE_INSENSITIVE_ORDER);
372: // map.putAll(runtimeEnv.getOverwrittenSchemaNameMap());
373: // dbSchemaOverrideMapMap.put(qualdbId, map);
374: // }
375: // }
376: // }
377: // }
378: // }
379: // }
380: //
381: // SQLDefinition sqlDefinition = etldefn.getSQLDefinition();
382: //
383: // try {
384: // sqlDefinition.overrideCatalogNamesForDb(dbCatalogOverrideMapMap);
385: // sqlDefinition.overrideSchemaNamesForDb(dbSchemaOverrideMapMap);
386: // ETLProcessFlowGenerator flowgen = ETLProcessFlowGeneratorFactory.getCollabFlowGenerator(sqlDefinition, true );
387: // flowgen.setWorkingFolder(ETLDeploymentConstants.PARAM_APP_DATAROOT);
388: // flowgen.setInstanceDBName(ETLDeploymentConstants.PARAM_INSTANCE_DB_NAME);
389: // flowgen.setInstanceDBFolder(codelet.getEngineInstanceDBDirectory());
390: // flowgen.setMonitorDBName(codelet.getDeployable().getName());
391: // flowgen.setMonitorDBFolder(codelet.getEngineMonitorDBDirectory());
392: // flowgen.applyConnectionDefinitions(connDefs, this.dbNamePoolNameMap, internalDBConfigParams);
393: // this.engine = flowgen.getScript();
394: // }finally{
395: // sqlDefinition.clearOverride(true, true);
396: // }
397: // }
398: //
399: // public String getEngineTaskNodes() {
400: // return engine.toXMLString();
401: // }
402: //
403: // private String createURLForAllOtherDBs(ISection section, String connectionURL, String extAppName, String extSysTypeName)
404: // throws CodeGenException, BaseException {
405: // StringBuffer url = new StringBuffer();
406: //
407: // url.append(convertDriverPropertiesToURL(section, false));
408: // if (StringUtil.isNullString(url.toString())) {
409: // url = new StringBuffer();
410: //
411: // String dbName = getStringParameter(section, ETLDeploymentConstants.DATABASE_NAME, false);
412: // String host = getStringParameter(section, ETLDeploymentConstants.SERVER_NAME, false);
413: // String portNumber = getStringParameter(section, ETLDeploymentConstants.PORT_NUMBER, false);
414: //
415: // if (isAnyParamNull(dbName, host, portNumber)) {
416: // throw new CodeGenException(MESSAGE_MGR.getString("ERR_CONN_PARAMS_NOTSET", extAppName, extSysTypeName));
417: // } else {
418: // Map connectionParams = new HashMap();
419: // connectionParams.put(DBConnectionDefinitionTemplate.KEY_DATABASE_NAME, dbName);
420: // connectionParams.put(DBConnectionDefinitionTemplate.KEY_HOST_NAME, host);
421: // connectionParams.put(DBConnectionDefinitionTemplate.KEY_HOST_PORT, portNumber);
422: // url.append(StringUtil.replace(connectionURL, connectionParams));
423: // }
424: // }
425: //
426: // String optionalParams = GenerateEngineFile.getOptionalDriverProperties(section);
427: // if (!StringUtil.isNullString(optionalParams)) {
428: // if (!url.toString().endsWith(";") && !optionalParams.startsWith(";")) {
429: // url.append(";");
430: // }
431: // url.append(optionalParams);
432: // }
433: //
434: // return url.toString();
435: // }
436: //
437: // private String createURLForDB2Connect(ISection section, final String urlTemplate,
438: // String extAppName, String extSysTypeName) throws CodeGenException, BaseException {
439: // StringBuffer url = new StringBuffer();
440: //
441: // Map connectionParams = new HashMap();
442: // url.append(convertDriverPropertiesToURL(section, false));
443: // if (StringUtil.isNullString(url.toString())) {
444: // url = new StringBuffer();
445: //
446: // String databaseName = getStringParameter(section, ETLDeploymentConstants.DATABASE_NAME, false);
447: // if (StringUtil.isNullString(databaseName)) {
448: // throw new CodeGenException(MESSAGE_MGR.getString("ERR_CONN_PARAMS_NOTSET", extAppName, extSysTypeName));
449: // } else {
450: // connectionParams.put(DBConnectionDefinitionTemplate.KEY_DATABASE_NAME, databaseName);
451: // url.append(StringUtil.replace(urlTemplate, connectionParams));
452: // }
453: // }
454: //
455: // String optionalParams = GenerateEngineFile.getOptionalDriverProperties(section);
456: // if (!StringUtil.isNullString(optionalParams)) {
457: // if (!url.toString().endsWith(":") && !optionalParams.startsWith(":")) {
458: // url.append(":");
459: // }
460: //
461: // url.append(optionalParams);
462: // // DB2 Connect driver expects every key-value property to be terminated by a semi-colon.
463: // if (!url.toString().endsWith(";")) {
464: // url.append(";");
465: // }
466: // }
467: //
468: // return url.toString();
469: // }
470: //
471: // private String createURLForDB2ConnectType4(ISection section, final String urlTemplate,
472: // String extAppName, String extSysTypeName) throws CodeGenException, BaseException {
473: // StringBuffer url = new StringBuffer();
474: //
475: // url.append(convertDriverPropertiesToURL(section, false));
476: // if (StringUtil.isNullString(url.toString())) {
477: // url = new StringBuffer();
478: //
479: // String dbName = getStringParameter(section, ETLDeploymentConstants.DATABASE_NAME, false);
480: // String host = getStringParameter(section, ETLDeploymentConstants.SERVER_NAME, false);
481: // String portNumber = getStringParameter(section, ETLDeploymentConstants.PORT_NUMBER, false);
482: //
483: // if (isAnyParamNull(dbName, host, portNumber)) {
484: // throw new CodeGenException(MESSAGE_MGR.getString("ERR_CONN_PARAMS_NOTSET", extAppName, extSysTypeName));
485: // } else {
486: // Map connectionParams = new HashMap();
487: // connectionParams.put(DBConnectionDefinitionTemplate.KEY_HOST_NAME, host);
488: // connectionParams.put(DBConnectionDefinitionTemplate.KEY_HOST_PORT, portNumber);
489: // connectionParams.put(DBConnectionDefinitionTemplate.KEY_DATABASE_NAME, dbName);
490: //
491: // url.append(StringUtil.replace(urlTemplate, connectionParams));
492: // }
493: // }
494: //
495: // String optionalParams = GenerateEngineFile.getOptionalDriverProperties(section);
496: // if (!StringUtil.isNullString(optionalParams)) {
497: // if (!url.toString().endsWith(":") && !optionalParams.startsWith(":")) {
498: // url.append(":");
499: // }
500: //
501: // url.append(optionalParams);
502: // // DB2 Connect driver expects every key-value property to be terminated by a semi-colon.
503: // if (!url.toString().endsWith(";")) {
504: // url.append(";");
505: // }
506: // }
507: //
508: // return url.toString();
509: // }
510: //
511: // private String createURLForDB2DataDirect(ISection section, final String urlTemplate,
512: // String extAppName, String extSysTypeName) throws CodeGenException, BaseException {
513: // StringBuffer url = new StringBuffer();
514: //
515: // url.append(convertDriverPropertiesToURL(section, false));
516: // if (StringUtil.isNullString(url.toString())) {
517: // url = new StringBuffer();
518: // Map connectionParams = new HashMap();
519: //
520: // String dbName = getStringParameter(section, ETLDeploymentConstants.DATABASE_NAME, false);
521: // String host = getStringParameter(section, ETLDeploymentConstants.SERVER_NAME, false);
522: // String portNumber = getStringParameter(section, ETLDeploymentConstants.PORT_NUMBER, false);
523: //
524: // // z/OS and/or AS/400 does not define DatabaseName; instead, LocationName and
525: // // PackageCollection are supplied.
526: // StringBuffer paramListBuf = new StringBuffer(30);
527: // if (StringUtil.isNullString(dbName)) {
528: // String locationName = getStringParameter(section, ETLDeploymentConstants.LOCATION_NAME, false);
529: // if (locationName != null) {
530: // paramListBuf.append("LocationName=").append(locationName);
531: // }
532: //
533: // String collectionID = getStringParameter(section, ETLDeploymentConstants.COLLECTION_ID, false);
534: // if (collectionID != null ) {
535: // paramListBuf.append(locationName != null ? ";" : "");
536: // paramListBuf.append("collectionId=").append(collectionID);
537: // }
538: //
539: // String packageCollection = getStringParameter(section, ETLDeploymentConstants.PACKAGE_COLLECTION, false);
540: // if ((packageCollection != null ) &&(! "".equals(packageCollection.trim()))){
541: // paramListBuf.append(((locationName != null) || (collectionID != null)) ? ";" : "");
542: // paramListBuf.append("packageCollection=").append(packageCollection);
543: // }
544: // } else {
545: // paramListBuf.append("DatabaseName=").append(dbName);
546: // }
547: //
548: // if (isAnyParamNull(paramListBuf.toString(), host, portNumber)) {
549: // throw new CodeGenException(MESSAGE_MGR.getString("ERR_CONN_PARAMS_NOTSET", extAppName, extSysTypeName));
550: // }
551: //
552: // connectionParams.put(DBConnectionDefinitionTemplate.KEY_PARAM_LIST, paramListBuf.toString());
553: // connectionParams.put(DBConnectionDefinitionTemplate.KEY_HOST_NAME, host);
554: // connectionParams.put(DBConnectionDefinitionTemplate.KEY_HOST_PORT, portNumber);
555: // url.append(StringUtil.replace(urlTemplate, connectionParams));
556: // }
557: //
558: // String optionalParams = GenerateEngineFile.getOptionalDriverProperties(section);
559: // if (!StringUtil.isNullString(optionalParams)) {
560: // if (!url.toString().endsWith(";") && !optionalParams.startsWith(";")) {
561: // url.append(";");
562: // }
563: //
564: // url.append(optionalParams);
565: // }
566: //
567: // return url.toString();
568: // }
569: //
570: // private SQLDBConnectionDefinition extractConnectionDefinitionParameters(CMLink link, IConfiguration iExtSubSysCfg, PortType portType, String portName)
571: // throws BaseException, CodeGenException, RepositoryException {
572: // SQLDBConnectionDefinition connDef = null;
573: //
574: // String extAppName = MESSAGE_MGR.getString("LBL_UNKNOWN");
575: // try {
576: // CMNode destNode = link.getDestinationNode();
577: // if (destNode != null) {
578: // extAppName = destNode.getName();
579: // }
580: // } catch (RepositoryException ignore) {
581: // // Ignore.
582: // }
583: //
584: // try {
585: // final String extSystemAdapterType = this.codelet.getExternalSystemType(link);
586: // final String extSysSubType = this.codelet.getExternalSystemTypeName(link);
587: //
588: // if (iExtSubSysCfg == null) {
589: // throw new CodeGenException(MESSAGE_MGR.getString("ERR_CONN_PARAMS_MISSING", extAppName, extSysSubType));
590: // }
591: //
592: // SQLDBConnectionDefinition conndefTemplate = this.connectionDefnTemplate.getDBConnectionDefinition(extSystemAdapterType);
593: // connDef = (SQLDBConnectionDefinition) conndefTemplate.cloneObject();
594: //
595: //
596: // if (ETLCodelet.EXTERNAL_APPLICATION_TYPE_FLATFILEDB.equalsIgnoreCase(extSystemAdapterType)){
597: // Map sectionMap = iExtSubSysCfg.getSections();
598: // ISection section = (ISection) sectionMap.get("parameter-settings");
599: // Logger.print(Logger.DEBUG, LOG_CATEGORY, "Section: " + section);
600: // String metadataDir = codelet.getEngineInstanceDBDirectory();
601: //
602: // String directory = getStringParameter(section, ETLDeploymentConstants.DIRECTORY);
603: // Logger.print(Logger.DEBUG, LOG_CATEGORY, "Directory for flatfile lookup: " + directory);
604: // if (this.isObjectTypeFlatfileObjectTypeDefinition(portType)) {
605: // InternalDBMetadata dbMetadata = new InternalDBMetadata(directory, isDynamicFilePath(section, "DynamicFilePath"),
606: // connDef.getName());
607: // internalDBConfigParams.put(portType.getOID() + portName, dbMetadata);
608: // }
609: //
610: // String collabName = codelet.getDeployable().getName();
611: //
612: // Map connectionParams = new HashMap();
613: // connectionParams.put(DBConnectionDefinitionTemplate.KEY_DATABASE_NAME, collabName);
614: // connectionParams.put(DBConnectionDefinitionTemplate.KEY_METADATA_DIR, metadataDir);
615: //
616: // connDef.setConnectionURL(StringUtil.replace(connDef.getConnectionURL(), connectionParams));
617: // }else{
618: // Map dbMap = iExtSubSysCfg.getSections();
619: // ISection section = (ISection) dbMap.get("JDBCConnectorSettings");
620: // String url = "";
621: //
622: // if ("DB2ADAPTER".equals(extSystemAdapterType)) {
623: // url = createURLForDB2DataDirect(section, connDef.getConnectionURL(), extAppName, extSysSubType);
624: // } else if ("DB2CONNECTADAPTER".equals(extSystemAdapterType)) {
625: // // NOTE: Ugly hack, but there isn't any other way to know what driver type
626: // // (and URL form) to use.
627: // if (extSysSubType.toUpperCase().indexOf("TYPE 4") != -1) {
628: // conndefTemplate = this.connectionDefnTemplate.getDBConnectionDefinition(extSystemAdapterType + "_TYPE4");
629: // connDef = (SQLDBConnectionDefinition) conndefTemplate.cloneObject();
630: // url = createURLForDB2ConnectType4(section, connDef.getConnectionURL(), extAppName, extSysSubType);
631: // } else {
632: // url = createURLForDB2Connect(section, connDef.getConnectionURL(), extAppName, extSysSubType);
633: // }
634: // } else {
635: // url = createURLForAllOtherDBs(section, connDef.getConnectionURL(), extAppName, extSysSubType);
636: // }
637: //
638: // connDef.setUserName(getStringParameter(section, ETLDeploymentConstants.USER));
639: // connDef.setPassword(getStringParameter(section, ETLDeploymentConstants.PASSWORD));
640: // connDef.setConnectionURL(url);
641: // }
642: // } catch (Exception e) {
643: // // Don't wrap exception if it's a BaseException or CodeGenException.
644: // if (e instanceof BaseException) {
645: // throw (BaseException) e;
646: // } else if (e instanceof CodeGenException) {
647: // throw (CodeGenException) e;
648: // }
649: // throw new BaseException(MESSAGE_MGR.getString("ERR_CONN_CONFIG_WRAPPED_EXCEPTION", extAppName));
650: // }
651: //
652: // return connDef;
653: // }
654: //
655: // private boolean isObjectTypeFlatfileObjectTypeDefinition(PortType type) {
656: // return (type instanceof FlatfileDefinition);
657: // }
658: //
659: // private void populateConnectionDefinitions(CMLink link, IConfiguration extSysCfg, Map connDefs, String poolName, PortType portType, String portName) throws CodeGenException {
660: // String extAppName = MESSAGE_MGR.getString("LBL_UNKNOWN");
661: // try {
662: // CMNode destNode = link.getDestinationNode();
663: // if (destNode != null) {
664: // extAppName = destNode.getName();
665: // }
666: // } catch (RepositoryException ignore) {
667: // // Ignore.
668: // }
669: //
670: // try {
671: // SQLDBConnectionDefinition conndef = extractConnectionDefinitionParameters(link, extSysCfg, portType, portName);
672: // conndef.setName(poolName);
673: // connDefs.put(poolName, conndef);
674: // } catch (CodeGenException e) {
675: // throw e;
676: // } catch (Exception e) {
677: // Logger.print(Logger.ERROR, LOG_CATEGORY, "Failed to configure" + " DBConnectionDefinition for runtime DataSourceConnection", e);
678: // String msg = e.getMessage();
679: // if (msg == null) {
680: // msg = MESSAGE_MGR.getString("ERR_EXTSYS_CONN_PARAMS_NOTSET", extAppName);
681: // }
682: // throw new CodeGenException(msg, e);
683: // }
684: // }
685: }
|