public String getProfileName() { return _database.getProfileName(); }
/** * Constructs a runnable to execute a group of SQL statements. * * @param request the plan request * @param databaseIdentifier the database identifier * @param postRun the runnable which will be invoked at last */ public GroupPlanSupportRunnable(PlanRequest request, DatabaseIdentifier databaseIdentifier, Runnable postRun) { super(request, databaseIdentifier.getProfileName(), databaseIdentifier.getDBname()); this._postRun = postRun; }
public IControlConnection getControlConnection(DatabaseIdentifier databaseIdentifier) { IControlConnection controlConnection = (IControlConnection) _controlConnectionMap.get(databaseIdentifier); if (controlConnection == null) { IControlConnection[] cc = getControlConnection(databaseIdentifier.getProfileName()); if (cc != null && cc.length > 0) { controlConnection = cc[0]; } } return controlConnection; }
public String encode() { // TODO: currently this method is hard coded. Need to be more extendable. StringBuffer buffer = new StringBuffer(); Map temp = new HashMap(); temp.put(PROP_PROFILE, _database.getProfileName()); temp.put(PROP_DBNAME, _database.getDBname()); temp.put(PROP_TYPE, String.valueOf(_type)); encodeMap(buffer, temp); encodeMap(buffer, propertyMap); return buffer.toString(); }
public IControlConnection[] getControlConnections(String profileName) { List controlConnections = new ArrayList(); //Get key set Set databaseIdentifierSet = _controlConnectionMap.keySet(); Iterator iterator = databaseIdentifierSet.iterator(); List databaseIdentifiers = new ArrayList(); while(iterator.hasNext()) { databaseIdentifiers.add(iterator.next()); } if (databaseIdentifiers.size() < 1) { return new IControlConnection[0]; } for (int i = 0; i < databaseIdentifiers.size(); i++) { DatabaseIdentifier databaseIdentifier = ((DatabaseIdentifier) databaseIdentifiers.get(i)); if (databaseIdentifier.getProfileName().equals(profileName)) { controlConnections.add(_controlConnectionMap.get(databaseIdentifier)); } } return (IControlConnection[]) controlConnections.toArray( new IControlConnection[controlConnections.size()]); }
/** * Closes the connection object. Subclasses may need to do further log or cleanup jobs. * @param connection * @param connId * @param databaseIdentifier * @throws SQLException */ public void closeConnection(Connection connection, int connId, DatabaseIdentifier databaseIdentifier) throws SQLException { ProfileUtil.closeConnection(databaseIdentifier.getProfileName(), databaseIdentifier.getDBname(), connection); }
/** * Returns a connection for caller to use. By default there's no connection pool associated with a connection * profile and this method just ignore the usePool parameter and delegates to {@link #createConnection(String, String)}. * Vendors who has the requirement to use connection pool may override this method. * @param databaseIdentifier the database identifier * @param usePool whether to retrieve the connection from connection pool. * @return a <code>Connection</code> instance * @throws SQLException if database error occurs */ public Connection createConnection(DatabaseIdentifier databaseIdentifier, boolean usePool) throws SQLException, NoSuchProfileException { return createConnection(databaseIdentifier.getProfileName(), databaseIdentifier.getDBname()); } /**
public void initializeFrom(ILaunchConfiguration configuration) { initUI(configuration); disableOptionTabIfNecessary(); if (_databaseIdentifier.getProfileName() != null && !_databaseIdentifier.getProfileName().trim().equals("")) //$NON-NLS-1$ { SQLDevToolsConfiguration conf = SQLToolsFacade.getConfigurationByProfileName(_databaseIdentifier .getProfileName()); IDataServerLaunchPreferenceSection accessor = (IDataServerLaunchPreferenceSection) _sections.get(conf .getDatabaseVendorDefinitionId().toString()); if (accessor == null) { return; } IPreferenceStore store = RoutineEditorActivator.getDefault().getPreferenceStore(); accessor.launchConfigurationInitialize(configuration, store); } }
/** * Construct a ServerIdentifier from a connection profile. * @param profileName * @return */ public static ServerIdentifier getServerIdentifier(DatabaseIdentifier databaseIdentifier) { ProfileManager pManager = ProfileManager.getInstance(); IConnectionProfile connProfile1 = pManager.getProfileByName(databaseIdentifier.getProfileName()); if(connProfile1 == null) { return null; } Properties profile1Props = connProfile1.getBaseProperties(); //TODO CONN won't support host and port anymore? // String host = profile1Props.getProperty(HOST); // String port = profile1Props.getProperty(PORT); String host = null; String port = null; String url = profile1Props.getProperty(URL); DBHelper helper = SQLToolsFacade.getDBHelper(databaseIdentifier); return helper.getServerIdentifier(host, port, url, ProfileUtil.getDatabaseVendorDefinitionId(databaseIdentifier.getProfileName())); }
public Connection createConnection(String[] connId) throws SQLException, CoreException, NoSuchProfileException { // using connection pool for debugging may produce unexpected results SQLDevToolsConfiguration f = SQLToolsFacade .getConfigurationByProfileName(getDatabaseIdentifier() .getProfileName()); ConnectionService conService = f.getConnectionService(); Connection con = conService.createConnection(getDatabaseIdentifier() .getProfileName(), getDatabaseIdentifier().getDBname()); if (connId != null && connId.length == 1) { connId[0] = "0"; } return con; }
/** * Gets the shared connection from the connection profile * TODO Now this method delegates to IConnectionProfile, which doesn't manage a connection for each * database. * @param databaseIdentifier database identifier used to locate the connection profile * @return the shared connection managed by the connection profile * @throws SQLException * @throws NoSuchProfileException */ public static Connection getReusableConnection(DatabaseIdentifier databaseIdentifier) throws SQLException, NoSuchProfileException { IConnectionProfile profile = getProfile(databaseIdentifier.getProfileName()); if (!profile.isConnected()) { throw new SQLException(NLS.bind(Messages.ProfileUtil_error_not_connected, (new Object[]{databaseIdentifier.getProfileName()}))); } IManagedConnection managedConn = profile.getManagedConnection("java.sql.Connection"); if (managedConn == null || !managedConn.isConnected()) { throw new SQLException(NLS.bind(Messages.ProfileUtil_error_getReusableConnection, (new Object[]{databaseIdentifier.toString()}))); } IConnection iconn = managedConn.getConnection(); DBHelper helper = SQLToolsFacade.getDBHelper(databaseIdentifier); Connection conn = (Connection)iconn.getRawConnection(); helper.switchDatabase(databaseIdentifier, conn); return conn; }
public OperationCommand getOperationCommand() { if (_operationCommand == null) { String parentDspName = _parentDisplayName == null ? Messages.GroupSQLResultRunnable_group_exec : _parentDisplayName; _operationCommand = new OperationCommand(getActionType(), parentDspName, getConsumerName(), //$NON-NLS-2$ _databaseIdentifier.getProfileName(), _databaseIdentifier.getDBname()); } return _operationCommand; } }
protected OperationCommand createDefaultOperationCommand() { return new OperationCommand(getActionType(), _sql, getConsumerName(), _databaseIdentifier.getProfileName(), _databaseIdentifier.getDBname()); }
protected OperationCommand createDefaultOperationCommand() { return new OperationCommand(getActionType(), _detailSql, getConsumerName(), _databaseIdentifier.getProfileName(), _databaseIdentifier.getDBname()); }
/** * Parse the given sp definition and returns the parameter name/IASTSQLParam pairs. * * @param databaseIdentifier used to determine the db type * @param sp the sp definition * @return */ public static HashMap getSPParams(DatabaseIdentifier databaseIdentifier, String sp) { HashMap map = new HashMap(); SQLParser parser = SQLToolsFacade.getSQLParser(databaseIdentifier.getProfileName(), ""); IDocument doc = new Document(sp); ParsingResult result = parser.parse(sp, new ParserParameters(false)); HashMap params = result.getParameters(doc, doc.getLength() - 1); return params; }
/** * Checks the validity of the unquoted identifier and unquotes content if necessary. * * @param id original identifier * @return */ public static String unquoteWhenNecessary(String id, DatabaseIdentifier databaseIdentifier) { if (id == null || id.equals("") || databaseIdentifier == null) { return id; } String newId = SQLUtil.unquote(id); SQLDevToolsConfiguration conf = SQLToolsFacade.getConfigurationByProfileName(databaseIdentifier.getProfileName()); IIdentifierValidator validator = conf.getSQLService().getIdentifierValidator(); if (validator != null) { ValidatorMessage msg = validator.isValid(newId, IIdentifierValidator.IDENTIFIER_TYPE_UNKNOW, databaseIdentifier); if (msg == null || !ValidatorMessage.hasError(msg, ValidatorMessage.ERROR)) { return newId; } } return id; }
/** * Disposes the resources. Child class can override this method, but * normally should call super.dispose() */ protected void dispose() { try { IConnectionProfile profile = ProfileUtil .getProfile(_databaseIdentifier.getProfileName()); IManagedConnection managedConn = profile .getManagedConnection("java.sql.Connection"); managedConn.removeConnectionListener(_managedConnectionListener); } catch (NoSuchProfileException e) { //ignore, this happens when the connection profile is deleted } catch (Exception e) { EditorCorePlugin.getDefault().log(e); } }
/** * Creates a launch configuration that can be used to launch a ILaunch that debug an external client connection. * * @param sd * @param connid * @return */ public static ILaunchConfigurationWorkingCopy createExternalClientConfiguration(DatabaseIdentifier databaseIdentifier, String connid) throws CoreException { ILaunchConfigurationWorkingCopy wc = null; ILaunchConfigurationType configType = getLaunchConfigType(); wc = configType.newInstance(null, "externalCon" + connid); wc.setAttribute(ROUTINE_LAUNCH_PROFILENAME, databaseIdentifier.getProfileName()); wc.setAttribute(ROUTINE_LAUNCH_DATABASENAME, databaseIdentifier.getDBname()); wc.setAttribute(ROUTINE_LAUNCH_EXTERNALID, connid); return wc; }
public static void saveTrigger(ILaunchConfigurationWorkingCopy configuration, ProcIdentifier proc, String sql) { configuration.setAttribute(ROUTINE_LAUNCH_PROFILENAME, proc == null ? "" : proc.getDatabaseIdentifier().getProfileName()); configuration.setAttribute(ROUTINE_LAUNCH_DATABASENAME, proc == null ? "" : proc.getDatabaseIdentifier().getDBname()); configuration.setAttribute(ROUTINE_LAUNCH_PROCID, proc == null ? "" : proc.encode()); configuration.setAttribute(ROUTINE_LAUNCH_TYPE, 0); configuration.setAttribute(ROUTINE_LAUNCH_SQL, sql); }
/** * Constructs an AbstractControlConnection. * * @param manager * {@link EditorCorePlugin#getControlConnectionManager()} * @param databaseIdentifier * contains connection profile info and database name */ public AbstractControlConnection(IControlConnectionManager manager, DatabaseIdentifier databaseIdentifier) { Assert.isTrue(manager instanceof ControlConnectionManager); this._manager = (ControlConnectionManager) manager; this._databaseIdentifier = databaseIdentifier; try { IConnectionProfile profile = ProfileUtil .getProfile(databaseIdentifier.getProfileName()); IManagedConnection managedConn = profile .getManagedConnection("java.sql.Connection"); _managedConnectionListener = new SQLToolsManagedConnectionListener(); managedConn.addConnectionListener(_managedConnectionListener); } catch (Exception e) { EditorCorePlugin.getDefault().log(e); } }