use of org.talend.repository.nosql.exceptions.NoSQLExtractSchemaException in project tbd-studio-se by Talend.
the class AbstractNoSQLRetrieveSchemaForm method addSchemaFields.
protected void addSchemaFields(Composite parent) {
// $NON-NLS-1$
Group schemaGroup = Form.createGroup(parent, 1, Messages.getString("AbstractNoSQLRetrieveSchemaForm.schemaGroup"));
Composite filterComposite = new Composite(schemaGroup, SWT.NONE);
GridLayout gridLayout = new GridLayout(2, false);
filterComposite.setLayout(gridLayout);
GridData filterCompGridData = new GridData(GridData.FILL_HORIZONTAL);
filterComposite.setLayoutData(filterCompGridData);
// $NON-NLS-1$
filterText = new LabelledText(filterComposite, Messages.getString("AbstractNoSQLRetrieveSchemaForm.nameFilter"), 1);
ScrolledComposite scrolledComposite = new ScrolledComposite(schemaGroup, SWT.H_SCROLL | SWT.V_SCROLL | SWT.NONE);
scrolledComposite.setExpandHorizontal(true);
scrolledComposite.setExpandVertical(true);
scrolledComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
schemaViewer = new ContainerCheckedTreeViewer(scrolledComposite, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION) {
@Override
protected void doCheckStateChanged(Object element) {
super.doCheckStateChanged(element);
performCheckStateChanged((INoSQLSchemaNode) element);
}
};
schemaViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
schemaViewer.setUseHashlookup(true);
schemaViewer.addFilter(new SchemaViewerFilter());
schemaTree = schemaViewer.getTree();
schemaTree.setHeaderVisible(true);
schemaTree.setLinesVisible(true);
scrolledComposite.setContent(schemaTree);
scrolledComposite.setMinSize(schemaTree.computeSize(SWT.DEFAULT, SWT.DEFAULT));
TreeColumnLayout tcLayout = new TreeColumnLayout();
scrolledComposite.setLayout(tcLayout);
TreeColumn column1 = new TreeColumn(schemaTree, SWT.LEFT);
// $NON-NLS-1$
column1.setText(Messages.getString("AbstractNoSQLRetrieveSchemaForm.name"));
column1.setWidth(300);
column1.setResizable(true);
tcLayout.setColumnData(column1, new ColumnWeightData(40, 150));
TreeColumn column2 = new TreeColumn(schemaTree, SWT.LEFT);
// $NON-NLS-1$
column2.setText(Messages.getString("AbstractNoSQLRetrieveSchemaForm.type"));
column2.setWidth(150);
column2.setResizable(true);
tcLayout.setColumnData(column2, new ColumnWeightData(25, 100));
TreeColumn column3 = new TreeColumn(schemaTree, SWT.LEFT);
// $NON-NLS-1$
column3.setText(Messages.getString("AbstractNoSQLRetrieveSchemaForm.colNum"));
column3.setWidth(130);
column3.setResizable(true);
tcLayout.setColumnData(column3, new ColumnWeightData(20, 50));
TreeColumn column4 = new TreeColumn(schemaTree, SWT.LEFT);
// $NON-NLS-1$
column4.setText(Messages.getString("AbstractNoSQLRetrieveSchemaForm.creationStauts"));
column4.setWidth(120);
column4.setResizable(true);
tcLayout.setColumnData(column4, new ColumnWeightData(15, 70));
try {
List<INoSQLSchemaNode> nodes = wizardPageProvider.createSchemaNodes(getConnection());
NoSQLSelectorTreeViewerProvider viewProvider = new NoSQLSelectorTreeViewerProvider();
schemaViewer.setContentProvider(viewProvider);
schemaViewer.setLabelProvider(viewProvider);
schemaViewer.setInput(nodes);
} catch (NoSQLExtractSchemaException e) {
ExceptionHandler.process(e);
}
}
use of org.talend.repository.nosql.exceptions.NoSQLExtractSchemaException in project tbd-studio-se by Talend.
the class MongoDBMetadataProvider method extractTheColumns.
private List<MetadataColumn> extractTheColumns(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;
}
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$
List<Object> indexes = (List<Object>) NoSQLReflection.invokeMethod(dbCollection, "getIndexInfo", new Object[0]);
for (Object index : indexes) {
// $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);
}
}
// $NON-NLS-1$
Object dbCursor = NoSQLReflection.invokeMethod(dbCollection, "find");
// $NON-NLS-1$
String documentClassName = "com.mongodb.BasicDBObject";
int rowNum = 0;
while ((Boolean) NoSQLReflection.invokeMethod(dbCursor, "hasNext")) {
// $NON-NLS-1$
if (rowNum > COUNT_ROWS) {
break;
}
// $NON-NLS-1$
Object dbObject = NoSQLReflection.invokeMethod(dbCursor, "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 });
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;
}
use of org.talend.repository.nosql.exceptions.NoSQLExtractSchemaException in project tbd-studio-se by Talend.
the class AbstractNoSQLSchemaForm method pressGuessSchemaButton.
protected void pressGuessSchemaButton() {
boolean doit = true;
if (tableEditorView.getMetadataEditor().getBeanCount() > 0) {
doit = // $NON-NLS-1$
MessageDialog.openConfirm(// $NON-NLS-1$
getShell(), // $NON-NLS-1$
Messages.getString("AbstractNoSQLSchemaForm.DialogUpdateTitle"), // $NON-NLS-1$
Messages.getString("AbstractNoSQLSchemaForm.DialogUpdateMsg"));
}
if (doit) {
List<MetadataColumn> metadataColumns = new ArrayList<MetadataColumn>();
IMetadataProvider metadataProvider = NoSQLRepositoryFactory.getInstance().getMetadataProvider(getConnection().getDbType());
if (metadataProvider != null) {
String tableName = tableCombo.getText();
try {
metadataColumns = metadataProvider.extractColumns(getConnection(), tableName);
} catch (NoSQLExtractSchemaException e) {
ExceptionHandler.process(e);
}
}
tableEditorView.getMetadataEditor().removeAll();
tableEditorView.getMetadataEditor().addAll(metadataColumns);
}
updateGuessSchemaButton();
changeTableNavigatorStatus(checkFieldsValue());
}
use of org.talend.repository.nosql.exceptions.NoSQLExtractSchemaException in project tbd-studio-se by Talend.
the class Neo4jMetadataProvider method extractTheColumns.
private List<MetadataColumn> extractTheColumns(NoSQLConnection connection, String cypher) throws NoSQLExtractSchemaException {
List<MetadataColumn> metadataColumns = new ArrayList<MetadataColumn>();
Object db = null;
try {
ClassLoader classLoader = NoSQLClassLoaderFactory.getClassLoader(connection);
Neo4jConnectionUtil.closeConnections();
Iterator<Map<String, Object>> resultIterator = null;
if (Neo4jConnectionUtil.isVersionSince32(connection)) {
return getTheColumns(connection, classLoader, cypher);
} else {
db = Neo4jConnectionUtil.getDB(connection);
if (db == null) {
return metadataColumns;
}
resultIterator = Neo4jConnectionUtil.getResultIterator(connection, cypher, db);
if (resultIterator == null) {
return metadataColumns;
}
List<String> columnLabels = new ArrayList<String>();
int rowNum = 0;
while (resultIterator.hasNext()) {
if (rowNum > COUNT_ROWS) {
break;
}
rowNum++;
Map<String, Object> row = (Map<String, Object>) resultIterator.next();
for (Entry<String, Object> column : row.entrySet()) {
String key = column.getKey();
Object value = column.getValue();
if (StringUtils.isEmpty(key) || value == null) {
continue;
}
addMetadataColumns(classLoader, db, key, value, metadataColumns, columnLabels, Neo4jConnectionUtil.isVersion1(connection));
}
}
}
} catch (Exception e) {
throw new NoSQLExtractSchemaException(e);
} finally {
if (db != null) {
Neo4jConnectionUtil.shutdownNeo4JDb(db);
}
}
return metadataColumns;
}
use of org.talend.repository.nosql.exceptions.NoSQLExtractSchemaException in project tbd-studio-se by Talend.
the class CassandraMetadataProvider method extractTheColumns.
private List<MetadataColumn> extractTheColumns(NoSQLConnection connection, String ksName, String cfName) throws NoSQLExtractSchemaException {
List<MetadataColumn> metadataColumns = new ArrayList<MetadataColumn>();
ICassandraMetadataHandler metadataHandler = CassandraConnectionUtil.getMetadataHandler(connection);
try {
List<Object> columndfs = metadataHandler.getColumns(connection, ksName, cfName);
for (Object columndf : columndfs) {
MetadataColumn column = ConnectionFactory.eINSTANCE.createMetadataColumn();
String colName = metadataHandler.getColumnName(connection, columndf);
colName = MetadataToolHelper.validateValue(colName);
column.setName(colName);
column.setLabel(colName);
String talendType = metadataHandler.getColumnTalendType(columndf);
column.setTalendType(talendType);
String dbType = metadataHandler.getColumnDbType(columndf);
column.setSourceType(dbType);
metadataColumns.add(column);
}
} catch (Exception e) {
throw new NoSQLExtractSchemaException(e);
}
return metadataColumns;
}
Aggregations