School Work


Comparison between several tools for mapping a database into objects and classes
of 8
All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
Related Documents
   Advanced Databases Object Relational Mapping Tools  1.   Introduction When developing a small or a big application, we always deal with data in different forms. It is not enough to keep our data in structures that are provided by the programming language that we use, only while the application is running. There are times when the application is shut down, or it gets jammed or we need to perform some maintenance, and so the data kept in those structures must be kept somewhere else until we restart the system. Therefore the need for persistency reveals. The implementation of persistency is much time tedious work, repeating some routines and so errors may be included in our application. As a result, Object Relational Mapping tools have been developed. Their goal is to simplify the creation of data layer access, automate data access or to generate data access code. The principle of object-relational mapping is to delegate to tools the management of persistency, and to work at code-level with objects  representing a domain model, and not with data structures in the same format as the relational database . Object-relational mapping tools establish a bidirectional link with data in a relational database and objects in code, based on a configuration and by executing SQL queries (dynamic most of the time) on the database. They all have their pros and cons, just as it is the case for mapping tools themselves of course. The criteria we considered is presented briefly: -   Customization of queries. We often need to go beyond what is possible with the provided query language. In these cases, we need to be able to provide custom SQL queries. HQL, which is a strong point of Hibernate/NHibernate, allows for this. We could also wish a dynamic mapping to be possible from developer provided SQL queries. -   Support any type of SQL joins (inner join, outer join) -   Concurrency management (support for optimistic and pessimistic approaches) -   Be able to map a single object to data coming from multiple tables (joins, views). Most of the tools handle a direct mapping of a class to one table. We often need more. -   Be able to dispatch the data from a single table to multiple objects. -   Global performance (good implementation of the object-relational mapping concept, ease of use, flexibility) -   Lazy loading (the loading of some data is deferred until it is needed) o   for the data through relations o   for some columns. When we want to display just a list of names, we do not need all the columns of a table to be loaded. We may need the blob fields only at certain point, under certain conditions, and so it is better to load them only at that time.   -   Cache dynamically generated queries, so that they do not get rebuilt at each call. -   Cache some data to avoid too many calls to the data source. -   Bulk updates or deletions. When we want to update or delete thousands of records at a time, it is not possible to load all the objects in memory, while this can be easily and quickly done with a SQL query (DELETE FROM Customer WHERE Balance < 0). Support from the tool is welcome to handle such massive operations without having to deal with SQL. Hibernate is not very good on this point for example. -   Supported databases -   Query Language. There is sometimes the need to execute dynamic queries. 1.1   The Database The application used for this analysis implements an invoice management system. An invoice contains one or more products and a product can be found on one or more invoices (the relation is based on the product ID). The invoices will have a Content, which also represents the key database for a many-to-many relational database. An user can execute one of the following operations for his invoices: adding/deleting an invoice, list the contents of an invoice, list a listing of his invoices, delete or modify the content of an invoice.   1.2 The tested ORMs -   ActiveJDBC   -   Carbonado   -   Hibernate   -   2.   ActiveJDBC  ActiveJDBC is a Java implementation of Active Record design pattern. It was inspired by ActiveRecord ORM from Ruby on Rails. Supported Databases: -   MySQL -   PostgreSQL -   Oracle -   H2 -   MS SQL Server There is also the possibility to provide support for other databases, but certain build scripts must be executed. Advantages: -   No implementation for the models; they must only extend the Model.class  -   ActiveJDBC has a certain inference mechanism through which it can infer table names and properties for the tables. (Eg.: class User -> Table: Users); -   For every model, the ActiveJDBC framework considers there is an id field/db property; -   You can also redefine Primary Keys and Foreign Keys through annotations; (Eg.: @Table( Facturi ) @IdName( pk_IDFactura ) @BelongsTo(parent = User.class, foreignKeyName = IDUser ) public   class  Facturi extends  Model{ } ) -   When a database is modelled, there is no need to have an external mapping file, but an “Instrumentation” script must be run before run -time, in order to generate the bytecode files of the models. Although no extra files are needed for mapping, this can become annoying if it is not integrated within a compile script; -   The basic CRUD operations have the expected effect and it is guaranteed; -   The user can also give an SQL statement to a find() call, as sometimes the code can become hard to read if only methods are used; -   ActiveJDBC offers the capability to export a result of whatever type, List, Map, Object to a JSON, XML file; -   All SQL generated statements can be parameterized; -   You have the possibility of extracting all the columns or only a certain one; -   C aching is by default not turned on; even if you use the “@Cached” annotation it is still necessary to make the correct entry in the file. -   The framework takes care to purge the tables that have been modified; -   Manual caching is available, but the user must concern about the stale data. -   Supports all types of relations; -   Batch processing resumes at updates and deletes; Disadvantages: -   The constant need to run the “Inst ru mentation” script is a drawback in terms of usability; -   The inference mechanism is almost alright to use if you have tables named in English, as the mechanism uses the plural forms of nouns. -   In order to get a row value from a result set the user must know the name of the column and give it as a parameter to the getString(String col_name) function for example; -   The caching framework is an open source framework, so it may have certain bugs but it can also have a lot of documentation; -   The use of multiple keys is not that easy; -   Multiple Foreign Keys per model can be annotated but only one FK will be used; -   Multiple Primary Keys can be used, but workaround code is necessary, therefore the code becomes a bit heavy; -   The native query cannot be analysed at request; sometimes it is shown in the error stack trace;

Raiyan's Ielts

Jul 23, 2017
We Need Your Support
Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

Thanks to everyone for your continued support.

No, Thanks