1 | <?xml version="1.0" encoding="UTF-8" ?>
|
---|
2 | <dr_custom_scripts>
|
---|
3 | <scr id="D36CE536-D575-BE5C-625F-23DE23913C6B" name="Complex rule - check comments demo" object="Table" engine="Mozilla Rhino" type="Warning" var="table" library="my first library" method="checkcomments" purpose="validation" >
|
---|
4 | <script>
|
---|
5 | <![CDATA[var ruleMessage;
|
---|
6 | var errType;
|
---|
7 | var table;
|
---|
8 | function checkcomments(object){
|
---|
9 | result = true;
|
---|
10 | ruleMessage="";
|
---|
11 | if(table.getCommentInRDBMS().equals("")){
|
---|
12 | ruleMessage="no comments in RDBMS defined";
|
---|
13 | errType="Problem:";
|
---|
14 | result = false;
|
---|
15 | }
|
---|
16 | if(table.getComment().equals("")){
|
---|
17 | if(ruleMessage.equals("")){
|
---|
18 | ruleMessage="no comments defined";
|
---|
19 | }else{
|
---|
20 | ruleMessage= ruleMessage +" , no comments defined";
|
---|
21 | }
|
---|
22 | errType="Error";
|
---|
23 | return false;
|
---|
24 | }
|
---|
25 | return result;
|
---|
26 | }]]>
|
---|
27 | </script>
|
---|
28 | </scr>
|
---|
29 | <scr id="0BAA564F-AB5F-D776-2E4F-31FDB3047F69" name="Tables to lower case - Rhino" object="relational" engine="Mozilla Rhino" type="" var="model" library="" method="" purpose="transformation" >
|
---|
30 | <script>
|
---|
31 | <![CDATA[tables = model.getTableSet().toArray();
|
---|
32 | for (var t = 0; t<tables.length;t++){
|
---|
33 | table = tables[t];
|
---|
34 | name = table.getName().toLowerCase();
|
---|
35 | table.setName(name);
|
---|
36 | columns = table.getElements();
|
---|
37 | size = table.getElementsCollection().size();
|
---|
38 | for (var i = 0; i < size; i++) {
|
---|
39 | column = columns[i];
|
---|
40 | cname = column.getName().toLowerCase();
|
---|
41 | column.setName(cname);
|
---|
42 | }
|
---|
43 | table.setDirty(true);
|
---|
44 | keys = table.getKeys();
|
---|
45 | for (var i = 0; i < keys.length; i++) {
|
---|
46 | key = keys[i];
|
---|
47 | if(!key.isFK()){
|
---|
48 | kname = key.getName().toLowerCase();
|
---|
49 | key.setName(kname);
|
---|
50 | }else{
|
---|
51 | kname = key.getFKAssociation().getName().toLowerCase();
|
---|
52 | key.getFKAssociation().setName(kname);
|
---|
53 | key.getFKAssociation().setDirty(true);
|
---|
54 | }
|
---|
55 | }
|
---|
56 | }]]>
|
---|
57 | </script>
|
---|
58 | </scr>
|
---|
59 | <scr id="B673F271-4836-DD48-15AC-487DDECCAF49" name="Tables to upper case - JRuby" object="relational" engine="JSR 223 JRuby Engine" type="" var="model" library="" method="" purpose="transformation" >
|
---|
60 | <script>
|
---|
61 | <![CDATA[tables =$model.getTableSet().toArray()
|
---|
62 | for t in 0..tables.length-1
|
---|
63 | table = tables[t]
|
---|
64 | name = table.getName().upcase
|
---|
65 | table.setName(name)
|
---|
66 | columns = table.getElements()
|
---|
67 | size = table.getElementsCollection().size()-1
|
---|
68 | for i in 0..size
|
---|
69 | column = columns[i]
|
---|
70 | cname = column.getName().upcase
|
---|
71 | column.setName(cname)
|
---|
72 | end
|
---|
73 | keys = table.getKeys()
|
---|
74 | for i in 0..keys.length-1
|
---|
75 | key = keys[i]
|
---|
76 | kname = key.getName().upcase
|
---|
77 | key.setName(kname)
|
---|
78 | end
|
---|
79 | end]]>
|
---|
80 | </script>
|
---|
81 | </scr>
|
---|
82 | <scr id="3E7C4F9E-9FCB-56C7-086F-F976F9A66384" name="Tables to upper case - JRuby - library usage" object="relational" engine="JSR 223 JRuby Engine" type="" var="model" library="Jruby lib" method="tables_up" purpose="transformation" >
|
---|
83 | <script>
|
---|
84 | <![CDATA[def tables_up(model)
|
---|
85 | tables = model.getTableSet().toArray()
|
---|
86 | for t in 0..tables.length-1
|
---|
87 | table = tables[t]
|
---|
88 | name = table.getName().upcase
|
---|
89 | table.setName(name)
|
---|
90 | columns = table.getElements()
|
---|
91 | size = table.getElementsCollection().size()-1
|
---|
92 | for i in 0..size
|
---|
93 | column = columns[i]
|
---|
94 | cname = column.getName().upcase
|
---|
95 | column.setName(cname)
|
---|
96 | end
|
---|
97 | keys = table.getKeys()
|
---|
98 | for i in 0..keys.length-1
|
---|
99 | key = keys[i]
|
---|
100 | kname = key.getName().upcase
|
---|
101 | key.setName(kname)
|
---|
102 | end
|
---|
103 | end
|
---|
104 | return true
|
---|
105 | end]]>
|
---|
106 | </script>
|
---|
107 | </scr>
|
---|
108 | <scr id="E60A5A28-BB9B-3787-10E7-259DF900B9E6" name="Table abbreviation to column" object="relational" engine="Mozilla Rhino" type="" var="model" library="" method="" purpose="transformation" >
|
---|
109 | <script>
|
---|
110 | <![CDATA[tables = model.getTableSet().toArray();
|
---|
111 | for (var t = 0; t<tables.length;t++){
|
---|
112 | table = tables[t];
|
---|
113 | abbr = table.getAbbreviation()+"_";
|
---|
114 | if(!"_".equals(abbr)){
|
---|
115 | columns = table.getElements();
|
---|
116 | for (var i = 0; i < columns.length; i++) {
|
---|
117 | column = columns[i];
|
---|
118 | cname = column.getName();
|
---|
119 | if(!cname.startsWith(abbr)){
|
---|
120 | column.setName(abbr+cname);
|
---|
121 | }
|
---|
122 | }
|
---|
123 | }
|
---|
124 | }]]>
|
---|
125 | </script>
|
---|
126 | </scr>
|
---|
127 | <scr id="9BE4E26C-36D8-A92C-ADEA-F183327DC239" name="Remove Table abbr from column" object="relational" engine="Mozilla Rhino" type="" var="model" library="" method="" purpose="transformation" >
|
---|
128 | <script>
|
---|
129 | <![CDATA[tables = model.getTableSet().toArray();
|
---|
130 | for (var t = 0; t<tables.length;t++){
|
---|
131 | table = tables[t];
|
---|
132 | abbr = table.getAbbreviation()+"_";
|
---|
133 | count = table.getAbbreviation().length()+1;
|
---|
134 | if(!"_".equals(abbr)){
|
---|
135 | columns = table.getElements();
|
---|
136 | for (var i = 0; i < columns.length; i++) {
|
---|
137 | column = columns[i];
|
---|
138 | cname = column.getName();
|
---|
139 | if(cname.startsWith(abbr)){
|
---|
140 | column.setName(cname.substring(count));
|
---|
141 | table.setDirty(true);
|
---|
142 | }
|
---|
143 | }
|
---|
144 | }
|
---|
145 | }]]>
|
---|
146 | </script>
|
---|
147 | </scr>
|
---|
148 | <scr id="23BE8827-D732-72B0-C6E6-266EFE116EDD" name="Table template" object="relational" engine="Mozilla Rhino" type="" var="model" library="" method="" purpose="transformation" >
|
---|
149 | <script>
|
---|
150 | <![CDATA[var t_name = "table_template";
|
---|
151 | var p_name = "ctemplateID";
|
---|
152 | template = model.getTableSet().getByName(t_name);
|
---|
153 | if(template!=null){
|
---|
154 | tcolumns = template.getElements();
|
---|
155 | tables = model.getTableSet().toArray();
|
---|
156 | for (var t = 0; t<tables.length;t++){
|
---|
157 | table = tables[t];
|
---|
158 | // compare name ignoring the case
|
---|
159 | if(!table.getName().equalsIgnoreCase(t_name)){
|
---|
160 | for (var i = 0; i < tcolumns.length; i++) {
|
---|
161 | column = tcolumns[i];
|
---|
162 | col = table.getColumnByProperty(p_name,column.getObjectID());
|
---|
163 | if(col==null){
|
---|
164 | col = table.createColumn();
|
---|
165 | }
|
---|
166 | column.copy(col);
|
---|
167 | //set property after copy otherwise it'll be cleared
|
---|
168 | col.setProperty(p_name,column.getObjectID());
|
---|
169 | table.setDirty(true);
|
---|
170 | }
|
---|
171 | }
|
---|
172 | }
|
---|
173 | }]]>
|
---|
174 | </script>
|
---|
175 | </scr>
|
---|
176 | <scr id="5A8A151A-13FD-4B0A-E233-E3C5126BA02C" name="Tables to upper case - Rhino" object="relational" engine="Mozilla Rhino" type="" var="model" library="" method="" purpose="transformation" >
|
---|
177 | <script>
|
---|
178 | <![CDATA[tables = model.getTableSet().toArray();
|
---|
179 | for (var t = 0; t<tables.length;t++){
|
---|
180 | table = tables[t];
|
---|
181 | name = table.getName().toUpperCase();
|
---|
182 | table.setName(name);
|
---|
183 | columns = table.getElements();
|
---|
184 | size = table.getElementsCollection().size();
|
---|
185 | for (var i = 0; i < size; i++) {
|
---|
186 | column = columns[i];
|
---|
187 | cname = column.getName().toUpperCase();
|
---|
188 | column.setName(cname);
|
---|
189 | }
|
---|
190 | table.setDirty(true);
|
---|
191 | keys = table.getKeys();
|
---|
192 | for (var i = 0; i < keys.length; i++) {
|
---|
193 | key = keys[i];
|
---|
194 | if(!key.isFK()){
|
---|
195 | kname = key.getName().toUpperCase();
|
---|
196 | key.setName(kname);
|
---|
197 | }else{
|
---|
198 | kname = key.getFKAssociation().getName().toUpperCase();
|
---|
199 | key.getFKAssociation().setName(kname);
|
---|
200 | key.getFKAssociation().setDirty(true);
|
---|
201 | }
|
---|
202 | }
|
---|
203 | }]]>
|
---|
204 | </script>
|
---|
205 | </scr>
|
---|
206 | <scr id="0528C35C-F29B-E7BB-57AC-37BA2780A98D" name="Table template - uses column name" object="relational" engine="Mozilla Rhino" type="" var="model" library="" method="" purpose="transformation" >
|
---|
207 | <script>
|
---|
208 | <![CDATA[// version without usage of dynamic properties, columns are found by column name
|
---|
209 | // this allow reuse of already existing columns
|
---|
210 | var t_name = "table_template";
|
---|
211 | template = model.getTableSet().getByName(t_name);
|
---|
212 | if(template!=null){
|
---|
213 | tcolumns = template.getElements();
|
---|
214 | tables = model.getTableSet().toArray();
|
---|
215 | for (var t = 0; t<tables.length;t++){
|
---|
216 | table = tables[t];
|
---|
217 | // compare name ignoring the case
|
---|
218 | if(!table.getName().equalsIgnoreCase(t_name)){
|
---|
219 | for (var i = 0; i < tcolumns.length; i++) {
|
---|
220 | column = tcolumns[i];
|
---|
221 | col = table.getElementByName(column.getName());
|
---|
222 | if(col==null){
|
---|
223 | col = table.createColumn();
|
---|
224 | }
|
---|
225 | column.copy(col);
|
---|
226 | table.setDirty(true);
|
---|
227 | }
|
---|
228 | }
|
---|
229 | }
|
---|
230 | }]]>
|
---|
231 | </script>
|
---|
232 | </scr>
|
---|
233 | <scr id="6279C414-90DD-A52B-4CEB-8D49AB31DC10" name="Copy Comments to Comments in RDBMS" object="relational" engine="Mozilla Rhino" type="" var="model" library="" method="" purpose="transformation" >
|
---|
234 | <script>
|
---|
235 | <![CDATA[max_length = 4000;
|
---|
236 | function copyComments(object){
|
---|
237 | if(object.getCommentInRDBMS().equals("")){
|
---|
238 | if(!object.getComment().equals("")){
|
---|
239 | if(object.getComment().length()>max_length){
|
---|
240 | object.setCommentInRDBMS(object.getComment().substring(0, max_length));
|
---|
241 | }else{
|
---|
242 | object.setCommentInRDBMS(object.getComment());
|
---|
243 | }
|
---|
244 | object.setDirty(true);
|
---|
245 | }
|
---|
246 | }
|
---|
247 | }
|
---|
248 |
|
---|
249 | tables = model.getTableSet().toArray();
|
---|
250 | for (var t = 0; t<tables.length;t++){
|
---|
251 | table = tables[t]
|
---|
252 | copyComments(table);
|
---|
253 | columns = table.getElements();
|
---|
254 | size = table.getElementsCollection().size();
|
---|
255 | for (var i = 0; i < columns.length; i++) {
|
---|
256 | column = columns[i];
|
---|
257 | copyComments(column);
|
---|
258 | }
|
---|
259 | keys = table.getKeys();
|
---|
260 | for (var i = 0; i < keys.length; i++) {
|
---|
261 | key = keys[i];
|
---|
262 | if(!key.isFK()){
|
---|
263 | copyComments(key);
|
---|
264 | }else{
|
---|
265 | copyComments(key.getFKAssociation());
|
---|
266 | }
|
---|
267 | }
|
---|
268 | }]]>
|
---|
269 | </script>
|
---|
270 | </scr>
|
---|
271 | <scr id="7C4EDFC0-26EA-859C-DBD9-AC9345DEAF98" name="Create index on FK" object="relational" engine="Mozilla Rhino" type="" var="model" library="" method="" purpose="transformation" >
|
---|
272 | <script>
|
---|
273 | <![CDATA[function getIndex(tab,cols){
|
---|
274 | keys = tab.getKeys();
|
---|
275 | for (var i = 0; i < keys.length; i++) {
|
---|
276 | index = keys[i];
|
---|
277 | if(!(index.isPK() || index.isUnique()) && !index.isFK() && index.isIndexForColumns(cols)){
|
---|
278 | return index
|
---|
279 | }
|
---|
280 | }
|
---|
281 | return null;
|
---|
282 | }
|
---|
283 |
|
---|
284 | tables = model.getTableSet().toArray();
|
---|
285 | for (var t = 0; t<tables.length;t++){
|
---|
286 | table = tables[t];
|
---|
287 | indexes = table.getKeys();
|
---|
288 | for (var i = 0; i < indexes.length; i++) {
|
---|
289 | index = indexes[i];
|
---|
290 | if(index.isFK()){
|
---|
291 | columns = index.getColumns();
|
---|
292 | if(columns.length>0){
|
---|
293 | newIndex = getIndex(table,columns);
|
---|
294 | if(newIndex==null){
|
---|
295 | newIndex = table.createIndex()
|
---|
296 | table.setDirty(true);
|
---|
297 | for (var k = 0; k < columns.length; k++){
|
---|
298 | newIndex.add(columns[k]);
|
---|
299 | }
|
---|
300 | }
|
---|
301 | }
|
---|
302 | }
|
---|
303 | }
|
---|
304 | }]]>
|
---|
305 | </script>
|
---|
306 | </scr>
|
---|
307 |
|
---|
308 | <lib id="B310E434-78AE-6AED-EA94-6808B0262483" name="my first library" engine="Mozilla Rhino" methods="checkcomments" >
|
---|
309 | <script>
|
---|
310 | <![CDATA[var ruleMessage;
|
---|
311 | var errType;
|
---|
312 | var table;
|
---|
313 | function checkcomments(object){
|
---|
314 | result = true;
|
---|
315 | ruleMessage="";
|
---|
316 | if(table.getCommentInRDBMS().equals("")){
|
---|
317 | ruleMessage="no comments in RDBMS defined";
|
---|
318 | errType="Problem:";
|
---|
319 | result = false;
|
---|
320 | }
|
---|
321 | if(table.getComment().equals("")){
|
---|
322 | if(ruleMessage.equals("")){
|
---|
323 | ruleMessage="no comments defined";
|
---|
324 | }else{
|
---|
325 | ruleMessage= ruleMessage +" , no comments defined";
|
---|
326 | }
|
---|
327 | errType="Error";
|
---|
328 | return false;
|
---|
329 | }
|
---|
330 | return result;
|
---|
331 | }]]>
|
---|
332 | </script>
|
---|
333 | </lib>
|
---|
334 | <lib id="2518F33A-DE50-9E1D-7216-DD2A0FD6B84C" name="Jruby lib" engine="JRuby Engine" methods="tables_up" >
|
---|
335 | <script>
|
---|
336 | <![CDATA[def tables_up(model)
|
---|
337 | tables = model.getTableSet().toArray()
|
---|
338 | for t in 0..tables.length-1
|
---|
339 | table = tables[t]
|
---|
340 | name = table.getName().upcase
|
---|
341 | table.setName(name)
|
---|
342 | columns = table.getElements()
|
---|
343 | size = table.getElementsCollection().size()-1
|
---|
344 | for i in 0..size
|
---|
345 | column = columns[i]
|
---|
346 | cname = column.getName().upcase
|
---|
347 | column.setName(cname)
|
---|
348 | end
|
---|
349 | keys = table.getKeys()
|
---|
350 | for i in 0..keys.length-1
|
---|
351 | key = keys[i]
|
---|
352 | kname = key.getName().upcase
|
---|
353 | key.setName(kname)
|
---|
354 | end
|
---|
355 | end
|
---|
356 | return true
|
---|
357 | end]]>
|
---|
358 | </script>
|
---|
359 | </lib>
|
---|
360 | </dr_custom_scripts>
|
---|