marshal2.diff
src/com/goldencode/p2j/persist/DynamicTablesHelper.java 2022-11-02 07:54:50 +0000 | ||
---|---|---|
79 | 79 |
** OM 20220914 Use MAX-WIDTH to generate custom sized varchar columns. |
80 | 80 |
** IAS 20221006 Added RAW type to the switch in the 'generateSchemaAst'. |
81 | 81 |
** IAS 20221013 Fixed setting of "serialize-name" and "serialize-hidden annotations". |
82 |
** IAS 20221014 Fixed 'column-codepage' support. |
|
82 | 83 |
*/ |
83 | 84 | |
84 | 85 |
/* |
... | ... | |
831 | 832 |
{ |
832 | 833 |
tableField.putAnnotation("col_lab", field.getColumnLabel()); |
833 | 834 |
} |
834 |
|
|
835 |
if (field.getCodePage() != null)
|
|
835 |
String cp = field.getCodePage(); |
|
836 |
if (cp != null && !cp.trim().equals(""))
|
|
836 | 837 |
{ |
837 |
tableField.putAnnotation("codePage", field.getCodePage());
|
|
838 |
tableField.putAnnotation("column-codepage", cp);
|
|
838 | 839 |
} |
839 | 840 | |
840 | 841 |
if (field.isSerializeHidden()) |
src/com/goldencode/p2j/persist/IndexDefinition.java 2022-11-04 14:40:16 +0000 | ||
---|---|---|
1 |
/* |
|
2 |
** Module : IndexDefinition.java |
|
3 |
** Abstract : A container for a table index metadata. |
|
4 |
** |
|
5 |
** Copyright (c) 2022, Golden Code Development Corporation. |
|
6 |
** |
|
7 |
** -#- -I- --Date-- ---------------------------------------Description--------------------------------------- |
|
8 |
** 001 IAS 20221104 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 | ||
65 |
package com.goldencode.p2j.persist; |
|
66 | ||
67 |
import static com.goldencode.util.NativeTypeSerializer.*; |
|
68 |
import java.io.*; |
|
69 |
import java.util.*; |
|
70 |
import java.util.stream.*; |
|
71 | ||
72 |
import com.goldencode.p2j.persist.TableMapper.*; |
|
73 |
import com.goldencode.p2j.util.*; |
|
74 | ||
75 |
/** |
|
76 |
* Container for a table index metadata. Used to send the metadata of a |
|
77 |
* DMO to a remote side, when remote appserver calls are involved. |
|
78 |
*/ |
|
79 |
public class IndexDefinition |
|
80 |
implements Externalizable |
|
81 |
{ |
|
82 |
/** The legacy name of this index. */ |
|
83 |
private String legacyName; |
|
84 |
|
|
85 |
/** |
|
86 |
* Determine if the index is a primary index: the one with the "primary" annotation or, if |
|
87 |
* there is no such one, the first in the definition order. |
|
88 |
*/ |
|
89 |
private boolean effectivePrimary; |
|
90 |
|
|
91 |
/** Determine if the index is an unique index. */ |
|
92 |
private boolean unique; |
|
93 |
|
|
94 |
/** Determine if the index is a word-index index. */ |
|
95 |
private boolean word; |
|
96 |
|
|
97 |
/** Index components (fields with sorting directions). */ |
|
98 |
private List<IndexComponentDefinition> components; |
|
99 | ||
100 |
/** |
|
101 |
* Default c'tor |
|
102 |
*/ |
|
103 |
public IndexDefinition() |
|
104 |
{ |
|
105 |
|
|
106 |
} |
|
107 | ||
108 |
/** |
|
109 |
* Constructor |
|
110 |
* @param lii |
|
111 |
* ORM index info |
|
112 |
* |
|
113 |
*/ |
|
114 |
public IndexDefinition(LegacyIndexInfo lii) |
|
115 |
{ |
|
116 |
this.legacyName = lii.getLegacyName(); |
|
117 |
this.effectivePrimary = lii.isEffectivePrimary(); |
|
118 |
this.unique = lii.isUnique(); |
|
119 |
this.word = lii.isWord(); |
|
120 |
this.components = lii.indexComponents().map(lici -> new IndexComponentDefinition(lici)). |
|
121 |
collect(Collectors.toList()); |
|
122 |
} |
|
123 |
|
|
124 |
/** |
|
125 |
* Add index to the <code>TableBuilder</code> |
|
126 |
* @param tb |
|
127 |
* <code>TableBuilder</code> instance. |
|
128 |
*/ |
|
129 |
public void addTo(TempTableBuilder tb) |
|
130 |
{ |
|
131 |
|
|
132 |
tb.addNewIndex(new character(legacyName), |
|
133 |
new logical(unique), |
|
134 |
new logical(effectivePrimary), |
|
135 |
new logical(word)); |
|
136 |
components.stream().forEach( |
|
137 |
c -> tb.addFieldToIndex(legacyName, |
|
138 |
c.fieldLegacyName, |
|
139 |
c.effectiveDescending ? "desc" : "asc")); |
|
140 |
} |
|
141 |
|
|
142 |
/** |
|
143 |
* Read the index definition from the specified input source. |
|
144 |
* |
|
145 |
* @param in |
|
146 |
* The input source from which the index definition will be read. |
|
147 |
* |
|
148 |
* @throws IOException |
|
149 |
* In case of I/O errors. |
|
150 |
* |
|
151 |
* @throws ClassNotFoundException |
|
152 |
* If the class of property could not be found/loaded. |
|
153 |
*/ |
|
154 |
@Override |
|
155 |
public void readExternal(ObjectInput in) |
|
156 |
throws IOException, |
|
157 |
ClassNotFoundException |
|
158 |
{ |
|
159 |
legacyName = readString(in); |
|
160 |
byte flags = in.readByte(); |
|
161 |
effectivePrimary = (flags & 1) != 0; |
|
162 |
unique = (flags & 2) != 0; |
|
163 |
word = (flags & 4) != 0; |
|
164 |
components = readList(in, () -> new IndexComponentDefinition()); |
|
165 |
} |
|
166 | ||
167 |
/** |
|
168 |
* Send the index definition to the specified output destination. |
|
169 |
* |
|
170 |
* @param out |
|
171 |
* The output destination to which the index definition will be sent. |
|
172 |
* |
|
173 |
* @throws IOException |
|
174 |
* In case of I/O errors. |
|
175 |
*/ |
|
176 |
@Override |
|
177 |
public void writeExternal(ObjectOutput out) |
|
178 |
throws IOException |
|
179 |
{ |
|
180 |
writeString(out, legacyName); |
|
181 |
out.writeByte((effectivePrimary ? 1 : 0) | (unique ? 2 : 0) | (word ? 1 : 0)); |
|
182 |
writeList(out, components); |
|
183 |
} |
|
184 | ||
185 |
/** A container with an index component information. */ |
|
186 |
public static class IndexComponentDefinition |
|
187 |
implements Externalizable |
|
188 |
{ |
|
189 |
/** The legacy name of the field participating in the index. */ |
|
190 |
private String fieldLegacyName; |
|
191 |
|
|
192 |
/** Determines if this component has descending sorting. */ |
|
193 |
private boolean effectiveDescending; |
|
194 |
|
|
195 |
/** |
|
196 |
* Default c'tor |
|
197 |
*/ |
|
198 |
public IndexComponentDefinition() |
|
199 |
{ |
|
200 |
|
|
201 |
} |
|
202 |
/** |
|
203 |
* Constructor |
|
204 |
* @param lici |
|
205 |
* DMO ORM index component info. |
|
206 |
*/ |
|
207 |
public IndexComponentDefinition(LegacyIndexComponentInfo lici) |
|
208 |
{ |
|
209 |
this.fieldLegacyName = lici.fieldLegacyName; |
|
210 |
this.effectiveDescending = lici.effectiveDescending; |
|
211 |
} |
|
212 |
|
|
213 | ||
214 |
|
|
215 |
/** |
|
216 |
* Read the index definition from the specified input source. |
|
217 |
* |
|
218 |
* @param in |
|
219 |
* The input source from which the index component definition will be read. |
|
220 |
* |
|
221 |
* @throws IOException |
|
222 |
* In case of I/O errors. |
|
223 |
* |
|
224 |
* @throws ClassNotFoundException |
|
225 |
* If the class of property could not be found/loaded. |
|
226 |
*/ |
|
227 |
@Override |
|
228 |
public void readExternal(ObjectInput in) |
|
229 |
throws IOException, |
|
230 |
ClassNotFoundException |
|
231 |
{ |
|
232 |
fieldLegacyName = readString(in); |
|
233 |
effectiveDescending = in.readByte() != 0; |
|
234 |
} |
|
235 | ||
236 |
/** |
|
237 |
* Send the index definition to the specified output destination. |
|
238 |
* |
|
239 |
* @param out |
|
240 |
* The output destination to which the index component definition will be sent. |
|
241 |
* |
|
242 |
* @throws IOException |
|
243 |
* In case of I/O errors. |
|
244 |
*/ |
|
245 |
@Override |
|
246 |
public void writeExternal(ObjectOutput out) |
|
247 |
throws IOException |
|
248 |
{ |
|
249 |
writeString(out, fieldLegacyName); |
|
250 |
out.writeByte(effectiveDescending ? 1 : 0); |
|
251 |
} |
|
252 |
} |
|
253 |
} |
src/com/goldencode/p2j/persist/PropertyDefinition.java 2022-11-02 10:39:37 +0000 | ||
---|---|---|
17 | 17 |
** SVL 20201030 Added format, label and columnLabel fields. |
18 | 18 |
** OM 20201120 Added SCHEMA-MARSHAL implementation. |
19 | 19 |
** CA 20220909 Always marshal the schema, otherwise the remote side will not be able to rebuild the table. |
20 |
** IAS 20221029 Added support for missed properties. |
|
21 |
** IAS 20221102 Re-worked serialization for SCHEMA-MARSHAL == NONE. |
|
20 | 22 |
*/ |
21 | 23 | |
22 | 24 |
/* |
... | ... | |
76 | 78 | |
77 | 79 |
import java.io.*; |
78 | 80 |
import java.util.*; |
81 | ||
82 |
import com.goldencode.p2j.persist.orm.*; |
|
83 |
import com.goldencode.p2j.util.*; |
|
84 | ||
79 | 85 |
import static com.goldencode.p2j.persist.AbstractTempTable.*; |
80 | 86 |
import static com.goldencode.util.NativeTypeSerializer.*; |
81 | 87 | |
... | ... | |
117 | 123 |
|
118 | 124 |
/** The column label of this property. */ |
119 | 125 |
private String columnLabel; |
120 |
|
|
126 | ||
127 |
/** HELP attribute of this field. */ |
|
128 |
private String help; |
|
129 |
|
|
130 |
/** INITIAL attribute of this field. */ |
|
131 |
private String initial; |
|
132 | ||
133 |
/** Flag indicating the field should not be included in serialized output. */ |
|
134 |
private boolean serializeHidden; |
|
135 |
|
|
136 |
/** Flag indicating the field is case-sensitive. */ |
|
137 |
private boolean caseSensitive; |
|
138 | ||
139 |
/** Node type of field in XML output. */ |
|
140 |
private String xmlNodeType; |
|
141 |
|
|
142 |
/** Code page of the CLOB field. */ |
|
143 |
private String codePage; |
|
144 | ||
121 | 145 |
/** |
122 | 146 |
* The SCHEMA-MARSHAL level for the parent temp-table. It is never {@code SM_DEFAULT} when object is to |
123 | 147 |
* be serialized. Always {@code SM_DEFAULT} for a read object. |
... | ... | |
303 | 327 |
this.label = label; |
304 | 328 |
this.columnLabel = columnLabel; |
305 | 329 |
} |
306 |
|
|
330 | ||
331 |
/** |
|
332 |
* Create a new property definition. |
|
333 |
* |
|
334 |
* @param prop |
|
335 |
* The ORM field <code>Property</code>. |
|
336 |
*/ |
|
337 |
public PropertyDefinition(Property prop) |
|
338 |
{ |
|
339 |
this.name = prop.name; |
|
340 |
verifyType(prop._fwdType); |
|
341 |
this.type = prop._fwdType; |
|
342 |
int extent = prop.index > 0 ? 0 : prop.extent; |
|
343 |
this.extent = extent == 0 ? NO_EXTENT : extent; |
|
344 |
this.legacyName = prop.legacy; |
|
345 |
this.format = prop.format; |
|
346 |
this.label = prop.label; |
|
347 |
this.columnLabel = prop.columnLabel; |
|
348 |
this.help = prop.help; |
|
349 |
this.initial = prop.initial; |
|
350 |
this.serializeHidden = prop.serializeHidden; |
|
351 |
this.caseSensitive = prop.caseSensitive; |
|
352 |
this.xmlNodeType = prop.xmlNodeType; |
|
353 |
this.codePage = prop.codePage; |
|
354 |
} |
|
307 | 355 |
/** |
308 | 356 |
* Get the type of this property. |
309 | 357 |
* |
... | ... | |
385 | 433 |
} |
386 | 434 | |
387 | 435 |
/** |
436 |
* Get help text of this property. |
|
437 |
* |
|
438 |
* @return help text of this property. |
|
439 |
*/ |
|
440 |
public String getHelp() |
|
441 |
{ |
|
442 |
return help; |
|
443 |
} |
|
444 | ||
445 |
/** |
|
446 |
* Get initial value of this property. |
|
447 |
* |
|
448 |
* @return initial value of this property. |
|
449 |
*/ |
|
450 |
public String getInitial() |
|
451 |
{ |
|
452 |
return initial; |
|
453 |
} |
|
454 | ||
455 |
/** |
|
456 |
* Get 'serialize hidden' flag of this property. |
|
457 |
* |
|
458 |
* @return 'serialize hidden' flag of this property. |
|
459 |
*/ |
|
460 |
public boolean isSerializeHidden() |
|
461 |
{ |
|
462 |
return serializeHidden; |
|
463 |
} |
|
464 | ||
465 |
/** |
|
466 |
* Get 'case-sensitive' flag of this property. |
|
467 |
* |
|
468 |
* @return 'case-sensitive' flag of this property. |
|
469 |
*/ |
|
470 |
public boolean isCaseSensitive() |
|
471 |
{ |
|
472 |
return caseSensitive; |
|
473 |
} |
|
474 | ||
475 |
|
|
476 |
/** |
|
477 |
* Get XML node type of this property. |
|
478 |
* |
|
479 |
* @return XML node type of this property. |
|
480 |
*/ |
|
481 |
public String getXmlNodeType() |
|
482 |
{ |
|
483 |
return xmlNodeType; |
|
484 |
} |
|
485 | ||
486 |
/** |
|
487 |
* Get code page of this property. |
|
488 |
* |
|
489 |
* @return code page of this property. |
|
490 |
*/ |
|
491 |
public String getCodePage() |
|
492 |
{ |
|
493 |
return codePage; |
|
494 |
} |
|
495 | ||
496 |
/** |
|
388 | 497 |
* Send the property definition to the specified output destination. |
389 | 498 |
* |
390 | 499 |
* @param out |
... | ... | |
396 | 505 |
public final void writeExternal(ObjectOutput out) |
397 | 506 |
throws IOException |
398 | 507 |
{ |
508 |
if (schemaMarshalLevel == SM_NONE) |
|
509 |
{ |
|
510 |
throw new IllegalStateException("Should not be called if schemaMarshalLevel == SM_NONE"); |
|
511 |
} |
|
399 | 512 |
boolean full = schemaMarshalLevel == SM_FULL || schemaMarshalLevel == SM_DEFAULT; |
400 |
// we can't omit the schema-related field information, as otherwise the remote side will not be able to |
|
401 |
// recreate the temp-table. |
|
402 |
boolean none = false; // schemaMarshalLevel == SM_NONE; |
|
403 | 513 |
|
404 |
writeString(out, none ? null : name); |
|
405 |
writeString(out, (type == null || none) ? null : type.getName()); |
|
406 |
out.writeInt(none ? 0 : extent); |
|
407 |
writeString(out, none ? null : legacyName); |
|
408 |
writeString(out, full ? format : null); |
|
409 |
writeString(out, full ? label : null); |
|
410 |
writeString(out, full ? columnLabel : null); |
|
514 |
writeString(out, name); |
|
515 |
writeString(out, legacyName); |
|
516 |
writeString(out, type == null ? null : type.getName()); |
|
517 |
out.writeInt(extent); |
|
518 |
writeString(out, initial); |
|
519 |
out.writeByte(serializeHidden ? 1 : 0); |
|
520 |
out.writeByte(caseSensitive ? 1 : 0); |
|
521 |
writeString(out, xmlNodeType); |
|
522 |
writeString(out, codePage); |
|
523 |
out.writeByte(full ? 1 : 0); |
|
524 |
if (!full ) |
|
525 |
{ |
|
526 |
return; |
|
527 |
} |
|
528 |
writeString(out, format); |
|
529 |
writeString(out, label); |
|
530 |
writeString(out, columnLabel); |
|
531 |
writeString(out, help); |
|
411 | 532 |
} |
412 | 533 |
|
413 | 534 |
/** |
... | ... | |
427 | 548 |
ClassNotFoundException |
428 | 549 |
{ |
429 | 550 |
name = readString(in); |
551 |
legacyName = readString(in); |
|
430 | 552 |
String tn = readString(in); |
431 | 553 |
type = (tn == null) ? null : Class.forName(tn); |
432 | 554 |
extent = in.readInt(); |
433 |
legacyName = readString(in); |
|
555 |
initial = readString(in); |
|
556 |
serializeHidden = in.readByte() == 1; |
|
557 |
caseSensitive = in.readByte() == 1; |
|
558 |
xmlNodeType = readString(in); |
|
559 |
codePage = readString(in); |
|
560 |
boolean full = in.readByte() == 1; |
|
561 |
if (!full) |
|
562 |
{ |
|
563 |
return; |
|
564 |
} |
|
434 | 565 |
format = readString(in); |
435 | 566 |
label = readString(in); |
436 | 567 |
columnLabel = readString(in); |
568 |
help = readString(in); |
|
437 | 569 |
} |
438 | 570 |
|
439 | 571 |
/** |
src/com/goldencode/p2j/persist/TableMapper.java 2022-11-04 14:15:48 +0000 | ||
---|---|---|
102 | 102 |
** CA 20220601 getIndexFieldNames must return lowercased legacy names. |
103 | 103 |
** OM 20220914 Added MAX-WIDTH support for CHARACTER fields. |
104 | 104 |
** IAS 20221006 Added 'definedFormat' and 'definedLabel'. |
105 |
** IAS 20221018 Fixed processing of 'now' and 'today' INITIAL attribute value. |
|
105 | 106 |
** CA 20221031 Added JMX instrumentation for 'mapTemporaryTable'. |
107 |
* IAS 20222204 Added 'indexComponents()' and 'getLegacyIndexes' methods. |
|
106 | 108 |
*/ |
107 | 109 | |
108 | 110 |
/* |
... | ... | |
163 | 165 |
import java.lang.reflect.*; |
164 | 166 |
import java.util.*; |
165 | 167 |
import java.util.concurrent.*; |
168 |
import java.util.stream.Stream; |
|
166 | 169 | |
167 | 170 |
import com.goldencode.p2j.persist.annotation.*; |
168 | 171 |
import com.goldencode.p2j.persist.annotation.Trigger; |
... | ... | |
788 | 791 |
} |
789 | 792 |
|
790 | 793 |
/** |
794 |
* Get stream for the indexes associated with the given temporary table. |
|
795 |
* |
|
796 |
* @param tt |
|
797 |
* Temp table object. |
|
798 |
* @return stream for the indexes associated with the given temporary table. |
|
799 |
*/ |
|
800 |
public static Stream<TableMapper.LegacyIndexInfo> getLegacyIndexes(TempTable tt) |
|
801 |
{ |
|
802 |
TempTableMapper mapper = locateTemp(tt); |
|
803 |
|
|
804 |
synchronized (mapper) |
|
805 |
{ |
|
806 |
return mapper.legacyIndexInfo(tt); |
|
807 |
} |
|
808 |
} |
|
809 |
/** |
|
791 | 810 |
* Get information about the index associated with the DMO referenced by the given buffer, |
792 | 811 |
* as a string. |
793 | 812 |
* |
... | ... | |
2663 | 2682 |
} |
2664 | 2683 |
|
2665 | 2684 |
/** |
2685 |
* Get stream for the indexes associated with the given temporary table. |
|
2686 |
* |
|
2687 |
* @param tt |
|
2688 |
* Temp table object. |
|
2689 |
* @return stream for the indexes associated with the given temporary table. |
|
2690 |
*/ |
|
2691 |
private Stream<LegacyIndexInfo> legacyIndexInfo(TempTable tt) |
|
2692 |
{ |
|
2693 |
LegacyTableInfo tableInfo = p2j.get(tt); |
|
2694 |
return new ArrayList<>(tableInfo.idx).stream(); |
|
2695 |
} |
|
2696 | ||
2697 |
/** |
|
2666 | 2698 |
* Get the legacy index name of converted index, which is defined by the specified backing |
2667 | 2699 |
* temp table. |
2668 | 2700 |
* |
... | ... | |
2882 | 2914 |
{ |
2883 | 2915 |
if ("today".equalsIgnoreCase(text)) |
2884 | 2916 |
{ |
2885 |
initialValue = date.today();
|
|
2917 |
initialValue = new character(text);
|
|
2886 | 2918 |
} |
2887 | 2919 |
else |
2888 | 2920 |
{ |
... | ... | |
2893 | 2925 |
{ |
2894 | 2926 |
if ("now".equalsIgnoreCase(text)) |
2895 | 2927 |
{ |
2896 |
initialValue = datetime.now();
|
|
2928 |
initialValue = new character(text);
|
|
2897 | 2929 |
} |
2898 | 2930 |
else if (text.toUpperCase().indexOf('T') > 0) |
2899 | 2931 |
{ |
... | ... | |
2910 | 2942 |
{ |
2911 | 2943 |
if ("now".equalsIgnoreCase(text)) |
2912 | 2944 |
{ |
2913 |
initialValue = datetimetz.now();
|
|
2945 |
initialValue = new character(text);
|
|
2914 | 2946 |
} |
2915 | 2947 |
else if (text.toUpperCase().indexOf('T') > 0) |
2916 | 2948 |
{ |
... | ... | |
3118 | 3150 |
} |
3119 | 3151 |
|
3120 | 3152 |
/** |
3153 |
* Get a stream for the index components. |
|
3154 |
* |
|
3155 |
* @return iterator for the index components. |
|
3156 |
*/ |
|
3157 |
public Stream<LegacyIndexComponentInfo> indexComponents() |
|
3158 |
{ |
|
3159 |
return Arrays.stream(components); |
|
3160 |
} |
|
3161 |
/** |
|
3121 | 3162 |
* Returns index information as a string. Format of this string is described in |
3122 | 3163 |
* {@link Buffer#indexInformation(int)} |
3123 | 3164 |
* |
... | ... | |
3216 | 3257 |
static class LegacyIndexComponentInfo |
3217 | 3258 |
{ |
3218 | 3259 |
/** The legacy name of the field participating in the index. */ |
3219 |
private final String fieldLegacyName;
|
|
3260 |
public final String fieldLegacyName;
|
|
3220 | 3261 |
|
3221 | 3262 |
/** Determines if this component has descending sorting. */ |
3222 |
private final boolean effectiveDescending;
|
|
3263 |
public final boolean effectiveDescending;
|
|
3223 | 3264 |
|
3224 | 3265 |
/** |
3225 | 3266 |
* Create a new index component information container, holding field name and sorting |
src/com/goldencode/p2j/persist/TableWrapper.java 2022-11-04 14:44:24 +0000 | ||
---|---|---|
28 | 28 |
** (so that relations, schema, etc is done on the server-side). |
29 | 29 |
** CA 20220428 Allow null peerDef at setPeerDef. |
30 | 30 |
** CA 20220602 Added basic support for transport of object instances over appserver call. |
31 |
** IAS 20221029 Added support for the SCHEMA-MARSHAL attribute. |
|
32 |
** IAS 20221102 Re-worked (de)serialization. |
|
33 |
** IAS 20221104 Added structured indexes data. |
|
31 | 34 |
*/ |
32 | 35 | |
33 | 36 |
/* |
... | ... | |
86 | 89 |
package com.goldencode.p2j.persist; |
87 | 90 | |
88 | 91 |
import static com.goldencode.util.NativeTypeSerializer.*; |
92 |
import static com.goldencode.p2j.persist.AbstractTempTable.*; |
|
93 | ||
89 | 94 |
import java.io.*; |
90 | 95 |
import java.lang.reflect.Array; |
91 | 96 |
import java.util.*; |
97 |
import java.util.stream.*; |
|
92 | 98 | |
99 |
import com.goldencode.p2j.oo.lang.*; |
|
93 | 100 |
import com.goldencode.p2j.util.*; |
101 |
import com.goldencode.util.*; |
|
94 | 102 | |
95 | 103 |
/** |
96 | 104 |
* Any {@link TableResultSet} instance will be wrapped in a {@link TableWrapper} instance before |
... | ... | |
122 | 130 | |
123 | 131 |
/** Table name. */ |
124 | 132 |
private String tableName; |
133 |
|
|
134 |
/** Flag indicating that table schema was received */ |
|
135 |
boolean receivedSchema = false; |
|
136 |
|
|
137 |
/** Table SCHEMA-MARSHAL attribute value encodes as int */ |
|
138 |
private int schemaMarshalLevel; |
|
125 | 139 | |
126 | 140 |
/** |
127 | 141 |
* Determines if this wrapper wraps data from a TABLE-HANDLE parameter. Necessary because of |
... | ... | |
159 | 173 |
*/ |
160 | 174 |
private String indexes = null; |
161 | 175 | |
176 |
/** List of indexes' descriptors */ |
|
177 |
private List<IndexDefinition> indexDefs = null; |
|
178 |
|
|
162 | 179 |
/** Flag indicating if the source is a JSON table. */ |
163 | 180 |
private boolean fromJson = false; |
164 | 181 |
|
... | ... | |
423 | 440 |
} |
424 | 441 |
|
425 | 442 |
/** |
443 |
* Get List of indexes' descriptors. |
|
444 |
* @return the List of indexes' descriptors. |
|
445 |
*/ |
|
446 |
public List<IndexDefinition> getIndexDefs() |
|
447 |
{ |
|
448 |
return indexDefs; |
|
449 |
} |
|
450 |
/** |
|
426 | 451 |
* Get the {@link #xmlns XML namespace}. |
427 | 452 |
* |
428 | 453 |
* @return See above. |
... | ... | |
682 | 707 |
return; |
683 | 708 |
} |
684 | 709 | |
685 |
writeString(out, tableName); |
|
686 |
out.writeByte(tableType); |
|
687 |
out.writeByte(numIndexes); |
|
688 |
writeString(out,indexes); |
|
689 |
writeString(out,xmlns); |
|
690 |
writeString(out,xmlPrefix); |
|
710 |
boolean writeSchema = schemaMarshalLevel != SM_NONE; |
|
711 |
out.writeByte(schemaMarshalLevel); |
|
712 |
if (writeSchema) |
|
713 |
{ |
|
714 |
writeString(out, tableName); |
|
715 |
out.writeByte(tableType); |
|
716 |
out.writeByte(numIndexes); |
|
717 |
writeString(out,indexes); |
|
718 |
writeList(out, indexDefs); |
|
719 |
writeString(out,xmlns); |
|
720 |
writeString(out,xmlPrefix); |
|
721 |
} |
|
691 | 722 | |
692 | 723 |
// write properties |
693 |
Set<Integer> blobProps = null;
|
|
694 |
Set<Integer> objectProps = null;
|
|
724 |
Set<Integer> blobProps = new HashSet<>();
|
|
725 |
Set<Integer> objectProps = new HashSet<>();
|
|
695 | 726 |
if (resultSet != null) |
696 | 727 |
{ |
697 | 728 |
int idx = 0; |
698 | 729 |
while (resultSet.hasMoreProperties()) |
699 | 730 |
{ |
700 | 731 |
PropertyDefinition property = resultSet.nextProperty(); |
701 |
out.writeByte(1); |
|
702 |
property.writeExternal(out); |
|
732 |
if (writeSchema) |
|
733 |
{ |
|
734 |
property.setMarshalLevel(schemaMarshalLevel); |
|
735 |
out.writeByte(1); |
|
736 |
property.writeExternal(out); |
|
737 |
} |
|
703 | 738 | |
704 | 739 |
if (property.getType() == blob.class) |
705 | 740 |
{ |
706 |
if (blobProps == null) |
|
707 |
{ |
|
708 |
blobProps = new HashSet<>(); |
|
709 |
} |
|
710 | 741 |
blobProps.add(idx); |
711 | 742 |
} |
712 | 743 |
else if (object.class.isAssignableFrom(property.getType())) |
713 | 744 |
{ |
714 |
if (objectProps == null) |
|
715 |
{ |
|
716 |
objectProps = new HashSet<>(); |
|
717 |
} |
|
718 | 745 |
objectProps.add(idx); |
719 | 746 |
} |
720 | 747 |
idx = idx + 1; |
721 | 748 |
} |
722 | 749 |
} |
723 |
out.writeByte(0); |
|
724 |
|
|
750 |
if (writeSchema) |
|
751 |
{ |
|
752 |
out.writeByte(0); |
|
753 |
} |
|
754 |
writeIntSet(out, blobProps); |
|
755 |
writeIntSet(out, objectProps); |
|
756 | ||
725 | 757 |
// write data |
726 | 758 |
if (resultSet != null) |
727 | 759 |
{ |
728 | 760 |
while (resultSet.hasMoreRows()) |
729 | 761 |
{ |
730 | 762 |
Object[] row = resultSet.nextRow(); |
731 |
if (blobProps != null)
|
|
763 |
if (!blobProps.isEmpty())
|
|
732 | 764 |
{ |
733 | 765 |
Object[] row2 = new Object[row.length]; |
734 | 766 |
System.arraycopy(row, 0, row2, 0, row2.length); |
... | ... | |
743 | 775 |
row = row2; |
744 | 776 |
} |
745 | 777 |
|
746 |
if (objectProps != null)
|
|
778 |
if (!objectProps.isEmpty())
|
|
747 | 779 |
{ |
748 | 780 |
Object[] row2 = new Object[row.length]; |
749 | 781 |
System.arraycopy(row, 0, row2, 0, row2.length); |
... | ... | |
751 | 783 |
{ |
752 | 784 |
if (row2[idx] instanceof object) |
753 | 785 |
{ |
754 |
row2[idx] = new LegacyObject((object) row2[idx]); |
|
786 |
row2[idx] = new LegacyObject((object<?>) row2[idx]);
|
|
755 | 787 |
} |
756 | 788 |
} |
757 | 789 |
|
... | ... | |
781 | 813 |
* @throws IOException |
782 | 814 |
* In case of I/O errors. |
783 | 815 |
* @throws ClassNotFoundException |
816 |
* If the class of property could not be found/loaded. |
|
784 | 817 |
*/ |
818 |
@Override |
|
785 | 819 |
public final void readExternal(ObjectInput in) |
786 | 820 |
throws IOException, |
787 | 821 |
ClassNotFoundException |
... | ... | |
802 | 836 |
return; |
803 | 837 |
} |
804 | 838 |
|
805 |
tableName = readString(in); |
|
806 |
tableType = in.readByte(); |
|
807 | ||
808 |
numIndexes = in.readByte(); |
|
809 |
indexes = readString(in); |
|
810 |
xmlns = readString(in); |
|
811 |
xmlPrefix = readString(in); |
|
812 |
|
|
813 |
Set<Integer> blobProps = null; |
|
814 |
Set<Integer> objectProps = null; |
|
815 |
int idx = 0; |
|
816 |
properties = new ArrayList<>(); |
|
817 |
do |
|
839 |
receivedSchema = in.readByte() != SM_NONE; |
|
840 |
if (receivedSchema) |
|
818 | 841 |
{ |
819 |
if (in.readByte() == 0) |
|
820 |
{ |
|
821 |
break; |
|
822 |
} |
|
823 |
PropertyDefinition pd = new PropertyDefinition(); |
|
824 |
pd.readExternal(in); |
|
825 |
properties.add(pd); |
|
826 |
|
|
827 |
if (pd.getType() == blob.class) |
|
828 |
{ |
|
829 |
if (blobProps == null) |
|
830 |
{ |
|
831 |
blobProps = new HashSet<>(); |
|
832 |
} |
|
833 |
blobProps.add(idx); |
|
834 |
} |
|
835 |
if (object.class.isAssignableFrom(pd.getType())) |
|
836 |
{ |
|
837 |
if (objectProps == null) |
|
838 |
{ |
|
839 |
objectProps = new HashSet<>(); |
|
840 |
} |
|
841 |
objectProps.add(idx); |
|
842 |
} |
|
843 |
idx = idx + 1; |
|
842 |
tableName = readString(in); |
|
843 |
tableType = in.readByte(); |
|
844 |
numIndexes = in.readByte(); |
|
845 |
indexes = readString(in); |
|
846 |
indexDefs = readList(in, () -> new IndexDefinition()); |
|
847 |
xmlns = readString(in); |
|
848 |
xmlPrefix = readString(in); |
|
849 |
properties = new ArrayList<>(); |
|
850 |
while (in.readByte() != 0) |
|
851 |
{ |
|
852 |
PropertyDefinition pd = new PropertyDefinition(); |
|
853 |
pd.readExternal(in); |
|
854 |
properties.add(pd); |
|
855 |
|
|
856 |
} |
|
844 | 857 |
} |
845 |
while (true); |
|
858 |
|
|
859 |
Set<Integer> blobProps = readIntSet(in); |
|
860 |
Set<Integer> objectProps = readIntSet(in); |
|
846 | 861 |
|
847 | 862 |
// read data |
848 | 863 |
rows = new ArrayList<>(); |
... | ... | |
857 | 872 |
|
858 | 873 |
Object[] row = (Object[]) next; |
859 | 874 |
rows.add(row); |
860 |
if (blobProps != null) |
|
861 |
{ |
|
862 |
for (Integer i : blobProps) |
|
863 |
{ |
|
864 |
row[i] = new blob(((MemoryBuffer) row[i]).getValue()); |
|
865 |
} |
|
866 |
} |
|
867 |
if (objectProps != null) |
|
868 |
{ |
|
869 |
for (Integer i : objectProps) |
|
870 |
{ |
|
871 |
LegacyObject ref = (LegacyObject) row[i]; |
|
872 |
ObjectVar v = new ObjectVar(ref.getType()); |
|
873 |
v.assign(ref.restore()); |
|
874 |
row[i] = v; |
|
875 |
} |
|
876 |
} |
|
875 |
blobProps.stream().forEach(i -> row[i] = new blob(((MemoryBuffer) row[i]).getValue())); |
|
876 |
objectProps.stream().forEach(i -> { |
|
877 |
LegacyObject ref = (LegacyObject) row[i]; |
|
878 |
ObjectVar<? extends _BaseObject_> v = new ObjectVar<>(ref.getType()); |
|
879 |
v.assign(ref.restore()); |
|
880 |
row[i] = v; |
|
881 |
}); |
|
877 | 882 | |
878 | 883 |
next = in.readObject(); |
879 | 884 |
rowsMeta.add((Object[]) next); |
... | ... | |
890 | 895 |
} |
891 | 896 |
} |
892 | 897 | |
898 |
/** |
|
899 |
* Check that table schema was received. |
|
900 |
* |
|
901 |
* @return <code>true</code> if table schema was received. |
|
902 |
*/ |
|
903 |
public boolean isReceivedSchema() |
|
904 |
{ |
|
905 |
return receivedSchema; |
|
906 |
} |
|
907 | ||
893 | 908 |
/** |
894 | 909 |
* Determines if this wrapper wraps data from a TABLE-HANDLE parameter. |
895 | 910 |
* |
... | ... | |
921 | 936 |
this.tableHandle = tableHandle; |
922 | 937 |
} |
923 | 938 | |
939 |
/** Get encoded table SCHEMA-MARSHAL attribute value. |
|
940 |
* |
|
941 |
* @return encoded table SCHEMA-MARSHAL attribute value. |
|
942 |
*/ |
|
943 |
public int getSchemaMarshalLevel() |
|
944 |
{ |
|
945 |
return schemaMarshalLevel; |
|
946 |
} |
|
947 | ||
948 |
/** Set encoded table SCHEMA-MARSHAL attribute value. |
|
949 |
* |
|
950 |
* @param schemaMarshalLevel |
|
951 |
* encoded table SCHEMA-MARSHAL attribute value. |
|
952 |
*/ |
|
953 |
public void setSchemaMarshalLevel(int schemaMarshalLevel) |
|
954 |
{ |
|
955 |
this.schemaMarshalLevel = schemaMarshalLevel; |
|
956 |
} |
|
957 | ||
924 | 958 |
/** |
925 | 959 |
* Initialize this wrapper with the info from the given temp-table. |
926 | 960 |
* |
... | ... | |
933 | 967 |
Buffer defBuff = (Buffer) table.defaultBufferHandle().getResource(); |
934 | 968 |
this.indexes = TableMapper.getLegacyIndexInfo(table); |
935 | 969 |
this.numIndexes = indexes.split("\\.").length; // TODO: "." or "\\." ? |
970 |
this.indexDefs = TableMapper.getLegacyIndexes(table).map(lif -> new IndexDefinition(lif)). |
|
971 |
collect(Collectors.toList()); |
|
936 | 972 |
this.xmlns = defBuff.namespaceURI().toStringMessage(); |
937 | 973 |
this.xmlPrefix = defBuff.namespacePrefix().toStringMessage(); |
938 | 974 |
} |
src/com/goldencode/p2j/persist/TempTableBuilder.java 2022-11-04 14:34:55 +0000 | ||
---|---|---|
122 | 122 |
** OM 20220914 Added MAX-WIDTH support for CHARACTER fields. |
123 | 123 |
** IAS 20221003 Fixed default value of the PRIMARY attribute |
124 | 124 |
** IAS 20221014 Added COMHANDLE to the 'datatypesMatchLen' map |
125 |
** IAS 20221029 Added support for missed properties. |
|
126 |
** IAS 20221104 Added indexes parsing for input remote table. |
|
125 | 127 |
*/ |
126 | 128 | |
127 | 129 |
/* |
... | ... | |
313 | 315 |
* The XML namespace. |
314 | 316 |
* @param xmlPrefix |
315 | 317 |
* The XML prefix. |
318 |
* @return default buffer for the table |
|
316 | 319 |
*/ |
317 | 320 |
public static BufferImpl createRemoteTable(String tableName, |
318 | 321 |
Iterator<PropertyDefinition> props, |
... | ... | |
320 | 323 |
String xmlns, |
321 | 324 |
String xmlPrefix) |
322 | 325 |
{ |
323 |
TempTableBuilder ttb = new TempTableBuilder(); |
|
324 |
props.forEachRemaining(ttb::addNewField); |
|
325 |
|
|
326 |
if (tableIndexes != null) |
|
327 |
{ |
|
328 |
String[] indexes = tableIndexes.split("\\."); |
|
329 |
for (int i = 0; i < indexes.length; i++) |
|
330 |
{ |
|
331 |
String indexDef = indexes[i]; |
|
332 |
if (indexDef.isEmpty()) |
|
333 |
{ |
|
334 |
continue; |
|
335 |
} |
|
336 |
String[] compAndName = indexDef.split(":"); |
|
337 |
String typeAndComps = compAndName[0]; |
|
338 |
String idxName = compAndName[1]; |
|
339 |
String[] comps = typeAndComps.split(","); |
|
340 |
boolean unique = (i != 0) || "1".equals(comps[0]); |
|
341 |
boolean primary = (i == 0) && ("1".equals(comps[0]) || "0".equals(comps[0])); |
|
342 |
|
|
343 |
ttb.addNewIndex(new character(idxName), |
|
344 |
new logical(unique), |
|
345 |
new logical(primary)); |
|
346 |
for (int j = (primary ? 1 : 0); j < comps.length; j++) |
|
347 |
{ |
|
348 |
ttb.addFieldToIndex(idxName, comps[j]); |
|
349 |
} |
|
350 |
} |
|
351 |
} |
|
352 |
|
|
353 |
ttb.tempTablePrepare(tableName); |
|
354 |
BufferImpl buff = (BufferImpl) ttb.defaultBufferHandle().getResource(); |
|
355 |
if (xmlns != null) |
|
356 |
{ |
|
357 |
buff.namespaceURI(xmlns); |
|
358 |
} |
|
359 |
if (xmlPrefix != null) |
|
360 |
{ |
|
361 |
buff.namespacePrefix(xmlPrefix); |
|
362 |
} |
|
363 |
|
|
364 |
return buff; |
|
326 |
return new TempTableBuilder().createTable(tableName, props, tableIndexes, xmlns, xmlPrefix); |
|
365 | 327 |
} |
366 | 328 |
|
367 | 329 |
/** |
... | ... | |
1340 | 1302 |
character label, |
1341 | 1303 |
character columnLabel) |
1342 | 1304 |
{ |
1305 |
return addNewField(name, type, extent, format, initial, label, columnLabel, |
|
1306 |
null, null, null, false, false); |
|
1307 |
} |
|
1308 |
/** |
|
1309 |
* Adds a field with the specified properties to the temp-table. |
|
1310 |
* This method is the P2J equivalent of <code>ADD-NEW-FIELD</code> method |
|
1311 |
* of Progress 4GL. |
|
1312 |
* <p> |
|
1313 |
* When a parameter is set to null, it means it was not specified by the business logic. |
|
1314 |
* |
|
1315 |
* @param name |
|
1316 |
* The name of the field to be created in the temp-table. |
|
1317 |
* @param type |
|
1318 |
* The data type of the specified field. |
|
1319 |
* @param extent |
|
1320 |
* An integer expression specifying the extent of an array. |
|
1321 |
* @param format |
|
1322 |
* The data format for the defined data type. If empty or unknown, format is |
|
1323 |
* replaced with default format. Null value means that format is not used in |
|
1324 |
* ADD-NEW-FIELD. |
|
1325 |
* @param initial |
|
1326 |
* An expression that evaluates to the initial value of the defined field. |
|
1327 |
* TODO: this method will probably be overloaded because of this. |
|
1328 |
* @param label |
|
1329 |
* The label of the defined field. If <code>null</code> or unknown the name |
|
1330 |
* parameter will be used. |
|
1331 |
* @param columnLabel |
|
1332 |
* The label of the column associated with the defined field |
|
1333 |
* @param help |
|
1334 |
* @param xmlNodeType |
|
1335 |
* @param codePage |
|
1336 |
* @param serializeHidden |
|
1337 |
* @param caseSensitive |
|
1338 |
* |
|
1339 |
* @return <code>true</code> on success. |
|
1340 |
*/ |
|
1341 |
public logical addNewField(character name, |
|
1342 |
character type, |
|
1343 |
integer extent, |
|
1344 |
character format, |
|
1345 |
BaseDataType initial, |
|
1346 |
character label, |
|
1347 |
character columnLabel, |
|
1348 |
character help, |
|
1349 |
character xmlNodeType, |
|
1350 |
character codePage, |
|
1351 |
boolean serializeHidden, |
|
1352 |
boolean caseSensitive) |
|
1353 |
{ |
|
1343 | 1354 |
addFunctionCalled = true; |
1344 | 1355 |
|
1345 | 1356 |
if (_prepared()) |
... | ... | |
1397 | 1408 |
|
1398 | 1409 |
String labelStr = label != null ? label.getValue() : null; |
1399 | 1410 |
String columnLabelStr = columnLabel != null ? columnLabel.getValue() : null; |
1411 |
String helpStr = help != null ? help.getValue() : null; |
|
1412 |
String codePageStr = codePage != null ? codePage.getValue() : null; |
|
1413 |
String xmlNodeTypeStr = xmlNodeType != null ? xmlNodeType.getValue() : null; |
|
1400 | 1414 |
|
1401 | 1415 |
// Note: case-sensitivity and CLOB code page cannot be specified using P4GL ADD-NEW-FIELD method |
1402 | 1416 |
long ext = extent == null || extent.getValue() == 1 ? 0 : extent.getValue(); |
1403 | 1417 |
P2JField field = new P2JField(fieldName, parmType, ext, formatStr, |
1404 |
initial, labelStr, columnLabelStr, false, null, null, false, null, null, |
|
1405 |
null, null, false, 0, 0); |
|
1418 |
initial, labelStr, columnLabelStr, caseSensitive, |
|
1419 |
codePageStr, helpStr, serializeHidden, null, null, |
|
1420 |
null, xmlNodeTypeStr, false, 0, 0); |
|
1406 | 1421 |
addField(field); |
1407 | 1422 |
return new logical(true); |
1408 | 1423 |
} |
... | ... | |
2727 | 2742 |
} |
2728 | 2743 |
|
2729 | 2744 |
/** |
2745 |
* Create a temp-table with the specified definition. |
|
2746 |
* |
|
2747 |
* @param tableName |
|
2748 |
* The table name. |
|
2749 |
* @param props |
|
2750 |
* The property definitions. |
|
2751 |
* @param tableIndexes |
|
2752 |
* The index definitions. |
|
2753 |
* @param xmlns |
|
2754 |
* The XML namespace. |
|
2755 |
* @param xmlPrefix |
|
2756 |
* The XML prefix. |
|
2757 |
* @return default buffer for the table |
|
2758 |
*/ |
|
2759 |
public BufferImpl createTable(String tableName, |
|
2760 |
Iterator<PropertyDefinition> props, |
|
2761 |
String tableIndexes, |
|
2762 |
String xmlns, |
|
2763 |
String xmlPrefix) |
|
2764 |
{ |
|
2765 |
return createTable(tableName, props, |
|
2766 |
() -> parseIndexString(tableIndexes), xmlns, xmlPrefix); |
|
2767 |
} |
|
2768 | ||
2769 |
/** |
|
2770 |
* Create a temp-table with the specified definition. |
|
2771 |
* |
|
2772 |
* @param tableName |
|
2773 |
* The table name. |
|
2774 |
* @param props |
|
2775 |
* The property definitions. |
|
2776 |
* @param indexProvider |
|
2777 |
* indexes' provider. |
|
2778 |
* @param xmlns |
|
2779 |
* The XML namespace. |
|
2780 |
* @param xmlPrefix |
|
2781 |
* The XML prefix. |
|
2782 |
* @return default buffer for the table |
|
2783 |
*/ |
|
2784 |
public BufferImpl createTable(String tableName, |
|
2785 |
Iterator<PropertyDefinition> props, |
|
2786 |
Runnable indexProvider, |
|
2787 |
String xmlns, |
|
2788 |
String xmlPrefix) |
|
2789 |
{ |
|
2790 |
props.forEachRemaining(this::addNewField); |
|
2791 |
|
|
2792 |
indexProvider.run(); |
|
2793 |
|
|
2794 |
tempTablePrepare(tableName); |
|
2795 |
BufferImpl buff = (BufferImpl) defaultBufferHandle.getResource(); |
|
2796 |
if (xmlns != null) |
|
2797 |
{ |
|
2798 |
buff.namespaceURI(xmlns); |
|
2799 |
} |
|
2800 |
if (xmlPrefix != null) |
|
2801 |
{ |
|
2802 |
buff.namespacePrefix(xmlPrefix); |
|
2803 |
} |
|
2804 |
|
|
2805 |
return buff; |
|
2806 |
} |
|
2807 | ||
2808 |
/** |
|
2730 | 2809 |
* Build temporary table from a table wrapper object. |
2731 | 2810 |
* |
2732 | 2811 |
* @param tableWrapper |
... | ... | |
2742 | 2821 |
{ |
2743 | 2822 |
return; |
2744 | 2823 |
} |
2745 | ||
2746 |
Iterator<PropertyDefinition> iter = tableWrapper.propertyIterator(); |
|
2747 |
while(iter.hasNext()) |
|
2748 |
{ |
|
2749 |
PropertyDefinition propertyDefinition = iter.next(); |
|
2750 |
addNewField(propertyDefinition); |
|
2751 |
} |
|
2752 |
tempTablePrepare(tableWrapper.getTableName()); |
|
2824 |
List<IndexDefinition> indexDefs = tableWrapper.getIndexDefs(); |
|
2825 |
if (indexDefs != null) |
|
2826 |
{ |
|
2827 |
createTable(tableWrapper.getTableName(), |
|
2828 |
tableWrapper.propertyIterator(), |
|
2829 |
() -> indexDefs.stream().forEach(idx -> idx.addTo(this)), |
|
2830 |
tableWrapper.getXmlns(), |
|
2831 |
tableWrapper.getXmlPrefix()); |
|
2832 |
} |
|
2833 |
else |
|
2834 |
{ |
|
2835 |
createTable(tableWrapper.getTableName(), |
|
2836 |
tableWrapper.propertyIterator(), |
|
2837 |
tableWrapper.getIndexes(), |
|
2838 |
tableWrapper.getXmlns(), |
|
2839 |
tableWrapper.getXmlPrefix()); |
|
2840 |
} |
|
2753 | 2841 |
TemporaryBuffer.insertAllRows(tableWrapper, |
2754 | 2842 |
(Temporary) defaultBufferHandle().getResource(), |
2755 | 2843 |
true, |
... | ... | |
3114 | 3202 |
new character(dataType), |
3115 | 3203 |
extent, |
3116 | 3204 |
new character(propertyDefinition.getFormat()), |
3117 |
null,
|
|
3205 |
new character(propertyDefinition.getInitial()),
|
|
3118 | 3206 |
new character(propertyDefinition.getLabel()), |
3119 |
new character(propertyDefinition.getColumnLabel())); |
|
3207 |
new character(propertyDefinition.getColumnLabel()), |
|
3208 |
new character(propertyDefinition.getHelp()), |
|
3209 |
new character(propertyDefinition.getXmlNodeType()), |
|
3210 |
new character(propertyDefinition.getCodePage()), |
|
3211 |
propertyDefinition.isSerializeHidden(), |
|
3212 |
propertyDefinition.isCaseSensitive()); |
|
3120 | 3213 |
} |
3121 | 3214 |
|
3122 | 3215 |
/** |
... | ... | |
3760 | 3853 |
} |
3761 | 3854 |
|
3762 | 3855 |
/** |
3856 |
* Add indexes based on multiIxCols string. |
|
3857 |
* |
|
3858 |
* @param tableIndexes |
|
3859 |
* multiIxCols string to be parsed. |
|
3860 |
*/ |
|
3861 |
private void parseIndexString(String tableIndexes) |
|
3862 |
{ |
|
3863 |
if (tableIndexes != null) |
|
3864 |
{ |
|
3865 |
String[] indexes = tableIndexes.split("\\."); |
|
3866 |
for (int i = 0; i < indexes.length; i++) |
|
3867 |
{ |
|
3868 |
String indexDef = indexes[i]; |
|
3869 |
if (indexDef.isEmpty()) |
|
3870 |
{ |
|
3871 |
continue; |
|
3872 |
} |
|
3873 |
String[] compAndName = indexDef.split(":"); |
|
3874 |
String typeAndComps = compAndName[0]; |
|
3875 |
String idxName = compAndName[1]; |
|
3876 |
String[] comps = typeAndComps.split(","); |
|
3877 |
boolean unique = (i != 0) || "1".equals(comps[0]); |
|
3878 |
boolean primary = (i == 0) && ("1".equals(comps[0]) || "0".equals(comps[0])); |
|
3879 |
|
|
3880 |
addNewIndex(new character(idxName), |
|
3881 |
new logical(unique), |
|
3882 |
new logical(primary)); |
|
3883 |
for (int j = (primary ? 1 : 0); j < comps.length; j++) |
|
3884 |
{ |
|
3885 |
addFieldToIndex(idxName, comps[j]); |
|
3886 |
} |
|
3887 |
} |
|
3888 |
} |
|
3889 |
} |
|
3890 | ||
3891 |
/** |
|
3763 | 3892 |
* Returns a string representation of the object. |
3764 | 3893 |
* |
3765 | 3894 |
* @return string representation of the object. |
src/com/goldencode/p2j/persist/TempTableResultSet.java 2022-11-04 08:12:06 +0000 | ||
---|---|---|
31 | 31 |
** SVL 20210701 Added clearRows. |
32 | 32 |
** CA 20221006 Do not access tableHandle() in the FWD runtime, get the TempTable instance directly. |
33 | 33 |
** Refs #6826 |
34 |
** IAS 20221029 Re-worked 'init' method. |
|
34 | 35 |
*/ |
35 | 36 | |
36 | 37 |
/* |
... | ... | |
189 | 190 |
* @param append |
190 | 191 |
* Flag indicating this table is sent in APPEND mode. |
191 | 192 |
* |
192 |
* @throws ClassNotFoundException |
|
193 |
* If the type of a property can not be resolved to a class. |
|
194 | 193 |
*/ |
195 | 194 |
public TempTableResultSet(Temporary dmo, boolean input, boolean output, boolean append) |
196 |
// throws ClassNotFoundException |
|
197 | 195 |
{ |
198 | 196 |
this(dmo, input, output, append, true); |
199 | 197 |
} |
... | ... | |
358 | 356 |
* TODO: improve this (i.e. use an open cursor or some other alternative to not read the data |
359 | 357 |
* in memory) |
360 | 358 |
* |
361 |
* @throws ClassNotFoundException |
|
362 |
* If the type of a property can not be resolved to a class. |
|
363 | 359 |
*/ |
364 | 360 |
private void init(boolean copyRows) |
365 |
// throws ClassNotFoundException |
|
366 | 361 |
{ |
367 | 362 |
TemporaryBuffer buffer = (TemporaryBuffer) ((BufferReference) dmo).buffer(); |
368 | 363 |
|
... | ... | |
387 | 382 |
{ |
388 | 383 |
dmoPropIndex.put(dmoProps[i], i); |
389 | 384 |
} |
390 |
PropertyDefinition[] props = new PropertyDefinition[dmoProps.length]; |
|
391 | 385 |
|
392 | 386 |
Iterator<Property> iter = dmoInfo.getFields(false); // skip properties that are not accessible via the DMO's API. |
393 |
while (iter.hasNext()) |
|
394 |
{ |
|
395 |
Property prop = iter.next(); |
|
396 |
// the Properties whose extent fields were denormalized are treated as simple ones |
|
397 |
int extent = prop.index > 0 ? 0 : prop.extent; |
|
398 |
if (extent == 0) |
|
399 |
{ |
|
400 |
props[dmoPropIndex.get(prop.name)] = |
|
401 |
new PropertyDefinition(prop.name, |
|
402 |
prop._fwdType, |
|
403 |
prop.legacy, |
|
404 |
prop.format, |
|
405 |
prop.label, |
|
406 |
prop.columnLabel); |
|
407 |
} |
|
408 |
else |
|
409 |
{ |
|
410 |
props[dmoPropIndex.get(prop.name)] = |
|
411 |
new PropertyDefinition(prop.name, |
|
412 |
prop._fwdType, |
|
413 |
extent, |
|
414 |
prop.legacy, |
|
415 |
prop.format, |
|
416 |
prop.label, |
|
417 |
prop.columnLabel); |
|
418 |
} |
|
419 |
} |
|
420 |
|
|
421 |
java.util.List<PropertyDefinition> lprops = new ArrayList<>(); |
|
422 |
for (int i = 0; i < props.length; i++) |
|
423 |
{ |
|
424 |
if (props[i] != null) |
|
425 |
{ |
|
426 |
lprops.add(props[i]); |
|
427 |
} |
|
428 |
} |
|
387 |
Map<Integer, PropertyDefinition> mprops = new TreeMap<>(); |
|
388 |
iter.forEachRemaining(prop -> mprops.put(dmoPropIndex.get(prop.name), new PropertyDefinition(prop))); |
|
389 |
List<PropertyDefinition> lprops = new ArrayList<>(mprops.values()); |
|
429 | 390 | |
430 | 391 |
if (copyRows) |
431 | 392 |
{ |
src/com/goldencode/p2j/persist/TemporaryBuffer.java 2022-11-04 08:10:53 +0000 | ||
---|---|---|
623 | 623 |
** they are not. |
624 | 624 |
** OM 20221027 Use Dialect API to create and drop sequences. |
625 | 625 |
** CA 20221031 Added JMX instrumentation for TABLE[-HANDLE] parameter processing. |
626 |
** IAS 20221102 Added error reporting for SCHEMA-MARSHAL == NONE. |
|
626 | 627 |
** OM 20221103 New class names for FQLPreprocessor, FQLExpression, FQLBundle, and FQLCache. |
628 |
** IAS 20221103 Fixed support for a binded table parameter. |
|
627 | 629 |
*/ |
628 | 630 | |
629 | 631 |
/* |
... | ... | |
2230 | 2232 |
src.setTable(dstDMO); |
2231 | 2233 |
} |
2232 | 2234 |
} |
2235 |
else if (bind) |
|
2236 |
{ |
|
2237 |
RecordBuffer rb = ((BufferReference) dstDMO).buffer(); |
|
2238 |
DmoMeta meta = rb.getDmoInfo(); |
|
2239 |
Iterator<Property> props = meta.getFields(false); |
|
2240 |
List<PropertyDefinition> pdl = new ArrayList<>(); |
|
2241 |
props.forEachRemaining(p -> pdl.add(new PropertyDefinition(p))); |
|
2242 |
src.getResultSet().setProperties(pdl); |
|
2243 |
} |
|
2233 | 2244 |
else |
2234 | 2245 |
{ |
2235 | 2246 |
// TODO: remote table-handle param ?? |
... | ... | |
2600 | 2611 |
else |
2601 | 2612 |
{ |
2602 | 2613 |
TableWrapper resultSet = src.getResultSet(); |
2614 |
if (!resultSet.isReceivedSchema()) |
|
2615 |
{ |
|
2616 |
ErrorManager.recordOrThrowError(12323); |
|
2617 |
} |
|
2603 | 2618 |
if (resultSet != null && resultSet.isValid() && resultSet.getTableName() != null) |
2604 | 2619 |
{ |
2605 | 2620 |
TempTableBuilder builder = new TempTableBuilder(); |
src/com/goldencode/p2j/persist/orm/DmoMeta.java 2022-10-18 08:44:59 +0000 | ||
---|---|---|
39 | 39 |
** to a better suited name. |
40 | 40 |
** OM 20220706 The objects returned by getDatabaseIndexes() carry the legacy names, too. |
41 | 41 |
** OM 20220914 Use MAX-WIDTH to generate custom sized varchar columns. |
42 |
** IAS 20221018 Fixed processing of 'now' and 'today' INITIAL attribute value. |
|
42 | 43 |
*/ |
43 | 44 | |
44 | 45 |
/* |
... | ... | |
1591 | 1592 |
{ |
1592 | 1593 |
if (bdtType == date.class) |
1593 | 1594 |
{ |
1594 |
init = "today".equalsIgnoreCase(p.initial) ? date.today() : new date(p.initial);
|
|
1595 |
init = "today".equalsIgnoreCase(p.initial) ? new character(p.initial) : new date(p.initial);
|
|
1595 | 1596 |
} |
1596 | 1597 |
else if (bdtType == datetime.class) |
1597 | 1598 |
{ |
1598 | 1599 |
if ("now".equalsIgnoreCase(p.initial)) |
1599 | 1600 |
{ |
1600 |
init = datetime.now();
|
|
1601 |
init = new character(p.initial);
|
|
1601 | 1602 |
} |
1602 | 1603 |
else if (p.initial.toUpperCase().indexOf('T') > 0) |
1603 | 1604 |
{ |
... | ... | |
1614 | 1615 |
{ |
1615 | 1616 |
if ("now".equalsIgnoreCase(p.initial)) |
1616 | 1617 |
{ |
1617 |
init = datetimetz.now();
|
|
1618 |
init = new character(p.initial);
|
|
1618 | 1619 |
} |
1619 | 1620 |
else if (p.initial.toUpperCase().indexOf('T') > 0) |
1620 | 1621 |
{ |
src/com/goldencode/p2j/persist/serial/XmlImport.java 2022-10-18 08:45:19 +0000 | ||
---|---|---|
42 | 42 |
** OM 20220914 Use MAX-WIDTH to generate custom sized varchar columns. |
43 | 43 |
** IAS 20220926 Fixed READ-XMLSCHEMA support. |
44 | 44 |
** IAS 20221014 More fixes to READ-XMLSCHEMA support. |
45 |
** IAS 20221018 Fixed processing of 'now' and 'today' INITIAL attribute value. |
|
45 | 46 |
*/ |
46 | 47 | |
47 | 48 |
/* |
... | ... | |
1866 | 1867 |
// Unable to set initial value '<value>' from XML Schema for field '<field>'. |
1867 | 1868 |
return false; |
1868 | 1869 |
} |
1869 |
|
|
1870 |
try |
|
1871 |
{ |
|
1872 |
Constructor<? extends BaseDataType> ctor = |
|
1873 |
(Constructor<? extends BaseDataType>) fwdType.getConstructor(String.class); |
|
1874 |
defVal = ctor.newInstance(defaultStrVal); |
|
1875 |
} |
|
1876 |
catch (NoSuchMethodException | IllegalAccessException | |
|
1877 |
InstantiationException | InvocationTargetException e) |
|
1878 |
{ |
|
1879 |
ErrorManager.recordOrShowError(13143, defaultStrVal, fieldName); |
|
1880 |
// Unable to set initial value '<value>' from XML Schema for field '<field>'. |
|
1881 |
return false; |
|
1870 |
if (fwdType == date.class && "today".equalsIgnoreCase(defaultStrVal)) |
|
1871 |
{ |
|
1872 |
defVal = new character("today"); |
|
1873 |
} |
|
1874 |
else if ((fwdType == datetime.class || fwdType == datetimetz.class) && |
|
1875 |
"now".equalsIgnoreCase(defaultStrVal)) |
|
1876 |
{ |
|
1877 |
defVal = new character("now"); |
|
1878 |
} |
|
1879 |
else |
|
1880 |
{ |
|
1881 |
try |
|
1882 |
{ |
|
1883 |
Constructor<? extends BaseDataType> ctor = |
|
1884 |
(Constructor<? extends BaseDataType>) fwdType.getConstructor(String.class); |
|
1885 |
defVal = ctor.newInstance(defaultStrVal); |
|
1886 |
} |
|
1887 |
catch (NoSuchMethodException | IllegalAccessException | |
|
1888 |
InstantiationException | InvocationTargetException e) |
|
1889 |
{ |
|
1890 |
ErrorManager.recordOrShowError(13143, defaultStrVal, fieldName); |
|
1891 |
// Unable to set initial value '<value>' from XML Schema for field '<field>'. |
|
1892 |
return false; |
|
1893 |
} |
|
1882 | 1894 |
} |
1883 | 1895 |
} |
1884 | 1896 |
|
src/com/goldencode/p2j/util/AppServerHelper.java 2022-11-02 07:58:35 +0000 | ||
---|---|---|
77 | 77 |
** CA 20220428 Fixed memptr, extent, table arguments when the request is remote. |
78 | 78 |
** CA 20220602 Added basic support for transport of object instances over appserver call. |
79 | 79 |
** CA 20220912 If a dataset from the call has no buffers added to it, set it to unknown. |
80 |
** IAS 20221029 Fixed TableParameter processing. |
|
80 | 81 |
*/ |
81 | 82 | |
82 | 83 |
/* |
... | ... | |
2660 | 2661 | |
2661 | 2662 |
boolean input = (mode == 'I' || mode == 'U'); |
2662 | 2663 |
boolean output = (mode == 'O' || mode == 'U'); |
2664 |
|
|
2665 |
int schemaMarshalLevel = tableParam.getSchemaMarshalLevel(); |
|
2663 | 2666 | |
2664 |
// try |