use of org.talend.core.model.metadata.IMetadataConnection in project tdi-studio-se by Talend.
the class ReadQueriesAction method doRun.
@Override
protected void doRun() {
IStructuredSelection selection = (IStructuredSelection) getSelection();
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
if (repositoryNode == null && selection != null) {
repositoryNode = (RepositoryNode) selection.getFirstElement();
}
DatabaseConnectionItem dbConnectionItem = null;
ConnectionParameters connParameters = new ConnectionParameters();
if (repositoryNode.getObjectType() == ERepositoryObjectType.METADATA_CONNECTIONS) {
dbConnectionItem = (DatabaseConnectionItem) repositoryNode.getObject().getProperty().getItem();
connParameters.setRepositoryName(repositoryNode.getObject().getLabel());
connParameters.setRepositoryId(repositoryNode.getObject().getId());
//$NON-NLS-1$
connParameters.setQuery("");
} else if (repositoryNode.getObjectType() == ERepositoryObjectType.METADATA_CON_QUERY) {
QueryRepositoryObject queryRepositoryObject = (QueryRepositoryObject) repositoryNode.getObject();
dbConnectionItem = (DatabaseConnectionItem) queryRepositoryObject.getProperty().getItem();
connParameters.setRepositoryName(dbConnectionItem.getProperty().getLabel());
connParameters.setRepositoryId(dbConnectionItem.getProperty().getId());
connParameters.setQueryObject(queryRepositoryObject.getQuery());
connParameters.setQuery(queryRepositoryObject.getQuery().getValue());
// first open Sql Builder,set true
connParameters.setFirstOpenSqlBuilder(true);
}
Display display = Display.getCurrent();
if (display == null) {
display = Display.getDefault();
}
Shell parentShell = new Shell(display);
TextUtil.setDialogTitle(TextUtil.SQL_BUILDER_TITLE_REP);
Connection connection = dbConnectionItem.getConnection();
String selectedContext = null;
if (connection.isContextMode()) {
ContextItem contextItem = ContextUtils.getContextItemById2(connection.getContextId());
if (contextItem != null && connection.isContextMode()) {
ContextSetsSelectionDialog setsDialog = new ContextSetsSelectionDialog(null, contextItem, false);
setsDialog.open();
selectedContext = setsDialog.getSelectedContext();
}
}
SQLBuilderDialog dial = new SQLBuilderDialog(parentShell, repositoryNode, selectedContext);
dial.setReadOnly(true);
if (connection instanceof DatabaseConnection) {
IMetadataConnection imetadataConnection = ConvertionHelper.convert(connection, true);
connParameters.setSchema(imetadataConnection.getSchema() == null ? "" : imetadataConnection.getSchema());
UIUtils.checkConnection(parentShell, imetadataConnection);
}
connParameters.setNodeReadOnly(true);
connParameters.setFromRepository(true);
dial.setConnParameters(connParameters);
dial.open();
refresh(repositoryNode);
}
use of org.talend.core.model.metadata.IMetadataConnection in project tdi-studio-se by Talend.
the class EditQueriesAction method doRun.
@Override
protected void doRun() {
IStructuredSelection selection = (IStructuredSelection) getSelection();
if (repositoryNode == null && selection != null) {
repositoryNode = (RepositoryNode) selection.getFirstElement();
}
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
IRepositoryViewObject nodeObject = repositoryNode.getObject();
boolean locked = false;
if (!factory.getRepositoryContext().isEditableAsReadOnly()) {
if (nodeObject.getRepositoryStatus() == ERepositoryStatus.LOCK_BY_OTHER) {
locked = true;
}
}
// Avoid to delete node which is locked.
if (locked || RepositoryManager.isOpenedItemInEditor(nodeObject)) {
final String title = "Impossible to edit queries";
String nodeName = nodeObject.getRepositoryObjectType().getLabel();
final String message = "item is already locked by another user.";
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
MessageDialog dialog = new MessageDialog(new Shell(), title, null, message, MessageDialog.ERROR, new String[] { IDialogConstants.OK_LABEL }, 0);
dialog.open();
}
});
return;
}
DatabaseConnectionItem dbConnectionItem = null;
boolean readOnly = false;
ConnectionParameters connParameters = new ConnectionParameters();
if (repositoryNode.getObjectType() == ERepositoryObjectType.METADATA_CONNECTIONS) {
dbConnectionItem = (DatabaseConnectionItem) repositoryNode.getObject().getProperty().getItem();
connParameters.setRepositoryName(repositoryNode.getObject().getLabel());
connParameters.setRepositoryId(repositoryNode.getObject().getId());
//$NON-NLS-1$
connParameters.setQuery("");
} else if (repositoryNode.getObjectType() == ERepositoryObjectType.METADATA_CON_QUERY) {
QueryRepositoryObject queryRepositoryObject = (QueryRepositoryObject) repositoryNode.getObject();
readOnly = SubItemHelper.isDeleted(queryRepositoryObject.getAbstractMetadataObject());
dbConnectionItem = (DatabaseConnectionItem) queryRepositoryObject.getProperty().getItem();
connParameters.setRepositoryName(dbConnectionItem.getProperty().getLabel());
connParameters.setRepositoryId(dbConnectionItem.getProperty().getId());
connParameters.setQueryObject(queryRepositoryObject.getQuery());
connParameters.setQuery(queryRepositoryObject.getQuery().getValue());
// first open Sql Builder,set true
connParameters.setFirstOpenSqlBuilder(true);
} else if (repositoryNode.getObjectType() == ERepositoryObjectType.METADATA_CON_TABLE) {
dbConnectionItem = (DatabaseConnectionItem) repositoryNode.getObject().getProperty().getItem();
connParameters.setRepositoryName(dbConnectionItem.getProperty().getLabel());
connParameters.setRepositoryId(dbConnectionItem.getProperty().getId());
connParameters.setMetadataTable((MetadataTableRepositoryObject) repositoryNode.getObject());
//$NON-NLS-1$
connParameters.setQuery("");
}
IRepositoryView viewPart = getViewPart();
Display display = null;
if (viewPart != null) {
display = viewPart.getViewer().getControl().getDisplay();
} else {
display = Display.getCurrent();
if (display == null) {
display = Display.getDefault();
}
}
Shell parentShell = new Shell(display);
TextUtil.setDialogTitle(TextUtil.SQL_BUILDER_TITLE_REP);
Connection connection = dbConnectionItem.getConnection();
String selectedContext = null;
if (connection.isContextMode()) {
ContextItem contextItem = ContextUtils.getContextItemById2(connection.getContextId());
if (contextItem != null && connection.isContextMode()) {
ContextSetsSelectionDialog setsDialog = new ContextSetsSelectionDialog(null, contextItem, false);
setsDialog.open();
selectedContext = setsDialog.getSelectedContext();
}
}
SQLBuilderDialog dial = new SQLBuilderDialog(parentShell, repositoryNode, selectedContext);
dial.setReadOnly(readOnly);
if (connection instanceof DatabaseConnection) {
IMetadataConnection imetadataConnection = ConvertionHelper.convert(connection, true);
connParameters.setSchema(imetadataConnection.getSchema() == null ? "" : imetadataConnection.getSchema());
UIUtils.checkConnection(parentShell, imetadataConnection);
}
connParameters.setNodeReadOnly(readOnly);
connParameters.setFromRepository(true);
dial.setConnParameters(connParameters);
dial.open();
IRepositoryView view = getViewPart();
if (view != null) {
view.refreshView();
}
}
use of org.talend.core.model.metadata.IMetadataConnection in project tdi-studio-se by Talend.
the class SQLBuilderService method openSQLBuilderDialog.
public Dialog openSQLBuilderDialog(Shell parentShell, String processName, ConnectionParameters connParameters) {
SQLBuilderDialog sqlBuilder = new SQLBuilderDialog(parentShell);
UIUtils.addSqlBuilderDialog(processName, sqlBuilder);
sqlBuilder.setConnParameters(connParameters);
// display a error message if the db connection is failed.
if (connParameters != null) {
DatabaseConnection connection = createConnection(connParameters);
if (connection != null) {
IMetadataConnection metadataConnection = ConvertionHelper.convert(connection);
UIUtils.checkConnection(parentShell, metadataConnection);
}
}
return sqlBuilder;
}
use of org.talend.core.model.metadata.IMetadataConnection in project tdi-studio-se by Talend.
the class GuessSchemaController method runShadowProcessForPerl.
private void runShadowProcessForPerl() {
final ProgressMonitorDialog pmd = new ProgressMonitorDialog(this.composite.getShell());
try {
pmd.run(true, true, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
if (columns != null) {
columns.clear();
}
//$NON-NLS-1$
monitor.beginTask(Messages.getString("GuessSchemaController.waitOpenDatabase"), IProgressMonitor.UNKNOWN);
if (connParameters == null) {
initConnectionParameters();
}
ISQLBuilderService service = (ISQLBuilderService) GlobalServiceRegister.getDefault().getService(ISQLBuilderService.class);
DatabaseConnection connt = service.createConnection(connParameters);
IMetadataConnection iMetadataConnection = null;
boolean isStatus = false;
ExtractMetaDataUtils extractMeta = ExtractMetaDataUtils.getInstance();
if (connt != null) {
iMetadataConnection = ConvertionHelper.convert(connt);
isStatus = checkConnection(iMetadataConnection);
}
if (!monitor.isCanceled()) {
try {
if (isStatus) {
extractMeta.getConnection(iMetadataConnection.getDbType(), iMetadataConnection.getUrl(), iMetadataConnection.getUsername(), iMetadataConnection.getPassword(), iMetadataConnection.getDatabase(), iMetadataConnection.getSchema(), iMetadataConnection.getDriverClass(), iMetadataConnection.getDriverJarPath(), iMetadataConnection.getDbVersionString(), iMetadataConnection.getAdditionalParams());
if (extractMeta.getConn() != null) {
Statement smst = extractMeta.getConn().createStatement();
extractMeta.setQueryStatementTimeout(smst);
ResultSet rs = smst.executeQuery(memoSQL);
ResultSetMetaData rsmd = rs.getMetaData();
int numbOfColumn = rsmd.getColumnCount();
int count = 0;
List<String[]> cvsArrays = new ArrayList<String[]>();
while (rs.next() && count < 50) {
String[] dataOneRow = new String[numbOfColumn];
for (int i = 1; i <= numbOfColumn; i++) {
String tempStr = rs.getString(i);
dataOneRow[i - 1] = tempStr;
}
cvsArrays.add(dataOneRow);
count++;
}
refreshMetaDataTable(rsmd, cvsArrays);
extractMeta.closeConnection();
}
} 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(composite.getShell(), part.getProcess().getContextManager());
}
}
});
}
} catch (Exception e) {
extractMeta.closeConnection();
ExceptionHandler.process(e);
final String strExcepton = "Connect to DB error ,or some errors in SQL query string, or 'Guess Schema' not compatible with current SQL query string." + System.getProperty("line.separator");
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
MessageDialog.openWarning(composite.getShell(), Messages.getString("GuessSchemaController.connError"), //$NON-NLS-1$
strExcepton);
}
});
}
}
}
});
} catch (Exception e) {
ExceptionHandler.process(e);
}
}
use of org.talend.core.model.metadata.IMetadataConnection 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