|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object de.mathema.pride.StoredProcedure
public abstract class StoredProcedure
This class simplifies calling stored procedures from Java code.
Derived types just have to declare the procedure's parameters
as public members. Input parameters must be declared final,
output parameters as non-final members. In/out parameters are
not supported because I didn't find an elegant way to do yet.
The procedure is called by running the execute(java.sql.Connection)
method.
E.g. the following class would run the procedure myproc
with two input Strings and one output integer:
public class myproc extends StoredProcedure { public final String p1; public final String p2; public int p3; public myproc(String p1, String p2) { this.p1 = p1; this.p2 = p2; } }The SQL types of the parameters are derived from the member's Java types. Currently there are the following types supported:
Field Summary | |
---|---|
protected Database |
db
|
static java.lang.String |
REVISION_ID
|
Constructor Summary | |
---|---|
StoredProcedure()
|
Method Summary | |
---|---|
protected java.lang.String |
assembleCallString()
|
void |
execute(java.sql.Connection con)
Executes the stored procedure represented by this object on the passed database connection. |
void |
execute(Database db)
Executes the stored procedure represented by this object on the passed database. |
java.lang.String |
format(java.lang.Object value)
Format a value as string. |
Database |
getDatabase()
Returns a database required by formatting and logging functions. |
protected java.lang.String |
getName()
Returns the name of the stored procedure to call. |
protected int |
getNumParams()
Returns the number of parameters for the SP call. |
protected java.lang.String |
getOutParam(java.sql.CallableStatement stmt,
java.lang.reflect.Field field,
int index)
|
protected java.lang.String |
getOutParams(java.sql.CallableStatement stmt)
|
protected int |
getSQLType(java.lang.Class type)
Returns the SQL type equivalent to the passed Java type |
boolean |
isLogging()
Returns true if the execution of the stored procedure should be logged. |
void |
log(java.lang.String operation)
Called by the execution method when logging is enabled (see isLogging() ) to write an execution string to
log media. |
protected java.lang.String |
setInParam(java.sql.CallableStatement stmt,
java.lang.reflect.Field field,
int index)
Sets an input values for an SP call |
protected java.lang.String |
setOutParamType(java.sql.CallableStatement stmt,
java.lang.reflect.Field field,
int index)
Sets an output value types for an SP call |
protected java.lang.String |
setParams(java.sql.CallableStatement stmt)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected Database db
public static final java.lang.String REVISION_ID
Constructor Detail |
---|
public StoredProcedure()
Method Detail |
---|
public Database getDatabase()
execute(java.sql.Connection)
method was called with a Database
object.
This object is returned, otherwise DatabaseFactory.getDatabase()
public boolean isLogging()
public void log(java.lang.String operation)
isLogging()
) to write an execution string to
log media. This function calls getDatabase().sqlLog() by
default and can be overridden in derived classes if required.
public java.lang.String format(java.lang.Object value)
protected java.lang.String getName()
protected int getNumParams()
protected java.lang.String setInParam(java.sql.CallableStatement stmt, java.lang.reflect.Field field, int index) throws IllegalDescriptorException, java.sql.SQLException
stmt
- The callable statement, representing the SP to callfield
- The data member holding the value to setindex
- The parameter's index in the statement's signature,
beginning with index 1.
IllegalDescriptorException
java.sql.SQLException
protected int getSQLType(java.lang.Class type) throws IllegalDescriptorException
IllegalDescriptorException
protected java.lang.String setOutParamType(java.sql.CallableStatement stmt, java.lang.reflect.Field field, int index) throws IllegalDescriptorException, java.sql.SQLException
stmt
- The callable statement, representing the SP to callfield
- The data member to derive the type from.index
- The parameter's index in the statement's signature,
beginning with index 1.
IllegalDescriptorException
java.sql.SQLException
protected java.lang.String setParams(java.sql.CallableStatement stmt) throws IllegalDescriptorException, java.sql.SQLException
IllegalDescriptorException
java.sql.SQLException
protected java.lang.String getOutParam(java.sql.CallableStatement stmt, java.lang.reflect.Field field, int index) throws IllegalDescriptorException, java.sql.SQLException
IllegalDescriptorException
java.sql.SQLException
protected java.lang.String getOutParams(java.sql.CallableStatement stmt) throws IllegalDescriptorException, java.sql.SQLException
IllegalDescriptorException
java.sql.SQLException
protected java.lang.String assembleCallString()
public void execute(java.sql.Connection con) throws java.sql.SQLException, IllegalDescriptorException
java.sql.SQLException
- if the stored procedure call failed
{@link
- IllegalDescriptorException} if the stored procedure
class is somehow malformed.
IllegalDescriptorException
public void execute(Database db) throws java.sql.SQLException, IllegalDescriptorException
java.sql.SQLException
- if the stored procedure call failed
{@link
- IllegalDescriptorException} if the stored procedure
class is somehow malformed.
IllegalDescriptorException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |