OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 17 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 17 Rev 142
Line 12... Line 12...
12
 */
12
 */
13
 
13
 
14
 /*
14
 /*
15
 * Copyright 2004 The Apache Software Foundation
15
 * Copyright 2004 The Apache Software Foundation
16
 *
16
 *
17
 * Licensed under the Apache License, Version 2.0 (the "License");
17
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
18
 * you may not use this file except in compliance with the License.
-
 
19
 * You may obtain a copy of the License at
18
 * in compliance with the License. You may obtain a copy of the License at
20
 *
19
 *
21
 *     http://www.apache.org/licenses/LICENSE-2.0
20
 * http://www.apache.org/licenses/LICENSE-2.0
22
 *
21
 *
23
 * Unless required by applicable law or agreed to in writing, software
22
 * Unless required by applicable law or agreed to in writing, software distributed under the License
24
 * distributed under the License is distributed on an "AS IS" BASIS,
-
 
25
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
26
 * See the License for the specific language governing permissions and
24
 * or implied. See the License for the specific language governing permissions and limitations under
27
 * limitations under the License.
25
 * the License.
28
 */
26
 */
29
 
27
 
30
package org.openconcerto.sql.model;
28
package org.openconcerto.sql.model;
31
 
29
 
32
import java.sql.ResultSet;
-
 
33
import java.sql.SQLException;
-
 
34
import java.util.ArrayList;
-
 
35
import java.util.List;
-
 
36
 
-
 
37
import org.apache.commons.dbutils.ResultSetHandler;
30
import org.apache.commons.dbutils.ResultSetHandler;
38
 
31
 
39
/**
32
/**
40
 * <code>ResultSetHandler</code> implementation that converts one
33
 * <code>ResultSetHandler</code> implementation that converts one <code>ResultSet</code> column into
41
 * <code>ResultSet</code> column into a <code>List</code> of
-
 
42
 * <code>Object</code>s. This class is thread safe.
34
 * a <code>List</code> of <code>Object</code>s. This class is thread safe.
43
 * 
35
 * 
44
 * @see ResultSetHandler
36
 * @see ResultSetHandler
45
 * @since DbUtils 1.1
37
 * @since DbUtils 1.1
46
 */
38
 */
47
public class ColumnListHandler implements ResultSetHandler {
39
public class ColumnListHandler extends ColumnListHandlerGeneric<Object> {
48
 
-
 
49
    /**
-
 
50
     * The column number to retrieve.
-
 
51
     */
-
 
52
    private int columnIndex = 1;
-
 
53
 
40
 
54
    /**
41
    /**
55
     * The column name to retrieve.  Either columnName or columnIndex
-
 
56
     * will be used but never both.
-
 
57
     */
-
 
58
    private String columnName = null;
-
 
59
 
-
 
60
    /** 
-
 
61
     * Creates a new instance of ColumnListHandler.  The first column of each
42
     * Creates a new instance of ColumnListHandler. The first column of each row will be returned
62
     * row will be returned from <code>handle()</code>.
43
     * from <code>handle()</code>.
63
     */
44
     */
64
    public ColumnListHandler() {
45
    public ColumnListHandler() {
65
        super();
46
        this(1);
66
    }
47
    }
67
 
48
 
68
    /** 
49
    /**
69
     * Creates a new instance of ColumnListHandler.
50
     * Creates a new instance of ColumnListHandler.
70
     * 
51
     * 
71
     * @param columnIndex The index of the column to retrieve from the 
52
     * @param columnIndex The index of the column to retrieve from the <code>ResultSet</code>.
72
     * <code>ResultSet</code>.
-
 
73
     */
53
     */
74
    public ColumnListHandler(int columnIndex) {
54
    public ColumnListHandler(int columnIndex) {
75
        this.columnIndex = columnIndex;
55
        this(columnIndex, null);
76
    }
56
    }
77
 
57
 
78
    /** 
58
    /**
79
     * Creates a new instance of ColumnListHandler.
59
     * Creates a new instance of ColumnListHandler.
80
     * 
60
     * 
81
     * @param columnName The name of the column to retrieve from the 
61
     * @param columnName The name of the column to retrieve from the <code>ResultSet</code>.
82
     * <code>ResultSet</code>.
-
 
83
     */
62
     */
84
    public ColumnListHandler(String columnName) {
63
    public ColumnListHandler(String columnName) {
85
        this.columnName = columnName;
64
        this(-1, columnName);
86
    }
65
    }
87
 
66
 
88
    /**
-
 
89
     * Returns one <code>ResultSet</code> column as a <code>List</code> of
-
 
90
     * <code>Object</code>s. The elements are added to the <code>List</code> via
-
 
91
     * the <code>ResultSet.getObject()</code> method.
-
 
92
     * 
-
 
93
     * @return A <code>List</code> of <code>Object</code>s, never
-
 
94
     * <code>null</code>. 
-
 
95
     * 
-
 
96
     * @throws SQLException
-
 
97
     * 
-
 
98
     * @see org.apache.commons.dbutils.ResultSetHandler#handle(java.sql.ResultSet)
-
 
99
     */
-
 
100
    public Object handle(ResultSet rs) throws SQLException {
67
    private ColumnListHandler(int columnIndex, String columnName) {
101
 
-
 
102
        List result = new ArrayList();
-
 
103
 
-
 
104
        while (rs.next()) {
-
 
105
            if (this.columnName == null) {
68
        super(columnIndex, columnName, Object.class);
106
                result.add(rs.getObject(this.columnIndex));
-
 
107
            } else {
-
 
108
                result.add(rs.getObject(this.columnName));
-
 
109
            }
-
 
110
        }
-
 
111
        return result;
-
 
112
    }
69
    }
113
}
70
}