Class ProcedureCallerFactory<T>

  • Type Parameters:
    T - the interface containing the stored procedure declarations

    public final class ProcedureCallerFactory<T>
    extends Object
    Creates instances of an interface containing stored procedure declarations. The instances will call the stored procedure.

    The instances created by build() and build(Class, DataSource) should have the life time of the application. They should be reused instead of creating new instances for every call. They are prime candidates for injection.

    This class implements the builder pattern allowing you to override various defaults. If you're fine with the defaults you can create interface instances directly with build(Class, DataSource).

    Instances of this class are not thread safe but the instances returned by build() and build(Class, DataSource) are.

    Simple Usage

    In the simplest case this class can be used like this:
    
      DataSource dataSource = ...; // some way to get the data source, either injection or look up
      Class<MyProcedures> inferfaceDeclaration = MyProcedures.class; // your interface containing your procedure declarations
      MyProcedures procedures = ProcedureCallerFactory.build(inferfaceDeclaration, dataSource);
      procedures.aProcedure("param1", "param2"); // actual procedure with actual parameters
     

    Advanced Usage

    If you want to customize the defaults you can use this class like this:
    
      DataSource dataSource = ...; // some way to get the data source, either injection or look up
      Class<MyProcedures> inferfaceDeclaration = MyProcedures.class; // your interface containing your procedure declarations
      MyProcedures procedures = ProcedureCallerFactory.of(inferfaceDeclaration, dataSource)
        .withParameterRegistration(ParameterRegistration.INDEX_AND_TYPE) // change one or multiple defaults
        .build();
      procedures.aProcedure("param1", "param2"); // actual procedure with actual parameters
     
    • Method Detail

      • of

        public static <T> ProcedureCallerFactory<T> of​(Class<T> inferfaceDeclaration,
                                                       DataSource dataSource)
        Creates a builder for the caller for the interface of stored procedures.
        Type Parameters:
        T - the interface type containing the stored procedure declarations
        Parameters:
        inferfaceDeclaration - the interface containing the store procedure declarations
        dataSource - the data source through with to make the calls
        Returns:
        the builder for the caller
      • build

        public static <T> T build​(Class<T> inferfaceDeclaration,
                                  DataSource dataSource)
        Creates a caller for the interface of stored procedures using the defaults.
        Type Parameters:
        T - the interface type containing the stored procedure declarations
        Parameters:
        inferfaceDeclaration - the interface containing the store procedure declarations
        dataSource - the data source through with to make the calls
        Returns:
        the interface instance
      • withProcedureNamingStrategy

        public ProcedureCallerFactory<T> withProcedureNamingStrategy​(NamingStrategy procedureNamingStrategy)
        Allows you to use a custom way how procedure names are derived from Java names.

        The given object is only applied if ProcedureName is not present.

        Parameters:
        procedureNamingStrategy - the naming strategy for procedures, not null
        Returns:
        this builder for chaining
      • withSchemaNamingStrategy

        public ProcedureCallerFactory<T> withSchemaNamingStrategy​(NamingStrategy schemaNamingStrategy)
        Causes a schema name to be added to the call string by applying the given function to the interface name.
        Parameters:
        schemaNamingStrategy - the naming strategy for schemas, not null
        Returns:
        this builder for chaining
      • withNamespaceNamingStrategy

        public ProcedureCallerFactory<T> withNamespaceNamingStrategy​(NamingStrategy namespaceNamingStrategy)
        Causes a namespace to be added to the call string by applying the given function to the interface name.
        Parameters:
        namespaceNamingStrategy - the naming strategy for namespaces, not null
        Returns:
        this builder for chaining
        See Also:
        Oracle Packages
      • withTypeNameResolver

        public ProcedureCallerFactory<T> withTypeNameResolver​(TypeNameResolver typeNameResolver)
        Allows you to change the way SQL type names for array elements are resolved.

        Only applied if TypeName is not present.

        Parameters:
        typeNameResolver - the type name resolver
        Returns:
        this builder for chaining
      • build

        public T build()
        Creates a caller for the interface of stored procedures using the configured options.
        Returns:
        the interface instance