Search in sources :

Example 1 with INoSQLSchemaNode

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

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

the class CassandraWizardPageProvider method addNode.

private void addNode(String nodeName, List<INoSQLSchemaNode> schemaNodes, INoSQLSchemaNode parentNode, boolean isSuper) {
    NoSQLSchemaNode node = new NoSQLSchemaNode();
    node.setName(nodeName);
    if (isSuper) {
        node.setNodeType(ICassandraConstants.SUPER_COLUMN_FAMILY);
        node.getParameters().put(ICassandraAttributies.COLUMN_FAMILY_TYPE, ICassandraAttributies.COLUMN_FAMILY_TYPE_SUPER);
    } else {
        node.setNodeType(ICassandraConstants.COLUMN_FAMILY);
        node.getParameters().put(ICassandraAttributies.COLUMN_FAMILY_TYPE, ICassandraAttributies.COLUMN_FAMILY_TYPE_STANDARD);
    }
    node.setSchemaType(ENoSQLSchemaType.TABLE);
    if (parentNode != null) {
        node.setParent(parentNode);
        parentNode.addChild(node);
    } else {
        schemaNodes.add(node);
    }
}
Also used : NoSQLSchemaNode(org.talend.repository.nosql.model.NoSQLSchemaNode) INoSQLSchemaNode(org.talend.repository.nosql.model.INoSQLSchemaNode)

Example 3 with INoSQLSchemaNode

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

the class CassandraWizardPageProvider method addSchemaNodes.

private List<INoSQLSchemaNode> addSchemaNodes(NoSQLConnection connection, INoSQLSchemaNode parentNode) throws NoSQLServerException {
    List<INoSQLSchemaNode> schemaNodes = new ArrayList<INoSQLSchemaNode>();
    Set<String> cfNames = null;
    Set<String> scfNames = null;
    String ksName = connection.getAttributes().get(ICassandraAttributies.DATABASE);
    if (parentNode != null && StringUtils.isNotEmpty(parentNode.getName())) {
        ksName = parentNode.getName();
    }
    ICassandraMetadataHandler metadataHandler = CassandraConnectionUtil.getMetadataHandler(connection);
    if (ksName != null) {
        cfNames = metadataHandler.getColumnFamilyNames(connection, ksName);
        if (!CassandraConnectionUtil.isUpgradeVersion(connection)) {
            scfNames = metadataHandler.getSuperColumnFamilyNames(connection, ksName);
        } else {
            scfNames = new HashSet<String>();
            metadataHandler.closeConnections();
        }
    } else {
        cfNames = metadataHandler.getColumnFamilyNames(connection);
        if (!CassandraConnectionUtil.isUpgradeVersion(connection)) {
            scfNames = metadataHandler.getSuperColumnFamilyNames(connection);
        } else {
            scfNames = new HashSet<String>();
            metadataHandler.closeConnections();
        }
    }
    if (CassandraConnectionUtil.isOldVersion(connection)) {
        collectNodesForOldVersion(schemaNodes, parentNode, cfNames, scfNames);
    } else {
        collectNodes(schemaNodes, parentNode, cfNames, scfNames);
    }
    return schemaNodes;
}
Also used : INoSQLSchemaNode(org.talend.repository.nosql.model.INoSQLSchemaNode) ArrayList(java.util.ArrayList) ICassandraMetadataHandler(org.talend.repository.nosql.db.handler.cassandra.ICassandraMetadataHandler)

Example 4 with INoSQLSchemaNode

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

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

the class AbstractNoSQLRetrieveSchemaForm method addTable.

private void addTable(TreeItem item) {
    INoSQLSchemaNode node = (INoSQLSchemaNode) item.getData();
    if (isExistTable(node, false)) {
        MetadataTable table = getTable(node, false);
        orgomg.cwm.objectmodel.core.Package pack = (orgomg.cwm.objectmodel.core.Package) table.eContainer();
        boolean confirm = MessageDialog.openConfirm(Display.getDefault().getActiveShell(), // $NON-NLS-1$
        Messages.getString("AbstractNoSQLRetrieveSchemaForm.confirm"), // $NON-NLS-1$
        Messages.getString("AbstractNoSQLRetrieveSchemaForm.ConfirmMessage", pack.getName()));
        if (confirm) {
            TreeItem existItem = getExistItem(table);
            if (existItem != null) {
                existItem.setChecked(false);
                deleteTable(existItem);
            }
        } else {
            item.setChecked(false);
            return;
        }
    }
    if (!retrieveSchemaExecutor.isThreadRunning(node) && node.getSchemaType() == ENoSQLSchemaType.TABLE) {
        RetrieveColumnRunnable runnable = new RetrieveColumnRunnable(metadataProvider, getConnection(), node, hitTablesMap) {

            @Override
            protected void refresh(INoSQLSchemaNode schemaNode) {
                refreshTable(schemaNode);
            }
        };
        retrieveSchemaExecutor.execute(runnable);
    }
}
Also used : INoSQLSchemaNode(org.talend.repository.nosql.model.INoSQLSchemaNode) TreeItem(org.eclipse.swt.widgets.TreeItem) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) RetrieveColumnRunnable(org.talend.repository.nosql.ui.thread.RetrieveColumnRunnable)

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