Search in sources :

Example 1 with NoSQLExtractSchemaException

use of org.talend.repository.nosql.exceptions.NoSQLExtractSchemaException in project tbd-studio-se by Talend.

the class CassandraWizardPageProvider method createSchemaNodes.

/*
     * (non-Javadoc)
     *
     * @see
     * org.talend.repository.nosql.ui.provider.IWizardPageProvider#createSchemaNodes(org.talend.repository.model.nosql
     * .NoSQLConnection)
     */
@Override
public List<INoSQLSchemaNode> createSchemaNodes(NoSQLConnection connection) throws NoSQLExtractSchemaException {
    List<INoSQLSchemaNode> schemaNodes = new ArrayList<INoSQLSchemaNode>();
    try {
        String ksName = connection.getAttributes().get(ICassandraAttributies.DATABASE);
        if (connection.isContextMode()) {
            ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(connection);
            ksName = ContextParameterUtils.getOriginalValue(contextType, ksName);
        }
        if (StringUtils.isEmpty(ksName)) {
            List<String> databaseNames = CassandraConnectionUtil.getMetadataHandler(connection).getKeySpaceNames(connection);
            for (String dbn : databaseNames) {
                INoSQLSchemaNode dbNode = new NoSQLSchemaNode();
                dbNode.setName(dbn);
                dbNode.setNodeType(ICassandraConstants.KEY_SPACE);
                dbNode.setSchemaType(ENoSQLSchemaType.DATABASE);
                dbNode.addChildren(addSchemaNodes(connection, dbNode));
                schemaNodes.add(dbNode);
            }
        } else {
            schemaNodes.addAll(addSchemaNodes(connection, null));
        }
    } catch (Exception e) {
        throw new NoSQLExtractSchemaException(e);
    }
    return schemaNodes;
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) INoSQLSchemaNode(org.talend.repository.nosql.model.INoSQLSchemaNode) ArrayList(java.util.ArrayList) NoSQLExtractSchemaException(org.talend.repository.nosql.exceptions.NoSQLExtractSchemaException) NoSQLSchemaNode(org.talend.repository.nosql.model.NoSQLSchemaNode) INoSQLSchemaNode(org.talend.repository.nosql.model.INoSQLSchemaNode) NoSQLServerException(org.talend.repository.nosql.exceptions.NoSQLServerException) NoSQLExtractSchemaException(org.talend.repository.nosql.exceptions.NoSQLExtractSchemaException)

Example 2 with NoSQLExtractSchemaException

use of org.talend.repository.nosql.exceptions.NoSQLExtractSchemaException in project tbd-studio-se by Talend.

the class MongoDBMetadataProvider method extractColumns.

@Override
public List<MetadataColumn> extractColumns(NoSQLConnection connection, INoSQLSchemaNode node) throws NoSQLExtractSchemaException {
    List<MetadataColumn> metadataColumns = new ArrayList<MetadataColumn>();
    if (connection == null || node == null) {
        return metadataColumns;
    }
    try {
        if (IMongoConstants.COLLECTION.equals(node.getNodeType())) {
            String dbName = null;
            INoSQLSchemaNode parent = node.getParent();
            if (parent != null && IMongoConstants.DATABASE.equals(parent.getNodeType())) {
                dbName = parent.getName();
            } else {
                dbName = ConnectionContextHelper.getParamValueOffContext(connection, connection.getAttributes().get(IMongoDBAttributes.DATABASE));
            }
            if (dbName == null) {
                return metadataColumns;
            }
            String collectionName = node.getName();
            if (MongoDBConnectionUtil.isUpgradeLatestVersion(connection)) {
                metadataColumns.addAll(extractTheColumns4Upgrade(connection, dbName, collectionName));
            } else {
                metadataColumns.addAll(extractTheColumns(connection, dbName, collectionName));
            }
        }
    } catch (Exception e) {
        throw new NoSQLExtractSchemaException(e);
    }
    return metadataColumns;
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) INoSQLSchemaNode(org.talend.repository.nosql.model.INoSQLSchemaNode) ArrayList(java.util.ArrayList) NoSQLExtractSchemaException(org.talend.repository.nosql.exceptions.NoSQLExtractSchemaException) NoSQLServerException(org.talend.repository.nosql.exceptions.NoSQLServerException) NoSQLExtractSchemaException(org.talend.repository.nosql.exceptions.NoSQLExtractSchemaException)

Example 3 with NoSQLExtractSchemaException

use of org.talend.repository.nosql.exceptions.NoSQLExtractSchemaException in project tbd-studio-se by Talend.

the class MongoDBMetadataProvider method extractTheColumns4Upgrade.

private List<MetadataColumn> extractTheColumns4Upgrade(NoSQLConnection connection, String dbName, String collectionName) throws NoSQLExtractSchemaException {
    List<MetadataColumn> metadataColumns = new ArrayList<MetadataColumn>();
    try {
        Object db = MongoDBConnectionUtil.getDB(connection, dbName);
        if (db == null) {
            return metadataColumns;
        }
        ClassLoader classLoader = NoSQLClassLoaderFactory.getClassLoader(connection);
        // $NON-NLS-1$
        Class<?> dbObjectClasszz = Class.forName("com.mongodb.DBObject", true, classLoader);
        // $NON-NLS-1$
        Class<?> documentClasszz = Class.forName("org.bson.Document", true, classLoader);
        String documentClassName = documentClasszz.getName();
        List<String> existColumnNames = new ArrayList<String>();
        // $NON-NLS-1$
        Object dbCollection = NoSQLReflection.invokeMethod(db, "getCollection", new Object[] { collectionName });
        Set<String> indexColNames = new HashSet<String>();
        // $NON-NLS-1$
        Iterable<Object> indexIter = (Iterable<Object>) NoSQLReflection.invokeMethod(dbCollection, "listIndexes", new Object[] { dbObjectClasszz });
        Iterator<Object> indexIterator = indexIter.iterator();
        while (indexIterator.hasNext()) {
            Object index = indexIterator.next();
            // $NON-NLS-1$//$NON-NLS-2$
            Object keyObj = NoSQLReflection.invokeMethod(index, "get", new Object[] { "key" });
            if (keyObj != null) {
                // $NON-NLS-1$
                Set<String> indexKeys = (Set<String>) NoSQLReflection.invokeMethod(keyObj, "keySet", new Object[0]);
                indexColNames.addAll(indexKeys);
            }
        }
        int rowNum = 0;
        // $NON-NLS-1$
        Iterable<Object> dbCursorIter = (Iterable<Object>) NoSQLReflection.invokeMethod(dbCollection, "find");
        Iterator<Object> dbCursorIterator = dbCursorIter.iterator();
        while (dbCursorIterator.hasNext()) {
            if (rowNum > COUNT_ROWS) {
                break;
            }
            Object dbObject = dbCursorIterator.next();
            // $NON-NLS-1$
            Set<String> columnNames = (Set<String>) NoSQLReflection.invokeMethod(dbObject, "keySet");
            for (String colName : columnNames) {
                colName = MetadataToolHelper.validateValue(colName);
                if (existColumnNames.contains(colName)) {
                    continue;
                }
                MetadataColumn column = ConnectionFactory.eINSTANCE.createMetadataColumn();
                column.setName(colName);
                column.setLabel(colName);
                // $NON-NLS-1$
                Object value = NoSQLReflection.invokeMethod(dbObject, "get", new Object[] { colName }, Object.class);
                JavaType javaType = null;
                if (value != null) {
                    if (!documentClassName.equals(value.getClass().getName())) {
                        javaType = JavaTypesManager.getJavaTypeFromName(value.getClass().getSimpleName());
                    } else {
                        javaType = JavaTypesManager.OBJECT;
                    }
                }
                if (javaType == null) {
                    javaType = JavaTypesManager.STRING;
                }
                column.setTalendType(javaType.getId());
                if (indexColNames.contains(colName)) {
                    column.setKey(true);
                    column.setNullable(false);
                }
                metadataColumns.add(column);
                existColumnNames.add(colName);
            }
            rowNum++;
        }
    } catch (Exception e) {
        throw new NoSQLExtractSchemaException(e);
    }
    return metadataColumns;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ArrayList(java.util.ArrayList) NoSQLServerException(org.talend.repository.nosql.exceptions.NoSQLServerException) NoSQLExtractSchemaException(org.talend.repository.nosql.exceptions.NoSQLExtractSchemaException) MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) JavaType(org.talend.core.model.metadata.types.JavaType) NoSQLExtractSchemaException(org.talend.repository.nosql.exceptions.NoSQLExtractSchemaException) HashSet(java.util.HashSet)

Example 4 with NoSQLExtractSchemaException

use of org.talend.repository.nosql.exceptions.NoSQLExtractSchemaException in project tbd-studio-se by Talend.

the class MongoDBMetadataProvider method extractColumns.

@Override
public List<MetadataColumn> extractColumns(NoSQLConnection connection, String tableName) throws NoSQLExtractSchemaException {
    List<MetadataColumn> metadataColumns = new ArrayList<MetadataColumn>();
    if (connection == null || tableName == null) {
        return metadataColumns;
    }
    try {
        String dbName = NoSQLSchemaUtil.getSchemaNameByTableLabel(connection, tableName);
        dbName = ConnectionContextHelper.getParamValueOffContext(connection, dbName);
        if (MongoDBConnectionUtil.isUpgradeLatestVersion(connection)) {
            metadataColumns.addAll(extractTheColumns4Upgrade(connection, dbName, tableName));
        } else {
            metadataColumns.addAll(extractTheColumns(connection, dbName, tableName));
        }
    } catch (Exception e) {
        throw new NoSQLExtractSchemaException(e);
    }
    return metadataColumns;
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) ArrayList(java.util.ArrayList) NoSQLExtractSchemaException(org.talend.repository.nosql.exceptions.NoSQLExtractSchemaException) NoSQLServerException(org.talend.repository.nosql.exceptions.NoSQLServerException) NoSQLExtractSchemaException(org.talend.repository.nosql.exceptions.NoSQLExtractSchemaException)

Example 5 with NoSQLExtractSchemaException

use of org.talend.repository.nosql.exceptions.NoSQLExtractSchemaException in project tbd-studio-se by Talend.

the class CassandraMetadataProvider method extractColumns.

/*
     * (non-Javadoc)
     *
     * @see
     * org.talend.repository.nosql.metadata.AbstractMetadataProvider#extractColumns(org.talend.repository.model.nosql
     * .NoSQLConnection, java.lang.String)
     */
@Override
public List<MetadataColumn> extractColumns(NoSQLConnection connection, String tableName) throws NoSQLExtractSchemaException {
    List<MetadataColumn> metadataColumns = new ArrayList<MetadataColumn>();
    if (connection == null || tableName == null) {
        return metadataColumns;
    }
    try {
        String dbName = NoSQLSchemaUtil.getSchemaNameByTableLabel(connection, tableName);
        metadataColumns.addAll(extractTheColumns(connection, dbName, tableName));
    } catch (Exception e) {
        throw new NoSQLExtractSchemaException(e);
    }
    return metadataColumns;
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) ArrayList(java.util.ArrayList) NoSQLExtractSchemaException(org.talend.repository.nosql.exceptions.NoSQLExtractSchemaException) NoSQLServerException(org.talend.repository.nosql.exceptions.NoSQLServerException) NoSQLExtractSchemaException(org.talend.repository.nosql.exceptions.NoSQLExtractSchemaException)

Aggregations

NoSQLExtractSchemaException (org.talend.repository.nosql.exceptions.NoSQLExtractSchemaException)13 ArrayList (java.util.ArrayList)11 MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)10 NoSQLServerException (org.talend.repository.nosql.exceptions.NoSQLServerException)10 INoSQLSchemaNode (org.talend.repository.nosql.model.INoSQLSchemaNode)5 HashSet (java.util.HashSet)2 Set (java.util.Set)2 JavaType (org.talend.core.model.metadata.types.JavaType)2 ContextType (org.talend.designer.core.model.utils.emf.talendfile.ContextType)2 NoSQLSchemaNode (org.talend.repository.nosql.model.NoSQLSchemaNode)2 List (java.util.List)1 Map (java.util.Map)1 TreeColumnLayout (org.eclipse.jface.layout.TreeColumnLayout)1 ColumnWeightData (org.eclipse.jface.viewers.ColumnWeightData)1 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Composite (org.eclipse.swt.widgets.Composite)1 Group (org.eclipse.swt.widgets.Group)1 TreeColumn (org.eclipse.swt.widgets.TreeColumn)1