Project

General

Profile

create_assign_bundle_patch.txt

Constantin Asofiei, 05/05/2020 04:18 PM

Download (7.27 KB)

 
1
Index: rules/annotations/database_general.rules
2
===================================================================
3
--- rules/annotations/database_general.rules	(revision 2287)
4
+++ rules/annotations/database_general.rules	(working copy)
5
@@ -215,6 +215,12 @@
6
    <variable name="supConnOpts"     type="java.util.Map" />
7
    <variable name="iter"            type="java.util.Iterator" />
8
    
9
+   <variable name="createAndAssign"         type="com.goldencode.ast.Aast" />
10
+   <variable name="createAndAssignBuf"      type="java.lang.String" />
11
+   <variable name="createAndAssignFields"   type="java.util.List" />
12
+   <variable name="createAndAssignLiterals" type="java.util.List" />
13
+   <variable name="idx"                     type="java.lang.Integer" />
14
+
15
    <!-- expression libraries -->
16
    <include name="common-progress" />
17
    
18
@@ -315,6 +321,10 @@
19
       
20
       <rule>connOpts = create("java.util.ArrayList")</rule>
21
       
22
+      <rule>createAndAssign = null</rule>
23
+      <rule>createAndAssignBuf = null</rule>
24
+      <rule>createAndAssignFields = null</rule>
25
+      <rule>createAndAssignLiterals = null</rule>
26
    </init-rules>
27
    
28
    <walk-rules>
29
@@ -975,10 +985,67 @@
30
          <action>copy.remove()</action>
31
       </rule>
32
       
33
+      <!-- special processing for this template, where 'tt1' is a temp-table:
34
+           create tt1. assign tt1.f1 = 1 tt1.f2 = "a" t1.f3 = no.
35
+           -->
36
+      <rule>this.type == prog.kw_create and parent.type == prog.statement
37
+         <action>ref = this.firstChild</action>
38
+         <rule>ref.type == prog.temp_table
39
+            <action>ref2 = parent.parent.getChildAt(parent.indexPos + 1)</action>
40
+            <rule>ref2.type == prog.statement and ref2.downPath("KW_ASSIGN/ASSIGN")
41
+               <action>createAndAssign = copy</action>
42
+               <action>createAndAssignBuf = ref.getAnnotation("bufname")</action>
43
+               <action>createAndAssignFields = create("java.util.ArrayList")</action>
44
+               <action>createAndAssignLiterals = create("java.util.ArrayList")</action>
45
+            </rule>
46
+         </rule>
47
+      </rule>
48
+      
49
+      <rule>createAndAssign != null              and 
50
+            evalLib("fields")                    and
51
+            upPath("STATEMENT/KW_ASSIGN/ASSIGN") and
52
+            getNoteString("bufname") == createAndAssignBuf
53
+         <action>createAndAssignFields.add(this.id)</action>
54
+         
55
+         <action>ref = this.parent.getChildAt(1)</action>
56
+         <rule>ref.type == prog.expression
57
+            <action>ref = ref.firstChild</action>
58
+            <rule>evalLib("literals", ref.type)
59
+               <!-- only assign to literal works -->
60
+               <action>createAndAssignLiterals.add(ref.id)</action>
61
+               
62
+               <action on="false">createAndAssign = null</action>
63
+               <action on="false">createAndAssignBuf = null</action>
64
+               <action on="false">createAndAssignFields = null</action>
65
+               <action on="false">createAndAssignLiterals = null</action>
66
+            </rule>
67
+         </rule>
68
+      </rule>
69
    </walk-rules>
70
    
71
    <ascent-rules>
72
-   
73
+      <rule>createAndAssign != null and relativePath("STATEMENT/KW_ASSIGN")
74
+         <!-- save as annotations all the field and literal AST IDs -->
75
+         <action>copy.parent.setHidden(true)</action>
76
+         
77
+         <action>idx = 0</action>
78
+         <while>idx &lt; createAndAssignFields.size()
79
+            <action>
80
+               createAndAssign.putAnnotation("create_and_assign_fields", 
81
+                                             #(java.lang.Long) createAndAssignFields.get(idx), 
82
+                                             -1)
83
+            </action>
84
+            <action>ref = getAst(#(java.lang.Long) createAndAssignLiterals.get(idx))</action>
85
+            <action>ref.move(createAndAssign, -1)</action>
86
+            <action>idx = idx + 1</action>
87
+         </while>
88
+         
89
+         <action>createAndAssign = null</action>
90
+         <action>createAndAssignFields = null</action>
91
+         <action>createAndAssignLiterals = null</action>
92
+         <action>createAndAssignBuf = null</action>
93
+      </rule>
94
+      
95
       <rule>(type == prog.kw_for and getNoteBoolean("quick_delete")) or type == prog.embedded_sql
96
          <action>unqualFields = false</action>
97
       </rule>
98
Index: rules/convert/database_access.rules
99
===================================================================
100
--- rules/convert/database_access.rules	(revision 2287)
101
+++ rules/convert/database_access.rules	(working copy)
102
@@ -840,7 +840,11 @@
103
               by database_references.rules), no kw_using support at this time -->
104
          <rule>type == prog.kw_create
105
             <action>methodtype = java.method_call</action>
106
-            <action>methodtxt = "create"</action>
107
+            
108
+            <rule>isNote("create_and_assign_fields")
109
+               <action>methodtxt = "createAndAssign"</action>
110
+               <action on="false">methodtxt = "create"</action>
111
+            </rule>
112
          </rule>
113
          
114
          <!-- delete language statement (record parameter will be emitted
115
@@ -2288,6 +2292,22 @@
116
    </next-child-rules>
117
    
118
    <ascent-rules>
119
+      <rule>type == prog.kw_create and isNote("create_and_assign_fields")
120
+         <!-- emit the field names followed by the literals -->
121
+         <action>idx = 0</action>
122
+         <while>idx &lt; this.annotationSize("create_and_assign_fields")
123
+            <action>
124
+               ref = getAst(#(java.lang.Long) this.getAnnotation("create_and_assign_fields", idx))
125
+            </action>
126
+            <action>
127
+               createJavaAst(java.string, 
128
+                             #(java.lang.String) ref.getAnnotation("fieldname"),
129
+                             closestPeerId,
130
+                             idx + 1)
131
+            </action>
132
+            <action>idx = idx + 1</action>
133
+         </while>
134
+      </rule>
135
       
136
       <!-- restore query name state at top level can-find -->
137
       <rule>(type == prog.func_logical and getNoteLong("oldtype") == prog.kw_can_find)
138
Index: src/com/goldencode/p2j/persist/Buffer.java
139
===================================================================
140
--- src/com/goldencode/p2j/persist/Buffer.java	(revision 2287)
141
+++ src/com/goldencode/p2j/persist/Buffer.java	(working copy)
142
@@ -519,6 +519,8 @@
143
     */
144
    public void create();
145
    
146
+   public void createAndAssign(Object... fieldsAndLiterals);
147
+   
148
    /**
149
     * Delete the record currently in the buffer, if any.
150
     *
151
Index: src/com/goldencode/p2j/persist/BufferImpl.java
152
===================================================================
153
--- src/com/goldencode/p2j/persist/BufferImpl.java	(revision 2287)
154
+++ src/com/goldencode/p2j/persist/BufferImpl.java	(working copy)
155
@@ -1244,6 +1244,24 @@
156
       buffer().create();
157
    }
158
    
159
+   @Override
160
+   public void createAndAssign(Object... fieldsAndLiterals)
161
+   {
162
+      RecordBuffer buffer = buffer();
163
+      buffer.create();
164
+      RecordBuffer.batch(() ->
165
+      {
166
+         int size = fieldsAndLiterals.length / 2;
167
+         for (int i = 0; i < size; i++)
168
+         {
169
+            String field = (String) fieldsAndLiterals[i];
170
+            Object value = fieldsAndLiterals[i + size];
171
+            
172
+            // TODO: field is DMO property... not legacy
173
+         }
174
+      });
175
+   }
176
+   
177
    /**
178
     * Delete the record currently in the buffer, if any.
179
     *