OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 156 Rev 182
Line 1... Line 1...
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
3
 * 
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
4
 * Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
5
 * 
5
 * 
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
9
 * language governing permissions and limitations under the License.
Line 12... Line 12...
12
 */
12
 */
13
 
13
 
14
 package org.openconcerto.sql.view.list;
14
 package org.openconcerto.sql.view.list;
15
 
15
 
16
import org.openconcerto.sql.model.FieldPath;
16
import org.openconcerto.sql.model.FieldPath;
-
 
17
import org.openconcerto.sql.model.RowRef;
17
import org.openconcerto.sql.model.SQLField;
18
import org.openconcerto.sql.model.SQLField;
-
 
19
import org.openconcerto.sql.model.SQLRowAccessor;
18
import org.openconcerto.sql.model.SQLRowValues;
20
import org.openconcerto.sql.model.SQLRowValues;
19
import org.openconcerto.sql.model.SQLRowValues.CreateMode;
21
import org.openconcerto.sql.model.SQLRowValues.CreateMode;
20
import org.openconcerto.sql.model.SQLTable;
22
import org.openconcerto.sql.model.SQLTable;
21
import org.openconcerto.sql.model.SQLTable.VirtualFields;
23
import org.openconcerto.sql.model.SQLTable.VirtualFields;
22
import org.openconcerto.sql.model.graph.Path;
24
import org.openconcerto.sql.model.graph.Path;
-
 
25
import org.openconcerto.sql.request.BaseFillSQLRequest.OrderValue;
-
 
26
import org.openconcerto.sql.request.ComboSQLRequest.KeepMode;
23
import org.openconcerto.sql.view.list.search.SearchQueue;
27
import org.openconcerto.sql.view.list.search.SearchQueue;
24
import org.openconcerto.utils.CollectionUtils;
28
import org.openconcerto.utils.CollectionUtils;
25
import org.openconcerto.utils.NumberUtils;
29
import org.openconcerto.utils.NumberUtils;
26
 
30
 
27
import java.util.ArrayList;
31
import java.util.ArrayList;
Line 66... Line 70...
66
    }
70
    }
67
 
71
 
68
    private final SQLTableModelLinesSource src;
72
    private final SQLTableModelLinesSource src;
69
    // unmodifiable
73
    // unmodifiable
70
    @GuardedBy("this")
74
    @GuardedBy("this")
71
    private SQLRowValues row;
75
    private SQLRowAccessor row;
-
 
76
    // If the whole graph of this.row isn't kept then we need to store the primary keys so that when
-
 
77
    // a SQLTableEvent is fired, we can know which lines is affected.
-
 
78
    private final Set<RowRef> pks;
72
    // Immutable
79
    // Immutable
73
    private final SQLTableModelSourceState state;
80
    private final SQLTableModelSourceState state;
74
    private final int id;
81
    private final int id;
75
    // allow to order by something not in the row
82
    // allow to order by something not in the row
76
    @GuardedBy("this")
83
    @GuardedBy("this")
77
    private Number order;
84
    private Number order;
-
 
85
    // If the whole graph of this.row isn't kept then we need to store rows needed to order the
-
 
86
    // lines. Otherwise don't allocate more memory just use this.rows.
-
 
87
    private final OrderValue reqOrderVal;
78
    // lists are accessed by Swing (model.getValueAt()) and
88
    // lists are accessed by Swing (model.getValueAt()) and
79
    // by the search queue (SearchRunnable#matchFilter(ListSQLLine line))
89
    // by the search queue (SearchRunnable#matchFilter(ListSQLLine line))
80
    // immutable
90
    // immutable
81
    @GuardedBy("this")
91
    @GuardedBy("this")
82
    private List<Object> list;
92
    private List<Object> list;
Line 85... Line 95...
85
        super();
95
        super();
86
        this.src = src;
96
        this.src = src;
87
        this.setRow(row);
97
        this.setRow(row);
88
        this.id = id;
98
        this.id = id;
89
        this.state = state;
99
        this.state = state;
-
 
100
        final boolean isGraph = src.getParent().getKeepMode() == KeepMode.GRAPH;
-
 
101
        this.reqOrderVal = isGraph ? null : state.getReq().createOrderValue(row);
-
 
102
        if (isGraph) {
90
        this.clearCache();
103
            this.clearCache();
-
 
104
            this.pks = null;
-
 
105
        } else {
-
 
106
            // compute all cells,
-
 
107
            this.list = Collections.emptyList();
-
 
108
            this.loadCache(state.getAllColumns().getAllColumns().size());
-
 
109
            // then free memory by keeping a single SQLRow and only RowIDRef
-
 
110
            this.setRow(row.asRow());
-
 
111
            final Set<RowRef> tmpRefs = new HashSet<>(row.getGraphSize(), 1.0f);
-
 
112
            for (final SQLRowValues v : row.getGraph().getItems()) {
-
 
113
                tmpRefs.add(v.getRowRef());
-
 
114
            }
-
 
115
            this.pks = Collections.unmodifiableSet(tmpRefs);
-
 
116
        }
91
    }
117
    }
92
 
118
 
93
    // load at least columnCount values
119
    // load at least columnCount values
94
    // (to avoid loading debug columns, which took more time than the regular columns, ie more than
120
    // (to avoid loading debug columns, which took more time than the regular columns, ie more than
95
    // half the time was passed on almost never displayed values)
121
    // half the time was passed on almost never displayed values)
Line 107... Line 133...
107
 
133
 
108
    public final SQLTableModelLinesSource getSrc() {
134
    public final SQLTableModelLinesSource getSrc() {
109
        return this.src;
135
        return this.src;
110
    }
136
    }
111
 
137
 
112
    private final void setRow(SQLRowValues v) {
138
    private final void setRow(SQLRowAccessor v) {
113
        if (!v.isFrozen())
139
        if (!v.isFrozen())
114
            throw new IllegalArgumentException("Not frozen : " + v);
140
            throw new IllegalArgumentException("Not frozen : " + v);
115
        synchronized (this) {
141
        synchronized (this) {
116
            this.row = v;
142
            this.row = v;
117
        }
143
        }
118
    }
144
    }
119
 
145
 
-
 
146
    public final SQLRowValues getRow() {
-
 
147
        return (SQLRowValues) this.getRowAccessor();
-
 
148
    }
-
 
149
 
120
    public synchronized final SQLRowValues getRow() {
150
    public synchronized final SQLRowAccessor getRowAccessor() {
121
        return this.row;
151
        return this.row;
122
    }
152
    }
123
 
153
 
-
 
154
    public final Set<RowRef> getPKs() {
-
 
155
        return this.pks;
-
 
156
    }
-
 
157
 
124
    @Override
158
    @Override
125
    public int compareTo(ListSQLLine o) {
159
    public int compareTo(ListSQLLine o) {
126
        if (this.src != o.src)
160
        if (this.src != o.src)
127
            throw new IllegalArgumentException(this.src + " != " + o.src);
161
            throw new IllegalArgumentException(this.src + " != " + o.src);
128
        return this.src.compare(this, o);
162
        return this.src.compare(this, o);
Line 146... Line 180...
146
                throw new IllegalStateException("Order mismatch :\n" + order1 + " for " + l1 + " not coherent with\n" + order2 + " for " + l2);
180
                throw new IllegalStateException("Order mismatch :\n" + order1 + " for " + l1 + " not coherent with\n" + order2 + " for " + l2);
147
            return NumberUtils.compare(order1, order2);
181
            return NumberUtils.compare(order1, order2);
148
        } else {
182
        } else {
149
            if (order2 != null)
183
            if (order2 != null)
150
                throw new IllegalStateException("Order mismatch :\n" + order1 + " for " + l1 + " not coherent with\n" + order2 + " for " + l2);
184
                throw new IllegalStateException("Order mismatch :\n" + order1 + " for " + l1 + " not coherent with\n" + order2 + " for " + l2);
-
 
185
 
-
 
186
            final OrderValue orderVal1 = l1.getRequestOrderValue();
-
 
187
            if (orderVal1 != null) {
-
 
188
                final OrderValue orderVal2 = l2.getRequestOrderValue();
-
 
189
                return orderVal1.compareTo(orderVal2);
-
 
190
            } else {
-
 
191
                // assert because we already checked same state above
-
 
192
                assert l2.getRequestOrderValue() == null;
151
            return l1.getState().getReq().order(l1.getRow(), l2.getRow());
193
                return l1.getState().getReq().order(l1.getRow(), l2.getRow());
152
        }
194
            }
153
    }
195
        }
-
 
196
    }
154
 
197
 
155
    public int getID() {
198
    public int getID() {
156
        return this.id;
199
        return this.id;
157
    }
200
    }
158
 
201
 
Line 162... Line 205...
162
 
205
 
163
    public synchronized final Number getOrder() {
206
    public synchronized final Number getOrder() {
164
        return this.order;
207
        return this.order;
165
    }
208
    }
166
 
209
 
-
 
210
    public final OrderValue getRequestOrderValue() {
-
 
211
        return this.reqOrderVal;
-
 
212
    }
-
 
213
 
167
    public synchronized List<Object> getList(int columnCount) {
214
    public synchronized List<Object> getList(int columnCount) {
168
        this.loadCache(columnCount);
215
        this.loadCache(columnCount);
169
        return this.list;
216
        return this.list;
170
    }
217
    }
171
 
218
 
Line 218... Line 265...
218
        }
265
        }
219
        return true;
266
        return true;
220
    }
267
    }
221
 
268
 
222
    public void clearCache() {
269
    public void clearCache() {
-
 
270
        if (this.getSrc().getParent().getKeepMode() != KeepMode.GRAPH)
-
 
271
            throw new IllegalStateException("Wouldn't be able to compute cell values");
223
        synchronized (this) {
272
        synchronized (this) {
224
            this.list = Collections.emptyList();
273
            this.list = Collections.emptyList();
225
        }
274
        }
226
    }
275
    }
227
 
276
 
Line 327... Line 376...
327
        return false;
376
        return false;
328
    }
377
    }
329
 
378
 
330
    @Override
379
    @Override
331
    public String toString() {
380
    public String toString() {
332
        return this.getClass().getSimpleName() + " on " + this.getRow();
381
        return this.getClass().getSimpleName() + " on " + this.getRowAccessor();
333
    }
382
    }
334
}
383
}