-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCayenneReferenceDataCache.java
More file actions
142 lines (122 loc) · 4.3 KB
/
Copy pathCayenneReferenceDataCache.java
File metadata and controls
142 lines (122 loc) · 4.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package application;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.apache.cayenne.query.ObjectSelect;
import com.tc.app.exchangemonitor.model.cayenne.persistent.Account;
import com.tc.app.exchangemonitor.model.cayenne.persistent.Commodity;
import com.tc.app.exchangemonitor.model.cayenne.persistent.IctsUser;
import com.tc.app.exchangemonitor.model.cayenne.persistent.Uom;
public class CayenneReferenceDataCache
{
public static void fetchAllReferenceData()
{
fetchAccountsReferenceData();
fetchIctsUsersReferenceData();
fetchCommoditiesReferenceData();
fetchUomsReferenceData();
}
private static Map<Integer, Account> accountsReferenceDataHashMap = null;
private static void fetchAccountsReferenceData()
{
try
{
if(accountsReferenceDataHashMap == null)
{
accountsReferenceDataHashMap = new HashMap<>();
final List<Account> accountList = ObjectSelect.query(Account.class).where(Account.ACCT_STATUS.eq("A")).select(CayenneHelper.getCayenneServerRuntime().newContext());
accountsReferenceDataHashMap = accountList.stream().collect(Collectors.toMap(Account::getAccountNum, theAccount -> theAccount, (theExistingAccount, theNewAccount) -> theNewAccount, LinkedHashMap::new));
}
}
catch(final Exception exception)
{
throw exception;
}
}
private static Map<String, IctsUser> ictsUsersReferenceDataHashMap = null;
private static void fetchIctsUsersReferenceData()
{
try
{
if(ictsUsersReferenceDataHashMap == null)
{
ictsUsersReferenceDataHashMap = new HashMap<>();
final List<IctsUser> ictsUsersList = ObjectSelect.query(IctsUser.class).where(IctsUser.USER_STATUS.eq("A")).select(CayenneHelper.getCayenneServerRuntime().newContext());
ictsUsersReferenceDataHashMap = ictsUsersList.stream().collect(Collectors.toMap(IctsUser::getUserInit, theIctsUser -> theIctsUser, (theExistingIctsUser, theNewIctsUser) -> theNewIctsUser, LinkedHashMap::new));
}
}
catch(final Exception exception)
{
throw exception;
}
}
private static Map<String, Commodity> commoditiesReferenceDataHashMap = null;
private static void fetchCommoditiesReferenceData()
{
try
{
if(commoditiesReferenceDataHashMap == null)
{
commoditiesReferenceDataHashMap = new HashMap<>();
//final List<Commodity> commoditiesList = ObjectSelect.query(Commodity.class).where(Commodity.CMDTY_STATUS.eq("A")).select(CayenneHelper.getCayenneServerRuntime().newContext());
final List<Commodity> commoditiesList = ObjectSelect.query(Commodity.class).where(Commodity.CMDTY_STATUS.eq("A")).select(CayenneHelper.getCayenneServerRuntime().newContext());
commoditiesReferenceDataHashMap = commoditiesList.stream().collect(Collectors.toMap(Commodity::getCmdtyCode, theCommodity -> theCommodity, (theExistingCommodity, theNewCommodity) -> theNewCommodity, LinkedHashMap::new));
}
}
catch(final Exception exception)
{
throw exception;
}
}
private static Map<String, Uom> uomsReferenceDataHashMap = null;
private static void fetchUomsReferenceData()
{
try
{
if(uomsReferenceDataHashMap == null)
{
uomsReferenceDataHashMap = new HashMap<>();
final List<Uom> uomsList = ObjectSelect.query(Uom.class).where(Uom.UOM_STATUS.eq("A")).select(CayenneHelper.getCayenneServerRuntime().newContext());
uomsReferenceDataHashMap = uomsList.stream().collect(Collectors.toMap(Uom::getUomCode, theUom -> theUom, (theExistingUom, theNewUom) -> theNewUom, LinkedHashMap::new));
}
}
catch(final Exception exception)
{
throw exception;
}
}
public static Map<Integer, Account> loadAllActiveAccounts()
{
if(accountsReferenceDataHashMap == null)
{
fetchAccountsReferenceData();
}
return accountsReferenceDataHashMap;
}
public static Map<String, IctsUser> loadAllActiveIctsUsers()
{
if(ictsUsersReferenceDataHashMap == null)
{
fetchIctsUsersReferenceData();
}
return ictsUsersReferenceDataHashMap;
}
public static Map<String, Commodity> loadAllActiveCommodities()
{
if(commoditiesReferenceDataHashMap == null)
{
fetchCommoditiesReferenceData();
}
return commoditiesReferenceDataHashMap;
}
public static Map<String, Uom> loadAllActiveUoms()
{
if(uomsReferenceDataHashMap == null)
{
fetchUomsReferenceData();
}
return uomsReferenceDataHashMap;
}
}