Object Relational Mapping Layer



Ähnliche Dokumente
Object Relational Mapping Layer

Hochschule Karlsruhe Technik und Wirtschaft Anhänge: Fakultät für Informatik und Wirtschaftsinformatik SS 2013 Prof. Schmidt.

Tutorium zum Aufbau einer objektrelationalen Abbildungsschicht in PHP (Version 2.8 vom )

Datenbanken SQL Einführung Datenbank in MySQL einrichten mit PhpMyAdmin

Object Relational Mapping Layer

SQL für Trolle. mag.e. Dienstag, Qt-Seminar

Tutorium zum Aufbau einer objektrelationalen Abbildungsschicht in PHP (Version 4.4 vom )

Aufgaben eines Codegenerators

Installation MySQL Replikationsserver

Modell/Metamodell. Generated Source Code. Generator. Model. Fakultät für Informatik und Wirtschaftsinformatik MDSD - SS 2014

Referenzielle Integrität SQL

Die Datenmanipulationssprache SQL

7. Datenbank-Zugriff. Vorlesung und Übung Dr. Peter Pfahler Institut für Informatik Universität Paderborn. Zum Beispiel aus PHP-Skripten: Client 7-2

Übungsblatt 8- Lösungsvorschlag

SQL und MySQL. Kristian Köhntopp

Datenbanken und Informationssysteme II

Java Application 1 Java Application 2. JDBC DriverManager. JDBC-ODBC Br idge. ODBC Driver Manager. Dr iver C. Dr iver D.

SQL structured query language

Datenbanken und Informationssysteme II

MySQL Queries on "Nmap Results"

Probeklausur Datenbanken und Informationssysteme II

Fakultät für Informatik & Wirtschaftsinformatik DB & IS II - SS Metadaten

DB2 SQL, der Systemkatalog & Aktive Datenbanken

PHP und MySQL. Integration von MySQL in PHP. Zellescher Weg 12 Willers-Bau A109 Tel Michael Kluge (michael.kluge@tu-dresden.

MySQL 101 Wie man einen MySQL-Server am besten absichert

Einführung in die Informatik II

Interaktive Webseiten mit PHP und MySQL

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

Präsentation mongodb. David Wild

DATENBANKEN SQL UND SQLITE VON MELANIE SCHLIEBENER

Order Ansicht Inhalt

ORM & OLAP. Object-oriented Enterprise Application Programming Model for In-Memory Databases. Sebastian Oergel

Einstieg in das SQL- und Datenbanktuning Loblied auf den Tabellen-Index!

SQL Tutorial. SQL - Tutorial SS 06. Hubert Baumgartner. INSO - Industrial Software

Praktische SQL-Befehle

MySQL: Einfaches Rechnen.

MySQL 5.7 JSON und GIS

Datenbanken: Datenintegrität.

PostgreSQL in großen Installationen

Informatik für Ökonomen II: Datenintegrität. Prof. Dr. Carl-Christian Kanne

Relationales Modell: SQL-DDL. SQL als Definitionssprache. 7. Datenbankdefinitionssprachen. Anforderungen an eine relationale DDL

Fakultät für Informatik & Wirtschaftsinformatik DB & IS II SS 2015 PHP. Object Relational Mapping Layer. Dr. Christian Senger PHP & ORM 1

Datenbanken und Informationssysteme II

NoSQL mit Postgres 15. Juni 2015

Web Technologien Klassische Datenbanken am Beispiel von MySQL

Datenintegrität. Bisherige Integritätsbedingungen

Referentielle Integrität

Allgemeines. veröffentlicht unter lizensiert unter. Creative Commons BY-SA 3.0. XQuery in MS SQL Server 2005

Einführung in SQL. Sprachumfang: Indizes. Datensätzen. Zugriffsrechten

SQL: statische Integrität

Datenbanken und Informationssysteme II (PO B.3)

PostgreSQL unter Debian Linux

Übung PL/SQL Trigger Lösungen

Referentielle Integrität

Relationales Datenbanksystem Oracle

Persistenz von Objekten relationale Datenbank Eigene Datenstruktur XML (JAXB) Proprietäre Dateiformate (Lochkarten)

Multimedia im Netz. Übung zur Vorlesung. Ludwig-Maximilians-Universität Wintersemester 2010/2011

SQL. Allgemeines CREATE TABLE DROP TABLE ALTER TABLE INSERT INTO UPADTE DELETE SELECT

Javadoc. Programmiermethodik. Eva Zangerle Universität Innsbruck

Transaktionen in der Praxis. Dr. Karsten Tolle

Indexing und Performance Tuning

Introduction to Data and Knowledge Engineering. 6. Übung SQL

MySQL 5.1. Kristian Köhntopp

Grails. Weiterführende Themen zu Internet- und WWW-Technologien. Matthias Springer. 06. Juni 2011

Mengenvergleiche: Alle Konten außer das, mit dem größten Saldo.

Datenbanksysteme I. Klausur zum Praktikum. Mehrere Professoren prüfen mit genau einem Beisitzer genau einen Studenten.

SQL. SQL: Structured Query Language. Früherer Name: SEQUEL. Standardisierte Anfragesprache für relationale DBMS: SQL-89, SQL-92, SQL-99

Fakultät für Informatik & Wirtschaftsinformatik DB & IS II SS 2015 PHP MVC. Dr. Christian Senger. PHP MVC 1 von 21

Datenbanken und Informationssysteme II (PO B.4)

Willkommen. Datenbanken und Anbindung

Enterprise java beans step-by-step

Oracle: Abstrakte Datentypen:

Analyse und praktischer Vergleich von neuen Access- Layer-Technologien in modernen Webanwendungen unter Java. Oliver Kalz

Übung 01 Tabellen erstellen

Universität Augsburg, Institut für Informatik WS 2006/2007 Dr. W.-T. Balke 11. Dez M. Endres, A. Huhn, T. Preisinger Lösungsblatt 7

Architektur des agimatec-validation Frameworks

php Hier soll ein Überblick über das Erstellen von php Programmen gegeben werden. Inhaltsverzeichnis 1.Überblick Parameterübergabe...

Partitionieren über Rechnergrenzen hinweg

Anwendungsentwicklung Datenbanken SQL. Stefan Goebel

Übung Datenbanken in der Praxis. Datenmodifikation mit SQL

IV. Datenbankmanagement

Labor 3 - Datenbank mit MySQL

Universität Augsburg, Institut für Informatik WS 2006/2007 Dr. W.-T. Balke 27. Nov M. Endres, A. Huhn, T. Preisinger Lösungsblatt 5

Grundlagen von Datenbanken

Ich liebe Java && Ich liebe C# Rolf Borst

Programmentwicklung ohne BlueJ

PHP + MySQL. Die MySQL-Datenbank. Hochschule Karlsruhe Technik & Wirtschaft Internet-Technologien T3B250 SS2014 Prof. Dipl.-Ing.

Datenbanken. Zusammenfassung. Datenbanksysteme

7. Datenbank-Zugriff. Vorlesung und Übung Dr. Peter Pfahler Institut für Informatik Universität Paderborn. Zum Beispiel aus PHP-Skripten: Client 7-2

Whitepaper. Produkt: combit Relationship Manager. Datensatzhistorie mit dem SQL Server 2000 und combit GmbH Untere Laube Konstanz

sm-client Projekt Aktualisierungsinstruktionen für R2.0.4 Finale Version SSK / BSV eahv/iv

Grundkonzepte von SQL

Kapitel 33. Der xml-datentyp. In diesem Kapitel: Der xml-datentyp 996 Abfragen aus xml-datentypen 1001 XML-Indizierung 1017 Zusammenfassung 1023

XML in Oracle 12c. Wolfgang Nast

Datumsangaben, enthält mindestens Jahr, Monat, Tag

SQL-Befehlsliste. Vereinbarung über die Schreibweise

Transkript:

Object Relational Mapping Layer Views Controlers Business logic GUI OO-application logic Object-relational-Mapping Relational DBMS PHP (propel) 1/18

Propel - Persistance Layer OR-Mapper für PHP Portierung von Torgue (Turbine Framework, Java) Konfiguration der Abbildung durch XML-Datei Unterstützt aktuell Oracle, MySQL, SQL-Server, PostgeSQL Generiert OR-Schicht, Datenbankschema Unterstützt Basic CRUD-Funktionalität Simuliert Foreign-Key Constraints falls nicht von DB unterstützt Criteria Klasse für Anfragen an Datenbank Validatoren für Spalten definierbar (match, nomatch, maxlength, maxvalue, minlength, minvalue, validvalues,...) Unterstützt 1:1, 1:n Beziehungen, Vererbung PHP (propel) 2/18

Ablauf der Generierung Base<x>.php extends schema.xml propel-gen (falls nicht existent) <x>.php Base<x>Peer.php extends (falls nicht existent) build.properties schema.sql <x>peer.php PHP (propel) 3/18

Reverse Engineering existing schema propel-gen./ creole schema.xml PHP (propel) 4/18

Beispiel: build.properties # The name of the project propel.project = HappySail # The database driver propel.database = mysql propel.mysql.tabletype=innodb # Connection Information propel.database.url = mysql:host=localhost;dbname=happysail propel.database.user = propeltest propel.database.password = test PHP (propel) 5/18

Beispiel schema.xml <?xml version="1.0" encoding="iso-8859-1" standalone="no"?> <database name="happysail" defaultidmethod="native"> <table name="schiff"> <column name="id" type="integer" primarykey="true" autoincrement="true"/> <column name="name" type="varchar" size="40" required="true"/> <column name="laenge" type="integer" required="true"/> <column name="plaetze" type="integer" required="true"/> <column name="hafen_fk" type="integer"/> <foreign-key foreigntable="hafen" ondelete="set null"> <reference local="hafen_fk" foreign="id"/> </foreign-key> </table> <table name="hafen"> <column name="id" type="integer" primarykey="true" autoincrement="true"/> <column name="name" type="varchar" size="40" required="true"/> <column name="ort" type="varchar" size="40" required="true"/> <column name="anlegeplaetze" type="integer"/> </table> </database> PHP (propel) 6/18

Fakultät IWI generiertes Datenbankschema #------------------------------------------------------------ #-- schiff #------------------------------------------------------------ DROP TABLE IF EXISTS `schiff`; CREATE TABLE `schiff` ( `id` INTEGER NOT NULL AUTO_INCREMENT, `name` VARCHAR(40) NOT NULL, `laenge` INTEGER NOT NULL, `plaetze` INTEGER NOT NULL, `hafen_fk` INTEGER, PRIMARY KEY (`id`), INDEX `schiff_fi_1` (`hafen_fk`), CONSTRAINT `schiff_fk_1` FOREIGN KEY (`hafen_fk`) REFERENCES `hafen` (`id`) ON DELETE SET NULL )Type=InnoDB; #------------------------------------------------------------ #-- hafen #------------------------------------------------------------ DROP TABLE IF EXISTS `hafen`; CREATE TABLE `hafen` ( `id` INTEGER NOT NULL AUTO_INCREMENT, `name` VARCHAR(40) NOT NULL, `ort` VARCHAR(40) NOT NULL, `anlegeplaetze` INTEGER, PRIMARY KEY (`id`) )Type=InnoDB; PHP (propel) 7/18

generierte Klassen CRUD Klassen (werden immer neu generiert) build/classes/happysail/om/basehafen.php build/classes/happysail/om/basehafenpeer.php build/classes/happysail/om/baseschiff.php build/classes/happysail/om/baseschiffpeer.php Applikationslogik Stubs (werden nur beim ersten mal generiert) build/classes/happysail/hafen.php build/classes/happysail/hafenpeer.php build/classes/happysail/schiff.php build/classes/happysail/schiffpeer.php PHP (propel) 8/18

BaseSchiff.php Variablenübersicht: $ grep protected build/classes/happysail/om/baseschiff.php grep -v function protected static $peer; protected $id; protected $name; protected $laenge; protected $plaetze; protected $hafen_fk; protected $ahafen; protected $alreadyinsave = false; protected $alreadyinvalidation = false; protected $validationfailures = array(); Foreign Key auf Hafen Datensatz Hafen Instanz alle Zeilen in denen das Wort protected vorkommt alle Zeilen in denen das Wort function nicht vorkommt PHP (propel) 9/18

Fakultät IWI BaseSchiff.php Methodenübersicht: $ grep function build/classes/happysail/om/baseschiff.php public function construct() public function getid() public function getname() public function getlaenge() public function getplaetze() public function gethafenfk() public function setid($v) public function setname($v) public function setlaenge($v) public function setplaetze($v) public function sethafenfk($v) public function delete(propelpdo $con = null) public function save(propelpdo $con = null) protected function dosave(propelpdo $con) public function getvalidationfailures() public function validate($columns = null) public function getprimarykey() public function setprimarykey($key) public function copyinto($copyobj, $deepcopy = false) public function copy($deepcopy = false) public function getpeer() public function sethafen(hafen $v = null) public function gethafen(propelpdo $con = null) PHP (propel) 10/18

Fakultät IWI BaseSchiffPeer.php $ grep function build/classes/happysail/om/baseschiffpeer.php... public static function addselectcolumns(criteria $criteria) public static function docount(criteria $criteria, $distinct = false, PropelPDO $con = null) public static function doselectone(criteria $criteria, PropelPDO $con =null) public static function doselect(criteria $criteria, PropelPDO $con = null) public static function doselectstmt(criteria $criteria, PropelPDO $con = null) public static function populateobjects(pdostatement $stmt) public static function docountjoinhafen(criteria $criteria, $distinct =false, PropelPDO $con = null, $join_behavior = Criteria::LEFT_JOIN) public static function doselectjoinhafen(criteria $c, $con = null, $join_behavior = Criteria::LEFT_JOIN) public static function docountjoinall(criteria $criteria, $distinct = false, PropelPDO $con = null, $join_behavior = Criteria::LEFT_JOIN) public static function doselectjoinall(criteria $c, $con = null, $join_behavior = Criteria::LEFT_JOIN) public static function doinsert($values, PropelPDO $con = null) public static function doupdate($values, PropelPDO $con = null) public static function dodeleteall($con = null) public static function dodelete($values, PropelPDO $con = null) public static function dovalidate(schiff $obj, $cols = null) public static function retrievebypk($pk, PropelPDO $con = null) public static function retrievebypks($pks, PropelPDO $con = null)... PHP (propel) 11/18

Hafen.php <?php require 'HappySail/om/BaseHafen.php'; /** * Skeleton subclass for representing a row from the 'hafen' table. * @package HappySail */ class Hafen extends BaseHafen { /** * Initializes internal state of Hafen object. * @see parent:: construct() */ public function construct() { // Make sure that parent constructor is always invoked, since that // is where any default values for this object are set. parent:: construct(); } } // Hafen PHP (propel) 12/18

HafenPeer.php <?php require 'HappySail/om/BaseHafenPeer.php'; /** * Skeleton subclass for performing query and update operations on the 'hafen' table. * You should add additional methods to this class to meet the * application requirements. This class will only be generated as * long as it does not already exist in the output directory. * * @package HappySail */ class HafenPeer extends BaseHafenPeer { } // HafenPeer PHP (propel) 13/18

Beispielprogramm Propel::init("./build/conf/HappySail-conf.php"); $hafen1 = new Hafen(); $hafen1->setname("marina Bas du Fort"); $hafen1->setort("point a Pitre (Guadeloupe)"); $hafen1->setanlegeplaetze(450); $hafen1->save(); $hafen2 = new Hafen(); $hafen2->setname("marine de Cocolin"); $hafen2->setort("cogolin"); $hafen2->setanlegeplaetze(760); $hafen2->save(); $schiff1 = new Schiff(); $schiff1->setname("fury"); $schiff1->setlaenge("12.5"); $schiff1->setplaetze(7); $schiff1->sethafen($hafen1); $schiff1->save(); PHP (propel) 14/18

Beispielprogramm (fortsetzung) $schiff2 = new Schiff(); $schiff2->setname("zampallo III"); $schiff2->setlaenge("10.5"); $schiff2->setplaetze(6); $schiff2->sethafen($hafen2); $schiff2->save(); $schiff3 = new Schiff();... echo "\nalle Schiffe mit Heimathafen Cocolin:\n"; $list = $hafen2->getschiffs(); foreach ($list as $ship) echo " ".$ship->getname()."\n"; echo "\nalle Schiffe mit mehr als 6 Plätzen\n"; $crit = new Criteria(); $crit->add(schiffpeer::plaetze,6,criteria::greater_than); foreach (SchiffPeer::doSelect($crit) as $s) echo " ",$s->getname()," (",$s->getplaetze()," Plätze) Heimathafen: ", $s->gethafen()->getname()."\n";?> PHP (propel) 15/18

c:/programme/php/php.exe test-run.php Alle Schiffe mit Heimathafen Cocolin: Zampallo III 13 pfeifende Schweine Alle Schiffe mit mehr als 6 Plätzen Fury (7 Plätze) Heimathafen: Marina Bas du Fort 13 pfeifende Schweine (9 Plätze) Heimathafen: Marine de Cocolin PHP (propel) 16/18

Datenbankeinträge $ c:/programme/mysql/bin/mysql.exe -u root HappySail mysql> select * from schiff; +----+-----------------------+--------+---------+----------+ id name laenge plaetze hafen_fk +----+-----------------------+--------+---------+----------+ 18 Fury 12 7 13 19 Zampallo III 10 6 14 20 13 pfeifende Schweine 16 9 14 +----+-----------------------+--------+---------+----------+ 3 rows in set (0.00 sec) mysql> select * from hafen; +----+--------------------+----------------------------+---------------+ id name ort anlegeplaetze +----+--------------------+----------------------------+---------------+ 13 Marina Bas du Fort Point a Pitre (Guadeloupe) 450 14 Marine de Cocolin Cogolin 760 +----+--------------------+----------------------------+---------------+ 2 rows in set (0.00 sec) PHP (propel) 17/18

Literaturhinweise http://www.propelorm.org/documentation/ Anderer bekannter OR-Mapper für PHP: http://www.doctrine-project.org/ PHP (propel) 18/18