Search in sources :

Example 11 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, org.talend.repository.nosql.model.INoSQLSchemaNode)
     */
@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 (ICassandraConstants.COLUMN_FAMILY.equals(node.getNodeType()) || ICassandraConstants.SUPER_COLUMN_FAMILY.equals(node.getNodeType())) {
            String dbName = null;
            INoSQLSchemaNode parent = node.getParent();
            if (parent != null && ICassandraConstants.KEY_SPACE.equals(parent.getNodeType())) {
                dbName = parent.getName();
            } else {
                dbName = connection.getAttributes().get(ICassandraAttributies.DATABASE);
            }
            if (dbName == null) {
                return metadataColumns;
            }
            String collectionName = node.getName();
            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 12 with NoSQLExtractSchemaException

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

the class MongoDBWizardPageProvider method createSchemaNodes.

@Override
public List<INoSQLSchemaNode> createSchemaNodes(NoSQLConnection connection) throws NoSQLExtractSchemaException {
    List<INoSQLSchemaNode> schemaNodes = new ArrayList<INoSQLSchemaNode>();
    try {
        String dbName = connection.getAttributes().get(IMongoDBAttributes.DATABASE);
        if (connection.isContextMode()) {
            ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(connection);
            dbName = ContextParameterUtils.getOriginalValue(contextType, dbName);
        }
        Object mongoClient = MongoDBConnectionUtil.getMongoVersioned(connection);
        if (StringUtils.isEmpty(dbName)) {
            List<String> databaseNames = MongoDBConnectionUtil.getDatabaseNames(connection, mongoClient);
            for (String dbn : databaseNames) {
                INoSQLSchemaNode dbNode = new NoSQLSchemaNode();
                dbNode.setName(dbn);
                dbNode.setNodeType(IMongoConstants.DATABASE);
                dbNode.setSchemaType(ENoSQLSchemaType.DATABASE);
                dbNode.addChildren(addSchemaNodes(connection, mongoClient, dbNode));
                schemaNodes.add(dbNode);
            }
        } else {
            schemaNodes.addAll(addSchemaNodes(connection, mongoClient, 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 13 with NoSQLExtractSchemaException

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

the class RetrieveColumnRunnable method run.

/*
     * (non-Javadoc)
     *
     * @see java.lang.Runnable#run()
     */
@Override
public void run() {
    if (isCanceled()) {
        return;
    }
    lock.lock();
    node.setStatus(PENDING);
    node.setRetrieved(true);
    try {
        MetadataTable table = RelationalFactory.eINSTANCE.createTdTable();
        String nodeName = node.getName();
        String tableName = MetadataToolHelper.validateTableName(nodeName);
        table.setName(nodeName);
        table.setLabel(tableName);
        table.setId(ProxyRepositoryFactory.getInstance().getNextId());
        List<MetadataColumn> columns = metadataProvider.extractColumns(connection, node);
        table.getColumns().addAll(columns);
        if (!ConnectionHelper.getTables(connection).contains(table)) {
            NoSQLSchemaUtil.addTable2Connection(connection, table, NoSQLRepositoryUtil.getDBName(node));
            hitTablesMap.put(tableName, table);
        }
        table.getAdditionalProperties().putAll(node.getParameters());
        if (columns != null) {
            node.setColNum(columns.size());
        }
        node.setHasProblem(false);
        node.setStatus(SUCCESS);
    } catch (Exception e) {
        NoSQLExtractSchemaException exception = new NoSQLExtractSchemaException(e);
        node.setHasProblem(true);
        node.setStatus(ERROR_MSG);
        // $NON-NLS-1$ //$NON-NLS-2$
        log.error("Retrieve '" + node.getName() + "' unsuccessfully.", exception);
    } finally {
        lock.unlock();
        refresh(node);
    }
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) NoSQLExtractSchemaException(org.talend.repository.nosql.exceptions.NoSQLExtractSchemaException) 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