use of org.talend.cwm.relational.TdColumn in project tdi-studio-se by Talend.
the class QueryGuessCommandTest method generateNewQuery.
@Test
public void generateNewQuery() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
connection = ConnectionFactory.eINSTANCE.createConnection();
node = Mockito.mock(INode.class);
connection.setContextMode(true);
TdTable table = RelationalFactory.eINSTANCE.createTdTable();
table.setName("tableName");
table.setLabel("tableLabel");
TdColumn column1 = RelationalFactory.eINSTANCE.createTdColumn();
column1.setId("ID1");
column1.setName("cName1");
TdColumn column2 = RelationalFactory.eINSTANCE.createTdColumn();
column2.setId("ID2");
column2.setName("cName2");
table.getColumns().add(column1);
table.getColumns().add(column2);
metadataTable = ConvertionHelper.convert(table);
ElementParameter parameter = new ElementParameter(node);
parameter.setName("DBTABLE");
parameter.setValue(table.getName());
Mockito.when(node.getPropertyValue(EParameterName.PROPERTY_TYPE.getName())).thenReturn("REPOSITORY");
Mockito.when(node.getElementParameterFromField(EParameterFieldType.DBTABLE)).thenReturn(parameter);
String schema = "schema";
// add test for PostgreSQL
String dbType = EDatabaseTypeName.PSQL.getDisplayName();
QueryGuessCommand command = new QueryGuessCommand(node, metadataTable, schema, dbType, connection);
Method method = command.getClass().getDeclaredMethod("generateNewQuery");
method.setAccessible(true);
String queryString = (String) method.invoke(command);
Assert.assertNotNull(queryString);
Assert.assertTrue(queryString.contains(schema));
Assert.assertTrue(queryString.contains(metadataTable.getTableName()));
Assert.assertTrue(queryString.contains("cName1"));
Assert.assertTrue(queryString.contains("cName2"));
// add test for MySQL
dbType = EDatabaseTypeName.MYSQL.getDisplayName();
command = new QueryGuessCommand(node, metadataTable, schema, dbType, connection);
method = command.getClass().getDeclaredMethod("generateNewQuery");
method.setAccessible(true);
queryString = (String) method.invoke(command);
Assert.assertNotNull(queryString);
Assert.assertFalse(queryString.contains(schema));
Assert.assertTrue(queryString.contains(metadataTable.getTableName()));
Assert.assertTrue(queryString.contains("cName1"));
Assert.assertTrue(queryString.contains("cName2"));
}
use of org.talend.cwm.relational.TdColumn in project tdi-studio-se by Talend.
the class QueryGuessCommandTest method generateNewTeradataQuery.
@Test
public void generateNewTeradataQuery() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, PersistenceException {
connection = ConnectionFactory.eINSTANCE.createConnection();
node = Mockito.mock(INode.class);
connection.setContextMode(true);
TdTable table = RelationalFactory.eINSTANCE.createTdTable();
table.setName("tableName");
table.setLabel("tableLabel");
TdColumn column1 = RelationalFactory.eINSTANCE.createTdColumn();
column1.setName("id");
TdColumn column2 = RelationalFactory.eINSTANCE.createTdColumn();
column2.setName("name");
table.getColumns().add(column1);
table.getColumns().add(column2);
metadataTable = ConvertionHelper.convert(table);
ElementParameter parameter = new ElementParameter(node);
parameter.setName("DBTABLE");
parameter.setValue(table.getName());
Mockito.when(node.getPropertyValue(EParameterName.PROPERTY_TYPE.getName())).thenReturn("REPOSITORY");
Mockito.when(node.getElementParameterFromField(EParameterFieldType.DBTABLE)).thenReturn(parameter);
// test case 1
String schema = "myschema";
String dbType = EDatabaseTypeName.TERADATA.getDisplayName();
String expectedQuery = "\"SELECT myschema.tableName.\\\"id\\\", myschema.tableName.name FROM myschema.tableName\"";
QueryGuessCommand command = new QueryGuessCommand(node, metadataTable, schema, dbType, connection);
Method method = command.getClass().getDeclaredMethod("generateNewQuery");
method.setAccessible(true);
String queryString = (String) method.invoke(command);
Assert.assertEquals(expectedQuery, queryString);
}
use of org.talend.cwm.relational.TdColumn in project tdi-studio-se by Talend.
the class MetadataColumnComparator method saveEMFMetadataColumn.
@SuppressWarnings("unchecked")
private static void saveEMFMetadataColumn(String id, List<MetadataColumn> columnNodes) {
DatabaseConnectionItem item = getEMFItem(id);
final DatabaseConnection connection = (DatabaseConnection) item.getConnection();
IMetadataConnection iMetadataConnection = ConvertionHelper.convert(connection);
Set<MetadataTable> tableset = ConnectionHelper.getTables(connection);
List<MetadataTable> tables = new ArrayList<MetadataTable>();
tables.addAll(tableset);
List<MetadataColumn> emfCols = new ArrayList<MetadataColumn>();
List<MetadataColumn> dbCols = new ArrayList<MetadataColumn>();
for (MetadataColumn col : columnNodes) {
for (MetadataTable table : tables) {
if (table.getLabel().equals(col.getTable().getLabel())) {
List<TdColumn> returnCols = ExtractMetaDataFromDataBase.returnMetadataColumnsFormTable(iMetadataConnection, table.getSourceName());
for (MetadataColumn emfcolumn : table.getColumns()) {
for (MetadataColumn column : returnCols) {
if (emfcolumn.getLabel().equals(col.getLabel()) && column.getLabel().equals(col.getOriginalField())) {
emfCols.add(emfcolumn);
dbCols.add(column);
}
}
}
}
}
}
saveOneMetadataColumn(emfCols, columnNodes, dbCols);
saveMetaData(item);
}
use of org.talend.cwm.relational.TdColumn in project tdq-studio-se by Talend.
the class FunctionalDependencyAnalysisDetailsPage method getColumnSet.
private List<RepositoryNode> getColumnSet(EReference reference) {
List<RepositoryNode> columns = new ArrayList<RepositoryNode>();
EList<Indicator> indicators = getCurrentModelElement().getResults().getIndicators();
for (Indicator indicator : indicators) {
TdColumn findColumn = (TdColumn) indicator.eGet(reference);
RepositoryNode recursiveFind = RepositoryNodeHelper.recursiveFind(findColumn);
if (recursiveFind == null) {
recursiveFind = RepositoryNodeHelper.createRepositoryNode(findColumn);
}
if (recursiveFind != null) {
columns.add(recursiveFind);
}
}
return columns;
}
use of org.talend.cwm.relational.TdColumn in project tdq-studio-se by Talend.
the class FunctionalDependencyAnalysisDetailsPage method validator.
private ReturnCode validator(List<RepositoryNode> columnASet, List<RepositoryNode> columnBSet) {
// MOD by gdbu 2011-3-21 bug 19179
ReturnCode canModRetCode = super.canSave();
if (!canModRetCode.isOk()) {
return canModRetCode;
}
if (columnASet.isEmpty() || columnBSet.isEmpty()) {
// $NON-NLS-1$
return new ReturnCode(DefaultMessagesImpl.getString("ColumnDependencyMasterDetailsPage.columnsBlankMessag"), false);
}
if (columnASet.size() != columnBSet.size()) {
// $NON-NLS-1$
return new ReturnCode(DefaultMessagesImpl.getString("ColumnsComparisonMasterDetailsPage.columnsSameMessage"), false);
}
for (int i = 0; i < columnASet.size(); i++) {
RepositoryNode columnANode = columnASet.get(i);
RepositoryNode columnBNode = columnBSet.get(i);
TdColumn tdColumnA = ((DBColumnRepNode) columnANode).getTdColumn();
TdColumn tdColumnB = ((DBColumnRepNode) columnBNode).getTdColumn();
ColumnSet ownerA = ColumnHelper.getColumnOwnerAsColumnSet(tdColumnA);
ColumnSet ownerB = ColumnHelper.getColumnOwnerAsColumnSet(tdColumnB);
String uuidA = ResourceHelper.getUUID(ownerA);
String uuidB = ResourceHelper.getUUID(ownerB);
if (!uuidA.equals(uuidB)) {
// $NON-NLS-1$
return new ReturnCode(DefaultMessagesImpl.getString("ColumnDependencyMasterDetailsPage.tableMessage"), false);
}
}
return new ReturnCode(true);
}
Aggregations