OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 144 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 144 Rev 180
Line 11... Line 11...
11
 * When distributing the software, include this License Header Notice in each file.
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
12
 */
13
 
13
 
14
 package org.openconcerto.sql.model;
14
 package org.openconcerto.sql.model;
15
 
15
 
-
 
16
import org.openconcerto.utils.cc.CachedTransformer;
-
 
17
 
16
import java.io.InputStream;
18
import java.io.InputStream;
17
import java.io.Reader;
19
import java.io.Reader;
18
import java.math.BigDecimal;
20
import java.math.BigDecimal;
19
import java.net.URL;
21
import java.net.URL;
20
import java.sql.Array;
22
import java.sql.Array;
Line 34... Line 36...
34
import java.sql.Timestamp;
36
import java.sql.Timestamp;
35
import java.util.Calendar;
37
import java.util.Calendar;
36
import java.util.HashMap;
38
import java.util.HashMap;
37
import java.util.Map;
39
import java.util.Map;
38
 
40
 
39
import org.apache.commons.collections.Transformer;
-
 
40
import org.apache.commons.collections.map.LazyMap;
-
 
41
 
-
 
42
/**
41
/**
43
 * A resultSet that wraps onto another one, caching name to index translation, and using a
42
 * A resultSet that wraps onto another one, caching name to index translation, and using a
44
 * ResultSetFullnameHelper.
43
 * ResultSetFullnameHelper.
45
 * 
44
 * 
46
 * @author Sylvain
45
 * @author Sylvain
Line 118... Line 117...
118
        }
117
        }
119
    }
118
    }
120
 
119
 
121
    private final ResultSet delegate;
120
    private final ResultSet delegate;
122
    private final ResultSetFullnameHelper helper;
121
    private final ResultSetFullnameHelper helper;
123
    private final Map indexes;
122
    private final CachedTransformer<String, Integer, SQLException> indexes;
124
    private int rowProcessedCount;
123
    private int rowProcessedCount;
125
 
124
 
126
    public SQLResultSet(ResultSet delegate) {
125
    public SQLResultSet(ResultSet delegate) {
127
        this.delegate = delegate;
126
        this.delegate = delegate;
128
        this.helper = new ResultSetFullnameHelper(this);
127
        this.helper = new ResultSetFullnameHelper(this);
129
        this.indexes = LazyMap.decorate(new HashMap(), new Transformer() {
128
        this.indexes = new CachedTransformer<>(new HashMap<>(), this::doFindColumn);
130
            public Object transform(Object input) {
-
 
131
                final String colName = (String) input;
-
 
132
                try {
-
 
133
                    return new Integer(doFindColumn(colName));
-
 
134
                } catch (SQLException e) {
-
 
135
                    return e;
-
 
136
                }
-
 
137
            }
-
 
138
        });
-
 
139
    }
129
    }
140
 
130
 
141
    private ResultSet getDelegate() {
131
    private ResultSet getDelegate() {
142
        return this.delegate;
132
        return this.delegate;
143
    }
133
    }
Line 169... Line 159...
169
    public void deleteRow() throws SQLException {
159
    public void deleteRow() throws SQLException {
170
        getDelegate().deleteRow();
160
        getDelegate().deleteRow();
171
    }
161
    }
172
 
162
 
173
    public int findColumn(String columnName) throws SQLException {
163
    public int findColumn(String columnName) throws SQLException {
174
        final Object res = this.indexes.get(columnName);
164
        final int index = this.indexes.get(columnName).intValue();
175
        if (res instanceof SQLException)
-
 
176
            throw (SQLException) res;
-
 
177
        else {
-
 
178
            final int index = ((Number) res).intValue();
-
 
179
            if (index < 1)
165
        if (index < 1)
180
                throw new SQLException(columnName + " not found");
166
            throw new SQLException(columnName + " not found");
181
            else
167
        else
182
                return index;
168
            return index;
183
        }
169
    }
184
    }
-
 
185
 
170
 
186
    private int doFindColumn(String columnName) throws SQLException {
171
    private int doFindColumn(String columnName) throws SQLException {
187
        try {
172
        try {
188
            return getDelegate().findColumn(columnName);
173
            return getDelegate().findColumn(columnName);
189
        } catch (SQLException e) {
174
        } catch (SQLException e) {