Search in sources :

Example 6 with ISQLBuilderService

use of org.talend.core.ui.services.ISQLBuilderService in project tdi-studio-se by Talend.

the class AbstractElementPropertySectionController method openSqlBuilderBuildIn.

public void openSqlBuilderBuildIn(final ConnectionParameters connParameters, final String propertyName) {
    ISQLBuilderService service = (ISQLBuilderService) GlobalServiceRegister.getDefault().getService(ISQLBuilderService.class);
    service.openSQLBuilderDialog(connParameters, composite, elem, propertyName, getCommandStack(), this, part);
}
Also used : ISQLBuilderService(org.talend.core.ui.services.ISQLBuilderService)

Example 7 with ISQLBuilderService

use of org.talend.core.ui.services.ISQLBuilderService 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);
    }
}
Also used : ErrorDialogWithDetailAreaAndContinueButton(org.talend.commons.ui.swt.dialogs.ErrorDialogWithDetailAreaAndContinueButton) Statement(java.sql.Statement) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) ExtractMetaDataUtils(org.talend.core.model.metadata.builder.database.ExtractMetaDataUtils) InvocationTargetException(java.lang.reflect.InvocationTargetException) ISQLBuilderService(org.talend.core.ui.services.ISQLBuilderService) InvocationTargetException(java.lang.reflect.InvocationTargetException) SQLException(java.sql.SQLException) ProcessorException(org.talend.designer.runprocess.ProcessorException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ResultSetMetaData(java.sql.ResultSetMetaData) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ResultSet(java.sql.ResultSet) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) List(java.util.List) ArrayList(java.util.ArrayList)

Example 8 with ISQLBuilderService

use of org.talend.core.ui.services.ISQLBuilderService in project tdi-studio-se by Talend.

the class SqlMemoController method refreshConnectionCommand.

private Command refreshConnectionCommand() {
    // open sql builder in repository mode, just use query object, no need for connection information
    ConnectionParameters connParameters = new ConnectionParameters();
    String queryId = (String) elem.getPropertyValue(EParameterName.REPOSITORY_QUERYSTORE_TYPE.getName());
    Query query = MetadataToolHelper.getQueryFromRepository(queryId);
    DatabaseConnectionItem item = findRepositoryItem(queryId);
    if (item != null) {
        connParameters.setRepositoryName(item.getProperty().getLabel());
        connParameters.setRepositoryId(item.getProperty().getId());
    }
    connParameters.setQueryObject(query);
    connParameters.setQuery(query.getValue());
    TextUtil.setDialogTitle(TextUtil.SQL_BUILDER_TITLE_REP);
    String processName = null;
    if (elem instanceof IProcess) {
        processName = ((IProcess) elem).getName();
    } else if (elem instanceof INode) {
        processName = ((INode) elem).getProcess().getName();
    } else if (elem instanceof IConnection) {
        processName = ((IConnection) elem).getSource().getProcess().getName();
    }
    connParameters.setNodeReadOnly(false);
    connParameters.setFromRepository(true);
    ISQLBuilderService sqlBuilderService = (ISQLBuilderService) GlobalServiceRegister.getDefault().getService(ISQLBuilderService.class);
    Dialog sqlBuilder = sqlBuilderService.openSQLBuilderDialog(composite.getShell(), processName, connParameters);
    String sql = null;
    if (Window.OK == sqlBuilder.open()) {
        sql = connParameters.getQuery();
    }
    if (sql != null && !queryText.isDisposed()) {
        queryText.setText(sql);
        String propertyName = (String) openSQLEditorButton.getData(PARAMETER_NAME);
        return new PropertyChangeCommand(elem, propertyName, sql);
    }
    return null;
}
Also used : INode(org.talend.core.model.process.INode) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) Query(org.talend.core.model.metadata.builder.connection.Query) ModelSelectionDialog(org.talend.commons.ui.swt.dialogs.ModelSelectionDialog) Dialog(org.eclipse.jface.dialogs.Dialog) ConnectionParameters(org.talend.core.sqlbuilder.util.ConnectionParameters) IConnection(org.talend.core.model.process.IConnection) IProcess(org.talend.core.model.process.IProcess) ISQLBuilderService(org.talend.core.ui.services.ISQLBuilderService) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem)

Aggregations

ISQLBuilderService (org.talend.core.ui.services.ISQLBuilderService)8 IMetadataConnection (org.talend.core.model.metadata.IMetadataConnection)3 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)3 IProcess (org.talend.core.model.process.IProcess)3 Dialog (org.eclipse.jface.dialogs.Dialog)2 ErrorDialogWithDetailAreaAndContinueButton (org.talend.commons.ui.swt.dialogs.ErrorDialogWithDetailAreaAndContinueButton)2 ModelSelectionDialog (org.talend.commons.ui.swt.dialogs.ModelSelectionDialog)2 INode (org.talend.core.model.process.INode)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ResultSet (java.sql.ResultSet)1 ResultSetMetaData (java.sql.ResultSetMetaData)1 SQLException (java.sql.SQLException)1 Statement (java.sql.Statement)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 EditPart (org.eclipse.gef.EditPart)1 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)1 AbstractGraphicalEditPart (org.eclipse.gef.editparts.AbstractGraphicalEditPart)1 MessageDialog (org.eclipse.jface.dialogs.MessageDialog)1