Use of OracleSequence and CompoundSqlOperation to create an EJB.

COMPONENT JAVA
Applying Design Patterns to JDBC: Building a Lightweight Object-Relational Mapping Framework
Frank Sauer
Listing 7. Use of OracleSequence and CompoundSqlOperation to create an EJB.


public CustomerPK ejbCreate(Customer value)
          throws RemoteException,
                    CreateException {
  try {
      value.printOn(System.err);
      // let Oracle decide what the next
      // primary key will be...
      BigDecimal nextId = (new OracleSequence(
                  SQLConstants.CUSTOMER_SEQ)
                  ).getNextValue();
      value.setId(nextId.intValue());
      InsertCustomer sql1 =
                  new InsertCustomer(value);
      InsertCustomerContact sql2 =
                  new InsertCustomerContact(value);

      CompoundSqlOperation cso =
                  new CompoundSqlOperation(sql1,sql2);
      // write the address if it's not null
      if (value.getDefaultAddress() != null) {
          cso.add(
             new InsertDefaultAddress(value));
      }
      cso.execute();
      setValue(value);
      return new CustomerPK(value.getId());
  } catch (SQLException x) {
      throw new CreateException(
  "SQLException trying to create customer " +
                  value);
  }
  }