1 9 package com.ziclix.python.sql.handler; 10 11 import com.ziclix.python.sql.FilterDataHandler; 12 import com.ziclix.python.sql.DataHandler; 13 14 import java.util.Map ; 15 import java.util.HashMap ; 16 import java.sql.Statement ; 17 import java.sql.SQLException ; 18 import java.lang.reflect.Method ; 19 20 import org.python.core.PyObject; 21 import org.python.core.Py; 22 23 30 public abstract class RowIdHandler extends FilterDataHandler { 31 32 private static Map ROWIDS = new HashMap (); 33 private static Object CHECKED = new Object (); 34 35 public RowIdHandler(DataHandler handler) { 36 super(handler); 37 } 38 39 45 protected abstract String getRowIdMethodName(); 46 47 53 public PyObject getRowId(Statement stmt) throws SQLException { 54 55 Class c = stmt.getClass(); 56 Object o = ROWIDS.get(c); 57 58 if (o == null) { 59 synchronized (ROWIDS) { 60 try { 61 o = c.getMethod(getRowIdMethodName(), (Class [])null); 62 ROWIDS.put(c, o); 63 } catch (Throwable t) { 64 ROWIDS.put(c, CHECKED); 65 } 66 } 67 } 68 69 if (!(o == null || o == CHECKED)) { 70 try { 71 return Py.java2py(((Method ) o).invoke(stmt, (Object [])null)); 72 } catch (Throwable t) {} 73 } 74 75 return super.getRowId(stmt); 76 } 77 78 } 79 | Popular Tags |