1 22 package org.jboss.ejb.plugins.cmp.jdbc.keygen; 23 24 import java.sql.Connection ; 25 import java.sql.PreparedStatement ; 26 import java.sql.ResultSet ; 27 import java.sql.SQLException ; 28 import javax.ejb.EJBException ; 29 import org.jboss.ejb.EntityEnterpriseContext; 30 import org.jboss.ejb.plugins.cmp.jdbc.JDBCIdentityColumnCreateCommand; 31 import org.jboss.ejb.plugins.cmp.jdbc.JDBCUtil; 32 33 41 public class JDBCDB2IdentityValLocalCreateCommand extends JDBCIdentityColumnCreateCommand { 42 private static final String SQL = "values (identity_val_local())"; 43 44 protected int executeInsert(int paramIndex, PreparedStatement ps, EntityEnterpriseContext ctx ) throws SQLException { 45 int rows = ps.executeUpdate(); 46 ResultSet results = null; 47 try { 48 Connection conn = ps.getConnection(); 49 results = conn.prepareStatement( SQL ).executeQuery(); 50 if( !results.next() ) { 51 throw new EJBException ( "identity_val_local() returned an empty ResultSet" ); 52 } 53 pkField.loadInstanceResults( results, 1, ctx ); 54 } catch( RuntimeException e ) { 55 throw e; 56 } catch( Exception e ) { 57 throw new EJBException ( "Error extracting identity_val_local()", e ); 59 } finally { 60 JDBCUtil.safeClose( results ); 61 } 62 return rows; 63 } 64 } 65 | Popular Tags |