use of org.talend.repository.nosql.exceptions.NoSQLExtractSchemaException 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;
}
use of org.talend.repository.nosql.exceptions.NoSQLExtractSchemaException 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;
}
use of org.talend.repository.nosql.exceptions.NoSQLExtractSchemaException in project tbd-studio-se by Talend.
the class MongoDBMetadataProvider method extractTheColumns4Upgrade.
private List<MetadataColumn> extractTheColumns4Upgrade(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;
}
ClassLoader classLoader = NoSQLClassLoaderFactory.getClassLoader(connection);
// $NON-NLS-1$
Class<?> dbObjectClasszz = Class.forName("com.mongodb.DBObject", true, classLoader);
// $NON-NLS-1$
Class<?> documentClasszz = Class.forName("org.bson.Document", true, classLoader);
String documentClassName = documentClasszz.getName();
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$
Iterable<Object> indexIter = (Iterable<Object>) NoSQLReflection.invokeMethod(dbCollection, "listIndexes", new Object[] { dbObjectClasszz });
Iterator<Object> indexIterator = indexIter.iterator();
while (indexIterator.hasNext()) {
Object index = indexIterator.next();
// $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);
}
}
int rowNum = 0;
// $NON-NLS-1$
Iterable<Object> dbCursorIter = (Iterable<Object>) NoSQLReflection.invokeMethod(dbCollection, "find");
Iterator<Object> dbCursorIterator = dbCursorIter.iterator();
while (dbCursorIterator.hasNext()) {
if (rowNum > COUNT_ROWS) {
break;
}
Object dbObject = dbCursorIterator.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 }, Object.class);
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 MongoDBMetadataProvider method extractColumns.
@Override
public List<MetadataColumn> extractColumns(NoSQLConnection connection, String tableName) throws NoSQLExtractSchemaException {
List<MetadataColumn> metadataColumns = new ArrayList<MetadataColumn>();
if (connection == null || tableName == null) {
return metadataColumns;
}
try {
String dbName = NoSQLSchemaUtil.getSchemaNameByTableLabel(connection, tableName);
dbName = ConnectionContextHelper.getParamValueOffContext(connection, dbName);
if (MongoDBConnectionUtil.isUpgradeLatestVersion(connection)) {
metadataColumns.addAll(extractTheColumns4Upgrade(connection, dbName, tableName));
} else {
metadataColumns.addAll(extractTheColumns(connection, dbName, tableName));
}
} 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 CassandraMetadataProvider method extractColumns.
/*
* (non-Javadoc)
*
* @see
* org.talend.repository.nosql.metadata.AbstractMetadataProvider#extractColumns(org.talend.repository.model.nosql
* .NoSQLConnection, java.lang.String)
*/
@Override
public List<MetadataColumn> extractColumns(NoSQLConnection connection, String tableName) throws NoSQLExtractSchemaException {
List<MetadataColumn> metadataColumns = new ArrayList<MetadataColumn>();
if (connection == null || tableName == null) {
return metadataColumns;
}
try {
String dbName = NoSQLSchemaUtil.getSchemaNameByTableLabel(connection, tableName);
metadataColumns.addAll(extractTheColumns(connection, dbName, tableName));
} catch (Exception e) {
throw new NoSQLExtractSchemaException(e);
}
return metadataColumns;
}
Aggregations