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 java.util.UUID;
022: import org.netbeans.modules.etl.utils.ETLDeploymentConstants;
023: import org.netbeans.modules.mashup.db.model.FlatfileDefinition;
024: import org.netbeans.modules.sql.framework.model.SQLConstants;
025: import org.netbeans.modules.sql.framework.model.SQLDBModel;
026: import com.sun.sql.framework.exception.BaseException;
027: import java.util.HashMap;
028: import java.util.Iterator;
029: import org.netbeans.modules.mashup.db.model.FlatfileDatabaseModel;
030: import org.netbeans.modules.mashup.db.model.impl.FlatfileDBConnectionDefinitionImpl;
031: import org.netbeans.modules.mashup.db.model.impl.FlatfileDBTableImpl;
032: import org.netbeans.modules.mashup.db.model.impl.FlatfileDatabaseModelImpl;
033: import org.netbeans.modules.sql.framework.model.DBConnectionDefinition;
034: import org.netbeans.modules.sql.framework.model.DBTable;
035: import org.netbeans.modules.sql.framework.model.DatabaseModel;
036: import org.netbeans.modules.sql.framework.model.SQLDBTable;
037: import org.netbeans.modules.sql.framework.model.impl.SQLDBModelImpl;
038:
039: /**
040: * Utility methods for generating engine file, Please note the class modifiers should be
041: * scoped to default to restrict their access to members of this package only.
042: *
043: * @author Ahimanikya Satapathy
044: */
045: public class ETLCodegenUtil {
046:
047: private static final String ETL_FOLDER = "eTL";
048:
049: //private static final String LOG_CATEGORY = ETLCodegenUtil.class.getName();
050:
051: //private static final MessageManager MESSAGE_MGR = MessageManager.getManager(ETLCodelet.class);
052: //private static final String IS_SECTION = "IS Configuration" ;
053: //private static final String IS_WORKSPACE_DIR = "WORKSPACEDIR" ;
054: // /**
055: // * Returns Folder for Monitor DB. Specific to each Collaboration/CMap service.
056: // * @param deployable
057: // * @return Parameterized Monitor DB path.
058: // * @throws BaseException
059: // */
060: // public static String getMonitorDBDir(Deployable deployable) throws BaseException {
061: // return getMonitorDBDir(deployable, ETLDeploymentConstants.PARAM_APP_DATAROOT);
062: // }
063: //
064: //
065: public static String getMonitorDBDir(String deployable,
066: String workspaceDir) throws BaseException {
067: String monitorDBFolder = null;
068: try {
069: String repOID = UUID.randomUUID().toString();
070:
071: // Use "/" for maximum portability as codegen OS may be different than OS on
072: // which service is deployed.
073: monitorDBFolder = workspaceDir + "/" + ETL_FOLDER + "/m/"
074: + repOID + "/" + deployable + "/";
075: } catch (Exception ex) {
076: throw new BaseException(
077: "Cannot create eTL monitor log folder.", ex);
078: }
079:
080: return monitorDBFolder;
081: }
082:
083: // public static String getRSWorkspaceDir (CodeGenFramework framework, ErrorBundle errorBundle,
084: // ProjectDeployment projDeployment, Deployable deployable) {
085: // String errorMessage = null;
086: // String svcName = "eTL Service" ;
087: // IConfiguration iConfig = null;
088: // String tRSWorkspaceDir = null;
089: // String runtimeServerWorkspaceDir = null;
090: // ETLDefinitionProjectElement etlDef = null;
091: // int i = 1;
092: //
093: // if (errorBundle == null) {
094: // errorBundle = framework.createErrorBundle();
095: // }
096: //
097: // Collection tc = errorBundle.getErrors() ;
098: // if (tc != null) {
099: // i = (i <= tc.size())?(tc.size()+1): i;
100: // }
101: //
102: // try {
103: // etlDef = (ETLDefinitionProjectElement) ((ProcessingNode) deployable).getProcessingDefinition();
104: // EnvironmentElement ee =projDeployment.getDeployedElement(deployable, projDeployment.getEnvironment());
105: // svcName = deployable.getName();
106: //
107: // if ((ee != null) && (ee instanceof IntegrationServer)){
108: // IntegrationServer is = (IntegrationServer) ee;
109: //
110: // iConfig = ETLCodegenHelper.getIConfiguration(is.getConfiguration());
111: //
112: // if ((iConfig != null) && (iConfig.getSection(IS_SECTION) != null)) {
113: // ISection section = iConfig.getSection(IS_SECTION) ;
114: // IParameter param = section.getParameter(IS_WORKSPACE_DIR);
115: // if ((param != null) && (param.getValue() != null)) {
116: // tRSWorkspaceDir = param.getValue().toString();
117: // }
118: //
119: // if ((tRSWorkspaceDir == null) || ("".equals(tRSWorkspaceDir.trim()))){
120: // errorMessage = MESSAGE_MGR.getString("ERR_RS_WORKSPACE_DIR_NOT_PRESENT", is.getName() );
121: // errorBundle.addError(framework.createErrorEntry(etlDef, new Integer(i++), errorMessage));
122: // runtimeServerWorkspaceDir = null;
123: // }else {
124: // runtimeServerWorkspaceDir = tRSWorkspaceDir;
125: // }
126: //
127: // }else {
128: // errorMessage = MESSAGE_MGR.getString("ERR_GETTING_RS_CONFIG", svcName );
129: // errorBundle.addError(framework.createErrorEntry(etlDef, new Integer(i++), errorMessage));
130: // }
131: // }else {
132: // errorMessage = MESSAGE_MGR.getString("ERR_COLLAB_SVC_NOT_DEPLOYED", svcName);
133: // errorBundle.addError(framework.createErrorEntry(etlDef, new Integer(i++), errorMessage));
134: // }
135: // }catch (RepositoryException re) {
136: // errorMessage = MESSAGE_MGR.getString("ERR_GETTING_RS_CONFIG", svcName );
137: // errorBundle.addError(framework.createErrorEntry(etlDef, new Integer(i++), errorMessage));
138: //
139: // }catch (Exception ex) {
140: // errorMessage = MESSAGE_MGR.getString("ERR_GETTING_RS_CONFIG", svcName);
141: // errorBundle.addError(framework.createErrorEntry(etlDef, new Integer(i++), errorMessage));
142: //
143: // }
144: //
145: // return runtimeServerWorkspaceDir;
146: // }
147: /**
148: * Returns Folder for Monitor DB. Specific to each Collaboration/CMap service.
149: * @return Parameterized engine instance DB path.
150: * @throws BaseException
151: */
152: public static String getEngineInstanceWorkingFolder() {
153: return getEngineInstanceWorkingFolder(ETLDeploymentConstants.PARAM_APP_DATAROOT);
154: }
155:
156: /**
157: * Returns Folder for Monitor DB. Specific to each Collaboration/CMap service.
158: * @return Parameterized engine instance DB path.
159: * @throws BaseException
160: */
161: public static String getEngineInstanceWorkingFolder(
162: String appWorkspaceDirectory) {
163: String engineInstanceDBFolder = null;
164: // Use "/" as codegen OS may be different than OS on which deployed.
165: engineInstanceDBFolder = appWorkspaceDirectory + "/"
166: + ETL_FOLDER + "/i/"
167: + ETLDeploymentConstants.PARAM_INSTANCE_DB_NAME + "/";
168: return engineInstanceDBFolder;
169: }
170:
171: /**
172: * Returns Folder for Monitor DB. Specific to each Collaboration/CMap service.
173: * @return Parameterized engine instance DB path.
174: * @throws BaseException
175: */
176: public static String getEngineInstanceWorkingFolder(
177: String appWorkspaceDirectory, String dbInstanceName) {
178: String engineInstanceDBFolder = null;
179: // Use "/" as codegen OS may be different than OS on which deployed.
180: engineInstanceDBFolder = appWorkspaceDirectory + "/"
181: + ETL_FOLDER + "/i/" + dbInstanceName + "/";
182: return engineInstanceDBFolder;
183: }
184:
185: public static FlatfileDefinition getFFDefinition(DBTable table) {
186: if (table.getParent().getSource() == null) {
187: DatabaseModel model = table.getParent();
188: DBConnectionDefinition condef = model
189: .getConnectionDefinition();
190: try {
191: Class.forName("org.axiondb.jdbc.AxionDriver");
192: } catch (ClassNotFoundException e1) {
193: // TODO Auto-generated catch block
194: e1.printStackTrace();
195:
196: }
197:
198: if (condef.getDriverClass().equals(
199: "org.axiondb.jdbc.AxionDriver")) {
200:
201: FlatfileDefinition fd = new FlatfileDefinition(model
202: .getModelName());
203: FlatfileDBConnectionDefinitionImpl ffdbConndef = new FlatfileDBConnectionDefinitionImpl(
204: condef.getName(), condef.getDriverClass(),
205: condef.getConnectionURL(),
206: condef.getUserName(), condef.getPassword(),
207: condef.getDescription());
208:
209: FlatfileDatabaseModel fdm = new FlatfileDatabaseModelImpl(
210: model.getModelName(), ffdbConndef);
211: Iterator iterator = model.getTables().iterator();
212: HashMap fftables = new HashMap();
213: while (iterator.hasNext()) {
214: SQLDBTable element = (SQLDBTable) iterator.next();
215: element.getClass();
216: FlatfileDBTableImpl ft = new FlatfileDBTableImpl(
217: element);
218: HashMap map = ((SQLDBModelImpl) model)
219: .getTableMetaData(condef, element);
220: ft.setProperties(map);
221: fftables.put(element.getName(), ft);
222: }
223: fdm.setTables(fftables);
224: fd.setFlatfileDatabaseModel(fdm);
225: // return (FlatfileDefinition) table.getParent().getSource();
226: return fd;
227: }
228: }
229:
230: return null;
231: }
232:
233: public static FlatfileDefinition getStcdbObjectTypeDefinition(
234: DBTable table) {
235: if (table.getParent().getSource() != null) {
236: Object obj = table.getParent().getSource();
237: if (obj instanceof FlatfileDefinition) {
238: return (FlatfileDefinition) obj;
239: }
240: } else {
241: return getFFDefinition(table);
242: }
243: return (FlatfileDefinition) null;
244: }
245:
246: public static String getQualifiedObjectId(SQLDBModel dbModel) {
247: String key = null;
248:
249: try {
250: key = dbModel.getSource().getObjectId();
251: if (dbModel.getObjectType() == SQLConstants.TARGET_DBMODEL) {
252: key = createTargetPortNameFromOID(key);
253: } else {
254: key = createSourcePortNameFromOID(key);
255: }
256: } catch (Exception ex) {
257: key = null;
258: }
259:
260: return key;
261: }
262:
263: public static String getQualifiedConnectionDefinitionName(
264: SQLDBModel dbModel, String name) {
265: String qName = name;
266: try {
267: if (dbModel.getObjectType() == SQLConstants.TARGET_DBMODEL) {
268: qName = "T_" + qName;
269: } else {
270: qName = "S_" + qName;
271: }
272: } catch (Exception ex) {
273: qName = null;
274: }
275:
276: return qName;
277: }
278:
279: public static String createSourcePortNameFromOID(String oid) {
280: return oid + SQLConstants.SOURCE_DB_MODEL_NAME_SUFFIX;
281: }
282:
283: public static String createTargetPortNameFromOID(String oid) {
284: return oid + SQLConstants.TARGET_DB_MODEL_NAME_SUFFIX;
285: }
286: }
|