use of net.sourceforge.sqlexplorer.dbproduct.User in project tdq-studio-se by Talend.
the class SqlexplorerService method findSqlExplorerTableNode.
/*
* (non-Javadoc)
*
* @see
* org.talend.dataprofiler.service.ISqlexplorerService#findSqlExplorerTableNode(org.talend.core.model.metadata.builder
* .connection.Connection, orgomg.cwm.objectmodel.core.Package, java.lang.String, java.lang.String)
*/
@Override
public void findSqlExplorerTableNode(Connection providerConnection, Package parentPackageElement, String tableName, String activeTabName) {
// Open data explore perspective.
if (GlobalServiceRegister.getDefault().isServiceRegistered(ITDQRepositoryService.class)) {
ITDQRepositoryService service = (ITDQRepositoryService) GlobalServiceRegister.getDefault().getService(ITDQRepositoryService.class);
if (service != null) {
service.changePerspectiveAction(SQLExplorerPluginPerspective.class.getName());
} else {
return;
}
}
Collection<Alias> aliases = SQLExplorerPlugin.getDefault().getAliasManager().getAliases();
String url = JavaSqlFactory.getURL(providerConnection);
User currentUser = null;
for (Alias alias : aliases) {
if (alias.getUrl().equals(url)) {
currentUser = alias.getDefaultUser();
OpenPasswordConnectDialogAction openDlgAction = new OpenPasswordConnectDialogAction(alias, alias.getDefaultUser(), false);
openDlgAction.run();
break;
}
}
// MOD qiongli bug 13093,2010-7-2,show the warning dialog when the table can't be found
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
if (currentUser == null) {
// $NON-NLS-1$
MessageDialog.openWarning(// $NON-NLS-1$
shell, // $NON-NLS-1$
Messages.getString("SqlExplorerBridge.Warning"), // $NON-NLS-1$
Messages.getString("SqlExplorerBridge.MissTable") + tableName);
return;
}
DatabaseNode root = currentUser.getMetaDataSession().getRoot();
root.load();
List<INode> catalogs = root.getCatalogs();
List<INode> schemas = root.getSchemas();
Catalog catalog = SwitchHelpers.CATALOG_SWITCH.doSwitch(parentPackageElement);
Schema schema = SwitchHelpers.SCHEMA_SWITCH.doSwitch(parentPackageElement);
INode catalogOrSchemaNode = null;
// TDQ-12005: fix Exasol/hive(TDQ-11887: hdp20 at least) database can view index/keys well
String findCatalogNodeName = isExasol(url) ? "EXA_DB" : (isHive(url) ? "NoCatalog" : "");
if (!findCatalogNodeName.equals("") && !catalogs.isEmpty()) {
for (INode catalogNode : catalogs) {
if (findCatalogNodeName.equalsIgnoreCase(catalogNode.getName())) {
catalogOrSchemaNode = catalogNode;
break;
}
}
} else {
if (catalog != null) {
// MOD klliu bug 14662 2010-08-05
if (!catalogs.isEmpty()) {
for (INode catalogNode : catalogs) {
if (parentPackageElement.getName().equalsIgnoreCase(catalogNode.getName())) {
catalogOrSchemaNode = catalogNode;
break;
}
}
} else {
catalogOrSchemaNode = root;
}
} else {
// MOD by zshen for 20517
if (schemas.isEmpty()) {
// the case for mssql/postgrel(which have catalog and schema structor) schema analysis.
Catalog shcmeaOfCatalogNode = CatalogHelper.getParentCatalog(parentPackageElement);
for (INode catalogNode : catalogs) {
if (shcmeaOfCatalogNode != null && shcmeaOfCatalogNode.getName().equalsIgnoreCase(catalogNode.getName())) {
catalogOrSchemaNode = catalogNode;
break;
}
}
}
for (INode schemaNode : schemas) {
if (parentPackageElement.getName().equalsIgnoreCase(schemaNode.getName())) {
catalogOrSchemaNode = schemaNode;
break;
}
}
}
}
// find the table folder node.
if (catalogOrSchemaNode == null) {
// $NON-NLS-1$
throw new NullPointerException(Messages.getString("SqlExplorerBridge.CATORSCHMISNULL"));
}
// catalog node.
if (schema != null) {
if (catalogOrSchemaNode.getSchemaName() == null) {
catalogOrSchemaNode.setSchemaName(schema.getName());
} else if (!StringUtils.equals(catalogOrSchemaNode.getSchemaName(), schema.getName())) {
// if this catalog already loaded its children of some schema, should reload for this schema.
if (catalogOrSchemaNode.isChildrenLoaded()) {
SQLExplorerPlugin.getDefault().getDatabaseStructureView().refreshSessionTrees(currentUser.getMetaDataSession());
List<INode> catalogs2 = currentUser.getMetaDataSession().getRoot().getCatalogs();
if (catalogs2.size() != 0) {
for (INode catalogNode : catalogs2) {
if (catalogOrSchemaNode.getName().equalsIgnoreCase(catalogNode.getName())) {
catalogOrSchemaNode = catalogNode;
catalogOrSchemaNode.setSchemaName(schema.getName());
break;
}
}
}
}
}
}
// ~
INode[] childNodes = catalogOrSchemaNode.getChildNodes();
// need to find the schema and load the table nodes
if (isNetezza(url)) {
SchemaNode sNode = getNetezzaSchema(childNodes, JavaSqlFactory.getUsername(providerConnection));
if (sNode != null) {
childNodes = sNode.getChildNodes();
}
}
TableFolderNode tableFolderNode = null;
for (INode node : childNodes) {
if ("TABLE".equals(node.getQualifiedName())) {
// $NON-NLS-1$
tableFolderNode = (TableFolderNode) node;
break;
}
}
if (tableFolderNode == null) {
// $NON-NLS-1$
log.fatal(Messages.getString("SqlExplorerBridge.TABLE_FOLDER_NULL0"));
} else {
INode[] tableNodes = tableFolderNode.getChildNodes();
for (INode node : tableNodes) {
if (tableName.equalsIgnoreCase(node.getName())) {
DetailTabManager.setActiveTabName(activeTabName);
DatabaseStructureView dsView = SQLExplorerPlugin.getDefault().getDatabaseStructureView();
dsView.setSessionSelectionNode(currentUser.getMetaDataSession(), new StructuredSelection(node));
// MOD qiongli bug 13093,2010-7-2
SQLExplorerPlugin.getDefault().getConnectionsView().getTreeViewer().setSelection(new StructuredSelection(currentUser));
return;
}
}
}
// $NON-NLS-1$
MessageDialog.openWarning(// $NON-NLS-1$
shell, // $NON-NLS-1$
Messages.getString("SqlExplorerBridge.Warning"), // $NON-NLS-1$
Messages.getString("SqlExplorerBridge.MissTable") + tableName);
}
use of net.sourceforge.sqlexplorer.dbproduct.User in project tdq-studio-se by Talend.
the class SqlexplorerService method addConnetionAliasToSQLPlugin.
@Override
public void addConnetionAliasToSQLPlugin(ModelElement... dataproviders) {
SQLExplorerPlugin sqlPlugin = SQLExplorerPlugin.getDefault();
AliasManager aliasManager = sqlPlugin.getAliasManager();
DriverManager driverManager = sqlPlugin.getDriverModel();
List<String> tdqSupportDBType = MetadataConnectionUtils.getTDQSupportDBTemplate();
// if all dataproviders are not supported on DQ side,don't save files SQLAliases.xml and
// SQLDrivers.xml.Otherwise,save it.
AliasAndManaDriverHelper aliasManaDriverHelper = AliasAndManaDriverHelper.getInstance();
for (ModelElement dataProvider : dataproviders) {
try {
Connection connection = SwitchHelpers.CONNECTION_SWITCH.doSwitch(dataProvider);
// MOD bug mzhao filter the other connections except database connection.
if (connection != null && connection instanceof DatabaseConnection) {
// TDQ-8379 do nothing if the database type isn't supproted on DQ side.
DatabaseConnection dbConn = ((DatabaseConnection) connection);
String databaseType = dbConn.getDatabaseType();
if (!tdqSupportDBType.contains(databaseType)) {
continue;
}
// only new Alias when it is not in aliasManager
Alias alias = aliasManager.getAlias(dataProvider.getName());
String url = JavaSqlFactory.getURL(connection);
// if the alias is not null and the url is same with the connection, this means the alias is already
// exist; if the alias is not null but hte url is not same with the connection, this means the
// connection has been overwrite , need to rebuild the alias
boolean aliasExist = alias != null && StringUtils.equals(url, alias.getUrl());
if (!aliasExist) {
if (alias == null) {
alias = new Alias(dataProvider.getName());
}
String user = JavaSqlFactory.getUsername(connection);
// MOD gdbu 2011-3-17 bug 19539
String password = JavaSqlFactory.getPassword(connection);
// ~19539
// user should not be null
// $NON-NLS-1$
user = user == null ? "" : user;
// password should not be null
// $NON-NLS-1$
password = password == null ? "" : password;
// is serialized correctly.
assert user != null;
assert password != null;
User previousUser = new User(user, password);
previousUser.setDatabaseConnection(dbConn);
alias.setDefaultUser(previousUser);
alias.setAutoLogon(false);
alias.setConnectAtStartup(true);
alias.setUrl(url);
ManagedDriver manDr = aliasManaDriverHelper.getManaDriverByConnection(dbConn);
if (manDr == null) {
manDr = aliasManaDriverHelper.createNewManagerDriver(dbConn);
driverManager.addDriver(manDr);
} else if (!manDr.isDriverClassLoaded()) {
this.loadDriverByLibManageSystem(dbConn);
}
if (manDr != null) {
alias.setDriver(manDr);
}
}
if (!aliasManager.contains(alias) && alias.getName() != null) {
aliasManager.addAlias(alias);
}
// MOD Qiongli TDQ-6166 just put once for every Alias
if (sqlPlugin.getPropertyFile().get(alias) == null) {
sqlPlugin.getPropertyFile().put(alias, getPropertyFile(dataProvider));
}
aliasManager.modelChanged();
}
} catch (Throwable e) {
// MOD scorreia 2010-07-24 catch all exceptions
log.error(e, e);
continue;
}
}
}
use of net.sourceforge.sqlexplorer.dbproduct.User in project tdq-studio-se by Talend.
the class NewConnectionDropDownAction method getMenu.
public Menu getMenu(Control parent) {
if (menu != null) {
menu.dispose();
menu = null;
}
for (Alias alias : SQLExplorerPlugin.getDefault().getAliasManager().getAliases()) for (User user : alias.getUsers()) {
if (menu == null)
menu = new Menu(parent);
NewConnection action = new NewConnection(user);
addActionToMenu(menu, action);
}
return menu;
}
use of net.sourceforge.sqlexplorer.dbproduct.User in project tdq-studio-se by Talend.
the class SQLEditorSessionSwitcher method createControl.
@Override
protected Control createControl(Composite parent) {
SQLExplorerPlugin.getDefault().getAliasManager().addListener(this);
_sessionCombo = new Combo(parent, SWT.READ_ONLY);
_sessionCombo.setToolTipText(Messages.getString("SQLEditor.Actions.ChooseSession.ToolTip"));
_sessionCombo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
// change session for this editor
User user = null;
int selIndex = _sessionCombo.getSelectionIndex();
if (selIndex != 0) {
user = sessionIndexes.get(selIndex - 1);
}
// Nothing to do?
if (user != null && _editor.getSession() != null && _editor.getSession().getUser() == user) {
return;
}
// Disconnect from the current session while we try to connect
_editor.setSession(null);
_sessionCombo.deselectAll();
_editor.refreshToolbars();
if (user == null) {
return;
}
// Start the connection job
ConnectionJob.createSession(user.getAlias(), user, SQLEditorSessionSwitcher.this, false);
}
});
setSessionOptions();
if (_sessionCombo.getItemCount() == 1) {
MessageDialog.openInformation(parent.getShell(), Messages.getString("SQLEditor.Actions.ChooseSession.NoConnections.Title"), Messages.getString("SQLEditor.Actions.ChooseSession.NoConnections.Message"));
}
return _sessionCombo;
}
use of net.sourceforge.sqlexplorer.dbproduct.User in project tdq-studio-se by Talend.
the class SQLEditor method setInput.
/*
* (non-JavaDoc)
*
* @see org.eclipse.ui.part.EditorPart#setInput(org.eclipse.ui.IEditorInput)
*/
@Override
protected void setInput(IEditorInput input) {
super.setInput(input);
if (textEditor != null) {
textEditor.setInput(input);
}
// Handle our own form of input
if (input instanceof SQLEditorInput) {
SQLEditorInput sqlInput = (SQLEditorInput) input;
if (input != null) {
User user = sqlInput.getUser();
if (user != null) {
user.queueForNewSession(new SessionEstablishedAdapter() {
@Override
public void sessionEstablished(Session session) {
setSession(session);
}
});
}
isDirty = true;
isUntitled = true;
}
}
// set part name as displayName + " " + version
String partName = input.getName();
if (input instanceof FileEditorInput) {
FileEditorInput fileEditorInput = (FileEditorInput) input;
// $NON-NLS-1$
IPath fileName = fileEditorInput.getPath().removeFileExtension().addFileExtension("properties");
Property property = null;
URI propURI = URI.createFileURI(fileName.toOSString());
Resource resource = new ResourceSetImpl().getResource(propURI, true);
if (resource.getContents() != null) {
Object object = EcoreUtil.getObjectByType(resource.getContents(), PropertiesPackage.eINSTANCE.getProperty());
if (object != null) {
property = (Property) object;
}
}
if (property != null) {
// $NON-NLS-1$
partName = property.getDisplayName() + " " + property.getVersion();
}
}
setPartName(partName);
}
Aggregations