OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 156 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 156 Rev 177
Line 18... Line 18...
18
import org.openconcerto.sql.element.ConfSQLElement;
18
import org.openconcerto.sql.element.ConfSQLElement;
19
import org.openconcerto.sql.element.SQLElementDirectory;
19
import org.openconcerto.sql.element.SQLElementDirectory;
20
import org.openconcerto.sql.model.DBRoot;
20
import org.openconcerto.sql.model.DBRoot;
21
import org.openconcerto.sql.model.DBSystemRoot;
21
import org.openconcerto.sql.model.DBSystemRoot;
22
import org.openconcerto.sql.model.SQLBase;
22
import org.openconcerto.sql.model.SQLBase;
-
 
23
import org.openconcerto.sql.model.SQLDataSource;
23
import org.openconcerto.sql.model.SQLField;
24
import org.openconcerto.sql.model.SQLField;
24
import org.openconcerto.sql.model.SQLFilter;
25
import org.openconcerto.sql.model.SQLFilter;
25
import org.openconcerto.sql.model.SQLRow;
26
import org.openconcerto.sql.model.SQLRow;
26
import org.openconcerto.sql.model.SQLTable;
27
import org.openconcerto.sql.model.SQLTable;
-
 
28
import org.openconcerto.sql.model.SQLTableEvent;
-
 
29
import org.openconcerto.sql.model.SQLTableModifiedListener;
27
import org.openconcerto.sql.users.UserCommonSQLElement;
30
import org.openconcerto.sql.users.UserCommonSQLElement;
28
import org.openconcerto.sql.users.rights.RightSQLElement;
31
import org.openconcerto.sql.users.rights.RightSQLElement;
29
import org.openconcerto.sql.users.rights.UserRightSQLElement;
32
import org.openconcerto.sql.users.rights.UserRightSQLElement;
30
import org.openconcerto.task.TM;
33
import org.openconcerto.task.TM;
31
import org.openconcerto.task.element.CompanyAccessSQLElement;
34
import org.openconcerto.task.element.CompanyAccessSQLElement;
Line 47... Line 50...
47
import java.util.Arrays;
50
import java.util.Arrays;
48
import java.util.Collections;
51
import java.util.Collections;
49
import java.util.List;
52
import java.util.List;
50
import java.util.Properties;
53
import java.util.Properties;
51
 
54
 
-
 
55
import net.jcip.annotations.GuardedBy;
-
 
56
 
52
public abstract class ComptaBasePropsConfiguration extends PropsConfiguration {
57
public abstract class ComptaBasePropsConfiguration extends PropsConfiguration {
53
 
58
 
54
    public abstract void setUpSocieteDataBaseConnexion(int base);
59
    public abstract void setUpSocieteDataBaseConnexion(int base);
55
 
60
 
56
    public static File getConfFile(final ProductInfo info) {
61
    public static File getConfFile(final ProductInfo info) {
Line 98... Line 103...
98
                return res;
103
                return res;
99
        }
104
        }
100
        throw new FileNotFoundException(name + " not found in " + Arrays.asList(dirs));
105
        throw new FileNotFoundException(name + " not found in " + Arrays.asList(dirs));
101
    }
106
    }
102
 
107
 
103
    private int idSociete = SQLRow.NONEXISTANT_ID;
108
    @GuardedBy("this")
104
    private SQLRow rowSociete = null;
109
    private SQLRow rowSociete = null;
-
 
110
    private final SQLTableModifiedListener rowSocieteListener = (evt) -> updateRowSociete(evt);
-
 
111
    @GuardedBy("this")
105
    private DBRoot baseSociete;
112
    private DBRoot baseSociete;
106
 
113
 
107
    {
114
    {
108
        // * logs
115
        // * logs
109
        LogUtils.rmRootHandlers();
116
        LogUtils.rmRootHandlers();
Line 113... Line 120...
113
 
120
 
114
    public ComptaBasePropsConfiguration(Properties props, final ProductInfo productInfo) {
121
    public ComptaBasePropsConfiguration(Properties props, final ProductInfo productInfo) {
115
        super(props);
122
        super(props);
116
 
123
 
117
        this.setProductInfo(productInfo);
124
        this.setProductInfo(productInfo);
118
        String name = "ilm";
-
 
119
        // don't overwrite (allow to map no roots, just to test connection)
125
        // don't overwrite (allow to map no roots, just to test connection)
120
        if (getProperty("systemRoot.rootsToMap") == null) {
126
        if (getProperty("systemRoot.rootsToMap") == null) {
-
 
127
            final String interAppRootName = getInterAppRootName();
121
            this.setProperty("systemRoot.rootsToMap", name + "_Common");
128
            this.setProperty("systemRoot.rootsToMap", interAppRootName);
122
            this.setProperty("systemRoot.rootPath", name + "_Common");
129
            this.setProperty("systemRoot.rootPath", interAppRootName);
-
 
130
        }
-
 
131
    }
-
 
132
 
-
 
133
    @Override
-
 
134
    public void destroy() {
-
 
135
        this.setRowSociete(null);
-
 
136
        super.destroy();
123
        }
137
    }
-
 
138
 
-
 
139
    public final String getInterAppRootName() {
-
 
140
        String name = "ilm";
-
 
141
        return name + "_Common";
124
    }
142
    }
125
 
143
 
126
 
144
 
127
    // use Configuration directory if it exists
145
    // use Configuration directory if it exists
128
    @Override
146
    @Override
129
    protected FileMode getFileMode() {
147
    protected FileMode getFileMode() {
130
        return FileMode.NORMAL_FILE;
148
        return FileMode.NORMAL_FILE;
131
    }
149
    }
132
 
150
 
133
    @Override
151
    @Override
-
 
152
    protected void initDS(SQLDataSource ds) {
-
 
153
        super.initDS(ds);
-
 
154
        // Old H2 versions need this to safely open page store files
-
 
155
        // (https://github.com/h2database/h2database/issues/1023), and new version ignore it
-
 
156
        // (https://github.com/h2database/h2database/pull/1208).
-
 
157
        ds.addConnectionProperty("MVCC", "false");
-
 
158
        // Don't begin transition from page store just yet.
-
 
159
        ds.addConnectionProperty("MV_STORE", "false");
-
 
160
    }
-
 
161
 
-
 
162
    @Override
134
    protected List<String> getMappings() {
163
    protected List<String> getMappings() {
135
        final List<String> res = new ArrayList<>(super.getMappings());
164
        final List<String> res = new ArrayList<>(super.getMappings());
136
        final String pkg = "/" + TM.class.getPackage().getName().replace('.', '/');
165
        final String pkg = "/" + TM.class.getPackage().getName().replace('.', '/');
137
        res.add(pkg + "/translation/SQLElementNames");
166
        res.add(pkg + "/translation/SQLElementNames");
138
        return res;
167
        return res;
Line 166... Line 195...
166
 
195
 
167
    public final String getSocieteBaseName() {
196
    public final String getSocieteBaseName() {
168
        return getRowSociete().getString("DATABASE_NAME");
197
        return getRowSociete().getString("DATABASE_NAME");
169
    }
198
    }
170
 
199
 
171
    public final SQLRow getRowSociete() {
200
    public synchronized final SQLRow getRowSociete() {
172
        return this.rowSociete;
201
        return this.rowSociete;
173
    }
202
    }
174
 
203
 
175
    public final int getSocieteID() {
204
    public final int getSocieteID() {
176
        return this.idSociete;
205
        final SQLRow row = this.getRowSociete();
-
 
206
        return row == null ? SQLRow.NONEXISTANT_ID : row.getID();
177
    }
207
    }
178
 
208
 
-
 
209
    private synchronized void updateRowSociete(SQLTableEvent evt) {
-
 
210
        if (evt.getRow().equals(this.rowSociete)) {
-
 
211
            this.rowSociete.fetchValues();
-
 
212
        }
-
 
213
    }
-
 
214
 
-
 
215
    public final SQLTable getSocieteTable() {
-
 
216
        return getSocieteTable(true);
-
 
217
    }
-
 
218
 
-
 
219
    protected final SQLTable getSocieteTable(final boolean mustExist) {
-
 
220
        return getSystemRoot().findTable("SOCIETE_COMMON", mustExist);
-
 
221
    }
-
 
222
 
-
 
223
    // undefined ID is allowed (used for the template root)
179
    protected final void setRowSociete(int id) {
224
    protected final void setRowSociete(Number id) {
-
 
225
        final boolean clear = id == null;
180
        this.idSociete = id;
226
        final SQLRow row;
181
        final SQLTable tableSociete = getSystemRoot().findTable("SOCIETE_COMMON");
227
        final SQLTable tableSociete = getSocieteTable(!clear);
-
 
228
        if (clear) {
-
 
229
            row = null;
-
 
230
            // might be null if mapsToRoot is empty (e.g. tests)
-
 
231
            if (tableSociete != null)
-
 
232
                tableSociete.removeTableModifiedListener(this.rowSocieteListener);
-
 
233
        } else {
182
        final SQLRow row = tableSociete.getRow(id);
234
            row = tableSociete.getRow(id.intValue());
183
        if (row == null) {
235
            if (row == null) {
184
            throw new IllegalArgumentException("no row for id " + id + " in " + tableSociete);
236
                throw new IllegalArgumentException("no row for id " + id + " in " + tableSociete);
185
        } else if (!row.isValid()) {
237
            } else if (!row.isValid()) {
186
            throw new IllegalArgumentException("invalid row : " + row);
238
                throw new IllegalArgumentException("invalid row : " + row);
187
        }
239
            }
-
 
240
            tableSociete.addTableModifiedListener(this.rowSocieteListener);
-
 
241
        }
-
 
242
        synchronized (this) {
188
        this.rowSociete = row;
243
            this.rowSociete = row;
189
    }
244
        }
-
 
245
    }
190
 
246
 
-
 
247
    @Deprecated
191
    public final SQLBase getSQLBaseSociete() {
248
    public final SQLBase getSQLBaseSociete() {
192
        return this.getRootSociete().getBase();
249
        return this.getRootSociete().getBase();
193
    }
250
    }
194
 
251
 
195
    public final DBRoot getRootSociete() {
252
    public final DBRoot getRootSociete() {
-
 
253
        return this.getRootSociete(true);
-
 
254
    }
-
 
255
 
-
 
256
    protected synchronized final DBRoot getRootSociete(final boolean create) {
196
        if (this.baseSociete == null && this.rowSociete != null)
257
        if (create && this.baseSociete == null && this.getRowSociete() != null)
197
            this.baseSociete = this.createSQLBaseSociete();
258
            this.baseSociete = this.createSQLBaseSociete();
198
        return this.baseSociete;
259
        return this.baseSociete;
199
    }
260
    }
200
 
261
 
201
    private DBRoot createSQLBaseSociete() {
262
    private DBRoot createSQLBaseSociete() {