{"id":5718,"date":"2021-07-07T00:09:01","date_gmt":"2021-07-07T00:09:01","guid":{"rendered":"https:\/\/swiv.com.br\/using-application-common-objects\/"},"modified":"2026-05-27T20:02:30","modified_gmt":"2026-05-27T19:02:30","slug":"using-application-common-objects","status":"publish","type":"post","link":"https:\/\/swiv.com.br\/index.php\/2021\/07\/07\/using-application-common-objects\/","title":{"rendered":"Using Application Common Objects"},"content":{"rendered":"\n<p>Neste artigo, vamos explorar os 3 tipos de Application Common Objects que podemos usar em nossa estrutura de Application Containers. Ainda baseados nos artigos anteriores, que fizemos a cria\u00e7\u00e3o da estrutura m\u00ednima para viabilizar os testes que ocorrer\u00e3o neste artigo.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Data-Linked Application Common Objects<\/h2>\n\n\n\n<p>Este tipo de objeto possui o seu metadados e dados armazenados em um Application Root, sendo acess\u00edveis de todos os Application PDBs necess\u00e1rios. \u00c9 ideal que as informa\u00e7\u00f5es n\u00e3o sejam vol\u00e1teis para a sua aplica\u00e7\u00e3o pr\u00e1tica, ou seja, que n\u00e3o sofrem altera\u00e7\u00f5es (por exemplo, dados de CEP&#8217;s). A sua cria\u00e7\u00e3o se d\u00e1 com o par\u00e2metro SHARING=DATA, conforme exemplo abaixo (objeto este que j\u00e1 criamos em artigos anteriores):<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nCREATE TABLE HR.REGIONS SHARING=DATA\n(\n  REGION_ID    NUMBER ,\n  REGION_NAME  VARCHAR2(25 BYTE)\n);\n<\/pre><\/div>\n\n\n<p>Vamos validar que os dados desse objeto s\u00e3o os mesmos, para os 2 Application PDBs criados em nosso ambiente laborat\u00f3rio:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&#x5B;oracle@quiasma admin]$ sqlplus hr\/oracle@\/\/quiasma:1521\/hr_pdb1.localdomain\n \nSQL*Plus: Release 18.0.0.0.0 - Production on Tue Jul 6 20:41:13 2021\nVersion 18.13.0.0.0\n \nCopyright (c) 1982, 2018, Oracle.  All rights reserved.\n \nLast Successful login time: Tue Jul 06 2021 20:02:14 -03:00\n \nConnected to:\nOracle Database 18c Enterprise Edition Release 18.0.0.0.0 - Production\nVersion 18.13.0.0.0\n \nSQL&gt; SELECT REGION_ID, REGION_NAME FROM REGIONS;\n \n REGION_ID REGION_NAME\n---------- -------------------------\n         1 Europe\n         2 Americas\n         3 Asia\n         4 Middle East and Africa\n \nSQL&gt; conn hr\/oracle@\/\/quiasma:1521\/hr_pdb2.localdomain\nConnected.\nSQL&gt; SELECT REGION_ID, REGION_NAME FROM REGIONS;\n \n REGION_ID REGION_NAME\n---------- -------------------------\n         1 Europe\n         2 Americas\n         3 Asia\n         4 Middle East and Africa\n \nSQL&gt;\n<\/pre><\/div>\n\n\n<p>Vemos que ao logar no Application PDB HR_PDB1 e tentar inserir dados na tabela, uma mensagem de erro \u00e9 reportada pelo Oracle:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSQL&gt; conn hr\/oracle@\/\/quiasma:1521\/hr_pdb1.localdomain\nConnected.\nSQL&gt; INSERT INTO REGIONS (REGION_ID,REGION_NAME) VALUES (101,&#039;BSS&#039;);\nINSERT INTO REGIONS (REGION_ID,REGION_NAME) VALUES (101,&#039;BSS&#039;)\n            *\nERROR at line 1:\nORA-65097: DML into a data link table is outside an application action\n \n \nSQL&gt;\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\">Metadata-linked  Application Common Objects <\/h2>\n\n\n\n<p>Neste tipo de objeto, apenas os metadados est\u00e3o armazenados em um Application Root. Isso permite que m\u00faltiplos PDBs possuam a mesma estrutura (DDL) de um objeto, mas que os seus dados sejam diferentes. Para a sua defini\u00e7\u00e3o, podemos usar o par\u00e2metro SHARING=METADATA, conforme exemplo abaixo:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nCREATE TABLE HR.DEPARTMENTS SHARING=METADATA\n(\n  DEPARTMENT_ID    NUMBER(4),\n  DEPARTMENT_NAME  VARCHAR2(30 BYTE) ,\n  MANAGER_ID       NUMBER(6),\n  LOCATION_ID      NUMBER(4)\n);\n<\/pre><\/div>\n\n\n<p>Logados no PDB HR_PDB1, vamos adicionar 2 registros na tabela mencionada acima:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSQL&gt; conn hr\/oracle@\/\/quiasma:1521\/hr_pdb1.localdomain\nConnected.\nSQL&gt; INSERT INTO DEPARTMENTS (DEPARTMENT_ID, DEPARTMENT_NAME, MANAGER_ID, LOCATION_ID) VALUES (&#039;10&#039;, &#039;MANAGEMENT&#039;, NULL, 1000);\n \n1 row created.\n \nSQL&gt; INSERT INTO HR.DEPARTMENTS (DEPARTMENT_ID, DEPARTMENT_NAME, MANAGER_ID, LOCATION_ID) VALUES (&#039;20&#039;, &#039;DEVELOPEMENT&#039;, NULL, 1000);\n \n1 row created.\n \nSQL&gt; COMMIT;\n \nCommit complete.\n \nSQL&gt; SELECT * FROM HR.DEPARTMENTS;\n \nDEPARTMENT_ID DEPARTMENT_NAME                MANAGER_ID LOCATION_ID\n------------- ------------------------------ ---------- -----------\n           10 MANAGEMENT                                       1000\n           20 DEVELOPEMENT                                     1000\n<\/pre><\/div>\n\n\n<p>J\u00e1 no PDB HR_PDB2, vamos adicionar outros 2 registros. Constatamos que um PDB n\u00e3o consegue ver os dados do outro:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSQL&gt; conn hr\/oracle@\/\/quiasma:1521\/hr_pdb2.localdomain\nConnected.\nSQL&gt; INSERT INTO HR.DEPARTMENTS (DEPARTMENT_ID, DEPARTMENT_NAME, MANAGER_ID, LOCATION_ID) VALUES ( &#039;100&#039;, &#039;MANAGEMENT&#039;, NULL, 2000);\n \n1 row created.\n \nSQL&gt; INSERT INTO HR.DEPARTMENTS (DEPARTMENT_ID, DEPARTMENT_NAME, MANAGER_ID, LOCATION_ID) VALUES ( &#039;200&#039;, &#039;DEVELOPEMENT&#039;, NULL, 2000);\n \n1 row created.\n \nSQL&gt; COMMIT;\n \nCommit complete.\n \nSQL&gt; SELECT * FROM HR.DEPARTMENTS;\n \nDEPARTMENT_ID DEPARTMENT_NAME                MANAGER_ID LOCATION_ID\n------------- ------------------------------ ---------- -----------\n          100 MANAGEMENT                                       2000\n          200 DEVELOPEMENT                                     2000\n<\/pre><\/div>\n\n\n<p>O interessante tamb\u00e9m \u00e9 notar que n\u00e3o conseguimos, a partir do Application PDB, alterar a estrutura do objeto em quest\u00e3o:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSQL&gt; ALTER TABLE DEPARTMENTS ADD ( NOTES VARCHAR2(100)) ;\nALTER TABLE DEPARTMENTS ADD ( NOTES VARCHAR2(100))\n*\nERROR at line 1:\nORA-65274: operation not allowed from outside an application action\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\">Extended Data-Linked Application Objects<\/h2>\n\n\n\n<p>Por \u00faltimo, o Extended Data-Linked \u00e9 um modelo h\u00edbrido: os metadados e dados est\u00e3o armazenados no Application Root, podendo ser acessados pelo Application PDBs, por\u00e9m, cada PDB pode ir criando seus pr\u00f3prios dados. Isso \u00e9 permitido a partir da instru\u00e7\u00e3o SHARING=EXTENDED DATA, conforme exemplo abaixo:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nCREATE TABLE HR.LOCATIONS sharing=extended data\n(\n  LOCATION_ID     NUMBER(4),\n  STREET_ADDRESS  VARCHAR2(40 BYTE),\n  POSTAL_CODE     VARCHAR2(12 BYTE),\n  CITY            VARCHAR2(30 BYTE) ,\n  STATE_PROVINCE  VARCHAR2(25 BYTE),\n  COUNTRY_ID      CHAR(2 BYTE)\n);\n<\/pre><\/div>\n\n\n<p>Para simular o seu funcionamento, vamos logar no PDB HR_PDB1 e inserir um registro na tabela acima:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSQL&gt; conn hr\/oracle@\/\/quiasma:1521\/hr_pdb1.localdomain\nConnected.\nSQL&gt; SELECT COUNT(*) FROM LOCATIONS;\n \n  COUNT(*)\n----------\n        23\n \nSQL&gt; INSERT INTO LOCATIONS (LOCATION_ID, CITY, COUNTRY_ID) VALUES (9000, &#039;Man U.&#039;, &#039;UK&#039;) ;\n \n1 row created.\n \nSQL&gt; COMMIT;\n \nCommit complete.\n \nSQL&gt; SELECT COUNT(*) FROM LOCATIONS;\n \n  COUNT(*)\n----------\n        24\n<\/pre><\/div>\n\n\n<p>Realizando o mesmo processo no HR_PDB2 (e j\u00e1 percebemos que o registro adicionado ao HR_PDB1 n\u00e3o \u00e9 exibido ao nosso PDB vigente):<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSQL&gt; conn hr\/oracle@\/\/quiasma:1521\/hr_pdb2.localdomain\nConnected.\nSQL&gt; SELECT COUNT(*) FROM LOCATIONS;\n \n  COUNT(*)\n----------\n        23\n \nSQL&gt; INSERT INTO LOCATIONS (LOCATION_ID, CITY, COUNTRY_ID) VALUES (9000, &#039;Man U.&#039;, &#039;UK&#039;) ;\n \n1 row created.\n \nSQL&gt; COMMIT;\n \nCommit complete.\n \nSQL&gt; SELECT COUNT(*) FROM LOCATIONS;\n \n  COUNT(*)\n----------\n        24\n<\/pre><\/div>\n\n\n<p>Agora vamos tentar deletar um registro que foi adicionado no momento da cria\u00e7\u00e3o do Application. Vemos que o mesmo n\u00e3o \u00e9 deletado, uma vez que seu conte\u00fado pertence ao Application Root, e n\u00e3o ao Application PDB:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSQL&gt; SELECT COUNT(*) FROM LOCATIONS WHERE LOCATION_ID=3200;\n \n  COUNT(*)\n----------\n         1\n \nSQL&gt; DELETE LOCATIONS WHERE LOCATION_ID=3200;\n \n0 rows deleted.\n<\/pre><\/div>\n\n\n<p>Por fim, vamos deletar o registro adicionado pelo Application PDB:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSQL&gt; SELECT COUNT(*) FROM LOCATIONS WHERE LOCATION_ID=9000;\n \n  COUNT(*)\n----------\n         1\n \nSQL&gt; DELETE LOCATIONS WHERE LOCATION_ID=9000;\n \n1 row deleted.\n \nSQL&gt; COMMIT;\n \nCommit complete.\n<\/pre><\/div>\n\n<p>Fonte: <a href=\"\/\/docs.oracle.com\/en\/database\/oracle\/oracle-database\/12.2\/cncpt\/overview-of-the-multitenant-architecture.html#GUID-D9FDDB3D-E3B8-40FA-9EC5-F88467733C92\\&quot;\" target=\"\\&quot;_blank\\&quot;\" rel=\"\\&quot;noreferrer noopener\">AQUI<\/a>.<\/p>\n\n\n<p>Obs: Este procedimento foi criado pelo senhor Ahmed Baraka (www.ahmedbaraka.com) e foi apenas reproduzido por mim em um laborat\u00f3rio pessoal para fins de aprendizado.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Neste artigo, vamos explorar os 3 tipos de Application Common Objects que podemos usar em nossa estrutura de Application Containers. Ainda baseados nos artigos anteriores, que fizemos a cria\u00e7\u00e3o da estrutura m\u00ednima para viabilizar os testes que ocorrer\u00e3o neste artigo. Data-Linked Application Common Objects Este tipo de objeto possui o seu metadados e dados armazenados [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-5718","post","type-post","status-publish","format-standard","hentry","category-multitenant"],"_links":{"self":[{"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/posts\/5718","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/comments?post=5718"}],"version-history":[{"count":1,"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/posts\/5718\/revisions"}],"predecessor-version":[{"id":9084,"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/posts\/5718\/revisions\/9084"}],"wp:attachment":[{"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/media?parent=5718"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/categories?post=5718"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/tags?post=5718"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}