Hi, > the columns of a table should be a set (and thus have no ordering).
That would be much slower. I also wrote a generic wrapper (abstract class) - see below. It's a bit faster than yours because the map is created when initializing. Be careful, I didn't actually test the adapter (it compiles, that's it). But please note HashMap<String, Object> is case sensitive; using SimpleResultSet is better I agree. > Maybe this remark could be added to trigger documentation? Yes, I will do that. > Indexing is sometimes 1 based and sometimes 0 based. > It's easy to get this wrong. In Java, array indexing is always 0 based. Regards, Thomas ---------------- http://h2database.com/p.html#b82cb3aa6ecf7915488c9f92019cc05a package db; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.HashMap; import org.h2.api.Trigger; import org.h2.util.New; public abstract class TriggerAdapter implements Trigger { private ArrayList<String> columnNames; public void init(Connection conn, String schemaName, String triggerName, String tableName, boolean before, int type) throws SQLException { ResultSet rs = conn.getMetaData().getColumns( null, schemaName, tableName, null); while (rs.next()) { columnNames.add(rs.getString("COLUMN_NAME")); } } public void fire(Connection conn, Object[] oldRow, Object[] newRow) throws SQLException { fire(conn, wrap(oldRow), wrap(newRow)); } public abstract void fire(Connection conn, HashMap<String, Object> oldRow, HashMap<String, Object> newRow); private HashMap<String, Object> wrap(Object[] row) { if (row == null) { return null; } HashMap<String, Object> map = New.hashMap(); for (int i = 0; i < row.length; i++) { map.put(columnNames.get(i), row[i]); } return map; } public void remove() throws SQLException { // do nothing by default } public void close() throws SQLException { // do nothing by default } } -- You received this message because you are subscribed to the Google Groups "H2 Database" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/h2-database?hl=en.
