Project

General

Profile

4286a_summary.patch

rev 11339 (branch 4286a) - Sergey Ivanovskiy, 09/20/2019 12:31 PM

Download (81.9 KB)

View differences:

src/com/goldencode/p2j/ui/BrowseKey.java 2019-09-17 20:05:17 +0000
65 65
import java.io.*;
66 66
import java.util.*;
67 67

  
68
import com.fasterxml.jackson.annotation.*;
69

  
68 70
/**
69 71
 * Key that uniquely identifies browse in an application using combination of the parent external
70 72
 * procedure name, browse name and set of column keys. If the parent external procedure name is
71 73
 * <code>null</code> then this key references to all browses.
72 74
 */
75
@JsonInclude(JsonInclude.Include.NON_NULL)
73 76
public class BrowseKey
74 77
implements Serializable
75 78
{
......
113 116
    * @param ehColumnKeys
114 117
    *        Set of column keys.
115 118
    */
119
   @JsonCreator
116 120
   public BrowseKey(String ehKeyProcName,
117 121
                    String ehKeyBrowseName,
118 122
                    Set<String> ehColumnKeys)
src/com/goldencode/p2j/ui/ClientExports.java 2019-09-13 09:26:59 +0000
316 316
 * design policies are required to maximize the performance of the remote
317 317
 * UI as well as to keep the remote UI implementation as simple as possible.
318 318
 */
319
public interface ClientExports
319
public interface ClientExports extends ObjectStorage
320 320
{
321 321
   /**
322 322
    * Rings a bell on the terminal.
src/com/goldencode/p2j/ui/ClientStorageProxy.java 2019-09-19 19:38:57 +0000
1
/*
2
** Module   : ClientStorageProxy.java
3
** Abstract : Implements the proxy for the client object storage that can be used on the server.
4
**
5
** Copyright (c) 2019, Golden Code Development Corporation.
6
**
7
** -#- -I- --Date-- ---------------------------------Description---------------------------------
8
** 001 SBI 20190911 Created initial version.
9
*/
10

  
11
/*
12
** This program is free software: you can redistribute it and/or modify
13
** it under the terms of the GNU Affero General Public License as
14
** published by the Free Software Foundation, either version 3 of the
15
** License, or (at your option) any later version.
16
**
17
** This program is distributed in the hope that it will be useful,
18
** but WITHOUT ANY WARRANTY; without even the implied warranty of
19
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
** GNU Affero General Public License for more details.
21
**
22
** You may find a copy of the GNU Affero GPL version 3 at the following
23
** location: https://www.gnu.org/licenses/agpl-3.0.en.html
24
** 
25
** Additional terms under GNU Affero GPL version 3 section 7:
26
** 
27
**   Under Section 7 of the GNU Affero GPL version 3, the following additional
28
**   terms apply to the works covered under the License.  These additional terms
29
**   are non-permissive additional terms allowed under Section 7 of the GNU
30
**   Affero GPL version 3 and may not be removed by you.
31
** 
32
**   0. Attribution Requirement.
33
** 
34
**     You must preserve all legal notices or author attributions in the covered
35
**     work or Appropriate Legal Notices displayed by works containing the covered
36
**     work.  You may not remove from the covered work any author or developer
37
**     credit already included within the covered work.
38
** 
39
**   1. No License To Use Trademarks.
40
** 
41
**     This license does not grant any license or rights to use the trademarks
42
**     Golden Code, FWD, any Golden Code or FWD logo, or any other trademarks
43
**     of Golden Code Development Corporation. You are not authorized to use the
44
**     name Golden Code, FWD, or the names of any author or contributor, for
45
**     publicity purposes without written authorization.
46
** 
47
**   2. No Misrepresentation of Affiliation.
48
** 
49
**     You may not represent yourself as Golden Code Development Corporation or FWD.
50
** 
51
**     You may not represent yourself for publicity purposes as associated with
52
**     Golden Code Development Corporation, FWD, or any author or contributor to
53
**     the covered work, without written authorization.
54
** 
55
**   3. No Misrepresentation of Source or Origin.
56
** 
57
**     You may not represent the covered work as solely your work.  All modified
58
**     versions of the covered work must be marked in a reasonable way to make it
59
**     clear that the modified work is not originating from Golden Code Development
60
**     Corporation or FWD.  All modified versions must contain the notices of
61
**     attribution required in this license.
62
*/
63

  
64
package com.goldencode.p2j.ui;
65

  
66

  
67
/**
68
 * Represents the server side client storage proxy
69
 */
70
public class ClientStorageProxy
71
implements ObjectStorage
72
{
73
   /** The client exported API */
74
   private final ClientExports client;
75
   
76
   /**
77
    * Creates a proxy object.
78
    * 
79
    * @param    client
80
    *           The delegate that represents the client exported API.
81
    */
82
   public ClientStorageProxy(ClientExports client)
83
   {
84
      this.client = client;
85
   }
86

  
87
   /**
88
    * Retrieves the number value of the given key from this storage.
89
    * 
90
    * @param    key
91
    *           The given key
92
    * 
93
    * @return   The number value of the given key 
94
    */
95
   @Override
96
   public Number getNumber(String key)
97
   {
98
      return client.getNumber(key);
99
   }
100

  
101
   /**
102
    * Saves the number value of this key in this storage.
103
    * 
104
    * @param    key
105
    *           The given key
106
    * @param    value
107
    *           The value of the given key
108
    */
109
   @Override
110
   public void setNumber(String key, Number value)
111
   {
112
      client.setNumber(key, value);
113
   }
114

  
115
   /**
116
    * Retrieves the boolean value of the given key from this storage.
117
    * 
118
    * @param    key
119
    *           The given key
120
    * 
121
    * @return   The boolean value of the given key
122
    */
123
   @Override
124
   public Boolean getBoolean(String key)
125
   {
126
      return client.getBoolean(key);
127
   }
128

  
129
   /**
130
    * Saves the boolean value of this key in this storage.
131
    * 
132
    * @param    key
133
    *           The given key
134
    * @param    value
135
    *           The value of the given key
136
    */
137
   @Override
138
   public void setBoolean(String key, Boolean value)
139
   {
140
      client.setBoolean(key, value);
141
   }
142

  
143
   /**
144
    * Retrieves the string value of the given key from this storage.
145
    * 
146
    * @param    key
147
    *           The given key
148
    * 
149
    * @return   The string value of the given key
150
    */
151
   @Override
152
   public String getString(String key)
153
   {
154
      return client.getString(key);
155
   }
156

  
157
   /**
158
    * Saves the string value of this key in this storage.
159
    * 
160
    * @param    key
161
    *           The given key
162
    * @param    value
163
    *           The value of the given key
164
    */
165
   @Override
166
   public void setString(String key, String value)
167
   {
168
      client.setString(key, value);
169
   }
170

  
171
   /**
172
    * Deletes the given key and its value from this storage.
173
    * 
174
    * @param    key
175
    *           The given key
176
    */
177
   @Override
178
   public void delete(String key)
179
   {
180
      client.delete(key);
181
   }
182

  
183
   /**
184
    * Retrieves the object value of the given key from this storage.
185
    * 
186
    * @param    key
187
    *           The given key
188
    * @param    clazz
189
    *           The java class that represents this object
190
    * 
191
    * @return   The object value of the given key
192
    */
193
   @SuppressWarnings("rawtypes")
194
   @Override
195
   public Object getObject(String key, Class clazz)
196
   {
197
      return client.getObject(key, clazz);
198
   }
199

  
200
   /**
201
    * Sets the object value of the given key for this storage.
202
    * 
203
    * @param    key
204
    *           The given key
205
    * @param    value
206
    *           The object value
207
    */
208
   @Override
209
   public void setObject(String key, Object value)
210
   {
211
      client.setObject(key, value);
212
   }
213

  
214
   /**
215
    * Returns the storage size.
216
    * 
217
    * @return   The storage size
218
    */
219
   @Override
220
   public int getSize()
221
   {
222
      return client.getSize();
223
   }
224

  
225
   /**
226
    * Returns the key by its index number in a sequence of all storage keys.
227
    * 
228
    * @param    index
229
    *           The given index number in a sequence of all storage keys.
230
    * 
231
    * @return   The key
232
    */
233
   @Override
234
   public String getKey(int index)
235
   {
236
      return client.getKey(index);
237
   }
238
}
src/com/goldencode/p2j/ui/EnhancedBrowseConfig.java 2019-09-17 20:06:41 +0000
67 67

  
68 68
package com.goldencode.p2j.ui;
69 69

  
70
import com.fasterxml.jackson.annotation.*;
70 71
import com.goldencode.p2j.ui.client.*;
71 72
import com.goldencode.p2j.ui.client.gui.*;
73

  
72 74
import java.io.*;
73 75
import java.util.*;
74 76

  
......
82 84
 *    <li>width, order and visibility of columns.</li>
83 85
 * </ul>
84 86
 */
87
@JsonInclude(JsonInclude.Include.NON_NULL)
85 88
public class EnhancedBrowseConfig
86 89
implements Serializable
87 90
{
......
229 232
    *
230 233
    * @return the key which identifies the underlying browse.
231 234
    */
235
   @JsonIgnore
232 236
   public BrowseKey getKey()
233 237
   {
234 238
      return new BrowseKey(ehKeyProcName,
......
244 248
    *
245 249
    * @return the storage key of this configuration.
246 250
    */
251
   @JsonIgnore
247 252
   public EnhancedBrowseConfigStorageKey getStorageKey()
248 253
   {
249 254
      return new EnhancedBrowseConfigStorageKey(userName, getKey());
src/com/goldencode/p2j/ui/EnhancedBrowseConfigStorageKey.java 2019-09-17 20:06:10 +0000
63 63

  
64 64
import java.util.*;
65 65

  
66
import com.fasterxml.jackson.annotation.*;
67

  
66 68
/**
67 69
 * Enhanced browse configuration storage key. Extends {@link BrowseKey} with the
68 70
 * field containing a user name. Used for keying configurations loaded from the directory.
......
89 91
    * @param configKey
90 92
    *        Key that uniquely identifies browse in an application.
91 93
    */
92
   public EnhancedBrowseConfigStorageKey(String userName, BrowseKey configKey)
94
   @JsonCreator
95
   public EnhancedBrowseConfigStorageKey(@JsonProperty("userName") String    userName,
96
                                         @JsonProperty("configKey")BrowseKey configKey)
93 97
   {
94 98
      this.userName = userName;
95 99
      this.configKey = configKey;
src/com/goldencode/p2j/ui/KeyValueStorage.java 2019-09-19 16:19:45 +0000
1
/*
2
** Module   : KeyValueStorage.java
3
** Abstract : Defines methods to store and retrieve key and value pairs.
4
**
5
** Copyright (c) 2019, Golden Code Development Corporation.
6
**
7
** -#- -I- --Date-- ---------------------------------Description---------------------------------
8
** 001 SBI 20190911 Created initial version.
9
*/
10

  
11
/*
12
** This program is free software: you can redistribute it and/or modify
13
** it under the terms of the GNU Affero General Public License as
14
** published by the Free Software Foundation, either version 3 of the
15
** License, or (at your option) any later version.
16
**
17
** This program is distributed in the hope that it will be useful,
18
** but WITHOUT ANY WARRANTY; without even the implied warranty of
19
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
** GNU Affero General Public License for more details.
21
**
22
** You may find a copy of the GNU Affero GPL version 3 at the following
23
** location: https://www.gnu.org/licenses/agpl-3.0.en.html
24
** 
25
** Additional terms under GNU Affero GPL version 3 section 7:
26
** 
27
**   Under Section 7 of the GNU Affero GPL version 3, the following additional
28
**   terms apply to the works covered under the License.  These additional terms
29
**   are non-permissive additional terms allowed under Section 7 of the GNU
30
**   Affero GPL version 3 and may not be removed by you.
31
** 
32
**   0. Attribution Requirement.
33
** 
34
**     You must preserve all legal notices or author attributions in the covered
35
**     work or Appropriate Legal Notices displayed by works containing the covered
36
**     work.  You may not remove from the covered work any author or developer
37
**     credit already included within the covered work.
38
** 
39
**   1. No License To Use Trademarks.
40
** 
41
**     This license does not grant any license or rights to use the trademarks
42
**     Golden Code, FWD, any Golden Code or FWD logo, or any other trademarks
43
**     of Golden Code Development Corporation. You are not authorized to use the
44
**     name Golden Code, FWD, or the names of any author or contributor, for
45
**     publicity purposes without written authorization.
46
** 
47
**   2. No Misrepresentation of Affiliation.
48
** 
49
**     You may not represent yourself as Golden Code Development Corporation or FWD.
50
** 
51
**     You may not represent yourself for publicity purposes as associated with
52
**     Golden Code Development Corporation, FWD, or any author or contributor to
53
**     the covered work, without written authorization.
54
** 
55
**   3. No Misrepresentation of Source or Origin.
56
** 
57
**     You may not represent the covered work as solely your work.  All modified
58
**     versions of the covered work must be marked in a reasonable way to make it
59
**     clear that the modified work is not originating from Golden Code Development
60
**     Corporation or FWD.  All modified versions must contain the notices of
61
**     attribution required in this license.
62
*/
63

  
64
package com.goldencode.p2j.ui;
65

  
66

  
67
/**
68
 * This interface defines access methods for a key value storage.
69
 */
70
public interface KeyValueStorage
71
{
72
   /**
73
    * Retrieves the number value of the given key from this storage.
74
    * 
75
    * @param    key
76
    *           The given key
77
    * 
78
    * @return   The number value of the given key 
79
    */
80
   Number getNumber(String key);
81
   
82
   /**
83
    * Saves the number value of this key in this storage.
84
    * 
85
    * @param    key
86
    *           The given key
87
    * @param    value
88
    *           The value of the given key
89
    */
90
   void setNumber(String key, Number value);
91
   
92
   /**
93
    * Retrieves the boolean value of the given key from this storage.
94
    * 
95
    * @param    key
96
    *           The given key
97
    * 
98
    * @return   The boolean value of the given key
99
    */
100
   Boolean getBoolean(String key);
101
   
102
   /**
103
    * Saves the boolean value of this key in this storage.
104
    * 
105
    * @param    key
106
    *           The given key
107
    * @param    value
108
    *           The value of the given key
109
    */
110
   void setBoolean(String key, Boolean value);
111
   
112
   /**
113
    * Retrieves the string value of the given key from this storage.
114
    * 
115
    * @param    key
116
    *           The given key
117
    * 
118
    * @return   The string value of the given key
119
    */
120
   String getString(String key);
121
   
122
   /**
123
    * Saves the string value of this key in this storage.
124
    * 
125
    * @param    key
126
    *           The given key
127
    * @param    value
128
    *           The value of the given key
129
    */
130
   void setString(String key, String value);
131
   
132
   /**
133
    * Deletes the given key and its value from this storage.
134
    * 
135
    * @param    key
136
    *           The given key
137
    */
138
   void delete(String key);
139
   
140
   /**
141
    * Returns the storage size.
142
    * 
143
    * @return   The storage size
144
    */
145
   int getSize();
146
   
147
   /**
148
    * Returns the key by its index number in a sequence of all storage keys.
149
    * 
150
    * @param    index
151
    *           The given index number in a sequence of all storage keys.
152
    * 
153
    * @return   The key
154
    */
155
   String getKey(int index);
156
}
src/com/goldencode/p2j/ui/KeyValueStorageAdapter.java 2019-09-19 19:08:16 +0000
1
/*
2
** Module   : KeyValueStorageAdapter.java
3
** Abstract : Implements the adapter for the KeyValueStorage backend and the client object storage.
4
**
5
** Copyright (c) 2019, Golden Code Development Corporation.
6
**
7
** -#- -I- --Date-- ---------------------------------Description---------------------------------
8
** 001 SBI 20190911 Created initial version.
9
*/
10

  
11
/*
12
** This program is free software: you can redistribute it and/or modify
13
** it under the terms of the GNU Affero General Public License as
14
** published by the Free Software Foundation, either version 3 of the
15
** License, or (at your option) any later version.
16
**
17
** This program is distributed in the hope that it will be useful,
18
** but WITHOUT ANY WARRANTY; without even the implied warranty of
19
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
** GNU Affero General Public License for more details.
21
**
22
** You may find a copy of the GNU Affero GPL version 3 at the following
23
** location: https://www.gnu.org/licenses/agpl-3.0.en.html
24
** 
25
** Additional terms under GNU Affero GPL version 3 section 7:
26
** 
27
**   Under Section 7 of the GNU Affero GPL version 3, the following additional
28
**   terms apply to the works covered under the License.  These additional terms
29
**   are non-permissive additional terms allowed under Section 7 of the GNU
30
**   Affero GPL version 3 and may not be removed by you.
31
** 
32
**   0. Attribution Requirement.
33
** 
34
**     You must preserve all legal notices or author attributions in the covered
35
**     work or Appropriate Legal Notices displayed by works containing the covered
36
**     work.  You may not remove from the covered work any author or developer
37
**     credit already included within the covered work.
38
** 
39
**   1. No License To Use Trademarks.
40
** 
41
**     This license does not grant any license or rights to use the trademarks
42
**     Golden Code, FWD, any Golden Code or FWD logo, or any other trademarks
43
**     of Golden Code Development Corporation. You are not authorized to use the
44
**     name Golden Code, FWD, or the names of any author or contributor, for
45
**     publicity purposes without written authorization.
46
** 
47
**   2. No Misrepresentation of Affiliation.
48
** 
49
**     You may not represent yourself as Golden Code Development Corporation or FWD.
50
** 
51
**     You may not represent yourself for publicity purposes as associated with
52
**     Golden Code Development Corporation, FWD, or any author or contributor to
53
**     the covered work, without written authorization.
54
** 
55
**   3. No Misrepresentation of Source or Origin.
56
** 
57
**     You may not represent the covered work as solely your work.  All modified
58
**     versions of the covered work must be marked in a reasonable way to make it
59
**     clear that the modified work is not originating from Golden Code Development
60
**     Corporation or FWD.  All modified versions must contain the notices of
61
**     attribution required in this license.
62
*/
63

  
64
package com.goldencode.p2j.ui;
65

  
66
import java.io.*;
67

  
68
import com.fasterxml.jackson.core.*;
69
import com.fasterxml.jackson.databind.*;
70

  
71

  
72
/**
73
 * Implements a string key value user's storage backed by java user preferences file storage.
74
 */
75
public class KeyValueStorageAdapter
76
implements ObjectStorage
77
{
78
   /** Object to JSON converter*/
79
   private final ObjectMapper mapper;
80
   
81
   /** The backed key and value storage */
82
   private KeyValueStorage backend;
83
   
84
   /**
85
    * Creates this adapter.
86
    */
87
   public KeyValueStorageAdapter()
88
   {
89
      this.mapper = new ObjectMapper();
90
      mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
91
   }
92
   
93
   /**
94
    * Retrieves the number value of the given key from this storage.
95
    * 
96
    * @param    key
97
    *           The given key
98
    * 
99
    * @return   The number value of the given key 
100
    */
101
   @Override
102
   public Number getNumber(String key)
103
   {
104
      return this.backend.getNumber(key);
105
   }
106

  
107
   /**
108
    * Saves the number value of this key in this storage.
109
    * 
110
    * @param    key
111
    *           The given key
112
    * @param    value
113
    *           The value of the given key
114
    */
115
   @Override
116
   public void setNumber(String key, Number value)
117
   {
118
      this.backend.setNumber(key, value);
119
   }
120

  
121
   /**
122
    * Retrieves the boolean value of the given key from this storage.
123
    * 
124
    * @param    key
125
    *           The given key
126
    * 
127
    * @return   The boolean value of the given key
128
    */
129
   @Override
130
   public Boolean getBoolean(String key)
131
   {
132
      return this.backend.getBoolean(key);
133
   }
134

  
135
   /**
136
    * Saves the boolean value of this key in this storage.
137
    * 
138
    * @param    key
139
    *           The given key
140
    * @param    value
141
    *           The value of the given key
142
    */
143
   @Override
144
   public void setBoolean(String key, Boolean value)
145
   {
146
      this.backend.setBoolean(key, value);
147
   }
148

  
149
   /**
150
    * Retrieves the string value of the given key from this storage.
151
    * 
152
    * @param    key
153
    *           The given key
154
    * 
155
    * @return   The string value of the given key
156
    */
157
   @Override
158
   public String getString(String key)
159
   {
160
      return this.backend.getString(key);
161
   }
162

  
163
   @Override
164
   public void setString(String key, String value)
165
   {
166
      this.backend.setString(key, value);
167
   }
168

  
169
   /**
170
    * Deletes the given key and its value from this storage.
171
    * 
172
    * @param    key
173
    *           The given key
174
    */
175
   @Override
176
   public void delete(String key)
177
   {
178
      this.backend.delete(key);
179
   }
180

  
181
   /**
182
    * Sets the backend key and value storage.
183
    * 
184
    * @param    backend
185
    *           The backend key and value storage
186
    */
187
   public void setBackend(KeyValueStorage backend)
188
   {
189
      this.backend = backend;
190
   }
191
   
192
   /**
193
    * Retrieves the object value of the given key from this storage.
194
    * 
195
    * @param    key
196
    *           The given key
197
    * @param    clazz
198
    *           The java class that represents this object
199
    * 
200
    * @return   The object value of the given key
201
    */
202
   @SuppressWarnings("rawtypes")
203
   @Override
204
   public Object getObject(String key, Class clazz)
205
   {
206
      return parseJSON(key, clazz);
207
   }
208

  
209
   /**
210
    * Sets the object value of the given key for this storage.
211
    * 
212
    * @param    key
213
    *           The given key
214
    * @param    value
215
    *           The object value
216
    */
217
   public void setObject(String key, Object value)
218
   {
219
      try
220
      {
221
         String json = mapper.writeValueAsString(value);
222
         backend.setString(key, json);
223
      }
224
      catch (JsonProcessingException e)
225
      {
226
         e.printStackTrace();
227
      }
228

  
229
   }
230

  
231
   /**
232
    * The template method to get the object from its json presentation retrieved from the storage
233
    * by the given key.
234
    * 
235
    * @param    key
236
    *           The given key
237
    * @param    clazz
238
    *           The java class that represents this object
239
    * 
240
    * @return   The object value of the given key
241
    */
242
   private <T> T parseJSON(String key, Class<T> clazz)
243
   {
244
      String content = backend.getString(key);
245
      
246
      if (content != null)
247
      {
248
         try
249
         {
250
            return mapper.readValue(content, clazz);
251
         }
252
         catch (IOException e)
253
         {
254
            e.printStackTrace();
255
         }
256
      }
257
      
258
      return null;
259
   }
260

  
261
   /**
262
    * Returns the storage size.
263
    * 
264
    * @return   The storage size
265
    */
266
   @Override
267
   public int getSize()
268
   {
269
      return backend.getSize();
270
   }
271

  
272
   /**
273
    * Returns the key by its index number in a sequence of all storage keys.
274
    * 
275
    * @param    index
276
    *           The given index number in a sequence of all storage keys.
277
    * 
278
    * @return   The key
279
    */
280
   @Override
281
   public String getKey(int index)
282
   {
283
      return backend.getKey(index);
284
   }
285
}
src/com/goldencode/p2j/ui/LogicalTerminal.java 2019-09-13 15:47:22 +0000
1216 1216
   /** Helper to use the TM without any context local lookups. */
1217 1217
   private TransactionManager.TransactionHelper tm;
1218 1218
   
1219
   /** The client local storage proxy */
1220
   private ObjectStorage clientLocalStorage;
1221
   
1219 1222
   /**
1220 1223
    * Constructor.
1221 1224
    */
......
1251 1254
         client = (ClientExports) RemoteObject.obtainLocalInstance(ClientExports.class, true);
1252 1255
      }
1253 1256
      
1257
      clientLocalStorage = new ClientStorageProxy(client);
1258
      
1254 1259
      ErrorManager.setSystemAlertBoxes(!client.isChui());
1255 1260

  
1256 1261
      // create the main window BUT DO NOT PUSH IT since a duplicate instance
......
7807 7812
   }
7808 7813
   
7809 7814
   /**
7815
    * Gets the client local storage.
7816
    * 
7817
    * @return   The client local storage
7818
    */
7819
   public static ObjectStorage getClientStorage()
7820
   {
7821
      return locate().clientLocalStorage;
7822
   }
7823
   
7824
   /**
7810 7825
    * Read the legacy text metrics for all the texts and each font defined in the font table, for
7811 7826
    * this user.
7812 7827
    *
src/com/goldencode/p2j/ui/ObjectStorage.java 2019-09-13 09:27:00 +0000
1
/*
2
** Module   : ObjectStorage.java
3
** Abstract : Extends a key and value storage to be used as a client object storage.
4
**
5
** Copyright (c) 2019, Golden Code Development Corporation.
6
**
7
** -#- -I- --Date-- ---------------------------------Description---------------------------------
8
** 001 SBI 20190911 Created initial version.
9
*/
10

  
11
/*
12
** This program is free software: you can redistribute it and/or modify
13
** it under the terms of the GNU Affero General Public License as
14
** published by the Free Software Foundation, either version 3 of the
15
** License, or (at your option) any later version.
16
**
17
** This program is distributed in the hope that it will be useful,
18
** but WITHOUT ANY WARRANTY; without even the implied warranty of
19
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
** GNU Affero General Public License for more details.
21
**
22
** You may find a copy of the GNU Affero GPL version 3 at the following
23
** location: https://www.gnu.org/licenses/agpl-3.0.en.html
24
** 
25
** Additional terms under GNU Affero GPL version 3 section 7:
26
** 
27
**   Under Section 7 of the GNU Affero GPL version 3, the following additional
28
**   terms apply to the works covered under the License.  These additional terms
29
**   are non-permissive additional terms allowed under Section 7 of the GNU
30
**   Affero GPL version 3 and may not be removed by you.
31
** 
32
**   0. Attribution Requirement.
33
** 
34
**     You must preserve all legal notices or author attributions in the covered
35
**     work or Appropriate Legal Notices displayed by works containing the covered
36
**     work.  You may not remove from the covered work any author or developer
37
**     credit already included within the covered work.
38
** 
39
**   1. No License To Use Trademarks.
40
** 
41
**     This license does not grant any license or rights to use the trademarks
42
**     Golden Code, FWD, any Golden Code or FWD logo, or any other trademarks
43
**     of Golden Code Development Corporation. You are not authorized to use the
44
**     name Golden Code, FWD, or the names of any author or contributor, for
45
**     publicity purposes without written authorization.
46
** 
47
**   2. No Misrepresentation of Affiliation.
48
** 
49
**     You may not represent yourself as Golden Code Development Corporation or FWD.
50
** 
51
**     You may not represent yourself for publicity purposes as associated with
52
**     Golden Code Development Corporation, FWD, or any author or contributor to
53
**     the covered work, without written authorization.
54
** 
55
**   3. No Misrepresentation of Source or Origin.
56
** 
57
**     You may not represent the covered work as solely your work.  All modified
58
**     versions of the covered work must be marked in a reasonable way to make it
59
**     clear that the modified work is not originating from Golden Code Development
60
**     Corporation or FWD.  All modified versions must contain the notices of
61
**     attribution required in this license.
62
*/
63

  
64
package com.goldencode.p2j.ui;
65

  
66

  
67
/**
68
 * Added methods to persist object values of keys. Extends this key value storage interface to be
69
 * an object storage interface. 
70
 */
71
public interface ObjectStorage extends KeyValueStorage
72
{
73
   /**
74
    * Retrieves the object value of the given key from this storage.
75
    * 
76
    * @param    key
77
    *           The given key
78
    * @param    clazz
79
    *           The java class that represents this object
80
    * 
81
    * @return   The object value of the given key
82
    */
83
   @SuppressWarnings("rawtypes")
84
   Object getObject(String key, Class clazz);
85
   
86
   /**
87
    * Sets the object value of the given key for this storage.
88
    * 
89
    * @param    key
90
    *           The given key
91
    * @param    value
92
    *           The object value
93
    */
94
   void setObject(String key, Object value);
95
}
src/com/goldencode/p2j/ui/chui/ThinClient.java 2019-09-19 19:06:21 +0000
23540 23540
         this.op = op;
23541 23541
      }
23542 23542
   }
23543

  
23544
   /**
23545
    * Gets the client storage.
23546
    * 
23547
    * @return   The client storage
23548
    */
23549
   public ObjectStorage getClientStorage()
23550
   {
23551
      return getOutputManager().getDriver().getClientStorage();
23552
   }
23553

  
23554
   /**
23555
    * Retrieves the object value of the given key from the client storage.
23556
    * 
23557
    * @param    key
23558
    *           The given key
23559
    * @param    clazz
23560
    *           The java class that represents this object
23561
    * 
23562
    * @return   The object value of the given key
23563
    */
23564
   @Override
23565
   public Object getObject(String key, Class clazz)
23566
   {
23567
      return getClientStorage().getObject(key, clazz);
23568
   }
23569

  
23570
   /**
23571
    * Sets the object value of the given key for the client storage.
23572
    * 
23573
    * @param    key
23574
    *           The given key
23575
    * @param    value
23576
    *           The object value
23577
    */
23578
   @Override
23579
   public void setObject(String key, Object value)
23580
   {
23581
      getClientStorage().setObject(key, value);
23582
   }
23583

  
23584
   /**
23585
    * Retrieves the number value of the given key from the client storage.
23586
    * 
23587
    * @param    key
23588
    *           The given key
23589
    * 
23590
    * @return   The number value of the given key 
23591
    */
23592
   @Override
23593
   public Number getNumber(String key)
23594
   {
23595
      return getClientStorage().getNumber(key);
23596
   }
23597

  
23598
   /**
23599
    * Saves the number value of this key in the client storage.
23600
    * 
23601
    * @param    key
23602
    *           The given key
23603
    * @param    value
23604
    *           The value of the given key
23605
    */
23606
   @Override
23607
   public void setNumber(String key, Number value)
23608
   {
23609
      getClientStorage().setNumber(key, value);
23610
   }
23611

  
23612
   /**
23613
    * Retrieves the boolean value of the given key from the client storage.
23614
    * 
23615
    * @param    key
23616
    *           The given key
23617
    * 
23618
    * @return   The boolean value of the given key
23619
    */
23620
   @Override
23621
   public Boolean getBoolean(String key)
23622
   {
23623
      return getClientStorage().getBoolean(key);
23624
   }
23625

  
23626
   /**
23627
    * Saves the boolean value of this key in the client storage.
23628
    * 
23629
    * @param    key
23630
    *           The given key
23631
    * @param    value
23632
    *           The value of the given key
23633
    */
23634
   @Override
23635
   public void setBoolean(String key, Boolean value)
23636
   {
23637
      getClientStorage().setBoolean(key, value);
23638
   }
23639

  
23640
   /**
23641
    * Retrieves the string value of the given key from the client storage.
23642
    * 
23643
    * @param    key
23644
    *           The given key
23645
    * 
23646
    * @return   The string value of the given key
23647
    */
23648
   @Override
23649
   public String getString(String key)
23650
   {
23651
      return getClientStorage().getString(key);
23652
   }
23653

  
23654
   /**
23655
    * Saves the string value of this key in the client storage.
23656
    * 
23657
    * @param    key
23658
    *           The given key
23659
    * @param    value
23660
    *           The value of the given key
23661
    */
23662
   @Override
23663
   public void setString(String key, String value)
23664
   {
23665
      getClientStorage().setString(key, value);
23666
   }
23667
   
23668
   /**
23669
    * Deletes the given key and its value from the client storage.
23670
    * 
23671
    * @param    key
23672
    *           The given key
23673
    */
23674
   @Override
23675
   public void delete(String key)
23676
   {
23677
      getClientStorage().delete(key);
23678
   }
23679

  
23680
   /**
23681
    * Returns the client storage size.
23682
    * 
23683
    * @return   The storage size
23684
    */
23685
   @Override
23686
   public int getSize()
23687
   {
23688
      return getClientStorage().getSize();
23689
   }
23690

  
23691
   /**
23692
    * Returns the key by its index number in a sequence of all keys from the client storage.
23693
    * 
23694
    * @param    index
23695
    *           The given index number in a sequence of all storage keys.
23696
    * 
23697
    * @return   The key
23698
    */
23699
   @Override
23700
   public String getKey(int index)
23701
   {
23702
      return getClientStorage().getKey(index);
23703
   }
23543 23704
}
src/com/goldencode/p2j/ui/client/UserKeyValueStorage.java 2019-09-19 19:24:49 +0000
1
/*
2
** Module   : UserKeyValueStorage.java
3
** Abstract : Represents an abstract key and value storage that can be used to persist users
4
**            settings for storage backends with the capacity limit on the maximal value size.
5
**
6
** Copyright (c) 2019, Golden Code Development Corporation.
7
**
8
** -#- -I- --Date-- ---------------------------------Description---------------------------------
9
** 001 SBI 20190916 Created initial version.
10
*/
11

  
12
/*
13
** This program is free software: you can redistribute it and/or modify
14
** it under the terms of the GNU Affero General Public License as
15
** published by the Free Software Foundation, either version 3 of the
16
** License, or (at your option) any later version.
17
**
18
** This program is distributed in the hope that it will be useful,
19
** but WITHOUT ANY WARRANTY; without even the implied warranty of
20
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
** GNU Affero General Public License for more details.
22
**
23
** You may find a copy of the GNU Affero GPL version 3 at the following
24
** location: https://www.gnu.org/licenses/agpl-3.0.en.html
25
** 
26
** Additional terms under GNU Affero GPL version 3 section 7:
27
** 
28
**   Under Section 7 of the GNU Affero GPL version 3, the following additional
29
**   terms apply to the works covered under the License.  These additional terms
30
**   are non-permissive additional terms allowed under Section 7 of the GNU
31
**   Affero GPL version 3 and may not be removed by you.
32
** 
33
**   0. Attribution Requirement.
34
** 
35
**     You must preserve all legal notices or author attributions in the covered
36
**     work or Appropriate Legal Notices displayed by works containing the covered
37
**     work.  You may not remove from the covered work any author or developer
38
**     credit already included within the covered work.
39
** 
40
**   1. No License To Use Trademarks.
41
** 
42
**     This license does not grant any license or rights to use the trademarks
43
**     Golden Code, FWD, any Golden Code or FWD logo, or any other trademarks
44
**     of Golden Code Development Corporation. You are not authorized to use the
45
**     name Golden Code, FWD, or the names of any author or contributor, for
46
**     publicity purposes without written authorization.
47
** 
48
**   2. No Misrepresentation of Affiliation.
49
** 
50
**     You may not represent yourself as Golden Code Development Corporation or FWD.
51
** 
52
**     You may not represent yourself for publicity purposes as associated with
53
**     Golden Code Development Corporation, FWD, or any author or contributor to
54
**     the covered work, without written authorization.
55
** 
56
**   3. No Misrepresentation of Source or Origin.
57
** 
58
**     You may not represent the covered work as solely your work.  All modified
59
**     versions of the covered work must be marked in a reasonable way to make it
60
**     clear that the modified work is not originating from Golden Code Development
61
**     Corporation or FWD.  All modified versions must contain the notices of
62
**     attribution required in this license.
63
*/
64

  
65
package com.goldencode.p2j.ui.client;
66

  
67
import java.util.*;
68

  
69
import com.fasterxml.jackson.annotation.*;
70
import com.goldencode.p2j.ui.*;
71

  
72

  
73
/**
74
 * Represents an abstract key and value storage that stores its data values into chunks in order
75
 * to store large data within the same storage backend with the capacity limit on the maximal
76
 * value size. 
77
 */
78
public abstract class UserKeyValueStorage
79
implements KeyValueStorage
80
{
81

  
82
   /**
83
    * Retrieves the value of the given key from this storage.
84
    * 
85
    * @param    key
86
    *           The given key
87
    * 
88
    * @return   The number value of the given key 
89
    */
90
   @Override
91
   public Number getNumber(String key)
92
   {
93
      Chunk head = getFirstChunk(key);
94
      
95
      if (head != null && head.head != null && head.head)
96
      {
97
         return head.number;
98
      }
99
      
100
      return null;
101
   }
102

  
103
   /**
104
    * Saves the number value of this key in this storage.
105
    * 
106
    * @param    key
107
    *           The given key
108
    * @param    value
109
    *           The value of the given key
110
    */
111
   @Override
112
   public void setNumber(String key, Number value)
113
   {
114
      if (isChunkKey(key))
115
      {
116
         return;
117
      }
118
      Chunk head = new Chunk();
119
      head.number = value;
120
      head.head  = true;
121
      
122
      saveHeadChunk(key, head);
123
      flushChanges();
124
   }
125

  
126
   /**
127
    * Retrieves the boolean value of the given key from this storage.
128
    * 
129
    * @param    key
130
    *           The given key
131
    * 
132
    * @return   The boolean value of the given key
133
    */
134
   @Override
135
   public Boolean getBoolean(String key)
136
   {
137
      Chunk head = getFirstChunk(key);
138
      
139
      if (head != null && head.head != null && head.head)
140
      {
141
         return head.bool;
142
      }
143
      
144
      return null;
145
   }
146

  
147
   /**
148
    * Saves the boolean value of this key in this storage.
149
    * 
150
    * @param    key
151
    *           The given key
152
    * @param    value
153
    *           The value of the given key
154
    */
155
   @Override
156
   public void setBoolean(String key, Boolean value)
157
   {
158
      if (isChunkKey(key))
159
      {
160
         return;
161
      }
162
      Chunk head = new Chunk();
163
      head.bool = value;
164
      head.head  = true;
165
      saveHeadChunk(key, head);
166
      flushChanges();
167
   }
168

  
169
   /**
170
    * Retrieves the string value of the given key from this storage.
171
    * 
172
    * @param    key
173
    *           The given key
174
    * 
175
    * @return   The string value of the given key
176
    */
177
   @Override
178
   public String getString(String key)
179
   {
180
      Chunk head = getFirstChunk(key);
181
      
182
      if (head != null && head.head != null && head.head)
183
      {
184
         if (head.nextChunkKey != null)
185
         {
186
            return collectChunks(key, head);
187
         }
188
         else
189
         {
190
            return head.value;
191
         }
192
      }
193
      
194
      return null;
195
   }
196

  
197
   /**
198
    * Saves the string value of this key in this storage.
199
    * 
200
    * @param    key
201
    *           The given key
202
    * @param    value
203
    *           The string value of the given key
204
    */
205
   @Override
206
   public void setString(String key, String value)
207
   {
208
      if (isChunkKey(key))
209
      {
210
         return;
211
      }
212
      saveByChunks(key, String.valueOf(value));
213
   }
214

  
215
   /**
216
    * Collect stored chunks into the string value of the given key.
217
    * 
218
    * @param    key
219
    *           The given key
220
    * @param    head
221
    *           The first chunk
222
    * 
223
    * @return   The string value of the given key
224
    */
225
   public String collectChunks(String key, Chunk head)
226
   {
227
      int size = head.size;
228
      
229
      char[] value = new char[size];
230
      
231
      int destPos = 0;
232
      
233
      int len = head.value.length();
234
      head.value.getChars(0, len, value, destPos);
235
      destPos += len;
236
      
237
      String nextChunkKey = head.nextChunkKey;
238
      
239
      while(nextChunkKey != null)
240
      {
241
         Chunk chunk = getNextChunk(head, nextChunkKey);
242

  
243
         if (chunk != null)
244
         {
245
            len = chunk.value.length();
246
            chunk.value.getChars(0, len, value, destPos);
247
            destPos += len;
248
            
249
            nextChunkKey = chunk.nextChunkKey;
250
         }
251
      }
252
      
253
      return new String(value);
254
   }
255

  
256
   /**
257
    * Saves the string value of this key in this storage by splitting it into chunks in order
258
    * to fit value capacity limits of this storage backend.
259
    * 
260
    * @param    key
261
    *           The given key
262
    * @param    value
263
    *           The string value of the given key
264
    */
265
   public void saveByChunks(String key, String value)
266
   {
267
      int maximalSize = getMaximalValueSize();
268
      int size = value.length();
269
      int curr = 0;
270
      int end;
271
      
272
      if (size > maximalSize)
273
      {
274
         end = maximalSize;
275
      }
276
      else
277
      {
278
         end = size;
279
      }
280
      
281
      LinkedList<Chunk> chunks = new LinkedList<>();
282
      
283
      Chunk head = new Chunk();
284
      head.value = value.substring(curr, end);
285
      head.size  = size;
286
      head.head  = true;
287
      
288
      if (end < size)
289
      {
290
         setUniqueHeadName(head);
291
      }
292
      
293
      chunks.add(head);
294
      
295
      int chunkNumber = 0;
296
      
297
      Chunk node = head;
298
      
299
      while(end < size)
300
      {
301
         node.nextChunkKey = getNextChunkKey(head, chunkNumber++);
302
         
303
         curr = end;
304
         
305
         int restSize = size - curr;
306
         
307
         if (restSize > maximalSize)
308
         {
309
            end = curr + maximalSize;
310
         }
311
         else
312
         {
313
            end = size;
314
         }
315
         
316
         node = new Chunk();
317
         node.value = value.substring(curr, end);
318
         chunks.add(node);
319
      }
320
      
321
      saveHeadChunk(key, head);
322
      
323
      node = head;
324
      
325
      for (int i = 1; i < chunks.size(); i++)
326
      {
327
         String nextChunkKey = node.nextChunkKey;
328
         
329
         node = chunks.get(i);
330
         
331
         saveNextChunk(head, nextChunkKey, node);
332
      }
333
      
334
      flushChanges();
335
   }
336

  
337
   /**
338
    * Sets the unique name to the given head chunk.
339
    * 
340
    * @param    head
341
    *           The first chunk
342
    */
343
   public void setUniqueHeadName(Chunk head)
344
   {
345
      head.name = UUID.randomUUID().toString();
346
   }
347

  
348
   /**
349
    * Returns the next chunk key.
350
    * 
351
    * @param    head
352
    *           The first chunk of the stored data value
353
    * @param    chunkNumber
354
    *           The current chunk number
355
    * 
356
    * @return   The next chunk key;
357
    */
358
   public String getNextChunkKey(Chunk head, int chunkNumber)
359
   {
360
      StringBuilder chunkKey = new StringBuilder(64);
361
      chunkKey.append(head.name).append('-').append(chunkNumber + 1);
362
      
363
      return chunkKey.toString();
364
   }
365

  
366
   /**
367
    * Tests if the given key is used by a chunk that follows the head chunk.
368
    * 
369
    * @param    key
370
    *           The given key to test
371
    * 
372
    * @return   Returns true if this key is used by a chunk.
373
    */
374
   public abstract boolean isChunkKey(String key);
375
   
376
   /**
377
    * Stores the head chunk with the given key within this storage backend.
378
    * 
379
    * @param    key
380
    *           The given key
381
    * @param    head
382
    *           The head chunk
383
    */
384
   public abstract void saveHeadChunk(String key, Chunk head);
385

  
386
   /**
387
    * Stores the given chunk with the given key within this storage backend.
388
    * 
389
    * @param    head
390
    *           The head chunk
... This diff was truncated because it exceeds the maximum size that can be displayed.