Skip to content

Commit d5928e7

Browse files
authored
Merge pull request #36 from OraMUC/feature-tenant-support
Feature tenant support
2 parents eff1cba + 61c5032 commit d5928e7

17 files changed

+880
-492
lines changed

README.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<!-- DO NOT EDIT THIS FILE DIRECTLY - it is generated from source file src/OM_TAPIGEN.pks -->
2+
<!-- markdownlint-disable MD003 MD012 MD033 -->
23

34
Oracle PL/SQL Table API Generator
45
=================================
@@ -14,8 +15,9 @@ Oracle PL/SQL Table API Generator
1415
<h2><a id="om_tapigen"></a>Package om_tapigen</h2>
1516
<!----------------------------------------------->
1617

17-
_This table API generator can be integrated in the Oracle SQL-Developer with an
18-
additional wrapper package for the [SQL Developer extension oddgen](https://www.oddgen.org/)._
18+
_This table API generator needs an Oracle DB version 12.1 or higher and can be
19+
integrated in the Oracle SQL-Developer with an additional wrapper package
20+
for the [SQL Developer extension oddgen](https://www.oddgen.org/)._
1921

2022
The effort of generated API's is to reduce your PL/SQL code by calling standard
2123
procedures and functions for usual DML operations on tables. So the generated
@@ -34,18 +36,20 @@ FEATURES
3436
- Generates small wrappers around your tables
3537
- Highly configurable
3638
- You can enable or disable separately insert, update and delete functionality
37-
- Standard CRUD methods (column and row type based) and an additional create
38-
or update method
39+
- Standard CRUD methods (column and row type based) and an additional create or update method
3940
- Set based methods for high performance DML processing
4041
- For each unique constraint a read method and a getter to fetch the primary key
41-
- Functions to check if a row exists (primary key based, returning boolean or
42-
varchar2)
42+
- Functions to check if a row exists (primary key based, returning boolean or varchar2)
4343
- Support for audit columns
4444
- Support for a row version column
4545
- Optional getter and setter for each column
4646
- Optional 1:1 view to support the separation of concerns (also known as ThickDB/SmartDB/PinkDB paradigm)
4747
- Optional DML view with an instead of trigger to support low code tools like APEX
4848

49+
PREREQUISITES
50+
51+
- Oracle 12.1 or higher
52+
4953
LICENSE
5054

5155
- [The MIT License (MIT)](https://github.com/OraMUC/table-api-generator/blob/master/LICENSE.txt)
@@ -79,7 +83,7 @@ SIGNATURE
7983
```sql
8084
PACKAGE om_tapigen AUTHID CURRENT_USER IS
8185
c_generator CONSTANT VARCHAR2(10 CHAR) := 'OM_TAPIGEN';
82-
c_generator_version CONSTANT VARCHAR2(10 CHAR) := '0.5.2.34';
86+
c_generator_version CONSTANT VARCHAR2(10 CHAR) := '0.5.2.39';
8387
```
8488

8589

@@ -124,6 +128,7 @@ PROCEDURE compile_api
124128
p_audit_column_mappings IN VARCHAR2 DEFAULT NULL, -- If not null, the provided comma separated column names are excluded and populated by the API (you don't need a trigger for update_by, update_on...).
125129
p_audit_user_expression IN VARCHAR2 DEFAULT c_audit_user_expression, -- You can overwrite here the expression to determine the user which created or updated the row (see also the parameter docs...).
126130
p_row_version_column_mapping IN VARCHAR2 DEFAULT NULL, -- If not null, the provided column name is excluded and populated by the API with the provided SQL expression (you don't need a trigger to provide a row version identifier).
131+
p_tenant_column_mapping IN VARCHAR2 DEFAULT NULL, -- If not null, the provided column name is hidden inside the API, populated with the provided SQL expression and used as a tenant_id in all relevant API methods.
127132
p_enable_custom_defaults IN BOOLEAN DEFAULT FALSE, -- If true, additional methods are created (mainly for testing and dummy data creation, see full parameter descriptions).
128133
p_custom_default_values IN XMLTYPE DEFAULT NULL -- Custom values in XML format for the previous option, if the generator provided defaults are not ok.
129134
);
@@ -174,6 +179,7 @@ FUNCTION compile_api_and_get_code
174179
p_audit_column_mappings IN VARCHAR2 DEFAULT NULL, -- If not null, the provided comma separated column names are excluded and populated by the API (you don't need a trigger for update_by, update_on...).
175180
p_audit_user_expression IN VARCHAR2 DEFAULT c_audit_user_expression, -- You can overwrite here the expression to determine the user which created or updated the row (see also the parameter docs...).
176181
p_row_version_column_mapping IN VARCHAR2 DEFAULT NULL, -- If not null, the provided column name is excluded and populated by the API with the provided SQL expression (you don't need a trigger to provide a row version identifier).
182+
p_tenant_column_mapping IN VARCHAR2 DEFAULT NULL, -- If not null, the provided column name is hidden inside the API, populated with the provided SQL expression and used as a tenant_id in all relevant API methods.
177183
p_enable_custom_defaults IN BOOLEAN DEFAULT FALSE, -- If true, additional methods are created (mainly for testing and dummy data creation, see full parameter descriptions).
178184
p_custom_default_values IN XMLTYPE DEFAULT NULL -- Custom values in XML format for the previous option, if the generator provided defaults are not ok.
179185
) RETURN CLOB;
@@ -226,6 +232,7 @@ FUNCTION get_code
226232
p_audit_column_mappings IN VARCHAR2 DEFAULT NULL, -- If not null, the provided comma separated column names are excluded and populated by the API (you don't need a trigger for update_by, update_on...).
227233
p_audit_user_expression IN VARCHAR2 DEFAULT c_audit_user_expression, -- You can overwrite here the expression to determine the user which created or updated the row (see also the parameter docs...).
228234
p_row_version_column_mapping IN VARCHAR2 DEFAULT NULL, -- If not null, the provided column name is excluded and populated by the API with the provided SQL expression (you don't need a trigger to provide a row version identifier).
235+
p_tenant_column_mapping IN VARCHAR2 DEFAULT NULL, -- If not null, the provided column name is hidden inside the API, populated with the provided SQL expression and used as a tenant_id in all relevant API methods.
229236
p_enable_custom_defaults IN BOOLEAN DEFAULT FALSE, -- If true, additional methods are created (mainly for testing and dummy data creation, see full parameter descriptions).
230237
p_custom_default_values IN XMLTYPE DEFAULT NULL -- Custom values in XML format for the previous option, if the generator provided defaults are not ok.
231238
) RETURN CLOB;

docs/changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Please use for all comments, discussions, feature requests or bug reports the Gi
4343
- added: double quoting of table and column names can now be configured (parameter p_double_quote_names, default true)
4444
- added: update function with return clause (mainly for use in create_or_update_row to prevent read row after update)
4545
- added: unit tests with utPLSQL (it will be a permanent task to improve the tests with every new feature or bugfix)
46+
- removed: support for database versions < 12.1 - if this is a problem for you then use the generator version 0.5.2 (without all the new features, sorry...)
4647
- removed: support for a generic change log (parameter p_enable_generic_change_log - makes no sense anymore with bulk processing and multi column primary keys)
4748
- removed: prevent updates if columns do not differ (remove was needed to support all possible column types and for performance reasons)
4849
- removed: parameter p_reuse_existing_api_params (usage was was not logic, simply provide always your needed parameters and create scripts or a wrapper)

docs/parameters.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
- [p_audit_column_mappings (since v0.6.0)](#p_audit_column_mappings-since-v060)
3939
- [p_audit_user_expression (since v0.6.0)](#p_audit_user_expression-since-v060)
4040
- [p_row_version_column_mapping (since v0.6.0)](#p_row_version_column_mapping-since-v060)
41+
- [p_tenant_column_mapping (since v0.6.0)](#p_tenant_column_mapping-since-v060)
4142
- [p_enable_custom_defaults (since v0.5.0)](#p_enable_custom_defaults-since-v050)
4243
- [p_custom_default_values (since v0.5.0)](#p_custom_default_values-since-v050)
4344
- [Removed Parameters](#removed-parameters)
@@ -223,6 +224,15 @@
223224
- Supports column prefix placeholders to be able to reuse the same mappings in multiple tables with different column_prefixes
224225
- Example with a global version sequence: `#PREFIX#_VERSION_ID=tag_global_version_sequence.nextval`
225226

227+
## p_tenant_column_mapping (since v0.6.0)
228+
- String (varchar2), default: null
229+
- If not null, the provided column name is excluded from the parameters and appended to all primary key where clauses with the provided SQL expression
230+
- If you have unique keys in your tables you should make sure the tenant column is part of it, otherwise the unique key based read_row methods are not filtering correct
231+
- For the ref cursor based bulk fetch method `read_rows` the API cannot do anything for you, because the ref cursor is defined outside the API - you need to make sure that all view provided to the users are secured correct with an appropriate where clause - the generated DML and 1:1 views do this also
232+
- You should consider to hide your column from standard `select *` queries: Also see [Invisible Columns in Oracle Database 12c Release 1 (12.1)](https://oracle-base.com/articles/12c/invisible-columns-12cr1)
233+
- Supports column prefix placeholders to be able to reuse the same mappings in multiple tables with different column_prefixes
234+
- Example: `#PREFIX#_TENANT_ID=to_number(sys_context('my_sec_ctx','my_tenant_id'))`
235+
226236
## p_enable_custom_defaults (since v0.5.0)
227237

228238
- Boolean, default: false

0 commit comments

Comments
 (0)