Class ProcedureCallerFactory<T>
- java.lang.Object
-
- com.github.marschall.storedprocedureproxy.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()
andbuild(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()
andbuild(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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ProcedureCallerFactory.ParameterRegistration
Determines how parameters should be registered.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description T
build()
Creates a caller for the interface of stored procedures using the configured options.static <T> T
build(Class<T> inferfaceDeclaration, DataSource dataSource)
Creates a caller for the interface of stored procedures using the defaults.static <T> ProcedureCallerFactory<T>
of(Class<T> inferfaceDeclaration, DataSource dataSource)
Creates a builder for the caller for the interface of stored procedures.ProcedureCallerFactory<T>
withExceptionAdapter(SQLExceptionAdapter exceptionAdapter)
Allows you to change the waySQLException
s are translated into unchecked exceptions.ProcedureCallerFactory<T>
withNamespace()
Causes a namespace to be added to the call string.ProcedureCallerFactory<T>
withNamespaceNamingStrategy(NamingStrategy namespaceNamingStrategy)
Causes a namespace to be added to the call string by applying the given function to the interface name.ProcedureCallerFactory<T>
withOracleArrays()
Uses Oracle API to create arrays.ProcedureCallerFactory<T>
withOracleExtensions()
Enables all Oracle extensions.ProcedureCallerFactory<T>
withOracleTypeMapper()
Uses Oracle JDBC types.ProcedureCallerFactory<T>
withParameterNamingStrategy(NamingStrategy parameterNamingStrategy)
Allows you to use a custom way how parameter names are derived from Java names.ProcedureCallerFactory<T>
withParameterRegistration(ProcedureCallerFactory.ParameterRegistration parameterRegistration)
Allows you to change the way procedure parameters are registered.ProcedureCallerFactory<T>
withPostgresArrays()
Uses PostgreS API to create primitive arrays.ProcedureCallerFactory<T>
withProcedureNamingStrategy(NamingStrategy procedureNamingStrategy)
Allows you to use a custom way how procedure names are derived from Java names.ProcedureCallerFactory<T>
withSchema()
Causes a schema name to be added to the call string.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.ProcedureCallerFactory<T>
withTypeMapper(TypeMapper typeMapper)
Allows you to change the way Java types are translated to SQL types.ProcedureCallerFactory<T>
withTypeNameResolver(TypeNameResolver typeNameResolver)
Allows you to change the way SQL type names for array elements are resolved.
-
-
-
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 declarationsdataSource
- 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 declarationsdataSource
- the data source through with to make the calls- Returns:
- the interface instance
-
withParameterNamingStrategy
public ProcedureCallerFactory<T> withParameterNamingStrategy(NamingStrategy parameterNamingStrategy)
Allows you to use a custom way how parameter names are derived from Java names.The given object is only applied if the parameter registration is either
ProcedureCallerFactory.ParameterRegistration.NAME_ONLY
orProcedureCallerFactory.ParameterRegistration.NAME_AND_TYPE
andParameterName
is not present. The given object is never applied to an out parameter. Source level parameter names are only available with you compile with -parameters.- Parameters:
parameterNamingStrategy
- the naming strategy for parameters, notnull
- Returns:
- this builder for chaining
-
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, notnull
- 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, notnull
- Returns:
- this builder for chaining
-
withSchema
public ProcedureCallerFactory<T> withSchema()
Causes a schema name to be added to the call string.Per default the interface name is used.
- Returns:
- this builder for chaining
- See Also:
Schema
,withSchemaNamingStrategy(NamingStrategy)
-
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, notnull
- Returns:
- this builder for chaining
- See Also:
- Oracle Packages
-
withNamespace
public ProcedureCallerFactory<T> withNamespace()
Causes a namespace to be added to the call string.Per default the interface name is used.
- Returns:
- this builder for chaining
- See Also:
Namespace
,withNamespaceNamingStrategy(NamingStrategy)
, Oracle Packages
-
withParameterRegistration
public ProcedureCallerFactory<T> withParameterRegistration(ProcedureCallerFactory.ParameterRegistration parameterRegistration)
Allows you to change the way procedure parameters are registered. The default isProcedureCallerFactory.ParameterRegistration.INDEX_ONLY
.- Parameters:
parameterRegistration
- the parameter registration- Returns:
- this builder for chaining
- See Also:
- Binding Parameters
-
withExceptionAdapter
public ProcedureCallerFactory<T> withExceptionAdapter(SQLExceptionAdapter exceptionAdapter)
Allows you to change the waySQLException
s are translated into unchecked exceptions.Only applied if the method is not
throws SQLException
. The default if Spring is not present is to useUncheckedSQLException
. The default if Spring is present is to useSQLErrorCodeSQLExceptionTranslator
.- Parameters:
exceptionAdapter
- the exception adapter- Returns:
- this builder for chaining
-
withTypeMapper
public ProcedureCallerFactory<T> withTypeMapper(TypeMapper typeMapper)
Allows you to change the way Java types are translated to SQL types.Only applied if
ParameterType
,OutParameter.type()
orReturnValue.type()
are not present. The default is defined inTypeMapper
.- Parameters:
typeMapper
- the type mapper- Returns:
- this builder for chaining
-
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
-
withOracleArrays
public ProcedureCallerFactory<T> withOracleArrays()
Uses Oracle API to create arrays.- Returns:
- this builder for chaining
- See Also:
withOracleExtensions()
, Binding Oracle Arrays
-
withPostgresArrays
public ProcedureCallerFactory<T> withPostgresArrays()
Uses PostgreS API to create primitive arrays.- Returns:
- this builder for chaining
- See Also:
- PostgreS extensions
-
withOracleTypeMapper
public ProcedureCallerFactory<T> withOracleTypeMapper()
Uses Oracle JDBC types.Maps booleans to PL/SQL booleans instead of SQL booleans.
This requires at least the 12.2c JDBC driver.
- Returns:
- this builder for chaining
- See Also:
withOracleExtensions()
, Binding Oracle Booleans
-
withOracleExtensions
public ProcedureCallerFactory<T> withOracleExtensions()
Enables all Oracle extensions.Currently only required for:
- boolean types
- arrays
- Returns:
- this builder for chaining
- See Also:
withOracleArrays()
,withOracleTypeMapper()
-
build
public T build()
Creates a caller for the interface of stored procedures using the configured options.- Returns:
- the interface instance
-
-