Search in sources :

Example 16 with Catalog

use of orgomg.cwm.resource.relational.Catalog in project tdq-studio-se by Talend.

the class PatternExplorerRealTest method testGetValidRowsStatement_5.

/**
 * Test method for {@link org.talend.dq.analysis.explore.PatternExplorer#getValidRowsStatement()}. when the test for
 * indicator is user define indicator
 */
@Test
public void testGetValidRowsStatement_5() {
    patternExplorer = new RegexPatternExplorer();
    // mock setEntity
    PatternMatchingIndicator indicator = IndicatorsFactoryImpl.eINSTANCE.createRegexpMatchingIndicator();
    UDIndicatorDefinition indicatorDef = UserdefineFactoryImpl.eINSTANCE.createUDIndicatorDefinition();
    indicator.setIndicatorDefinition(indicatorDef);
    TdExpression udiTdExpression = RelationalFactoryImpl.eINSTANCE.createTdExpression();
    udiTdExpression.setLanguage(SupportDBUrlType.HIVEDEFAULTURL.getLanguage());
    udiTdExpression.setBody(ViewValidRows);
    indicatorDef.getViewValidRowsExpression().add(udiTdExpression);
    // create pattern parameter
    IndicatorParameters createIndicatorParameters = IndicatorsFactory.eINSTANCE.createIndicatorParameters();
    indicator.setParameters(createIndicatorParameters);
    Domain createDomain = DomainFactoryImpl.eINSTANCE.createDomain();
    createIndicatorParameters.setDataValidDomain(createDomain);
    Pattern createPattern = PatternFactoryImpl.eINSTANCE.createPattern();
    createDomain.getPatterns().add(createPattern);
    RegularExpression createPatternComponent = PatternFactoryImpl.eINSTANCE.createRegularExpression();
    createPattern.getComponents().add(createPatternComponent);
    TdExpression createTdExpression = RelationalFactoryImpl.eINSTANCE.createTdExpression();
    createPatternComponent.setExpression(createTdExpression);
    createTdExpression.setLanguage(SupportDBUrlType.HIVEDEFAULTURL.getLanguage());
    // $NON-NLS-1$
    createTdExpression.setBody("`su.*`");
    TdColumn element = RelationalFactoryImpl.eINSTANCE.createTdColumn();
    // $NON-NLS-1$
    element.setName("lname");
    TdTable createTdTable = RelationalFactoryImpl.eINSTANCE.createTdTable();
    // $NON-NLS-1$
    createTdTable.setName("table1");
    TableHelper.addColumn(createTdTable, element);
    Catalog createCatalog = orgomg.cwm.resource.relational.impl.RelationalFactoryImpl.eINSTANCE.createCatalog();
    // $NON-NLS-1$
    createCatalog.setName("catalog1");
    List<TdTable> tableList = new ArrayList<TdTable>();
    tableList.add(createTdTable);
    CatalogHelper.addTables(tableList, createCatalog);
    indicator.setAnalyzedElement(element);
    Expression createIndiExpression = CoreFactoryImpl.eINSTANCE.createExpression();
    createIndiExpression.setLanguage(SupportDBUrlType.HIVEDEFAULTURL.getLanguage());
    // $NON-NLS-1$
    createIndiExpression.setBody("SELECT *  FROM `tbi`.`customer`  WHERE (customer.lname = \"sunny\")");
    indicator.setInstantiatedExpression(createIndiExpression);
    Analysis analysis = AnalysisFactoryImpl.eINSTANCE.createAnalysis();
    AnalysisContext createAnalysisContext = AnalysisFactoryImpl.eINSTANCE.createAnalysisContext();
    analysis.setContext(createAnalysisContext);
    DatabaseConnection createDatabaseConnection = ConnectionFactoryImpl.eINSTANCE.createDatabaseConnection();
    TaggedValueHelper.setTaggedValue(createDatabaseConnection, TaggedValueHelper.DB_PRODUCT_NAME, SupportDBUrlType.HIVEDEFAULTURL.getLanguage());
    // $NON-NLS-1$
    TaggedValueHelper.setTaggedValue(createDatabaseConnection, TaggedValueHelper.DB_PRODUCT_VERSION, "1.0");
    // $NON-NLS-1$
    TaggedValueHelper.setTaggedValue(createDatabaseConnection, TaggedValueHelper.DB_IDENTIFIER_QUOTE_STRING, "`");
    createAnalysisContext.setConnection(createDatabaseConnection);
    ChartDataEntity cdEntity = new ChartDataEntity();
    cdEntity.setIndicator(indicator);
    Assert.assertTrue(patternExplorer.setAnalysis(analysis));
    patternExplorer.setEnitty(cdEntity);
    String clause = patternExplorer.getValidRowsStatement();
    // $NON-NLS-1$
    assertEquals("SELECT * FROM `catalog1`.`table1` ", clause);
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) TdTable(org.talend.cwm.relational.TdTable) UDIndicatorDefinition(org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition) TdExpression(org.talend.cwm.relational.TdExpression) IndicatorParameters(org.talend.dataquality.indicators.IndicatorParameters) ArrayList(java.util.ArrayList) AnalysisContext(org.talend.dataquality.analysis.AnalysisContext) ChartDataEntity(org.talend.dq.indicators.preview.table.ChartDataEntity) Catalog(orgomg.cwm.resource.relational.Catalog) PatternMatchingIndicator(org.talend.dataquality.indicators.PatternMatchingIndicator) TdColumn(org.talend.cwm.relational.TdColumn) TdExpression(org.talend.cwm.relational.TdExpression) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) Expression(orgomg.cwm.objectmodel.core.Expression) Analysis(org.talend.dataquality.analysis.Analysis) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Domain(org.talend.dataquality.domain.Domain) Test(org.junit.Test)

Example 17 with Catalog

use of orgomg.cwm.resource.relational.Catalog in project tdq-studio-se by Talend.

the class DbmsLanguageTest method createTdTable.

private TdTable createTdTable() {
    Connection conn = ConnectionFactory.eINSTANCE.createDatabaseConnection();
    // $NON-NLS-1$
    Catalog catalog = CatalogHelper.createCatalog("myCatalog");
    ConnectionHelper.addCatalog(catalog, conn);
    List<TdTable> tables = new ArrayList<TdTable>();
    TdTable tdTable = RelationalFactory.eINSTANCE.createTdTable();
    // $NON-NLS-1$
    tdTable.setName("myTable");
    tables.add(tdTable);
    CatalogHelper.addTables(tables, catalog);
    return tdTable;
}
Also used : TdTable(org.talend.cwm.relational.TdTable) Connection(org.talend.core.model.metadata.builder.connection.Connection) ArrayList(java.util.ArrayList) Catalog(orgomg.cwm.resource.relational.Catalog)

Example 18 with Catalog

use of orgomg.cwm.resource.relational.Catalog in project tdq-studio-se by Talend.

the class SwitchContextGroupNameImplTest method testUpdateContextGroupSuccessMysql.

/**
 * Test method for
 * {@link org.talend.repository.ui.utils.SwitchContextGroupNameImpl#updateContextGroup(org.talend.core.model.properties.ConnectionItem)}
 * . mysql case
 */
@Test
public void testUpdateContextGroupSuccessMysql() {
    boolean updateContextGroup = SwitchContextGroupNameImpl.getInstance().updateContextGroup(createDatabaseConnectionItem, ContextTpeyNameNew);
    Connection connection = createDatabaseConnectionItem.getConnection();
    List<Catalog> catalogs = ConnectionHelper.getCatalogs(connection);
    assertTrue(updateContextGroup);
    assertTrue(catalogs.size() == 1);
    assertTrue(catalogs.get(0).getName().equalsIgnoreCase(catalogNew));
}
Also used : DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) Catalog(orgomg.cwm.resource.relational.Catalog) Test(org.junit.Test)

Example 19 with Catalog

use of orgomg.cwm.resource.relational.Catalog in project tdq-studio-se by Talend.

the class SwitchContextGroupNameImplTest method testUpdateContextGroupfail1.

/**
 * Test method for
 * {@link org.talend.repository.ui.utils.SwitchContextGroupNameImpl#updateContextGroup(org.talend.core.model.properties.ConnectionItem)}
 * . fail1: createDatabaseConnectionItem is null will nothing to do and return false
 */
@Test
public void testUpdateContextGroupfail1() {
    boolean updateContextGroup = SwitchContextGroupNameImpl.getInstance().updateContextGroup(null, ContextTpeyNameNew);
    Connection connection = createDatabaseConnectionItem.getConnection();
    List<Catalog> catalogs = ConnectionHelper.getCatalogs(connection);
    assertFalse(updateContextGroup);
    assertTrue(catalogs.size() == 1);
    assertTrue(catalogs.get(0).getName().equalsIgnoreCase(catalogOld));
}
Also used : DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) Catalog(orgomg.cwm.resource.relational.Catalog) Test(org.junit.Test)

Example 20 with Catalog

use of orgomg.cwm.resource.relational.Catalog in project tdq-studio-se by Talend.

the class SwitchContextGroupNameImplTest method createCatalogSchema.

/**
 * DOC talend Comment method "createSchema".
 *
 * @param schemaOld2
 */
private void createCatalogSchema(String schemaOld2) {
    Connection connection = createDatabaseConnectionItem.getConnection();
    ((DatabaseConnection) connection).setUiSchema(this.contextSchemaName);
    List<Catalog> catalogs = ConnectionHelper.getCatalogs(connection);
    Catalog catalog = catalogs.get(0);
    Schema createSchema = SchemaHelper.createSchema(schemaOld);
    List<Schema> schemas = new ArrayList<Schema>();
    schemas.add(createSchema);
    CatalogHelper.addSchemas(schemas, catalog);
}
Also used : Schema(orgomg.cwm.resource.relational.Schema) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) ArrayList(java.util.ArrayList) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Catalog(orgomg.cwm.resource.relational.Catalog)

Aggregations

Catalog (orgomg.cwm.resource.relational.Catalog)106 Schema (orgomg.cwm.resource.relational.Schema)56 Connection (org.talend.core.model.metadata.builder.connection.Connection)32 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)31 ArrayList (java.util.ArrayList)28 TdTable (org.talend.cwm.relational.TdTable)27 Test (org.junit.Test)19 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)19 TdColumn (org.talend.cwm.relational.TdColumn)19 IRepositoryNode (org.talend.repository.model.IRepositoryNode)17 RepositoryNode (org.talend.repository.model.RepositoryNode)17 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)16 Package (orgomg.cwm.objectmodel.core.Package)15 MetadataCatalogRepositoryObject (org.talend.core.repository.model.repositoryObject.MetadataCatalogRepositoryObject)12 TdExpression (org.talend.cwm.relational.TdExpression)11 EObject (org.eclipse.emf.ecore.EObject)10 Expression (orgomg.cwm.objectmodel.core.Expression)10 RegularExpression (org.talend.dataquality.domain.pattern.RegularExpression)9 List (java.util.List)8 PersistenceException (org.talend.commons.exception.PersistenceException)8