filmov
tv
Build Object Relational Mapping Database in HarmonyOS

Показать описание
Here's how to Build Object Relational Mapping Database in HarmonyOS.
i. Here are some basic concepts to understand when working with Object Relational Mapping (ORM):
1. Mapping: This refers to the process of mapping application objects in an object-oriented programming language like Java to database tables and records. The ORM framework handles this mapping.
2. Entity: An entity represents a business object, typically mapped to a database table. For example, a Customer object getting mapped to customers table.
3. Attribute: Attributes are properties or fields inside an entity. In customers table, attributes can be name, address, phone etc. Mapped to member variables in Customer class.
4. Primary Key: This uniquely identifies a record in the table, often auto-generated id or sequence. ORM handles primary key mappings and value generation.
5. Relationships: Entity relationships like one-to-one, one-to-many are preserved in ORM between objects. Handles foreign key mappings.
6. Lazy Loading: Delaying the loading of related objects until they are actually needed to avoid unnecessary queries. Improves performance.
7. Eager Loading: Loading all dependent entities upfront when the source entity is fetched to avoid multiple future trips to database.
8. Dirty Checking: Tracking changes made to entity objects and only updating those fields in database instead of whole records. Optimizes updates.
So in summary, an ORM enables developers to work with objects vs manual SQL handling while bridging between object oriented and relational paradigms behind the scenes.
ii. Here are some of the key working principles for Object-Relational Mapping (ORM) databases:
1. Abstraction - ORM provides an abstracted, object-oriented view of the database structure and queries that hides the underlying SQL complexity. Developers work with classes and objects instead of tables and rows.
2. Automated Mapping - The ORM framework automatically handles the mapping between database tables & relationships to programming language classes, objects and relationships. This includes data type conversions.
3. Transparent Persistence - When objects are created, updated or deleted in code, the ORM transparently handles the required SQL INSERT, UPDATE and DELETE operations behind the scenes to persist these changes to the database.
4. Lazy Loading - ORM supports retrieving only the data that is actually needed from the database rather than entire result sets improving performance. Related data is loaded on demand.
5. Caching - Frequently used data can be cached in memory by the ORM improving application performance and reducing load on the database.
6. Change Tracking - ORM can track changes made to persistent object instances and only save the updated fields/objects to the database and not rewrite entire records every time.
7) Database Abstraction - The application code can be abstracted & shielded from underlying database changes if the ORM remains the same. This reduces maintenance costs.
So in essence, ORM handles the impedance mismatch between object-oriented code and relational databases behind the scenes.
iii. Here are some notable limitations and constraints of Object-Relational Mapping (ORM) databases:
1. Performance Overheads - The abstraction layers and automapping can lead to sub-optimal SQL queries and introduce performance overhead compared to hand-tuned SQL.
2. Impedance Mismatch - There is still an impedance mismatch between objects and tables that can result in overly complex mapping scenarios in certain cases.
3. Vendor Dependence - The ORM capabilities rely heavily on the features of the underlying database. This can constrain flexibility in switching database vendors.
4. Reduced Control - Developers have less control, visibility and flexibility compared to using raw SQL queries, especially for complex reporting/analytics use cases.
5. Steep Learning Curve - The ORM also has its own complexity and learning curve in terms of its configuration, mapping definitions, lazy loading concepts etc.
6. Immature Standards - ORM frameworks have proliferated, with various different implementations and limited mature standards compared to SQL.
7. Multi-database Constraints - Managing schema changes and mappings across multiple database types can prove challenging with ORM.
8. Testing Overheads - The abstraction makes testing slightly difficult compared to mock testing of SQL, requiring debugging integration issues.
So while ORM provides huge productivity and maintainability benefits, the costs in flexibility, control and testability need to be accounted for.
i. Here are some basic concepts to understand when working with Object Relational Mapping (ORM):
1. Mapping: This refers to the process of mapping application objects in an object-oriented programming language like Java to database tables and records. The ORM framework handles this mapping.
2. Entity: An entity represents a business object, typically mapped to a database table. For example, a Customer object getting mapped to customers table.
3. Attribute: Attributes are properties or fields inside an entity. In customers table, attributes can be name, address, phone etc. Mapped to member variables in Customer class.
4. Primary Key: This uniquely identifies a record in the table, often auto-generated id or sequence. ORM handles primary key mappings and value generation.
5. Relationships: Entity relationships like one-to-one, one-to-many are preserved in ORM between objects. Handles foreign key mappings.
6. Lazy Loading: Delaying the loading of related objects until they are actually needed to avoid unnecessary queries. Improves performance.
7. Eager Loading: Loading all dependent entities upfront when the source entity is fetched to avoid multiple future trips to database.
8. Dirty Checking: Tracking changes made to entity objects and only updating those fields in database instead of whole records. Optimizes updates.
So in summary, an ORM enables developers to work with objects vs manual SQL handling while bridging between object oriented and relational paradigms behind the scenes.
ii. Here are some of the key working principles for Object-Relational Mapping (ORM) databases:
1. Abstraction - ORM provides an abstracted, object-oriented view of the database structure and queries that hides the underlying SQL complexity. Developers work with classes and objects instead of tables and rows.
2. Automated Mapping - The ORM framework automatically handles the mapping between database tables & relationships to programming language classes, objects and relationships. This includes data type conversions.
3. Transparent Persistence - When objects are created, updated or deleted in code, the ORM transparently handles the required SQL INSERT, UPDATE and DELETE operations behind the scenes to persist these changes to the database.
4. Lazy Loading - ORM supports retrieving only the data that is actually needed from the database rather than entire result sets improving performance. Related data is loaded on demand.
5. Caching - Frequently used data can be cached in memory by the ORM improving application performance and reducing load on the database.
6. Change Tracking - ORM can track changes made to persistent object instances and only save the updated fields/objects to the database and not rewrite entire records every time.
7) Database Abstraction - The application code can be abstracted & shielded from underlying database changes if the ORM remains the same. This reduces maintenance costs.
So in essence, ORM handles the impedance mismatch between object-oriented code and relational databases behind the scenes.
iii. Here are some notable limitations and constraints of Object-Relational Mapping (ORM) databases:
1. Performance Overheads - The abstraction layers and automapping can lead to sub-optimal SQL queries and introduce performance overhead compared to hand-tuned SQL.
2. Impedance Mismatch - There is still an impedance mismatch between objects and tables that can result in overly complex mapping scenarios in certain cases.
3. Vendor Dependence - The ORM capabilities rely heavily on the features of the underlying database. This can constrain flexibility in switching database vendors.
4. Reduced Control - Developers have less control, visibility and flexibility compared to using raw SQL queries, especially for complex reporting/analytics use cases.
5. Steep Learning Curve - The ORM also has its own complexity and learning curve in terms of its configuration, mapping definitions, lazy loading concepts etc.
6. Immature Standards - ORM frameworks have proliferated, with various different implementations and limited mature standards compared to SQL.
7. Multi-database Constraints - Managing schema changes and mappings across multiple database types can prove challenging with ORM.
8. Testing Overheads - The abstraction makes testing slightly difficult compared to mock testing of SQL, requiring debugging integration issues.
So while ORM provides huge productivity and maintainability benefits, the costs in flexibility, control and testability need to be accounted for.