use of org.talend.core.sqlbuilder.util.ConnectionParameters in project tdi-studio-se by Talend.
the class DBStructureComposite method openNewQueryEditor.
/**
* qzhang Comment method "openNewQueryEditor".
*/
public void openNewQueryEditor() {
final ConnectionParameters connParameters = builderDialog.getConnParameters();
final RepositoryNode selectQuery = this.treeLabelProvider.getSelectedExtReposiotryNode();
expandNodes = new ArrayList<RepositoryNode>();
getNeedExpandedNodes(selectQuery);
if (expandNodes.size() > 0) {
treeViewer.setExpandedElements(expandNodes.toArray(new Object[0]));
}
if (treeViewer.getTree().getItemCount() > 0) {
treeViewer.getTree().setSelection(treeViewer.getTree().getItem(0));
}
Action tempOpenNewEditorAction = new OpenNewEditorAction(treeViewer, builderDialog, connParameters, true);
tempOpenNewEditorAction.run();
}
use of org.talend.core.sqlbuilder.util.ConnectionParameters in project tdi-studio-se by Talend.
the class AbstractElementPropertySectionController method initConnectionParameters.
protected void initConnectionParameters() {
connParameters = null;
IElementParameter basePropertyParameter = null;
for (IElementParameter param : elem.getElementParameters()) {
if (param.getFieldType() == EParameterFieldType.PROPERTY_TYPE) {
if (param.getRepositoryValue().startsWith("DATABASE")) {
basePropertyParameter = param;
break;
}
}
}
// jobsetting view load the db info from current selected category
IElementParameter updateBasePropertyParameter = updateBasePropertyParameter();
if (updateBasePropertyParameter != null && !updateBasePropertyParameter.equals(basePropertyParameter)) {
basePropertyParameter = updateBasePropertyParameter;
}
connParameters = new ConnectionParameters();
//$NON-NLS-1$
String type = getValueFromRepositoryName(elem, "TYPE", basePropertyParameter);
if (type.equals("Oracle") || type.contains("OCLE")) {
IElementParameter ele = elem.getElementParameter("CONNECTION_TYPE");
if (ele != null) {
type = (String) ele.getValue();
} else {
//$NON-NLS-1$
type = "ORACLE_SID";
}
} else if (EDatabaseTypeName.HIVE.getProduct().equalsIgnoreCase(type)) {
// if (EDatabaseVersion4Drivers.HIVE_EMBEDDED.getVersionValue().equals(
// elem.getElementParameter("CONNECTION_MODE").getValue())) {
setHiveRelatedParams(elem);
// }
} else if (EDatabaseTypeName.IMPALA.getProduct().equalsIgnoreCase(type)) {
String distroKey = getValueFromRepositoryName(elem, "DISTRIBUTION");
connParameters.getParameters().put(ConnParameterKeys.CONN_PARA_KEY_IMPALA_DISTRIBUTION, distroKey);
String distroVersion = getValueFromRepositoryName(elem, "IMPALA_VERSION");
connParameters.getParameters().put(ConnParameterKeys.CONN_PARA_KEY_IMPALA_VERSION, distroVersion);
}
// Get real hsqldb type
if (type.equals(EDatabaseTypeName.HSQLDB.name()) && getValueFromRepositoryName(elem, "RUNNING_MODE").equals("HSQLDB_INPROGRESS_PERSISTENT")) {
//$NON-NLS-1$
type = EDatabaseTypeName.HSQLDB_IN_PROGRESS.getDisplayName();
}
connParameters.setDbType(type);
//$NON-NLS-1$
String driverName = getValueFromRepositoryName(elem, "DB_VERSION", basePropertyParameter);
String dbVersionName = EDatabaseVersion4Drivers.getDbVersionName(type, driverName);
if (EDatabaseTypeName.HIVE.getProduct().equalsIgnoreCase(type)) {
if (EDatabaseVersion4Drivers.HIVE_EMBEDDED.getVersionValue().equals(elem.getElementParameter("CONNECTION_MODE").getValue())) {
connParameters.setDbVersion(EDatabaseVersion4Drivers.HIVE_EMBEDDED.getVersionValue());
} else {
connParameters.setDbVersion(EDatabaseVersion4Drivers.HIVE.getVersionValue());
}
} else {
connParameters.setDbVersion(dbVersionName);
}
connParameters.setNode(elem);
String selectedComponentName = (String) elem.getPropertyValue(EParameterName.UNIQUE_NAME.getName());
connParameters.setSelectedComponentName(selectedComponentName);
connParameters.setFieldType(paramFieldType);
if (elem instanceof Node && !((Node) elem).getMetadataList().isEmpty()) {
connParameters.setMetadataTable(((Node) elem).getMetadataList().get(0));
}
connParameters.setSchemaRepository(EmfComponent.REPOSITORY.equals(elem.getPropertyValue(EParameterName.SCHEMA_TYPE.getName())));
connParameters.setFromDBNode(true);
//$NON-NLS-1$
connParameters.setQuery("");
List<? extends IElementParameter> list = elem.getElementParameters();
boolean end = false;
for (int i = 0; i < list.size() && !end; i++) {
IElementParameter param = list.get(i);
if (param.getFieldType() == EParameterFieldType.MEMO_SQL) {
connParameters.setNodeReadOnly(param.isReadOnly());
end = true;
}
}
//$NON-NLS-1$
Object value = elem.getPropertyValue("USE_EXISTING_CONNECTION");
IElementParameter compList = elem.getElementParameterFromField(EParameterFieldType.COMPONENT_LIST);
if (value != null && (value instanceof Boolean) && ((Boolean) value) && compList != null) {
Object compValue = compList.getValue();
if (compValue != null && !compValue.equals("")) {
//$NON-NLS-1$
List<? extends INode> nodes = part.getProcess().getGraphicalNodes();
for (INode node : nodes) {
if (node.getUniqueName().equals(compValue) && (node instanceof Node)) {
connectionNode = node;
break;
}
}
if (connectionNode == null) {
nodes = part.getProcess().getGeneratingNodes();
for (INode node : nodes) {
if (node.getUniqueName().equals(compValue) && (node instanceof INode)) {
connectionNode = node;
break;
}
}
}
if (connectionNode != null) {
setAllConnectionParameters(type, connectionNode);
}
}
} else {
setAllConnectionParameters(null, elem);
}
if (connectionNode != null) {
setConnectionParameterNames(connectionNode, connParameters, basePropertyParameter);
} else {
setConnectionParameterNames(elem, connParameters, basePropertyParameter);
}
}
use of org.talend.core.sqlbuilder.util.ConnectionParameters in project tdi-studio-se by Talend.
the class OpenQueryAction method run.
@Override
public void run() {
RepositoryNode node = (RepositoryNode) getStructuredSelection().getFirstElement();
if (node == null) {
return;
}
if (node.getProperties(EProperties.CONTENT_TYPE) == RepositoryNodeType.QUERY) {
List<String> repositoryName = repositoryNodeManager.getALLReposotoryNodeNames();
ConnectionParameters connectionParameters = new ConnectionParameters();
IRepositoryViewObject repViewObject = node.getObject();
if (repViewObject instanceof QueryRepositoryObject) {
QueryRepositoryObject queryRepObj = (QueryRepositoryObject) repViewObject;
Query query = queryRepObj.getQuery();
connectionParameters.setQueryObject(query);
dialog.setConnParameters(connectionParameters);
}
connectionParameters.setQuery(dialog.getConnParameters().getQuery());
connectionParameters.setShowDesignerPage(false);
dialog.openEditor(node, repositoryName, connectionParameters, false);
}
}
use of org.talend.core.sqlbuilder.util.ConnectionParameters in project tdi-studio-se by Talend.
the class ReadQueriesAction method doRun.
@Override
protected void doRun() {
IStructuredSelection selection = (IStructuredSelection) getSelection();
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
if (repositoryNode == null && selection != null) {
repositoryNode = (RepositoryNode) selection.getFirstElement();
}
DatabaseConnectionItem dbConnectionItem = null;
ConnectionParameters connParameters = new ConnectionParameters();
if (repositoryNode.getObjectType() == ERepositoryObjectType.METADATA_CONNECTIONS) {
dbConnectionItem = (DatabaseConnectionItem) repositoryNode.getObject().getProperty().getItem();
connParameters.setRepositoryName(repositoryNode.getObject().getLabel());
connParameters.setRepositoryId(repositoryNode.getObject().getId());
//$NON-NLS-1$
connParameters.setQuery("");
} else if (repositoryNode.getObjectType() == ERepositoryObjectType.METADATA_CON_QUERY) {
QueryRepositoryObject queryRepositoryObject = (QueryRepositoryObject) repositoryNode.getObject();
dbConnectionItem = (DatabaseConnectionItem) queryRepositoryObject.getProperty().getItem();
connParameters.setRepositoryName(dbConnectionItem.getProperty().getLabel());
connParameters.setRepositoryId(dbConnectionItem.getProperty().getId());
connParameters.setQueryObject(queryRepositoryObject.getQuery());
connParameters.setQuery(queryRepositoryObject.getQuery().getValue());
// first open Sql Builder,set true
connParameters.setFirstOpenSqlBuilder(true);
}
Display display = Display.getCurrent();
if (display == null) {
display = Display.getDefault();
}
Shell parentShell = new Shell(display);
TextUtil.setDialogTitle(TextUtil.SQL_BUILDER_TITLE_REP);
Connection connection = dbConnectionItem.getConnection();
String selectedContext = null;
if (connection.isContextMode()) {
ContextItem contextItem = ContextUtils.getContextItemById2(connection.getContextId());
if (contextItem != null && connection.isContextMode()) {
ContextSetsSelectionDialog setsDialog = new ContextSetsSelectionDialog(null, contextItem, false);
setsDialog.open();
selectedContext = setsDialog.getSelectedContext();
}
}
SQLBuilderDialog dial = new SQLBuilderDialog(parentShell, repositoryNode, selectedContext);
dial.setReadOnly(true);
if (connection instanceof DatabaseConnection) {
IMetadataConnection imetadataConnection = ConvertionHelper.convert(connection, true);
connParameters.setSchema(imetadataConnection.getSchema() == null ? "" : imetadataConnection.getSchema());
UIUtils.checkConnection(parentShell, imetadataConnection);
}
connParameters.setNodeReadOnly(true);
connParameters.setFromRepository(true);
dial.setConnParameters(connParameters);
dial.open();
refresh(repositoryNode);
}
use of org.talend.core.sqlbuilder.util.ConnectionParameters in project tdi-studio-se by Talend.
the class EditQueriesAction method doRun.
@Override
protected void doRun() {
IStructuredSelection selection = (IStructuredSelection) getSelection();
if (repositoryNode == null && selection != null) {
repositoryNode = (RepositoryNode) selection.getFirstElement();
}
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
IRepositoryViewObject nodeObject = repositoryNode.getObject();
boolean locked = false;
if (!factory.getRepositoryContext().isEditableAsReadOnly()) {
if (nodeObject.getRepositoryStatus() == ERepositoryStatus.LOCK_BY_OTHER) {
locked = true;
}
}
// Avoid to delete node which is locked.
if (locked || RepositoryManager.isOpenedItemInEditor(nodeObject)) {
final String title = "Impossible to edit queries";
String nodeName = nodeObject.getRepositoryObjectType().getLabel();
final String message = "item is already locked by another user.";
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
MessageDialog dialog = new MessageDialog(new Shell(), title, null, message, MessageDialog.ERROR, new String[] { IDialogConstants.OK_LABEL }, 0);
dialog.open();
}
});
return;
}
DatabaseConnectionItem dbConnectionItem = null;
boolean readOnly = false;
ConnectionParameters connParameters = new ConnectionParameters();
if (repositoryNode.getObjectType() == ERepositoryObjectType.METADATA_CONNECTIONS) {
dbConnectionItem = (DatabaseConnectionItem) repositoryNode.getObject().getProperty().getItem();
connParameters.setRepositoryName(repositoryNode.getObject().getLabel());
connParameters.setRepositoryId(repositoryNode.getObject().getId());
//$NON-NLS-1$
connParameters.setQuery("");
} else if (repositoryNode.getObjectType() == ERepositoryObjectType.METADATA_CON_QUERY) {
QueryRepositoryObject queryRepositoryObject = (QueryRepositoryObject) repositoryNode.getObject();
readOnly = SubItemHelper.isDeleted(queryRepositoryObject.getAbstractMetadataObject());
dbConnectionItem = (DatabaseConnectionItem) queryRepositoryObject.getProperty().getItem();
connParameters.setRepositoryName(dbConnectionItem.getProperty().getLabel());
connParameters.setRepositoryId(dbConnectionItem.getProperty().getId());
connParameters.setQueryObject(queryRepositoryObject.getQuery());
connParameters.setQuery(queryRepositoryObject.getQuery().getValue());
// first open Sql Builder,set true
connParameters.setFirstOpenSqlBuilder(true);
} else if (repositoryNode.getObjectType() == ERepositoryObjectType.METADATA_CON_TABLE) {
dbConnectionItem = (DatabaseConnectionItem) repositoryNode.getObject().getProperty().getItem();
connParameters.setRepositoryName(dbConnectionItem.getProperty().getLabel());
connParameters.setRepositoryId(dbConnectionItem.getProperty().getId());
connParameters.setMetadataTable((MetadataTableRepositoryObject) repositoryNode.getObject());
//$NON-NLS-1$
connParameters.setQuery("");
}
IRepositoryView viewPart = getViewPart();
Display display = null;
if (viewPart != null) {
display = viewPart.getViewer().getControl().getDisplay();
} else {
display = Display.getCurrent();
if (display == null) {
display = Display.getDefault();
}
}
Shell parentShell = new Shell(display);
TextUtil.setDialogTitle(TextUtil.SQL_BUILDER_TITLE_REP);
Connection connection = dbConnectionItem.getConnection();
String selectedContext = null;
if (connection.isContextMode()) {
ContextItem contextItem = ContextUtils.getContextItemById2(connection.getContextId());
if (contextItem != null && connection.isContextMode()) {
ContextSetsSelectionDialog setsDialog = new ContextSetsSelectionDialog(null, contextItem, false);
setsDialog.open();
selectedContext = setsDialog.getSelectedContext();
}
}
SQLBuilderDialog dial = new SQLBuilderDialog(parentShell, repositoryNode, selectedContext);
dial.setReadOnly(readOnly);
if (connection instanceof DatabaseConnection) {
IMetadataConnection imetadataConnection = ConvertionHelper.convert(connection, true);
connParameters.setSchema(imetadataConnection.getSchema() == null ? "" : imetadataConnection.getSchema());
UIUtils.checkConnection(parentShell, imetadataConnection);
}
connParameters.setNodeReadOnly(readOnly);
connParameters.setFromRepository(true);
dial.setConnParameters(connParameters);
dial.open();
IRepositoryView view = getViewPart();
if (view != null) {
view.refreshView();
}
}
Aggregations