@Override public List<Project> handle(ResultSet rs) throws SQLException { if (!rs.next()) { return Collections.<Project>emptyList(); } ArrayList<Project> projects = new ArrayList<Project>(); do { int id = rs.getInt(1); String name = rs.getString(2); boolean active = rs.getBoolean(3); long modifiedTime = rs.getLong(4); long createTime = rs.getLong(5); int version = rs.getInt(6); String lastModifiedBy = rs.getString(7); String description = rs.getString(8); int encodingType = rs.getInt(9); byte[] data = rs.getBytes(10); Project project; if (data != null) { EncodingType encType = EncodingType.fromInteger(encodingType); Object blobObj; try { // Convoluted way to inflate strings. Should find common package or // helper function. if (encType == EncodingType.GZIP) { // Decompress the sucker. String jsonString = GZIPUtils.unGzipString(data, "UTF-8"); blobObj = JSONUtils.parseJSONFromString(jsonString); } else { String jsonString = new String(data, "UTF-8"); blobObj = JSONUtils.parseJSONFromString(jsonString); } project = Project.projectFromObject(blobObj); } catch (IOException e) { throw new SQLException("Failed to get project.", e); } } else { project = new Project(id, name); } // update the fields as they may have changed project.setActive(active); project.setLastModifiedTimestamp(modifiedTime); project.setCreateTimestamp(createTime); project.setVersion(version); project.setLastModifiedUser(lastModifiedBy); project.setDescription(description); projects.add(project); } while (rs.next()); return projects; }