/** * Return a database-specific utility class. * */ public DBHelper getDBHelper() { return new DBHelper(); }
/** * Returns all error messages by following the exception chain. * @param exception * @return */ public String getExceptionChainMessage(SQLException exception) { if (exception != null) { StringBuffer sb = new StringBuffer(exception.getMessage()).append(LINE_SEPARATOR); if (exception.getNextException() != null && exception.getNextException() != exception) { sb.append(getExceptionChainMessage(exception.getNextException())); } return sb.toString(); } return null; } }
/** * Returns a ProcIdentifer based on the profilename and object name & type * @see {@link #getProcIdentifier(DatabaseIdentifier, String, int, String, String, String)} * * Note: Do not override this method. * @param databaseIdentifier * @param dbObjectName * @param dbObjectType @see <code>ProcIdentifier</code> * @return a ProcIdentifer object * */ public ProcIdentifier getProcIdentifier( DatabaseIdentifier databaseIdentifier, String dbObjectName, int dbObjectType, String tableName, String ownerName) { String tableOwnerName = null; if (dbObjectType == ProcIdentifier.TYPE_TRIGGER) { //assume they are the same tableOwnerName = ownerName; } return getProcIdentifier(databaseIdentifier, dbObjectName, dbObjectType, tableName, ownerName, tableOwnerName); }
h = config.getDBHelper(); } else { h = new DBHelper(); Schema schema = ((Routine) routine).getSchema(); if (routine instanceof Procedure) { proc = h.getProcIdentifier(databaseIdentifier, routine .getName(), ProcIdentifier.TYPE_SP, null, schema .getName()); } else if (routine instanceof Function) { proc = h.getProcIdentifier(databaseIdentifier, routine .getName(), ProcIdentifier.TYPE_UDF, null, schema .getName()); Schema schema = ((Trigger) routine).getSchema(); Table table = ((Trigger) routine).getSubjectTable(); proc = h.getProcIdentifier(databaseIdentifier, routine.getName(), ProcIdentifier.TYPE_TRIGGER, table.getName(), schema .getName(), table.getSchema().getName()); proc = h.getProcIdentifier(databaseIdentifier, routine.getName(), ProcIdentifier.TYPE_EVENT, null, creator); } else { if (schemaFeature != null && eventIdFeature != null) proc = h.getProcIdentifier(databaseIdentifier, routine.getName(), ProcIdentifier.TYPE_EVENT, null, ((Schema)routine.eGet(schemaFeature)).getName());
/** * 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 String getSQLStatements() { return _sqlEditor == null ? null : SQLToolsFacade.getDBHelper(getDatabaseIdentifier()).preprocessSQLScript(_sqlEditor.getSelectedText()); }
/** * 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())); }
if (helper != null) paramType = helper.getCorrectParamType(paramType);
helper.switchDatabase(databaseIdentifier, conn);
public String getSQLStatements() { return _sqlEditor == null ? null : SQLToolsFacade.getDBHelper(getDatabaseIdentifier()).preprocessSQLScript(_sqlEditor.getText()); }
return h.getProcIdentifier(new DatabaseIdentifier(profile, dbname), (String)map.get(PROP_NAME), type, (String)map.get(PROP_TABLENAME), (String)map.get(PROP_OWNER), tableOwnerName);
DBHelper helper = SQLToolsFacade.getDBHelper(databaseIdentifier); Connection conn = (Connection)iconn.getRawConnection(); helper.switchDatabase(databaseIdentifier, conn); return conn;
public static ProcIdentifier decode(String encoded) throws ParseException { Map map = decodeMap(encoded); String profile = (String)map.remove(PROP_PROFILE); String dbname = (String) map.remove(PROP_DBNAME); String typestr = (String) map.remove(PROP_TYPE); if (profile == null || dbname == null || typestr == null) { throw new ParseException(Messages.ProcIdentifierImpl_invalid_identifier_string, -1); } try { int type = Integer.parseInt(typestr); SQLDevToolsConfiguration config = SQLToolsFacade.getConfigurationByProfileName(profile); if (config != null) { DBHelper h = config.getDBHelper(); return h.getProcIdentifier(new DatabaseIdentifier(profile, dbname), type, map); } return new ProcIdentifierImpl(type, new DatabaseIdentifier(profile, dbname), map); } catch(NumberFormatException ex) { throw new ParseException(Messages.ProcIdentifierImpl_invalid_identifier_string, -1); } }