OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 25 Rev 94
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.erp.utils;
14
 package org.openconcerto.erp.utils;
15
 
15
 
-
 
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
16
import org.openconcerto.map.model.DatabaseAccessor;
17
import org.openconcerto.map.model.DatabaseAccessor;
17
import org.openconcerto.map.model.Ville;
18
import org.openconcerto.map.model.Ville;
18
import org.openconcerto.sql.Configuration;
19
import org.openconcerto.sql.Configuration;
19
import org.openconcerto.sql.model.SQLRow;
20
import org.openconcerto.sql.model.SQLRow;
20
import org.openconcerto.sql.model.SQLRowListRSH;
21
import org.openconcerto.sql.model.SQLRowListRSH;
Line 27... Line 28...
27
import java.util.ArrayList;
28
import java.util.ArrayList;
28
import java.util.List;
29
import java.util.List;
29
 
30
 
30
// TODO use the one from Nego
31
// TODO use the one from Nego
31
public class NXDatabaseAccessor implements DatabaseAccessor {
32
public class NXDatabaseAccessor implements DatabaseAccessor {
-
 
33
 
-
 
34
    private final SQLTable tableVille;
-
 
35
 
-
 
36
    public NXDatabaseAccessor(ComptaPropsConfiguration comptaConf) {
-
 
37
        super();
-
 
38
        if (comptaConf.getRootSociete().contains("VILLE")) {
-
 
39
            this.tableVille = ComptaPropsConfiguration.getInstanceCompta().getRootSociete().getTable("VILLE");
-
 
40
        } else {
-
 
41
            this.tableVille = comptaConf.getBase().getTable("VILLE");
-
 
42
        }
-
 
43
    }
-
 
44
 
32
    @SuppressWarnings("unchecked")
45
    @SuppressWarnings("unchecked")
33
    public List<Ville> read() {
46
    public List<Ville> read() {
34
        SQLTable ville = Configuration.getInstance().getBase().getTable("VILLE");
-
 
35
        SQLSelect sel = new SQLSelect(Configuration.getInstance().getBase());
47
        SQLSelect sel = new SQLSelect();
36
        sel.addSelectStar(ville);
48
        sel.addSelectStar(this.tableVille);
37
        List<SQLRow> l = (List<SQLRow>) Configuration.getInstance().getBase().getDataSource().execute(sel.asString(), SQLRowListRSH.createFromSelect(sel));
49
        List<SQLRow> l = (List<SQLRow>) Configuration.getInstance().getBase().getDataSource().execute(sel.asString(), SQLRowListRSH.createFromSelect(sel));
38
 
50
 
39
        List<Ville> lResult = new ArrayList<Ville>();
51
        List<Ville> lResult = new ArrayList<Ville>();
40
        for (SQLRow row : l) {
52
        for (SQLRow row : l) {
41
            final String nom = row.getString("NOM");
53
            final String nom = row.getString("NOM");
Line 49... Line 61...
49
 
61
 
50
        return lResult;
62
        return lResult;
51
    }
63
    }
52
 
64
 
53
    public void store(Ville v) {
65
    public void store(Ville v) {
54
        SQLTable ville = Configuration.getInstance().getBase().getTable("VILLE");
-
 
55
        SQLRowValues rowVals = new SQLRowValues(ville);
66
        SQLRowValues rowVals = new SQLRowValues(this.tableVille);
56
        rowVals.put("NOM", v.getName());
67
        rowVals.put("NOM", v.getName());
57
        rowVals.put("CODE_POSTAL", v.getCodepostal());
68
        rowVals.put("CODE_POSTAL", v.getCodepostal());
58
        rowVals.put("X_LAMBERT", v.getXLambert());
69
        rowVals.put("X_LAMBERT", v.getXLambert());
59
        rowVals.put("Y_LAMBERT", v.getYLambert());
70
        rowVals.put("Y_LAMBERT", v.getYLambert());
60
        rowVals.put("POPULATION", v.getPopulation());
71
        rowVals.put("POPULATION", v.getPopulation());
61
        try {
72
        try {
62
            rowVals.insert();
73
            rowVals.insert();
63
        } catch (SQLException e) {
74
        } catch (SQLException e) {
64
            // TODO Auto-generated catch block
-
 
65
            e.printStackTrace();
75
            e.printStackTrace();
66
        }
76
        }
67
    }
77
    }
68
 
78
 
69
    @Override
79
    @Override
70
    public void delete(Ville v) {
80
    public void delete(Ville v) {
71
        SQLTable villeT = Configuration.getInstance().getBase().getTable("VILLE");
-
 
72
        final Where w = new Where(villeT.getField("NOM"), "=", v.getName()).and(new Where(villeT.getField("CODE_POSTAL"), "=", v.getCodepostal()));
81
        final Where w = new Where(this.tableVille.getField("NOM"), "=", v.getName()).and(new Where(this.tableVille.getField("CODE_POSTAL"), "=", v.getCodepostal()));
73
        villeT.getDBSystemRoot().getDataSource().execute("DELETE FROM " + villeT.getSQLName().quote() + " WHERE " + w);
82
        this.tableVille.getDBSystemRoot().getDataSource().execute("DELETE FROM " + this.tableVille.getSQLName().quote() + " WHERE " + w);
74
    }
83
    }
-
 
84
 
75
}
85
}