Libraryless. Click here for Pure Java version (17417L/106K).
1 | // returns true if change |
2 | sbool _csetField(Concept c, S field, O value) ctex { |
3 | Field f = setOpt_findField(c.getClass(), field); |
4 | //print("cset: " + c.id + " " + field + " " + struct(value) + " " + f); |
5 | if (value instanceof RC) value = c._concepts.getConcept((RC) value); |
6 | value = deref(value); |
7 | |
8 | if (value instanceof S && l((S) value) >= concepts_internStringsLongerThan) value = intern((S) value); |
9 | |
10 | if (f == null) { |
11 | // dynamic field (undeclared) |
12 | |
13 | assertIdentifier(field); |
14 | O oldVal = mapGet(c.fieldValues, field); |
15 | |
16 | if (value cast Concept) { |
17 | if (oldVal instanceof Concept.Ref) |
18 | // change existing reference |
19 | ret ((Concept.Ref) oldVal).set(value); |
20 | else { |
21 | // overwrite non-reference value if any, |
22 | // create new reference |
23 | dynamicObject_setRawFieldValue(c, field, c.new Ref(value)); |
24 | c.change(); true; |
25 | } |
26 | } else { |
27 | // value is not a concept |
28 | |
29 | // if it was a reference, cleanly delete it |
30 | if (oldVal cast Concept.Ref) oldVal.unindexAndDrop(); |
31 | |
32 | if (eq(oldVal, value)) false; |
33 | |
34 | if (isConceptList(value) && nempty(value/L)) { |
35 | // TODO: clean-up etc |
36 | dynamicObject_setRawFieldValue(c, field, c.new RefL(value/L)); |
37 | c.change(); true; |
38 | } |
39 | |
40 | if (value == null) { |
41 | // delete field |
42 | dynamicObject_dropRawField(c, field); |
43 | } else { |
44 | // update or create field |
45 | if (!isPersistable(value)) |
46 | fail("Can't persist: " + c + "." + field + " = "+ value); |
47 | |
48 | dynamicObject_setRawFieldValue(c, field, value); |
49 | } |
50 | c.change(); true; |
51 | } |
52 | } else if (isSubtypeOf(f.getType(), Concept.Ref.class)) { |
53 | // Concept.Ref magic |
54 | ((Concept.Ref) f.get(c)).set((Concept) derefRef(value)); |
55 | c.change(); true; |
56 | } else if (isSubtypeOf(f.getType(), Concept.RefL.class)) { |
57 | // Concept.RefL magic |
58 | ((Concept.RefL) f.get(c)).replaceWithList(lmap derefRef((L) value)); |
59 | c.change(); true; |
60 | } else { |
61 | O old = f.get(c); |
62 | if (neq(value, old)) { |
63 | bool isTransient = isTransient(f); |
64 | if (!isTransient && !isPersistable(value)) |
65 | fail("Can't persist: " + c + "." + field + " = "+ value); |
66 | f.set(c, value); |
67 | if (!isTransient) c.change(); |
68 | true; |
69 | } |
70 | } |
71 | false; |
72 | } |
download show line numbers debug dex old transpilations
Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1026007 |
Snippet name: | _csetField - used by cset [LIVE] |
Eternal ID of this version: | #1026007/20 |
Text MD5: | 41a999cd7a3d7352d971cd6d98d73b6a |
Transpilation MD5: | e2213703e048d210ca9a41207fbdb50c |
Author: | stefan |
Category: | javax / concepts |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-08-30 18:52:39 |
Source code size: | 2377 bytes / 72 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 432 / 636 |
Version history: | 19 change(s) |
Referenced in: | [show references] |