use of org.talend.core.model.metadata.builder.connection.MetadataColumn in project tbd-studio-se by Talend.
the class Neo4jMetadataProvider method addMetadataColumn.
private void addMetadataColumn(String columnName, String columnType, String returnParam, List<MetadataColumn> metadataColumns, List<String> columnLabels) {
MetadataColumn metaColumn = ConnectionFactory.eINSTANCE.createMetadataColumn();
metaColumn.setName(columnName);
metaColumn.setLabel(columnName);
metaColumn.setTalendType(columnType);
EList<TaggedValue> keyTaggedValue = metaColumn.getTaggedValue();
TaggedValue keyTV = CoreFactory.eINSTANCE.createTaggedValue();
keyTV.setTag(INeo4jConstants.RETURN_PARAMETER);
keyTV.setValue(returnParam);
keyTaggedValue.add(keyTV);
metadataColumns.add(metaColumn);
columnLabels.add(metaColumn.getLabel());
}
use of org.talend.core.model.metadata.builder.connection.MetadataColumn 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;
}
use of org.talend.core.model.metadata.builder.connection.MetadataColumn in project tbd-studio-se by Talend.
the class HCatalogRepositoryContentHandler method createPartitionColumns.
private void createPartitionColumns(RepositoryNode tableNode, IRepositoryViewObject repObj, MetadataTable metadataTable) {
List<MetadataColumn> partitionColumns = new ArrayList<MetadataColumn>();
EMap<String, String> properties = metadataTable.getAdditionalProperties();
String partitionStr = properties.get(HCatalogConstants.PARTITIONS);
if (partitionStr != null) {
partitionColumns = ExtractMetaDataFromHCatalog.extractPartitionsByJsonStr(partitionStr);
}
int num = partitionColumns.size();
StringBuffer floderName = new StringBuffer();
// $NON-NLS-1$
floderName.append(Messages.getString("HCatalogRepositoryContentHandler.partitions"));
// $NON-NLS-1$
floderName.append("(");
floderName.append(num);
// $NON-NLS-1$
floderName.append(")");
RepositoryNode columnsNode = new StableRepositoryNode(tableNode, floderName.toString(), ECoreImage.FOLDER_CLOSE_ICON);
tableNode.getChildren().add(columnsNode);
for (MetadataColumn column : partitionColumns) {
if (column == null) {
continue;
}
RepositoryNode columnNode = RepositoryNodeManager.createMataColumnNode(columnsNode, repObj, column);
columnsNode.getChildren().add(columnNode);
}
}
use of org.talend.core.model.metadata.builder.connection.MetadataColumn in project tbd-studio-se by Talend.
the class HCatalogSchemaForm method pressRetreiveSchemaButton.
private void pressRetreiveSchemaButton() {
ConnectionStatus connectionStatus = checkConnection(false);
if (!connectionStatus.getResult()) {
tableSettingsInfoLabel.setText(connectionStatus.getMessageException());
} else {
boolean doit = true;
if (tableEditorView.getMetadataEditor().getBeanCount() > 0) {
doit = // $NON-NLS-1$
MessageDialog.openConfirm(// $NON-NLS-1$
getShell(), // $NON-NLS-1$
Messages.getString("HCatalogSchemaForm.title.confirmChange"), // $NON-NLS-1$
Messages.getString("HCatalogSchemaForm.msg.changeSchema"));
}
if (doit) {
String tableName = metadataTable.getName();
List<MetadataColumn> metadataColumns = null;
List<MetadataColumn> partitionColumns = null;
String partitionJsonStr = null;
try {
metadataColumns = ExtractMetaDataFromHCatalog.extractColumns(getConnection(), tableName);
} catch (Exception e) {
ExceptionHandler.process(e);
return;
}
try {
partitionColumns = ExtractMetaDataFromHCatalog.extractPartitions(getConnection(), tableName);
partitionJsonStr = ExtractMetaDataFromHCatalog.extractPartitionsJsonStr(getConnection(), tableName);
} catch (Exception e) {
// $NON-NLS-1$
log.warn(Messages.getString("HCatalogTableSelectorForm.cannotExtractPartitionsWarn", tableName), e);
}
Map<String, MetadataColumn> partitionColumnsMap = new HashMap<String, MetadataColumn>();
if (partitionColumns != null && partitionColumns.size() > 0) {
for (MetadataColumn column : partitionColumns) {
partitionColumnsMap.put(column.getLabel(), column);
}
}
Iterator<MetadataColumn> columnIterator = metadataColumns.iterator();
while (columnIterator.hasNext()) {
MetadataColumn column = columnIterator.next();
if (partitionColumnsMap.get(column.getLabel()) != null) {
columnIterator.remove();
}
}
tableEditorView.getMetadataEditor().removeAll();
tableEditorView.getMetadataEditor().addAll(metadataColumns);
if (partitionJsonStr != null) {
EMap<String, String> properties = metadataTable.getAdditionalProperties();
properties.put(HCatalogConstants.PARTITIONS, partitionJsonStr);
}
}
}
updateRetreiveSchemaButton();
changeTableNavigatorStatus(checkFieldsValue());
}
use of org.talend.core.model.metadata.builder.connection.MetadataColumn in project tbd-studio-se by Talend.
the class Neo4jMetadataProviderTest method testLocalRetrieveSchema.
@Test
public void testLocalRetrieveSchema() throws Exception {
EMap<String, String> attributes = localConnection.getAttributes();
// $NON-NLS-1$
attributes.put(INeo4jAttributes.REMOTE_SERVER, "false");
attributes.put(INeo4jAttributes.DATABASE_PATH, tmpFolder.getCanonicalPath());
attributes.put(INeo4jAttributes.DB_VERSION, INeo4jConstants.NEO4J_3_2_X);
localConnection.setDbType("NEO4J");
ExecutorService threadExecutor = null;
try {
threadExecutor = Executors.newSingleThreadExecutor();
Future future = threadExecutor.submit(new Runnable() {
public void run() {
try {
Neo4jConnectionUtil.checkConnection(localConnection);
List<MetadataColumn> metadataColumns = new ArrayList<MetadataColumn>();
String cypher = "create (n:Test {first_name : 'Peppa', last_name : 'Pig'})\r\nreturn n;";
IMetadataProvider metadataProvider = NoSQLRepositoryFactory.getInstance().getMetadataProvider(localConnection.getDbType());
metadataColumns = metadataProvider.extractColumns(localConnection, cypher);
String lastName = metadataColumns.get(0).getName();
assertEquals("last_name", lastName);
String firstName = metadataColumns.get(1).getName();
assertEquals("first_name", firstName);
} catch (Exception e) {
fail(e.getMessage());
}
}
});
while (true) {
if (future.get() == null) {
break;
}
Thread.sleep(1000);
}
} catch (Exception exception) {
fail(exception.getMessage());
} finally {
if (threadExecutor != null) {
threadExecutor.shutdown();
threadExecutor = null;
}
}
}
Aggregations