Search in sources :

Example 51 with DatabaseConnection

use of org.talend.core.model.metadata.builder.connection.DatabaseConnection in project tdq-studio-se by Talend.

the class UpdateDBConnectionDriverJarPathTask method doExecute.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.dataprofiler.migration.AMigrationTask#doExecute()
     */
@Override
protected boolean doExecute() throws Exception {
    List<IRepositoryViewObject> allConnectionObject = ProxyRepositoryFactory.getInstance().getAll(ERepositoryObjectType.METADATA_CONNECTIONS);
    for (IRepositoryViewObject object : allConnectionObject) {
        ConnectionItem item = (ConnectionItem) object.getProperty().getItem();
        Connection connection = item.getConnection();
        if (connection instanceof DatabaseConnection) {
            DatabaseConnection dbConn = (DatabaseConnection) connection;
            String oldJarPath = dbConn.getDriverJarPath();
            String newJarPath = null;
            try {
                if (oldJarPath != null && !"".equals(oldJarPath.trim())) {
                    // $NON-NLS-1$
                    IPath path = Path.fromOSString(oldJarPath);
                    if (path.isAbsolute()) {
                        newJarPath = path.lastSegment();
                    }
                }
                if (newJarPath != null) {
                    dbConn.setDriverJarPath(newJarPath);
                    ProxyRepositoryFactory.getInstance().save(item, true);
                }
            } catch (Exception e) {
                return false;
            }
        }
    }
    return true;
}
Also used : IPath(org.eclipse.core.runtime.IPath) ConnectionItem(org.talend.core.model.properties.ConnectionItem) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection)

Example 52 with DatabaseConnection

use of org.talend.core.model.metadata.builder.connection.DatabaseConnection in project tdq-studio-se by Talend.

the class DefValueCountIndicatorImpl method prepare.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.dataquality.indicators.impl.IndicatorImpl#prepare()
     * 
     * ADD yyi 2009-09-02 prepare()
     */
@Override
public boolean prepare() {
    TdColumn tdColumn = SwitchHelpers.COLUMN_SWITCH.doSwitch(this.getAnalyzedElement());
    this.defValue = ColumnHelper.getDefaultValue(tdColumn);
    // MOD qiongli 2011-5-31 bug 21655,if it is oracle db,need to handel the default value.
    Connection connection = ConnectionHelper.getConnection(tdColumn);
    if (SwitchHelpers.DATABASECONNECTION_SWITCH.doSwitch(connection) != null) {
        String databaseType = ((DatabaseConnection) connection).getDatabaseType();
        if (databaseType != null && databaseType.contains("Oracle")) {
            // $NON-NLS-1$
            isOracle = true;
        }
    }
    // this indicator.
    if (defValue != null) {
        if (isOracle) {
            getDefValueForOracle(tdColumn);
        } else if (Java2SqlType.isDateInSQL(tdColumn.getSqlDataType().getJavaDataType())) {
            String defTmp = defValue.toString();
            try {
                if (StringUtils.contains(defTmp, ":")) {
                    // $NON-NLS-1$
                    defValue = DateFormat.getDateTimeInstance().parse(defTmp);
                } else {
                    defValue = DateFormat.getDateInstance().parse(defTmp);
                }
            } catch (ParseException exc) {
                // if parse fail,reset defValue to String
                defValue = defTmp;
                log.warn("Parse default value failure!");
            }
        }
    }
    return super.prepare();
}
Also used : TdColumn(org.talend.cwm.relational.TdColumn) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) ParseException(java.text.ParseException)

Example 53 with DatabaseConnection

use of org.talend.core.model.metadata.builder.connection.DatabaseConnection in project tdq-studio-se by Talend.

the class SoftwareSystemManagerTest method testUpdateSoftwareSystem.

/**
 * Test method for
 * {@link org.talend.cwm.management.api.SoftwareSystemManager#updateSoftwareSystem(java.sql.Connection, orgomg.cwm.foundation.softwaredeployment.SoftwareSystem)}
 * .
 */
@Test
public void testUpdateSoftwareSystem() {
    SoftwareSystemManager softwareSystemManger = SoftwareSystemManager.getInstance();
    PowerMockito.mockStatic(EMFSharedResources.class);
    EMFSharedResources emfSharedResourceMock = mock(EMFSharedResources.class);
    when(EMFSharedResources.getInstance()).thenReturn(emfSharedResourceMock).thenReturn(emfSharedResourceMock);
    Resource softwareSysResource = mock(Resource.class);
    when(emfSharedResourceMock.getSoftwareDeploymentResource()).thenReturn(softwareSysResource);
    EList<EObject> existedSystems = new BasicEList<EObject>();
    when(softwareSysResource.getContents()).thenReturn(existedSystems);
    when(emfSharedResourceMock.saveResource(softwareSysResource)).thenReturn(Boolean.TRUE);
    try {
        softwareSystemManger.updateSoftwareSystem(null);
        Connection mockConnection = mock(Connection.class);
        DatabaseMetaData mockDBMetaData = mock(DatabaseMetaData.class);
        // Mocking Static Class
        PowerMockito.mockStatic(DriverManager.class);
        // $NON-NLS-1$
        String sql = "jdbc:mysql://localhost:3306/tbi";
        when(DriverManager.getConnection(sql)).thenReturn(mockConnection);
        when(mockConnection.getMetaData()).thenReturn(mockDBMetaData);
        // Mock database product name.
        // $NON-NLS-1$
        String mysqlDB = "MYSQL";
        when(mockDBMetaData.getDatabaseProductName()).thenReturn(mysqlDB);
        // Mock database product version
        // $NON-NLS-1$
        String version = "5.5";
        when(mockDBMetaData.getDatabaseProductVersion()).thenReturn(version);
        when(mockDBMetaData.getDatabaseMinorVersion()).thenReturn(5);
        when(mockDBMetaData.getDatabaseMajorVersion()).thenReturn(5);
        DatabaseConnection dbConn = ConnectionPackage.eINSTANCE.getConnectionFactory().createDatabaseConnection();
        TaggedValueHelper.setTaggedValue(dbConn, TaggedValueHelper.DB_PRODUCT_NAME, mysqlDB);
        TaggedValueHelper.setTaggedValue(dbConn, TaggedValueHelper.DB_PRODUCT_VERSION, version);
        PowerMockito.mockStatic(ConvertionHelper.class);
        // $NON-NLS-1$
        when(ConvertionHelper.convert(dbConn, false, "")).thenReturn(null);
        PowerMockito.mockStatic(MetadataFillFactory.class);
        MetadataFillFactory metadataFillFactory = mock(MetadataFillFactory.class);
        when(MetadataFillFactory.getDBInstance()).thenReturn(metadataFillFactory);
        TypedReturnCode<java.sql.Connection> returnCode = new TypedReturnCode<Connection>(Boolean.TRUE);
        returnCode.setObject(mockConnection);
        when(metadataFillFactory.createConnection(null)).thenReturn(returnCode);
        softwareSystemManger.updateSoftwareSystem(dbConn);
        Assert.assertTrue(existedSystems.size() > 0);
        SoftwareSystem newSoftwareSys = (SoftwareSystem) existedSystems.get(0);
        Assert.assertEquals(mysqlDB, newSoftwareSys.getSubtype());
        Assert.assertEquals(version, newSoftwareSys.getVersion());
    } catch (SQLException e) {
        Assert.fail(e.getMessage());
    }
}
Also used : SQLException(java.sql.SQLException) BasicEList(org.eclipse.emf.common.util.BasicEList) Resource(org.eclipse.emf.ecore.resource.Resource) Connection(java.sql.Connection) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) DatabaseMetaData(java.sql.DatabaseMetaData) EMFSharedResources(org.talend.dq.writer.EMFSharedResources) EObject(org.eclipse.emf.ecore.EObject) TypedReturnCode(org.talend.utils.sugars.TypedReturnCode) TdSoftwareSystem(org.talend.cwm.softwaredeployment.TdSoftwareSystem) SoftwareSystem(orgomg.cwm.foundation.softwaredeployment.SoftwareSystem) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) MetadataFillFactory(org.talend.metadata.managment.model.MetadataFillFactory) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 54 with DatabaseConnection

use of org.talend.core.model.metadata.builder.connection.DatabaseConnection in project tdq-studio-se by Talend.

the class ColumnAnalysisExecutorTest method testCreateSqlStatement_1.

/**
 * when there are some catelog
 * {@link org.talend.dq.analysis.ColumnAnalysisExecutor#createSqlStatement(org.talend.dataquality.analysis.Analysis)}
 * .
 */
@Test
public void testCreateSqlStatement_1() {
    Analysis analysis = AnalysisFactory.eINSTANCE.createAnalysis();
    AnalysisContext context = AnalysisFactory.eINSTANCE.createAnalysisContext();
    analysis.setContext(context);
    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");
    AnalysisParameters analysisPara = AnalysisFactory.eINSTANCE.createAnalysisParameters();
    analysisPara.setStoreData(false);
    analysis.setParameters(analysisPara);
    context.getAnalysedElements().add(tdColumn);
    AnalysisResult analysisResult = AnalysisFactory.eINSTANCE.createAnalysisResult();
    ExecutionInformations info = AnalysisFactory.eINSTANCE.createExecutionInformations();
    analysisResult.setResultMetadata(info);
    analysis.setResults(analysisResult);
    // mock(Catalog.class);
    Package catalog = orgomg.cwm.resource.relational.RelationalFactory.eINSTANCE.createCatalog();
    // $NON-NLS-1$
    catalog.setName("catalogName");
    tdTable.setNamespace(catalog);
    DatabaseConnection createConnection = ConnectionFactory.eINSTANCE.createDatabaseConnection();
    createConnection.getTaggedValue().add(TaggedValueHelper.createTaggedValue(TaggedValueHelper.DB_PRODUCT_NAME, SupportDBUrlType.MYSQLDEFAULTURL.getLanguage()));
    analysis.getContext().setConnection(createConnection);
    ColumnAnalysisExecutor columnAnalysisExecutor = new ColumnAnalysisExecutor();
    // $NON-NLS-1$
    assertEquals("SELECT `columnName` FROM `catalogName`.`tableName`", columnAnalysisExecutor.createSqlStatement(analysis));
}
Also used : ExecutionInformations(org.talend.dataquality.analysis.ExecutionInformations) TdColumn(org.talend.cwm.relational.TdColumn) TdTable(org.talend.cwm.relational.TdTable) Analysis(org.talend.dataquality.analysis.Analysis) AnalysisParameters(org.talend.dataquality.analysis.AnalysisParameters) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) AnalysisContext(org.talend.dataquality.analysis.AnalysisContext) Package(orgomg.cwm.objectmodel.core.Package) AnalysisResult(org.talend.dataquality.analysis.AnalysisResult) Test(org.junit.Test)

Example 55 with DatabaseConnection

use of org.talend.core.model.metadata.builder.connection.DatabaseConnection in project tdq-studio-se by Talend.

the class ColumnAnalysisExecutorTest method testCreateSqlStatement_2.

/**
 * when there are some schema.
 * {@link org.talend.dq.analysis.ColumnAnalysisExecutor#createSqlStatement(org.talend.dataquality.analysis.Analysis)}
 * .
 */
@Test
public void testCreateSqlStatement_2() {
    Analysis analysis = AnalysisFactory.eINSTANCE.createAnalysis();
    AnalysisContext context = AnalysisFactory.eINSTANCE.createAnalysisContext();
    analysis.setContext(context);
    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");
    AnalysisParameters analysisPara = AnalysisFactory.eINSTANCE.createAnalysisParameters();
    analysisPara.setStoreData(false);
    analysis.setParameters(analysisPara);
    context.getAnalysedElements().add(tdColumn);
    AnalysisResult analysisResult = AnalysisFactory.eINSTANCE.createAnalysisResult();
    ExecutionInformations info = AnalysisFactory.eINSTANCE.createExecutionInformations();
    analysisResult.setResultMetadata(info);
    analysis.setResults(analysisResult);
    // 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);
    DatabaseConnection createConnection = ConnectionFactory.eINSTANCE.createDatabaseConnection();
    createConnection.getTaggedValue().add(TaggedValueHelper.createTaggedValue(TaggedValueHelper.DB_PRODUCT_NAME, SupportDBUrlType.MSSQLDEFAULTURL.getLanguage()));
    analysis.getContext().setConnection(createConnection);
    ColumnAnalysisExecutor columnAnalysisExecutor = new ColumnAnalysisExecutor();
    assertEquals("SELECT columnName FROM catalogName.schemaName.tableName", // $NON-NLS-1$
    columnAnalysisExecutor.createSqlStatement(analysis));
}
Also used : ExecutionInformations(org.talend.dataquality.analysis.ExecutionInformations) TdColumn(org.talend.cwm.relational.TdColumn) TdTable(org.talend.cwm.relational.TdTable) Analysis(org.talend.dataquality.analysis.Analysis) AnalysisParameters(org.talend.dataquality.analysis.AnalysisParameters) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) AnalysisContext(org.talend.dataquality.analysis.AnalysisContext) Package(orgomg.cwm.objectmodel.core.Package) AnalysisResult(org.talend.dataquality.analysis.AnalysisResult) Test(org.junit.Test)

Aggregations

DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)211 DatabaseConnectionItem (org.talend.core.model.properties.DatabaseConnectionItem)66 Connection (org.talend.core.model.metadata.builder.connection.Connection)53 ConnectionItem (org.talend.core.model.properties.ConnectionItem)42 ArrayList (java.util.ArrayList)41 PersistenceException (org.talend.commons.exception.PersistenceException)41 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)39 Test (org.junit.Test)33 IMetadataConnection (org.talend.core.model.metadata.IMetadataConnection)30 Property (org.talend.core.model.properties.Property)30 Item (org.talend.core.model.properties.Item)26 DelimitedFileConnection (org.talend.core.model.metadata.builder.connection.DelimitedFileConnection)20 IElementParameter (org.talend.core.model.process.IElementParameter)19 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)18 RepositoryNode (org.talend.repository.model.RepositoryNode)18 SQLException (java.sql.SQLException)17 TdTable (org.talend.cwm.relational.TdTable)17 Catalog (orgomg.cwm.resource.relational.Catalog)17 List (java.util.List)15 ReturnCode (org.talend.utils.sugars.ReturnCode)14