use of org.talend.core.database.EDatabaseTypeName in project tdi-studio-se by Talend.
the class TracesConnectionUtils method createConnection.
/**
* DOC hwang Comment method "createConnection".
*/
public static DatabaseConnection createConnection(ConnectionParameters parameters) {
ExtractMetaDataUtils extractMeta = ExtractMetaDataUtils.getInstance();
String dbType = parameters.getDbType();
boolean isNeedSchema = EDatabaseTypeName.getTypeFromDbType(dbType).isNeedSchema();
String productName = EDatabaseTypeName.getTypeFromDisplayName(dbType).getProduct();
// boolean isOralceWithSid = productName.equals(EDatabaseTypeName.ORACLEFORSID.getProduct());
String schema = parameters.getSchema();
EDatabaseTypeName type = EDatabaseTypeName.getTypeFromDbType(dbType);
if (ManagerConnection.isSchemaFromSidOrDatabase(type)) {
schema = parameters.getDbName();
}
if ("".equals(schema) && EDatabaseTypeName.INFORMIX.getProduct().equals(productName)) {
//$NON-NLS-1$
schema = parameters.getUserName();
}
if (EDatabaseTypeName.EXASOL.getProduct().equals(productName)) {
schema = parameters.getDbName();
}
boolean isSchemaInValid = //$NON-NLS-1$ //$NON-NLS-2$
(schema == null) || (schema.equals("\'\'")) || (schema.equals("\"\"")) || //$NON-NLS-1$
(schema.trim().equals(""));
// from 616 till line 622 modified by hyWang
NotReallyNeedSchemaDBS dbs = new NotReallyNeedSchemaDBS();
dbs.init();
List<String> names = dbs.getNeedSchemaDBNames();
boolean ifNeedSchemaDB = names.contains(productName);
if (isNeedSchema && isSchemaInValid && !ifNeedSchemaDB) {
//$NON-NLS-1$
parameters.setConnectionComment(Messages.getString("TracesConnectionUtils.connectionComment"));
return null;
}
DatabaseConnection connection = ConnectionFactory.eINSTANCE.createDatabaseConnection();
connection.setFileFieldName(parameters.getFilename());
connection.setDatabaseType(dbType);
connection.setUsername(parameters.getUserName());
connection.setPort(parameters.getPort());
connection.setRawPassword(parameters.getPassword());
if (dbType != null && dbType.equals(EDatabaseTypeName.ORACLE_OCI.getDisplayName()) && parameters.getLocalServiceName() != null && !"".equals(parameters.getLocalServiceName())) {
connection.setSID(parameters.getLocalServiceName());
} else {
connection.setSID(parameters.getDbName());
}
connection.setLabel(parameters.getDbName());
connection.setDatasourceName(parameters.getDatasource());
if (parameters.getDbType().equals(EDatabaseTypeName.GODBC.getDisplayName()) && StringUtils.isEmpty(parameters.getDatasource())) {
connection.setDatasourceName(parameters.getDbName());
}
if ("".equals(connection.getLabel())) {
//$NON-NLS-1$
connection.setLabel(parameters.getDatasource());
}
String driverClassByDbType = null;
if (parameters.getDriverClass() != null) {
driverClassByDbType = parameters.getDriverClass();
} else {
driverClassByDbType = extractMeta.getDriverClassByDbType(dbType);
}
String driverJar = parameters.getDriverJar();
connection.setDriverClass(driverClassByDbType);
connection.setDriverJarPath(driverJar);
String databaseType = connection.getDatabaseType();
if (driverClassByDbType != null && !"".equals(driverClassByDbType) && EDatabaseTypeName.GENERAL_JDBC.getDisplayName().equals(parameters.getDbType())) {
if (driverClassByDbType.startsWith("\"") && driverClassByDbType.endsWith("\"")) {
driverClassByDbType = TalendTextUtils.removeQuotes(driverClassByDbType);
}
String dbTypeByClassName = "";
if (driverJar != null && !"".equals(driverJar)) {
dbTypeByClassName = extractMeta.getDbTypeByClassNameAndDriverJar(driverClassByDbType, driverJar);
} else {
dbTypeByClassName = extractMeta.getDbTypeByClassName(driverClassByDbType);
}
if (dbTypeByClassName != null) {
databaseType = dbTypeByClassName;
}
}
final String product = EDatabaseTypeName.getTypeFromDisplayName(databaseType).getProduct();
;
connection.setProductId(product);
if (MetadataTalendType.getDefaultDbmsFromProduct(product) != null) {
final String mapping = MetadataTalendType.getDefaultDbmsFromProduct(product).getId();
connection.setDbmsId(mapping);
}
if (!isSchemaInValid && isNeedSchema) {
//$NON-NLS-1$ //$NON-NLS-2$
schema = schema.replaceAll("\'", "");
//$NON-NLS-1$ //$NON-NLS-2$
schema = schema.replaceAll("\"", "");
connection.setUiSchema(schema);
}
connection.setServerName(parameters.getHost());
connection.setAdditionalParams(parameters.getJdbcProperties());
connection.setURL(parameters.getCombineURL());
connection.setDBRootPath(parameters.getDirectory());
connection.setDbVersionString(parameters.getDbVersion());
// Added by Marvin Wang to add other parameters.
Map<String, String> params = parameters.getParameters();
if (params != null && params.size() > 0) {
Set<Entry<String, String>> collection = params.entrySet();
for (Entry<String, String> para : collection) {
connection.getParameters().put(para.getKey(), para.getValue());
}
}
return connection;
}
use of org.talend.core.database.EDatabaseTypeName in project tdi-studio-se by Talend.
the class ErDiagramComposite method getSqlStatement.
//$NON-NLS-1$
@SuppressWarnings("unchecked")
private String getSqlStatement() {
//$NON-NLS-1$
String sql = "";
List<String> tables = new ArrayList<String>();
List<String> columns = new ArrayList<String>();
List<String> wheres = new ArrayList<String>();
if (editor != null) {
if (editor.getViewer().getContents() instanceof ErDiagramPart) {
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
String schemaPrefix = "".equals(getSchema()) ? "" : getSchema() + ".";
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
String schemaPrefixWithDoubleQuotes = "".equals(getSchema()) ? "" : "\"" + getSchema() + "\".";
ErDiagramPart er = (ErDiagramPart) editor.getViewer().getContents();
for (Object object : er.getChildren()) {
if (object instanceof TablePart) {
TablePart tablePart = (TablePart) object;
Table table = (Table) tablePart.getModel();
if (TextUtil.isDoubleQuotesNeededDbType(getCurrentDbType())) {
//$NON-NLS-1$
tables.add(schemaPrefixWithDoubleQuotes + "\"" + table.getElementName() + "\"");
} else {
tables.add(schemaPrefix + TalendTextUtils.addQuotesWithSpaceField(table.getElementName(), getCurrentDbType()));
}
boolean oracleDbType = TextUtil.isOracleDbType(getCurrentDbType());
for (Object obj : tablePart.getChildren()) {
if (obj instanceof ColumnPart) {
ColumnPart columnPart = (ColumnPart) obj;
Column column = (Column) columnPart.getModel();
CheckBox isSelected = columnPart.getPrimativeFigure().getFigureCustomColumnIsSelectedFigure();
if (isSelected != null && isSelected.isSelected() && !column.getElementName().equals("*")) {
//$NON-NLS-1$
if (TextUtil.isDoubleQuotesNeededDbType(getCurrentDbType())) {
//$NON-NLS-1$
columns.add(schemaPrefixWithDoubleQuotes + "\"" + table.getElementName() + "\".\"" + column.getElementName() + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"\"");
} else {
// added by hyWang
String leftQuote = TalendTextUtils.getQuoteByDBType(getCurrentDbType(), true);
String rightQuote = TalendTextUtils.getQuoteByDBType(getCurrentDbType(), false);
String columnContent = column.getElementName();
//$NON-NLS-1$
Pattern pattern = Pattern.compile("\\w+");
Matcher matcher = pattern.matcher(columnContent);
EDatabaseTypeName dbType = EDatabaseTypeName.getTypeFromDbType(getCurrentDbType());
// modify for bug 12092
boolean sqlKeyword = KeywordsValidator.isSqlKeyword(column.getElementName(), dbType.getProduct());
if (!matcher.matches() || (sqlKeyword && oracleDbType)) {
columns.add(schemaPrefix + TalendTextUtils.addQuotesWithSpaceField(table.getElementName(), getCurrentDbType()) + //$NON-NLS-1$
"." + TalendTextUtils.addQuotesWithSpaceField(leftQuote + column.getElementName() + rightQuote, getCurrentDbType()));
} else {
columns.add(schemaPrefix + TalendTextUtils.addQuotesWithSpaceField(table.getElementName(), getCurrentDbType()) + //$NON-NLS-1$
"." + TalendTextUtils.addQuotesWithSpaceField(column.getElementName(), getCurrentDbType()));
}
}
}
for (Relation rel : (List<Relation>) column.getOutputs()) {
Column source = rel.getSource();
Column target = rel.getTarget();
if (TextUtil.isDoubleQuotesNeededDbType(getCurrentDbType())) {
String where1 = schemaPrefixWithDoubleQuotes + "\"" + source.getTable().getElementName() + //$NON-NLS-1$ //$NON-NLS-2$
"\".\"" + source.getElementName() + "\"= " + schemaPrefixWithDoubleQuotes + "\"" + //$NON-NLS-1$
target.getTable().getElementName() + "\".\"" + target.getElementName() + //$NON-NLS-1$ //$NON-NLS-2$
"\"";
if (!wheres.contains(where1)) {
wheres.add(where1);
}
} else {
String where1 = schemaPrefix + TalendTextUtils.addQuotesWithSpaceField(source.getTable().getElementName(), getCurrentDbType()) + //$NON-NLS-1$
"." + TalendTextUtils.addQuotesWithSpaceField(source.getElementName(), getCurrentDbType()) + //$NON-NLS-1$
"=" + schemaPrefix + TalendTextUtils.addQuotesWithSpaceField(target.getTable().getElementName(), getCurrentDbType()) + //$NON-NLS-1$
"." + TalendTextUtils.addQuotesWithSpaceField(target.getElementName(), getCurrentDbType());
if (!wheres.contains(where1)) {
wheres.add(where1);
}
}
}
}
}
}
}
}
}
// Mssql query need add catalog and schema before the table, like this "catolog.schema.table"
Connection conn = null;
if (rootNode != null) {
Item connectionItem = rootNode.getObject().getProperty().getItem();
if (connectionItem instanceof ConnectionItem) {
conn = ((ConnectionItem) connectionItem).getConnection();
}
}
if (getCurrentDbType() != null && (getCurrentDbType().equals(EDatabaseTypeName.MSSQL.getDisplayName()) || getCurrentDbType().equals(EDatabaseTypeName.MSSQL.name())) && conn != null) {
List<String> newTables = new ArrayList<String>();
for (String str : tables) {
newTables.add(getMssqlCatalog(str, conn));
}
tables = newTables;
}
sql = getSelectStatement(tables, columns, wheres);
if (sql.endsWith(",")) {
//$NON-NLS-1$
return sql.substring(0, sql.length() - 1);
} else if (sql.endsWith(" and ")) {
//$NON-NLS-1$
return sql.substring(0, sql.length() - 5);
}
//$NON-NLS-1$
return "";
}
use of org.talend.core.database.EDatabaseTypeName in project tdi-studio-se by Talend.
the class MetadataColumnComparator method createConnection.
/**
* dev Comment method "createConnection".
*
* @param parameters inputed when use Built-In .
* @return DatabaseConnection : connetion .
*/
public DatabaseConnection createConnection(ConnectionParameters parameters) {
String dbType = parameters.getDbType();
boolean isNeedSchema = EDatabaseTypeName.getTypeFromDbType(dbType).isNeedSchema();
String productName = EDatabaseTypeName.getTypeFromDisplayName(dbType).getProduct();
// boolean isOralceWithSid = productName.equals(EDatabaseTypeName.ORACLEFORSID.getProduct());
String schema = parameters.getSchema();
EDatabaseTypeName type = EDatabaseTypeName.getTypeFromDbType(dbType);
if (ManagerConnection.isSchemaFromSidOrDatabase(type)) {
schema = parameters.getDbName();
}
if ("".equals(schema) && EDatabaseTypeName.INFORMIX.getProduct().equals(productName)) {
//$NON-NLS-1$
schema = parameters.getUserName();
}
if (EDatabaseTypeName.EXASOL.getProduct().equals(productName)) {
schema = parameters.getDbName();
}
boolean isSchemaInValid = //$NON-NLS-1$ //$NON-NLS-2$
(schema == null) || (schema.equals("\'\'")) || (schema.equals("\"\"")) || //$NON-NLS-1$
(schema.trim().equals(""));
// from 616 till line 622 modified by hyWang
NotReallyNeedSchemaDBS dbs = new NotReallyNeedSchemaDBS();
dbs.init();
List<String> names = dbs.getNeedSchemaDBNames();
boolean ifNeedSchemaDB = names.contains(productName);
if (isNeedSchema && isSchemaInValid && !ifNeedSchemaDB) {
//$NON-NLS-1$
parameters.setConnectionComment(Messages.getString("SQLBuilderRepositoryNodeManager.connectionComment"));
return null;
}
DatabaseConnection connection = ConnectionFactory.eINSTANCE.createDatabaseConnection();
connection.setFileFieldName(parameters.getFilename());
connection.setDatabaseType(dbType);
connection.setUsername(parameters.getUserName());
connection.setPort(parameters.getPort());
connection.setRawPassword(parameters.getPassword());
if (dbType != null && dbType.equals(EDatabaseTypeName.ORACLE_OCI.getDisplayName()) && parameters.getLocalServiceName() != null && !"".equals(parameters.getLocalServiceName())) {
connection.setSID(parameters.getLocalServiceName());
} else {
connection.setSID(parameters.getDbName());
}
connection.setLabel(parameters.getDbName());
connection.setDatasourceName(parameters.getDatasource());
if ("".equals(connection.getLabel())) {
//$NON-NLS-1$
connection.setLabel(parameters.getDatasource());
}
final String product = EDatabaseTypeName.getTypeFromDisplayName(connection.getDatabaseType()).getProduct();
connection.setProductId(product);
if (MetadataTalendType.getDefaultDbmsFromProduct(product) != null) {
final String mapping = MetadataTalendType.getDefaultDbmsFromProduct(product).getId();
connection.setDbmsId(mapping);
}
if (!isSchemaInValid && isNeedSchema) {
//$NON-NLS-1$ //$NON-NLS-2$
schema = schema.replaceAll("\'", "");
//$NON-NLS-1$ //$NON-NLS-2$
schema = schema.replaceAll("\"", "");
connection.setUiSchema(schema);
}
connection.setServerName(parameters.getHost());
connection.setAdditionalParams(parameters.getJdbcProperties());
String driverClassByDbType = null;
if (parameters.getDriverClass() != null) {
driverClassByDbType = parameters.getDriverClass();
} else {
driverClassByDbType = ExtractMetaDataUtils.getInstance().getDriverClassByDbType(dbType);
}
connection.setDriverClass(driverClassByDbType);
connection.setDriverJarPath(parameters.getDriverJar());
connection.setURL(parameters.getCombineURL());
connection.setDBRootPath(parameters.getDirectory());
connection.setDbVersionString(parameters.getDbVersion());
return connection;
}
use of org.talend.core.database.EDatabaseTypeName in project tdi-studio-se by Talend.
the class MergeTosMetadataMigrationTask method execute.
@Override
public ExecutionResult execute(Item item) {
if (item instanceof ConnectionItem) {
try {
URI itemURI = getItemURI(item);
if (itemURI != null) {
URI itemResourceURI = getItemResourceURI(itemURI);
if (metadata400to410 == null) {
metadata400to410 = new TosMetadataMigrationFrom400to410();
}
Resource migratedResource = metadata400to410.migrate(itemResourceURI.toString(), new NullProgressMonitor());
HashMap<String, Object> xmlSaveOtions = XML_SAVE_OTIONS_1_0;
if (migratedResource != null) {
// check for DB connection caus we need to setup Schema and Catalog properly
EObject content = migratedResource.getContents().get(0);
if (content != null && "DatabaseConnection".equals(content.eClass().getName())) {
// resource is dynamic EMF so convert it to static model by serialising it and reloading it
ByteArrayOutputStream tempStream = new ByteArrayOutputStream();
try {
// serialize into memory
try {
migratedResource.save(tempStream, XML_SAVE_OTIONS_1_0);
} catch (Exception e) {
// try with version 1.1
tempStream = new ByteArrayOutputStream();
xmlSaveOtions = XML_SAVE_OTIONS_1_1;
migratedResource.save(tempStream, xmlSaveOtions);
} finally {
tempStream.close();
}
// create a resource to laod the inmemory resource that should be a static EMF model
migratedResource = resourceSet.createResource(URI.createURI(//$NON-NLS-1$
"http://talend/dummy_static.metadata"));
migratedResource.load(new ByteArrayInputStream(tempStream.toByteArray()), xmlSaveOtions);
// check that DBConnection is firdt element
DatabaseConnection databaseConnection = SwitchHelpers.DATABASECONNECTION_SWITCH.doSwitch(migratedResource.getContents().get(0));
// do not check for null caus DB connection is already check above
String databaseType = databaseConnection.getDatabaseType();
databaseConnection.setDriverClass(ExtractMetaDataUtils.getInstance().getDriverClassByDbType(databaseType));
EDatabaseTypeName currentType = EDatabaseTypeName.getTypeFromDbType(databaseType);
EDatabaseSchemaOrCatalogMapping curCatalog = currentType.getCatalogMappingField();
EDatabaseSchemaOrCatalogMapping curSchema = currentType.getSchemaMappingField();
// all the DB connection are migrated with a Schema by default
if (!curCatalog.equals(EDatabaseSchemaOrCatalogMapping.None)) {
List<Schema> schemas = ConnectionHelper.getSchema(databaseConnection);
if (!curSchema.equals(EDatabaseSchemaOrCatalogMapping.None)) {
// we need to place the current schemas into a catalogs
ConnectionHelper.removeSchemas(schemas, databaseConnection);
for (Schema schema : schemas) {
// compute the name of the schema and the catalogs
String schemaName = computeSchemaName(schema, databaseConnection, curSchema);
String catalogName = computeCatalogName(databaseConnection, curCatalog);
schema.setName(schemaName);
Catalog catalog = RelationalFactory.eINSTANCE.createCatalog();
// catalogs are not in a contained reference
migratedResource.getContents().add(catalog);
catalog.setName(catalogName);
// add the schema to the catalog and the the catalog to the connection
CatalogHelper.addSchemas(Collections.singleton(schema), catalog);
ConnectionHelper.addCatalog(catalog, databaseConnection);
}
} else {
// we need to replace the Schemas with a Catalogs
for (Schema schema : schemas) {
// compute the name the catalog
String catalogName = computeCatalogName(databaseConnection, curCatalog);
// use owned elements to get everything regardless of tables or views or
// else
Catalog catalog = RelationalFactory.eINSTANCE.createCatalog();
// catalogs are not in a contained reference
migratedResource.getContents().add(catalog);
catalog.setName(catalogName);
catalog.getOwnedElement().addAll(schema.getOwnedElement());
ConnectionHelper.addCatalog(catalog, databaseConnection);
ConnectionHelper.removeSchemas(Collections.singleton(schema), databaseConnection);
}
}
} else if (!curSchema.equals(EDatabaseSchemaOrCatalogMapping.None)) {
List<Schema> schemas = ConnectionHelper.getSchema(databaseConnection);
for (Schema schema : schemas) {
String schemaName = computeSchemaName(schema, databaseConnection, curSchema);
schema.setName(schemaName);
}
}
// else no catalog so we keep the schema as is
} catch (Exception e) {
// we have an exception finalising the migration but we trap it caus we still try to
// save it
log.error("Cannot complete merge metadata migration on file:" + itemResourceURI.toString(), e);
ExceptionHandler.process(e);
} finally {
tempStream.close();
}
}
// else not a DB connection so persist
OutputStream outputStream = item.eResource().getResourceSet().getURIConverter().createOutputStream(itemResourceURI, null);
try {
migratedResource.save(outputStream, xmlSaveOtions);
} finally {
outputStream.close();
}
}
return ExecutionResult.SUCCESS_WITH_ALERT;
}
} catch (ATLCoreException e) {
log.error(e);
ExceptionHandler.process(e);
return ExecutionResult.SUCCESS_NO_ALERT;
} catch (IOException e) {
log.error(e);
ExceptionHandler.process(e);
return ExecutionResult.SUCCESS_NO_ALERT;
} finally {
resourceSet.getResources().clear();
}
}
return ExecutionResult.NOTHING_TO_DO;
}
use of org.talend.core.database.EDatabaseTypeName in project tdi-studio-se by Talend.
the class GuessSchemaProcess method buildProcess.
private void buildProcess() {
process = new Process(property);
process.getContextManager().getListContext().addAll(node.getProcess().getContextManager().getListContext());
process.getContextManager().setDefaultContext(this.selectContext);
outputComponent = ComponentsFactoryProvider.getInstance().get(EDatabaseComponentName.FILEDELIMITED.getOutPutComponentName(), ComponentCategory.CATEGORY_4_DI.getName());
if (node.getModulesNeeded().size() > 0 && !node.getComponent().getName().equals("tRedshiftInput")) {
//$NON-NLS-1$
for (ModuleNeeded module : node.getModulesNeeded()) {
if (module.isRequired(node.getElementParameters())) {
Node libNode1 = new Node(ComponentsFactoryProvider.getInstance().get(LIB_NODE, ComponentCategory.CATEGORY_4_DI.getName()), process);
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
libNode1.setPropertyValue("LIBRARY", "\"" + module.getModuleName() + "\"");
NodeContainer nc = process.loadNodeContainer(libNode1, false);
process.addNodeContainer(nc);
}
}
} else {
// hywang add for 9594
if (node.getComponent().getName().equals("tJDBCInput") || node.getComponent().getName().equals("tRedshiftInput")) {
List<String> drivers = EDatabaseVersion4Drivers.getDrivers(info.getTrueDBTypeForJDBC(), info.getDbVersion());
String moduleNeedName = "";
Node libNode1 = new Node(ComponentsFactoryProvider.getInstance().get(LIB_NODE, ComponentCategory.CATEGORY_4_DI.getName()), process);
if (drivers.size() > 0) {
// use the first driver as defalult.
// added for bug 13592
moduleNeedName = drivers.get(0).toString();
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
libNode1.setPropertyValue("LIBRARY", "\"" + moduleNeedName + "\"");
}
process.addNodeContainer(new NodeContainer(libNode1));
}
}
INode connectionNode = null;
IElementParameter existConnection = node.getElementParameter("USE_EXISTING_CONNECTION");
boolean useExistConnection = (existConnection == null ? false : (Boolean) existConnection.getValue());
if (useExistConnection) {
IElementParameter connector = node.getElementParameter("CONNECTION");
if (connector != null) {
String connectorValue = connector.getValue().toString();
List<? extends INode> generatingNodes = originalProcess.getGeneratingNodes();
for (INode node : generatingNodes) {
if (node.getUniqueName().equals(connectorValue)) {
connectionNode = node;
break;
}
}
}
}
List<ModuleNeeded> neededLibraries = new ArrayList<ModuleNeeded>();
JavaProcessUtil.addNodeRelatedModules(process, neededLibraries, node);
for (ModuleNeeded module : neededLibraries) {
Node libNode1 = new Node(ComponentsFactoryProvider.getInstance().get(LIB_NODE), process);
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
libNode1.setPropertyValue("LIBRARY", "\"" + module.getModuleName() + "\"");
process.addNodeContainer(new NodeContainer(libNode1));
}
if (connectionNode != null) {
neededLibraries = new ArrayList<ModuleNeeded>();
JavaProcessUtil.addNodeRelatedModules(process, neededLibraries, connectionNode);
for (ModuleNeeded module : neededLibraries) {
Node libNode1 = new Node(ComponentsFactoryProvider.getInstance().get(LIB_NODE), process);
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
libNode1.setPropertyValue("LIBRARY", "\"" + module.getModuleName() + "\"");
process.addNodeContainer(new NodeContainer(libNode1));
}
}
// create the tLibraryLoad for the output component which is "tFileOutputDelimited"
for (ModuleNeeded module : outputComponent.getModulesNeeded()) {
Node libNode2 = new Node(ComponentsFactoryProvider.getInstance().get(LIB_NODE), process);
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
libNode2.setPropertyValue("LIBRARY", "\"" + module.getModuleName() + "\"");
process.addNodeContainer(new NodeContainer(libNode2));
}
// for sql statement, feature 6622.
int fetchSize = maximumRowsToPreview;
if (maximumRowsToPreview > 1000) {
fetchSize = 1000;
}
String codeStart, codeMain, codeEnd;
temppath = buildTempCSVFilename();
// Should also replace "/r". NMa.
// ISO-8859-15
memoSQL = memoSQL.replace("\r", " ");
// fix for TDI-26285
//$NON-NLS-1$
String createStatament = "conn.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY)";
//$NON-NLS-1$
String systemProperty = "";
if (info.isHive()) {
//$NON-NLS-1$
createStatament = "conn.createStatement()";
systemProperty = //$NON-NLS-1$ //$NON-NLS-2$
"System.setProperty(\"mapred.job.tracker\",\"" + info.getJobTracker() + "\");\r\n" + "System.setProperty(\"fs.default.name\", \"" + info.getNameNode() + //$NON-NLS-1$ //$NON-NLS-2$
"\");\r\n";
// only embeded hive need the following params
if (info.getThrifturi() != null) {
systemProperty = //$NON-NLS-1$
systemProperty + " System.setProperty(\"hive.metastore.local\", \"false\");\r\n" + " System.setProperty(\"hive.metastore.uris\", \"" + info.getThrifturi() + //$NON-NLS-1$ //$NON-NLS-2$
"\");\r\n" + //$NON-NLS-1$
"System.setProperty(\"hive.metastore.execute.setugi\", \"true\");\r\n";
}
}
// add for bug TDI-27137 by fwang on 27 August, 2013.
EDatabaseTypeName dbType = EDatabaseTypeName.JAVADB_EMBEDED.getTypeFromDbType(info.getDbType());
if (EDatabaseTypeName.JAVADB_EMBEDED.equals(dbType)) {
IElementParameter dbPathElement = node.getElementParameter("DBPATH");
if (dbPathElement != null) {
String derbyPath = dbPathElement.getValue().toString().replace("\"", "").trim();
systemProperty = systemProperty + "System.setProperty(\"derby.system.home\",\"" + derbyPath + "\");\r\n";
}
}
// the Sqlite
if (EDatabaseTypeName.SQLITE.getXmlName().equals(info.getDbType())) {
createStatament = "conn.createStatement()";
}
// the VERTICA
if (ConnectionUtils.isVertica(info.getUrl())) {
createStatament = "conn.createStatement()";
}
if (EDatabaseTypeName.GENERAL_JDBC.getXmlName().equals(info.getDbType()) && "com.sap.db.jdbc.Driver".equals(info.getDriverClassName()) || EDatabaseTypeName.SAPHana.getXmlName().equals(info.getDbType())) {
createStatament = "conn.createStatement()";
}
codeStart = systemProperty + getCodeStart(connectionNode, createStatament, fetchSize);
codeMain = //$NON-NLS-1$ //$NON-NLS-2$
"String[] dataOneRow = new String[numbOfColumn];\r\n" + "for (int i = 1; i <= numbOfColumn; i++) {\r\n" + " \r\n" + " try{\r\n" + " String tempStr = rs.getString(i);\r\n" + " dataOneRow[i-1] = tempStr;\r\n" + " } catch (java.sql.SQLException e) {\r\n" + "}\r\n" + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
"}\r\n" + //$NON-NLS-1$
"csvWriter.writeNext(dataOneRow);";
if (EDatabaseTypeName.REDSHIFT.getXmlName().equals(info.getDbType())) {
codeEnd = //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
"nbRows++;\r\n" + " if (nbRows > " + maximumRowsToPreview + ") break;\r\n" + "}\r\n" + "conn.close();\r\n" + //$NON-NLS-1$ //$NON-NLS-2$
"csvWriter.close();\r\n";
} else {
codeEnd = //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
"nbRows++;\r\n" + " if (nbRows > " + maximumRowsToPreview + ") break;\r\n" + "}\r\n" + "conn.close();\r\n" + //$NON-NLS-1$ //$NON-NLS-2$
"csvWriter.close();\r\n";
}
IComponent component = null;
switch(LanguageManager.getCurrentLanguage()) {
case JAVA:
//$NON-NLS-1$
component = ComponentsFactoryProvider.getInstance().get("tJavaFlex");
break;
case PERL:
default:
//$NON-NLS-1$
component = ComponentsFactoryProvider.getInstance().get("tPerlFlex");
break;
}
Node flexNode = new Node(component, process);
//$NON-NLS-1$
flexNode.setPropertyValue("CODE_START", codeStart);
//$NON-NLS-1$
flexNode.setPropertyValue("CODE_MAIN", codeMain);
//$NON-NLS-1$
flexNode.setPropertyValue("CODE_END", codeEnd);
process.addNodeContainer(new NodeContainer(flexNode));
}
Aggregations