Skip to main content

skip to main content

developerWorks  >  Information Management | Java technology  >

Write high performance, Java data access applications, Part 1: Introducing pureQuery annotated method style

Maximize security and configurability

developerWorks

Return to article


Listing 2. pureQuery code generator output
                
// Generated on 2007-11-05-08:59:43.898 using plug-in com.ibm.pdq.tools.  
Generator version 1.0.18
// This generated code should not be modified. 
    Any changes should be made to the Interface source
// file and this implementation code regenerated.
package com.ibm.db2.pureQuery;

import com.ibm.pdq.runtime.StoredProcedureResult;
import java.util.Iterator;
import com.ibm.db2.pureQuery.Customer;
import com.ibm.pdq.runtime.generator.BaseParameterHandler;
import com.ibm.pdq.runtime.statement.SqlStatementType;
import com.ibm.pdq.runtime.handlers.RowHandler;
import com.ibm.pdq.annotation.Metadata;
import com.ibm.pdq.runtime.generator.BaseData;
import com.ibm.pdq.runtime.generator.BaseCallHandler;
import com.ibm.pdq.runtime.statement.StatementDescriptor;
import java.sql.CallableStatement;
import java.sql.Types;
import java.sql.PreparedStatement;
import java.sql.SQLException;


public class CustomerDataImpl  extends BaseData implements CustomerData
{

  public CustomerDataImpl() {} 

  public static final String generatorVersion = "1.0.18";
  public static final String identifier = "Custome";
  public static final String collection = "NULLID";
  public static final long generationTime = 1194274783898l;

  // select CID, NAME, COUNTRY, STREET, CITY, PROVINCE, ZIP, PHONE, 
    INFO from PDQ_SC.CUSTOMER
  public Iterator<Customer> getCustomers ()
  {
    return queryIterator (getCustomersStatementDescriptor);
  }

  @Metadata ()
  public static final StatementDescriptor getCustomersStatementDescriptor =
createStatementDescriptor (
    "getCustomers()",
    "select CID, NAME, COUNTRY, STREET, CITY, PROVINCE, ZIP, PHONE, 
       INFO from PDQ_SC.CUSTOMER",
    SqlStatementType.QUERY,
    null,
    null,
    null,
    new GetCustomersRowHandler (),
    new int[][]{  {Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, 
Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.CLOB}, 
{10, 128, 128, 128, 128, 128, 128, 128, 32768}, 
{0, 0, 0, 0, 0, 0, 0, 0, 0},
 {0, 1208, 1208, 1208, 1208, 1208, 1208, 1208, 1208}},
    identifier,
    collection,
    generationTime,
    1);

  public static class GetCustomersRowHandler implements RowHandler<Customer>
  {
    public Customer handle (java.sql.ResultSet rs, Customer returnObject) 
      throws java.sql.SQLException
    {
      returnObject = new Customer ();
      returnObject.setCid(rs.getInt (1)); 
      returnObject.setName(rs.getString (2)); 
      returnObject.setCountry(rs.getString (3)); 
      returnObject.setStreet(rs.getString (4)); 
      returnObject.setCity(rs.getString (5)); 
      returnObject.setProvince(rs.getString (6)); 
      returnObject.setZip(rs.getString (7)); 
      returnObject.setPhone(rs.getString (8)); 
      returnObject.setInfo(rs.getString (9)); 
    
      return returnObject;
    }
  }

  // select CID, NAME, COUNTRY, STREET, CITY, PROVINCE, ZIP, PHONE, 
      INFO from PDQ_SC.CUSTOMER where CID = ?
  public Customer getCustomer (int cid)
  {
    return queryFirst (getCustomerStatementDescriptor, cid);
  }

  @Metadata ()
  public static final StatementDescriptor 
      getCustomerStatementDescriptor = createStatementDescriptor (
    "getCustomer(int)",
    "select CID, NAME, COUNTRY, STREET, CITY, PROVINCE, ZIP, PHONE, 
      INFO from PDQ_SC.CUSTOMER where CID = ?",
    SqlStatementType.SINGLE_ROW_QUERY,
    null,
    new GetCustomerParameterHandler (),
    new int[][]{{Types.INTEGER}, {10}, {0}, {1}},
    new GetCustomerRowHandler (),
    new int[][]{
 {Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
      Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.CLOB},
 {10, 128, 128, 128, 128, 128, 128, 128, 32768},
 {0, 0, 0, 0, 0, 0, 0, 0, 0},
 {0, 1208, 1208, 1208, 1208, 1208, 1208, 1208, 1208}},
    identifier,
    collection,
    generationTime,
    2);

  public static class GetCustomerParameterHandler extends BaseParameterHandler 
  {
    public void handleParameters (PreparedStatement stmt, Object... parameters)
       throws SQLException
    {
      setInteger (stmt, 1, Types.INTEGER, (Integer)parameters[0]);
    }
  }

  public static class GetCustomerRowHandler implements RowHandler<Customer>
  {
    public Customer handle (java.sql.ResultSet rs, Customer returnObject)\
      throws java.sql.SQLException
    {
      returnObject = new Customer ();
      returnObject.setCid(rs.getInt (1)); 
      returnObject.setName(rs.getString (2)); 
      returnObject.setCountry(rs.getString (3)); 
      returnObject.setStreet(rs.getString (4)); 
      returnObject.setCity(rs.getString (5)); 
      returnObject.setProvince(rs.getString (6)); 
      returnObject.setZip(rs.getString (7)); 
      returnObject.setPhone(rs.getString (8)); 
      returnObject.setInfo(rs.getString (9)); 
    
      return returnObject;
    }
  }

}

Return to article