SlideShare a Scribd company logo
Persistence with
Ada Database Objects (ADO)
Stéphane Carrez FOSDEM 2019
https://github.com/stcarrez/ada-ado 2
Design Goals
●
Support several databases à la JDBC
●
Type safe interface to create/read/update/delete
●
Map SQL rows and results in Ada records
●
Generate database mappings
●
Still allow to use and tune SQL queries
https://github.com/stcarrez/ada-ado 3
Database Session Factory
●
The session factory manages database connections
●
The factory is a limited type to prevent copies
●
It is initialized with a connection string:
– mysql://localhost:3306/samples?user=test
– sqlite:///samples.db?synchronous=OFF&encoding=’UTF-8’
– postgresql://localhost:5432/samples?user=test
with ADO.Sessions.Factory;
with ADO.Drivers;
procedure Select_User is
Factory : ADO.Sessions.Factory.Session_Factory;
begin
ADO.Drivers.Initialize (“samples.properties”);
Factory.Create (ADO.Drivers.Get_Config (“ado.database”));
...
end Select_User;
https://github.com/stcarrez/ada-ado 4
Database Session
●
Holds the database connection
●
Two types of database sessions to support database replication:
– A Session type to connect to a read-only database server (replicated
server)
– A Master_Session type to connect to a write capable database server
(master)
●
Session and Master_Session types can be copied and use
reference counting
with ADO.Sessions;
Session : ADO.Sessions.Session := Factory.Get_Session;
-- Can only run queries
Session : ADO.Sessions.Master_Session : Factory.Get_Master_Session;
-- Can run queries, start transactions, insert, update, delete
https://github.com/stcarrez/ada-ado 5
Simple SQL query
●
Create a query statement using SQL
●
Execute and get manually each row and column
with ADO.Statements;
...
Name : String := ...;
Stmt : ADO.Statements.Query_Statement
:= Session.Create_Statement
(“SELECT * FROM user WHERE name = :name”);
...
Stmt.Bind_Param (“name”, Name);
Statement.Execute;
while Stmt.Has_Elements loop
Id := Stmt.Get_Identifier (0);
...
Stmt.Next;
end loop;
https://github.com/stcarrez/ada-ado 6
But...
●
Difficulties with the manual approach
– Can make errors when getting values,
– Can make type errors when updating
●
Solution
– Map SQL results in Ada
– Map database tables in Ada
https://github.com/stcarrez/ada-ado 7
Mapping SQL to Ada
●
Map the SELECT row in an Ada record
●
Define a Vector of the Ada record
●
Procedure to run the query and map the results
type User_Info is record
Id : ADO.Identifier;
Name : Unbounded_String;
Email : Unbounded_String;
end record;
package User_Info_Vectors is
new Ada.Containers.Vectors (Index_Type => Positive,
Element_Type => User_Info);
subtype User_Info_Vector is User_Info_Vectors.Vector;
procedure List (Object : in out User_Info_Vector;
Session : in out ADO.Sessions.Session’Class;
Context : in out ADO.Queries.Context’Class);
SELECT
u.id AS id,
u.name AS name,
u.email AS email
FROM
user AS u
ORDER BY
u.name ASC
https://github.com/stcarrez/ada-ado 8
Database Modeling
XML Model
Dynamo
Generator
Model
Doc
(HTML)
SQL
Tables
Ada
Model
Packages
UML Model
Ada Database
Objects Library
Generated Application Model Packages
Your Application Code
Ada Utility Library
Postgresql, MySQL or SQLite
Generate Develop
YAML Model
Design
https://github.com/stcarrez/ada-ado 9
Database Modeling YAML vs UML
Samples.User.Model.User:
type: entity
table: user
description: Record representing a user
id:
id:
type: identifier
column: id
not-null: true
unique: true
description: the user identifier
generator:
strategy: sequence
fields:
version:
type: integer
column: object_version
not-null: true
version: true
name:
type: string
length: 255
column: name
not-null: true
description: the user name
date:
type: date
column: date
not-null: true
description: the user registration
...
https://github.com/stcarrez/ada-ado 10
Generated Ada Model
●
Public object reference type with accessors
●
Private implementation type holds the values
●
Load, Save, Delete, Find operations
package Samples.User.Model is
type Status_Type is (INACTIVE, REGISTERING, ACTIVE);
type Email_Ref is new ADO.Objects.Object_Ref with null record;
type User_Ref is new ADO.Objects.Object_Ref with null record;
procedure Set_Name (Object : in out User_Ref; Value : in String);
function Get_Name (Object : in User_Ref) return String;
overriding procedure Save (Object : in out User_Ref; ...);
...
private
type Email_Impl is new ADO.Objects.Object_Record ...;
type User_Impl is new ADO.Objects.Object_Record ...;
end Samples.User.Model;
https://github.com/stcarrez/ada-ado 11
Using the Ada Model
●
Declare T_Ref instances
●
Use Get_X and Set_X to access attributes
●
Use Load, Find to retrieve and Save, Delete to modify
User : User_Ref;
Email : Email_Ref;
User.Set_Name (“Ada Lovelace”);
User.Set_Status (REGISTERING);
User.Save (Session);
...
Email.Set_Emailaddress (“ada@protonmail.com”);
Email.Set_User (User);
Email.Save (Session);
User.Set_Email (Email);
User.Set_Status (ACTIVE);
User.Save (Session);
INSERT INTO user (id,object_version,name,
email,date,status) VALUES(?, ?, ?, ?, ?, ?)
INSERT INTO email (id,version,name,
emailAddress, user) VALUES(?, ?, ?, ?)
UPDATE user SET status = ?, email = ?
WHERE id = ? AND object_version = ?
https://github.com/stcarrez/ada-ado 12
Bonus: database auditing
●
Track and record changes in database
●
Apply <<auditable>> UML stereotype to
attributes or auditable: true in YAML
●
Audit_Manager interface called after each
Save with:
– Object record
– List of changes with field, old value, new value
https://github.com/stcarrez/ada-ado 13
Conclusion
●
Generated model simplifies database access
●
Strong typing representation of SQL queries
●
Dynamo generates Ada model and SQL tables
●
Ada Database Objects Programmer’s Guide
– https://ada-ado.readthedocs.io/en/latest/

More Related Content

What's hot

Oracle Developer Day, 20 October 2009, Oracle De Meern, Holland: Oracle Datab...
Oracle Developer Day, 20 October 2009, Oracle De Meern, Holland: Oracle Datab...Oracle Developer Day, 20 October 2009, Oracle De Meern, Holland: Oracle Datab...
Oracle Developer Day, 20 October 2009, Oracle De Meern, Holland: Oracle Datab...
Marco Gralike
 
Spring framework part 2
Spring framework part 2Spring framework part 2
Spring framework part 2
Haroon Idrees
 
Introduction to Hibernate Framework
Introduction to Hibernate FrameworkIntroduction to Hibernate Framework
Introduction to Hibernate Framework
Raveendra R
 
OakTable World 2015 - Using XMLType content with the Oracle In-Memory Column...
OakTable World 2015  - Using XMLType content with the Oracle In-Memory Column...OakTable World 2015  - Using XMLType content with the Oracle In-Memory Column...
OakTable World 2015 - Using XMLType content with the Oracle In-Memory Column...
Marco Gralike
 
Cloudera Impala, updated for v1.0
Cloudera Impala, updated for v1.0Cloudera Impala, updated for v1.0
Cloudera Impala, updated for v1.0
Scott Leberknight
 
UKOUG Tech14 - Getting Started With JSON in the Database
UKOUG Tech14 - Getting Started With JSON in the DatabaseUKOUG Tech14 - Getting Started With JSON in the Database
UKOUG Tech14 - Getting Started With JSON in the Database
Marco Gralike
 
MongoDB & NoSQL 101
 MongoDB & NoSQL 101 MongoDB & NoSQL 101
MongoDB & NoSQL 101
Jollen Chen
 
Hibernate working with criteria- Basic Introduction
Hibernate working with criteria- Basic IntroductionHibernate working with criteria- Basic Introduction
Hibernate working with criteria- Basic Introduction
Er. Gaurav Kumar
 
Starting with JSON Path Expressions in Oracle 12.1.0.2
Starting with JSON Path Expressions in Oracle 12.1.0.2Starting with JSON Path Expressions in Oracle 12.1.0.2
Starting with JSON Path Expressions in Oracle 12.1.0.2
Marco Gralike
 
UKOUG 2010 (Birmingham) - XML Indexing strategies - Choosing the Right Index ...
UKOUG 2010 (Birmingham) - XML Indexing strategies - Choosing the Right Index ...UKOUG 2010 (Birmingham) - XML Indexing strategies - Choosing the Right Index ...
UKOUG 2010 (Birmingham) - XML Indexing strategies - Choosing the Right Index ...
Marco Gralike
 
Hibernate
HibernateHibernate
Hibernate
Leonardo Passos
 
Miracle Open World 2011 - XML Index Strategies
Miracle Open World 2011  -  XML Index StrategiesMiracle Open World 2011  -  XML Index Strategies
Miracle Open World 2011 - XML Index Strategies
Marco Gralike
 
What's new, what's hot in PHP 5.3
What's new, what's hot in PHP 5.3What's new, what's hot in PHP 5.3
What's new, what's hot in PHP 5.3
Jeremy Coates
 
Intro to Rails ActiveRecord
Intro to Rails ActiveRecordIntro to Rails ActiveRecord
Intro to Rails ActiveRecord
Mark Menard
 
Oak Lucene Indexes
Oak Lucene IndexesOak Lucene Indexes
Oak Lucene Indexes
Chetan Mehrotra
 
Drupal 7 entities & TextbookMadness.com
Drupal 7 entities & TextbookMadness.comDrupal 7 entities & TextbookMadness.com
Drupal 7 entities & TextbookMadness.com
JD Leonard
 
Spring data jpa
Spring data jpaSpring data jpa
Spring data jpa
Jeevesh Pandey
 
supporting t-sql scripts for Heap vs clustered table
supporting t-sql scripts for Heap vs clustered tablesupporting t-sql scripts for Heap vs clustered table
supporting t-sql scripts for Heap vs clustered table
Mahabubur Rahaman
 
UKOUG Tech14 - Using Database In-Memory Column Store with Complex Datatypes
UKOUG Tech14 - Using Database In-Memory Column Store with Complex DatatypesUKOUG Tech14 - Using Database In-Memory Column Store with Complex Datatypes
UKOUG Tech14 - Using Database In-Memory Column Store with Complex Datatypes
Marco Gralike
 
UKOUG 2011 - Drag, Drop and other Stuff. Using your Database as a File Server
UKOUG 2011 - Drag, Drop and other Stuff. Using your Database as a File ServerUKOUG 2011 - Drag, Drop and other Stuff. Using your Database as a File Server
UKOUG 2011 - Drag, Drop and other Stuff. Using your Database as a File Server
Marco Gralike
 

What's hot (20)

Oracle Developer Day, 20 October 2009, Oracle De Meern, Holland: Oracle Datab...
Oracle Developer Day, 20 October 2009, Oracle De Meern, Holland: Oracle Datab...Oracle Developer Day, 20 October 2009, Oracle De Meern, Holland: Oracle Datab...
Oracle Developer Day, 20 October 2009, Oracle De Meern, Holland: Oracle Datab...
 
Spring framework part 2
Spring framework part 2Spring framework part 2
Spring framework part 2
 
Introduction to Hibernate Framework
Introduction to Hibernate FrameworkIntroduction to Hibernate Framework
Introduction to Hibernate Framework
 
OakTable World 2015 - Using XMLType content with the Oracle In-Memory Column...
OakTable World 2015  - Using XMLType content with the Oracle In-Memory Column...OakTable World 2015  - Using XMLType content with the Oracle In-Memory Column...
OakTable World 2015 - Using XMLType content with the Oracle In-Memory Column...
 
Cloudera Impala, updated for v1.0
Cloudera Impala, updated for v1.0Cloudera Impala, updated for v1.0
Cloudera Impala, updated for v1.0
 
UKOUG Tech14 - Getting Started With JSON in the Database
UKOUG Tech14 - Getting Started With JSON in the DatabaseUKOUG Tech14 - Getting Started With JSON in the Database
UKOUG Tech14 - Getting Started With JSON in the Database
 
MongoDB & NoSQL 101
 MongoDB & NoSQL 101 MongoDB & NoSQL 101
MongoDB & NoSQL 101
 
Hibernate working with criteria- Basic Introduction
Hibernate working with criteria- Basic IntroductionHibernate working with criteria- Basic Introduction
Hibernate working with criteria- Basic Introduction
 
Starting with JSON Path Expressions in Oracle 12.1.0.2
Starting with JSON Path Expressions in Oracle 12.1.0.2Starting with JSON Path Expressions in Oracle 12.1.0.2
Starting with JSON Path Expressions in Oracle 12.1.0.2
 
UKOUG 2010 (Birmingham) - XML Indexing strategies - Choosing the Right Index ...
UKOUG 2010 (Birmingham) - XML Indexing strategies - Choosing the Right Index ...UKOUG 2010 (Birmingham) - XML Indexing strategies - Choosing the Right Index ...
UKOUG 2010 (Birmingham) - XML Indexing strategies - Choosing the Right Index ...
 
Hibernate
HibernateHibernate
Hibernate
 
Miracle Open World 2011 - XML Index Strategies
Miracle Open World 2011  -  XML Index StrategiesMiracle Open World 2011  -  XML Index Strategies
Miracle Open World 2011 - XML Index Strategies
 
What's new, what's hot in PHP 5.3
What's new, what's hot in PHP 5.3What's new, what's hot in PHP 5.3
What's new, what's hot in PHP 5.3
 
Intro to Rails ActiveRecord
Intro to Rails ActiveRecordIntro to Rails ActiveRecord
Intro to Rails ActiveRecord
 
Oak Lucene Indexes
Oak Lucene IndexesOak Lucene Indexes
Oak Lucene Indexes
 
Drupal 7 entities & TextbookMadness.com
Drupal 7 entities & TextbookMadness.comDrupal 7 entities & TextbookMadness.com
Drupal 7 entities & TextbookMadness.com
 
Spring data jpa
Spring data jpaSpring data jpa
Spring data jpa
 
supporting t-sql scripts for Heap vs clustered table
supporting t-sql scripts for Heap vs clustered tablesupporting t-sql scripts for Heap vs clustered table
supporting t-sql scripts for Heap vs clustered table
 
UKOUG Tech14 - Using Database In-Memory Column Store with Complex Datatypes
UKOUG Tech14 - Using Database In-Memory Column Store with Complex DatatypesUKOUG Tech14 - Using Database In-Memory Column Store with Complex Datatypes
UKOUG Tech14 - Using Database In-Memory Column Store with Complex Datatypes
 
UKOUG 2011 - Drag, Drop and other Stuff. Using your Database as a File Server
UKOUG 2011 - Drag, Drop and other Stuff. Using your Database as a File ServerUKOUG 2011 - Drag, Drop and other Stuff. Using your Database as a File Server
UKOUG 2011 - Drag, Drop and other Stuff. Using your Database as a File Server
 

Similar to Persistence with Ada Database Objects (ADO)

Green dao
Green daoGreen dao
Green dao
Droidcon Berlin
 
SproutCore and the Future of Web Apps
SproutCore and the Future of Web AppsSproutCore and the Future of Web Apps
SproutCore and the Future of Web Apps
Mike Subelsky
 
PofEAA and SQLAlchemy
PofEAA and SQLAlchemyPofEAA and SQLAlchemy
PofEAA and SQLAlchemy
Inada Naoki
 
Slick Data Sharding: Slides from DrupalCon London
Slick Data Sharding: Slides from DrupalCon LondonSlick Data Sharding: Slides from DrupalCon London
Slick Data Sharding: Slides from DrupalCon London
Phase2
 
Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)
Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)
Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)
lennartkats
 
Ruby on Rails: Coding Guideline
Ruby on Rails: Coding GuidelineRuby on Rails: Coding Guideline
Ruby on Rails: Coding Guideline
Nascenia IT
 
mongodb-introduction
mongodb-introductionmongodb-introduction
mongodb-introduction
Tse-Ching Ho
 
Using the Tooling API to Generate Apex SOAP Web Service Clients
Using the Tooling API to Generate Apex SOAP Web Service ClientsUsing the Tooling API to Generate Apex SOAP Web Service Clients
Using the Tooling API to Generate Apex SOAP Web Service Clients
Salesforce Developers
 
Using Document Databases with TYPO3 Flow
Using Document Databases with TYPO3 FlowUsing Document Databases with TYPO3 Flow
Using Document Databases with TYPO3 Flow
Karsten Dambekalns
 
ASP.Net Presentation Part2
ASP.Net Presentation Part2ASP.Net Presentation Part2
ASP.Net Presentation Part2
Neeraj Mathur
 
Spring data requery
Spring data requerySpring data requery
Spring data requery
Sunghyouk Bae
 
SQL overview and software
SQL overview and softwareSQL overview and software
Architecture | Busy Java Developers Guide to NoSQL | Ted Neward
Architecture | Busy Java Developers Guide to NoSQL | Ted NewardArchitecture | Busy Java Developers Guide to NoSQL | Ted Neward
Architecture | Busy Java Developers Guide to NoSQL | Ted Neward
JAX London
 
Android | Busy Java Developers Guide to Android: Persistence | Ted Neward
Android | Busy Java Developers Guide to Android: Persistence | Ted NewardAndroid | Busy Java Developers Guide to Android: Persistence | Ted Neward
Android | Busy Java Developers Guide to Android: Persistence | Ted Neward
JAX London
 
Scala Frameworks for Web Application 2016
Scala Frameworks for Web Application 2016Scala Frameworks for Web Application 2016
Scala Frameworks for Web Application 2016
takezoe
 
ActiveJDBC - ActiveRecord implementation in Java
ActiveJDBC - ActiveRecord implementation in JavaActiveJDBC - ActiveRecord implementation in Java
ActiveJDBC - ActiveRecord implementation in Java
ipolevoy
 
Oracle Objects And Transactions
Oracle Objects And TransactionsOracle Objects And Transactions
Oracle Objects And Transactions
tepsum
 
Easy data-with-spring-data-jpa
Easy data-with-spring-data-jpaEasy data-with-spring-data-jpa
Easy data-with-spring-data-jpa
Staples
 
Java Technology
Java TechnologyJava Technology
Java Technology
ifnu bima
 
Msql
Msql Msql
Msql
ksujitha
 

Similar to Persistence with Ada Database Objects (ADO) (20)

Green dao
Green daoGreen dao
Green dao
 
SproutCore and the Future of Web Apps
SproutCore and the Future of Web AppsSproutCore and the Future of Web Apps
SproutCore and the Future of Web Apps
 
PofEAA and SQLAlchemy
PofEAA and SQLAlchemyPofEAA and SQLAlchemy
PofEAA and SQLAlchemy
 
Slick Data Sharding: Slides from DrupalCon London
Slick Data Sharding: Slides from DrupalCon LondonSlick Data Sharding: Slides from DrupalCon London
Slick Data Sharding: Slides from DrupalCon London
 
Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)
Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)
Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)
 
Ruby on Rails: Coding Guideline
Ruby on Rails: Coding GuidelineRuby on Rails: Coding Guideline
Ruby on Rails: Coding Guideline
 
mongodb-introduction
mongodb-introductionmongodb-introduction
mongodb-introduction
 
Using the Tooling API to Generate Apex SOAP Web Service Clients
Using the Tooling API to Generate Apex SOAP Web Service ClientsUsing the Tooling API to Generate Apex SOAP Web Service Clients
Using the Tooling API to Generate Apex SOAP Web Service Clients
 
Using Document Databases with TYPO3 Flow
Using Document Databases with TYPO3 FlowUsing Document Databases with TYPO3 Flow
Using Document Databases with TYPO3 Flow
 
ASP.Net Presentation Part2
ASP.Net Presentation Part2ASP.Net Presentation Part2
ASP.Net Presentation Part2
 
Spring data requery
Spring data requerySpring data requery
Spring data requery
 
SQL overview and software
SQL overview and softwareSQL overview and software
SQL overview and software
 
Architecture | Busy Java Developers Guide to NoSQL | Ted Neward
Architecture | Busy Java Developers Guide to NoSQL | Ted NewardArchitecture | Busy Java Developers Guide to NoSQL | Ted Neward
Architecture | Busy Java Developers Guide to NoSQL | Ted Neward
 
Android | Busy Java Developers Guide to Android: Persistence | Ted Neward
Android | Busy Java Developers Guide to Android: Persistence | Ted NewardAndroid | Busy Java Developers Guide to Android: Persistence | Ted Neward
Android | Busy Java Developers Guide to Android: Persistence | Ted Neward
 
Scala Frameworks for Web Application 2016
Scala Frameworks for Web Application 2016Scala Frameworks for Web Application 2016
Scala Frameworks for Web Application 2016
 
ActiveJDBC - ActiveRecord implementation in Java
ActiveJDBC - ActiveRecord implementation in JavaActiveJDBC - ActiveRecord implementation in Java
ActiveJDBC - ActiveRecord implementation in Java
 
Oracle Objects And Transactions
Oracle Objects And TransactionsOracle Objects And Transactions
Oracle Objects And Transactions
 
Easy data-with-spring-data-jpa
Easy data-with-spring-data-jpaEasy data-with-spring-data-jpa
Easy data-with-spring-data-jpa
 
Java Technology
Java TechnologyJava Technology
Java Technology
 
Msql
Msql Msql
Msql
 

More from Stephane Carrez

Implementing a build manager in Ada
Implementing a build manager in AdaImplementing a build manager in Ada
Implementing a build manager in Ada
Stephane Carrez
 
Porion a new Build Manager
Porion a new Build ManagerPorion a new Build Manager
Porion a new Build Manager
Stephane Carrez
 
Protect Sensitive Data with Ada Keystore
Protect Sensitive Data with Ada KeystoreProtect Sensitive Data with Ada Keystore
Protect Sensitive Data with Ada Keystore
Stephane Carrez
 
AKT un outil pour sécuriser vos données et documents sensibles
AKT un outil pour sécuriser vos données et documents sensiblesAKT un outil pour sécuriser vos données et documents sensibles
AKT un outil pour sécuriser vos données et documents sensibles
Stephane Carrez
 
Ada for Web Development
Ada for Web DevelopmentAda for Web Development
Ada for Web Development
Stephane Carrez
 
Secure Web Applications with AWA
Secure Web Applications with AWASecure Web Applications with AWA
Secure Web Applications with AWA
Stephane Carrez
 
Writing REST APIs with OpenAPI and Swagger Ada
Writing REST APIs with OpenAPI and Swagger AdaWriting REST APIs with OpenAPI and Swagger Ada
Writing REST APIs with OpenAPI and Swagger Ada
Stephane Carrez
 
IP Network Stack in Ada 2012 and the Ravenscar Profile
IP Network Stack in Ada 2012 and the Ravenscar ProfileIP Network Stack in Ada 2012 and the Ravenscar Profile
IP Network Stack in Ada 2012 and the Ravenscar Profile
Stephane Carrez
 

More from Stephane Carrez (8)

Implementing a build manager in Ada
Implementing a build manager in AdaImplementing a build manager in Ada
Implementing a build manager in Ada
 
Porion a new Build Manager
Porion a new Build ManagerPorion a new Build Manager
Porion a new Build Manager
 
Protect Sensitive Data with Ada Keystore
Protect Sensitive Data with Ada KeystoreProtect Sensitive Data with Ada Keystore
Protect Sensitive Data with Ada Keystore
 
AKT un outil pour sécuriser vos données et documents sensibles
AKT un outil pour sécuriser vos données et documents sensiblesAKT un outil pour sécuriser vos données et documents sensibles
AKT un outil pour sécuriser vos données et documents sensibles
 
Ada for Web Development
Ada for Web DevelopmentAda for Web Development
Ada for Web Development
 
Secure Web Applications with AWA
Secure Web Applications with AWASecure Web Applications with AWA
Secure Web Applications with AWA
 
Writing REST APIs with OpenAPI and Swagger Ada
Writing REST APIs with OpenAPI and Swagger AdaWriting REST APIs with OpenAPI and Swagger Ada
Writing REST APIs with OpenAPI and Swagger Ada
 
IP Network Stack in Ada 2012 and the Ravenscar Profile
IP Network Stack in Ada 2012 and the Ravenscar ProfileIP Network Stack in Ada 2012 and the Ravenscar Profile
IP Network Stack in Ada 2012 and the Ravenscar Profile
 

Recently uploaded

Explore-Insanony: Watch Instagram Stories Secretly
Explore-Insanony: Watch Instagram Stories SecretlyExplore-Insanony: Watch Instagram Stories Secretly
Explore-Insanony: Watch Instagram Stories Secretly
Trending Blogers
 
Azure EA Sponsorship - Customer Guide.pdf
Azure EA Sponsorship - Customer Guide.pdfAzure EA Sponsorship - Customer Guide.pdf
Azure EA Sponsorship - Customer Guide.pdf
AanSulistiyo
 
假文凭国外(Adelaide毕业证)澳大利亚国立大学毕业证成绩单办理
假文凭国外(Adelaide毕业证)澳大利亚国立大学毕业证成绩单办理假文凭国外(Adelaide毕业证)澳大利亚国立大学毕业证成绩单办理
假文凭国外(Adelaide毕业证)澳大利亚国立大学毕业证成绩单办理
cuobya
 
manuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaal
manuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaalmanuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaal
manuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaal
wolfsoftcompanyco
 
国外证书(Lincoln毕业证)新西兰林肯大学毕业证成绩单不能毕业办理
国外证书(Lincoln毕业证)新西兰林肯大学毕业证成绩单不能毕业办理国外证书(Lincoln毕业证)新西兰林肯大学毕业证成绩单不能毕业办理
国外证书(Lincoln毕业证)新西兰林肯大学毕业证成绩单不能毕业办理
zoowe
 
留学学历(UoA毕业证)奥克兰大学毕业证成绩单官方原版办理
留学学历(UoA毕业证)奥克兰大学毕业证成绩单官方原版办理留学学历(UoA毕业证)奥克兰大学毕业证成绩单官方原版办理
留学学历(UoA毕业证)奥克兰大学毕业证成绩单官方原版办理
bseovas
 
可查真实(Monash毕业证)西澳大学毕业证成绩单退学买
可查真实(Monash毕业证)西澳大学毕业证成绩单退学买可查真实(Monash毕业证)西澳大学毕业证成绩单退学买
可查真实(Monash毕业证)西澳大学毕业证成绩单退学买
cuobya
 
留学挂科(UofM毕业证)明尼苏达大学毕业证成绩单复刻办理
留学挂科(UofM毕业证)明尼苏达大学毕业证成绩单复刻办理留学挂科(UofM毕业证)明尼苏达大学毕业证成绩单复刻办理
留学挂科(UofM毕业证)明尼苏达大学毕业证成绩单复刻办理
uehowe
 
Design Thinking NETFLIX using all techniques.pptx
Design Thinking NETFLIX using all techniques.pptxDesign Thinking NETFLIX using all techniques.pptx
Design Thinking NETFLIX using all techniques.pptx
saathvikreddy2003
 
重新申请毕业证书(RMIT毕业证)皇家墨尔本理工大学毕业证成绩单精仿办理
重新申请毕业证书(RMIT毕业证)皇家墨尔本理工大学毕业证成绩单精仿办理重新申请毕业证书(RMIT毕业证)皇家墨尔本理工大学毕业证成绩单精仿办理
重新申请毕业证书(RMIT毕业证)皇家墨尔本理工大学毕业证成绩单精仿办理
vmemo1
 
Search Result Showing My Post is Now Buried
Search Result Showing My Post is Now BuriedSearch Result Showing My Post is Now Buried
Search Result Showing My Post is Now Buried
Trish Parr
 
办理新西兰奥克兰大学毕业证学位证书范本原版一模一样
办理新西兰奥克兰大学毕业证学位证书范本原版一模一样办理新西兰奥克兰大学毕业证学位证书范本原版一模一样
办理新西兰奥克兰大学毕业证学位证书范本原版一模一样
xjq03c34
 
Ready to Unlock the Power of Blockchain!
Ready to Unlock the Power of Blockchain!Ready to Unlock the Power of Blockchain!
Ready to Unlock the Power of Blockchain!
Toptal Tech
 
[HUN][hackersuli] Red Teaming alapok 2024
[HUN][hackersuli] Red Teaming alapok 2024[HUN][hackersuli] Red Teaming alapok 2024
[HUN][hackersuli] Red Teaming alapok 2024
hackersuli
 
学位认证网(DU毕业证)迪肯大学毕业证成绩单一比一原版制作
学位认证网(DU毕业证)迪肯大学毕业证成绩单一比一原版制作学位认证网(DU毕业证)迪肯大学毕业证成绩单一比一原版制作
学位认证网(DU毕业证)迪肯大学毕业证成绩单一比一原版制作
zyfovom
 
办理毕业证(NYU毕业证)纽约大学毕业证成绩单官方原版办理
办理毕业证(NYU毕业证)纽约大学毕业证成绩单官方原版办理办理毕业证(NYU毕业证)纽约大学毕业证成绩单官方原版办理
办理毕业证(NYU毕业证)纽约大学毕业证成绩单官方原版办理
uehowe
 
成绩单ps(UST毕业证)圣托马斯大学毕业证成绩单快速办理
成绩单ps(UST毕业证)圣托马斯大学毕业证成绩单快速办理成绩单ps(UST毕业证)圣托马斯大学毕业证成绩单快速办理
成绩单ps(UST毕业证)圣托马斯大学毕业证成绩单快速办理
ysasp1
 
Understanding User Behavior with Google Analytics.pdf
Understanding User Behavior with Google Analytics.pdfUnderstanding User Behavior with Google Analytics.pdf
Understanding User Behavior with Google Analytics.pdf
SEO Article Boost
 
制作原版1:1(Monash毕业证)莫纳什大学毕业证成绩单办理假
制作原版1:1(Monash毕业证)莫纳什大学毕业证成绩单办理假制作原版1:1(Monash毕业证)莫纳什大学毕业证成绩单办理假
制作原版1:1(Monash毕业证)莫纳什大学毕业证成绩单办理假
ukwwuq
 
存档可查的(USC毕业证)南加利福尼亚大学毕业证成绩单制做办理
存档可查的(USC毕业证)南加利福尼亚大学毕业证成绩单制做办理存档可查的(USC毕业证)南加利福尼亚大学毕业证成绩单制做办理
存档可查的(USC毕业证)南加利福尼亚大学毕业证成绩单制做办理
fovkoyb
 

Recently uploaded (20)

Explore-Insanony: Watch Instagram Stories Secretly
Explore-Insanony: Watch Instagram Stories SecretlyExplore-Insanony: Watch Instagram Stories Secretly
Explore-Insanony: Watch Instagram Stories Secretly
 
Azure EA Sponsorship - Customer Guide.pdf
Azure EA Sponsorship - Customer Guide.pdfAzure EA Sponsorship - Customer Guide.pdf
Azure EA Sponsorship - Customer Guide.pdf
 
假文凭国外(Adelaide毕业证)澳大利亚国立大学毕业证成绩单办理
假文凭国外(Adelaide毕业证)澳大利亚国立大学毕业证成绩单办理假文凭国外(Adelaide毕业证)澳大利亚国立大学毕业证成绩单办理
假文凭国外(Adelaide毕业证)澳大利亚国立大学毕业证成绩单办理
 
manuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaal
manuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaalmanuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaal
manuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaal
 
国外证书(Lincoln毕业证)新西兰林肯大学毕业证成绩单不能毕业办理
国外证书(Lincoln毕业证)新西兰林肯大学毕业证成绩单不能毕业办理国外证书(Lincoln毕业证)新西兰林肯大学毕业证成绩单不能毕业办理
国外证书(Lincoln毕业证)新西兰林肯大学毕业证成绩单不能毕业办理
 
留学学历(UoA毕业证)奥克兰大学毕业证成绩单官方原版办理
留学学历(UoA毕业证)奥克兰大学毕业证成绩单官方原版办理留学学历(UoA毕业证)奥克兰大学毕业证成绩单官方原版办理
留学学历(UoA毕业证)奥克兰大学毕业证成绩单官方原版办理
 
可查真实(Monash毕业证)西澳大学毕业证成绩单退学买
可查真实(Monash毕业证)西澳大学毕业证成绩单退学买可查真实(Monash毕业证)西澳大学毕业证成绩单退学买
可查真实(Monash毕业证)西澳大学毕业证成绩单退学买
 
留学挂科(UofM毕业证)明尼苏达大学毕业证成绩单复刻办理
留学挂科(UofM毕业证)明尼苏达大学毕业证成绩单复刻办理留学挂科(UofM毕业证)明尼苏达大学毕业证成绩单复刻办理
留学挂科(UofM毕业证)明尼苏达大学毕业证成绩单复刻办理
 
Design Thinking NETFLIX using all techniques.pptx
Design Thinking NETFLIX using all techniques.pptxDesign Thinking NETFLIX using all techniques.pptx
Design Thinking NETFLIX using all techniques.pptx
 
重新申请毕业证书(RMIT毕业证)皇家墨尔本理工大学毕业证成绩单精仿办理
重新申请毕业证书(RMIT毕业证)皇家墨尔本理工大学毕业证成绩单精仿办理重新申请毕业证书(RMIT毕业证)皇家墨尔本理工大学毕业证成绩单精仿办理
重新申请毕业证书(RMIT毕业证)皇家墨尔本理工大学毕业证成绩单精仿办理
 
Search Result Showing My Post is Now Buried
Search Result Showing My Post is Now BuriedSearch Result Showing My Post is Now Buried
Search Result Showing My Post is Now Buried
 
办理新西兰奥克兰大学毕业证学位证书范本原版一模一样
办理新西兰奥克兰大学毕业证学位证书范本原版一模一样办理新西兰奥克兰大学毕业证学位证书范本原版一模一样
办理新西兰奥克兰大学毕业证学位证书范本原版一模一样
 
Ready to Unlock the Power of Blockchain!
Ready to Unlock the Power of Blockchain!Ready to Unlock the Power of Blockchain!
Ready to Unlock the Power of Blockchain!
 
[HUN][hackersuli] Red Teaming alapok 2024
[HUN][hackersuli] Red Teaming alapok 2024[HUN][hackersuli] Red Teaming alapok 2024
[HUN][hackersuli] Red Teaming alapok 2024
 
学位认证网(DU毕业证)迪肯大学毕业证成绩单一比一原版制作
学位认证网(DU毕业证)迪肯大学毕业证成绩单一比一原版制作学位认证网(DU毕业证)迪肯大学毕业证成绩单一比一原版制作
学位认证网(DU毕业证)迪肯大学毕业证成绩单一比一原版制作
 
办理毕业证(NYU毕业证)纽约大学毕业证成绩单官方原版办理
办理毕业证(NYU毕业证)纽约大学毕业证成绩单官方原版办理办理毕业证(NYU毕业证)纽约大学毕业证成绩单官方原版办理
办理毕业证(NYU毕业证)纽约大学毕业证成绩单官方原版办理
 
成绩单ps(UST毕业证)圣托马斯大学毕业证成绩单快速办理
成绩单ps(UST毕业证)圣托马斯大学毕业证成绩单快速办理成绩单ps(UST毕业证)圣托马斯大学毕业证成绩单快速办理
成绩单ps(UST毕业证)圣托马斯大学毕业证成绩单快速办理
 
Understanding User Behavior with Google Analytics.pdf
Understanding User Behavior with Google Analytics.pdfUnderstanding User Behavior with Google Analytics.pdf
Understanding User Behavior with Google Analytics.pdf
 
制作原版1:1(Monash毕业证)莫纳什大学毕业证成绩单办理假
制作原版1:1(Monash毕业证)莫纳什大学毕业证成绩单办理假制作原版1:1(Monash毕业证)莫纳什大学毕业证成绩单办理假
制作原版1:1(Monash毕业证)莫纳什大学毕业证成绩单办理假
 
存档可查的(USC毕业证)南加利福尼亚大学毕业证成绩单制做办理
存档可查的(USC毕业证)南加利福尼亚大学毕业证成绩单制做办理存档可查的(USC毕业证)南加利福尼亚大学毕业证成绩单制做办理
存档可查的(USC毕业证)南加利福尼亚大学毕业证成绩单制做办理
 

Persistence with Ada Database Objects (ADO)

  • 1. Persistence with Ada Database Objects (ADO) Stéphane Carrez FOSDEM 2019
  • 2. https://github.com/stcarrez/ada-ado 2 Design Goals ● Support several databases à la JDBC ● Type safe interface to create/read/update/delete ● Map SQL rows and results in Ada records ● Generate database mappings ● Still allow to use and tune SQL queries
  • 3. https://github.com/stcarrez/ada-ado 3 Database Session Factory ● The session factory manages database connections ● The factory is a limited type to prevent copies ● It is initialized with a connection string: – mysql://localhost:3306/samples?user=test – sqlite:///samples.db?synchronous=OFF&encoding=’UTF-8’ – postgresql://localhost:5432/samples?user=test with ADO.Sessions.Factory; with ADO.Drivers; procedure Select_User is Factory : ADO.Sessions.Factory.Session_Factory; begin ADO.Drivers.Initialize (“samples.properties”); Factory.Create (ADO.Drivers.Get_Config (“ado.database”)); ... end Select_User;
  • 4. https://github.com/stcarrez/ada-ado 4 Database Session ● Holds the database connection ● Two types of database sessions to support database replication: – A Session type to connect to a read-only database server (replicated server) – A Master_Session type to connect to a write capable database server (master) ● Session and Master_Session types can be copied and use reference counting with ADO.Sessions; Session : ADO.Sessions.Session := Factory.Get_Session; -- Can only run queries Session : ADO.Sessions.Master_Session : Factory.Get_Master_Session; -- Can run queries, start transactions, insert, update, delete
  • 5. https://github.com/stcarrez/ada-ado 5 Simple SQL query ● Create a query statement using SQL ● Execute and get manually each row and column with ADO.Statements; ... Name : String := ...; Stmt : ADO.Statements.Query_Statement := Session.Create_Statement (“SELECT * FROM user WHERE name = :name”); ... Stmt.Bind_Param (“name”, Name); Statement.Execute; while Stmt.Has_Elements loop Id := Stmt.Get_Identifier (0); ... Stmt.Next; end loop;
  • 6. https://github.com/stcarrez/ada-ado 6 But... ● Difficulties with the manual approach – Can make errors when getting values, – Can make type errors when updating ● Solution – Map SQL results in Ada – Map database tables in Ada
  • 7. https://github.com/stcarrez/ada-ado 7 Mapping SQL to Ada ● Map the SELECT row in an Ada record ● Define a Vector of the Ada record ● Procedure to run the query and map the results type User_Info is record Id : ADO.Identifier; Name : Unbounded_String; Email : Unbounded_String; end record; package User_Info_Vectors is new Ada.Containers.Vectors (Index_Type => Positive, Element_Type => User_Info); subtype User_Info_Vector is User_Info_Vectors.Vector; procedure List (Object : in out User_Info_Vector; Session : in out ADO.Sessions.Session’Class; Context : in out ADO.Queries.Context’Class); SELECT u.id AS id, u.name AS name, u.email AS email FROM user AS u ORDER BY u.name ASC
  • 8. https://github.com/stcarrez/ada-ado 8 Database Modeling XML Model Dynamo Generator Model Doc (HTML) SQL Tables Ada Model Packages UML Model Ada Database Objects Library Generated Application Model Packages Your Application Code Ada Utility Library Postgresql, MySQL or SQLite Generate Develop YAML Model Design
  • 9. https://github.com/stcarrez/ada-ado 9 Database Modeling YAML vs UML Samples.User.Model.User: type: entity table: user description: Record representing a user id: id: type: identifier column: id not-null: true unique: true description: the user identifier generator: strategy: sequence fields: version: type: integer column: object_version not-null: true version: true name: type: string length: 255 column: name not-null: true description: the user name date: type: date column: date not-null: true description: the user registration ...
  • 10. https://github.com/stcarrez/ada-ado 10 Generated Ada Model ● Public object reference type with accessors ● Private implementation type holds the values ● Load, Save, Delete, Find operations package Samples.User.Model is type Status_Type is (INACTIVE, REGISTERING, ACTIVE); type Email_Ref is new ADO.Objects.Object_Ref with null record; type User_Ref is new ADO.Objects.Object_Ref with null record; procedure Set_Name (Object : in out User_Ref; Value : in String); function Get_Name (Object : in User_Ref) return String; overriding procedure Save (Object : in out User_Ref; ...); ... private type Email_Impl is new ADO.Objects.Object_Record ...; type User_Impl is new ADO.Objects.Object_Record ...; end Samples.User.Model;
  • 11. https://github.com/stcarrez/ada-ado 11 Using the Ada Model ● Declare T_Ref instances ● Use Get_X and Set_X to access attributes ● Use Load, Find to retrieve and Save, Delete to modify User : User_Ref; Email : Email_Ref; User.Set_Name (“Ada Lovelace”); User.Set_Status (REGISTERING); User.Save (Session); ... Email.Set_Emailaddress (“ada@protonmail.com”); Email.Set_User (User); Email.Save (Session); User.Set_Email (Email); User.Set_Status (ACTIVE); User.Save (Session); INSERT INTO user (id,object_version,name, email,date,status) VALUES(?, ?, ?, ?, ?, ?) INSERT INTO email (id,version,name, emailAddress, user) VALUES(?, ?, ?, ?) UPDATE user SET status = ?, email = ? WHERE id = ? AND object_version = ?
  • 12. https://github.com/stcarrez/ada-ado 12 Bonus: database auditing ● Track and record changes in database ● Apply <<auditable>> UML stereotype to attributes or auditable: true in YAML ● Audit_Manager interface called after each Save with: – Object record – List of changes with field, old value, new value
  • 13. https://github.com/stcarrez/ada-ado 13 Conclusion ● Generated model simplifies database access ● Strong typing representation of SQL queries ● Dynamo generates Ada model and SQL tables ● Ada Database Objects Programmer’s Guide – https://ada-ado.readthedocs.io/en/latest/