## org.eclipse.datatools.sqltools.core.profile
Class ProfileUtil

    java.lang.Object
      org.eclipse.datatools.sqltools.core.profile.ProfileUtil

public class ProfileUtil
extends java.lang.Object

Utility class for `IConnectionProfile` in connectivity layer. Encapsulating all the code to processing `IConnectionProfile` object can reduce the maintainence effort and make it easy for consumers in the SQL Dev Tools to use.

Author:
  Hui Cao

Field Summary
`static java.lang.String` `DATABASENAME`
`static java.lang.String` `DRIVERCLASS`
`static java.lang.String` `DRIVERDEFINITIONID`
`static java.lang.String` `PWD`
`static java.lang.String` `UID`
`static java.lang.String` `URL`

Constructor Summary
`ProfileUtil()`

Method Summary
`static void` `closeConnection(java.lang.String profileName, java.lang.String dbName, java.sql.Connection conn)` Closes the given connection object.
`static java.sql.Connection` `createConnection(IConnectionProfile profile, java.lang.String dbName)` Returns a connection from the connection layer
`static java.sql.Connection` `createConnection(java.lang.String profileName, java.lang.String dbName)` Returns a connection from the connection layer
`static java.lang.String` `getConnectionProfileId(java.lang.String profileName)` Gets the connection profile provider id by the profile name.
`static Database` `getDatabase(DatabaseIdentifier databaseIdentifier)` Returns the SQL model `Database` object identified by `databaseIdentifier`.
`static DatabaseDefinition` `getDatabaseDefinition(java.lang.String profileName)` Returns the associated DatabaseVendorDefinition object from the given connection profile.
`static java.util.List` `getDatabaseList(java.lang.String profileName)` Retrieves the database name list located at the server identified by profileName.
`static DatabaseVendorDefinitionId` `getDatabaseVendorDefinitionId(java.lang.String profileName)` Given the connection profile name, return a DataVendorIdentifier object which identifies the data server type that profileName points to.
`static java.lang.String` `getPassword(IConnectionProfile profile)` Gets the password defined in the `IConnectionProfile` object.
`static IConnectionProfile` `getProfile(java.lang.String name)` Returns a `IConnectionProfile` object by the name.
`static java.sql.Connection` `getReusableConnection(DatabaseIdentifier databaseIdentifier)` Gets the shared connection from the connection profile TODO Now this method delegates to IConnectionProfile, which doesn't manage a connection for each database.
`static java.lang.String[]` `getSupportedDatabaseProfiles()` Returns all the connection profiles belonging to the database category.
`static java.lang.String` `getUserName(IConnectionProfile profile)` Gets the user name defined in the `IConnectionProfile` object.
`static boolean` `isDatabaseProfile(IConnectionProfile connectionProfile)` This method is used to verify if this profile is database profile.
`static boolean` `isDatabaseProfile(java.lang.String profileName)` This method is used to verify if this profile is database profile.

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### UID

    public static final java.lang.String UID

See Also:
  Constant Field Values

### PWD

    public static final java.lang.String PWD

See Also:
  Constant Field Values

### DRIVERDEFINITIONID

    public static final java.lang.String DRIVERDEFINITIONID

See Also:
  Constant Field Values

### DATABASENAME

    public static final java.lang.String DATABASENAME

See Also:
  Constant Field Values

### URL

    public static final java.lang.String URL

See Also:
  Constant Field Values

### DRIVERCLASS

    public static final java.lang.String DRIVERCLASS

See Also:
  Constant Field Values

Constructor Detail

### ProfileUtil

    public ProfileUtil()

Method Detail

### getDatabaseDefinition

    public static DatabaseDefinition getDatabaseDefinition(java.lang.String profileName)

  Returns the associated DatabaseVendorDefinition object from the given connection profile. The DatabaseVendorDefinition object is contributed by vendor tool plugins.

  Returns:

### getProfile

    public static IConnectionProfile getProfile(java.lang.String name)
                                         throws NoSuchProfileException

  Returns a `IConnectionProfile` object by the name.

  Parameters:
    `name` - connection profile name
  Returns:
    `IConnectionProfile`
  Throws:
    `NoSuchProfileException` - when no connection profile identified by the given name can be found

### getDatabaseVendorDefinitionId

    public static DatabaseVendorDefinitionId getDatabaseVendorDefinitionId(java.lang.String profileName)

  Given the connection profile name, return a DataVendorIdentifier object which identifies the data server type that profileName points to. Basically, there are 2 approaches to do it: 1. connect to server using a specific factoryId (which is not defined by DTP connectivity layer yet), then get DatabaseDefinition from the ISQLEditorConnectionInfo object; 2. find driver template, then get the vendor and version info from it. Since the latter one allows us to do the job without having to connect, we'll use it in this method.

  Parameters:
    `profileName` -
  Returns:

### getUserName

    public static java.lang.String getUserName(IConnectionProfile profile)

  Gets the user name defined in the `IConnectionProfile` object.

  Parameters:
    `profile` - the `IConnectionProfile`
  Returns:
    user name

### getPassword

    public static java.lang.String getPassword(IConnectionProfile profile)

  Gets the password defined in the `IConnectionProfile` object.

  Parameters:
    `profile` - the `IConnectionProfile`
  Returns:
    user name

### getConnectionProfileId

    public static java.lang.String getConnectionProfileId(java.lang.String profileName)
                                                   throws NoSuchProfileException

  Gets the connection profile provider id by the profile name.

  Parameters:
    `profileName` - connection profile name
  Returns:
    the provider id for the connection profile
  Throws:
    `NoSuchProfileException`

### getDatabase

    public static Database getDatabase(DatabaseIdentifier databaseIdentifier)

  Returns the SQL model `Database` object identified by `databaseIdentifier`.

  Note: this method can only return one Database object for one connection profile. This problem should be addressed in multiple database environment, such as ASE.

  Returns:
    the SQL model `Database` object

### getReusableConnection

    public static java.sql.Connection getReusableConnection(DatabaseIdentifier databaseIdentifier)
                                                     throws java.sql.SQLException,
                                                            NoSuchProfileException

  Gets the shared connection from the connection profile TODO Now this method delegates to IConnectionProfile, which doesn't manage a connection for each database.

  Parameters:
    `databaseIdentifier` - database identifier used to locate the connection profile
  Returns:
    the shared connection managed by the connection profile
  Throws:
    `java.sql.SQLException`
    `NoSuchProfileException`

### createConnection

    public static java.sql.Connection createConnection(java.lang.String profileName,
                                                       java.lang.String dbName)

  Returns a connection from the connection layer

  Parameters:
    `profileName` -
    `dbName` -
  Returns:
    jdbc connection
  See Also:
    `createConnection(IConnectionProfile, String)`

### createConnection

    public static java.sql.Connection createConnection(IConnectionProfile profile,
                                                       java.lang.String dbName)

  Returns a connection from the connection layer

  Parameters:
    `profile` -
    `dbName` -
  Returns:
    jdbc connection

### closeConnection

    public static void closeConnection(java.lang.String profileName,
                                       java.lang.String dbName,
                                       java.sql.Connection conn)

  Closes the given connection object. This method checks the shared connection maintained by connectivity layer.

  Parameters:
    `profileName` -
    `dbName` -
    `conn` -

### isDatabaseProfile

    public static boolean isDatabaseProfile(IConnectionProfile connectionProfile)

  This method is used to verify if this profile is database profile.

  Returns:
    true means this profile is database profile

### isDatabaseProfile

    public static boolean isDatabaseProfile(java.lang.String profileName)

  This method is used to verify if this profile is database profile.

  Parameters:
    `profileName` -
  Returns:
    true means this profile is database profile

### getDatabaseList

    public static java.util.List getDatabaseList(java.lang.String profileName)

  Retrieves the database name list located at the server identified by profileName. This method will first try to get the database list from DatabaseMetadata. if failed, will use the default database name defined in the connection profile.

  Parameters:
    `profileName` - connection profile name
  Returns:
    database name list.

### getSupportedDatabaseProfiles

    public static java.lang.String[] getSupportedDatabaseProfiles()

  Returns all the connection profiles belonging to the database category.

  Returns:
    connection profile name array

Copyright © 2006 Actuate, IBM Corporation, Sybase, Inc. and others. All rights reserved.