## 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` `DATABASE_CATEGORY_ID`
`static java.lang.String` `DATABASENAME`
`static java.lang.String` `DRIVER_DATABASE_CATEGORY_ID`
`static java.lang.String` `DRIVER_DB_VENDOR_NAME`
`static java.lang.String` `DRIVER_DB_VERSION`
`static java.lang.String` `DRIVERCLASS`
`static java.lang.String` `DRIVERDEFINITIONID`
`static java.lang.String` `PROFILE_DB_VENDOR_NAME`
`static java.lang.String` `PROFILE_DB_VERSION`
`static java.lang.String` `PROFILE_DB_VERSION_TYPE`
`static java.lang.String` `PROP_DB_CONN_PROPS`
`static java.lang.String` `PWD`
`static int` `SQLMODEL_MODE_NONE` SQL Model operation mode indicating no SQL model is involved.
`static int` `SQLMODEL_MODE_OFFLINE` SQL Model operation mode indicating a local resource is used to load SQL models.
`static int` `SQLMODEL_MODE_ONLINE` SQL Model operation mode indicating a connection is established to data server and the SQL model reflects the data server metadata.
`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` `connectProfile(java.lang.String profileName)` Connects the connection profile and returns the shared connection.
`static java.sql.Connection` `connectProfile(java.lang.String profileName, java.lang.String dbname)` Connects the connection profile and returns the shared connection.
`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 Database` `getDatabase(DatabaseIdentifier databaseIdentifier, boolean connect)` Returns the SQL model `Database` object identified by `databaseIdentifier`.
`static DatabaseDefinition` `getDatabaseDefinition(DatabaseVendorDefinitionId id)` Returns the associated DatabaseVendorDefinition object from the given connection profile.
`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)` Shortcut to #getDatabaseList(profileName, true) TODO This method is remained for backward compatibility.
`static java.util.List` `getDatabaseList(java.lang.String profileName, boolean connect)` Returns database name list from the connection profile name, only connect when required.
`static DatabaseVendorDefinitionId` `getDatabaseVendorDefinitionId(IConnectionProfile profile)`
`static DatabaseVendorDefinitionId` `getDatabaseVendorDefinitionId(IConnectionProfile profile, boolean getCacheInfo, boolean normalize)` Returns a DatabaseVendorDefinitionId object which identifies the data server type.
`static DatabaseVendorDefinitionId` `getDatabaseVendorDefinitionId(java.lang.String profileName)` Given the connection profile name, return a DatabaseVendorDefinitionId object which identifies the data server type that profileName points to.
`static DatabaseVendorDefinitionId` `getDatabaseVendorDefinitionId(java.lang.String profileName, boolean getCacheInfo, boolean normalize)`
`static java.sql.Connection` `getOrCreateReusableConnection(DatabaseIdentifier databaseIdentifier)` Gets the shared connection from the connection profile.
`static java.lang.String` `getPassword(IConnectionProfile profile)` Gets the password defined in the `IConnectionProfile` object.
`static java.lang.String` `getProductVersion(java.lang.String profileName)` Returns the real version info by pinging the server if it's not cached in connection profile yet.
`static IConnectionProfile` `getProfile(java.lang.String name)` Returns a `IConnectionProfile` object by the name.
`static java.lang.String` `getProfileDatabaseName(java.lang.String profileName)` Get profile's database name, if no database name in profile then return ""
`static IConnectionProfile[]` `getProfiles()` Get the profiles which are supported by DMP.
`static java.lang.String` `getProfileUserName(DatabaseIdentifier databaseIdentifier, boolean createConnection)` Returns the database user name that matches the user name defined in DatabaseIdentifier.
`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 ServerIdentifier` `getServerIdentifier(DatabaseIdentifier databaseIdentifier)` Construct a ServerIdentifier from a connection profile.
`static int` `getSQLModelMode(SQLObject object)` Given an instance of `SQLObject`, returns the SQL model operation mode.
`static int` `getSQLModelMode(java.lang.String profileName)` Given a connection profile name, returns the SQL model operation mode.
`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(ConnectProfile connectProfile)` This method is used to verify if this profile is database profile.
`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.
`static boolean` `isSupportedProfile(IConnectionProfile profile)` This method is used to verify if this profile is supported by DMP.
`static boolean` `profileExist(java.lang.String name)`

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

Field Detail

### PROFILE_DB_VERSION_TYPE

    public static final java.lang.String PROFILE_DB_VERSION_TYPE

See Also:
  Constant Field Values

### PROFILE_DB_VERSION

    public static final java.lang.String PROFILE_DB_VERSION

See Also:
  Constant Field Values

### PROFILE_DB_VENDOR_NAME

    public static final java.lang.String PROFILE_DB_VENDOR_NAME

See Also:
  Constant Field Values

### DRIVER_DB_VERSION

    public static final java.lang.String DRIVER_DB_VERSION

### DRIVER_DB_VENDOR_NAME

    public static final java.lang.String DRIVER_DB_VENDOR_NAME

### UID

    public static final java.lang.String UID

### PWD

    public static final java.lang.String PWD

### DRIVERDEFINITIONID

    public static final java.lang.String DRIVERDEFINITIONID

See Also:
  Constant Field Values

### DATABASENAME

    public static final java.lang.String DATABASENAME

### URL

    public static final java.lang.String URL

### DRIVERCLASS

    public static final java.lang.String DRIVERCLASS

### DRIVER_DATABASE_CATEGORY_ID

    public static final java.lang.String DRIVER_DATABASE_CATEGORY_ID

### DATABASE_CATEGORY_ID

    public static final java.lang.String DATABASE_CATEGORY_ID

See Also:
  Constant Field Values

### PROP_DB_CONN_PROPS

    public static final java.lang.String PROP_DB_CONN_PROPS

### SQLMODEL_MODE_NONE

    public static final int SQLMODEL_MODE_NONE

  SQL Model operation mode indicating no SQL model is involved.

  See Also:
    Constant Field Values

### SQLMODEL_MODE_ONLINE

    public static final int SQLMODEL_MODE_ONLINE

  SQL Model operation mode indicating a connection is established to data server and the SQL model reflects the data server metadata.

  See Also:
    Constant Field Values

### SQLMODEL_MODE_OFFLINE

    public static final int SQLMODEL_MODE_OFFLINE

  SQL Model operation mode indicating a local resource is used to load SQL models.

  See Also:
    Constant Field Values

Constructor Detail

### ProfileUtil

    public ProfileUtil()

Method Detail

### getSQLModelMode

    public static int getSQLModelMode(SQLObject object)

  Given an instance of `SQLObject`, returns the SQL model operation mode.

  Parameters:
    `object` -
  Returns:

### getSQLModelMode

    public static int getSQLModelMode(java.lang.String profileName)

  Given a connection profile name, returns the SQL model operation mode.

  Parameters:
    `profileName` -
  Returns:

### 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. Clients of this API must be aware that the return value might be null.

  Parameters:
    `profile` -
  Returns:

### getDatabaseDefinition

    public static DatabaseDefinition getDatabaseDefinition(DatabaseVendorDefinitionId id)

  Returns the associated DatabaseVendorDefinition object from the given connection profile. The DatabaseVendorDefinition object is contributed by vendor tool plugins. Clients of this API must be aware that the return value might be null.

  Parameters:
    `profile` -
  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

### profileExist

    public static boolean profileExist(java.lang.String name)

### getDatabaseVendorDefinitionId

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

  Given the connection profile name, return a DatabaseVendorDefinitionId 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. CAUTION: This method stops pinging the server to get the version info, which means the version info got from this method might be different with the real version.

  Parameters:
    `profileName` -
  Returns:

### getDatabaseVendorDefinitionId

    public static DatabaseVendorDefinitionId getDatabaseVendorDefinitionId(IConnectionProfile profile)

### getDatabaseVendorDefinitionId

    public static DatabaseVendorDefinitionId getDatabaseVendorDefinitionId(java.lang.String profileName,
                                                                           boolean getCacheInfo,
                                                                           boolean normalize)

### getDatabaseVendorDefinitionId

    public static DatabaseVendorDefinitionId getDatabaseVendorDefinitionId(IConnectionProfile profile,
                                                                           boolean getCacheInfo,
                                                                           boolean normalize)

  Returns a DatabaseVendorDefinitionId object which identifies the data server type.

  Parameters:
    `profile` - connection profile
    `getCacheInfo` -
    `normalize` - whether needs to normalize the DatabaseVendorDefinitionId to conform with the database definition declaration
  Returns:

### getServerIdentifier

    public static ServerIdentifier getServerIdentifier(DatabaseIdentifier databaseIdentifier)

  Construct a ServerIdentifier from a connection profile.

  Parameters:
    `profileName` -
  Returns:

### getProductVersion

    public static java.lang.String getProductVersion(java.lang.String profileName)

  Returns the real version info by pinging the server if it's not cached in connection profile yet.

  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`. Shortcut to #getDatabase(databaseIdentifier, true) TODO This method is remained for backward compatibility. Callers of this API should revisit whether connect should be automatically performed.

  Returns:
    the SQL model `Database` object

### getDatabase

    public static Database getDatabase(DatabaseIdentifier databaseIdentifier,
                                       boolean connect)

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

  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`

### getOrCreateReusableConnection

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

  Gets the shared connection from the connection profile. If the profile is not connected yet, IConnectionProfile.connect will be called first. 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)`

### connectProfile

    public static java.sql.Connection connectProfile(java.lang.String profileName)

  Connects the connection profile and returns the shared connection. If for some reason, the connection can't be made, the result would be null.

  Parameters:
    `profileName` -
  Returns:

### connectProfile

    public static java.sql.Connection connectProfile(java.lang.String profileName,
                                                     java.lang.String dbname)

  Connects the connection profile and returns the shared connection.

  Parameters:
    `profileName` - name of profile to connect to
    `dbname` - name of database to use or switch to in the connection; may be null
  Returns:
    shared connection; may be null if connect failed

### createConnection

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

  Returns a connection from the connection layer. If the connection profile is not in "connected" state, connect it first and returns the shared connection.

  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` -

### getDatabaseList

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

  Shortcut to #getDatabaseList(profileName, true) TODO This method is remained for backward compatibility. Callers of this API should revisit whether connect should be automatically performed.

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

### getDatabaseList

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

  Returns database name list from the connection profile name, only connect when required.

  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

### getProfileUserName

    public static java.lang.String getProfileUserName(DatabaseIdentifier databaseIdentifier,
                                                      boolean createConnection)

  Returns the database user name that matches the user name defined in DatabaseIdentifier. If a connection can't be established, will simply return the user name defined in DatabaseIdentifier.

  Parameters:
    `databaseIdentifier` -
    `createConnection` - whether need to create connection if none exists

### isSupportedProfile

    public static boolean isSupportedProfile(IConnectionProfile profile)

  This method is used to verify if this profile is supported by DMP. The supported profiles include ASE, ASA, ASIQ, Replication Server.

  Parameters:
    `profile` -
  Returns:
    true means this profile is supported by DMP.

### isDatabaseProfile

    public static boolean isDatabaseProfile(IConnectionProfile connectionProfile)

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

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

### isDatabaseProfile

    public static boolean isDatabaseProfile(ConnectProfile connectProfile)

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

  Parameters:
    `connectProfile` -
  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

### getProfileDatabaseName

    public static java.lang.String getProfileDatabaseName(java.lang.String profileName)

  Get profile's database name, if no database name in profile then return ""

  Parameters:
    `profileName` -
  Returns:

### getProfiles

    public static IConnectionProfile[] getProfiles()

  Get the profiles which are supported by DMP. For example: ASA, ASE, ASIQ, Replication Server. The profiles are filtered by profileId.

  Returns:
    IConnectionProfile[]

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