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;
}
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;
}
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;
}
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);
}
}
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());
}
}
Aggregations