jinlin
2024-01-31 9025b9cf7ec8610003d445a31d93e35e7bd73c2e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
package com.zt.generator.data;
 
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
 
import java.io.Serializable;
import java.sql.*;
import java.util.*;
import java.util.Date;
 
public class DataTable implements Serializable, Cloneable {
 
    private boolean isWebMode;// 默认值为false,True表示getString的结果是null或者""时转成 
 
    private DataRow[] rows;
 
    private DataColumn[] columns;
 
    public DataTable() {
        this.rows = new DataRow[0];
        this.columns = new DataColumn[0];
    }
 
    public DataTable(DataColumn[] types, Object[][] values) {
        if (types == null) {
            types = new DataColumn[0];
        }
        columns = null;
        rows = null;
        // 判断是否有相同列名
        if (this.checkColumns(types)) {
            columns = types;
        }
        if (values != null) {
            rows = new DataRow[values.length];
            for (int i = 0; i < rows.length; i++) {
                rows[i] = new DataRow(columns, values[i]);
            }
        } else {
            this.rows = new DataRow[0];
        }
    }
 
    // 判断是否有相同列名
    public boolean checkColumns(DataColumn[] types) {
        if (types == null) {
            return false;
        }
        for (int i = 0; i < types.length; i++) {
            String columnName = types[i].getColumnName();
            for (int j = 0; j < i; j++) {
                if (columnName == null) {
                    throw new RuntimeException("DataTable中第" + i + "列列名为null!");
                }
                if (columnName.equals(types[j].getColumnName())) {
                    throw new RuntimeException("一个DataTable中不充许有重名的列:" + columnName);
                }
            }
        }
        return true;
    }
 
    public DataTable(ResultSet rs) {
        this(rs, Integer.MAX_VALUE, 0);
    }
 
    public DataTable(ResultSet rs, int pageSize, int pageIndex) {
        ResultSetMetaData rsmd;
        try {
            // 以下准备DataColumn[]
            rsmd = rs.getMetaData();
            int columnCount = rsmd.getColumnCount();
            DataColumn[] types = new DataColumn[columnCount];
            for (int i = 1; i <= columnCount; i++) {
                String name = rsmd.getColumnLabel(i);
                boolean b = rsmd.isNullable(i) == ResultSetMetaData.columnNullable;
                DataColumn dc = new DataColumn();
                dc.setAllowNull(b);
                dc.setColumnName(name);
 
                // 以下设置数据类型
                int dataType = rsmd.getColumnType(i);
                if (dataType == Types.CHAR || dataType == Types.VARCHAR || dataType == Types.LONGVARCHAR) {
                    dc.ColumnType = DataColumn.STRING;
                } else if (dataType == Types.TIMESTAMP || dataType == Types.DATE) {
                    dc.ColumnType = DataColumn.DATETIME;
                } else if (dataType == Types.DECIMAL) {
                    dc.ColumnType = DataColumn.DECIMAL;
                } else if (dataType == Types.FLOAT) {
                    dc.ColumnType = DataColumn.FLOAT;
                } else if (dataType == Types.INTEGER) {
                    dc.ColumnType = DataColumn.INTEGER;
                } else if (dataType == Types.SMALLINT) {
                    dc.ColumnType = DataColumn.SMALLINT;
                } else if (dataType == Types.BIGINT) {
                    dc.ColumnType = DataColumn.LONG;
                } else if (dataType == Types.BLOB) {
                    dc.ColumnType = DataColumn.BLOB;
                } else if (dataType == Types.CLOB) {
                    dc.ColumnType = DataColumn.CLOB;
                } else if (dataType == Types.NUMERIC) {
                    int dataScale = rsmd.getScale(i);
                    int dataPrecision = rsmd.getPrecision(i);
                    if (dataScale == 0) {
                        if (dataPrecision == 0) {
                            dc.ColumnType = DataColumn.BIGDECIMAL;
                        } else {
                            dc.ColumnType = DataColumn.LONG;
                        }
                    } else {
                        dc.ColumnType = DataColumn.BIGDECIMAL;
                    }
                } else {
                    DatabaseMetaData md = rs.getStatement().getConnection().getMetaData();
                    String DBType = md.getDatabaseProductName().toUpperCase();
                    if (dataType == Types.LONGVARBINARY && DBType.equals(DBConnConfig.MYSQL)) {
                        dc.ColumnType = DataColumn.BLOB;
                    } else {
                        dc.ColumnType = DataColumn.STRING;
                    }
                }
                types[i - 1] = dc;
            }
 
            if (this.checkColumns(types)) {
                columns = types;
            }
            // 以下准备ColumnValues[]
            List list = new ArrayList();
            int index = 0;
            int begin = pageIndex * pageSize;
            int end = (pageIndex + 1) * pageSize;
            while (rs.next()) {
                if (index >= end) {
                    break;
                }
                if (index >= begin) {
                    Object[] t = new Object[columnCount];
                    for (int j = 1; j <= columnCount; j++) {
                        if (columns[j - 1].getColumnType() == DataColumn.CLOB) {
                            t[j - 1] = LobUtil.clobToString(rs.getClob(j));
                        } else if (columns[j - 1].getColumnType() == DataColumn.BLOB) {
                            t[j - 1] = LobUtil.blobToBytes(rs.getBlob(j));
                        } else {
                            t[j - 1] = rs.getObject(j);
                        }
                    }
                    DataRow tmpRow = new DataRow(columns, t);
                    list.add(tmpRow);
                }
                index++;
            }
            this.rows = new DataRow[list.size()];
            list.toArray(this.rows);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
 
    public void deleteColumn(int columnIndex) {
        if (columns.length == 0) {
            return;
        }
        if (columnIndex < 0 || (columns != null && columnIndex >= columns.length)) {
            throw new RuntimeException("DataRow中没有指定的列:" + columnIndex);
        }
        this.columns = (DataColumn[]) ArrayUtils.remove(this.columns, columnIndex);
        for (int i = 0; i < rows.length; i++) {
            rows[i].columns = null;
            rows[i].columns = this.columns;
            rows[i].values = ArrayUtils.remove(rows[i].values, columnIndex);
        }
    }
 
    public void deleteColumn(String columnName) {
        if (columns.length == 0) {
            return;
        }
        for (int i = 0; i < columns.length; i++) {
            if (columns[i].getColumnName().equalsIgnoreCase(columnName)) {
                deleteColumn(i);
                break;
            }
        }
    }
 
    public void insertColumn(String columnName) {
        insertColumn(new DataColumn(columnName, DataColumn.STRING), null, columns.length);
    }
 
    public void insertColumn(String columnName, Object columnValue) {
        Object[] cv = new Object[rows.length];
        for (int i = 0; i < cv.length; i++) {
            cv[i] = columnValue;
        }
        insertColumn(new DataColumn(columnName, DataColumn.STRING), cv, columns.length);
    }
 
    public void insertColumns(String[] columnNames) {
        for (int i = 0; i < columnNames.length; i++) {
            insertColumn(new DataColumn(columnNames[i], DataColumn.STRING), null, columns.length);
        }
    }
 
    public void insertColumn(String columnName, Object[] columnValue) {
        insertColumn(new DataColumn(columnName, DataColumn.STRING), columnValue, columns.length);
    }
 
    public void insertColumn(DataColumn dc) {
        insertColumn(dc, null, columns.length);
    }
 
    public void insertColumn(DataColumn dc, Object[] columnValue) {
        insertColumn(dc, columnValue, columns.length);
    }
 
    public void insertColumn(String columnName, Object[] columnValue, int index) {
        insertColumn(new DataColumn(columnName, DataColumn.STRING), columnValue, index);
    }
 
    public void insertColumn(DataColumn dc, Object[] columnValue, int index) {
        if (index > columns.length) {
            throw new RuntimeException("DataRow中没有指定的列:" + index);
        }
        for (int i = 0; i < columns.length; i++) {
            if (columns[i].getColumnName().equalsIgnoreCase(dc.getColumnName())) {
                throw new RuntimeException("DataTable中已经存在列:" + dc.getColumnName());
            }
        }
        this.columns = (DataColumn[]) ArrayUtils.add(columns, index, dc);
        if (columnValue == null) {
            columnValue = new Object[rows.length];
        }
        if (rows.length == 0) {
            rows = new DataRow[columnValue.length];
            for (int i = 0; i < rows.length; i++) {
                rows[i] = new DataRow(this.columns, new Object[] { columnValue[i] });
            }
        } else {
            for (int i = 0; i < rows.length; i++) {
                rows[i].columns = null;
                rows[i].columns = this.columns;
                rows[i].values = ArrayUtils.add(rows[i].values, index, columnValue[i]);
            }
        }
    }
 
    public void insertRow(DataRow dr) {
        insertRow(dr, rows.length);
    }
 
    public void insertRow(DataRow dr, int index) {
        if (columns.length == 0) {
            columns = dr.columns;
        }
        insertRow(dr.getDataValues(), index);
    }
 
    public void insertRow(Object[] rowValue) {
        insertRow(rowValue, rows.length);
    }
 
    public void insertRow(Object[] rowValue, int index) {
        if (index > rows.length) {
            throw new RuntimeException(index + "超出范围,最大允许值为" + rows.length + "!");
        }
        if (rowValue != null) {
            if (columns.length == 0) {
                columns = new DataColumn[rowValue.length];
                for (int i = 0; i < columns.length; i++) {
                    columns[i] = new DataColumn("_Columns_" + i, DataColumn.STRING);
                }
            }
            if (rowValue.length != columns.length) {
                throw new RuntimeException("新增行的列数为" + rowValue.length + ",要求的列数为" + columns.length + "!");
            }
            for (int i = 0; i < columns.length; i++) {
                if (columns[i].ColumnType == DataColumn.DATETIME) {
                    if (rowValue[i] != null && !Date.class.isInstance(rowValue[i])) {
                        throw new RuntimeException("第" + i + "列必须是Date对象!");
                    }
                }
            }
        } else {
            rowValue = new Object[columns.length];
        }
        DataRow[] newRows = new DataRow[rows.length + 1];
        System.arraycopy(rows, 0, newRows, 0, index);
        if (index < rows.length) {
            System.arraycopy(rows, index, newRows, index + 1, rows.length - index);
        }
        newRows[index] = new DataRow(columns, rowValue);
        rows = newRows;
    }
 
    public void deleteRow(int index) {
        if (index >= rows.length) {
            throw new RuntimeException(index + "超出范围,最大允许值为" + (rows.length - 1) + "!");
        }
        rows = (DataRow[]) ArrayUtils.remove(rows, index);
    }
 
    public void deleteRow(DataRow dr) {
        for (int i = 0; i < rows.length; i++) {
            if (dr == rows[i]) {
                deleteRow(i);
                return;
            }
        }
        throw new RuntimeException("指定的DataRow对象不属于此DataTable!");
    }
 
    public DataRow get(int rowIndex) {
        if (rowIndex >= rows.length || rowIndex < 0) {
            throw new RuntimeException("指定的行索引值超出范围");
        }
        return rows[rowIndex];
    }
 
    public void set(int rowIndex, int colIndex, Object value) {
        getDataRow(rowIndex).set(colIndex, value);
    }
 
    public void set(int rowIndex, String columnName, Object value) {
        getDataRow(rowIndex).set(columnName, value);
    }
 
    public void set(int rowIndex, int colIndex, int value) {
        getDataRow(rowIndex).set(colIndex, value);
    }
 
    public void set(int rowIndex, String columnName, int value) {
        getDataRow(rowIndex).set(columnName, value);
    }
 
    public void set(int rowIndex, int colIndex, long value) {
        getDataRow(rowIndex).set(colIndex, value);
    }
 
    public void set(int rowIndex, String columnName, long value) {
        getDataRow(rowIndex).set(columnName, value);
    }
 
    public void set(int rowIndex, int colIndex, double value) {
        getDataRow(rowIndex).set(colIndex, value);
    }
 
    public void set(int rowIndex, String columnName, double value) {
        getDataRow(rowIndex).set(columnName, value);
    }
 
    public Object get(int rowIndex, int colIndex) {
        return getDataRow(rowIndex).get(colIndex);
    }
 
    public Object get(int rowIndex, String columnName) {
        return getDataRow(rowIndex).get(columnName);
    }
 
    public String getString(int rowIndex, int colIndex) {
        return getDataRow(rowIndex).getString(colIndex);
    }
 
    public String getString(int rowIndex, String columnName) {
        return getDataRow(rowIndex).getString(columnName);
    }
 
    public int getInt(int rowIndex, int colIndex) {
        return getDataRow(rowIndex).getInt(colIndex);
    }
 
    public int getInt(int rowIndex, String columnName) {
        return getDataRow(rowIndex).getInt(columnName);
    }
 
    public long getLong(int rowIndex, int colIndex) {
        return getDataRow(rowIndex).getLong(colIndex);
    }
 
    public long getLong(int rowIndex, String columnName) {
        return getDataRow(rowIndex).getLong(columnName);
    }
 
    public double getDouble(int rowIndex, int colIndex) {
        return getDataRow(rowIndex).getDouble(colIndex);
    }
 
    public double getDouble(int rowIndex, String columnName) {
        return getDataRow(rowIndex).getDouble(columnName);
    }
 
    public Date getDate(int rowIndex, int colIndex) {
        return getDataRow(rowIndex).getDate(colIndex);
    }
 
    public Date getDate(int rowIndex, String columnName) {
        return getDataRow(rowIndex).getDate(columnName);
    }
 
    public DataRow getDataRow(int rowIndex) {
        if (rowIndex >= rows.length || rowIndex < 0) {
            throw new RuntimeException("指定的行索引值超出范围");
        }
        return rows[rowIndex];
    }
 
    public DataColumn getDataColumn(int columnIndex) {
        if (columnIndex < 0 || columnIndex >= columns.length) {
            throw new RuntimeException("指定的列索引值超出范围");
        }
        return columns[columnIndex];
    }
 
    public DataColumn getDataColumn(String columnName) {
        for (int i = 0; i < columns.length; i++) {
            if (columns[i].getColumnName().equalsIgnoreCase(columnName)) {
                return (getDataColumn(i));
            }
        }
        return null;
    }
 
    public Object[] getColumnValues(int columnIndex) {
        if (columnIndex < 0 || columnIndex >= columns.length) {
            throw new RuntimeException("指定的列索引值超出范围");
        }
        Object[] arr = new Object[this.getRowCount()];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = this.rows[i].values[columnIndex];
        }
        return arr;
    }
 
    public Object[] getColumnValues(String columnName) {
        for (int i = 0; i < columns.length; i++) {
            if (columns[i].getColumnName().equalsIgnoreCase(columnName)) {
                return getColumnValues(i);
            }
        }
        return null;
    }
 
    public void sort(Comparator c) {
        Arrays.sort(rows, c);
    }
 
    public void sort(String columnName) {
        sort(columnName, "desc", false);
    }
 
    public void sort(String columnName, String order) {
        sort(columnName, order, false);
    }
 
    public void sort(String columnName, String order, final boolean isNumber) {
        final String cn = columnName;
        final String od = order;
        sort(new Comparator() {
            public int compare(Object obj1, Object obj2) {
                DataRow dr1 = (DataRow) obj1;
                DataRow dr2 = (DataRow) obj2;
                Object v1 = dr1.get(cn);
                Object v2 = dr2.get(cn);
                if (v1 instanceof Number && v2 instanceof Number) {
                    double d1 = ((Number) v1).doubleValue();
                    double d2 = ((Number) v2).doubleValue();
                    if (d1 == d2) {
                        return 0;
                    } else if (d1 > d2) {
                        return "asc".equalsIgnoreCase(od) ? 1 : -1;
                    } else {
                        return "asc".equalsIgnoreCase(od) ? -1 : 1;
                    }
                } else if (v1 instanceof Date && v2 instanceof Date) {
                    Date d1 = (Date) v1;
                    Date d2 = (Date) v1;
                    if ("asc".equalsIgnoreCase(od)) {
                        return d1.compareTo(d2);
                    } else {
                        return -d1.compareTo(d2);
                    }
                } else if (isNumber) {
                    double d1 = 0, d2 = 0;
                    try {
                        d1 = Double.parseDouble(String.valueOf(v1));
                        d2 = Double.parseDouble(String.valueOf(v2));
                    } catch (Exception e) {
                    }
                    if (d1 == d2) {
                        return 0;
                    } else if (d1 > d2) {
                        return "asc".equalsIgnoreCase(od) ? -1 : 1;
                    } else {
                        return "asc".equalsIgnoreCase(od) ? 1 : -1;
                    }
                } else {
                    int c = dr1.getString(cn).compareTo(dr2.getString(cn));
                    if ("asc".equalsIgnoreCase(od)) {
                        return c;
                    } else {
                        return -c;
                    }
                }
            }
        });
    }
 
    // public DataTable filter(Filter filter) {
    // List valueList = new ArrayList();
    // for (int i = 0; i < rows.length; i++) {
    // if (filter.filter(rows[i])) {
    // valueList.add(rows[i]);
    // }
    // }
    // DataTable dt = new DataTable();
    // dt.columns = this.columns;
    // dt.rows = new DataRow[valueList.size()];
    // valueList.toArray(dt.rows);
    // dt.setWebMode(this.isWebMode);
    // return dt;
    // }
 
    /**
     * 还存在一些问题,只是浅层拷贝,有待于类型更为严格之后再来修改
     */
    public Object clone() {
        DataColumn[] dcs = new DataColumn[columns.length];
        for (int i = 0; i < columns.length; i++) {
            dcs[i] = (DataColumn) this.columns[i].clone();
        }
        DataTable dt = new DataTable();
        dt.columns = dcs;
        dt.rows = (DataRow[]) this.rows.clone();
        dt.setWebMode(this.isWebMode);
        return dt;
    }
 
    /**
     * 以指定的列字段值为key,以另一指定的列值为value,填充到一个Map中,并返回此Map
     */
    public Map toMap(String keyColumnName, String valueColumnName) {
        if (StringUtils.isEmpty(keyColumnName)) {
            throw new RuntimeException("不能存取列名为空的列");
        }
        if (StringUtils.isEmpty(valueColumnName)) {
            throw new RuntimeException("不能存取列名为空的列");
        }
        int keyIndex = 0, valueIndex = 0;
        boolean keyFlag = false, valueFlag = false;
        for (int i = 0; i < columns.length; i++) {
            if (columns[i].getColumnName().equalsIgnoreCase(keyColumnName)) {
                keyIndex = i;
                keyFlag = true;
                if (valueFlag) {
                    break;
                }
            }
            if (columns[i].getColumnName().equalsIgnoreCase(valueColumnName)) {
                valueIndex = i;
                valueFlag = true;
                if (keyFlag) {
                    break;
                }
 
            }
        }
        return toMap(keyIndex, valueIndex);
    }
 
    /**
     * 以指定的列字段值为key,以另一指定的列值为value,填充到一个Map中,并返回此Map
     */
    public Map toMap(int keyColumnIndex, int valueColumnIndex) {
        if (keyColumnIndex < 0 || keyColumnIndex >= columns.length) {
            throw new RuntimeException("DataRow中没有指定的列:" + keyColumnIndex);
        }
        if (valueColumnIndex < 0 || valueColumnIndex >= columns.length) {
            throw new RuntimeException("DataRow中没有指定的列:" + valueColumnIndex);
        }
        Map map = new HashMap();
        for (int i = 0; i < rows.length; i++) {
            Object key = this.rows[i].values[keyColumnIndex];
            if (key == null) {
                map.put(key, this.rows[i].values[valueColumnIndex]);
            } else {
                map.put(key.toString(), this.rows[i].values[valueColumnIndex]);
            }
        }
        return map;
    }
 
    /**
     * 以指定列的值为key,去map中寻找对应的值,并把值置到新增的列中,新增列的列名=指定列列名+"Name"
     */
    public void decodeColumn(String colName, Map map) {
        for (int i = 0; i < columns.length; i++) {
            if (columns[i].getColumnName().equalsIgnoreCase(colName)) {
                decodeColumn(i, map);
                return;
            }
        }
    }
 
    public void decodeColumn(int colIndex, Map map) {
        String newName = this.columns[colIndex].ColumnName + "Name";
        this.insertColumn(newName);
        for (int i = 0; i < getRowCount(); i++) {
            String v = getString(i, colIndex);
            set(i, newName, map.get(v));
        }
    }
 
    /**
     * 将两个表的内容合并
     */
    public void union(DataTable anotherDT) {
        if (anotherDT.getRowCount() == 0) {
            return;
        }
        if (this.getRowCount() == 0) {
            this.rows = anotherDT.rows;
            return;
        }
        if (this.getColCount() != anotherDT.getColCount()) {
            throw new RuntimeException("两个DataTable的列数不一致,列数1:" + this.getColCount() + " ,列数2:"
                    + anotherDT.getColCount());
        }
        int srcPos = rows.length;
        DataRow[] newRows = new DataRow[rows.length + anotherDT.getRowCount()];
        System.arraycopy(rows, 0, newRows, 0, srcPos);
        System.arraycopy(anotherDT.rows, 0, newRows, srcPos, anotherDT.getRowCount());
        rows = null;
        rows = newRows;
    }
 
    public int getRowCount() {
        return this.rows.length;
    }
 
    public int getColCount() {
        return this.columns.length;
    }
 
    public DataColumn[] getDataColumns() {
        return columns;
    }
 
    public boolean isWebMode() {
        return isWebMode;
    }
 
    public void setWebMode(boolean isWebMode) {
        this.isWebMode = isWebMode;
        for (int i = 0; i < rows.length; i++) {
            this.rows[i].setWebMode(isWebMode);
        }
    }
 
    public String toString() {
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < columns.length; i++) {
            if (i != 0) {
                sb.append("\t");
            }
            sb.append(this.columns[i].getColumnName());
        }
        sb.append("\n");
        for (int i = 0; i < rows.length; i++) {
            if (i != 0) {
                sb.append("\n");
            }
            for (int j = 0; j < columns.length; j++) {
                if (j != 0) {
                    sb.append("\t");
                }
                sb.append(this.get(i, j));
            }
        }
        return sb.toString();
    }
 
    public JSONArray toJSONArray() {
        JSONArray jsonArray = new JSONArray();
        int rows = this.getRowCount();
        for (int i = 0; i < rows; i++) {
            DataRow row = getDataRow(i);
            JSONObject json = new JSONObject();
            int cols = row.getColumnCount();
            for (int k = 0; k < cols; k++) {
                Object value = row.get(k);
                if (value instanceof Date) {
                    value = DateUtil.formatDateTime((Date) value);
                } else if (value instanceof byte[]) {// blob
                    value = new String((byte[]) value);
                }
                value = value == null ? "" : value;
                json.put(DBUtil.columnNameParser(columns[k].getColumnName()), value);
            }
            json.put("isTableColumn",true);
            json.put("isSelectColumn",false);
//            json.put("op","EQ");
            jsonArray.add(json);
        }
        return jsonArray;
    }
}