T
- the interface containing the stored procedure declarationspublic final class ProcedureCallerFactory<T> extends Object
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.
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
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
Modifier and Type | Class | Description |
---|---|---|
static class |
ProcedureCallerFactory.ParameterRegistration |
Determines how parameters should be registered.
|
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 way
SQLException 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.
|
public static <T> ProcedureCallerFactory<T> of(Class<T> inferfaceDeclaration, DataSource dataSource)
T
- the interface type containing the stored procedure declarationsinferfaceDeclaration
- the interface containing the store procedure declarationsdataSource
- the data source through with to make the callspublic static <T> T build(Class<T> inferfaceDeclaration, DataSource dataSource)
T
- the interface type containing the stored procedure declarationsinferfaceDeclaration
- the interface containing the store procedure declarationsdataSource
- the data source through with to make the callspublic ProcedureCallerFactory<T> withParameterNamingStrategy(NamingStrategy parameterNamingStrategy)
The given object is only applied if the parameter registration is either
ProcedureCallerFactory.ParameterRegistration.NAME_ONLY
or ProcedureCallerFactory.ParameterRegistration.NAME_AND_TYPE
and ParameterName
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.
parameterNamingStrategy
- the naming strategy for parameters, not null
public ProcedureCallerFactory<T> withProcedureNamingStrategy(NamingStrategy procedureNamingStrategy)
The given object is only applied if ProcedureName
is not present.
procedureNamingStrategy
- the naming strategy for procedures, not null
public ProcedureCallerFactory<T> withSchemaNamingStrategy(NamingStrategy schemaNamingStrategy)
schemaNamingStrategy
- the naming strategy for schemas, not null
public ProcedureCallerFactory<T> withSchema()
Per default the interface name is used.
Schema
,
withSchemaNamingStrategy(NamingStrategy)
public ProcedureCallerFactory<T> withNamespaceNamingStrategy(NamingStrategy namespaceNamingStrategy)
namespaceNamingStrategy
- the naming strategy for namespaces, not null
public ProcedureCallerFactory<T> withNamespace()
Per default the interface name is used.
Namespace
,
withNamespaceNamingStrategy(NamingStrategy)
,
Oracle Packagespublic ProcedureCallerFactory<T> withParameterRegistration(ProcedureCallerFactory.ParameterRegistration parameterRegistration)
ProcedureCallerFactory.ParameterRegistration.INDEX_ONLY
.parameterRegistration
- the parameter registrationpublic ProcedureCallerFactory<T> withExceptionAdapter(SQLExceptionAdapter exceptionAdapter)
SQLException
s are translated into
unchecked exceptions.
Only applied if the method is not throws SQLException
. The default
if Spring is not present is to use UncheckedSQLException
. The default
if Spring is present is to use SQLErrorCodeSQLExceptionTranslator
.
exceptionAdapter
- the exception adapterpublic ProcedureCallerFactory<T> withTypeMapper(TypeMapper typeMapper)
Only applied if ParameterType
, OutParameter.type()
or
ReturnValue.type()
are not present. The default is defined in
TypeMapper
.
typeMapper
- the type mapperpublic ProcedureCallerFactory<T> withTypeNameResolver(TypeNameResolver typeNameResolver)
Only applied if TypeName
is not present.
typeNameResolver
- the type name resolverpublic ProcedureCallerFactory<T> withOracleArrays()
withOracleExtensions()
,
Binding Oracle Arrayspublic ProcedureCallerFactory<T> withPostgresArrays()
public ProcedureCallerFactory<T> withOracleTypeMapper()
Maps booleans to PL/SQL booleans instead of SQL booleans.
This requires at least the 12.2c JDBC driver.
withOracleExtensions()
,
Binding Oracle Booleanspublic ProcedureCallerFactory<T> withOracleExtensions()
Currently only required for:
withOracleArrays()
,
withOracleTypeMapper()
public T build()
Copyright © 2016–2018. All rights reserved.