the power of the oracle apex repository patrick wolf, sphinx it consulting doag sig – apex für...

37
The Power of the Oracle APEX Repository Patrick Wolf, Sphinx IT Consulting DOAG SIG – APEX für Fortgeschrittene, 31.05.2007

Upload: feirefiz-lauser

Post on 05-Apr-2015

133 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: The Power of the Oracle APEX Repository Patrick Wolf, Sphinx IT Consulting DOAG SIG – APEX für Fortgeschrittene, 31.05.2007

The Power of theOracle APEX Repository

Patrick Wolf, Sphinx IT ConsultingDOAG SIG – APEX für Fortgeschrittene, 31.05.2007

Page 2: The Power of the Oracle APEX Repository Patrick Wolf, Sphinx IT Consulting DOAG SIG – APEX für Fortgeschrittene, 31.05.2007

Über Sphinx IT Consulting• Gegründet 1993• Erstellung von Individualsoftware• Consulting im Bereich Datenbanken & Java Middleware • Spezialist im Oracle Umfeld• Weitere Informationen auf http://www.sphinx.at/

Über Patrick Wolf• 13 Jahre Oracle Erfahrung in SQL, PL/SQL und Oracle

Forms• Solution Architect bei Sphinx IT Consulting• Betreibt einen APEX Blog – http://inside-apex.blogspot.

com• Autor des ApexLib Frameworks – http://apexlib.

sourceforge.net/• Autor des Oracle APEX Builder Plugins• Zu erreichen unter [email protected]

Page 3: The Power of the Oracle APEX Repository Patrick Wolf, Sphinx IT Consulting DOAG SIG – APEX für Fortgeschrittene, 31.05.2007

Agenda• Das Oracle APEX Repository• Teil 1 - Die APEX Dictionary Views

– Einfache Auswertungen– Automatische Dokumentation erstellen– APEX Applikation überwachen– Generischen Code mithilfe des Repositories erstellen

• Teil 2 – APEX Repository direkt manipulieren– Massenupdates im Repository durchführen– Neue Page Items, ... erstellen

• Fragen & Antworten

Page 4: The Power of the Oracle APEX Repository Patrick Wolf, Sphinx IT Consulting DOAG SIG – APEX für Fortgeschrittene, 31.05.2007

Das Oracle APEX Repository• Oracle APEX speichert alle Meta-Daten zu einer

Applikation in einem Repository in der Datenbank

– Schema FLOWS_xxx (zB.: FLOWS_030000)

– Tabellen beginnen mit WWV_FLOW_*

– Diese Tabellen sind aber (leider) nicht öffentlich.

• Seit Version 2.2 gibt es eine View Schicht.

• Die Views haben als Präfix APEX_*

• Seit 3.0 gibt es auch eine Oberfläche für einfache Abfragen. Zu finden unter Utilities/APEX Dictionary

Page 5: The Power of the Oracle APEX Repository Patrick Wolf, Sphinx IT Consulting DOAG SIG – APEX für Fortgeschrittene, 31.05.2007

Die APEX Dictionary Views• Zeigen eine „lesbare“ Form der internen APEX Repository

Tabellen– Kaschieren das weitgehend generischere/alte Datenmodell– Machen Lookups für einige Foreign-Keys– Übersetzen interne Enumerations ins Englische– Beinhalten teilweise Statistikwerte – z.B. Anzahl

Kindelemente– Berücksichtigen Zugriffsrechte (man sieht nur die Daten

seiner Applikationen)• Als Schema User: Alle Applikationen der Workspaces

denen das Schema zugeordnet ist.• Als SYS, SYSTEM, FLOWS_xxx: Alle Applikationen• Anderer User: Nichts

• Sind Public und können daher sowohl in APEX Applikationen verwendet werden als auch in externen Scripts.

Page 6: The Power of the Oracle APEX Repository Patrick Wolf, Sphinx IT Consulting DOAG SIG – APEX für Fortgeschrittene, 31.05.2007

Die APEX Dictionary Views

Page 7: The Power of the Oracle APEX Repository Patrick Wolf, Sphinx IT Consulting DOAG SIG – APEX für Fortgeschrittene, 31.05.2007

Tree Ansicht auswählen

Die APEX Dictionary Views

Page 8: The Power of the Oracle APEX Repository Patrick Wolf, Sphinx IT Consulting DOAG SIG – APEX für Fortgeschrittene, 31.05.2007

Hierarchische Darstellung

Die APEX Dictionary Views

Page 9: The Power of the Oracle APEX Repository Patrick Wolf, Sphinx IT Consulting DOAG SIG – APEX für Fortgeschrittene, 31.05.2007

Die APEX Dictionary Views

Dokumentation jeder Spalte

Page 10: The Power of the Oracle APEX Repository Patrick Wolf, Sphinx IT Consulting DOAG SIG – APEX für Fortgeschrittene, 31.05.2007

Die APEX Dictionary Views

Page 11: The Power of the Oracle APEX Repository Patrick Wolf, Sphinx IT Consulting DOAG SIG – APEX für Fortgeschrittene, 31.05.2007

Hochkomma nichtvergessen!

Zum Ausführen„Go“ Button amSeitenanfangdrücken

Die APEX Dictionary Views

Page 12: The Power of the Oracle APEX Repository Patrick Wolf, Sphinx IT Consulting DOAG SIG – APEX für Fortgeschrittene, 31.05.2007

Die APEX Dictionary Views• Unterteilen sich in 3 Bereiche

– Applikations-Meta-Daten• APEX_APPLICATION*

– Monitoring Daten zu den Applikationen• APEX_WORKSPACE_ACCESS_LOG• APEX_WORKSPACE_ACTIVITY_LOG• APEX_WORKSPACE_LOG_SUMMARY*• APEX_WORKSPACE_CLICKS• APEX_WORKSPACE_SESSIONS

– Workspace-Meta-Daten• Die restlichen APEX_WORKSPACE* Views wie z.B.

APEX_WORKSPACE_APEX_USERS, ...

Page 13: The Power of the Oracle APEX Repository Patrick Wolf, Sphinx IT Consulting DOAG SIG – APEX für Fortgeschrittene, 31.05.2007

Die APEX Dictionary Views• Wozu kann man diese Views jetzt verwenden?• Ein paar Beispiele

– Überprüfung von Codierrichtlinien– Dynamische Generierung von Site-Maps– Automatische Dokumentation der Applikation– Automatische Überwachung der Applikation– Ein paar nette Charts für Zugriffsstatistiken– Zur Erstellung von generischen Code– Und so weiter...

Page 14: The Power of the Oracle APEX Repository Patrick Wolf, Sphinx IT Consulting DOAG SIG – APEX für Fortgeschrittene, 31.05.2007

Überprüfung von Codierrichtlinien 1

• Bei Page Items soll NICHT das „xxx Label with Help“ Label Template verwendet werden.

SELECT APPLICATION_NAME , PAGE_ID , ITEM_NAME , DISPLAY_AS , ITEM_LABEL_TEMPLATE FROM APEX_APPLICATION_PAGE_ITEMS WHERE ITEM_LABEL_TEMPLATE LIKE '%Label with Help' AND DISPLAY_AS <> 'Hidden' ORDER BY APPLICATION_NAME , PAGE_ID , ITEM_NAME;

Page 15: The Power of the Oracle APEX Repository Patrick Wolf, Sphinx IT Consulting DOAG SIG – APEX für Fortgeschrittene, 31.05.2007

Überprüfung von Codierrichtlinien 2

• Wurden alle Labels linksbündig ausgerichtet?

SELECT APPLICATION_NAME , PAGE_ID , ITEM_NAME , DISPLAY_AS , LABEL_ALIGNMENT FROM APEX_APPLICATION_PAGE_ITEMS WHERE LABEL_ALIGNMENT <> 'Left' AND DISPLAY_AS <> 'Hidden' ORDER BY APPLICATION_NAME , PAGE_ID , ITEM_NAME;

Page 16: The Power of the Oracle APEX Repository Patrick Wolf, Sphinx IT Consulting DOAG SIG – APEX für Fortgeschrittene, 31.05.2007

Überprüfung von Codierrichtlinien 3

• Wurden für alle Felder Hilfetexte erfasst, dort wo das „xxx Label with Help“ Template verwendet wurde?

SELECT APPLICATION_NAME , PAGE_ID , ITEM_NAME , DISPLAY_AS FROM APEX_APPLICATION_PAGE_ITEMS WHERE ITEM_LABEL_TEMPLATE LIKE '%Label with Help' AND DISPLAY_AS <> 'Hidden' AND ITEM_HELP_TEXT IS NULL ORDER BY APPLICATION_NAME , PAGE_ID , ITEM_NAME;

Page 17: The Power of the Oracle APEX Repository Patrick Wolf, Sphinx IT Consulting DOAG SIG – APEX für Fortgeschrittene, 31.05.2007

Dynamische Site-Maps• Eine automatisch generierte Site-Map in die Applikation

einbauen.• Relevante Seiten im Seiten Kommentar mit $SITEMAP$

markieren.SELECT PAGE_ID , PAGE_TITLE , PAGE_GROUP FROM APEX_APPLICATION_PAGES WHERE APPLICATION_ID = :APP_ID AND INSTR(PAGE_COMMENT, '$SITEMAP$') > 0 ORDER BY PAGE_TITLE;

• SQL Report mit obigem SQL Statement erstellen.• Bei der Spalte „PAGE_TITLE“ den Link Text auf

#PAGE_TITLE# und Page auf #PAGE_ID# setzen.• Die Spalte „PAGE_ID“ auf „Hidden“ setzen.• Mit Page Groups könnte das ganze Hierarchisch in einem

Tree angezeigt werden...

Page 18: The Power of the Oracle APEX Repository Patrick Wolf, Sphinx IT Consulting DOAG SIG – APEX für Fortgeschrittene, 31.05.2007

Automatische Dokumentation• Wäre es nicht nett, manchmal den Page Flow einer

Applikation grafisch zu sehen? Welche Seite ruft welche Seite auf...

• Wie z.B. beim JDeveloper, wo es Page Flow Seite für JSF Applikationen gibt, die jedoch manuell erstellt werden muss.

• Um Gegensatz zu anderen Entwicklungsumgebungen, wo das vielleicht irgendwo in XML Dateien oder in Java/... Code gespeichert ist, haben wir alles über einfache SQL Abfragen im Zugriff!

• Mithilfe von Graphviz, einem Open Source Tool, ist eine grafische Ausgabe kein Problem.

Page 19: The Power of the Oracle APEX Repository Patrick Wolf, Sphinx IT Consulting DOAG SIG – APEX für Fortgeschrittene, 31.05.2007

Page Flow Generator• Analysiert die Meta-Daten einer Applikation wie z.B.

Pages, Branches, Buttons, Links- in Report Columns, HTML Regions und SQL Statements.

• Erstellt ein Beziehungsmodell im Memory und• erstellt für jede Page Group ein eigenes Diagram, damit

es übersichtlicht bleibt.• Das komplizierte daran war Graphviz Syntax• Der Page Flow Generator ist Teil des ApexLib Frameworks.

Page 20: The Power of the Oracle APEX Repository Patrick Wolf, Sphinx IT Consulting DOAG SIG – APEX für Fortgeschrittene, 31.05.2007
Page 21: The Power of the Oracle APEX Repository Patrick Wolf, Sphinx IT Consulting DOAG SIG – APEX für Fortgeschrittene, 31.05.2007

APEX Applikationen überwachen 1

• Wäre es nicht schön, bei Fehlern in der Applikation automatisch informiert zu werden, dass etwas schief gelaufen ist?

• APEX bietet dazu die View APEX_WORKSPACE_ACTIVITY_LOG und die Spalte ERROR_MESSAGE gibt Auskunft über etwaige Fehler.

• Ein DBMS_JOB kann dazu verwendet werden um sie periodisch abzufragen.

• Siehe dazu Blog Eintrag auf http://oraclequirks.blogspot.com/2007/05/simple-pager-for-apex-30.html

• Und mit http://inside-apex.blogspot.com/2007/05/sending-sms-to-mobile-phone.html kann man auch eine SMS verschicken.

Page 22: The Power of the Oracle APEX Repository Patrick Wolf, Sphinx IT Consulting DOAG SIG – APEX für Fortgeschrittene, 31.05.2007

APEX Applikationen überwachen 2

• Wie können Einbruchsversuche erkannt werden?• Die View APEX_WORKSPACE_ACCESS_LOG protokolliert

jeden Login Versuch mit– Zeitpunkt– Usernamen– IP Adresse– Ergebnis – Erfolgreich/Nicht Erfolgreich

Page 23: The Power of the Oracle APEX Repository Patrick Wolf, Sphinx IT Consulting DOAG SIG – APEX für Fortgeschrittene, 31.05.2007

APEX Applikationen überwachen 3

• Wie kann erkannt werden, dass sich die Response Time der Applikation verschlechtert?

• Die View APEX_WORKSPACE_ACTIVITY_LOG protokolliert jeden Seitenaufruf und ELAPSED_TIME gibt Aufschluss über die Zeit welche APEX für die Seitengenerierung benötigt hat.

• Kombiniert mit Historischen Daten und der Anzahl User, die gleichzeitig Abfragen gemacht haben, kann man Trends ermitteln.

• Mit der View kann man auch eine Analyse des Navigationsver-haltens der Benutzer machen. Siehe dazu auch die Spalte THINK_TIME

• Oder eine Abfrage, welche Seiten nie in Verwendung sind.• Und so weiter...

Page 24: The Power of the Oracle APEX Repository Patrick Wolf, Sphinx IT Consulting DOAG SIG – APEX für Fortgeschrittene, 31.05.2007

Generischen Code erstellen 1• Schon mal das Problem gehabt, eine Seite zu haben, wo

mehrere Page Items durchnummeriert sind und die gleichen Überprü-fungen haben? Haben Sie für jedes Feld die gleiche Validierung erstellt?

• Es geht auch anders und mit wesentlich weniger Aufwand!BEGIN FOR rITEM IN ( SELECT ITEM_NAME FROM APEX_APPLICATION_PAGE_ITEMS WHERE APPLICATION_ID = :APP_ID AND PAGE_ID = :PAGE_ID AND ITEM_NAME LIKE 'P'||:PAGE_ID||'_VALUE%' ) LOOP IF V(rITEM.ITEM_NAME) IS NOT NULL THEN APEX_Util.set_session_state ( p_name => rITEM.ITEM_NAME , p_value => 1 ); END IF; END IF;END;

Page 25: The Power of the Oracle APEX Repository Patrick Wolf, Sphinx IT Consulting DOAG SIG – APEX für Fortgeschrittene, 31.05.2007

Generischen Code erstellen 2• Schon mal abhängige/hierarchische LOVs benötigt?• Für jede LOV das AJAX Beispiel vom Carl Backstom (http://

carlback.blogspot.com/) implementiert?• Provokante Frage: Ist nicht eigentlich schon alles in den

Meta-Daten der entsprechenden Page Items vorhanden? Die WHERE Clause der LOVs enthält doch alle Abhängigkeiten!

• Warum verwenden wir sie nicht, anstatt Code und Informationen zu duplizieren?

• Genau das macht der Open Source ApexLib Framework (http://apexlib.sourceforge.net/)!

• Kurze Demonstration des Frameworks

Page 26: The Power of the Oracle APEX Repository Patrick Wolf, Sphinx IT Consulting DOAG SIG – APEX für Fortgeschrittene, 31.05.2007

APEX Dictionary Views - Conclusio

• Sind ein mächtiges Werkzeug mit dem man seine Applikationen oder die Entwicklung vereinfachen/verbessern kann.

• Viele Anwendungsmöglichkeiten, man braucht nur ein paar gute Ideen.

• Verwenden Sie den APEX Dictionary View Browser, um sich damit vertraut zu machen!

• Ab Oracle APEX Version 2.2 verfügbar.

Page 27: The Power of the Oracle APEX Repository Patrick Wolf, Sphinx IT Consulting DOAG SIG – APEX für Fortgeschrittene, 31.05.2007

APEX Repository direkt manipulieren

• Haben Sie schon einmal die Anforderung gehabt, größere Änderungen in einer Applikation durchführen zu wollen? z.B. bei allen Feldern das Label Template auf „ohne Hilfe“ umzustellen.

• Oder per eigenem Code neue Page Items, ... zu erstellen. Sozusagen ein eigener Wizard.

• Oracle APEX bietet leider keine Tools, mit dem obige Anforderungen offiziell umgesetzt werden können.

• Aber wenn schon alle Meta-Daten der Applikation in der Datenbank sind ...

• Der Versuch eines direkten Updates in den Repository Tabellen kann sehr ernüchternd sein. Die Applikation ist danach auf einmal nicht mehr zugreifbar!

• Wie geht es also richtig?

Page 28: The Power of the Oracle APEX Repository Patrick Wolf, Sphinx IT Consulting DOAG SIG – APEX für Fortgeschrittene, 31.05.2007

APEX Repository direkt manipulieren

BACKUP, BACKUP, BACKUP!!!

• Machen Sie bevor Sie das Repository selbst manipulieren ein Backup/Export Ihres FLOW_XXX Schemas. Zumindest einen Export Ihrer Applikation!

• Die Anwendung der nachfolgenden Tipps geschieht aufeigene Gefahr !

Page 29: The Power of the Oracle APEX Repository Patrick Wolf, Sphinx IT Consulting DOAG SIG – APEX für Fortgeschrittene, 31.05.2007

APEX Repository direkt manipulieren

• Manipulation erfolgt unter dem FLOWS_xxx (z.B. FLOWS_030000) User Account.

• Die Tabellen beginnen mit WWV_FLOW*• Tabellen und Spalten sind am einfachsten über die APEX

Dictionary Views identifizierbar.• Referenz Datensatz erstellen z.B. mit dem neuen Label

Template• APEX Kontext mit

WWV_Flow_API.set_security_group_idsetzen.

• Was ist die Security Group ID?– Entspricht der Workspace ID und kann über Apex_Util.get_security_group_id(`Workspacename`)ermittelt werden.

Page 30: The Power of the Oracle APEX Repository Patrick Wolf, Sphinx IT Consulting DOAG SIG – APEX für Fortgeschrittene, 31.05.2007

APEX Repository direkt manipulieren

DECLARE vSecurityGroupId NUMBER;BEGIN vSecurityGroupId := Apex_Util.find_security_group_id ( p_workspace => 'SPHINX_SXSD' ); IF vSecurityGroupId = 0 THEN RAISE_APPLICATION_ERROR ( -20111 , 'Workspace not found! Do not issue updates' ); END IF; -- WWV_Flow_Api.set_security_group_id(vSecurityGroupId); WWV_Flow.g_user := 'PWOLF';END;

• Beispiel zum initialisieren des APEX Kontexts.

Page 31: The Power of the Oracle APEX Repository Patrick Wolf, Sphinx IT Consulting DOAG SIG – APEX für Fortgeschrittene, 31.05.2007

APEX Repository direkt manipulieren

• Beispiel, welches bei allen Page Items der Seite 4 das Label Template von „Optional Label with Help“ auf „Optional Label“ setzt.

UPDATE WWV_FLOW_STEP_ITEMS SET ITEM_FIELD_TEMPLATE = 6.61528317798547E18 WHERE FLOW_ID = 106 AND FLOW_STEP_ID = 4 AND ITEM_FIELD_TEMPLATE = 7.22798225629576E18;

FLOW_ID entspricht Application Id

FLOW_STEP_ID entspricht Page Id

Page 32: The Power of the Oracle APEX Repository Patrick Wolf, Sphinx IT Consulting DOAG SIG – APEX für Fortgeschrittene, 31.05.2007

APEX Repository direkt manipulieren

• Was kann man machen, wenn eine Applikation nach dem Update auf einmal verschwunden ist?– Die SECURITY_GROUP_ID in WWV_FLOWS überprüfen.– Ist sie 0, dann den APEX Kontext initialisieren und die

SECURITY_GROUP_ID im WWV_FLOWS wieder setzen.

UPDATE WWV_FLOWS SET SECURITY_GROUP_ID = NULL WHERE FLOW_ID = 106;

NULL wurde bewusst verwendet!

Page 33: The Power of the Oracle APEX Repository Patrick Wolf, Sphinx IT Consulting DOAG SIG – APEX für Fortgeschrittene, 31.05.2007

APEX Repository direkt manipulieren

• Wie können jetzt neue Page Items, ... angelegt werden?• APEX bietet dazu das öffentliche(!) Package

WWV_Flow_Api• Kann daher sowohl von einem Package im

Applikationsschema als auch von FLOWS_XXX aufgerufen werden.

• Beispiele gibt es genug, einfach einen Export einer Applikation machen.

• WWV_Flow_Api.g_id_offset wird dazu verwendet, um beim Import eindeutige IDs zu bekommen -> für unseren Fall nicht notwendig.

• Die nächste freie ID gibt es von WWV_Flow_Id.next_val.

Page 34: The Power of the Oracle APEX Repository Patrick Wolf, Sphinx IT Consulting DOAG SIG – APEX für Fortgeschrittene, 31.05.2007

APEX Repository direkt manipulieren

• Die folgenden Session Initialisierungsschritte sind nur notwendig wenn keine APEX Session vorhanden ist. z.B. wenn mit FLOWS_XXX connected wurde.

• APEX Kontext wie bei Update herstellen + folgenden Code ausführen

BEGIN SELECT VALUE INTO WWV_Flow_Api.g_nls_numeric_chars FROM NLS_SESSION_PARAMETERS WHERE PARAMETER = 'NLS_NUMERIC_CHARACTERS' ; EXECUTE IMMEDIATE 'ALTER SESSION SET NLS_NUMERIC_CHARACTERS=''.,'''; -- WWV_FLOW.g_browser_language := 'en'; WWV_Flow_Api.g_id_offset := 0;END;

Page 35: The Power of the Oracle APEX Repository Patrick Wolf, Sphinx IT Consulting DOAG SIG – APEX für Fortgeschrittene, 31.05.2007

APEX Repository direkt manipulieren

• Danach ganz einfach mit folgendem Codebeispiel ein Page Item erstellen.

DECLARE vPageItemId NUMBER;BEGIN WWV_Flow_Api.set_version ( WWV_Flow_Api.g_compatable_from_version ); WWV_Flow.g_flow_id := 100; -- Application Id -- vPageItemId := WWV_Flow_Id.next_val; -- WWV_Flow_Api.create_page_item ( p_id => vPageItemId , p_flow_id => WWV_Flow.g_flow_id , p_flow_step_id => 4 , p_name => 'P4_TESTIT' ... );END;

Page 36: The Power of the Oracle APEX Repository Patrick Wolf, Sphinx IT Consulting DOAG SIG – APEX für Fortgeschrittene, 31.05.2007

APEX Repository direkt manipulieren - Conclusio

• BACKUP, BACKUP, BACKUP!!!• Updates am besten direkt machen.• Immer Referenzdatensatz erstellen.• Inserts mit dem Package WWV_Flow_Api durchführen.• Applikations Export File gibt gute Beispiele vor.

Page 37: The Power of the Oracle APEX Repository Patrick Wolf, Sphinx IT Consulting DOAG SIG – APEX für Fortgeschrittene, 31.05.2007

Danke für die Aufmerksamkeit!

Haben Sie noch Fragen?