comparison flys-artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/ResultData.java @ 5831:bd047b71ab37

Repaired internal references
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 12:06:39 +0200
parents flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/ResultData.java@ac2746f3e75f
children
comparison
equal deleted inserted replaced
5830:160f53ee0870 5831:bd047b71ab37
1 package org.dive4elements.river.artifacts.datacage.templating;
2
3 import java.io.Serializable;
4
5 import java.sql.ResultSetMetaData;
6 import java.sql.ResultSet;
7 import java.sql.SQLException;
8
9 import java.util.List;
10 import java.util.ArrayList;
11
12 import org.apache.log4j.Logger;
13
14
15 /** Result Data from a DB/SQL query. */
16 public class ResultData
17 implements Serializable
18 {
19 private static Logger log = Logger.getLogger(ResultData.class);
20
21 protected String [] columns;
22
23 protected List<Object []> rows;
24
25 public ResultData() {
26 rows = new ArrayList<Object []>();
27 }
28
29 public ResultData(String [] columns, List<Object []> rows) {
30 this.columns = columns;
31 this.rows = rows;
32 }
33
34 public ResultData(ResultSetMetaData meta)
35 throws SQLException
36 {
37 this();
38
39 boolean debug = log.isDebugEnabled();
40
41 int N = meta.getColumnCount();
42
43 columns = new String[N];
44
45 if (debug) {
46 log.debug("ResultSet column names:");
47 }
48
49 for (int i = 1; i <= N; ++i) {
50 columns[i-1] = meta.getColumnLabel(i).toUpperCase();
51 if (debug) {
52 log.debug(" " + i + ": " + columns[i-1]);
53 }
54 }
55 }
56
57 public String [] getColumnLabels() {
58 return columns;
59 }
60
61 public ResultData addAll(ResultSet result) throws SQLException {
62 while (result.next()) {
63 add(result);
64 }
65 return this;
66 }
67
68 public void add(ResultSet result) throws SQLException {
69 Object [] row = new Object[columns.length];
70 for (int i = 0; i < columns.length; ++i) {
71 row[i] = result.getObject(i+1);
72 }
73 rows.add(row);
74 }
75
76 public List<Object []> getRows() {
77 return rows;
78 }
79
80 public boolean isEmpty() {
81 return rows.isEmpty();
82 }
83 }
84 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org