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