1 22 23 import org.xquark.mapping.*; 24 import java.sql.*; 25 import java.math.*; 26 27 33 34 public class ClientId implements UserGenerator { 35 36 private static int counter = -1; 37 38 public String getXMLType() { 39 return "int"; 40 } 41 42 public synchronized Object getValue(StorageContext context) { 43 if (counter < 0) 44 initCounter(context.getConnection()); 45 return new BigDecimal(++counter); 46 } 47 48 void initCounter(Connection connection) { 49 ResultSet rs = null; 50 Statement statement = null; 51 try { 52 statement = connection.createStatement(); 53 rs = statement.executeQuery("select max(\"id\") from \"client\""); 54 Object result = null; 55 while (rs.next()) { 56 counter = rs.getInt(1); 57 } 58 } 59 catch (Exception ex) { 60 ex.printStackTrace(); 61 } 62 finally { 63 try { 64 if (rs != null) 65 rs.close(); 66 if (statement != null) 67 statement.close(); 68 } 69 catch (SQLException ex) { 70 } 72 } 73 } 74 } 75 | Popular Tags |