use of org.talend.core.database.EDatabaseTypeName in project tdi-studio-se by Talend.
the class PropertyTypeController method updateDBType.
// see bug 0004305
private void updateDBType(CompoundCommand compoundCommand, Connection repositoryConnection) {
if (repositoryConnection == null) {
return;
}
if (!(repositoryConnection instanceof DatabaseConnection)) {
return;
}
//$NON-NLS-1$
final String property = "DBTYPE";
if (elem.getElementParameter(property) == null) {
return;
}
String currentDbType = ((DatabaseConnection) repositoryConnection).getDatabaseType();
EDatabaseTypeName typeName = EDatabaseTypeName.getTypeFromDbType(currentDbType);
Command command = new PropertyChangeCommand(elem, property, typeName.getXMLType());
compoundCommand.add(command);
}
use of org.talend.core.database.EDatabaseTypeName in project tdi-studio-se by Talend.
the class JobSettingsManager method createExtraContextLoadNodes.
public static List<DataNode> createExtraContextLoadNodes(IProcess process) {
List<DataNode> nodeList = new ArrayList<DataNode>();
String paramName = EParameterName.IMPLICIT_TCONTEXTLOAD.getName();
boolean useContextLoad = ((Boolean) process.getElementParameter(paramName).getValue()) && process.getElementParameter(paramName).isShow(process.getElementParameters());
if (!useContextLoad) {
// not used
return Collections.emptyList();
}
// file
paramName = JobSettingsConstants.getExtraParameterName(EParameterName.FROM_FILE_FLAG.getName());
boolean fileFlag = ((Boolean) process.getElementParameter(paramName).getValue()) && process.getElementParameter(paramName).isShow(process.getElementParameters());
// db
String dbInput = null;
paramName = JobSettingsConstants.getExtraParameterName(EParameterName.FROM_DATABASE_FLAG.getName());
boolean dbFlag = ((Boolean) process.getElementParameter(paramName).getValue()) && process.getElementParameter(paramName).isShow(process.getElementParameters());
if (!dbFlag) {
dbInput = null;
} else {
dbInput = (String) process.getElementParameter(JobSettingsConstants.getExtraParameterName(EParameterName.DB_TYPE.getName())).getValue();
dbInput = OracleComponentHelper.filterOracleComponentName(dbInput);
if (dbInput == null || dbInput.equals("")) {
//$NON-NLS-1$
dbInput = null;
dbFlag = false;
}
}
if (!fileFlag && !dbFlag) {
// not used
return Collections.emptyList();
}
IComponent tContextLoadComponent = new JobContextLoadComponent(fileFlag, dbInput);
//$NON-NLS-1$
final String uniqueName = "Implicit_Context";
DataNode tContextLoadNode = new DataNode(tContextLoadComponent, uniqueName);
tContextLoadNode.setStart(true);
tContextLoadNode.setSubProcessStart(true);
tContextLoadNode.setActivate(true);
IMetadataTable table = getSchemaTablefromComponent(JobContextLoadComponent.CONTEXTLOAD_COMPONENT, uniqueName);
if (table != null) {
tContextLoadNode.getMetadataList().clear();
tContextLoadNode.getMetadataList().add(table);
}
// set parameters
IElementParameter param = null;
if (fileFlag) {
// is file
String inputFile = (String) process.getElementParameter(EParameterName.IMPLICIT_TCONTEXTLOAD_FILE.getName()).getValue();
String fileSparator = (String) process.getElementParameter(EParameterName.FIELDSEPARATOR.getName()).getValue();
tContextLoadNode.getElementParameter(EParameterName.IMPLICIT_TCONTEXTLOAD_FILE.getName()).setValue(inputFile);
String regex = FileSeparator.getSeparatorsRegexp(TalendQuoteUtils.removeQuotes(fileSparator));
tContextLoadNode.getElementParameter(JobSettingsConstants.IMPLICIT_TCONTEXTLOAD_REGEX).setValue(regex);
} else {
// is db
paramName = JobSettingsConstants.getExtraParameterName(EParameterName.URL.getName());
param = process.getElementParameter(paramName);
if (param != null) {
tContextLoadNode.getElementParameter(paramName).setValue(param.getValue());
}
paramName = JobSettingsConstants.getExtraParameterName(EParameterName.DRIVER_JAR.getName());
param = process.getElementParameter(paramName);
if (param != null) {
tContextLoadNode.getElementParameter(paramName).setValue(param.getValue());
}
paramName = JobSettingsConstants.getExtraParameterName(EParameterName.DRIVER_CLASS.getName());
param = process.getElementParameter(paramName);
if (param != null) {
tContextLoadNode.getElementParameter(paramName).setValue(param.getValue());
}
paramName = JobSettingsConstants.getExtraParameterName(EParameterName.HOST.getName());
tContextLoadNode.getElementParameter(paramName).setValue(process.getElementParameter(paramName).getValue());
paramName = JobSettingsConstants.getExtraParameterName(EParameterName.PORT.getName());
tContextLoadNode.getElementParameter(paramName).setValue(process.getElementParameter(paramName).getValue());
paramName = JobSettingsConstants.getExtraParameterName(EParameterName.DBNAME.getName());
tContextLoadNode.getElementParameter(paramName).setValue(process.getElementParameter(paramName).getValue());
paramName = JobSettingsConstants.getExtraParameterName(EParameterName.DB_VERSION.getName());
tContextLoadNode.getElementParameter(paramName).setValue(process.getElementParameter(paramName).getValue());
paramName = JobSettingsConstants.getExtraParameterName(EParameterName.PROPERTIES.getName());
param = process.getElementParameter(paramName);
if (param != null) {
tContextLoadNode.getElementParameter(paramName).setValue(param.getValue());
}
paramName = JobSettingsConstants.getExtraParameterName(EParameterName.SCHEMA_DB.getName());
param = process.getElementParameter(paramName);
if (param != null) {
tContextLoadNode.getElementParameter(paramName).setValue(param.getValue());
}
String schema = (String) process.getElementParameter(paramName).getValue();
if (schema != null) {
schema = TalendTextUtils.removeQuotes(schema);
}
paramName = JobSettingsConstants.getExtraParameterName(EParameterName.USER.getName());
tContextLoadNode.getElementParameter(paramName).setValue(process.getElementParameter(paramName).getValue());
paramName = JobSettingsConstants.getExtraParameterName(EParameterName.PASS.getName());
tContextLoadNode.getElementParameter(paramName).setValue(process.getElementParameter(paramName).getValue());
paramName = JobSettingsConstants.getExtraParameterName(EParameterName.CONNECTION_TYPE.getName());
tContextLoadNode.getElementParameter(paramName).setValue(OracleComponentHelper.filterOracleConnectionType((String) process.getElementParameter(JobSettingsConstants.getExtraParameterName(EParameterName.DB_TYPE.getName())).getValue()));
paramName = JobSettingsConstants.getExtraParameterName(EParameterName.DBTABLE.getName());
tContextLoadNode.getElementParameter(paramName).setValue(process.getElementParameter(paramName).getValue());
// query
String dbTableName = (String) process.getElementParameter(paramName).getValue();
String realTableName = getCurrentTableName(dbTableName);
if (realTableName == null) {
realTableName = QueryUtil.DEFAULT_TABLE_NAME;
}
String dbType = getDatabaseTypeFromParameter(process);
if (dbType != null) {
// TDI-18161:the SQL script's syntax is not right because of the implicit context of General JDBC.
if (dbType.equals(EDatabaseTypeName.GENERAL_JDBC.getDisplayName())) {
dbType = findRealDbTypeForJDBC(process, dbType);
}
EDatabaseTypeName dbTypeName = EDatabaseTypeName.getTypeFromDbType(dbType);
if (EDatabaseTypeName.ORACLE_OCI.equals(dbTypeName) || EDatabaseTypeName.ORACLEFORSID.equals(dbTypeName) || EDatabaseTypeName.ORACLESN.equals(dbTypeName)) {
for (IMetadataColumn column : table.getListColumns()) {
column.setOriginalDbColumnName(column.getOriginalDbColumnName().toUpperCase());
}
}
if (realTableName.startsWith(TalendTextUtils.QUOTATION_MARK) && realTableName.endsWith(TalendTextUtils.QUOTATION_MARK) && realTableName.length() > 2) {
realTableName = realTableName.substring(1, realTableName.length() - 1);
}
String query = TalendTextUtils.addSQLQuotes(QueryUtil.generateNewQuery(null, table, dbType, schema, realTableName));
paramName = JobSettingsConstants.getExtraParameterName(EParameterName.QUERY_CONDITION.getName());
String conditionStatement = (String) process.getElementParameter(paramName).getValue();
if (conditionStatement != null) {
String tmp = TalendTextUtils.removeQuotes(conditionStatement);
if (!"".equals(tmp)) {
//$NON-NLS-1$
//$NON-NLS-1$
query = query + CONNECTOR + QUOTE + " WHERE " + QUOTE + CONNECTOR + conditionStatement;
}
}
final String quoteByDBType = TalendTextUtils.getQuoteByDBType(dbType, false);
if (dbTypeName == EDatabaseTypeName.MSSQL) {
query = //$NON-NLS-1$
query.replaceAll(//$NON-NLS-1$
"(?i)\bkey\b", //$NON-NLS-1$ //$NON-NLS-2$
"\\\\" + quoteByDBType + "key\\\\" + quoteByDBType);
}
tContextLoadNode.getElementParameter(JobSettingsConstants.QUERY).setValue(query);
}
}
// tContextLoad
paramName = EParameterName.LOAD_NEW_VARIABLE.getName();
param = process.getElementParameter(paramName);
if (param != null) {
tContextLoadNode.getElementParameter(paramName).setValue(param.getValue());
}
paramName = EParameterName.NOT_LOAD_OLD_VARIABLE.getName();
param = process.getElementParameter(paramName);
if (param != null) {
tContextLoadNode.getElementParameter(paramName).setValue(param.getValue());
}
paramName = EParameterName.PRINT_OPERATIONS.getName();
tContextLoadNode.getElementParameter(paramName).setValue(process.getElementParameter(paramName).getValue());
paramName = EParameterName.DISABLE_ERROR.getName();
param = process.getElementParameter(paramName);
if (param != null) {
tContextLoadNode.getElementParameter(paramName).setValue(param.getValue());
}
paramName = EParameterName.DISABLE_INFO.getName();
param = process.getElementParameter(paramName);
if (param != null) {
tContextLoadNode.getElementParameter(paramName).setValue(param.getValue());
}
paramName = EParameterName.DISABLE_WARNINGS.getName();
tContextLoadNode.getElementParameter(paramName).setValue(process.getElementParameter(paramName).getValue());
tContextLoadNode.setProcess(process);
nodeList.add(tContextLoadNode);
return nodeList;
}
use of org.talend.core.database.EDatabaseTypeName in project tdq-studio-se by Talend.
the class DQStructureComparer method getRefreshedDataProvider.
public static TypedReturnCode<Connection> getRefreshedDataProvider(Connection prevDataProvider) {
// ADD xqliu 2010-03-29 bug 11951
TypedReturnCode<Connection> returnProvider = new TypedReturnCode<Connection>();
// ~11951
// MOD by zshen 2012-07-05 for bug 5074 remove convert about DatabaseParameter instead
// Connection->DatabaseParameter->ImetadataConnection into Connection->ImetadataConnection
IMetadataConnection metadataConnection = ConvertionHelper.convert((DatabaseConnection) prevDataProvider, false, prevDataProvider.getContextName());
Connection copyedConnection = null;
EDatabaseTypeName currentEDatabaseType = EDatabaseTypeName.getTypeFromDbType(metadataConnection.getDbType());
if (currentEDatabaseType != null) {
MetadataFillFactory dbInstance = MetadataFillFactory.getDBInstance(metadataConnection);
TypedReturnCode<?> trc = (TypedReturnCode<?>) dbInstance.createConnection(metadataConnection);
Object sqlConnObject = trc.getObject();
DatabaseMetaData dbJDBCMetadata = null;
if (trc.isOk() && sqlConnObject instanceof java.sql.Connection) {
java.sql.Connection sqlConn = (java.sql.Connection) sqlConnObject;
// MOD sizhaoliu 2012-5-21 TDQ-4884 reload structure issue
// dbJDBCMetadata = org.talend.utils.sql.ConnectionUtils.getConnectionMetadata(sqlConn);
dbJDBCMetadata = ExtractMetaDataUtils.getInstance().getDatabaseMetaData(sqlConn, (DatabaseConnection) prevDataProvider);
copyedConnection = EObjectHelper.deepCopy(prevDataProvider);
copyedConnection.getDataPackage().clear();
// MOD zshen the parameter for packageFiler need to differnent isCatalog or not.
dbInstance.fillCatalogs(copyedConnection, dbJDBCMetadata, metadataConnection, MetadataConnectionUtils.getPackageFilter(copyedConnection, dbJDBCMetadata, true));
dbInstance.fillSchemas(copyedConnection, dbJDBCMetadata, metadataConnection, MetadataConnectionUtils.getPackageFilter(copyedConnection, dbJDBCMetadata, false));
ConnectionUtils.closeConnection(sqlConn);
} else {
returnProvider.setMessage(trc.getMessage());
}
}
if (copyedConnection == null) {
returnProvider.setOk(false);
} else {
returnProvider.setObject(copyedConnection);
}
// ~11951
return returnProvider;
}
Aggregations