use of org.talend.core.model.properties.DatabaseConnectionItem in project tdi-studio-se by Talend.
the class AddTablesDialog method setRootNode.
//$NON-NLS-1$
@SuppressWarnings("unchecked")
public void setRootNode(RepositoryNode rootNode) {
this.rootNode = rootNode;
DatabaseConnectionItem item = SQLBuilderRepositoryNodeManager.getItem(getRootNode());
tables = new HashSet<MetadataTable>();
tables.addAll(ConnectionHelper.getTables((DatabaseConnection) item.getConnection()));
}
use of org.talend.core.model.properties.DatabaseConnectionItem 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.properties.DatabaseConnectionItem in project tdi-studio-se by Talend.
the class SqlMemoController method findRepositoryItem.
/**
* Find the label of DatabaseConnectionItem that contains current query.
*
* @param queryId
* @return
*/
private DatabaseConnectionItem findRepositoryItem(String queryId) {
try {
//$NON-NLS-1$
String[] names = queryId.split(" - ");
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
IRepositoryViewObject node = factory.getLastVersion(names[0]);
DatabaseConnectionItem item = (DatabaseConnectionItem) node.getProperty().getItem();
return item;
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
return null;
}
use of org.talend.core.model.properties.DatabaseConnectionItem in project tdi-studio-se by Talend.
the class SqlMemoController method refreshConnectionCommand.
private Command refreshConnectionCommand() {
// open sql builder in repository mode, just use query object, no need for connection information
ConnectionParameters connParameters = new ConnectionParameters();
String queryId = (String) elem.getPropertyValue(EParameterName.REPOSITORY_QUERYSTORE_TYPE.getName());
Query query = MetadataToolHelper.getQueryFromRepository(queryId);
DatabaseConnectionItem item = findRepositoryItem(queryId);
if (item != null) {
connParameters.setRepositoryName(item.getProperty().getLabel());
connParameters.setRepositoryId(item.getProperty().getId());
}
connParameters.setQueryObject(query);
connParameters.setQuery(query.getValue());
TextUtil.setDialogTitle(TextUtil.SQL_BUILDER_TITLE_REP);
String processName = null;
if (elem instanceof IProcess) {
processName = ((IProcess) elem).getName();
} else if (elem instanceof INode) {
processName = ((INode) elem).getProcess().getName();
} else if (elem instanceof IConnection) {
processName = ((IConnection) elem).getSource().getProcess().getName();
}
connParameters.setNodeReadOnly(false);
connParameters.setFromRepository(true);
ISQLBuilderService sqlBuilderService = (ISQLBuilderService) GlobalServiceRegister.getDefault().getService(ISQLBuilderService.class);
Dialog sqlBuilder = sqlBuilderService.openSQLBuilderDialog(composite.getShell(), processName, connParameters);
String sql = null;
if (Window.OK == sqlBuilder.open()) {
sql = connParameters.getQuery();
}
if (sql != null && !queryText.isDisposed()) {
queryText.setText(sql);
String propertyName = (String) openSQLEditorButton.getData(PARAMETER_NAME);
return new PropertyChangeCommand(elem, propertyName, sql);
}
return null;
}
use of org.talend.core.model.properties.DatabaseConnectionItem in project tdi-studio-se by Talend.
the class ProjectSettingMultipleThreadDynamicComposite method updateConnectionFromRepository.
private void updateConnectionFromRepository() {
if (repositoryPropertyName == null || repositoryPropertyName.split(":").length != 2 || connectionUpdated) {
return;
}
String[] split = repositoryPropertyName.split(":");
String parentParamName = split[0];
Element elementParams = elem;
IElementParameter elementParameter = elementParams.getElementParameter(parentParamName);
if (elementParameter != null && elementParameter.isShow(elem.getElementParameters()) && elementParameter.getChildParameters() != null) {
if (elementParameter.getChildParameters().get("PROPERTY_TYPE") != null && !EmfComponent.BUILTIN.equals(elementParameter.getChildParameters().get("PROPERTY_TYPE").getValue())) {
DatabaseConnection connection = null;
String id = (String) elementParameter.getChildParameters().get("REPOSITORY_PROPERTY_TYPE").getValue();
// bug 0018192
String propertyType = (String) elementParameter.getChildParameters().get("PROPERTY_TYPE").getValue();
ProxyRepositoryFactory proxyRepositoryFactory = ProxyRepositoryFactory.getInstance();
IRepositoryViewObject lastVersion = null;
if (null != id && !"".equals(id)) {
try {
lastVersion = proxyRepositoryFactory.getLastVersion(id);
if (null == lastVersion && propertyType.equals(EmfComponent.REPOSITORY)) {
List<ConnectionItem> connectionItems = proxyRepositoryFactory.getMetadataConnectionsItem();
if (connectionItems.isEmpty()) {
elem.setPropertyValue("REPOSITORY_PROPERTY_TYPE", "");
ChangeValuesFromRepository changeValuesFromRepository1 = new ChangeValuesFromRepository(elem, null, parentParamName + ":" + "PROPERTY_TYPE", EmfComponent.REPOSITORY);
changeValuesFromRepository1.execute();
}
for (ConnectionItem cItem : connectionItems) {
if (cItem instanceof DatabaseConnectionItem) {
id = cItem.getProperty().getId();
lastVersion = proxyRepositoryFactory.getLastVersion(id);
elem.setPropertyValue("REPOSITORY_PROPERTY_TYPE", id);
break;
}
}
}
} catch (PersistenceException e) {
e.printStackTrace();
}
} else {
try {
List<ConnectionItem> connectionItems = proxyRepositoryFactory.getMetadataConnectionsItem();
for (ConnectionItem cItem : connectionItems) {
if (cItem instanceof DatabaseConnectionItem) {
lastVersion = UpdateRepositoryUtils.getRepositoryObjectById(cItem.getProperty().getId());
id = cItem.getProperty().getId();
lastVersion = UpdateRepositoryUtils.getRepositoryObjectById(id);
elem.setPropertyValue("REPOSITORY_PROPERTY_TYPE", id);
break;
}
}
} catch (PersistenceException e) {
e.printStackTrace();
}
}
if (lastVersion != null && lastVersion.getProperty() != null) {
Item item = lastVersion.getProperty().getItem();
if (item instanceof DatabaseConnectionItem) {
DatabaseConnectionItem dbItem = (DatabaseConnectionItem) item;
connection = (DatabaseConnection) dbItem.getConnection();
}
}
if (connection != null) {
boolean sameValues = true;
for (IElementParameter param : elementParams.getElementParameters()) {
String repositoryValue = param.getRepositoryValue();
if (param.isShow(elementParams.getElementParameters()) && repositoryValue != null && !param.getName().equals("PROPERTY_TYPE")) {
Object repValue = RepositoryToComponentProperty.getValue(connection, repositoryValue, null);
if (repValue == null) {
continue;
}
if (repositoryValue.equals(UpdatesConstants.TYPE)) {
// datebase type
boolean found = false;
String[] list = param.getListRepositoryItems();
for (int i = 0; (i < list.length) && (!found); i++) {
if (repValue.equals(list[i])) {
found = true;
}
}
if (!found) {
sameValues = false;
break;
}
} else {
// check the value
if (!param.getValue().equals(repValue)) {
sameValues = false;
break;
}
}
}
}
if (!sameValues) {
ChangeValuesFromRepository changeValuesFromRepository = new ChangeValuesFromRepository(elem, connection, repositoryPropertyName, id);
changeValuesFromRepository.execute();
connectionUpdated = true;
}
}
// bug 0018192
// else {
// change to build in
// ChangeValuesFromRepository changeValuesFromRepository1 = new ChangeValuesFromRepository(elem,
// null,
// parentParamName + ":" + "PROPERTY_TYPE", EmfComponent.BUILTIN);
// changeValuesFromRepository1.execute();
// }
}
}
}
Aggregations