use of org.talend.core.ui.metadata.dialog.DbTableSelectorObject in project tdi-studio-se by Talend.
the class DbTableController method openDbTableSelectorJob.
/**
* qzhang Comment method "openDbTableSelectorJob".
*
* @param openListTable
*/
private void openDbTableSelectorJob(final Button openListTable) {
Job job = new //$NON-NLS-1$
Job(//$NON-NLS-1$
Messages.getString("DbTableController.openSelectionDialog")) {
@Override
protected IStatus run(final IProgressMonitor monitor) {
//$NON-NLS-1$
monitor.beginTask(Messages.getString("DbTableController.waitingForOpen"), IProgressMonitor.UNKNOWN);
DatabaseConnection existConnection = getExistConnection();
if (existConnection == null) {
if (connParameters == null) {
initConnectionParameters();
}
existConnection = TracesConnectionUtils.createConnection(connParameters);
}
final DatabaseConnection con = existConnection;
IMetadataConnection iMetadataConnection = null;
final IMetadataConnection[] iMetadata = new IMetadataConnection[1];
boolean isStatus = false;
if (existConnection != null) {
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
IMetadataConnection convert = ConvertionHelper.convert(con);
iMetadata[0] = convert;
}
});
iMetadataConnection = iMetadata[0];
// Added by Marvin Wang for bug TDI-24288.
if (EDatabaseTypeName.HIVE.getProduct().equalsIgnoreCase(con.getDatabaseType())) {
if (EDatabaseVersion4Drivers.HIVE_EMBEDDED.getVersionValue().equalsIgnoreCase(con.getDbVersionString())) {
try {
HiveConnectionManager.getInstance().checkConnection(iMetadataConnection);
isStatus = true;
} catch (ClassNotFoundException e) {
isStatus = false;
ExceptionHandler.process(e);
} catch (InstantiationException e) {
isStatus = false;
ExceptionHandler.process(e);
} catch (IllegalAccessException e) {
isStatus = false;
ExceptionHandler.process(e);
} catch (SQLException e) {
isStatus = false;
ExceptionHandler.process(e);
}
}
} else {
isStatus = checkConnection(iMetadataConnection);
}
}
String type = null;
if (iMetadataConnection != null) {
type = iMetadataConnection.getDbType();
}
final String dbType = type;
if (!monitor.isCanceled()) {
try {
if (isStatus) {
// Added by Marvin Wang for bug TDI-24288.
if (EDatabaseTypeName.HIVE.getProduct().equalsIgnoreCase(con.getDatabaseType())) {
if (EDatabaseVersion4Drivers.HIVE_EMBEDDED.getVersionValue().equalsIgnoreCase(con.getDbVersionString())) {
JavaSqlFactory.doHivePreSetup((DatabaseConnection) iMetadataConnection.getCurrentConnection());
returnTablesFormConnection = ExtractMetaDataFromDataBase.fetchAllTablesForHiveEmbeddedModel(iMetadataConnection);
JavaSqlFactory.doHiveConfigurationClear();
}
} else {
returnTablesFormConnection = ExtractMetaDataFromDataBase.returnTablesFormConnection(iMetadataConnection);
}
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
final DbTableSelectorObject object = new DbTableSelectorObject();
DbTableSelectorObject connO = new DbTableSelectorObject();
if (dbType != null && dbType.equals(EDatabaseTypeName.ORACLE_OCI.getDisplayName())) {
connO.setLabel(connParameters.getLocalServiceName());
} else if ("".equals(connParameters.getDbName())) {
//$NON-NLS-1$
connO.setLabel(connParameters.getDatasource());
} else {
connO.setLabel(connParameters.getDbName());
}
// ...
if (connO.getLabel() == null || connO.getLabel().equals("")) {
//$NON-NLS-1$
if (elem instanceof INode) {
connO.setLabel(elem.getElementName());
} else {
connO.setLabel("tJDBCConnection");
}
}
connO.setType(ObjectType.DB);
if (monitor.isCanceled()) {
monitor.done();
return;
}
for (String string : returnTablesFormConnection) {
DbTableSelectorObject tableO = new DbTableSelectorObject();
tableO.setLabel(string);
tableO.setType(ObjectType.TABLE);
connO.addChildren(tableO);
}
object.addChildren(connO);
String propertyName = (String) openListTable.getData(PARAMETER_NAME);
DbTableSelectorDialog selectorDialog = new DbTableSelectorDialog(composite.getShell(), object);
if (selectorDialog.open() == DbTableSelectorDialog.OK) {
String name = selectorDialog.getSelectName();
if (name != null) {
Command dbSelectorCommand = new PropertyChangeCommand(elem, propertyName, TalendTextUtils.addQuotes(name));
executeCommand(dbSelectorCommand);
Text labelText = (Text) hashCurControls.get(propertyName);
labelText.setText(TalendTextUtils.addQuotes(name));
}
}
}
});
} else {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
//$NON-NLS-1$
String pid = "org.talend.sqlbuilder";
//$NON-NLS-1$
String mainMsg = "Database connection is failed. ";
ErrorDialogWithDetailAreaAndContinueButton dialog = new ErrorDialogWithDetailAreaAndContinueButton(composite.getShell(), pid, mainMsg, connParameters.getConnectionComment());
if (dialog.getCodeOfButton() == Window.OK) {
openParamemerDialog(openListTable, part.getProcess().getContextManager());
}
}
});
}
} catch (SQLException e) {
// Added by Marvin Wang for bug TDI-24288.
JavaSqlFactory.doHiveConfigurationClear();
ExceptionHandler.process(e);
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
MessageDialog.openError(openListTable.getShell(), //$NON-NLS-1$
Messages.getString("DbTableController.dialog.title"), //$NON-NLS-1$
Messages.getString("DbTableController.dialog.contents.fetchTableFailed"));
}
});
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
monitor.done();
return Status.OK_STATUS;
}
};
if (part != null) {
IWorkbenchSiteProgressService siteps = (IWorkbenchSiteProgressService) part.getSite().getAdapter(IWorkbenchSiteProgressService.class);
siteps.showInDialog(composite.getShell(), job);
} else {
PlatformUI.getWorkbench().getProgressService().showInDialog(composite.getShell(), job);
}
job.setUser(true);
job.schedule();
}
Aggregations