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;
}
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();
}
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());
}
}
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));
}
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));
}
Aggregations