OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev Author Line No. Line
102 ilm 1
package org.openconcerto.modules.common.batchprocessing;
2
 
3
import java.awt.FlowLayout;
4
import java.sql.SQLException;
5
import java.util.Date;
6
import java.util.List;
7
 
8
import javax.swing.JLabel;
9
import javax.swing.JPanel;
10
 
11
import org.openconcerto.sql.model.SQLField;
12
import org.openconcerto.sql.model.SQLRowAccessor;
13
import org.openconcerto.sql.model.SQLRowValues;
14
import org.openconcerto.ui.JDate;
15
 
16
public class DateProcessor extends JPanel implements BatchProcessor {
17
    private final JDate d = new JDate(true);
18
    private final SQLField field;
19
 
181 ilm 20
    public DateProcessor(BatchField field) {
21
        this.field = field.getField();
102 ilm 22
        this.setLayout(new FlowLayout());
23
        this.add(new JLabel("forcer la date au "));
24
        this.add(d);
25
 
26
    }
27
 
28
    @Override
29
    public void process(List<SQLRowValues> r) throws SQLException {
30
        final Date date = d.getDate();
31
        for (SQLRowAccessor sqlRowAccessor : r) {
32
            final SQLRowValues rowValues = sqlRowAccessor.createEmptyUpdateRow();
33
            rowValues.put(field.getName(), date);
34
            processBeforeUpdate(sqlRowAccessor, rowValues);
35
            rowValues.update();
36
        }
37
 
38
    }
39
 
40
    @Override
41
    public boolean checkParameters() {
42
        final Date date = d.getDate();
43
        if (date == null && !field.isNullable()) {
44
            return false;
45
        }
46
        return true;
47
    }
48
 
49
    @Override
50
    public void processBeforeUpdate(SQLRowAccessor from, SQLRowValues to) {
51
    }
52
}