use of org.talend.cwm.relational.TdColumn in project tdi-studio-se by Talend.
the class QueryGuessCommandTest method generateNewTeradataQuery2.
@Test
public void generateNewTeradataQuery2() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, PersistenceException {
ProxyRepositoryFactory repFactory = ProxyRepositoryFactory.getInstance();
String propertyId = repFactory.getNextId();
try {
DatabaseConnection connection = ConnectionFactory.eINSTANCE.createDatabaseConnection();
connection.setSID("myschema");
Property connectionProperty = PropertiesFactory.eINSTANCE.createProperty();
connectionProperty.setAuthor(((RepositoryContext) CoreRuntimePlugin.getInstance().getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY)).getUser());
connectionProperty.setVersion(VersionUtils.DEFAULT_VERSION);
//$NON-NLS-1$
connectionProperty.setStatusCode("");
connectionProperty.setId(propertyId);
connectionProperty.setLabel("test_connection");
ConnectionItem connectionItem = PropertiesFactory.eINSTANCE.createDatabaseConnectionItem();
connectionItem.setProperty(connectionProperty);
connectionItem.setConnection(connection);
repFactory.create(connectionItem, new Path(""));
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);
ElementParameter connectionId = new ElementParameter(node);
connectionId.setValue(connectionProperty.getId());
Mockito.when(node.getElementParameter(EParameterName.REPOSITORY_PROPERTY_TYPE.getName())).thenReturn(connectionId);
// test case 1
String schema = "";
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);
} catch (Exception e) {
throw e;
} finally {
IRepositoryViewObject lastVersion = repFactory.getLastVersion(propertyId);
if (lastVersion != null) {
repFactory.deleteObjectPhysical(lastVersion);
}
}
}
use of org.talend.cwm.relational.TdColumn in project tdi-studio-se by Talend.
the class FillParametersForDatabaseConnectionMigrationTask method fillParamaters.
/**
* DOC sgandon Comment method "fillParamaters".
*
* @param tcol
*/
private void fillParamaters(List<TdColumn> allColumns) {
for (TdColumn tdCol : allColumns) {
TdSqlDataType sqlDataType = RelationalFactory.eINSTANCE.createTdSqlDataType();
// it is impossible to find out what is the java data type from the type name
// because every jdbc constructor may implement their own types
// see http://download.oracle.com/javase/1.3/docs/guide/jdbc/getstart/mapping.html#table1
// so we set it to NULL type and 0.
// TOP may test it and retreive it from the DB when necessary.
sqlDataType.setName(NULL_SQL_TYPE_NAME);
sqlDataType.setJavaDataType(java.sql.Types.NULL);
tdCol.setSqlDataType(sqlDataType);
}
}
use of org.talend.cwm.relational.TdColumn in project tdq-studio-se by Talend.
the class RepositoryNodeHelper method getColumnOwner.
public static ColumnSet getColumnOwner(RepositoryNode node) {
if (node == null) {
return null;
}
MetadataColumnRepositoryObject columnObject = (MetadataColumnRepositoryObject) node.getObject();
TdColumn column = ((TdColumn) columnObject.getTdColumn());
if (column != null && column.eIsProxy()) {
column = (TdColumn) EObjectHelper.resolveObject(column);
}
return ColumnHelper.getColumnOwnerAsColumnSet(column);
}
use of org.talend.cwm.relational.TdColumn in project tdq-studio-se by Talend.
the class RepositoryNodeHelper method filterMatchingColumns.
/**
* DOC klliu Comment method "filterMatchingColumns".
*
* @param columns
* @param patterns
* @return
*/
private static List<TdColumn> filterMatchingColumns(List<TdColumn> columns, String[] patterns) {
List<TdColumn> resetColumns = new ArrayList<TdColumn>();
int size = 0;
for (TdColumn t : columns) {
for (String pattern : patterns) {
// $NON-NLS-1$ //$NON-NLS-2$
String regex = pattern.replaceAll("%", ".*").toLowerCase();
String name = t.getName().toLowerCase();
// MOD gdbu 2011-1-13 TDQ-4129 Change the way of matching.
if (isMatch(regex, name)) {
resetColumns.add(t);
size++;
if (size > 2000) {
return resetColumns;
}
break;
}
}
}
return resetColumns;
}
use of org.talend.cwm.relational.TdColumn in project tdq-studio-se by Talend.
the class RepositoryNodeHelper method filterColumns.
public static List<TdColumn> filterColumns(List<TdColumn> columns, String columnSetPattern) {
// $NON-NLS-1$
String[] patterns = cleanPatterns(columnSetPattern.split(","));
List<TdColumn> filterMatchingColumnSets = filterMatchingColumns(columns, patterns);
List<TdColumn> filterColumns = new ArrayList<TdColumn>();
for (TdColumn column : filterMatchingColumnSets) {
TdColumn table = column;
filterColumns.add(table);
}
return filterColumns;
}
Aggregations