The syntax diagrams and the descriptions of the syntax elements are in the following sections.
To understand the conventions that are used in the syntax diagrams, see How to read syntax diagrams.
Use this syntax for declaring annotated methods that run DML statements that do not use cursors. You can also use this syntax to run DDL statements.
>>-@Update--(--sql--=--"--SQL-statement--"--)-------------------> >--+------------------------------------------------------------------------------------------+--> '-@Handler--(--+-parameterHandler--=--class-name--------------------------------------+--)-' +-resultHandler--=--class-name--+------------------------------------+-+ | '-,--parameterHandler--=--class-name-' | '-rowHandler--=--class-name--+------------------------------------+----' '-,--parameterHandler--=--class-name-' >--modifiers--return-type--method-name--(--+-----------------------+--+------------------------------------+--);->< '-handler--handler-name-' | .-,------------------------------. | | V | | '---parameter-type--parameter-name-+-'
Example
Here is an example of the syntax for a method that runs a SELECT statement:
@Select(sql = "SELECT PID, QUANTITY, LOCATION FROM HEATHR.INVENTORY WHERE PID = ?")
Inventory getInventory(String pid);
Here is an example of the syntax for a method that runs an INSERT statement:
@Update(sql = "INSERT INTO HEATHR.INVENTORY (PID, QUANTITY, LOCATION) VALUES (?, ?, ?)")
int createInventory(String pid, int quantity, String location);
Use this syntax for declaring annotated methods that run CALL statements.
>>-@Call--(--sql--=--"--SQL-statement--"--)---------------------> >--+------------------------------------------------------------------------------------------------------+--> '-@Handler--(--+-callHandlerWithParameters--=--class-name--+------------------------------------+-+--)-' | '-,--parameterHandler--=--class-name-' | '-parameterHandler--=--class-name--------------------------------------------------' >--modifiers--return-type--method-name--(--+-----------------------+--+------------------------------------+--);->< '-handler--handler-name-' | .-,------------------------------. | | V | | '---parameter-type--parameter-name-+-'
Example
@Call(sql = "Call MYSCHEMA.BONUS_INCREASE( :p_bonusfactor, :p_bonusmaxsumfordept,
:p_deptswithoutnewbonuses, :p_countdeptsviewed, :p_countdeptsbonuschanged,
:p_errormsg )")
StoredProcedureResult callBONUS_INCREASE(Bonus_increaseParam parms);
Use this syntax for declaring annotated methods that run SELECT statements. If you use the @Cursor annotation, you must import java.sql.ResultSet in your interface.
>>-@Select--(--sql--=--"--SQL-statement--"--)-------------------> >--+-----------------------------------------------------------------------------------------+--> | .-,-------------------------------------------------------------------. | | (1) V .-false-. | | '-@Cursor--(--------+-allowStaticRowsetCursors--=--+-true--+--------------------------+-+-' | .-java.sql.ResultSet.CONCUR_READ_ONLY-. | +-concurrency--=--+-java.sql.ResultSet.CONCUR_UPDATABLE-+---------+ | .-java.sql.ResultSet.CLOSE_CURSORS_AT_COMMIT--. | +-holdability--=--+-java.sql.ResultSet.HOLD_CURSORS_OVER_COMMIT-+-+ | .-java.sql.ResultSet.TYPE_FORWARD_ONLY-------. | '-type--=--+-java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE-+---------' '-java.sql.ResultSet.TYPE_SCROLL_SENSITIVE---' >--+------------------------------------------------------------------------------------------+--> '-@Handler--(--+-parameterHandler--=--class-name--------------------------------------+--)-' +-resultHandler--=--class-name--+------------------------------------+-+ | '-,--parameterHandler--=--class-name-' | '-rowHandler--=--class-name--+------------------------------------+----' '-,--parameterHandler--=--class-name-' >--modifiers--return-type--method-name--(--+-----------------------+--+------------------------------------+--);->< '-handler--handler-name-' | .-,------------------------------. | | V | | '---parameter-type--parameter-name-+-'
Example
@Select (sql="select PUBLISHER_ID, BOOK_NAME, BOOK_ID, COUNTY
from BOOKS WHERE STATE='CALIFORNIA'")
@Cursor (concurrency = ResultSet.CONCUR_READ_ONLY,
type=ResultSet.TYPE_FORWARD_ONLY,
holdability=ResultSet.HOLD_CURSORS_OVER_COMMIT)
Iterator<Books> getBooksInCaliforniaAndNameCursor ();
Use this syntax when declaring annotated methods for performing positioned updates and deletes. If you use the @Cursor annotation, you must import java.sql.ResultSet in your interface.
For information about writing annotated methods for positioned updates and deletes, see Performing positioned updates and deletes.
Syntax of the method that runs the SELECT statement that opens and names a cursor for a positioned update or delete.
>>-@Select--(--sql--=--"--SQL-statement--"--)-------------------> >--+------------------------------------------------------------------------------------------------------------------------------+--> | .-,-----------------------------------------------------------------------. | | V (1) .-java.sql.ResultSet.CONCUR_READ_ONLY-. | | '-@Cursor--(--cursorName--=--"--cursor-name--"--------+-concurrency--=--+-java.sql.ResultSet.CONCUR_UPDATABLE-+---------+-+--)-' | .-java.sql.ResultSet.CLOSE_CURSORS_AT_COMMIT--. | +-holdability--=--+-java.sql.ResultSet.HOLD_CURSORS_OVER_COMMIT-+-+ | .-java.sql.ResultSet.TYPE_FORWARD_ONLY-------. | '-type--=--+-java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE-+---------' '-java.sql.ResultSet.TYPE_SCROLL_SENSITIVE---' >--+---------------------------------------------------------------------------------------+--> '-@Handler--(--+-parameterHandler--=--class-name-----------------------------------+--)-' '-rowHandler--=--class-name--+------------------------------------+-' '-,--parameterHandler--=--class-name-' >--modifiers--+-Iterator-----------+--method-name--(--+-----------------------+--+------------------------------------+--);->< '-java.sql.ResultSet-' '-handler--handler-name-' | .-,------------------------------. | | V | | '---parameter-type--parameter-name-+-'
Syntax of the method that runs an UPDATE or DELETE statement that uses the named cursor
>>-@Update--(--sql--=--"--SQL-statement--"--,--positionedCursorName--=--"--cursor-name--"--)--> >--+-------------------------------------------------+----------> '-@Handler--(--parameterHandler--=--class-name--)-' >--modifiers--return-type--method-name--(--+-----------------------+--+------------------------------------+--);->< '-handler--handler-name-' | .-,------------------------------. | | V | | '---parameter-type--parameter-name-+-'
Example
Here is an example of the syntax for a method that runs a SELECT statement that opens a cursor for positioned updates and deletes:
@Select (sql="select PUBLISHER_ID, BOOK_NAME, BOOK_ID, COUNTY
from BOOKS WHERE STATE='CALIFORNIA' FOR UPDATE OF PUBLISHER_ID")
@Cursor (concurrency = ResultSet.CONCUR_UPDATABLE,
type=ResultSet.TYPE_FORWARD_ONLY,
holdability=ResultSet.HOLD_CURSORS_OVER_COMMIT,
cursorName="TESTCURSORITER")
Iterator<Books> getBooksInCaliforniaAndNameCursor ();
Here is an example of the syntax for a method that runs an UPDATE statement that uses the cursor:
@Update (sql="update BOOKS SET PUBLISHER_ID = :publisher_id",
positionedCursorName = "TESTCURSORITER")
int updateBooksByUsingNamedCursor (Book b);
pureQuery considers a statement as updatable if either of these conditions are true:
A repeating argument pair that shows the types and names of the arguments that are expected at method invocation time.
These parameters are matched with the parameter markers specified in the SQL statement according to the following rules. These parameters can be scalar types, bean classes, or Map objects. If the SQL uses the :name notation for parameter references, the first parameter-type must be a bean or a Map. The property names from the bean or Map are used for matching with the :name occurrences in the SQL string.
If the SQL uses the ? notation for parameter references, you can provide only scalar values.
If the ?n and ?n.name notation is used, the method parameters must be either all scalar types or a combination of and bean classes and Map objects.
The parameters specified are normally used only input variables. However, in the case of OUT or INOUT parameters on an SQL CALL statement, they might represent output variables. See the earlier section that discusses the CALL statement support for more details.
This table shows the return types that are possible for methods that use the @Call, @Select, and @Update annotations.
Abbreviation | Meaning |
---|---|
CAL | CallHandlerWithParameters |
I | Iterator |
L | List |
M | Map |
O | Object |
R | java.sql.ResultSet |
RES | ResultHandler |
ROW | RowHandler |
S | String |
SPR | StoredProcedureResult |
T | The primitive type int, a wrapper class for a primitive Java type, a simple Object type, or a bean. T is allowed to be an int only with @Update annotations, and in @Update annotations T is required to be int. |
Annotation | ||||
---|---|---|---|---|
@Call | @Select | @Update | ||
Return type | CAL | ✓ | ||
int | ✓ | |||
int[] | ✓ | |||
I<M<S,O>> | ✓ | ✓ | ||
I<T> | ✓ | ✓ | ||
L<M<S,O>> | ✓ | ✓ | ||
L<T> | ✓ | ✓ | ||
M<S,O> | ✓ | |||
M<S,O>[] | ✓ | ✓ | ||
R | ✓ | |||
RES | ✓ | |||
ROW | ✓ | |||
ROW[] | ✓ | |||
L<ROW> | ✓ | |||
I<ROW> | ✓ | |||
SPR | ✓ | |||
<T> | ✓ | |||
<T>[] | ✓ | ✓ | ||
void | ✓ | ✓ |
When you use an annotated method, do not specify that a @Select or @Call returns a primitive Java type, or an Array, List, or Iterator of a primitive Java type.
Information regarding SQL null values is lost whenever information queried from SQL is stored in a primitive Java type. Also, Java requires that a generic method that specifies generic <T> class of a <primitive Java type>.class must return an instance of the wrapper class that is appropriate for that primitive Java type.
int tCount = myGenericMethod( int.class );
where
this is the definition of myGenericMethod:<T> T myGenericMethod( Class<T> cl );
Integer tCount = myQuery.myGenericMethod( Integer.class );
This restriction is associated with use of generic methods even though there is no explicit use of generic method signatures (no use of <T> and return class information) in the method signatures that are defined in your annotated interface. This restriction is needed because the generated implementation of an annotated interface uses methods similar in some respects to the inline method API's. Specifically, the implementation makes use of generic methods.
Any underlying database ResultSet object is closed.
When a <T> object is returned by a CALL statement, the source of the data that populates the object is the first ResultSet object that the stored procedure returns.
When a <T> object is returned by a SELECT statement, the source of the data that populates the object is the result of the query.
When a Map<String,Object> object is returned by a CALL statement, the source of the data that populates the object is the first ResultSet object that the stored procedure returns.
When a Map<String,Object> object is returned by a SELECT statement, the source of the data that populates the object is the result of the query.
Any underlying database ResultSet object is closed.
Any underlying database ResultSet object is closed.
Specifies that a scalar or bean is returned. A scalar could be a wrapper such as Double, or a String, Date, or Timestamp.
If the provided SQL statement is a query and if more than one row qualifies, the value from the first row is returned.
Any underlying database ResultSet object is closed.
Specifies that an Iterator of Map<String,Object> objects is returned. See the description of returned Map<String,Object> objects for details.
The query result rows are retrieved from the data source as the application executes each next() operation on the Iterator.
Iterators in pureQuery are of type ResultIterator. You must close them with the ResultIterator.close() method after you finish using them.
Specifies that an Iterator object is returned, with each element corresponding to a row. The parameterized type T must be specified.
The query result rows are retrieved from the data source as the application executes each next() operation on the Iterator.
When a <T> object is returned by a CALL statement, the source of the data that populates the object is the first ResultSet object that the stored procedure returns.
When a <T> object is returned by a SELECT statement, the source of the data that populates the object is the result of the query.
Iterators in pureQuery are of type ResultIterator. You must close them with the ResultIterator.close() method after you finish using them.