17 |
ilm |
1 |
/*
|
|
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
|
|
3 |
*
|
182 |
ilm |
4 |
* Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
|
17 |
ilm |
5 |
*
|
|
|
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
|
|
|
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.
|
|
|
10 |
*
|
|
|
11 |
* When distributing the software, include this License Header Notice in each file.
|
|
|
12 |
*/
|
|
|
13 |
|
|
|
14 |
package org.openconcerto.sql.view.list;
|
|
|
15 |
|
93 |
ilm |
16 |
import org.openconcerto.sql.Log;
|
17 |
ilm |
17 |
import org.openconcerto.sql.model.SQLRowAccessor;
|
|
|
18 |
import org.openconcerto.sql.model.SQLRowValues;
|
|
|
19 |
import org.openconcerto.sql.model.graph.Path;
|
93 |
ilm |
20 |
import org.openconcerto.utils.SleepingQueue.LethalFutureTask;
|
|
|
21 |
import org.openconcerto.utils.SleepingQueue.RunningState;
|
|
|
22 |
import org.openconcerto.utils.Value;
|
17 |
ilm |
23 |
|
|
|
24 |
import java.sql.SQLException;
|
|
|
25 |
import java.util.ArrayList;
|
182 |
ilm |
26 |
import java.util.Collection;
|
17 |
ilm |
27 |
import java.util.List;
|
93 |
ilm |
28 |
import java.util.concurrent.Future;
|
|
|
29 |
import java.util.concurrent.TimeUnit;
|
17 |
ilm |
30 |
|
93 |
ilm |
31 |
import javax.swing.SwingUtilities;
|
|
|
32 |
|
17 |
ilm |
33 |
/**
|
|
|
34 |
* Lines are taken directly from the database.
|
|
|
35 |
*
|
|
|
36 |
* @author Sylvain
|
|
|
37 |
*/
|
|
|
38 |
public class SQLTableModelLinesSourceOnline extends SQLTableModelLinesSource {
|
|
|
39 |
|
|
|
40 |
private final SQLTableModelSourceOnline parent;
|
93 |
ilm |
41 |
private MoveQueue moveQ;
|
17 |
ilm |
42 |
|
|
|
43 |
public SQLTableModelLinesSourceOnline(SQLTableModelSourceOnline parent, final ITableModel model) {
|
|
|
44 |
super(model);
|
|
|
45 |
this.parent = parent;
|
93 |
ilm |
46 |
this.moveQ = null;
|
17 |
ilm |
47 |
}
|
|
|
48 |
|
93 |
ilm |
49 |
MoveQueue getMoveQ() {
|
|
|
50 |
assert SwingUtilities.isEventDispatchThread();
|
|
|
51 |
if (this.moveQ == null) {
|
|
|
52 |
this.moveQ = new MoveQueue(getModel());
|
156 |
ilm |
53 |
getModel().startQueue(this.moveQ);
|
93 |
ilm |
54 |
}
|
|
|
55 |
return this.moveQ;
|
|
|
56 |
}
|
|
|
57 |
|
17 |
ilm |
58 |
@Override
|
|
|
59 |
protected void die() {
|
93 |
ilm |
60 |
if (this.moveQ != null) {
|
|
|
61 |
final RunningState threadState = this.moveQ.getRunningState();
|
|
|
62 |
if (threadState == RunningState.RUNNING) {
|
|
|
63 |
final LethalFutureTask<?> dieMove = this.moveQ.die();
|
|
|
64 |
getModel().wait(dieMove, 15, TimeUnit.MILLISECONDS);
|
|
|
65 |
} else {
|
|
|
66 |
Log.get().warning("Not dying since queue is " + threadState);
|
|
|
67 |
}
|
|
|
68 |
}
|
|
|
69 |
|
17 |
ilm |
70 |
super.die();
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
@Override
|
|
|
74 |
public final SQLTableModelSourceOnline getParent() {
|
|
|
75 |
return this.parent;
|
|
|
76 |
}
|
|
|
77 |
|
93 |
ilm |
78 |
@Override
|
182 |
ilm |
79 |
public List<ListSQLLine> get(Collection<? extends Number> ids) {
|
|
|
80 |
final List<SQLRowValues> values = this.getUpdateQueueReq().getValuesFromIDs(ids);
|
17 |
ilm |
81 |
final List<ListSQLLine> res = new ArrayList<ListSQLLine>(values.size());
|
|
|
82 |
for (final SQLRowValues v : values) {
|
|
|
83 |
final ListSQLLine newLine = createLine(v);
|
|
|
84 |
if (newLine != null)
|
|
|
85 |
res.add(newLine);
|
|
|
86 |
}
|
|
|
87 |
return res;
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
@Override
|
93 |
ilm |
91 |
public Value<ListSQLLine> get(final int id) {
|
|
|
92 |
return Value.getSome(createLine(this.getUpdateQueueReq().getValues(id)));
|
17 |
ilm |
93 |
}
|
|
|
94 |
|
|
|
95 |
@Override
|
93 |
ilm |
96 |
public Future<?> moveBy(List<? extends SQLRowAccessor> rows, int inc) {
|
|
|
97 |
return this.getMoveQ().move(rows, inc);
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
@Override
|
|
|
101 |
public Future<?> moveTo(List<? extends Number> rows, int rowIndex) {
|
|
|
102 |
return this.getMoveQ().moveTo(rows, rowIndex);
|
|
|
103 |
}
|
|
|
104 |
|
|
|
105 |
@Override
|
17 |
ilm |
106 |
public void commit(ListSQLLine l, Path path, SQLRowValues vals) throws SQLException {
|
|
|
107 |
vals.update();
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
}
|