Overview of inline methods

When you use the inline programming style, you can code your SQL queries, update statements, or CALL statements inline in your applications. An SQL statement appears as a parameter in the invocation of a method.

These are some of the advantages of using inline methods:

All inline methods are defined in the Data interface, which defines methods for querying and updating databases, running stored procedures, querying Collection and Iterator objects, and for managing transactions.

Types of query methods in the Data interface

The query methods can be classified into two groups.

Query methods that return results as individual beans or scalar objects, or as beans or scalar objects that are grouped together into Arrays, Lists, or Iterators
The class of the return bean is passed in as a parameter. Here are a few examples:
Employee employee = data.queryFirst("SELECT * FROM HRDEPT.EMP WHERE lastname = ?1", 
     Employee.class, lastName);

List<Employee> employees = data.queryList("SELECT * FROM HRDEPT.EMP",  Employee.class);

Employee[] employees = data.queryArray("SELECT * FROM HRDEPT.EMP", Employee.class);

Iterator<Employee> employees = data.queryIterator("SELECT * FROM HRDEPT.EMP", 
     Employee.class);
Query methods that return results as individual Map objects or as Map objects grouped together into Arrays, Lists, or Iterators
In a Map, column labels become String keys and column values become Object values. Here are two examples:
Map<String,Object> employee = data.queryFirst("SELECT * FROM HRDEPT.EMP WHERE lastname=?1", 
     lastName);

List<Map<String,Object>> employees = data.queryList("SELECT * FROM  HRDEPT.EMP"
     + "WHERE lastname LIKE ?", "Br%");

Inserts, updates, and deletes

You use the Data.update() method for single operations.

Employee newEmployee =
   new Employee("000010", "CHRISTINE", "I", "HAAS", "A00", 
      "3978", new java.sql.Date(System.currentTimeMillis()));

int rowsAffected = data.update("insert into hrdept.emp (id, firstname, midinit, lastname, deptno," 
     + "phoneext, hiredate)  VALUES (:id, :firstName, :midInit, :lastName, :deptNo, :phoneExt, :hireDate)", 
     newEmployee);

Employee employee =
   new Employee("000010", "CHRISTINE", "I", "HAAS", "A00", 
      "3978", new java.sql.Date(System.currentTimeMillis()));

int rowsAffected = data.update("update hrdept.emp set firstname = :firstName, midinit = :midInit," 
     + "lastname = :lastName, deptno = :deptNo, phoneext = :phoneExt, hiredate = :hireDate WHERE id = :id", employee);

int rowsAffected = data.update("delete from hrderp.emp where id=?1", id);

You use the Data.updateMany() method to perform an update operation multiple times.


Feedback