Class ConnectionManager

java.lang.Object
org.pentaho.di.connections.ConnectionManager

public class ConnectionManager extends Object
A class from managing named connections in PDI

Created by bmorrise on 2/3/19.

  • Method Details

    • reset

      public void reset()
      Resets the in-memory storage. The next call that needs it will refresh the connection information from the metastore.
    • getInstance

      @NonNull public static ConnectionManager getInstance()
      This getter should not generally be used because it is limited to the global scope. It would be better to have almost all callers use Bowl.getConnectionManager().

      This instance may still be used to register ConnectionProviders and Lookup Filters.

      Returns:
      ConnectionManager
    • getInstance

      @NonNull public static ConnectionManager getInstance(@NonNull Supplier<org.pentaho.metastore.api.IMetaStore> metaStoreSupplier, @NonNull Bowl bowl)
      Construct a new instance of a ConnectionManager associated with a given meta-store and bowl.

      Instances returned by this will not share in-memory state with any other instances. If you need the ConnectionManager for a Bowl, use Bowl.getConnectionManager() instead.

      Parameters:
      metaStoreSupplier - The meta-store supplier.
      bowl - The bowl.
      Returns:
      ConnectionManager
    • setMetastoreSupplier

      public void setMetastoreSupplier(@NonNull Supplier<org.pentaho.metastore.api.IMetaStore> metaStoreSupplier)
      Set the default meta store supplier for the Connection Manager
      Parameters:
      metaStoreSupplier - A meta store supplier
    • getBowl

      @NonNull public Bowl getBowl()
      Gets the bowl of the connection manager.
      Returns:
      A bowl.
    • addLookupFilter

      public void addLookupFilter(LookupFilter lookupFilter)
      Add a key lookup filter
      Parameters:
      lookupFilter - The lookup filter to add
    • addConnectionProvider

      public void addConnectionProvider(String key, ConnectionProvider<? extends ConnectionDetails> connectionProvider)
      Add a connection provider with a specific key
      Parameters:
      key - The key used to query the connection provider
      connectionProvider - The connection provider
    • getConnectionProvider

      public ConnectionProvider<? extends ConnectionDetails> getConnectionProvider(String key)
      Get a connection provider from the key
      Parameters:
      key - The connection provider key
      Returns:
      The connection provider
    • getLookupKey

      protected String getLookupKey(String value)
      Get the lookup key for a provider
      Parameters:
      value - The key to lookup
      Returns:
      the key returned from the lookup
    • save

      public <T extends ConnectionDetails> boolean save(org.pentaho.metastore.api.IMetaStore metaStore, T connectionDetails)
      Save a named connection to a specific meta store
      Parameters:
      metaStore - A meta store
      connectionDetails - The named connection details to save
      Returns:
      A boolean signifying the success of the save operation
    • save

      public <T extends ConnectionDetails> boolean save(org.pentaho.metastore.api.IMetaStore metaStore, T connectionDetails, boolean prepare)
      Save a named connection to a specific meta store
      Parameters:
      metaStore - A meta store
      connectionDetails - The named connection details to save
      prepare - Prepare the named connection
      Returns:
      A boolean signifying the success of the save operation
    • save

      public <T extends ConnectionDetails> boolean save(T connectionDetails)
      Save a named connection to the default meta store
      Parameters:
      connectionDetails - The named connection details to save
      Returns:
      A boolean signifying the success of the save operation
    • test

      public <T extends ConnectionDetails> boolean test(@NonNull T details) throws KettleException
      Tests if a connection is valid, given its details, with default testing options.

      If the given connection details is a VFS connection, this method delegates to VFSConnectionManagerHelper.test(ConnectionManager, VFSConnectionDetails, VFSConnectionTestOptions). Otherwise, this method delegates directly to ConnectionProvider.test(ConnectionDetails).

      Parameters:
      details - The details of the connection to test.
      Returns:
      true if the connection is valid; false otherwise.
      Throws:
      KettleException
    • delete

      public void delete(String name)
      Delete a connection by name from the default
      Parameters:
      name - The name of the named connection
    • delete

      public void delete(org.pentaho.metastore.api.IMetaStore metaStore, String name)
      Delete a connection by name from a specified meta store
      Parameters:
      metaStore - A meta store
      name - The name of the named connection
    • getProviders

      public List<ConnectionProvider<? extends ConnectionDetails>> getProviders()
      Get a list of connection providers
      Returns:
      A list of connection providers
    • getProvidersByType

      public List<ConnectionProvider<? extends ConnectionDetails>> getProvidersByType(Class<? extends ConnectionProvider> providerClass)
      Get a list of connection providers by type
      Parameters:
      providerClass - The type of provider to filter by
      Returns:
      A list of connection providers
    • getNames

      public List<String> getNames(boolean clearCache)
      Get the names of named connections by provider from the default meta store
      Parameters:
      clearCache - - Whether or not to clear cache (unused)
      Returns:
      A list of named connection names
    • getNames

      public List<String> getNames()
      Get the names of named connections by provider from the default meta store
      Returns:
      A list of named connection names
    • getNames

      public List<String> getNames(org.pentaho.metastore.api.IMetaStore metaStore)
      Get the names of named connections by provider from specified meta store
      Parameters:
      metaStore - A meta store
      Returns:
      A list of named connection names
    • exists

      public boolean exists(String name)
      Find out if a named connection exists
      Parameters:
      name - The named connection name to check
      Returns:
      A boolean whether or not the connection exists
    • getNamesByType

      public <T extends ConnectionProvider<?>> List<String> getNamesByType(Class<T> providerClass)
      Get the names of named connection by connection provider type
      Parameters:
      providerClass - The connection provider type
      Returns:
      A list of named connection names
    • getNamesByKey

      public List<String> getNamesByKey(String key)
      Get the names of named connections by connection type key
      Parameters:
      key - The connection type key
      Returns:
      A list of named connection names
    • getConnectionDetails

      public ConnectionDetails getConnectionDetails(org.pentaho.metastore.api.IMetaStore metaStore, String key, String name)
      Get the named connection from a specified meta store
      Parameters:
      metaStore - A meta store
      key - The provider key
      name - The connection name
      Returns:
      The named connection details
    • getConnectionDetails

      public ConnectionDetails getConnectionDetails(String key, String name)
      Get the named connection from the default meta store
      Parameters:
      key - The provider key
      name - The connection name
      Returns:
      The named connection details
    • getConnectionDetails

      public ConnectionDetails getConnectionDetails(String name)
      Get the named connection from a specified meta store
      Parameters:
      name - The connection name
      Returns:
      The named connection details
    • getDetails

      @Nullable public <T extends ConnectionDetails> T getDetails(@Nullable String name)
      Gets a connection given its name, casting it to the type parameter.
      Parameters:
      name - The connection name
      Returns:
      The named connection details
    • getExistingDetails

      @NonNull public <T extends ConnectionDetails> T getExistingDetails(@Nullable String name) throws KettleException
      Gets the details of a connection, given its name, casting it to the type parameter, and throwing if it does not exist.
      Parameters:
      name - The connection name
      Returns:
      The named connection details
      Throws:
      KettleException - When a connection with the given name is not defined.
    • getConnectionDetails

      public ConnectionDetails getConnectionDetails(org.pentaho.metastore.api.IMetaStore metaStore, String name)
      Get the named connection from a specified meta store
      Parameters:
      metaStore - A meta store
      name - The connection name
      Returns:
      The named connection details
    • createConnectionDetails

      public ConnectionDetails createConnectionDetails(String scheme)
      Get a new connection details object by scheme/key
      Parameters:
      scheme - The scheme/key
      Returns:
      A empty named connection
    • getConnectionDetailsByScheme

      public List<? extends ConnectionDetails> getConnectionDetailsByScheme(String scheme)
      Get all named connections by key/scheme
      Parameters:
      scheme - The scheme/key
      Returns:
      A list of named connections
    • clear

      public void clear(org.pentaho.metastore.api.IMetaStore metaStore)
      Delete all named connections stored in a meta store
      Parameters:
      metaStore - A meta store
    • copy

      public void copy(org.pentaho.metastore.api.IMetaStore sourceMetaStore, org.pentaho.metastore.api.IMetaStore destinationMetaStore)
      Copy the named connections stored in one meta store into another meta store
      Parameters:
      sourceMetaStore - The meta store to copy from
      destinationMetaStore - The meta store to copy to
    • getItems

      public List<ConnectionManager.Type> getItems()
      Get a list of value/label pairs of named connection types
      Returns:
      A list of value/label pairs of named connection types
    • getItemsByType

      public <T extends ConnectionProvider<?>> List<ConnectionManager.Type> getItemsByType(@Nullable Class<T> providerClass)
      Get a list of value/label pairs of named connection types, optionally filtered to be of a given provider class.
      Parameters:
      providerClass - The provider class; when null, all providers are returned.
      Returns:
      A list of value/label pairs of named connection types.