News for hackers. Stuff that matters.
Re:Why isn't Java used for modern web application development? by fizx on Sunday June 10, 2012 @05:21PM (#4092253)
I tend to work more with document-like stores than SQL these days, so there may be more idiomatic solutions....

If you're complaining about having to update the fields in your object, I think thats kinda silly. You bought into the idea of static typing at some point, and now your data has type constraints. If you need need need flexibility you can of course make some field a Map<String, Object>.

If you're complaining about boilerplate, you can at least automate the mapping with code like:

    class Util {
      public static <T> T resultSetToObject(ResultSet rs, Class<T> klass) {
        List<Map<String, Object>> rows = new ArrayList<Map<String, Object>>();
        ResultSetMetaData metaData = resultSet.getMetaData();
        int columnCount = metaData.getColumnCount();

        while (resultSet.next()) {
          Map<String, Object> columns = new LinkedHashMap<String, Object>();

          for (int i = 1; i <= columnCount; i++) {
            columns.put(metaData.getColumnLabel(i), resultSet.getObject(i));
          }

          rows.add(columns);
        }
    
        return new ObjectMapper().convertValue(rows, klass)
      }
    }
Re:Why isn't Java used for modern web application development? by swah on Monday June 11, 2012 @10:09AM (#4094640)
Yes, I wrote something similar (a Rowmap object)... But I have to admit it took me a while to realize that I could break that pattern.