Search in sources :

Example 96 with TdColumn

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);
        }
    }
}
Also used : Path(org.eclipse.core.runtime.Path) INode(org.talend.core.model.process.INode) TdTable(org.talend.cwm.relational.TdTable) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) PersistenceException(org.talend.commons.exception.PersistenceException) ElementParameter(org.talend.designer.core.model.components.ElementParameter) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) TdColumn(org.talend.cwm.relational.TdColumn) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Property(org.talend.core.model.properties.Property) Test(org.junit.Test)

Example 97 with TdColumn

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);
    }
}
Also used : TdColumn(org.talend.cwm.relational.TdColumn) TdSqlDataType(org.talend.cwm.relational.TdSqlDataType)

Example 98 with TdColumn

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);
}
Also used : TdColumn(org.talend.cwm.relational.TdColumn) MetadataColumnRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataColumnRepositoryObject)

Example 99 with TdColumn

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;
}
Also used : TdColumn(org.talend.cwm.relational.TdColumn) ArrayList(java.util.ArrayList)

Example 100 with TdColumn

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;
}
Also used : TdColumn(org.talend.cwm.relational.TdColumn) ArrayList(java.util.ArrayList)

Aggregations

TdColumn (org.talend.cwm.relational.TdColumn)182 ArrayList (java.util.ArrayList)49 TdTable (org.talend.cwm.relational.TdTable)49 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)40 Test (org.junit.Test)37 ColumnSet (orgomg.cwm.resource.relational.ColumnSet)35 MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)28 RepositoryNode (org.talend.repository.model.RepositoryNode)26 IRepositoryNode (org.talend.repository.model.IRepositoryNode)23 Indicator (org.talend.dataquality.indicators.Indicator)20 Catalog (orgomg.cwm.resource.relational.Catalog)19 Connection (org.talend.core.model.metadata.builder.connection.Connection)17 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)16 TdSqlDataType (org.talend.cwm.relational.TdSqlDataType)16 Analysis (org.talend.dataquality.analysis.Analysis)16 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)15 IndicatorParameters (org.talend.dataquality.indicators.IndicatorParameters)14 DBColumnRepNode (org.talend.dq.nodes.DBColumnRepNode)14 Package (orgomg.cwm.objectmodel.core.Package)14 MetadataColumnRepositoryObject (org.talend.core.repository.model.repositoryObject.MetadataColumnRepositoryObject)13