CERN/IT/DB Oracle C++ Call Interface Dirk Geppert IT/DB DB Workshop July 11-13, 2001.

Slides:



Advertisements
Similar presentations
Connecting to Databases. relational databases tables and relations accessed using SQL database -specific functionality –transaction processing commit.
Advertisements

Database Security and Auditing: Protecting Data Integrity and Accessibility Chapter 8 Application Data Auditing.
Database Security and Auditing: Protecting Data Integrity and Accessibility Chapter 8 Application Data Auditing.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 13 Introduction to SQL Programming Techniques.
Fast Track to ColdFusion 9. Getting Started with ColdFusion Understanding Dynamic Web Pages ColdFusion Benchmark Introducing the ColdFusion Language Introducing.
Oracle SQL*plus John Ortiz. Lecture 10SQL: Overview2 Overview  SQL: Structured Query Language, pronounced S. Q. L. or sequel.  A standard language for.
Adapted from Afyouni, Database Security and Auditing Database Application Auditing – Ch. 8.
Training - Day 3 OJB. What is OR Mapping? OR Mapping is the mapping of relational database tables to objects (Java Objects in our case) Many OR Mapping.
Dale Roberts 8/24/ Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
Advance Computer Programming Java Database Connectivity (JDBC) – In order to connect a Java application to a database, you need to use a JDBC driver. –
Getting connected.  Java application calls the JDBC library.  JDBC loads a driver which talks to the database.  We can change database engines without.
JDBC Vs. Java Blend Presentation by Gopal Manchikanti Shivakumar Balasubramanyam.
Database System Concepts and Architecture Lecture # 3 22 June 2012 National University of Computer and Emerging Sciences.
Chapter Oracle Server An Oracle Server consists of an Oracle database (stored data, control and log files.) The Server will support SQL to define.
I Copyright © 2004, Oracle. All rights reserved. Introduction.
Database Security and Auditing: Protecting Data Integrity and Accessibility Chapter 6 Virtual Private Databases.
Enterprise JavaBeans. What is EJB? l An EJB is a specialized, non-visual JavaBean that runs on a server. l EJB technology supports application development.
PL/SQLPL/SQL Oracle10g Developer: PL/SQL Programming Chapter 7 PL/SQL Packages.
1 Oracle Architectural Components. 1-2 Objectives Listing the structures involved in connecting a user to an Oracle server Listing the stages in processing.
Copyright  Oracle Corporation, All rights reserved. 1 Oracle Architectural Components.
ObjectStore Database System By C. Lamb, G Landis, J.Orenstein, L. Weinreb Presentation by Meghana Chemburkar December 4, 2002 Instructor: Dr.Vasilis Megalooikonomou.
Advanced SQL: Cursors & Stored Procedures
Lecture2: Database Environment Prepared by L. Nouf Almujally 1 Ref. Chapter2 Lecture2.
Hibernate 3.0. What is Hibernate Hibernate is a free, open source Java package that makes it easy to work with relational databases. Hibernate makes it.
DataMAPPER - Applied Database Tech. 이화여대 과학기술대학원 석사 3 학기 992COG08 김지혜.
A Brief Documentation.  Provides basic information about connection, server, and client.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Java Database Connectivity. Java and the database Database is used to store data. It is also known as persistent storage as the data is stored and can.
SQL Fundamentals  SQL: Structured Query Language is a simple and powerful language used to create, access, and manipulate data and structure in the database.
Copyright © 2002 ProsoftTraining. All rights reserved. Building Database Client Applications Using JDBC 2.0.
Creating and Maintaining Geographic Databases. Outline Definitions Characteristics of DBMS Types of database Relational model SQL Spatial databases.
1 Database Management Systems (DBMS). 2 Database Management Systems (DBMS) n Overview of: ä Database Management Components ä Database Systems Architecture.
INTRODUCTION TO DBS Database: a collection of data describing the activities of one or more related organizations DBMS: software designed to assist in.
JDBC. Java.sql.package The java.sql package contains various interfaces and classes used by the JDBC API. This collection of interfaces and classes enable.
Communicating with the Outside. Hardware [Processor(s), Disk(s), Memory] Operating System Concurrency ControlRecovery Storage Subsystem Indexes Query.
Apr. 8, 2002Calibration Database Browser Workshop1 Database Access Using D0OM H. Greenlee Calibration Database Browser Workshop Apr. 8, 2002.
Bernhard Düchting Principal Sales Consultant BU Database - Migration Oracle Germany.
Topic : Hibernate 1 Kaster Nurmukan. An ORM tool The problem fixed by ORM Advantage Hibernate Hibernate Basic –Hibernate sessionFactory –Hibernate Session.
Authorization in Oracle Part 1 Ji-WonMahesh. Sources Starting source: Starting source: Oracle Database – Security Guide Oracle Database – Security Guide.
SQL.. AN OVERVIEW lecture3 1. Overview of SQL 2  Query: allow questions to be asked of the data and display only the information required. It can include.
Access Databases from Java Programs via JDBC Tessema M. Mengistu Department of Computer Science Southern Illinois University Carbondale
Object storage and object interoperability
Basics of JDBC Session 14.
Chapter 6 Virtual Private Databases
Topic : Hibernate 1 Kaster Nurmukan. An ORM tool Used in data layer of applications Implements JPA.
Overview of C/C++ DB APIs Dirk Düllmann, IT-ADC Database Workshop for LHC developers 27 January, 2005.
Copyright 2007, Information Builders. Slide 1 iWay Web Services and WebFOCUS Consumption Michael Florkowski Information Builders.
Oracle 10g Database Administrator: Implementation and Administration Chapter 10 Basic Data Management.
G.Govi CERN/IT-DB 1GridPP7 June30 - July 2, 2003 Data Storage with the POOL persistency framework Motivation Strategy Storage model Storage operation Summary.
CS 440 Database Management Systems Stored procedures & OR mapping 1.
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe.
4 Copyright © 2004, Oracle. All rights reserved. Advanced Interface Methods.
1 Copyright © 2008, Oracle. All rights reserved. Repository Basics.
Evaluation of the C++ binding to the Oracle Database System Dirk Geppert and Krzysztof Nienartowicz, IT/DB CERN IT Fellow Seminar November 20, 2002.
Oracle9i Developer: PL/SQL Programming Chapter 6 PL/SQL Packages.
Preface IIntroduction Course Objectives I-2 Oracle Complete Solution I-3 Course Agenda I-4 Tables Used in This Course I-5 The Order Entry Schema I-6 The.
Oracle Database Architectural Components
Database: JDBC Overview
Jean-Philippe Baud, IT-GD, CERN November 2007
ODBC, OCCI and JDBC overview
Database JDBC Overview CS Programming Languages for Web Applications
Introduction What is a Database?.
DATABASE MANAGEMENT SYSTEM
Data Model.
SQL .. An overview lecture3.
Oracle Architectural Components
Chapter 8 Advanced SQL.
Prof. Arfaoui. COM390 Chapter 7
INTRODUCTION A Database system is basically a computer based record keeping system. The collection of data, usually referred to as the database, contains.
Presentation transcript:

CERN/IT/DB Oracle C++ Call Interface Dirk Geppert IT/DB DB Workshop July 11-13, 2001

CERN/IT/DB Outline  Overview  Advanced features  Example  Summary  Advanced example

CERN/IT/DB What is it?  API to access Oracle database  OCI Oracle Call Interface  OCCI Oracle C++ Call Interface  OCCI a better OCI: wrapper  scalable, high performance, multi-tiered  ANSI C++, STL  JDBC like

CERN/IT/DB What to use it for?  Relational Programming  Associative Access of Relational Data SQL DDL (data definition) SQL DML (data manipulating) SQL queries PL/SQL  Object Programming  Navigational and Associative Access of Objects

CERN/IT/DB Advanced features  Thread safety  Connection pooling  Client-side object cache  Complex Object Retrieval  Metadata  Context USER

CERN/IT/DB Thread safety  Oracle database server and OCCI in multi-threaded environment  Mechanism to maintain integrity of data accessed by multiple threads  Mutexes are granted on basis of OCCI Environment class  THREADED_MUTEXED Thread safe, mutexed internally managed by OCCI  THREADED_UN_MUTEXED Thread safe, client responsible for mutexing

CERN/IT/DB Connection pooling  Multi-threading typically  large number of threads need connections to DB for short duration  Open connection for each thread  Inefficient  Poor performance  OCCI connection pooling  create small number of connections  dynamically select free connection to execute statement  release connection

CERN/IT/DB Client-side object cache  Memory buffer for objects  Lookup and memory management support  Stores and tracks objects fetched from server to client side  Maintains references  Manages automatic object swapping  Meta-attributes or type information  Created when OCCI-Environment initialized in object mode  Benefits  Reduces client/server round-trips  Object-level locking

CERN/IT/DB Complex Object Retrieval  OO data models  Interrelated objects forming graphs  Navigate/traverse: fetch & pin each object individually  Costly network round-trips (client/server)  Oracle’s Complex Object Retrieval  Pre-fetching (content, boundary) Specific type up to depth level All attribute types up to depth level  Objects only pre-fetched, not pinned  Limited by client-side cache size

CERN/IT/DB Metadata  Dynamically discover attributes of database objects  Database itself  Schema objects e.g. tables, columns, types, type attributes, result attributes MetaData evt_md=conn->getMetaData(“Event”); vector attr_list = evt_md.getVector(ATTR_LIST_TYPE_ATTRS);

CERN/IT/DB Context USER  user owns  e.g. tables, types, objects  May grant privileges to other users, roles (named groups of privileges)  Access, modify OCCI_STD_NAMESPACE::string Event_C::getSQLTypeName() const {return OCCI_STD_NAMESPACE::string(“SCOTT.EVENT_C");}

CERN/IT/DB Type mapping  Oracle database - C++ (host language)  Oracle internal – external  Data conversion of C++ data send/requested to/from database CHARchar NUMBERint, float VARRAYSTL vector REFOCCI Ref

CERN/IT/DB create type array as varray(1000) of number / create type atype as object ( n number, a array, p ref atype) / create table atable of atype; insert into atable values (atype(0,null,null)); commit; type atype generate ctype as mytype SQL – OTT – C++ ctype Number n Vector a Ref p mytype PObject SQLOTTOCCI see Peter’s talk

CERN/IT/DB Generated C++ classes class ctype : public oracle::occi::Pobject { private: // attributes … public: // set & get attributes … void *operator new(size_t size); void *operator new(size_t size, const oracle::occi::Connection * sess, const OCCI_STD_NAMESPACE::string& table); OCCI_STD_NAMESPACE::string getSQLTypeName() const; ctype(); ctype(void *ctxOCCI_) : oracle::occi::PObject (ctxOCCI_) { }; static void *readSQL(void *ctxOCCI_); virtual void readSQL(oracle::occi::AnyData& streamOCCI_); static void writeSQL(void *objOCCI_, void *ctxOCCI_); virtual void writeSQL(oracle::occi::AnyData& streamOCCI_); } Persistent Object transient persistent SQL

CERN/IT/DB Environment *env=Environment::createEnvironment(Environment::OBJECT); RegisterMappings(env); Connection *conn=env->createConnection(“scott”,”tiger”,””); Statement *stmt=conn->createStatement(); ResultSet *resultSet=stmt->executeQuery(“select ref(t) from atable t where n=0”); if (ResultSet::DATA_AVAILABLE == resultSet->next()) { Ref ref=resultSet->getRef(1); } conn->commit(); stmt->closeResultSet(resultSet); conn->terminateConnection(conn); Environment::terminateEnvironment(env); Example Session create/modify/delete objects easy to use

CERN/IT/DB Ref ref=resultSet->getRef(1); ref_next=new(conn,”ATABLE”) mytype(); ref->setP(ref_next); // forward ref->markModified(); Creating new objects Ref ref=resultSet->getRef(1); do { ref->dump(); mytype *ptr=ref.ptr(); // if needed } while (!((ref=ref->getP()).isNull())); dereference, pin reference pointer Example navigation persistentmodify

CERN/IT/DB Summary  OCCI is C++ API to communicate with Oracle database server  Built on top of OCI  High-performance  scalable  Easy to use  Does it provide the flexibility to use it for HEP data models & access patterns? Tests are on the way…

CERN/IT/DB UML Event Track VertexHeader PObject * 1 1 *

CERN/IT/DB create type header_o as object (run number,evt number); create type track_o; -- dummy create type track_ref_varray_o as varray(100) of ref track_o; create type vertex_o as object (id number,x number,y number,z number,trk track_ref_varray_o); create type vertex_ref_varray_o as varray(100) of ref vertex_o; create or replace type track_o as object ( id number,px number,py number,pz number,vtx ref vertex_o); create type event_o as object (id number,hdr header,vtx vertex_ref_varray_o,nxt ref event_o); create table event_t of event_o create table vertex_t of vertex_o create table track_t of track_o insert into event_t values (event_o(0,header_o(0,0),null,null)); commit; SQL

CERN/IT/DB TYPE Header_O GENERATE Header_C AS Header TYPE Track_O GENERATE Track_C AS Track TYPE Vertex_O GENERATE Vertex_C AS Vertex TYPE Event_O GENERATE Event_C AS Event OTT Oracle C++ User (inherit from C++ class)

CERN/IT/DB class Event_C : public oracle::occi::PObject { private: oracle::occi::Number ID; Header * HDR; OCCI_STD_NAMESPACE::vector > VTX; oracle::occi::Ref NXT; public: oracle::occi::Number getId() const; void setId(const oracle::occi::Number &value); Header *getHdr() const; void setHdr(Header *value); OCCI_STD_NAMESPACE::vector > getVtx() const; void setVtx(const OCCI_STD_NAMESPACE::vector > &value); oracle::occi::Ref getNxt() const; void setNxt(const oracle::occi::Ref &value); C++.h set & get attributes

CERN/IT/DB void *operator new(size_t size); void *operator new(size_t size, const oracle::occi::Connection * sess, const OCCI_STD_NAMESPACE::string& table); OCCI_STD_NAMESPACE::string getSQLTypeName() const; Event_C(); Event_C(void *ctxOCCI_) : oracle::occi::PObject (ctxOCCI_) { }; static void *readSQL(void *ctxOCCI_); virtual void readSQL(oracle::occi::AnyData& streamOCCI_); static void writeSQL(void *objOCCI_, void *ctxOCCI_); virtual void writeSQL(oracle::occi::AnyData& streamOCCI_); } C++.h cont’d new SQL ctor

CERN/IT/DB oracle::occi::Number Event_C::getId() const { return ID; } void Event_C::setId(const oracle::occi::Number &value) { ID = value; } Header_C * Event_c::getHdr() const { return HDR; } void Event_C::setHdr(Header * value) { HDR = value; } OCCI_STD_NAMESPACE::vector > Event_C::getVtx() const { return VTX; } void Event_C::setVtx(const OCCI_STD_NAMESPACE::vector > &value) { VTX = value; } oracle::occi::Ref Event_C::getNxt() const { return NXT; } void Event_C::setNxt(const oracle::occi::Ref &value) { NXT = value; } C++.cpp set & get

CERN/IT/DB void *Event_C::operator new(size_t size) { return oracle::occi::PObject::operator new(size); } void *Event_C::operator new(size_t size, const oracle::occi::Connection * sess, const OCCI_STD_NAMESPACE::string& table) { return oracle::occi::PObject::operator new(size, sess, table, (char *) “SCOTT.EVENT_O"); } OCCI_STD_NAMESPACE::string Event_C::getSQLTypeName() const { return OCCI_STD_NAMESPACE::string(“SCOTT.EVENT_O"); } Event_C::Event_C() {HDR = (Header *) 0;} C++.cpp cont’d new ctor

CERN/IT/DB void *Event_C::readSQL(void *ctxOCCI_) { Event_C *objOCCI_ = new Event_C(ctxOCCI_); oracle::occi::AnyData streamOCCI_(ctxOCCI_); try { if (streamOCCI_.isNull()) objOCCI_->setNull(); else objOCCI_->readSQL(streamOCCI_); } catch (oracle::occi::SQLException& excep) { delete objOCCI_; excep.setErrorCtx(ctxOCCI_); return (void *)NULL; } return (void *)objOCCI_; } void Event_C::readSQL(oracle::occi::AnyData& streamOCCI_) { ID = streamOCCI_.getNumber(); HDR = (Header *) streamOCCI_.getObject(); getVector(streamOCCI_, VTX); NXT = streamOCCI_.getRef(); } C++.cpp cont’d readSQL

CERN/IT/DB void Event_C::writeSQL(void *objectOCCI_, void *ctxOCCI_) { Event_C *objOCCI_ = (Event_C *) objectOCCI_; oracle::occi::AnyData streamOCCI_(ctxOCCI_); try { if (objOCCI_->isNull()) streamOCCI_.setNull(); else objOCCI_->writeSQL(streamOCCI_); } catch (oracle::occi::SQLException& excep) { excep.setErrorCtx(ctxOCCI_); } return; } void Event_C::writeSQL(oracle::occi::AnyData& streamOCCI_) { streamOCCI_.setNumber(ID); streamOCCI_.setObject(HDR); setVector(streamOCCI_,VTX); streamOCCI_.setRef(NXT); } C++.cpp cont’d writeSQL

CERN/IT/DB void Event::dump() { cout << "Event::dump()" << endl; cout << " ID= " << int(getId()) << endl; if (getHdr()!=0) getHdr()->dump(); OCCI_STD_NAMESPACE::vector > &vtx=getVtx(); cout << " Vtx length= " << vtx.size() << endl; for (int i=0; i<vtx.size(); i++) { oracle::occi::Ref v=vtx[i]; v->dump(); } if (getNxt().isNull()) cout << " Next is NULL" << endl; else cout << " Next exists " << endl; }; User C++ class Event : public Event_C { public: void dump(); };

CERN/IT/DB Ref evt_ref, evt_ref_next; Event *evt_ptr, *evt_ptr_next; unsigned long int eid,vid,tid; int evt,run; Header* hdr; Vertex* vtx; Track* trk; evt_ref = resultSet->getRef(1); for (int ievent=0; ievent<nevent; ievent++) { hdr = new Header(); // and set attributes… Navigation - write Header

CERN/IT/DB OCCI_STD_NAMESPACE::vector > vtx_ref_arr; for (int ivertex=0; ivertex<nvertex; ivertex++) { vtx=new (conn,"VERTEX_T") Vertex(); OCCI_STD_NAMESPACE::vector > trk_ref_arr; for (int itrack=0; itrack<2; itrack++) { trk=new (conn,"TRACK_T") Track(); trk->setVtx(vtx); // and other attributes… trk_ref_arr.push_back(trk); } vtx->setTrk(trk_ref_arr); // and other attributes… vtx_ref_arr.push_back(vtx); } evt_ptr_next = new(conn,"EVENT_T") Event(); evt_ptr_next->setHdr(hdr); evt_ptr_next->setVtx(vtx_ref_arr); // and other attributes… evt_ptr->setNxt(evt_ptr_next); // forward pointing evt_ptr->markModified(); conn->commit(); evt_ptr=evt_ptr_next; } Navigation - write cont’d Track Vertex Event

CERN/IT/DB Ref evt_ref = resultSet->getRef(1); do { evt_ref->dump(); } while (!((evt_ref=evt_ref->getNxt()).isNull())); Navigation - read

CERN/IT/DB MAPFILE fileCPPFILE fileHFILE file OCCI Source Compiler OCCI libraryLinkerObject file Executable OTT INTYPE fileSQL DDL Database Server Type Definitions Object Type Translator