OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 151 | Details | Compare with Previous | Last modification | View Log | RSS feed

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