Community
Participate
Working Groups
Build Identifier: DBAdapter validates a table by doing a full query and relies on SQLExceptions to see if a table has already been created. On most databases this isn't a problem, because they have server-side cursors. H2, on the other hand reads the entire table (tested with H2 1.1), which is quite an expensive operation if table has many rows. H2 reads the whole table into memory which can result in extensive swapping. Please consider overriding validateTable() in H2Adapter as so: @Override protected void validateTable(IDBTable table, Statement statement) throws DBException { String sql = null; try { StringBuilder builder = new StringBuilder(); builder.append("SELECT "); appendFieldNames(builder, table); builder.append(" FROM "); builder.append(table); builder.append(" LIMIT 1"); // Only retrieve the first result sql = builder.toString(); ResultSet resultSet = statement.executeQuery(sql); ResultSetMetaData metaData = resultSet.getMetaData(); int columnCount = metaData.getColumnCount(); if (columnCount != table.getFieldCount()) { throw new DBException("DBTable " + table + " has " + columnCount + " columns instead of " + table.getFieldCount()); } } catch (SQLException ex) { throw new DBException("Problem with table " + table, ex, sql); } } ... or another similar solution that duplicates less code. Reproducible: Always
Created attachment 193040 [details] Patch v1 What about this vendor-agnostic approach? Can you confirm that it solves the issue with H2?
(In reply to comment #1) > Created attachment 193040 [details] > Patch v1 > > What about this vendor-agnostic approach? Can you confirm that it solves the > issue with H2? Yes, this seems to work also. Thanks for the quick reply!
You're welcome ;-) Committed revision 7610
Available in R20110608-1407