SlideShare une entreprise Scribd logo
1  sur  12
Mapping Inheritance Structures &  Mapping Class-Scope Properties   Todor Kolev
Overview (mapping) ,[object Object],[object Object],[object Object]
Intent (mapping) The heart of the problem is translating the logical representation of the objects into an atomized form that is capable of being stored on the database, while somehow preserving the properties of the objects and their relationships so that they can be reloaded as an object when needed. If this storage and retrieval functionality is implemented, the objects are then said to be persistent.
Mapping  Inheritance Structures ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Problem - first we have a three classes –  Person  hierarchy - the second version of the hierarchy adds a fourth concrete class The idea is that you have implemented the first class hierarchy and are now presented with a new requirement to support giving executives, but not non-executive employees, fixed annual bonuses.
Approach 1 Map the entire class hierarchy to a single table   Solution -The first column is the primary key for the table and the second is a code indicating whether the person is a customer, an employee, or perhaps both.  -PersonPOID  is a persistent object identifier (POID). -The  PersonType  column is required to identify the type of object that can be instantiated from a given row. For example the value of  E  would indicate the person is an employee. -When you discover that combinations are possible you should consider applying the  Replace Type Code With Booleans  database refactoring:
Approach 2 Map Each Concrete Class To Its Own Table
Approach 3 Map Each Class To Its Own Table The data for the  Customer  class for example   is stored in two tables,  Customer  and  Person , therefore to retrieve this data you would need to join the two tables (or do two separate reads, one to each table). The addition of  views  is also an option in many cases. Person_view:  Simple query: SELECT name, bonus SELECT name, bonus FROM table_person p JOIN table_executive e FROM Person_view ON p.personPOID = e.personPOID
Approach 4 Map Classes To A Generic Table Structure A fourth option for mapping inheritance structures into a relational database is to take a generic, sometimes called meta-data driven approach, to mapping your classes. The value of a single attribute is stored in the  Value  table, therefore to store an object with ten business attributes there would be ten records, one for each attribute. The  Value.ObjectPOID  column stores the unique identifier for the specific object (this approach assumes a common key strategy across all objects, when this isn’t the case you’ll need to extend this table appropriately). The  AttributeType  table contains rows for basic data types such as data, string, money, integer and so on. This information is required to convert the value of the object attribute into the varchar stored in  Value.Value .
Mapping the inheritance structure between  Person  and  Customer  into the same schema Each class would be represented by a row in the  Class  table. There would also be a row in the  Inheritance  table, the value of  Inheritance.SuperClassPOID  would refer to the row in  Class  representing  Person  and  Inheritance.SubClassPOID  would refer to the row in  Class  representing  Customer
Mapping Class-Scope Properties Sometimes a class will implement a property that is applicable to all of its instances and not just single instances.
Strategy Example Advantages Disadvantages Single Column, Single-RowTable The  Customer Number  table implements this strategy. Simple Fast access Could result in many small tables Multi-Column, Single-Row Table for a Single Class If  Customer implemented a second class scope attribute then a  CustomerValues  table could be introduced with one column for each Attribute Simple Fast access Could result in many small tables, although fewer than the single column approach Multi-Column, Single Raw Table for all Classes The topmost version of the Class Variables table. This table contains one column for each class attribute within your application, so if the Employee class had a nextEmployeeNumber class attribute then there would be a column for this as well. Minimal number of tables introduced to your data schema. Potential for concurrency problems if many classes need to access the data at once. One solution is to introduce a  ClassConstants  table, as shown in Figure 19, to separate attributes that are read only from those that can be updated. Multi-Row Generic Schema for all Classes The bottommost version of the  ClassVariables  and  ClassConstants . The table contains one row for each class scope property in your system. Minimal number of tables introduced to your data schema. Reduces concurrenyproblems (assuming your database supports row-based locking). Need to convert between types (e.g.  CustomerNumber  is an integer but is stored as character data). The data schema is coupled to the names of your classes and their class scope properties.

Contenu connexe

Tendances

Introduction to Database Concepts
Introduction to Database ConceptsIntroduction to Database Concepts
Introduction to Database Concepts
Rosalyn Lemieux
 
Database Design
Database DesignDatabase Design
Database Design
learnt
 
Towards a New Data Modelling Architecture - Part 1
Towards a New Data Modelling Architecture - Part 1Towards a New Data Modelling Architecture - Part 1
Towards a New Data Modelling Architecture - Part 1
JEAN-MICHEL LETENNIER
 

Tendances (16)

ADB introduction
ADB introductionADB introduction
ADB introduction
 
224-2009
224-2009224-2009
224-2009
 
Introduction to Database Concepts
Introduction to Database ConceptsIntroduction to Database Concepts
Introduction to Database Concepts
 
Data Processing-Presentation
Data Processing-PresentationData Processing-Presentation
Data Processing-Presentation
 
Characterization
CharacterizationCharacterization
Characterization
 
Data Mining: Concepts and Techniques (3rd ed.) - Chapter 3 preprocessing
Data Mining:  Concepts and Techniques (3rd ed.)- Chapter 3 preprocessingData Mining:  Concepts and Techniques (3rd ed.)- Chapter 3 preprocessing
Data Mining: Concepts and Techniques (3rd ed.) - Chapter 3 preprocessing
 
Data processing
Data processingData processing
Data processing
 
Relational Database Design
Relational Database DesignRelational Database Design
Relational Database Design
 
DBMS _Relational model
DBMS _Relational modelDBMS _Relational model
DBMS _Relational model
 
Database Design
Database DesignDatabase Design
Database Design
 
Towards a New Data Modelling Architecture - Part 1
Towards a New Data Modelling Architecture - Part 1Towards a New Data Modelling Architecture - Part 1
Towards a New Data Modelling Architecture - Part 1
 
AtomiDB Dr Ashis Banerjee reviews
AtomiDB Dr Ashis Banerjee reviewsAtomiDB Dr Ashis Banerjee reviews
AtomiDB Dr Ashis Banerjee reviews
 
DBMS_INTRODUCTION OF SQL
DBMS_INTRODUCTION OF SQLDBMS_INTRODUCTION OF SQL
DBMS_INTRODUCTION OF SQL
 
How to process data in SPSS ?
How to process data in SPSS ? How to process data in SPSS ?
How to process data in SPSS ?
 
Ch10
Ch10Ch10
Ch10
 
Mca ii-dbms- u-ii-the relational database model
Mca ii-dbms- u-ii-the relational database modelMca ii-dbms- u-ii-the relational database model
Mca ii-dbms- u-ii-the relational database model
 

Similaire à Mapping inheritance structures_mapping_class

Mapping objects to_relational_databases
Mapping objects to_relational_databasesMapping objects to_relational_databases
Mapping objects to_relational_databases
Ivan Paredes
 
Part2- The Atomic Information Resource
Part2- The Atomic Information ResourcePart2- The Atomic Information Resource
Part2- The Atomic Information Resource
JEAN-MICHEL LETENNIER
 
AB Database Assignment 1 –FOR STUDENTS TO COMPLETEFirst create .docx
AB Database Assignment 1 –FOR STUDENTS TO COMPLETEFirst create .docxAB Database Assignment 1 –FOR STUDENTS TO COMPLETEFirst create .docx
AB Database Assignment 1 –FOR STUDENTS TO COMPLETEFirst create .docx
bartholomeocoombs
 
Mapping object to_data_models_with_the_uml
Mapping object to_data_models_with_the_umlMapping object to_data_models_with_the_uml
Mapping object to_data_models_with_the_uml
Ivan Paredes
 

Similaire à Mapping inheritance structures_mapping_class (20)

Mapping objects to_relational_databases
Mapping objects to_relational_databasesMapping objects to_relational_databases
Mapping objects to_relational_databases
 
Bca3020– data base management system(dbms)
Bca3020– data base management system(dbms)Bca3020– data base management system(dbms)
Bca3020– data base management system(dbms)
 
BIS08 Application Development - II
BIS08 Application Development - IIBIS08 Application Development - II
BIS08 Application Development - II
 
Part2- The Atomic Information Resource
Part2- The Atomic Information ResourcePart2- The Atomic Information Resource
Part2- The Atomic Information Resource
 
Database aggregation using metadata
Database aggregation using metadataDatabase aggregation using metadata
Database aggregation using metadata
 
Mit202 data base management system(dbms)
Mit202  data base management system(dbms)Mit202  data base management system(dbms)
Mit202 data base management system(dbms)
 
Databases and its representation
Databases and its representationDatabases and its representation
Databases and its representation
 
COMPUTERS Database
COMPUTERS Database COMPUTERS Database
COMPUTERS Database
 
Data models
Data modelsData models
Data models
 
AB Database Assignment 1 –FOR STUDENTS TO COMPLETEFirst create .docx
AB Database Assignment 1 –FOR STUDENTS TO COMPLETEFirst create .docxAB Database Assignment 1 –FOR STUDENTS TO COMPLETEFirst create .docx
AB Database Assignment 1 –FOR STUDENTS TO COMPLETEFirst create .docx
 
Database fundamentals
Database fundamentalsDatabase fundamentals
Database fundamentals
 
Presentation1
Presentation1Presentation1
Presentation1
 
Database system the final assignment for this course is an eight to
Database system the final assignment for this course is an eight toDatabase system the final assignment for this course is an eight to
Database system the final assignment for this course is an eight to
 
Data models
Data modelsData models
Data models
 
Data models
Data modelsData models
Data models
 
Bca examination 2015 dbms
Bca examination 2015 dbmsBca examination 2015 dbms
Bca examination 2015 dbms
 
Sda 9
Sda   9Sda   9
Sda 9
 
DBMS - Introduction
DBMS - IntroductionDBMS - Introduction
DBMS - Introduction
 
Mapping object to_data_models_with_the_uml
Mapping object to_data_models_with_the_umlMapping object to_data_models_with_the_uml
Mapping object to_data_models_with_the_uml
 
Learning from similarity and information extraction from structured documents...
Learning from similarity and information extraction from structured documents...Learning from similarity and information extraction from structured documents...
Learning from similarity and information extraction from structured documents...
 

Dernier

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Dernier (20)

Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

Mapping inheritance structures_mapping_class

  • 1. Mapping Inheritance Structures & Mapping Class-Scope Properties Todor Kolev
  • 2.
  • 3. Intent (mapping) The heart of the problem is translating the logical representation of the objects into an atomized form that is capable of being stored on the database, while somehow preserving the properties of the objects and their relationships so that they can be reloaded as an object when needed. If this storage and retrieval functionality is implemented, the objects are then said to be persistent.
  • 4.
  • 5. Problem - first we have a three classes – Person hierarchy - the second version of the hierarchy adds a fourth concrete class The idea is that you have implemented the first class hierarchy and are now presented with a new requirement to support giving executives, but not non-executive employees, fixed annual bonuses.
  • 6. Approach 1 Map the entire class hierarchy to a single table Solution -The first column is the primary key for the table and the second is a code indicating whether the person is a customer, an employee, or perhaps both. -PersonPOID is a persistent object identifier (POID). -The PersonType column is required to identify the type of object that can be instantiated from a given row. For example the value of E would indicate the person is an employee. -When you discover that combinations are possible you should consider applying the Replace Type Code With Booleans database refactoring:
  • 7. Approach 2 Map Each Concrete Class To Its Own Table
  • 8. Approach 3 Map Each Class To Its Own Table The data for the Customer class for example is stored in two tables, Customer and Person , therefore to retrieve this data you would need to join the two tables (or do two separate reads, one to each table). The addition of views is also an option in many cases. Person_view: Simple query: SELECT name, bonus SELECT name, bonus FROM table_person p JOIN table_executive e FROM Person_view ON p.personPOID = e.personPOID
  • 9. Approach 4 Map Classes To A Generic Table Structure A fourth option for mapping inheritance structures into a relational database is to take a generic, sometimes called meta-data driven approach, to mapping your classes. The value of a single attribute is stored in the Value table, therefore to store an object with ten business attributes there would be ten records, one for each attribute. The Value.ObjectPOID column stores the unique identifier for the specific object (this approach assumes a common key strategy across all objects, when this isn’t the case you’ll need to extend this table appropriately). The AttributeType table contains rows for basic data types such as data, string, money, integer and so on. This information is required to convert the value of the object attribute into the varchar stored in Value.Value .
  • 10. Mapping the inheritance structure between Person and Customer into the same schema Each class would be represented by a row in the Class table. There would also be a row in the Inheritance table, the value of Inheritance.SuperClassPOID would refer to the row in Class representing Person and Inheritance.SubClassPOID would refer to the row in Class representing Customer
  • 11. Mapping Class-Scope Properties Sometimes a class will implement a property that is applicable to all of its instances and not just single instances.
  • 12. Strategy Example Advantages Disadvantages Single Column, Single-RowTable The Customer Number table implements this strategy. Simple Fast access Could result in many small tables Multi-Column, Single-Row Table for a Single Class If Customer implemented a second class scope attribute then a CustomerValues table could be introduced with one column for each Attribute Simple Fast access Could result in many small tables, although fewer than the single column approach Multi-Column, Single Raw Table for all Classes The topmost version of the Class Variables table. This table contains one column for each class attribute within your application, so if the Employee class had a nextEmployeeNumber class attribute then there would be a column for this as well. Minimal number of tables introduced to your data schema. Potential for concurrency problems if many classes need to access the data at once. One solution is to introduce a ClassConstants table, as shown in Figure 19, to separate attributes that are read only from those that can be updated. Multi-Row Generic Schema for all Classes The bottommost version of the ClassVariables and ClassConstants . The table contains one row for each class scope property in your system. Minimal number of tables introduced to your data schema. Reduces concurrenyproblems (assuming your database supports row-based locking). Need to convert between types (e.g. CustomerNumber is an integer but is stored as character data). The data schema is coupled to the names of your classes and their class scope properties.