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.model;
|
|
|
15 |
|
|
|
16 |
import java.util.HashMap;
|
|
|
17 |
import java.util.Map;
|
|
|
18 |
|
|
|
19 |
// do not use fields DEFAULT since they're not always constants, plus for some systems we need a
|
|
|
20 |
// trip to the db anyway to interpret them and they're not easily updateable.
|
|
|
21 |
// MAYBE don't piggyback on undefinedID, rather create a defaultValuesID (eg add column in
|
|
|
22 |
// FWK_UNDEF_ID) that would be archived so as to not appear in results
|
|
|
23 |
public class UndefinedRowValuesCache {
|
|
|
24 |
private static final UndefinedRowValuesCache instance = new UndefinedRowValuesCache();
|
|
|
25 |
|
|
|
26 |
public synchronized static UndefinedRowValuesCache getInstance() {
|
|
|
27 |
return instance;
|
|
|
28 |
}
|
|
|
29 |
|
|
|
30 |
private final Map<SQLTable, SQLRowValues> map = new HashMap<SQLTable, SQLRowValues>();
|
|
|
31 |
|
|
|
32 |
public SQLRowValues getDefaultRowValues(final SQLTable t) {
|
|
|
33 |
SQLRowValues rv = this.map.get(t);
|
|
|
34 |
if (rv == null) {
|
|
|
35 |
rv = new SQLRowValues(t);
|
|
|
36 |
final SQLRow undefRow = t.getRow(t.getUndefinedID());
|
|
|
37 |
if (undefRow == null)
|
|
|
38 |
throw new IllegalStateException(t.getSQLName() + " doesn't contain undef ID " + t.getUndefinedID());
|
|
|
39 |
rv.loadAllSafe(undefRow);
|
|
|
40 |
this.map.put(t, rv);
|
|
|
41 |
}
|
|
|
42 |
return rv;
|
|
|
43 |
}
|
|
|
44 |
}
|