Search in sources :

Example 11 with INoSQLSchemaNode

use of org.talend.repository.nosql.model.INoSQLSchemaNode in project tbd-studio-se by Talend.

the class MongoDBWizardPageProvider method addSchemaNodes.

private List<INoSQLSchemaNode> addSchemaNodes(NoSQLConnection connection, Object mongoClient, INoSQLSchemaNode parentNode) throws NoSQLServerException {
    List<INoSQLSchemaNode> schemaNodes = new ArrayList<INoSQLSchemaNode>();
    Set<String> collectionNames = null;
    String dbName = null;
    if (parentNode != null && StringUtils.isNotEmpty(parentNode.getName())) {
        dbName = parentNode.getName();
    }
    if (dbName != null) {
        collectionNames = MongoDBConnectionUtil.getCollectionNames(connection, dbName, mongoClient);
    } else {
        collectionNames = MongoDBConnectionUtil.getCollectionNames(connection, null, mongoClient);
    }
    for (String name : collectionNames) {
        NoSQLSchemaNode node = new NoSQLSchemaNode();
        node.setName(name);
        node.setNodeType(IMongoConstants.COLLECTION);
        node.setSchemaType(ENoSQLSchemaType.TABLE);
        if (parentNode != null) {
            node.setParent(parentNode);
            parentNode.addChild(node);
        } else {
            schemaNodes.add(node);
        }
    }
    return schemaNodes;
}
Also used : INoSQLSchemaNode(org.talend.repository.nosql.model.INoSQLSchemaNode) ArrayList(java.util.ArrayList) NoSQLSchemaNode(org.talend.repository.nosql.model.NoSQLSchemaNode) INoSQLSchemaNode(org.talend.repository.nosql.model.INoSQLSchemaNode)

Example 12 with INoSQLSchemaNode

use of org.talend.repository.nosql.model.INoSQLSchemaNode 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 INoSQLSchemaNode

use of org.talend.repository.nosql.model.INoSQLSchemaNode in project tbd-studio-se by Talend.

the class AbstractNoSQLRetrieveSchemaForm method getExistItem.

private TreeItem getExistItem(MetadataTable table) {
    if (!schemaTree.isDisposed() && table != null && table.eContainer() != null) {
        String parentName = ((orgomg.cwm.objectmodel.core.Package) table.eContainer()).getName();
        TreeItem[] items = schemaTree.getItems();
        for (TreeItem treeItem : items) {
            if (treeItem.getData() != null) {
                ENoSQLSchemaType schemaType = ((INoSQLSchemaNode) treeItem.getData()).getSchemaType();
                if (ENoSQLSchemaType.DATABASE.equals(schemaType)) {
                    for (TreeItem item : treeItem.getItems()) {
                        if (MetadataToolHelper.validateTableName(item.getText(0)).equals(table.getLabel()) && treeItem.getText(0).equals(parentName) && item.getChecked()) {
                            return item;
                        }
                    }
                } else if (ENoSQLSchemaType.TABLE.equals(schemaType)) {
                    if (MetadataToolHelper.validateTableName(treeItem.getText(0)).equals(table.getLabel()) && treeItem.getChecked()) {
                        return treeItem;
                    }
                }
            }
        }
    }
    return null;
}
Also used : INoSQLSchemaNode(org.talend.repository.nosql.model.INoSQLSchemaNode) ENoSQLSchemaType(org.talend.repository.nosql.model.ENoSQLSchemaType) TreeItem(org.eclipse.swt.widgets.TreeItem)

Example 14 with INoSQLSchemaNode

use of org.talend.repository.nosql.model.INoSQLSchemaNode in project tbd-studio-se by Talend.

the class AbstractNoSQLRetrieveSchemaForm method deleteTable.

private void deleteTable(TreeItem item) {
    INoSQLSchemaNode node = (INoSQLSchemaNode) item.getData();
    if (node != null && node.getSchemaType() == ENoSQLSchemaType.TABLE) {
        String tableName = MetadataToolHelper.validateTableName(node.getName());
        NoSQLSchemaUtil.removeTableFromConnection(getConnection(), tableName, NoSQLRepositoryUtil.getDBName(node));
        hitTablesMap.remove(tableName);
        clearItemStatus(node);
        RetrieveColumnRunnable runnable = retrieveSchemaExecutor.getRunnable(node);
        if (runnable != null) {
            runnable.setCanceled(true);
        }
        schemaViewer.refresh(node);
    }
}
Also used : INoSQLSchemaNode(org.talend.repository.nosql.model.INoSQLSchemaNode) RetrieveColumnRunnable(org.talend.repository.nosql.ui.thread.RetrieveColumnRunnable)

Example 15 with INoSQLSchemaNode

use of org.talend.repository.nosql.model.INoSQLSchemaNode in project tbd-studio-se by Talend.

the class AbstractNoSQLRetrieveSchemaForm method getDBItem.

private TreeItem getDBItem(TreeItem treeItem) {
    if (treeItem == null || treeItem.getData() == null) {
        return null;
    }
    INoSQLSchemaNode node = (INoSQLSchemaNode) treeItem.getData();
    ENoSQLSchemaType schemaType = node.getSchemaType();
    if (ENoSQLSchemaType.DATABASE.equals(schemaType)) {
        return treeItem;
    } else {
        return getDBItem(treeItem.getParentItem());
    }
}
Also used : INoSQLSchemaNode(org.talend.repository.nosql.model.INoSQLSchemaNode) ENoSQLSchemaType(org.talend.repository.nosql.model.ENoSQLSchemaType)

Aggregations

INoSQLSchemaNode (org.talend.repository.nosql.model.INoSQLSchemaNode)17 ArrayList (java.util.ArrayList)6 NoSQLExtractSchemaException (org.talend.repository.nosql.exceptions.NoSQLExtractSchemaException)6 TreeItem (org.eclipse.swt.widgets.TreeItem)5 NoSQLSchemaNode (org.talend.repository.nosql.model.NoSQLSchemaNode)5 NoSQLServerException (org.talend.repository.nosql.exceptions.NoSQLServerException)4 ENoSQLSchemaType (org.talend.repository.nosql.model.ENoSQLSchemaType)3 MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)2 ContextType (org.talend.designer.core.model.utils.emf.talendfile.ContextType)2 RetrieveColumnRunnable (org.talend.repository.nosql.ui.thread.RetrieveColumnRunnable)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 TreeColumnLayout (org.eclipse.jface.layout.TreeColumnLayout)1 ColumnWeightData (org.eclipse.jface.viewers.ColumnWeightData)1 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1