use of org.talend.core.model.metadata.builder.connection.DatabaseConnection in project tdq-studio-se by Talend.
the class ColumnAnalysisSqlExecutorTest method setUp.
/**
* DOC zshen Comment method "setUp".
*
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
// create analysis element
TdColumn testTdColumn = RelationalFactory.eINSTANCE.createTdColumn();
// $NON-NLS-1$
testTdColumn.setName("columnName");
// testAnalysisResult.setModelElement(testTdColumn);
// create sqlDataType
TdSqlDataType testTdSqlDataType = RelationalFactory.eINSTANCE.createTdSqlDataType();
testTdColumn.setSqlDataType(testTdSqlDataType);
testTdSqlDataType.setJavaDataType(DataminingType.NOMINAL_VALUE);
// create TdTable
TdTable testTdTable = RelationalFactory.eINSTANCE.createTdTable();
testTdColumn.setNamespace(testTdTable);
// $NON-NLS-1$
testTdTable.setName("generateTable");
// create connection
DatabaseConnection testDatabaseConnection = ConnectionFactory.eINSTANCE.createDatabaseConnection();
TaggedValueHelper.setTaggedValue(testDatabaseConnection, TaggedValueHelper.DB_PRODUCT_NAME, SupportDBUrlType.MYSQLDEFAULTURL.getDBKey());
// create catalog
Catalog testCatalog = orgomg.cwm.resource.relational.RelationalFactory.eINSTANCE.createCatalog();
// $NON-NLS-1$
testCatalog.setName("TBI");
testTdTable.setNamespace(testCatalog);
testCatalog.setNamespace(testDatabaseConnection);
testCatalog.getDataManager().add(testDatabaseConnection);
// create analysis
testAnalysis = AnalysisFactory.eINSTANCE.createAnalysis();
// create Analaysis result
AnalysisResult testAnalysisResult = AnalysisFactory.eINSTANCE.createAnalysisResult();
testAnalysis.setResults(testAnalysisResult);
// create analysis parameter
AnalysisParameters testAnalysisParameters = AnalysisFactory.eINSTANCE.createAnalysisParameters();
testAnalysis.setParameters(testAnalysisParameters);
// create analysis Content
AnalysisContext testAnalysisContext = AnalysisFactory.eINSTANCE.createAnalysisContext();
testAnalysis.setContext(testAnalysisContext);
testAnalysisContext.setConnection(testDatabaseConnection);
// create row count indicatorDefinition
testIndicatorDefinition = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
// $NON-NLS-1$
testIndicatorDefinition.setLabel("Pattern Frequency Table");
// create row count indicator
testFrequencyIndicator = IndicatorsFactory.eINSTANCE.createPatternFreqIndicator();
testAnalysisResult.getIndicators().add(testFrequencyIndicator);
testFrequencyIndicator.setAnalyzedElement(testTdColumn);
testFrequencyIndicator.setIndicatorDefinition(testIndicatorDefinition);
}
use of org.talend.core.model.metadata.builder.connection.DatabaseConnection in project tdq-studio-se by Talend.
the class TalendCWMServiceTest method testGetNameContexTrueForCatalog.
/**
* Test method for
* {@link org.talend.core.service.TalendCWMService#getReadableName(orgomg.cwm.foundation.softwaredeployment.DataManager, java.lang.String)}
* .
*
* @throws PersistenceException
*/
@Test
public void testGetNameContexTrueForCatalog() throws PersistenceException {
// $NON-NLS-1$
String connectionName = "conn1";
// $NON-NLS-1$
String catalogName = "catalog1";
// $NON-NLS-1$
String ContextTpeyName = "default";
// should be label of
String Connectionlabel = ConnectionContextHelper.convertContextLabel(connectionName);
// connection property when
// use
String prefixName = Connectionlabel + ConnectionContextHelper.LINE;
String paramName = prefixName + DBConnectionContextUtils.EDBParamName.Database;
String contextCatalogName = ContextParameterUtils.JAVA_NEW_CONTEXT_PREFIX + paramName;
// ContextType--default
ContextType createContextDefault = TalendFileFactory.eINSTANCE.createContextType();
createContextDefault.setName(ContextTpeyName);
ContextParameterType createContextParameterTypeForDefault = TalendFileFactory.eINSTANCE.createContextParameterType();
createContextParameterTypeForDefault.setName(paramName);
createContextParameterTypeForDefault.setValue(catalogName);
createContextDefault.getContextParameter().add(createContextParameterTypeForDefault);
// ~ContextType--default
// ConntextItem
ContextItem contextItem = PropertiesFactory.eINSTANCE.createContextItem();
Property contextProperty = PropertiesFactory.eINSTANCE.createProperty();
contextProperty.setAuthor(((RepositoryContext) CoreRuntimePlugin.getInstance().getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY)).getUser());
contextProperty.setVersion(VersionUtils.DEFAULT_VERSION);
// $NON-NLS-1$
contextProperty.setStatusCode("");
// $NON-NLS-1$
contextProperty.setLabel("context1");
contextItem.setProperty(contextProperty);
JobContextManager contextManager = new JobContextManager();
String nextId = factory.getNextId();
contextProperty.setId(nextId);
contextProperty.setLabel(contextProperty.getDisplayName());
contextManager.saveToEmf(contextItem.getContext());
contextItem.setDefaultContext(contextManager.getDefaultContext().getName());
contextItem.getContext().add(createContextDefault);
factory.create(contextItem, Path.EMPTY);
// ContextItem
// DatabaseConnection
DatabaseConnection createDatabaseConnection = ConnectionFactory.eINSTANCE.createDatabaseConnection();
createDatabaseConnection.setName(connectionName);
createDatabaseConnection.setContextMode(true);
createDatabaseConnection.setContextId(contextProperty.getId());
createDatabaseConnection.setContextName(ContextTpeyName);
// ~DatabaseConnection
String readableName = null;
readableName = TalendCWMService.getReadableName(createDatabaseConnection, contextCatalogName);
assert (catalogName.equals(readableName));
}
use of org.talend.core.model.metadata.builder.connection.DatabaseConnection in project tdq-studio-se by Talend.
the class TalendCWMServiceTest method testGetNameContexTrueForSchema.
/**
* Test method for
* {@link org.talend.core.service.TalendCWMService#getReadableName(orgomg.cwm.foundation.softwaredeployment.DataManager, java.lang.String)}
* .
*
* @throws PersistenceException
*/
@Test
public void testGetNameContexTrueForSchema() throws PersistenceException {
// $NON-NLS-1$
String connectionName = "conn1";
// $NON-NLS-1$
String catalogName = "catalog1";
// $NON-NLS-1$
String ContextTpeyName = "default";
// should be label of
String Connectionlabel = ConnectionContextHelper.convertContextLabel(connectionName);
// connection property when
// use
String prefixName = Connectionlabel + ConnectionContextHelper.LINE;
String paramName = prefixName + DBConnectionContextUtils.EDBParamName.Schema;
String contextCatalogName = ContextParameterUtils.JAVA_NEW_CONTEXT_PREFIX + paramName;
// ContextType--default
ContextType createContextDefault = TalendFileFactory.eINSTANCE.createContextType();
createContextDefault.setName(ContextTpeyName);
ContextParameterType createContextParameterTypeForDefault = TalendFileFactory.eINSTANCE.createContextParameterType();
createContextParameterTypeForDefault.setName(paramName);
createContextParameterTypeForDefault.setValue(catalogName);
createContextDefault.getContextParameter().add(createContextParameterTypeForDefault);
// ~ContextType--default
// ConntextItem
ContextItem contextItem = PropertiesFactory.eINSTANCE.createContextItem();
Property contextProperty = PropertiesFactory.eINSTANCE.createProperty();
contextProperty.setAuthor(((RepositoryContext) CoreRuntimePlugin.getInstance().getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY)).getUser());
contextProperty.setVersion(VersionUtils.DEFAULT_VERSION);
// $NON-NLS-1$
contextProperty.setStatusCode("");
// $NON-NLS-1$
contextProperty.setLabel("context2");
contextItem.setProperty(contextProperty);
JobContextManager contextManager = new JobContextManager();
String nextId = factory.getNextId();
contextProperty.setId(nextId);
contextProperty.setLabel(contextProperty.getDisplayName());
contextManager.saveToEmf(contextItem.getContext());
contextItem.setDefaultContext(contextManager.getDefaultContext().getName());
contextItem.getContext().add(createContextDefault);
factory.create(contextItem, Path.EMPTY);
// ContextItem
// DatabaseConnection
DatabaseConnection createDatabaseConnection = ConnectionFactory.eINSTANCE.createDatabaseConnection();
createDatabaseConnection.setName(connectionName);
createDatabaseConnection.setContextMode(true);
createDatabaseConnection.setContextId(contextProperty.getId());
createDatabaseConnection.setContextName(ContextTpeyName);
// ~DatabaseConnection
String readableName = null;
readableName = TalendCWMService.getReadableName(createDatabaseConnection, contextCatalogName);
assert (catalogName.equals(readableName));
}
use of org.talend.core.model.metadata.builder.connection.DatabaseConnection in project tdq-studio-se by Talend.
the class UnitTestBuildHelper method getDB2DataManager.
/**
* getDataManager of DB2
*
* @return
*/
public Connection getDB2DataManager() {
// TypedProperties connectionParams = PropertiesLoader.getProperties(IndicatorEvaluator.class, "db.properties"); //$NON-NLS-1$
// $NON-NLS-1$
String driverClassName = "com.ibm.db2.jcc.DB2Driver";
// $NON-NLS-1$
String dbUrl = "jdbc:db2://192.168.31.135:50000/sample";
// $NON-NLS-1$
String sqlTypeName = "IBM DB2";
DBConnectionParameter params = new DBConnectionParameter();
// $NON-NLS-1$
params.setName("DB2_Connection");
params.setDriverClassName(driverClassName);
params.setJdbcUrl(dbUrl);
params.setSqlTypeName(sqlTypeName);
Properties properties = new Properties();
properties.setProperty(TaggedValueHelper.UNIVERSE, "");
properties.setProperty(TaggedValueHelper.DATA_FILTER, "");
properties.setProperty(TaggedValueHelper.USER, "db2inst1");
properties.setProperty(TaggedValueHelper.PASSWORD, "db2inst1");
params.setParameters(properties);
// create connection
ConnectionUtils.setTimeout(false);
MetadataFillFactory instance = MetadataFillFactory.getDBInstance();
IMetadataConnection metaConnection = instance.fillUIParams(ParameterUtil.toMap(params));
ReturnCode rc = null;
try {
rc = instance.checkConnection(metaConnection);
} catch (java.lang.RuntimeException e) {
Assert.fail("connect to " + dbUrl + "failed," + e.getMessage());
}
Connection dataProvider = null;
if (rc.isOk()) {
dataProvider = instance.fillUIConnParams(metaConnection, null);
dataProvider.setName("DB2_Connection");
// because the DI side code is changed, modify the following code.
metaConnection.setCurrentConnection(dataProvider);
try {
ProjectNodeHelper.fillCatalogAndSchemas(metaConnection, (DatabaseConnection) dataProvider);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Assert.assertNotNull("Can not connect to Database: " + dbUrl, dataProvider);
return dataProvider;
}
use of org.talend.core.model.metadata.builder.connection.DatabaseConnection in project tdq-studio-se by Talend.
the class PatternExplorerRealTest method testGetInvalidValuesStatement_3.
/**
* Test method for {@link org.talend.dq.analysis.explore.PatternExplorer#getInvalidValuesStatement()}. when the test
* for indicator is user define indicator
*/
@Test
public void testGetInvalidValuesStatement_3() {
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(ViewInvalidValues);
indicatorDef.getViewInvalidValuesExpression().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.getInvalidValuesStatement();
// $NON-NLS-1$
assertEquals("SELECT `lname` FROM `catalog1`.`table1` WHERE NOT (id>=1) ", clause);
}
Aggregations