Skip to content

CardamaS99/Mapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mapper

What is it?

Mapper is a library that allow the object-relational mapping from Relational Databases to Java objects.

Why was it developed?

This library was developed as part of an assigment in the subject Databases II from the Computer Engineering Degree in the University of Santiago de Compostela. Specifically, it consisted in the development of a social network which required the usage of SQL databases.

How does it work?

How to define the mapping of a Java class?

The library provides the user with an interface which relies on the usage of the annotations available in Java. These can be classified in two categories:

  1. MapperTable: class level annotation that points the library which is the database's table from where the data will be mapped.
  2. MapperColumn: attribute level annotation that points the library which is the database's column from where the data will be obtained.

Via these annotations, the library is able to parse basic SQL tables along with their properties, such as primary keys, or default values. Following up, an example shows a Java class Student which maps the Students table.

@MapperTable(nombre="students")
public class Student {

    @MapperColumn(columna="name")
    private String name;
    
    @MapperColumn(pkey=true)
    private String dni;
    
    @MapperColumn
    private Date birthday;
    
    @MapperColumn(fkey="teacher:id", targetClass="Teacher.class")
    private Teacher teacher;
}

How to perform the mapping of Java class?

To map an already defined Java class using annotations, the user will need to rely on the available Mapper classes in the library. Within these, a parent class is divided into several subclasses, each one specializing in an specific kind of tasks:

  1. InsertionMapper: performs the insertion of an object in the database.
  2. QueryMapper: performs queries over the database, allowing the recovery of every present information in the shape of a mapped class' instance.
  3. DeleteMapper: performs the deletion of the specified object in the database.
  4. UpdateMapper: performs the update of the specified object's data in the database.

Advantages of using the Mapper

Some of the benefits that the Mapper can provide to a software project are:

  1. Disengage the connection with the database through the usage of the mapper as an intermediary in the sharing of data.
  2. Increase of the security, as the mapper with take care of preventing common security flaws in software such as SQL injection.
  3. Ease of executing SQL sentences, due to the abstraction that the mapper provides over the connection with the database.
  4. The possibility of using non-atomic classes as foreign keys (namely, using a Java class as a foreign key instead of a single attribute); in addition, the mapper is able to extract from the database all the information about the referenced class as an object, not only its primary key, but also its other data regardless of its type, providing the user with the appropiate abstraction.

Authors

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages