Qore Schema Module Reference: doxygen/qlib/Schema.qm.dox.h Source File

Qore Schema Module Reference 1.0

- Main Page
- Related Pages
- Namespaces
- Classes

All Classes Namespaces Functions Variables Groups Pages
Schema.qm.dox.h
1 // -*- mode: c++; indent-tabs-mode: nil -*-
2 // @file Schema.qm Qore user module for working with SQL data
3
4 /* Schema.qm Copyright 2014 Qore Technologies, sro
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 FOR ANY 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.11 or better
26
27 // requires the SqlUtil module
28
29 // requires the Util module
30
31 // don't use "$" signs for variables and class members, assume local variable scope
32
33 // require type definitions everywhere
34
35 // enable all warnings
36
37
57 namespace Schema {
60 class SchemaCallbackHelper {
61
62 public:
63 public :
64 AbstractSchema schema;
65 int verbose;
66 int change_count = 0;
67 int dot_count = 0;
68 int error_count = 0;
69 list sql_cache = ();
70
71 public:
72
74
77 constructor(AbstractSchema sc, int v = 0);
78
79
81 infoCallback(string str, int ac, *string type, *string name, *string table, *string new_name, *string info);
82
83
85 sqlCallback(string str);
86
87
89 nothing sqlForceCallback(string str);
90
91
93 hash getCallbacks(bool force = False);
94
95 };
96
98
130 class AbstractSchema {
131
132 public:
133 private :
135 string name;
137 string version;
138
140 hash schema;
141
143 *hash index_options;
145 *hash creation_options;
147 *hash column_options;
149 *hash all_options;
150
152 AbstractDatasource ds;
154 string drv;
155
157 SqlUtil::Database db;
158
160 hash pure_callback_opts;
162 hash callback_opts;
163
165 code info_callback;
166
168 *string data_ts;
169
171 *string index_ts;
172
173 public:
174
176
180 constructor(AbstractDatasource n_ds, *string dts, *string its);
181
182
184 string getName();
185
186
188 string getVersion();
189
190
192 AbstractDatasource getDatasource();
193
194
196 AbstractDatabase getDatabase();
197
198
200
202 logpf(string fmt);
203
204
206
208 log(string fmt);
209
210
212
214 logProgress(string str);
215
216
218
225 int align(bool force = False, int verbose = 0);
226
227
229 drop(bool force = False, int verbose = 0);
230
231
233
237 *hash getIndexOptions();
238
239
241
245 *hash getCreationOptions();
246
247
249
252 *hash getColumnOptions();
253
254
256
259 *hash getTables();
260
261
263
266 *hash getSequences();
267
268
270
273 *hash getTypes();
274
275
277
280 *hash getFunctions();
281
282
284
287 *hash getProcedures();
288
289
291
294 *hash getPackages();
295
296
298
301 *hash getMaterializedViews();
302
303
305
308 *hash getStrictReferenceDataHash();
309
310
312
315 *hash getReferenceDataHash();
316
317
319
322 *hash getCreateOnlyReferenceData();
323
324
326
329 *hash getInsertOnlyReferenceData();
330
331
333 private abstract string getNameImpl();
334
336 private abstract string getVersionImpl();
337
339
341 private *hash getIndexOptionsImpl();
342
343
345
347 private *hash getColumnOptionsImpl();
348
349
351
353 private *hash getGenericOptionsImpl();
354
355
357
359 private *hash getTablesImpl();
360
361
363
365 private *hash getSequencesImpl();
366
367
369
371 private *hash getTypesImpl();
372
373
375
377 private *hash getFunctionsImpl();
378
379
381
383 private *hash getProceduresImpl();
384
385
387
389 private *hash getPackagesImpl();
390
391
393
395 private *hash getMaterializedViewsImpl();
396
397
399
401 private *hash getStrictReferenceDataHashImpl();
402
403
405
407 private *hash getReferenceDataHashImpl();
408
409
411
413 private *hash getCreateOnlyReferenceDataImpl();
414
415
417
419 private *hash getInsertOnlyReferenceDataImpl();
420
421
423
426 private bool checkExistence();
427
428
430 private bool checkFirstTimeInstall();
431
432
434 private bool checkDropSchema(bool force);
435
436
438 private bool checkUpdateSchema(bool force, reference initial_schema_info);
439
440
442 private doPostAlignment(Tables table_cache, bool first_time_install, *hash initial_schema_info);
443
444
446 private int getUpsertStrategy(bool first_time_install);
447
448
450 private postDataActions(bool first_time_install);
451
452
454 private doTable(AbstractTable table, list rows, int upsert_strategy, bool delete_others, int verbose, reference sh);
455
456
458
460 static list getRows(*softlist l);
461
463 static hash combineOptions(*hash h);
464 };
465
467
476 class AbstractVersionedSchema : public AbstractSchema {
477
478 public:
479 private :
481 string version_table;
483 string version_column;
485 hash version_where;
486
487 public:
488
490
492 constructor(AbstractDatasource ds, *string dts, *string its);
493
494
496 private *softstring getSchemaVersion();
497
498
500 private bool checkDropSchema(bool force);
501
502
504 private bool checkUpdateSchema(bool force, reference initial_schema_info);
505
506
508 private bool checkUpgrade(string current_version);
509
510
512 private bool checkDowngrade(string current_version);
513
514
516
519 private string getVersionTable();
520
521
523
526 private string getVersionColumn();
527
528
530
533 private hash getVersionWhere();
534
535
537 private abstract string getVersionTableImpl();
538
540 private abstract string getVersionColumnImpl();
541
543 private abstract hash getVersionWhereImpl();
544 };
545 };
Schema::AbstractSchema::getDatabase
AbstractDatabase getDatabase()
returns the AbstractDatabase object used for the schema
Schema::AbstractVersionedSchema::getVersionColumn
private string getVersionColumn()
returns the name of the column holding the schema version string by calling getVersionColumnImpl() ...
Schema::AbstractSchema::getTablesImpl
private *hash getTablesImpl()
returns table definitions
Schema::AbstractSchema::logProgress
logProgress(string str)
outputs a log message without any newline
Schema::AbstractSchema::getIndexOptions
*hash getIndexOptions()
returns index options
Schema::AbstractVersionedSchema::checkUpgrade
private bool checkUpgrade(string current_version)
this method is called if the current schema version is less than the target version; returns True if ...
Schema::AbstractSchema::getProcedures
*hash getProcedures()
returns stored procedure definitions
Schema::AbstractSchema::getStrictReferenceDataHashImpl
private *hash getStrictReferenceDataHashImpl()
returns a hash of "strict reference data", describing the only data that can appear in the target tab...
Schema::AbstractSchema::getGenericOptionsImpl
private *hash getGenericOptionsImpl()
returns schema creation options
Schema::AbstractVersionedSchema::getVersionColumnImpl
abstract private string getVersionColumnImpl()
returns the name of the column holding the schema version string
Schema::SchemaCallbackHelper::getCallbacks
hash getCallbacks(bool force=False)
returns a callback option hash usable with SqlUtil schema operations
Schema::SchemaCallbackHelper::infoCallback
infoCallback(string str, int ac, *string type, *string name, *string table, *string new_name, *string info)
this is the informational callback method for schema operations
Schema::AbstractSchema::getReferenceDataHashImpl
private *hash getReferenceDataHashImpl()
returns a hash of "normal reference data", describing data that must appear in the target table...
Schema::AbstractSchema::ds
AbstractDatasource ds
the datasource for the schema
Definition: Schema.qm.dox.h:152
Schema::AbstractSchema::checkUpdateSchema
private bool checkUpdateSchema(bool force, reference initial_schema_info)
this method returns True if the schema can be updated
Schema::AbstractSchema::name
string name
the name of the schema
Definition: Schema.qm.dox.h:135
Schema::AbstractSchema::getSequences
*hash getSequences()
returns sequence definitions
Schema::AbstractVersionedSchema::getVersionWhere
private hash getVersionWhere()
returns the where clause hash defining the row where the schema version string is located by calling ...
Schema::AbstractSchema::doPostAlignment
private doPostAlignment(Tables table_cache, bool first_time_install, *hash initial_schema_info)
this method is called after schema structural alignment has been executed but before schema reference...
Schema::AbstractSchema::getVersion
string getVersion()
returns the version of the schema
Schema::AbstractSchema::getTables
*hash getTables()
returns table definitions
Schema::AbstractSchema::column_options
*hash column_options
column options, as provided by getColumnOptions()
Definition: Schema.qm.dox.h:147
Schema::AbstractSchema::checkFirstTimeInstall
private bool checkFirstTimeInstall()
returns True if checkExistence() returns False
Schema::AbstractSchema::getReferenceDataHash
*hash getReferenceDataHash()
returns a hash of "normal reference data", describing data that must appear in the target table...
Schema::AbstractSchema::getColumnOptions
*hash getColumnOptions()
returns column options
Schema::AbstractSchema::callback_opts
hash callback_opts
callback options plus all options
Definition: Schema.qm.dox.h:162
Schema::AbstractVersionedSchema::getVersionWhereImpl
abstract private hash getVersionWhereImpl()
returns the where clause hash defining the row where the schema version string is located ...
Schema::AbstractSchema::align
int align(bool force=False, int verbose=0)
executes a schema alignment action on the database with the current schema template ...
SqlUtil::Database
Schema::AbstractSchema::getFunctions
*hash getFunctions()
returns function definitions
False
const False
list
list list(...)
Schema::AbstractSchema::index_options
*hash index_options
index options, as provided by getIndexOptions()
Definition: Schema.qm.dox.h:143
Schema::SchemaCallbackHelper::sqlCallback
sqlCallback(string str)
this is the SQL callback method for schema operations
Schema::AbstractVersionedSchema::version_column
string version_column
the name of the column containing the version string
Definition: Schema.qm.dox.h:483
Schema::AbstractSchema::getColumnOptionsImpl
private *hash getColumnOptionsImpl()
returns column options
Schema::AbstractSchema::drop
drop(bool force=False, int verbose=0)
executes a schema drop operation in the database
Schema::AbstractSchema::data_ts
*string data_ts
explicit data tablespace name
Definition: Schema.qm.dox.h:168
Schema::AbstractSchema::getMaterializedViews
*hash getMaterializedViews()
returns materialized view definitions
Schema::AbstractSchema::constructor
constructor(AbstractDatasource n_ds, *string dts, *string its)
creates the object from the arguments
Schema::SchemaCallbackHelper::constructor
constructor(AbstractSchema sc, int v=0)
creates the callback object from the given arguments
Schema::AbstractSchema::log
log(string fmt)
outputs a log message
Schema::AbstractSchema::getCreateOnlyReferenceData
*hash getCreateOnlyReferenceData()
returns a hash of "create-only reference data", describing data that is written to the table when the...
Schema::AbstractVersionedSchema::getVersionTableImpl
abstract private string getVersionTableImpl()
returns the name of the table holding the schema version string
Schema::AbstractSchema::getSequencesImpl
private *hash getSequencesImpl()
returns sequence definitions
Schema::AbstractVersionedSchema
this class extends Schema::AbstractSchema by providing version logic based on a schema version string...
Definition: Schema.qm.dox.h:476
Schema::AbstractSchema::getVersionImpl
abstract private string getVersionImpl()
returns the version of the schema
Schema::AbstractVersionedSchema::checkDropSchema
private bool checkDropSchema(bool force)
this method returns True if the schema can be dropped
Schema::AbstractSchema::postDataActions
private postDataActions(bool first_time_install)
this method is called after schema reference data has been managed
type
string type(any arg)
Schema::AbstractSchema::creation_options
*hash creation_options
creation options, as provided by getCreationOptions()
Definition: Schema.qm.dox.h:145
Schema::AbstractSchema::getIndexOptionsImpl
private *hash getIndexOptionsImpl()
returns index options
Schema::AbstractSchema::schema
hash schema
the schema template, as assembled from method callbacks providing schema element definitions ...
Definition: Schema.qm.dox.h:140
Schema::AbstractSchema::getInsertOnlyReferenceDataImpl
private *hash getInsertOnlyReferenceDataImpl()
returns a hash of "create-only reference data", describing data that will only be inserted if missing...
Schema::SchemaCallbackHelper
this class provides callback support for schema operations
Definition: Schema.qm.dox.h:60
Schema::AbstractSchema::getStrictReferenceDataHash
*hash getStrictReferenceDataHash()
returns a hash of "strict reference data", describing the only data that can appear in the target tab...
Schema::AbstractSchema::getInsertOnlyReferenceData
*hash getInsertOnlyReferenceData()
returns a hash of "create-only reference data", describing data that will only be inserted if missing...
Schema::AbstractSchema::getCreationOptions
*hash getCreationOptions()
returns schema creation options
Schema::AbstractSchema::getRows
static list getRows(*softlist l)
returns a list of hashes from a list of lists where the first list element in the top-level list is a...
Schema::AbstractSchema::checkExistence
private bool checkExistence()
returns True if the method can detect that DB objects defined in the schema exist in the database ...
Schema::AbstractVersionedSchema::version_table
string version_table
the name of the table containing the version string
Definition: Schema.qm.dox.h:481
Schema::AbstractSchema::getTypes
*hash getTypes()
returns type definitions
Schema::AbstractSchema::getName
string getName()
returns the name of the schema
Schema::AbstractSchema::db
SqlUtil::Database db
the Database object for the schema
Definition: Schema.qm.dox.h:157
Schema::AbstractSchema::getProceduresImpl
private *hash getProceduresImpl()
returns stored procedure definitions
Schema::AbstractSchema::info_callback
code info_callback
the info callback for schema operations; can be used for explicit logging
Definition: Schema.qm.dox.h:165
Schema::AbstractSchema::getFunctionsImpl
private *hash getFunctionsImpl()
returns function definitions
Schema::AbstractSchema::version
string version
the version of the schema
Definition: Schema.qm.dox.h:137
Schema::AbstractVersionedSchema::checkUpdateSchema
private bool checkUpdateSchema(bool force, reference initial_schema_info)
this method returns True if the schema can be updated
Schema::AbstractSchema::all_options
*hash all_options
combined creation and column options
Definition: Schema.qm.dox.h:149
Schema::AbstractVersionedSchema::getSchemaVersion
private *softstring getSchemaVersion()
returns the existing schema version or NOTHING if not present
Schema::AbstractSchema::getNameImpl
abstract private string getNameImpl()
returns the version of the schema
Schema::AbstractSchema::drv
string drv
the name of the database driver
Definition: Schema.qm.dox.h:154
Schema::AbstractSchema::getUpsertStrategy
private int getUpsertStrategy(bool first_time_install)
this method is called to return the upsert strategy before schema reference data management ...
Schema::AbstractVersionedSchema::version_where
hash version_where
a where clause hash defining the row where the schema version string is located
Definition: Schema.qm.dox.h:485
Schema::AbstractVersionedSchema::checkDowngrade
private bool checkDowngrade(string current_version)
this method is called if the current schema version is greater than the target version; returns True ...
Schema::AbstractSchema::getDatasource
AbstractDatasource getDatasource()
returns the datasource used for the schema
Schema::AbstractSchema::logpf
logpf(string fmt)
outputs a log message prefixed with the schema name
Schema::AbstractSchema::pure_callback_opts
hash pure_callback_opts
just callback options
Definition: Schema.qm.dox.h:160
Schema::AbstractSchema::getMaterializedViewsImpl
private *hash getMaterializedViewsImpl()
returns materialized view definitions
hash
hash hash(object obj)
Schema::AbstractSchema::doTable
private doTable(AbstractTable table, list rows, int upsert_strategy, bool delete_others, int verbose, reference sh)
this method is called to perform schema reference data managment on the given table with the given da...
Schema::AbstractSchema::getPackagesImpl
private *hash getPackagesImpl()
returns (Oracle) package definitions
Schema::AbstractSchema::getPackages
*hash getPackages()
returns (Oracle) package definitions
Schema::AbstractVersionedSchema::getVersionTable
private string getVersionTable()
returns the name of the table holding the schema version string by calling getVersionTableImpl() ...
Schema::AbstractSchema::getCreateOnlyReferenceDataImpl
private *hash getCreateOnlyReferenceDataImpl()
returns a hash of "create-only reference data", describing data that is written to the table when the...
Schema::AbstractSchema::getTypesImpl
private *hash getTypesImpl()
returns type definitions
Schema::AbstractSchema::index_ts
*string index_ts
explicit index tablespace name
Definition: Schema.qm.dox.h:171
Schema::SchemaCallbackHelper::sqlForceCallback
nothing sqlForceCallback(string str)
this is the SQL callback method for forced schema operations
Schema::AbstractSchema
the AbstractSchema class is a base class to assist with automatic schema management ...
Definition: Schema.qm.dox.h:130
Schema::AbstractSchema::combineOptions
static hash combineOptions(*hash h)
combines option hashes into a single target option hash
Schema::AbstractVersionedSchema::constructor
constructor(AbstractDatasource ds, *string dts, *string its)
creates the object based on the arguments giving the location of the schema
Schema::AbstractSchema::checkDropSchema
private bool checkDropSchema(bool force)
this method returns True if the schema can be dropped