use of org.talend.core.model.metadata.builder.connection.QueriesConnection in project tdi-studio-se by Talend.
the class QueryTypeController method createComboCommand.
/*
* (non-Javadoc)
*
* @see
* org.talend.designer.core.ui.editor.properties.controllers.AbstractRepositoryController#createComboCommand(org
* .eclipse.swt.custom.CCombo)
*/
@Override
protected Command createComboCommand(CCombo combo) {
String paramName = (String) combo.getData(PARAMETER_NAME);
IElementParameter param = elem.getElementParameter(paramName);
IElementParameter switchParam = elem.getElementParameter(EParameterName.REPOSITORY_ALLOW_AUTO_SWITCH.getName());
String name = param.getName();
String value = combo.getText();
for (int j = 0; j < param.getListItemsValue().length; j++) {
if (combo.getText().equals(param.getListItemsDisplayName()[j])) {
value = (String) param.getListItemsValue()[j];
}
}
if (name.equals(EParameterName.QUERYSTORE_TYPE.getName())) {
if (elem instanceof Node) {
String querySelected;
Query repositoryQuery = null;
// Map<String, Query> repositoryQueryStoreMap = this.dynamicProperty.getRepositoryQueryStoreMap();
IElementParameter repositoryParam = param.getParentParameter().getChildParameters().get(EParameterName.REPOSITORY_QUERYSTORE_TYPE.getName());
querySelected = (String) repositoryParam.getValue();
/* value can be devided means the value like "connectionid - label" */
String[] keySplitValues = querySelected.toString().split(" - ");
if (keySplitValues.length > 1) {
String connectionId = querySelected.split(" - ")[0];
String queryLabel = querySelected.split(" - ")[1];
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
Item item = null;
try {
IRepositoryViewObject repobj = factory.getLastVersion(connectionId);
if (repobj != null) {
Property property = repobj.getProperty();
if (property != null) {
item = property.getItem();
}
}
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
if (item != null && item instanceof DatabaseConnectionItem) {
Connection conn = ((DatabaseConnectionItem) item).getConnection();
if (conn instanceof DatabaseConnection) {
DatabaseConnection dbconn = (DatabaseConnection) conn;
QueriesConnection queryConnection = dbconn.getQueries();
for (Query query : queryConnection.getQuery()) {
if (query.getLabel().equals(queryLabel)) {
repositoryQuery = query;
break;
}
}
}
}
}
if (switchParam != null) {
switchParam.setValue(Boolean.FALSE);
}
if (repositoryQuery != null) {
return new RepositoryChangeQueryCommand(elem, repositoryQuery, name, value);
} else {
return new PropertyChangeCommand(elem, name, value);
}
}
}
return null;
}
use of org.talend.core.model.metadata.builder.connection.QueriesConnection in project tdi-studio-se by Talend.
the class ControllerRepositoryValueHander method fastRepositoryUpdateQuery.
private void fastRepositoryUpdateQuery(IElementParameter param) {
if (param != null && param.getValue() != null) {
String queryIdAndName = (String) param.getValue();
//$NON-NLS-1$
String[] names = queryIdAndName.split(" - ");
if (names.length < 2) {
return;
}
String linkedRepository = names[0];
String queryName = null;
if (names.length == 2) {
queryName = names[1];
} else if (names.length > 2) {
queryName = queryIdAndName.substring(linkedRepository.length() + 3);
}
if (lastItemUsed != null) {
if (!linkedRepository.equals(lastItemUsed.getProperty().getId())) {
lastItemUsed = null;
}
}
if (lastItemUsed == null) {
IProxyRepositoryFactory factory = DesignerPlugin.getDefault().getProxyRepositoryFactory();
Item item;
try {
IRepositoryViewObject object = factory.getLastVersion(linkedRepository);
if (object == null) {
return;
}
item = object.getProperty().getItem();
lastItemUsed = (ConnectionItem) item;
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
}
Assert.isTrue(lastItemUsed instanceof DatabaseConnectionItem);
QueriesConnection queriesConnection = ((DatabaseConnection) lastItemUsed.getConnection()).getQueries();
EList<Query> queries = queriesConnection.getQuery();
String repositoryAliasName = RepositoryObjectHelper.getRepositoryAliasName(lastItemUsed);
for (Query currentQuery : queries) {
if (currentQuery.getLabel().equals(queryName)) {
String displayName = //$NON-NLS-1$
repositoryAliasName + ":" + lastItemUsed.getProperty().getLabel() + " - " + //$NON-NLS-1$
currentQuery.getLabel();
param.setListItemsDisplayName(new String[] { displayName });
param.setListItemsValue(new String[] { (String) param.getValue() });
/* query cache should be deleted ,bug 16969 */
// dynamicProperty.getRepositoryQueryStoreMap().clear();
// dynamicProperty.getRepositoryQueryStoreMap().put((String) param.getValue(), currentQuery);
}
}
}
}
use of org.talend.core.model.metadata.builder.connection.QueriesConnection in project tdi-studio-se by Talend.
the class DynamicComposite method updateRepositoryList.
/**
* ftang Comment method "updateRepositoryList".
*/
//$NON-NLS-1$
@SuppressWarnings("unchecked")
private void updateRepositoryList() {
IProxyRepositoryFactory factory = DesignerPlugin.getDefault().getProxyRepositoryFactory();
tableIdAndDbTypeMap = new HashMap<String, String>();
tableIdAndDbSchemaMap = new HashMap<String, String>();
List<ConnectionItem> metadataConnectionsItem = null;
String[] repositoryTableNameList = new String[] {};
String[] repositoryTableValueList = new String[] {};
String[] repositoryConnectionNameList = new String[] {};
String[] repositoryConnectionValueList = new String[] {};
String[] repositoryQueryNameList = new String[] {};
String[] repositoryQueryValueList = new String[] {};
try {
metadataConnectionsItem = getConnectionItems();
} catch (PersistenceException e) {
throw new RuntimeException(e);
}
if (metadataConnectionsItem != null) {
repositoryTableMap.clear();
repositoryQueryStoreMap.clear();
repositoryConnectionItemMap.clear();
tablesMap.clear();
queriesMap.clear();
List<String> tableNamesList = new ArrayList<String>();
List<String> tableValuesList = new ArrayList<String>();
List<String> queryStoreNameList = new ArrayList<String>();
List<String> queryStoreValuesList = new ArrayList<String>();
for (ConnectionItem connectionItem : metadataConnectionsItem) {
Connection connection = connectionItem.getConnection();
if (!connection.isReadOnly()) {
//$NON-NLS-1$
repositoryConnectionItemMap.put(connectionItem.getProperty().getId() + "", connectionItem);
for (Object tableObj : ConnectionHelper.getTables(connection)) {
org.talend.core.model.metadata.builder.connection.MetadataTable table;
table = (org.talend.core.model.metadata.builder.connection.MetadataTable) tableObj;
if (factory.getStatus(connectionItem) != ERepositoryStatus.DELETED) {
if (!factory.isDeleted(table)) {
String name = //$NON-NLS-1$
getRepositoryAliasName(connectionItem) + ":" + connectionItem.getProperty().getLabel() + " - " + //$NON-NLS-1$
table.getLabel();
//$NON-NLS-1$
String value = connectionItem.getProperty().getId() + " - " + table.getLabel();
IMetadataTable newTable = ConvertionHelper.convert(table);
repositoryTableMap.put(value, newTable);
if (connection instanceof DatabaseConnection) {
String dbType = ((DatabaseConnection) connection).getDatabaseType();
String schema = ((DatabaseConnection) connection).getUiSchema();
tableIdAndDbTypeMap.put(newTable.getId(), dbType);
if (schema != null && !schema.equals("")) {
//$NON-NLS-1$
tableIdAndDbSchemaMap.put(newTable.getId(), schema);
}
}
addOrderDisplayNames(tableValuesList, tableNamesList, value, name);
// tableNamesList.add(name);
// tableValuesList.add(value);
}
}
}
}
tablesMap.put(connectionItem.getProperty().getId(), tableValuesList);
if (connection instanceof DatabaseConnection && !connection.isReadOnly()) {
DatabaseConnection dbConnection = (DatabaseConnection) connection;
QueriesConnection queriesConnection = dbConnection.getQueries();
if (queriesConnection != null) {
List<Query> qs = queriesConnection.getQuery();
for (Query query : qs) {
String name = //$NON-NLS-1$
getRepositoryAliasName(connectionItem) + ":" + connectionItem.getProperty().getLabel() + " - " + //$NON-NLS-1$
query.getLabel();
//$NON-NLS-1$
String value = connectionItem.getProperty().getId() + " - " + query.getLabel();
repositoryQueryStoreMap.put(value, query);
addOrderDisplayNames(queryStoreValuesList, queryStoreNameList, value, name);
// queryStoreNameList.add(name);
// queryStoreValuesList.add(value);
}
}
}
queriesMap.put(connectionItem.getProperty().getId(), queryStoreValuesList);
}
repositoryTableNameList = tableNamesList.toArray(new String[0]);
repositoryTableValueList = tableValuesList.toArray(new String[0]);
repositoryQueryNameList = queryStoreNameList.toArray(new String[0]);
repositoryQueryValueList = queryStoreValuesList.toArray(new String[0]);
}
initMaps();
for (int i = 0; i < elem.getElementParameters().size(); i++) {
IElementParameter param = elem.getElementParameters().get(i);
if (param.getFieldType().equals(EParameterFieldType.SCHEMA_TYPE)) {
IElementParameter repositoryType = param.getChildParameters().get(EParameterName.REPOSITORY_SCHEMA_TYPE.getName());
repositoryType.setListItemsDisplayName(repositoryTableNameList);
repositoryType.setListItemsValue(repositoryTableValueList);
if (!repositoryTableMap.keySet().contains(repositoryType.getValue())) {
IElementParameter repositoryPropertyType = elem.getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE, param.getCategory());
if (repositoryPropertyType != null) {
List<String> list2 = tablesMap.get(repositoryPropertyType.getChildParameters().get(EParameterName.REPOSITORY_PROPERTY_TYPE.getName()).getValue());
boolean isNeeded = list2 != null && !list2.isEmpty();
if (repositoryTableNameList.length > 0 && repositoryConnectionValueList.length > 0 && isNeeded) {
repositoryType.setValue(getDefaultRepository(param, true, repositoryConnectionValueList[0]));
}
}
}
}
if (param.getFieldType().equals(EParameterFieldType.QUERYSTORE_TYPE)) {
IElementParameter repositoryType = param.getChildParameters().get(EParameterName.REPOSITORY_QUERYSTORE_TYPE.getName());
repositoryType.setListItemsDisplayName(repositoryQueryNameList);
repositoryType.setListItemsValue(repositoryQueryValueList);
if (!repositoryQueryStoreMap.keySet().contains(repositoryType.getValue())) {
IElementParameter repositoryPropertyType = elem.getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE, param.getCategory());
if (repositoryPropertyType != null) {
List<String> list2 = queriesMap.get(repositoryPropertyType.getChildParameters().get(EParameterName.REPOSITORY_PROPERTY_TYPE.getName()).getValue());
boolean isNeeded = list2 != null && !list2.isEmpty();
if (repositoryQueryNameList.length > 0 && repositoryConnectionValueList.length > 0 && isNeeded) {
repositoryType.setValue(getDefaultRepository(elem.getElementParameterFromField(EParameterFieldType.SCHEMA_TYPE), false, repositoryConnectionValueList[0]));
}
}
}
}
if (param.getFieldType().equals(EParameterFieldType.PROPERTY_TYPE)) {
IElementParameter repositoryType = param.getChildParameters().get(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
List<String> nameList = new ArrayList<String>();
List<String> valueList = new ArrayList<String>();
updateRepositoryListExtra(repositoryType, nameList, valueList, false);
repositoryConnectionNameList = nameList.toArray(new String[0]);
repositoryConnectionValueList = valueList.toArray(new String[0]);
}
}
}
use of org.talend.core.model.metadata.builder.connection.QueriesConnection in project tdi-studio-se by Talend.
the class EMFRepositoryNodeManager method getQueryByLabel.
/**
* dev Comment method "getQueryByLabel".
*
* @param node all repository node Type
* @param label search query label
* @return
*/
@SuppressWarnings("unchecked")
public Query getQueryByLabel(RepositoryNode node, String label) {
root = null;
if (node.getObjectType().equals(ERepositoryObjectType.METADATA_CON_QUERY)) {
root = node.getParent().getParent();
} else {
root = SQLBuilderRepositoryNodeManager.getRoot(node);
}
if (root == null) {
return null;
}
DatabaseConnectionItem item = SQLBuilderRepositoryNodeManager.getItem(root);
DatabaseConnection connection = (DatabaseConnection) item.getConnection();
QueriesConnection queriesConnection = connection.getQueries();
if (queriesConnection != null) {
List<Query> queries = queriesConnection.getQuery();
for (Query query : queries) {
if (query.getLabel().equals(label)) {
return query;
}
}
}
return null;
}
use of org.talend.core.model.metadata.builder.connection.QueriesConnection in project tdi-studio-se by Talend.
the class MetadataColumnComparator method getALLQueryLabels.
/**
* dev Comment method "getALLQueryLabels".
*
* @param repositoryNode current RepositoryNode.
* @return all QueryLabels in Emf.
*/
@SuppressWarnings("unchecked")
public List<String> getALLQueryLabels(RepositoryNode repositoryNode) {
List<String> allQueries = new ArrayList<String>();
DatabaseConnectionItem item = getEMFItem(repositoryNode.getObject().getId());
DatabaseConnection connection = (DatabaseConnection) item.getConnection();
QueriesConnection queriesConnection = connection.getQueries();
if (queriesConnection != null) {
List<Query> qs = queriesConnection.getQuery();
for (Query q1 : qs) {
allQueries.add(q1.getLabel());
}
}
return allQueries;
}
Aggregations