Search in sources :

Example 16 with DbmsLanguage

use of org.talend.dq.dbms.DbmsLanguage in project tdq-studio-se by Talend.

the class AnalysisExecutorHelperTest method testGetTableName_4.

/**
 * try the db2 db type. Test method for
 * {@link org.talend.dq.helper.AnalysisExecutorHelper#getTableName(orgomg.cwm.objectmodel.core.ModelElement, org.talend.dq.dbms.DbmsLanguage)}
 * .
 */
@Test
public void testGetTableName_4() {
    TdColumn tdColumn = RelationalFactory.eINSTANCE.createTdColumn();
    TdTable tdTable = RelationalFactory.eINSTANCE.createTdTable();
    // $NON-NLS-1$
    tdTable.setName("tableName");
    tdColumn.setOwner(tdTable);
    // $NON-NLS-1$
    tdColumn.setName("columnName");
    DbmsLanguage dbmsLanguage = DbmsLanguageFactory.createDbmsLanguage(SupportDBUrlType.DB2DEFAULTURL.getLanguage(), null);
    // mock(Catalog.class);
    Package catalog = orgomg.cwm.resource.relational.RelationalFactory.eINSTANCE.createCatalog();
    // $NON-NLS-1$
    catalog.setName("catalogName");
    tdTable.setNamespace(catalog);
    // $NON-NLS-1$
    assertEquals("catalogName.tableName", AnalysisExecutorHelper.getTableName(tdColumn, dbmsLanguage));
}
Also used : DbmsLanguage(org.talend.dq.dbms.DbmsLanguage) TdColumn(org.talend.cwm.relational.TdColumn) TdTable(org.talend.cwm.relational.TdTable) Package(orgomg.cwm.objectmodel.core.Package) Test(org.junit.Test)

Example 17 with DbmsLanguage

use of org.talend.dq.dbms.DbmsLanguage in project tdq-studio-se by Talend.

the class AnalysisExecutorHelperTest method testGetTableName_1.

/**
 * try the MSSQL db type. Test method for
 * {@link org.talend.dq.helper.AnalysisExecutorHelper#getTableName(orgomg.cwm.objectmodel.core.ModelElement, org.talend.dq.dbms.DbmsLanguage)}
 * .
 */
@Test
public void testGetTableName_1() {
    TdColumn tdColumn = RelationalFactory.eINSTANCE.createTdColumn();
    TdTable tdTable = RelationalFactory.eINSTANCE.createTdTable();
    // $NON-NLS-1$
    tdTable.setName("tableName");
    tdColumn.setOwner(tdTable);
    // $NON-NLS-1$
    tdColumn.setName("columnName");
    DbmsLanguage dbmsLanguage = DbmsLanguageFactory.createDbmsLanguage(SupportDBUrlType.MSSQLDEFAULTURL.getLanguage(), null);
    // mock(Schema.class);
    Package schema = orgomg.cwm.resource.relational.RelationalFactory.eINSTANCE.createSchema();
    // $NON-NLS-1$
    schema.setName("schemaName");
    tdTable.setNamespace(schema);
    // mock(Catalog.class);
    Package catalog = orgomg.cwm.resource.relational.RelationalFactory.eINSTANCE.createCatalog();
    // $NON-NLS-1$
    catalog.setName("catalogName");
    schema.setNamespace(catalog);
    // $NON-NLS-1$
    assertEquals("catalogName.schemaName.tableName", AnalysisExecutorHelper.getTableName(tdColumn, dbmsLanguage));
}
Also used : DbmsLanguage(org.talend.dq.dbms.DbmsLanguage) TdColumn(org.talend.cwm.relational.TdColumn) TdTable(org.talend.cwm.relational.TdTable) Package(orgomg.cwm.objectmodel.core.Package) Test(org.junit.Test)

Example 18 with DbmsLanguage

use of org.talend.dq.dbms.DbmsLanguage in project tdq-studio-se by Talend.

the class PatternTestView method openSQLEditor.

/**
 * DOC rli Comment method "openSQLEditor".
 */
private void openSQLEditor() {
    DbmsLanguage dbmsLanguage = this.getDbmsLanguage();
    if (dbmsLanguage != null) {
        // MOD gdbu 2011-6-13 bug : 19119
        dbmsLanguage.setRegularExpressionFunction(getFunctionName());
        // ~19119
        String selectRegexpTestString = dbmsLanguage.getSelectRegexpTestString(testText.getText(), regularText.getText());
        // MOD sizhaoliu TDQ-5237 changed the way to open SQL Explorer for Pattern Test View
        SqlExplorerUtils.getDefault().runInDQViewer(getDBConnectionFromDBName(dbCombo.getText()), selectRegexpTestString, SqlExplorerUtils.SQLEDITOR_ID);
    } else {
        // $NON-NLS-1$
        MessageDialog.openWarning(new Shell(), "", NO_DATABASE_SELECTEDED);
    }
}
Also used : DbmsLanguage(org.talend.dq.dbms.DbmsLanguage) Shell(org.eclipse.swt.widgets.Shell)

Example 19 with DbmsLanguage

use of org.talend.dq.dbms.DbmsLanguage in project tdq-studio-se by Talend.

the class PatternTestView method createPatternTestCom.

protected void createPatternTestCom(final Composite parent) {
    ScrolledComposite scrolledComposite = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL);
    scrolledComposite.setExpandHorizontal(true);
    scrolledComposite.setExpandVertical(true);
    final Composite mainComposite = new Composite(scrolledComposite, SWT.NULL);
    scrolledComposite.setContent(mainComposite);
    GridLayout blay = new GridLayout();
    mainComposite.setLayout(blay);
    // create coboCom line
    final Composite coboCom = new Composite(mainComposite, SWT.NULL);
    imgCom = new Composite(mainComposite, SWT.NONE);
    final Composite textCom = new Composite(mainComposite, SWT.NULL);
    final Composite buttonsCom = new Composite(mainComposite, SWT.FILL | SWT.NULL);
    mainComposite.addListener(SWT.Resize, new Listener() {

        public void handleEvent(Event event) {
            GridData formData = new GridData(GridData.FILL_HORIZONTAL);
            formData.heightHint = 105;
            textCom.setLayoutData(formData);
            buttonsCom.setLayoutData(formData);
        }
    });
    // ~
    // set cobo com layout
    GridLayout layout = new GridLayout();
    layout.numColumns = 3;
    coboCom.setLayout(layout);
    GridData data = new GridData(GridData.FILL_BOTH);
    // MOD qiongli feature 16799: Add java in Pattern Test View
    buttonJava = new Button(coboCom, SWT.RADIO);
    buttonJava.setText(ExecutionLanguage.JAVA.getLiteral());
    data = new GridData(GridData.BEGINNING, GridData.BEGINNING, false, false);
    buttonJava.setLayoutData(data);
    buttonJava.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            isJavaEngine = true;
            sqlButton.setEnabled(false);
            dbCombo.setEnabled(false);
            functionNameText.setEnabled(false);
        }
    });
    buttonSql = new Button(coboCom, SWT.RADIO);
    data = new GridData(GridData.BEGINNING, GridData.BEGINNING, false, false);
    // $NON-NLS-1$
    buttonSql.setText(DefaultMessagesImpl.getString("PatternTestView.Connections"));
    buttonSql.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            isJavaEngine = false;
            sqlButton.setEnabled(true);
            dbCombo.setEnabled(true);
            functionNameText.setEnabled(true);
        }
    });
    buttonSql.setSelection(true);
    buttonSql.setEnabled(!isJavaEngine);
    buttonSql.setLayoutData(data);
    dbCombo = new CCombo(coboCom, SWT.DROP_DOWN | SWT.BORDER);
    dbCombo.setEditable(false);
    data = new GridData(GridData.FILL, GridData.BEGINNING, false, false);
    dbCombo.setLayoutData(data);
    // MOD gdbu 2011-5-31 bug : 19119
    Label dummyLabel = new Label(coboCom, SWT.NONE);
    dummyLabel.setLayoutData(new GridData(GridData.BEGINNING, GridData.BEGINNING, false, false));
    functionLabel = new Label(coboCom, SWT.NONE);
    // $NON-NLS-1$
    functionLabel.setText(DefaultMessagesImpl.getString("PatternTestView.FunctionName"));
    functionNameText = new Text(coboCom, SWT.BORDER);
    functionNameText.setText(PluginConstant.EMPTY_STRING);
    GridData functionNameTextGD = new GridData(GridData.BEGINNING, GridData.BEGINNING, false, false);
    data = new GridData(GridData.FILL, GridData.BEGINNING, false, false);
    functionNameText.setLayoutData(data);
    functionLabel.setLayoutData(functionNameTextGD);
    functionNameText.setVisible(false);
    functionLabel.setVisible(false);
    // ~19119
    GridData comData = new GridData(GridData.FILL_HORIZONTAL);
    comData.heightHint = 50;
    coboCom.setLayoutData(comData);
    // create image com
    layout = new GridLayout();
    layout.numColumns = 2;
    imgCom.setLayout(layout);
    emoticonLabel = new Label(imgCom, SWT.NONE);
    GridData gd = new GridData();
    gd.heightHint = 18;
    gd.widthHint = 18;
    emoticonLabel.setLayoutData(gd);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.heightHint = 18;
    // gd.widthHint = 65;
    // MOD TDQ-4599,mzhao, don't truncate the label.
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = GridData.FILL;
    resultLabel = new Label(imgCom, SWT.NONE);
    resultLabel.setLayoutData(gd);
    GridData imgData = new GridData(GridData.FILL_HORIZONTAL);
    // imgData.heightHint = 0;
    imgData.horizontalAlignment = GridData.FILL;
    imgData.grabExcessHorizontalSpace = true;
    imgCom.setLayoutData(imgData);
    // ~
    // create text com
    layout = new GridLayout();
    layout.numColumns = 2;
    textCom.setLayout(layout);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalAlignment = GridData.BEGINNING;
    // MOD gdbu 2011-5-31 bug : 19119
    textAreaLabel = new Label(textCom, SWT.NONE);
    // $NON-NLS-1$
    textAreaLabel.setText(DefaultMessagesImpl.getString("PatternTestView.area"));
    testText = AutoScrollBarTextFactory.getDefault().createText(textCom, SWT.BORDER | SWT.MULTI | SWT.WRAP);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.heightHint = 40;
    testText.setLayoutData(data);
    // $NON-NLS-1$
    testText.setToolTipText(DefaultMessagesImpl.getString("PatternTestView.enterHere"));
    GridData textAreaLabelGD = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    // textAreaLabelGD.widthHint = 180;
    textAreaLabel.setLayoutData(textAreaLabelGD);
    regularLabel = new Label(textCom, SWT.WRAP);
    // $NON-NLS-1$
    regularLabel.setText(DefaultMessagesImpl.getString("PatternTestView.regularExpressionParameter"));
    // $NON-NLS-1$
    regularLabel.setToolTipText(DefaultMessagesImpl.getString("PatternTestView.regularExpressionParameter"));
    GridData regularLabelGD = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    regularLabelGD.heightHint = 40;
    regularLabelGD.widthHint = 70;
    // regularLabelGD.widthHint = 260;
    regularLabel.setLayoutData(regularLabelGD);
    // ~19119
    this.regularText = AutoScrollBarTextFactory.getDefault().createText(textCom, SWT.BORDER | SWT.MULTI | SWT.WRAP);
    this.regularText.setLayoutData(data);
    // $NON-NLS-1$
    regularText.setToolTipText(DefaultMessagesImpl.getString("PatternTestView.enterHereAgainst"));
    regularText.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            boolean enabled = (!regularText.getText().equals(PluginConstant.EMPTY_STRING)) && (CheckValueUtils.isPatternValue(regularText.getText()));
            if (pattern != null) {
                saveButton.setEnabled(enabled);
            }
            createPatternButton.setEnabled(enabled);
        }
    });
    GridData textData = new GridData(GridData.FILL_BOTH);
    textData.heightHint = 400;
    textCom.setLayoutData(textData);
    // ~~~~~~
    GridLayout llayout = new GridLayout();
    llayout.numColumns = 4;
    buttonsCom.setLayout(llayout);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.heightHint = 25;
    data.widthHint = 92;
    sqlButton = new Button(buttonsCom, SWT.PUSH);
    // $NON-NLS-1$
    sqlButton.setText(DefaultMessagesImpl.getString("PatternTestView.SQL"));
    // $NON-NLS-1$
    sqlButton.setToolTipText(DefaultMessagesImpl.getString("PatternTestView.generatedSQLStatement"));
    sqlButton.setLayoutData(data);
    sqlButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            openSQLEditor();
        }
    });
    createPatternButton = new Button(buttonsCom, SWT.PUSH);
    // $NON-NLS-1$
    createPatternButton.setText(DefaultMessagesImpl.getString("PatternTestView.createPattern"));
    // $NON-NLS-1$
    createPatternButton.setToolTipText(DefaultMessagesImpl.getString("PatternTestView.CreateNewPattern"));
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.heightHint = 25;
    data.widthHint = 92;
    createPatternButton.setLayoutData(data);
    createPatternButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            String language = null;
            if (regularExpression != null) {
                language = regularExpression.getExpression().getLanguage();
            } else {
                DbmsLanguage dbmsLanguage = getDbmsLanguage();
                // MOD gdbu 2011-5-13 bug : 19119
                if (dbmsLanguage != null) {
                    dbmsLanguage.setRegularExpressionFunction(getFunctionName());
                    language = dbmsLanguage.getDbmsName();
                } else {
                    // ADD msjian 2012-2-10 TDQ-4600: fix set the default language is "Java"
                    language = SupportDBUrlType.JAVADEFAULTURL.getDBKey();
                // TDQ-4600~
                }
            // ~19119
            }
            // MOD mzhao 2009-03-13 Feature 6066 Move all folders into one
            // project.
            // MOD mzhao TDQ-4734 set relative customer pattern folder, same level to the pattern to be replicated.
            IFolder customizedPattFolder = ResourceManager.getPatternRegexFolder();
            if (pattern != null && pattern.eResource() != null) {
                IContainer oriPattContainer = WorkspaceUtils.getModelElementResource(pattern).getParent();
                if (oriPattContainer instanceof IFolder) {
                    customizedPattFolder = (IFolder) oriPattContainer;
                }
            }
            new CreatePatternAction(customizedPattFolder, ExpressionType.REGEXP, regularText.getText(), language).run();
        }
    });
    createPatternButton.setEnabled(false);
    saveButton = new Button(buttonsCom, SWT.PUSH);
    // $NON-NLS-1$
    saveButton.setText(DefaultMessagesImpl.getString("PatternTestView.Save"));
    saveButton.setEnabled(false);
    // $NON-NLS-1$
    saveButton.setToolTipText(DefaultMessagesImpl.getString("PatternTestView.SaveRegularExpression"));
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.heightHint = 25;
    data.widthHint = 92;
    saveButton.setLayoutData(data);
    saveButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            savePattern();
        }
    });
    testButton = new Button(buttonsCom, SWT.PUSH);
    data = new GridData(GridData.FILL_HORIZONTAL);
    testButton.setLayoutData(data);
    // $NON-NLS-1$
    testButton.setText(DefaultMessagesImpl.getString("PatternTestView.test"));
    // $NON-NLS-1$
    testButton.setToolTipText(DefaultMessagesImpl.getString("PatternTestView.ValidateEnteredString"));
    testButton.setLayoutData(data);
    testButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            testRegularText();
        }
    });
    // MOD gdbu TDQ-4153 2011-12-19 Initialize the position error of composite.
    expandImageComposite();
    // ~TDQ-4153
    data = new GridData(GridData.FILL_HORIZONTAL);
    buttonsCom.setLayoutData(data);
    scrolledComposite.setMinSize(mainComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
    mainComposite.layout();
    activateContext();
    // MOD gdbu 2011-5-31 bug : 19119
    fillComboData();
// ~19119
}
Also used : SelectionListener(org.eclipse.swt.events.SelectionListener) Listener(org.eclipse.swt.widgets.Listener) ModifyListener(org.eclipse.swt.events.ModifyListener) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ModifyListener(org.eclipse.swt.events.ModifyListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) DbmsLanguage(org.talend.dq.dbms.DbmsLanguage) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) CCombo(org.eclipse.swt.custom.CCombo) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IContainer(org.eclipse.core.resources.IContainer) CreatePatternAction(org.talend.dataprofiler.core.pattern.actions.CreatePatternAction) IFolder(org.eclipse.core.resources.IFolder)

Example 20 with DbmsLanguage

use of org.talend.dq.dbms.DbmsLanguage in project tdq-studio-se by Talend.

the class PatternTestView method savePattern.

/**
 * If the pattern is not null, will save it and update the corresponding pattern editor content.
 */
private void savePattern() {
    // If the pattern is not null, will update the pattern editor content.
    if (pattern != null) {
        String expressionLanguage = this.regularExpression.getExpression().getLanguage();
        DbmsLanguage dbmsLanguage = this.getDbmsLanguage();
        // MOD gdbu 2011-6-13 bug : 21695
        if (null != dbmsLanguage) {
            dbmsLanguage.setRegularExpressionFunction(getFunctionName());
        }
        // ~21695
        // ~19119
        // MOD qiongli 2011-1-7 featrue 16799.
        boolean isLanguageMatched = false;
        if (isJavaEngine && expressionLanguage.equals(ExecutionLanguage.JAVA.getLiteral()) || dbmsLanguage != null && (dbmsLanguage.getDbmsName().equalsIgnoreCase(expressionLanguage))) {
            isLanguageMatched = true;
        }
        if (!isLanguageMatched) {
            String messageInfo = DefaultMessagesImpl.getString("PatternTestView.modifiedTheRegularExpression", expressionLanguage, dbmsLanguage.getDbmsName(), expressionLanguage, expressionLanguage, // $NON-NLS-1$
            dbmsLanguage.getDbmsName());
            MessageDialog messageDialog = new MessageDialog(new Shell(), // $NON-NLS-1$
            DefaultMessagesImpl.getString("PatternTestView.warning"), // $NON-NLS-1$
            null, // $NON-NLS-1$
            messageInfo, // $NON-NLS-1$
            MessageDialog.WARNING, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0);
            int result = messageDialog.open();
            if (result == MessageDialog.OK) {
                regularExpression.getExpression().setBody(regularText.getText());
            } else {
                EList<PatternComponent> components = this.pattern.getComponents();
                boolean isContainLanguage = false;
                for (int i = 0; i < components.size(); i++) {
                    RegularExpressionImpl regularExpress = (RegularExpressionImpl) components.get(i);
                    // expression
                    if (dbmsLanguage.getDbmsName().equalsIgnoreCase(regularExpress.getExpression().getLanguage())) {
                        regularExpress.getExpression().setBody(regularText.getText());
                        isContainLanguage = true;
                        break;
                    }
                }
                // expression.
                if (!isContainLanguage) {
                    RegularExpression newRegularExpress = BooleanExpressionHelper.createRegularExpression(dbmsLanguage.getDbmsName(), regularText.getText());
                    this.pattern.getComponents().add(newRegularExpress);
                }
            }
        } else {
            regularExpression.getExpression().setBody(regularText.getText());
        }
        EMFUtil.saveSingleResource(pattern.eResource());
        editorPage.updatePatternDefinitonSection();
        // MessageDialog.openInformation(new Shell(), "Success",
        // "Success to save the pattern '" +
        // pattern.getName()
        // + "'");
        saveButton.setEnabled(false);
    }
}
Also used : DbmsLanguage(org.talend.dq.dbms.DbmsLanguage) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) Shell(org.eclipse.swt.widgets.Shell) RegularExpressionImpl(org.talend.dataquality.domain.pattern.impl.RegularExpressionImpl) PatternComponent(org.talend.dataquality.domain.pattern.PatternComponent) MessageDialog(org.eclipse.jface.dialogs.MessageDialog)

Aggregations

DbmsLanguage (org.talend.dq.dbms.DbmsLanguage)29 Test (org.junit.Test)10 Connection (org.talend.core.model.metadata.builder.connection.Connection)9 TdColumn (org.talend.cwm.relational.TdColumn)9 Expression (orgomg.cwm.objectmodel.core.Expression)7 TdTable (org.talend.cwm.relational.TdTable)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 ModelElementIndicator (org.talend.dataprofiler.core.model.ModelElementIndicator)5 IndicatorUnit (org.talend.dataprofiler.core.ui.editor.preview.IndicatorUnit)5 Indicator (org.talend.dataquality.indicators.Indicator)5 Package (orgomg.cwm.objectmodel.core.Package)4 ArrayList (java.util.ArrayList)3 IFolder (org.eclipse.core.resources.IFolder)3 Shell (org.eclipse.swt.widgets.Shell)3 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)3 CreatePatternAction (org.talend.dataprofiler.core.pattern.actions.CreatePatternAction)3 IRepositoryNode (org.talend.repository.model.IRepositoryNode)3 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)3 Statement (java.sql.Statement)2 HashMap (java.util.HashMap)2