1 16 17 package org.apache.cocoon.components.modules.database; 18 19 import java.sql.Connection ; 20 import java.sql.PreparedStatement ; 21 import java.sql.ResultSet ; 22 import java.sql.SQLException ; 23 import java.sql.Statement ; 24 import java.util.Map ; 25 26 import org.apache.avalon.framework.configuration.Configuration; 27 import org.apache.avalon.framework.configuration.ConfigurationException; 28 import org.apache.avalon.framework.thread.ThreadSafe; 29 30 37 public class SQLServerIdentityAutoIncrementModule implements AutoIncrementModule, ThreadSafe { 38 39 public Object getPostValue( Configuration tableConf, Configuration columnConf, Configuration modeConf, 40 Connection conn, Statement stmt, Map objectModel ) throws SQLException , ConfigurationException { 41 42 Integer id = null; 43 50 51 PreparedStatement pstmt = conn.prepareStatement("select @@IDENTITY"); 52 ResultSet resultSet = pstmt.executeQuery(); 53 while ( resultSet.next() ) { 54 id = new Integer (resultSet.getInt(1)); 55 } 56 resultSet.close(); 57 58 return id; 59 } 60 61 62 public boolean includeInQuery() { return false; } 63 64 65 public boolean includeAsValue() { return false; } 66 67 68 public Object getPreValue( Configuration tableConf, Configuration columnConf, Configuration modeConf, 69 Connection conn, Map objectModel ) throws SQLException , ConfigurationException { 70 71 return null; 72 } 73 74 75 public String getSubquery( Configuration tableConf, Configuration columnConf, Configuration modeConf ) 76 throws ConfigurationException { 77 78 return null; 79 } 80 } 81 | Popular Tags |