use of org.talend.core.model.metadata.builder.connection.QueriesConnection in project tdi-studio-se by Talend.
the class DBTreeProvider method createQueries.
private void createQueries(RepositoryNode node, final IRepositoryViewObject repObj, DatabaseConnection metadataConnection, boolean isBuildIn) {
QueriesConnection queriesConnection = metadataConnection.getQueries();
if (queriesConnection != null) {
QueriesConnectionRepositoryObject repositoryObject = new QueriesConnectionRepositoryObject(repObj, queriesConnection);
repositoryObject.setImage(IMAGES_APPEND_TO_EDITOR);
//$NON-NLS-1$
repositoryObject.setSourceName(Messages.getString("DBTreeProvider.sourceName"));
RepositoryNode queriesConnectionNode = new RepositoryNodeExt(repositoryObject, node, ENodeType.REPOSITORY_ELEMENT);
queriesConnectionNode.setProperties(EProperties.CONTENT_TYPE, RepositoryNodeType.QUERIESCONNECTION);
node.getChildren().add(queriesConnectionNode);
createQuery(queriesConnectionNode, repObj, queriesConnection);
}
}
use of org.talend.core.model.metadata.builder.connection.QueriesConnection in project tdi-studio-se by Talend.
the class MetadataColumnComparator method saveEMFQuery.
/**
* method "saveQuery" use save inputed Query to EMF's xml File.
*
* @param repositoryNode current RepositoryNode
* @param query need to save Query
*/
private void saveEMFQuery(String id, Query query, String oldQuery) {
DatabaseConnectionItem item = getEMFItem(id);
if (query != null) {
Connection connection = item.getConnection();
QueriesConnection queriesConnection = connection.getQueries();
if (queriesConnection == null) {
queriesConnection = ConnectionFactory.eINSTANCE.createQueriesConnection();
queriesConnection.setConnection(connection);
connection.setQueries(queriesConnection);
}
boolean isModify = false;
List<Query> queries = queriesConnection.getQuery();
for (Query query2 : queries) {
if (oldQuery != null && (query2.getLabel().equals(oldQuery)) || query2.getLabel().equals(query.getLabel())) {
// reset new label, if changed
query2.setLabel(query.getLabel());
query2.setComment(query.getComment());
query2.setValue(query.getValue());
// add by hywang
query2.setContextMode(query.isContextMode());
// assign id to old query without id
assignQueryId(query2, queriesConnection);
isModify = true;
}
}
if (!isModify) {
// assign id to new query
assignQueryId(query, queriesConnection);
queriesConnection.getQuery().add(query);
}
}
deleteNouseTables(item.getConnection());
saveMetaData(item);
}
use of org.talend.core.model.metadata.builder.connection.QueriesConnection in project tdi-studio-se by Talend.
the class RepositoryValueUtils method updateRepositoryList.
private void updateRepositoryList() {
IProxyRepositoryFactory factory = DesignerPlugin.getDefault().getProxyRepositoryFactory();
tableIdAndDbTypeMap = new HashMap<String, String>();
tableIdAndDbSchemaMap = new HashMap<String, String>();
repositoryTableMap = new HashMap<String, IMetadataTable>();
repositoryQueryStoreMap = new HashMap<String, Query>();
repositoryConnectionItemMap = new HashMap<String, ConnectionItem>();
List<ConnectionItem> metadataConnectionsItem = null;
try {
metadataConnectionsItem = factory.getMetadataConnectionsItem();
} 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);
repositoryDBIdAndNameMap.put(connectionItem.getProperty().getId(), getRepositoryAliasName(connectionItem) + //$NON-NLS-1$
":" + connectionItem.getProperty().getLabel());
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);
}
}
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);
queryStoreNameList.add(name);
queryStoreValuesList.add(value);
}
}
}
queriesMap.put(connectionItem.getProperty().getId(), queryStoreValuesList);
}
}
}
use of org.talend.core.model.metadata.builder.connection.QueriesConnection in project tdi-studio-se by Talend.
the class DynamicTabbedPropertySection method updateRepositoryList.
/**
* ftang Comment method "updateRepositoryList".
*/
@SuppressWarnings("unchecked")
public 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 = factory.getMetadataConnectionsItem();
} 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) || param.getFieldType().equals(EParameterFieldType.SCHEMA_REFERENCE)) {
IElementParameter repositorySchemaType = param.getChildParameters().get(EParameterName.REPOSITORY_SCHEMA_TYPE.getName());
repositorySchemaType.setListItemsDisplayName(repositoryTableNameList);
repositorySchemaType.setListItemsValue(repositoryTableValueList);
if (!repositoryTableMap.keySet().contains(repositorySchemaType.getValue())) {
List<String> list2 = tablesMap.get(elem.getPropertyValue(EParameterName.REPOSITORY_PROPERTY_TYPE.getName()));
boolean isNeeded = list2 != null && !list2.isEmpty();
if (repositoryTableNameList.length > 0 && repositoryConnectionValueList.length > 0 && isNeeded) {
repositorySchemaType.setValue(getDefaultRepository(param, true, repositoryConnectionValueList[0]));
// elem.setPropertyValue(EParameterName.REPOSITORY_SCHEMA_TYPE.getName(),
// getDefaultRepository(
// true, repositoryConnectionValueList[0]));
}
}
}
if (param.getName().equals(EParameterName.REPOSITORY_QUERYSTORE_TYPE.getName())) {
param.setListItemsDisplayName(repositoryQueryNameList);
param.setListItemsValue(repositoryQueryValueList);
if (!repositoryQueryStoreMap.keySet().contains(param.getValue())) {
List<String> list2 = queriesMap.get(elem.getPropertyValue(EParameterName.REPOSITORY_PROPERTY_TYPE.getName()));
boolean isNeeded = list2 != null && !list2.isEmpty();
if (repositoryQueryNameList.length > 0 && repositoryConnectionValueList.length > 0 && isNeeded) {
elem.setPropertyValue(EParameterName.REPOSITORY_QUERYSTORE_TYPE.getName(), getDefaultRepository(elem.getElementParameterFromField(EParameterFieldType.SCHEMA_TYPE), false, repositoryConnectionValueList[0]));
}
}
}
if (param.getName().equals(EParameterName.REPOSITORY_PROPERTY_TYPE.getName())) {
updateRepositoryListExtra(param, repositoryConnectionNameList, repositoryConnectionValueList, false);
}
// // for job settings extra (feature 2710)
// if (param.getName().equals(extraRepositoryPropertyTypeName)) {
// updateRepositoryListExtra(param, repositoryConnectionNameList, repositoryConnectionValueList, true);
// }
}
updateQuery();
}
use of org.talend.core.model.metadata.builder.connection.QueriesConnection in project tdi-studio-se by Talend.
the class DowngradeParameterHelper method getOldLabelFromId.
/**
* DOC nrousseau Comment method "getOldLabelFromId".
*
* @param id
* @param type
* @return
*/
private static String getOldLabelFromId(String id, ERepositoryObjectType type) {
final IProxyRepositoryFactory proxyRepositoryFactory = DesignerPlugin.getDefault().getProxyRepositoryFactory();
try {
ERepositoryObjectType repositoryConnectionsNeeded;
if (type == ERepositoryObjectType.METADATA_CON_QUERY) {
repositoryConnectionsNeeded = ERepositoryObjectType.METADATA_CONNECTIONS;
} else {
repositoryConnectionsNeeded = ERepositoryObjectType.METADATA;
}
List<IRepositoryViewObject> objects = proxyRepositoryFactory.getAll(repositoryConnectionsNeeded);
ConnectionItem connectionItem = null;
for (IRepositoryViewObject object : objects) {
connectionItem = (ConnectionItem) object.getProperty().getItem();
if (type == ERepositoryObjectType.METADATA_CON_QUERY) {
QueriesConnection queries = connectionItem.getConnection().getQueries();
if (queries == null) {
continue;
}
for (Query query : (List<Query>) queries.getQuery()) {
if (query.getId().equals(id)) {
return connectionItem.getProperty().getId() + SEPARATOR + query.getLabel();
}
}
} else if (type == ERepositoryObjectType.METADATA_CON_TABLE) {
for (MetadataTable table : (Set<MetadataTable>) ConnectionHelper.getTables(connectionItem.getConnection())) {
if (table.getId().equals(id)) {
return connectionItem.getProperty().getId() + SEPARATOR + table.getLabel();
}
}
}
}
} catch (PersistenceException e) {
return null;
}
return null;
}
Aggregations