use of org.talend.core.model.metadata.builder.connection.DatabaseConnection in project tdi-studio-se by Talend.
the class DbTypeListController method getCurrentDbms.
private static String getCurrentDbms(INode node) {
boolean hasMappingType = false;
String currentDbms = null;
for (IElementParameter currentParam : node.getElementParameters()) {
if (currentParam.getFieldType().equals(EParameterFieldType.MAPPING_TYPE) && currentParam.isShow(node.getElementParameters())) {
currentDbms = (String) currentParam.getValue();
hasMappingType = true;
}
}
if (!hasMappingType) {
// if there is no mapping type, then check if a db repository schema is used
//$NON-NLS-1$
IElementParameter schemaTypeParameter = node.getElementParameter("SCHEMA_TYPE");
if (schemaTypeParameter == null) {
return null;
}
String schemaType = (String) schemaTypeParameter.getValue();
if (schemaType.equals("REPOSITORY")) {
//$NON-NLS-1$
// repository mode
//$NON-NLS-1$
String metaRepositoryName = (String) node.getElementParameter("REPOSITORY_SCHEMA_TYPE").getValue();
Connection connection = MetadataToolHelper.getConnectionFromRepository(metaRepositoryName);
if (connection instanceof DatabaseConnection) {
// bug 13200
if (((DatabaseConnection) connection).getDatabaseType().equals(EDatabaseTypeName.GENERAL_JDBC.getDisplayName())) {
// bug 7618 modify
currentDbms = (DBConnectionContextUtils.cloneOriginalValueConnection((DatabaseConnection) connection, true, null)).getDbmsId();
} else {
currentDbms = ((DatabaseConnection) connection).getDbmsId();
}
}
} else {
//$NON-NLS-1$
String componentDbType = "";
for (IElementParameter param : (List<IElementParameter>) node.getElementParameters()) {
if (param.getRepositoryValue() != null) {
if (param.getRepositoryValue().equals("TYPE")) {
//$NON-NLS-1$
componentDbType = (String) param.getValue();
}
}
}
String componentProduct = EDatabaseTypeName.getTypeFromDbType(componentDbType).getProduct();
if (EDatabaseTypeName.supportDbType(componentDbType)) {
currentDbms = MetadataTalendType.getDefaultDbmsFromProduct(componentProduct).getId();
}
}
}
return currentDbms;
}
use of org.talend.core.model.metadata.builder.connection.DatabaseConnection in project tdi-studio-se by Talend.
the class GuessSchemaController method useMockJob.
private void useMockJob() {
/*
* get the select node,it's the input node of the process. then transfer selected context varriable to
* openContextChooseDialog, added by hyWang
*/
final IElementParameter switchParam = elem.getElementParameter(EParameterName.REPOSITORY_ALLOW_AUTO_SWITCH.getName());
final Shell parentShell = this.composite.getShell();
final Node inputNode = (Node) this.curParameter.getElement();
if (connParameters == null) {
initConnectionParameters();
}
final String tmpMemoSql = this.memoSQL;
final DatabaseConnection connt = TracesConnectionUtils.createConnection(connParameters);
IMetadataConnection iMetadataConnection = null;
boolean isStatus = false;
try {
if (connt != null) {
iMetadataConnection = ConvertionHelper.convert(connt);
isStatus = checkConnection(iMetadataConnection);
}
if (isStatus) {
if (EDatabaseTypeName.GENERAL_JDBC.getDisplayName().equals(iMetadataConnection.getDbType())) {
info = new DbInfo(iMetadataConnection.getDbType(), iMetadataConnection.getUsername(), iMetadataConnection.getPassword(), iMetadataConnection.getDbVersionString(), iMetadataConnection.getUrl(), iMetadataConnection.getDriverClass(), iMetadataConnection.getDriverJarPath(), iMetadataConnection.getAdditionalParams());
} else if (EDatabaseTypeName.HIVE.getDisplayName().equals(iMetadataConnection.getDbType())) {
String jobTracker = TalendTextUtils.removeQuotes(String.valueOf(iMetadataConnection.getParameter(ConnParameterKeys.CONN_PARA_KEY_JOB_TRACKER_URL)));
String nameNode = TalendTextUtils.removeQuotes(String.valueOf(iMetadataConnection.getParameter(ConnParameterKeys.CONN_PARA_KEY_NAME_NODE_URL)));
String thrifturi = null;
if (HiveModeInfo.get(iMetadataConnection.getDbVersionString()) == HiveModeInfo.EMBEDDED) {
thrifturi = "thrift://" + iMetadataConnection.getServerName() + ":" + iMetadataConnection.getPort();
}
info = new DbInfo(iMetadataConnection.getDbType(), iMetadataConnection.getUsername(), iMetadataConnection.getPassword(), iMetadataConnection.getDbVersionString(), iMetadataConnection.getUrl(), jobTracker, nameNode, thrifturi, iMetadataConnection.getDriverJarPath());
String hiveServerVersion = String.valueOf(iMetadataConnection.getParameter(ConnParameterKeys.HIVE_SERVER_VERSION));
//$NON-NLS-1$
String driverClass = "";
if (HiveServerVersionInfo.HIVE_SERVER_2.getKey().equals(hiveServerVersion)) {
driverClass = EDatabase4DriverClassName.HIVE2.getDriverClass();
} else {
driverClass = EDatabase4DriverClassName.HIVE.getDriverClass();
}
info.setDriverClassName(driverClass);
} else {
info = new DbInfo(iMetadataConnection.getDbType(), iMetadataConnection.getUsername(), iMetadataConnection.getPassword(), iMetadataConnection.getDbVersionString(), iMetadataConnection.getUrl(), iMetadataConnection.getDriverJarPath());
}
final Property property = GuessSchemaProcess.getNewmockProperty();
List<IContext> allcontexts = inputNode.getProcess().getContextManager().getListContext();
OpenContextChooseComboDialog dialog = new OpenContextChooseComboDialog(parentShell, allcontexts);
dialog.create();
dialog.getShell().setText(CONTEXT_CHOOSE_DIALOG_TITLE);
IContext selectContext = null;
// job only have defoult context,or the query isn't context mode
if (allcontexts.size() == 1 || TalendTextUtils.isCommonString(tmpMemoSql)) {
selectContext = inputNode.getProcess().getContextManager().getDefaultContext();
} else if (Window.OK == dialog.open()) {
selectContext = dialog.getSelectedContext();
}
final IContext context = selectContext;
if (context != null) {
//
final ProgressMonitorDialog pmd = new ProgressMonitorDialog(this.composite.getShell());
pmd.run(true, true, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
runShadowProcess(property, inputNode, context, switchParam);
}
});
}
});
}
} else {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
//$NON-NLS-1$
String pid = "org.talend.sqlbuilder";
//$NON-NLS-1$
String mainMsg = Messages.getString("GuessSchemaController.connectionFailed");
ErrorDialogWithDetailAreaAndContinueButton dialog = new ErrorDialogWithDetailAreaAndContinueButton(composite.getShell(), pid, mainMsg, connParameters.getConnectionComment());
if (dialog.getCodeOfButton() == Window.OK) {
openParamemerDialog(composite.getShell(), part.getProcess().getContextManager());
}
}
});
}
} catch (Exception e) {
ExceptionHandler.process(e);
}
// else {
// try {
// pmd2.run(true, true, new IRunnableWithProgress() {
// public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
// Display.getDefault().asyncExec(new Runnable() {
//
// public void run() {
// String pid = SqlBuilderPlugin.PLUGIN_ID;
// String mainMsg = Messages.getString("GuessSchemaController.connectionFailed"); //$NON-NLS-1$
// ErrorDialogWithDetailAreaAndContinueButton dialog = new ErrorDialogWithDetailAreaAndContinueButton(composite
// .getShell(), pid, mainMsg, connParameters.getConnectionComment());
// if (dialog.getCodeOfButton() == Window.OK) {
// openParamemerDialog(composite.getShell(), part.getTalendEditor().getProcess().getContextManager());
// }
// }
// });
// }
// });
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
}
use of org.talend.core.model.metadata.builder.connection.DatabaseConnection in project tdi-studio-se by Talend.
the class AddProductAndMappingInDBConnectionEMFMigrationTask method addProductAndMapping.
/**
* qzhang Comment method "addProductAndMapping".
*/
private void addProductAndMapping(ConnectionItem item) throws PersistenceException {
ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
final DatabaseConnection connection = (DatabaseConnection) item.getConnection();
final String product = EDatabaseTypeName.getTypeFromDisplayName(connection.getDatabaseType()).getProduct();
connection.setProductId(product);
connection.setDbmsId(MetadataTalendType.getDefaultDbmsFromProduct(product).getId());
factory.save(item);
}
use of org.talend.core.model.metadata.builder.connection.DatabaseConnection in project tdi-studio-se by Talend.
the class AbstractJobSettingsPage method updateProjectSetting.
public void updateProjectSetting() {
String[] split = getRepositoryPropertyName().split(":");
String parentParamName = split[0];
Element elementParams = elem;
IElementParameter elementParameter = elementParams.getElementParameter(parentParamName);
if (elementParameter != null && elementParameter.isShow(elem.getElementParameters()) && elementParameter.getChildParameters() != null) {
if (elementParameter.getChildParameters().get("PROPERTY_TYPE") != null && !EmfComponent.BUILTIN.equals(elementParameter.getChildParameters().get("PROPERTY_TYPE").getValue())) {
DatabaseConnection connection = null;
String id = (String) elementParameter.getChildParameters().get("REPOSITORY_PROPERTY_TYPE").getValue();
IRepositoryViewObject lastVersion = UpdateRepositoryUtils.getRepositoryObjectById(id);
if (lastVersion != null && lastVersion.getProperty() != null) {
Item item = lastVersion.getProperty().getItem();
if (item instanceof DatabaseConnectionItem) {
DatabaseConnectionItem dbItem = (DatabaseConnectionItem) item;
connection = (DatabaseConnection) dbItem.getConnection();
}
}
if (connection != null) {
boolean sameValues = true;
for (IElementParameter param : elementParams.getElementParameters()) {
String repositoryValue = param.getRepositoryValue();
if (param.isShow(elementParams.getElementParameters()) && repositoryValue != null && !param.getName().equals("PROPERTY_TYPE")) {
Object repValue = RepositoryToComponentProperty.getValue(connection, repositoryValue, null);
if (repValue == null) {
continue;
}
if (repositoryValue.equals(UpdatesConstants.TYPE)) {
// datebase type
boolean found = false;
String[] list = param.getListRepositoryItems();
for (int i = 0; (i < list.length) && (!found); i++) {
if (repValue.equals(list[i])) {
found = true;
}
}
if (!found) {
sameValues = false;
break;
}
} else {
// check the value
if (!param.getValue().equals(repValue)) {
sameValues = false;
break;
}
}
}
}
if (!sameValues) {
boolean ok = MessageDialog.openQuestion(getShell(), getDisplayName(), "Connection has been changed , do you want to change value from repository ?");
if (ok) {
ChangeValuesFromRepository changeValuesFromRepository = new ChangeValuesFromRepository(elem, connection, getRepositoryPropertyName(), id);
changeValuesFromRepository.execute();
isConnectionChanged = true;
}
}
} else {
MessageDialog.openInformation(getShell(), getDisplayName(), "Connection has been deleted ,change to build in automaticlly");
ChangeValuesFromRepository changeValuesFromRepository1 = new ChangeValuesFromRepository(elem, null, getPropertyTypeName(), EmfComponent.BUILTIN);
changeValuesFromRepository1.execute();
isConnectionChanged = true;
}
}
}
}
use of org.talend.core.model.metadata.builder.connection.DatabaseConnection in project tdi-studio-se by Talend.
the class DynamicComposite method updateRepositoryListExtra.
/**
* for job settings extra (feature 2710).
*
*/
private void updateRepositoryListExtra(IElementParameter param, List<String> repositoryConnectionNameList, List<String> repositoryConnectionValueList, boolean extra) {
String repositoryValue = param.getParentParameter().getRepositoryValue();
if (repositoryValue != null) {
List<String> connectionNamesList = new ArrayList<String>();
List<String> connectionValuesList = new ArrayList<String>();
for (String key : repositoryConnectionItemMap.keySet()) {
ConnectionItem connectionItem = repositoryConnectionItemMap.get(key);
Connection connection = connectionItem.getConnection();
String name = //$NON-NLS-1$
getRepositoryAliasName(connectionItem) + ":" + connectionItem.getProperty().getLabel();
if ((connection instanceof DelimitedFileConnection) && (repositoryValue.equals(ERepositoryCategoryType.DELIMITED.getName()))) {
addOrderDisplayNames(connectionValuesList, connectionNamesList, key, name);
}
if ((connection instanceof PositionalFileConnection) && (repositoryValue.equals(ERepositoryCategoryType.POSITIONAL.getName()))) {
addOrderDisplayNames(connectionValuesList, connectionNamesList, key, name);
}
if ((connection instanceof RegexpFileConnection) && (repositoryValue.equals(ERepositoryCategoryType.REGEX.getName()))) {
addOrderDisplayNames(connectionValuesList, connectionNamesList, key, name);
}
if ((connection instanceof XmlFileConnection) && (repositoryValue.equals(ERepositoryCategoryType.XML.getName()))) {
addOrderDisplayNames(connectionValuesList, connectionNamesList, key, name);
}
if ((connection instanceof FileExcelConnection) && (repositoryValue.equals(ERepositoryCategoryType.EXCEL.getName()))) {
addOrderDisplayNames(connectionValuesList, connectionNamesList, key, name);
}
if ((connection instanceof GenericSchemaConnection) && (repositoryValue.equals(ERepositoryCategoryType.GENERIC.getName()))) {
addOrderDisplayNames(connectionValuesList, connectionNamesList, key, name);
}
if ((connection instanceof LDAPSchemaConnection) && (repositoryValue.equals(ERepositoryCategoryType.LDAP.getName()))) {
addOrderDisplayNames(connectionValuesList, connectionNamesList, key, name);
}
if ((connection instanceof SalesforceSchemaConnection) && (repositoryValue.equals(ERepositoryCategoryType.SALESFORCE.getName()))) {
addOrderDisplayNames(connectionValuesList, connectionNamesList, key, name);
}
if ((connection instanceof WSDLSchemaConnection) && (repositoryValue.equals(ERepositoryCategoryType.WSDL.getName()))) {
addOrderDisplayNames(connectionValuesList, connectionNamesList, key, name);
}
if ((connection instanceof DatabaseConnection) && (repositoryValue.startsWith(ERepositoryCategoryType.DATABASE.getName()))) {
//$NON-NLS-1$
String currentDbType = (String) RepositoryToComponentProperty.getValue(connection, "TYPE", null);
if (repositoryValue.contains(":")) {
// database //$NON-NLS-1$
// is
// specified
// //$NON-NLS-1$
//$NON-NLS-1$
String neededDbType = repositoryValue.substring(repositoryValue.indexOf(":") + 1);
if (neededDbType.equals(currentDbType)) {
addOrderDisplayNames(connectionValuesList, connectionNamesList, key, name);
}
} else {
addOrderDisplayNames(connectionValuesList, connectionNamesList, key, name);
}
}
}
repositoryConnectionNameList.addAll(connectionNamesList);
repositoryConnectionValueList.addAll(connectionValuesList);
} else {
List<String> connectionValuesList = new ArrayList<String>();
List<String> connectionStringList = new ArrayList<String>();
for (String key : repositoryConnectionItemMap.keySet()) {
ConnectionItem connectionItem = repositoryConnectionItemMap.get(key);
String name = connectionItem.getProperty().getLabel();
addOrderDisplayNames(connectionValuesList, connectionStringList, key, name);
}
repositoryConnectionNameList.addAll(connectionStringList);
repositoryConnectionValueList.addAll(connectionValuesList);
}
param.setListItemsDisplayName(repositoryConnectionNameList.toArray(new String[0]));
param.setListItemsValue(repositoryConnectionValueList.toArray(new String[0]));
if (!repositoryConnectionItemMap.keySet().contains(param.getValue())) {
if (repositoryConnectionNameList.size() > 0) {
param.setValue(repositoryConnectionValueList.get(0));
}
}
}
Aggregations