How can I create triggers automatically for the journaling columns?

Every single table in our database has columns USER_CREATED, USER_MODIFIED, DATE_CREATED, DATE_MODIFIED. Is there a way to get Data Modeler to create the triggers for inserting data to those columns? YES!

The thing you need is Table DDL Transformation:

TableDDL1

 

Define a new Table DDL Transformation Script set (in my example Trigger_for_Technical_Column):

TableDDL2

Define a After Create script and write something like this to it (thank you Marko Helskyaho ūüôā ):

/*
variable ddlStatementsList should be used to return the list with DDL statements
that are created by script – as shown below:
ddlStatementsList.add(new java.lang.String(ddl));
other available variables:
– model – relational model instance
– pModel – physical model instance
– table – the table in relational model
– tableProxy – table definition in physical model
*/
var ddl;
var lname;
// trigger name prefix
trgPre = “BIU_”;
// trigger name suffix
trgSuf = “_TRG”;
prompt = model.getAppView().getSettings().isIncludePromptInDDL();
useSchema = model.getAppView().getSettings().isIncludeSchemaInDDL();
if(model.getStorageDesign().isOpen()){
if(useSchema){
lname = tableProxy.getLongName();
}else{
lname = tableProxy.getName();
}
}else{
if(useSchema){
lname = table.getLongName();
}else{
lname = table.getName();
}
}

if(prompt){
ddl= “\nPROMPT Creating Trigger for ‘”+lname+”‘;\n”;
}else{
ddl = “\n”;
}
ddl = ddl +
“CREATE OR REPLACE TRIGGER “+trgPre+lname+trgSuf +”\n”+
” BEFORE \n” +
” INSERT OR \n” +
” UPDATE ON “+lname+” FOR EACH ROW \n” +
” BEGIN \n” +
” IF INSERTING THEN \n” +
” :NEW.DATE_CREATED := SYSDATE; \n” +
” :NEW.USER_CREATED := NVL(WWV_FLOW.G_USER,USER); \n” +
” END IF; \n” +
” :NEW.DATE_MODIFIED := SYSDATE; \n” +
” :NEW.USER_MODIFIED := NVL(WWV_FLOW.G_USER,USER); \n” +
” END; \n” +
” /”
ddlStatementsList.add(new java.lang.String(ddl));

You can immediatelly test it. Select one of your tables as Table To Test (in my example Isa) and press Test. This is what I got:

TableDDL3

Looks what I wanted but how can I use this script?

When generating DDLs select Include Table DDL Scripts tab. Then select the script from Active Script Set list and select those tables you want to execute it:

TableDDL4

OK. And this is what I got:

CREATE TABLE isa (
avain_uusi NUMBER(16) NOT NULL,
jokumuu VARCHAR2(50 CHAR) NOT NULL,
user_created VARCHAR2(50 CHAR) NOT NULL,
user_modified VARCHAR2(50 CHAR),
date_created DATE NOT NULL,
date_modified DATE
);

ALTER TABLE isa ADD CONSTRAINT isa_pk PRIMARY KEY ( avain_uusi );

CREATE OR REPLACE TRIGGER BIU_Isa_TRG
BEFORE
INSERT OR
UPDATE ON Isa FOR EACH ROW
BEGIN
IF INSERTING THEN
:NEW.DATE_CREATED := SYSDATE;
:NEW.USER_CREATED := NVL(WWV_FLOW.G_USER,USER);
END IF;
:NEW.DATE_MODIFIED := SYSDATE;
:NEW.USER_MODIFIED := NVL(WWV_FLOW.G_USER,USER);
END;
/

CREATE TABLE lapsi (
avainlapsi NUMBER(16) NOT NULL,
lisatieto VARCHAR2(50 CHAR) NOT NULL,
avain_uusi NUMBER(16) NOT NULL,
user_created VARCHAR2(50 CHAR) NOT NULL,
user_modified VARCHAR2(50 CHAR),
date_created DATE NOT NULL,
date_modified DATE
);

ALTER TABLE lapsi ADD CONSTRAINT lapsi_pk PRIMARY KEY ( avainlapsi,avain_uusi );

CREATE OR REPLACE TRIGGER BIU_lapsi_TRG
BEFORE
INSERT OR
UPDATE ON lapsi FOR EACH ROW
BEGIN
IF INSERTING THEN
:NEW.DATE_CREATED := SYSDATE;
:NEW.USER_CREATED := NVL(WWV_FLOW.G_USER,USER);
END IF;
:NEW.DATE_MODIFIED := SYSDATE;
:NEW.USER_MODIFIED := NVL(WWV_FLOW.G_USER,USER);
END;
/

ALTER TABLE lapsi
ADD CONSTRAINT lapsi_isa_fk FOREIGN KEY ( avain_uusi )
REFERENCES isa ( avain_uusi );

 

 

Advertisements

How can I get technical columns to the relational model?

I always define columns like USER_CREATED, USER_MODIFIED, DATE_CREATED, DATE_MODIFIED for my tables but I would not like to design them in the logical model. Is there a way to get them automatically to the relational model? YES!

Here’s my logical model. None of my entities has those attributes defined.

TempTable0

 

First design a table that only has those technical columns, nothing else. In my example a table is called TempTable:

TempTable1

 

Then when Engineering to Relational Model select General Options, Use Template Table and select this table from the list:

TempTable2

Engineer.

Now all the tables you just generated to a relational model has these columns:

TempTable3

 

 

 

 

ODC Appreciation Day: JSON Data Guide

There are so many features I like but this feature is something I think people do not know about and it is a feature that will be very valuable for a multi-model database which I believe is the future.

JSON Data Guide allows JSON data to be saved as it is and to be used with SQL. In other words it gives the ability to be able to write without schema but read with schema which is a functionality we need in the world of Big Data.

JSON Data Guide can be either persistent or transient. There are two formats of JSON Data Guide: flat or hierarchical. The hierarchical format includes features like views on top of a set of JSON files and virtual columns.

JSON Data Guide enables FSDM (Flexible Schema Data Management) in a RDBMS. It allows saving data in its original format without missing the opportunity to use that data efficiently. And therefore it is one step closer to a multi-model database.

 

OOW is just around the corner

I cannot believe how fast time flies! It has been an exceptionally busy year and that is the reason I have not had time to write blog posts either. I have been speaking in amazing events like BIWA Summit, APEX Connect, Riga DevDays 2017, OTNEMEA Tour in Baku and in Madrid, BGOUG, E4, KScope17, Oracle Code Bengaluru, the first ever APEX Day in Finland, Oracle Code Seoul, POUG, and Tajikistan TechDay. Next on my list is Oracle OpenWorld. As always it will be a busy week.

I will fly to San Francisco on Thursday to attend the ACE Director briefing on Friday at the Oracle HQ. I will have three talks:

OOW_session_catalog

And I will also have two short talks:

  • one at the EOUC trackEOUC.jpg
  • and another one at the WIT Lightning Storm sessionWIT

I will have several meetings, swimming, running and chocolate tasking

https://www.eventbrite.com/e/chocolate-tasting-at-oracle-openworld-2017-tickets-38069813838

Just to mention some of the social activities during the week. To me the social side is very important, I am a big believer of face-to-face meetings.

Now my only concern is will I finish all my presentations on time so I guess I need to stop writing and start working… I hope to see many of you next week in San Francisco!

Version 17.2 is out

The new versioning systems now applies to SQL Developer and Data Modeler too. A new version comes out about four times a year and the version number is created using the last two digits of the year and the number of the quarter. So version 17.2 is out for both of them and can be downloaded here:

Data Modeler

http://www.oracle.com/technetwork/developer-tools/datamodeler/overview/index.html

Bugs fixed:

26280295 – MISSING ; FOR AUTOMATICALLY GENERATED INDEXES FOR PK, UK AND FK CONSTRAINTS
22145935 – DOMAIN ADMINISTRATION SHOWS MULTIPLE SAME DATA TYPE
26285068 – DDL ALTER TABLE NOT INCLUDING SCHEMA NAME FOR FOREIGN KEYS FOR SQL SERVER
25896354 – DB2 ASSOCIATION DATABASE-STORAGE GROUP & TABLESPACE-STORAGE TEMPLATE NOT WORKING
26090903 – UNABLE TO SELECT MULTIPLE ATTRIBUTES/COLUMNS IN ENTITY/TABLE WITH SHIFT/CTRL KEY
26006706 – ERRORS FOR THE FOREIGN KEY INDEX WITH THE SAME NAME AS THE FOREIGN KEY
26120866 – PHYSICAL MODEL, TABLE PARTITIONING SETTINGS LOST ON LOAD MODEL-SINGLE FILE
25888833 – SINGLE QUOTES IN DOMAIN CONSTRAINT ARE NOT PROCESSED PROPERLY DURING SAVE OPEN
22662213 – SAVED SEARCHES NOT OVERWRITING
25777203 – ERROR ON EXCEL REPORTS WITH COLUMN UDP
25923812 – NPE DURING IMPORT FROM DATABASE WHEN TARGET IS “NEW RELATIONAL MODEL”
25813010 – DOMAINS IN REMOTE TABLE ARE NOT SYNCHRONIZED PROPERLY WHEN REMOTE DESIGN IS OPEN

SQL Developer

http://www.oracle.com/technetwork/developer-tools/sql-developer/overview/index.html

Bugs fixed:

 25956060 РCONNECTION DISCONNECT ON TAB SWITCHES
 26275211 РPREVENTED POSSIBLE REGRESSION ON DIVISION EXPRESSION
 25735609 Р: OPERATORS ARE NOT SUPPORTED
 26041444 РDRAG AND DROP MULTI TABLES JOIN FAILED
 26103385 РBUG IN CONNECTIONS ORDS NAVIGATOR 3.0.10.
 26229132 РORDS SEARCH CODE FAILS DUE TO THE METADATA TABLE NOT VISIBLE
 25773801 РCARET POSITIONED AT BEGINNING OF FIELD WHEN EDIT STARTED BY KEYSTONES
 25777168 РTABLE COLUMN ARE ALL REMOVED WHEN ONE COLUMN REMOVED
 25966899 РRUN PL/SQL DIALOG AND PARAMETERS FOR DOUBLE QUOTED PROCEDURE/PACKAGES MISSING.
 26107832 РCOMMIT AND ROLLBACK FAIL TO TRANSLATE
 25962766 Р: CODE OUTLINE REGRESSION, CODE POSITION NOT REFLECTED IN THE TREE
 25986304 РSQL CODE HAVING COMMENTS WITH SEMICOLON AT THE END WILL CAUSE ERRORS JIRA: SQLDEV-350
 26177821 РVIEW-REST DATA SERVICES РDEVELOPMENT DOES NOT DISPLAY RESTFUL SERVICES
 25735609 Р: OPERATORS ARE NOT SUPPORTED
 26200926 РINSERT INTO FORMAT SHOWN NOT RIGHT WHEN FORMAT ON WORKSHEET
 26200893 РFUNCTION FORMAT SHOWN NOT RIGHT AFTER FORMAT ON WORKSHEET
¬†26202027 – WORKSHEET FORMAT FOR ‘||’ SHOWN NOT RIGHT
 26150496 Р: LONG LINE IS WRAPPED WITH BLANK EXTRA LINE
 26121270 Р: PARSER BUG FOR XMLTABLE
 26108903 РNO BREAK AT THE END OF SELECT CLAUSE WITH CERTAIN OPTIONS
 26086483 РSQLCL INPUT DO NOT WANDER AROUND SCREEN E.G. ACCEPT/CONNECT SQLDEV-385
 25976240 РSET ERROR LOGGING NOT SUPPORTED IN THE SCRIPTRUNNER
 25689058 РSQLCL NOT ABLE TO CONNECT TO DB WHEN USING SECURE PASS STORE BUG SQLDEV-82
¬†25952884 – PARSER DOESN’T LIKE SELECT WITH (PLSQL) SQLDEV-340 -check in on 17.2 side
 25875722 РSQLCL: PARSE ERROR WHILE USING FORMAT COMMAND FOR A VALID SQL FILE
¬†25519246 – FORMATTER DOESN’T UNDERSTAND $IF $ELSIF $ELSE
 25707227 РTHE EXAMPLE URL WHEN SPECIFY TEMPLATE SHOULD INCLUDE SCHEMA NAME AND HOST NAME
 25931871 Р: AFTER FORMATTING EDITOR SELECTED TEXT CURSOR JUMPS TO LINE 1
 25911214 Р: FORMAT OPTIONS ARE BLANK
 25860843 РSQLCL: DDL WHEN REDISPLAYED ELIMINATES BLANK LINES

 

Gather Statistics

I have given a presentation about my favourite SQL Developer features several times but those features just keep adding up… Here’s one more (I guess there will be more coming ūüėÄ ).

I needed to test something quickly and part of the test was also gathering the statistics. I was just curious to see if I can do that using SQL Developer (I always do it on command line) and of course I can!

Right-click the table name in the Browser, select Statistics and Gather Statistics.

statistics1

Define the parameters and press OK.

statistics2.jpg

 

statistics3

DONE!

If you want to be sure, go and check the Statistics tab:

statistics4

 

 

 

Data Modeler 4.2

The 4.2 version of Data Modeler is out: http://www.oracle.com/technetwork/developer-tools/datamodeler/downloads/index.html

New features (http://www.oracle.com/technetwork/developer-tools/datamodeler/downloads/dm-newfeatures-42-3220396.html):

Import from Oracle Database

  • ¬†Support for Oracle Database 12c Release 2
  • ¬†Performance and filtering enhancements
  • ¬†Ability to define Oracle Client for thick connections
  • ¬†View and materialized view driving query and columns now parsed and validated during import

General

    • ¬†Better management of change requests
    • ¬†Design rules can be invoked directly on Subview or selection of objects
    • ¬†More formats are supported in export/import functionality for glossaries
    • ¬†Improvements in performance
    • ¬†New models are shown as a single node in pending changes window

 

Diagrams

    • ¬†Print diagrams to SVG and HTML/SVG file – for logical and relational model diagrams
    • ¬†Better handling of labels in Logical model diagrams

 

Versioning

    • ¬†Improvements in performance
    • ¬†Removed usage of SVN properties as additional metadata layer
    • ¬†Git supported for design repository via ‘git svn’ – Modeler will use SVN calls against your Git repository

 

Reporting

  • ¬†PDF diagrams can be embed into PDF report
  • ¬†SVG diagrams can be embed in HTML reports
  • ¬†External CSS file is used for formatting

Bugs fixed (http://www.oracle.com/technetwork/developer-tools/datamodeler/downloads/dm-bugsfixed-42-3418891.html):

25407455 – DDL GENERATION CREATES WRONG FILENAMES FOR SPECIFIC OBJECTS
25427960 – COLOR SETTING FOR TRANSPARENCY IS LOST AFTER MODEL IS RELOADED
25428000 – COLOR SETTING FOR FK LINE ARE LOST WHEN THAT FK HAS PRESENTATION IN SUBVIEW
25461330 – COMPARE MODELS DIALOG DOESN’T RETAIN SELECTION AFTER REFRESH TREE PRESSED
25584892 – VIEW HEADER COLUMNS LIST DROPPED AFTER VALIDATING VIEW
25590365 – CLASSCASTEXCEPTION WHEN USING “MAC OS X” LOOK AND FEEL
25610620 – DM DOES NOT MARK FOREIGN KEYS AS CHANGED BUT AS NEW

Defining the tablespace for several objects at the same time

I have hundreds of indexes and I need to define the tablespace for them. Do I need to do it manually, one by one? No ūüôā

 

First define the tablespace you want to set for the indexes:

prop1

Then select one of the indexes and set the Tablespace Property:

prop2

Press Apply.

Press Propagate Properties.

prop3

In the Properties section press Deselect All. Select Tablespace.

In the Object section press Select All.

prop4

Press OK.

 

Now the tablespace for all indexes has been set as Index_Tablespace1.

 

 

 

 

How to define an identity column?

I want to define an identity column and set the Auto Increment properties. How can I do that?

This definition can be made in the relational model. Select the primary key column and go to the Column Properties (the XYZ and a pen icon).

identity_1

In General tab select Indentity Column and Auto Increment.

Then select the Auto Increment tab:

identoty_column2

And set the properties as wanted.

Now if you generate the DDL this is what you get:

identity_2