Qore SchemaReverse Module Reference  1.1
SchemaReverse.qm.dox.h
1 // -*- mode: c++; indent-tabs-mode: nil -*-
2 // @file SchemaReverse.qm Qore user module for reverse engineering of database SQL schemas
3 
4 /* SchemaReverse.qm Copyright 2016 - 2017 Qore Technologies, s.r.o.
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FORANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23 */
24 
25 // this module requires Qore 0.8.13 or better
26 
27 // requires the SqlUtil module
28 
29 // requires the Util module
30 
31 // requires the Qorize module
32 
33 
34 
35 
123 namespace SchemaReverse {
125 
127  const TYPE_TO_CLASS = (
128  "sequence" : "SequenceReverse",
129  "table" : "TableReverse",
130  "type" : "TypeReverse",
131  "view" : "ViewReverse",
132  "mview" : "MViewReverse",
133  "function" : "FunctionReverse",
134  "procedure" : "ProcedureReverse",
135  "package" : "PackageReverse",
136  );
137 
139  const MULTI_TO_CLASS = (
140  "sequences" : "SequencesReverse",
141  "tables" : "TablesReverse",
142  "types" : "TypesReverse",
143  "views" : "ViewsReverse",
144  "mviews" : "MViewsReverse",
145  "functions" : "FunctionsReverse",
146  "procedures" : "ProceduresReverse",
147  "packages" : "PackagesReverse",
148  );
149 
151  const TEMPLATE = '
152 
153 
154 
155 const GenericOptions = (
156  "replace": True,
157  );
158 
159 const IndexOptions = (
160  "driver": (
161  "oracle": ("compute_statistics": False,),
162  ),
163  );
164 
165 const ColumnOptions = (
166  "driver": (
167  "oracle": ("character_semantics": True,),
168  ),
169  );
170 
171 const SEQUENCES = <SCHEMA_SEQUENCES>;
172 
173 const TABLES = <SCHEMA_TABLES>;
174 
175 const TYPES = <SCHEMA_TYPES>;
176 
177 const VIEWS = <SCHEMA_VIEWS>;
178 
179 const MATERIALIZED_VIEWS = <SCHEMA_MVIEWS>;
180 
181 const FUNCTIONS = <SCHEMA_FUNCTIONS>;
182 
183 const PROCEDURES = <SCHEMA_PROCEDURES>;
184 
185 const PACKAGES = <SCHEMA_PACKAGES>;
186 
187 
188 class <X_SCHEMA_NAME> : public AbstractSchema {
189  public {
190  const SchemaName = "<X_SCHEMA_NAME>";
191  const SchemaVersion = "1.0";
192  }
193 
194  constructor(AbstractDatasource ds, *string dts, *string its) ;
195 
196 
197 
198 private:
199  string getNameImpl();
200 public:
201 
202 
203 
204 private:
205  string getVersionImpl();
206 public:
207 
208 
209 
210 private:
211  *hash getTablesImpl();
212 public:
213 
214 
215 
216 private:
217  *hash getSequencesImpl();
218 public:
219 
220 
221 
222 private:
223  *hash getTypesImpl();
224 public:
225 
226 
227 
228 private:
229  *hash getViewsImpl();
230 public:
231 
232 
233 
234 private:
235  *hash getMaterializedViewsImpl();
236 public:
237 
238 
239 
240 private:
241  *hash getFunctionsImpl();
242 public:
243 
244 
245 
246 private:
247  *hash getProceduresImpl();
248 public:
249 
250 
251 
252 private:
253  *hash getPackagesImpl();
254 public:
255 
256 
257 
258 private:
259  *hash getIndexOptionsImpl();
260 public:
261 
262 
263 
264 private:
265  *hash getGenericOptionsImpl();
266 public:
267 
268 
269 
270 private:
271  *hash getColumnOptionsImpl();
272 public:
273 
274 
275 } // class <X_SCHEMA_NAME>
276 ';
277 
279 
286 
287 public:
288  private :
289  AbstractDatasource m_ds;
290  Database m_db;
291  string m_name;
292 
293 public:
294 
299  constructor(AbstractDatasource ds, string name);
300 
301 
303  AbstractDatasource datasource();
304 
305 
307  Database database();
308 
309 
311  string name();
312 
313 
315 
318  abstract any toQore();
319 
321 
323  string toString();
324 
325  }; // class AbstractReverseObject
326 
329 
330 public:
334  constructor(AbstractDatasource ds, string name)
335  : AbstractReverseObject(ds, name)
336  {
337  }
338 
339  hash toQore();
340 
341  }; // class SequenceReverse
342 
344 
347 
348 public:
352  constructor(AbstractDatasource ds, string mask = ".*")
353  : AbstractReverseObject(ds, mask)
354  {
355  }
356 
357  hash toQore();
358 
359  }; // class SequencesReverse
360 
363 
364 public:
368  constructor(AbstractDatasource ds, string name)
369  : AbstractReverseObject(ds, name)
370  {
371  }
372 
373  hash toQore();
374 
375  }; // class TypeReverse
376 
379 
380 public:
384  constructor(AbstractDatasource ds, string mask = ".*")
385  : AbstractReverseObject(ds, mask)
386  {
387  }
388 
389  hash toQore();
390 
391  }; // class TypesReverse
392 
395 
396 public:
400  constructor(AbstractDatasource ds, string name)
401  : AbstractReverseObject(ds, name)
402  {
403  }
404 
405  hash toQore();
406 
407 
408  any columnToQore(AbstractColumn c);
409 
410 
411  }; // class TableReverse
412 
415 
416 public:
420  constructor(AbstractDatasource ds, string mask = ".*")
421  : AbstractReverseObject(ds, mask)
422  {
423  }
424 
425  hash toQore();
426 
427  }; // class TablesReverse
428 
430 
435 
436 public:
437  private :
438  string m_object_type;
439  string m_function_name;
440  hash<string, bool> m_ignored_keys;
441 
442 public:
443 
450  constructor(string object_type,
451  AbstractDatasource ds,
452  string name,
453  string function_name,
454  softlist ignored_keys
455  )
456  : AbstractReverseObject(ds, name)
457  {
458  m_object_type = object_type;
459  m_function_name = function_name;
460  // make a hash of keys to ignore for fast lookups (to similate a set)
461  m_ignored_keys = map {$1: True}, ignored_keys;
462  }
463 
464  hash toQore();
465 
466  }; // class CodeBaseReverse
467 
469 
474 
475 public:
476  private :
477  string m_object_type;
478  string m_function_name;
479 
480 public:
481 
487  constructor(string object_type,
488  AbstractDatasource ds,
489  string mask,
490  string function_name,
491  )
492  : AbstractReverseObject(ds, mask)
493  {
494  if (!exists TYPE_TO_CLASS{object_type});
495 
496  m_object_type = object_type;
497  m_function_name = function_name;
498  }
499 
500  hash toQore();
501 
502  }; // class CodeBaseReverse
503 
505 class ViewReverse : public CodeBaseReverse {
506 
507 public:
511  constructor(AbstractDatasource ds, string name)
512  : CodeBaseReverse("view", ds, name, "getView", ("schema", "name", ))
513  {
514  }
515  }; // class ViewReverse
516 
519 
520 public:
524  constructor(AbstractDatasource ds, string mask = ".*")
525  : CodesBaseReverse("view", ds, mask, "viewIterator")
526  {
527  }
528  }; // class ViewsReverse
529 
532 
533 public:
537  constructor(AbstractDatasource ds, string name)
538  : CodeBaseReverse("mview", ds, name, "getMaterializedView", ("schema", "name", "type"))
539  {
540  }
541  }; // class MViewReverse
542 
545 
546 public:
550  constructor(AbstractDatasource ds, string mask = ".*")
551  : CodesBaseReverse("mview", ds, mask, "materializedViewIterator")
552  {
553  }
554  }; // class MViewsReverse
555 
558 
559 public:
563  constructor(AbstractDatasource ds, string name)
564  : AbstractReverseObject(ds, name)
565  {
566  }
567 
568  string toQore();
569 
570  }; // class FunctionReverse
571 
574 
575 public:
579  constructor(AbstractDatasource ds, string mask = ".*")
580  : CodesBaseReverse("function", ds, mask, "functionIterator")
581  {
582  }
583  }; // class FunctionsReverse
584 
587 
588 public:
592  constructor(AbstractDatasource ds, string name)
593  : AbstractReverseObject(ds, name)
594  {
595  }
596 
597  string toQore();
598 
599  }; // class ProcedureReverse
600 
603 
604 public:
608  constructor(AbstractDatasource ds, string mask = ".*")
609  : CodesBaseReverse("procedure", ds, mask, "procedureIterator")
610  {
611  }
612  }; // class ProceduresReverse
613 
616 
617 public:
621  constructor(AbstractDatasource ds, string name)
622  : AbstractReverseObject(ds, name)
623  {
624  }
625 
626  hash toQore();
627 
628  }; // class ProcedureReverse
629 
632 
633 public:
637  constructor(AbstractDatasource ds, string mask = ".*")
638  : CodesBaseReverse("package", ds, mask, "packageIterator")
639  {
640  }
641  }; // class ProceduresReverse
642 
645 
646 public:
647  private :
648  AbstractDatasource m_ds;
649  string m_class_name;
650 
651 public:
652 
656  constructor(AbstractDatasource ds, string class_name);
657 
658 
659  string toString();
660 
661 
662  }; // class SchemaReverse
663 
665 
672  AbstractReverseObject get_object(string object_type);
673 
674 
675 } // namespace SchemaReverse
Structure dump of functions.
Definition: SchemaReverse.qm.dox.h:573
constructor(AbstractDatasource ds, string name)
Definition: SchemaReverse.qm.dox.h:511
constructor(string object_type, AbstractDatasource ds, string name, string function_name, softlist ignored_keys)
Definition: SchemaReverse.qm.dox.h:450
constructor(AbstractDatasource ds, string mask=".*")
Definition: SchemaReverse.qm.dox.h:637
this namespace contains all public definitions in the SchemaReverse module
Definition: SchemaReverse.qm.dox.h:124
constructor(string object_type, AbstractDatasource ds, string mask, string function_name,)
Definition: SchemaReverse.qm.dox.h:487
constructor(AbstractDatasource ds, string mask=".*")
Definition: SchemaReverse.qm.dox.h:608
constructor(AbstractDatasource ds, string mask=".*")
Definition: SchemaReverse.qm.dox.h:524
Structure dump of a package.
Definition: SchemaReverse.qm.dox.h:615
constructor(AbstractDatasource ds, string name)
Definition: SchemaReverse.qm.dox.h:334
Structure dump of views.
Definition: SchemaReverse.qm.dox.h:518
Structure dump of a &#39;type&#39; or &#39;named type&#39;.
Definition: SchemaReverse.qm.dox.h:362
constructor(AbstractDatasource ds, string name)
Definition: SchemaReverse.qm.dox.h:368
AbstractReverseObject get_object(string object_type)
An universal wrapper to get any of SchemaReverse::AbstractReverseObject instance. ...
const True
abstract any toQore()
Dedicated functionlity to get DB object info into the internal structure is done here.
constructor(AbstractDatasource ds, string name)
Definition: SchemaReverse.qm.dox.h:621
constructor(AbstractDatasource ds, string name)
constructor(AbstractDatasource ds, string name)
Definition: SchemaReverse.qm.dox.h:400
Structure dump of a view.
Definition: SchemaReverse.qm.dox.h:505
constructor(AbstractDatasource ds, string mask=".*")
Definition: SchemaReverse.qm.dox.h:384
A basic class for all DB object classes which use SQL code as base of its content.
Definition: SchemaReverse.qm.dox.h:434
Structure dump of &#39;types&#39; or &#39;named types&#39;.
Definition: SchemaReverse.qm.dox.h:378
Structure dump of tables.
Definition: SchemaReverse.qm.dox.h:414
A basic class for all DB object classes which use SQL code as base of its content.
Definition: SchemaReverse.qm.dox.h:473
Structure dump of materialized views or snapshots.
Definition: SchemaReverse.qm.dox.h:544
Structure dump of a materialized view or snapshot.
Definition: SchemaReverse.qm.dox.h:531
Structure dump of sequences.
Definition: SchemaReverse.qm.dox.h:346
constructor(AbstractDatasource ds, string name)
Definition: SchemaReverse.qm.dox.h:592
bool exists(...)
Structure dump of a procedure.
Definition: SchemaReverse.qm.dox.h:586
constructor(AbstractDatasource ds, string name)
Definition: SchemaReverse.qm.dox.h:563
Structure dump of a function.
Definition: SchemaReverse.qm.dox.h:557
constructor(AbstractDatasource ds, string mask=".*")
Definition: SchemaReverse.qm.dox.h:352
Structure dump of packages.
Definition: SchemaReverse.qm.dox.h:631
string toString()
Make a string with Qore code from a structure prepared by AbstractReverseObject::toQore().
constructor(AbstractDatasource ds, string mask=".*")
Definition: SchemaReverse.qm.dox.h:420
const MULTI_TO_CLASS
A map translating multi DB objects name into its class.
Definition: SchemaReverse.qm.dox.h:139
Structure dump of a sequence.
Definition: SchemaReverse.qm.dox.h:328
Structure dump of a table.
Definition: SchemaReverse.qm.dox.h:394
A basic class for all SchemaReverse DB object related classes.
Definition: SchemaReverse.qm.dox.h:285
hash hash(object obj)
constructor(AbstractDatasource ds, string name)
Definition: SchemaReverse.qm.dox.h:537
constructor(AbstractDatasource ds, string mask=".*")
Definition: SchemaReverse.qm.dox.h:579
Structure dump of procedures.
Definition: SchemaReverse.qm.dox.h:602
const TYPE_TO_CLASS
A map translating simple DB object name into its class.
Definition: SchemaReverse.qm.dox.h:127
const TEMPLATE
A template string for full schema used in SchemaReverse::SchemaReverse class.
Definition: SchemaReverse.qm.dox.h:151
constructor(AbstractDatasource ds, string mask=".*")
Definition: SchemaReverse.qm.dox.h:550