@Test public void getWhereStatement() { TestModel m = new TestModel(); m.setId(4); String where = Utils.getWhereStatement(m); assertEquals(where, "id=4"); }
static String getWhereStatement(Model m) { final ModelInfo info = ModelInfo.from(m.getClass()); final StringBuilder where = new StringBuilder(); final Object[] args = new Object[info.keys.size()]; for (int i = 0; i < info.keys.size(); i++) { final ModelInfo.ColumnField column = info.keys.get(i); where.append(column.name); where.append("=?"); column.field.setAccessible(true); try { args[i] = column.field.get(m); } catch (IllegalAccessException e) { throw new RuntimeException(e); } if (i < info.keys.size()-1) { where.append(" AND "); } } return Utils.insertSqlArgs(where.toString(), args); }
Utils { static String getWhereStatement(Model m) { final ModelInfo info = ModelInfo.from(m.getClass()); final StringBuilder where = new StringBuilder(); final Object[] args = new Object[info.keys.size()]; for (int i = 0; i < info.keys.size(); i++) { final ModelInfo.ColumnField column = info.keys.get(i); where.append(column.name); where.append("=?"); column.field.setAccessible(true); try { args[i] = column.field.get(m); } catch (IllegalAccessException e) { throw new RuntimeException(e); } if (i < info.keys.size()-1) { where.append(" AND "); } } return Utils.insertSqlArgs(where.toString(), args); } }
Utils { static String getWhereStatement(Model m) { final ModelInfo info = ModelInfo.from(m.getClass()); final StringBuilder where = new StringBuilder(); final Object[] args = new Object[info.keys.size()]; for (int i = 0; i < info.keys.size(); i++) { final ModelInfo.ColumnField column = info.keys.get(i); where.append(column.name); where.append("=?"); column.field.setAccessible(true); try { args[i] = column.field.get(m); } catch (IllegalAccessException e) { throw new RuntimeException(e); } if (i < info.keys.size()-1) { where.append(" AND "); } } return Utils.insertSqlArgs(where.toString(), args); }  }
Utils { static String getWhereStatement(Model m) { final ModelInfo info = ModelInfo.from(m.getClass()); final StringBuilder where = new StringBuilder(); final Object[] args = new Object[info.keys.size()]; for (int i = 0; i < info.keys.size(); i++) { final ModelInfo.ColumnField column = info.keys.get(i); where.append(column.name); where.append("=?"); column.field.setAccessible(true); try { args[i] = column.field.get(m); } catch (IllegalAccessException e) { throw new RuntimeException(e); } if (i < info.keys.size()-1) { where.append(" AND "); } } return Utils.insertSqlArgs(where.toString(), args); }   }
Utils { static String getWhereStatement(Model m) { final ModelInfo info = ModelInfo.from(m.getClass()); final StringBuilder where = new StringBuilder(); final Object[] args = new Object[info.keys.size()]; for (int i = 0; i < info.keys.size(); i++) { final ModelInfo.ColumnField column = info.keys.get(i); where.append(column.name); where.append("=?"); column.field.setAccessible(true); try { args[i] = column.field.get(m); } catch (IllegalAccessException e) { throw new RuntimeException(e); } if (i < info.keys.size()-1) { where.append(" AND "); } } return Utils.insertSqlArgs(where.toString(), args); }    }