Search in sources :

Example 6 with ProductVersion

use of org.talend.utils.ProductVersion in project tdq-studio-se by Talend.

the class DbmsLanguageTest method testGetSqlExpressionDB2Case2.

/**
 * Test method for
 * {@link org.talend.dq.dbms.DbmsLanguage#getSqlExpression(IndicatorDefinition, String, EList, ProductVersion)} .
 */
@Test
public void testGetSqlExpressionDB2Case2() {
    // $NON-NLS-1$
    String sqlLang = "SQL";
    // $NON-NLS-1$
    String sqlBody = "SQL body";
    // $NON-NLS-1$
    String db2Lang = "DB2";
    // $NON-NLS-1$
    String db2Body = "DB2 body";
    // $NON-NLS-1$
    String db2NTLang = "DB2/NT";
    // $NON-NLS-1$
    String db2NTBody = "DB2/NT body";
    IndicatorDefinition indicatorDefinition = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
    String language = db2Lang;
    EList<TdExpression> sqlGenericExpression = new BasicEList<TdExpression>();
    TdExpression tdExpression1 = RelationalFactory.eINSTANCE.createTdExpression();
    tdExpression1.setLanguage(sqlLang);
    tdExpression1.setBody(sqlBody);
    sqlGenericExpression.add(tdExpression1);
    TdExpression tdExpression2 = RelationalFactory.eINSTANCE.createTdExpression();
    tdExpression2.setLanguage(db2Lang);
    tdExpression2.setBody(db2Body);
    sqlGenericExpression.add(tdExpression2);
    TdExpression tdExpression3 = RelationalFactory.eINSTANCE.createTdExpression();
    tdExpression3.setLanguage(db2NTLang);
    tdExpression3.setBody(db2NTBody);
    sqlGenericExpression.add(tdExpression3);
    ProductVersion dbVersion = new ProductVersion(1, 0);
    TdExpression sqlExpression = DbmsLanguage.getSqlExpression(indicatorDefinition, language, sqlGenericExpression, dbVersion);
    Assert.assertEquals(tdExpression2, sqlExpression);
}
Also used : TdExpression(org.talend.cwm.relational.TdExpression) BasicEList(org.eclipse.emf.common.util.BasicEList) ProductVersion(org.talend.utils.ProductVersion) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) UDIndicatorDefinition(org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition) Test(org.junit.Test)

Example 7 with ProductVersion

use of org.talend.utils.ProductVersion in project tdq-studio-se by Talend.

the class DbmsLanguageTest method testGetSqlExpressionRedshiftCase1.

/**
 * Test method for
 * {@link org.talend.dq.dbms.DbmsLanguage#getSqlExpression(IndicatorDefinition, String, EList, ProductVersion)} .
 */
@Test
public void testGetSqlExpressionRedshiftCase1() {
    // TDQ-11558 msjian: test for get sql expresstion for redshift database
    // $NON-NLS-1$
    String sqlLang = "SQL";
    // $NON-NLS-1$
    String sqlBody = "SQL body";
    String redshiftLang = SupportDBUrlType.REDSHIFT.getLanguage();
    // $NON-NLS-1$
    String redshiftBody = "Amazon redshift body";
    String postgresqlLang = SupportDBUrlType.POSTGRESQLEFAULTURL.getLanguage();
    // $NON-NLS-1$
    String postgresqlBody = "PostgreSQL body";
    IndicatorDefinition indicatorDefinition = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
    EList<TdExpression> sqlGenericExpression = new BasicEList<TdExpression>();
    TdExpression tdExpression1 = RelationalFactory.eINSTANCE.createTdExpression();
    tdExpression1.setLanguage(sqlLang);
    tdExpression1.setBody(sqlBody);
    sqlGenericExpression.add(tdExpression1);
    TdExpression tdExpression3 = RelationalFactory.eINSTANCE.createTdExpression();
    tdExpression3.setLanguage(postgresqlLang);
    tdExpression3.setBody(postgresqlBody);
    sqlGenericExpression.add(tdExpression3);
    TdExpression tdExpression4 = RelationalFactory.eINSTANCE.createTdExpression();
    tdExpression4.setLanguage(redshiftLang);
    tdExpression4.setBody(redshiftBody);
    sqlGenericExpression.add(tdExpression4);
    ProductVersion dbVersion = new ProductVersion(1, 0);
    TdExpression sqlExpression = DbmsLanguage.getSqlExpression(indicatorDefinition, redshiftLang, sqlGenericExpression, dbVersion);
    Assert.assertEquals(tdExpression4, sqlExpression);
}
Also used : TdExpression(org.talend.cwm.relational.TdExpression) BasicEList(org.eclipse.emf.common.util.BasicEList) ProductVersion(org.talend.utils.ProductVersion) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) UDIndicatorDefinition(org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition) Test(org.junit.Test)

Example 8 with ProductVersion

use of org.talend.utils.ProductVersion in project tdq-studio-se by Talend.

the class DbmsLanguageTest method testGetSqlExpressionRedshiftCase3.

/**
 * Test method for
 * {@link org.talend.dq.dbms.DbmsLanguage#getSqlExpression(IndicatorDefinition, String, EList, ProductVersion)} .
 */
@Test
public void testGetSqlExpressionRedshiftCase3() {
    // TDQ-11558 msjian: test for get sql expresstion for redshift database when there is no redshift and ParAccel
    // and PostgreSQL defined
    // $NON-NLS-1$
    String sqlLang = "SQL";
    // $NON-NLS-1$
    String sqlBody = "SQL body";
    String redshiftLang = SupportDBUrlType.REDSHIFT.getLanguage();
    IndicatorDefinition indicatorDefinition = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
    EList<TdExpression> sqlGenericExpression = new BasicEList<TdExpression>();
    TdExpression tdExpression1 = RelationalFactory.eINSTANCE.createTdExpression();
    tdExpression1.setLanguage(sqlLang);
    tdExpression1.setBody(sqlBody);
    sqlGenericExpression.add(tdExpression1);
    ProductVersion dbVersion = new ProductVersion(1, 0);
    TdExpression sqlExpression = DbmsLanguage.getSqlExpression(indicatorDefinition, redshiftLang, sqlGenericExpression, dbVersion);
    Assert.assertEquals(tdExpression1, sqlExpression);
}
Also used : TdExpression(org.talend.cwm.relational.TdExpression) BasicEList(org.eclipse.emf.common.util.BasicEList) ProductVersion(org.talend.utils.ProductVersion) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) UDIndicatorDefinition(org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition) Test(org.junit.Test)

Example 9 with ProductVersion

use of org.talend.utils.ProductVersion in project tdq-studio-se by Talend.

the class FileSystemImportWriter method migration.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.dataprofiler.core.ui.imex.model.IImexWriter#migration(org.eclipse.core.runtime.IProgressMonitor)
     */
public void migration(IProgressMonitor monitor) {
    List<IMigrationTask> modelTasks = new ArrayList<IMigrationTask>();
    if (versionFile != null && versionFile.exists()) {
        ProductVersion version = WorkspaceVersionHelper.getVesion(new Path(versionFile.getAbsolutePath()));
        MigrationTaskManager manager = new MigrationTaskManager(version, MigrationTaskType.FILE);
        List<IMigrationTask> taskList = manager.getValidTasks();
        if (!taskList.isEmpty()) {
            for (IMigrationTask task : taskList) {
                if (task.isModelTask()) {
                    ((AbstractWorksapceUpdateTask) task).setWorkspacePath(basePath);
                    modelTasks.add(task);
                } else {
                    // MOD msjian TDQ-7365 2013-5-27: only added the not inclued tasks
                    if (!commTasks.contains(task)) {
                        commTasks.add(task);
                    }
                // TDQ-7365~
                }
            }
        }
    }
    if (!modelTasks.isEmpty()) {
        MigrationTaskManager.doMigrationTask(modelTasks, monitor);
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) MigrationTaskManager(org.talend.dataprofiler.migration.manager.MigrationTaskManager) AbstractWorksapceUpdateTask(org.talend.dataprofiler.core.migration.AbstractWorksapceUpdateTask) ArrayList(java.util.ArrayList) IMigrationTask(org.talend.dataprofiler.migration.IMigrationTask) ProductVersion(org.talend.utils.ProductVersion)

Example 10 with ProductVersion

use of org.talend.utils.ProductVersion in project tdq-studio-se by Talend.

the class ConnectionUtils method getDatabaseVersion.

/**
 * get the database product version.
 *
 * @param connection
 * @return
 */
public static ProductVersion getDatabaseVersion(IMetadataConnection connection) {
    ProductVersion version = null;
    Connection conn = (Connection) connection.getCurrentConnection();
    Properties props = new Properties();
    String userName = JavaSqlFactory.getUsername(conn);
    String password = JavaSqlFactory.getPassword(conn);
    props.put(TaggedValueHelper.USER, userName);
    props.put(TaggedValueHelper.PASSWORD, password);
    String dbType = connection.getDbType();
    if (dbType != null) {
        props.put(TaggedValueHelper.DBTYPE, dbType);
    }
    java.sql.Connection createConnection = null;
    try {
        List list = ExtractMetaDataUtils.getInstance().connect(dbType, connection.getUrl(), userName, password, connection.getDriverClass(), connection.getDriverJarPath(), connection.getDbVersionString(), connection.getAdditionalParams());
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i) instanceof java.sql.Connection) {
                createConnection = (java.sql.Connection) list.get(i);
                break;
            }
        }
        if (createConnection != null) {
            if (createConnection.getMetaData() != null) {
                String temp = createConnection.getMetaData().getDatabaseProductVersion();
                if (temp != null) {
                    version = ProductVersion.fromString(temp);
                }
                if (version == null) {
                    version = ProductVersion.fromString(createConnection.getMetaData().getDatabaseMajorVersion() + // $NON-NLS-1$
                    "." + createConnection.getMetaData().getDatabaseMinorVersion() + // $NON-NLS-1$
                    ".0");
                }
            }
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
    } finally {
        if (createConnection != null) {
            try {
                createConnection.close();
            } catch (SQLException e) {
                ExceptionHandler.process(e);
            }
        }
    }
    if (version == null) {
        // $NON-NLS-1$
        version = ProductVersion.fromString("0.0.0");
    }
    return version;
}
Also used : SQLException(java.sql.SQLException) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) DelimitedFileConnection(org.talend.core.model.metadata.builder.connection.DelimitedFileConnection) FileConnection(org.talend.core.model.metadata.builder.connection.FileConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) ManagerConnection(org.talend.metadata.managment.repository.ManagerConnection) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) EList(org.eclipse.emf.common.util.EList) ProductVersion(org.talend.utils.ProductVersion) Properties(java.util.Properties) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SQLException(java.sql.SQLException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) PersistenceException(org.talend.commons.exception.PersistenceException)

Aggregations

ProductVersion (org.talend.utils.ProductVersion)16 BasicEList (org.eclipse.emf.common.util.BasicEList)9 Test (org.junit.Test)9 TdExpression (org.talend.cwm.relational.TdExpression)9 IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)9 UDIndicatorDefinition (org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition)9 ArrayList (java.util.ArrayList)3 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 Properties (java.util.Properties)2 IMigrationTask (org.talend.dataprofiler.migration.IMigrationTask)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MalformedURLException (java.net.MalformedURLException)1 SQLException (java.sql.SQLException)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 IFile (org.eclipse.core.resources.IFile)1 IPath (org.eclipse.core.runtime.IPath)1