An innovative object mapping technology. HRM provides a dynamic method of mapping database data to multi-dimensional hash-maps. HRM is well suited to handling joins and organising that data into a user-defined hierarchical format.
Its Dynamic nature means that the query data structure hierarchies can change at runtime. Most ORMs deal with static object types, while HRM uses hash-map which can be modified in-flight.
HRM is designed for a new bred of dynamic applications whose very functionality can be altered at run time – from the front-end through to the back-end.
Enables developers to load data from any JDBC data-source into an organised hierarchical hash-map format. Joins are where HRM shines. This is achieved through multi-dimensional arrays.
Data which is the result of a join query can be organised in a hierarchical structure using this format:
Table1.Table1
Table1.Table2
Table1.Table3
this equals
tablekey[0][0]
tablekey[0][1]
tablekey[0][2]
The sample structure shown above would define a parent table (Table1) with other Child tables – Table2 and Table3. Table1.Table represents the root of the hierarchy.
The Child tables represent embedded tables - more on this later.
As well as defining the child parent relationship a key would be required to differentiate each record within the structure.
config1.setKey("return Key;");
config1.setTable("Table1");
config2.setKey("return Key2;");
config2.setTable("Table2");
...
The key are defined through MVEL script. So they can be derived from the database key or derived from multiple properties that are available. More information on keys later
HRM is built on JDBC. So it inherits all its benefits. In general the benefits of any ORM (Object Relationship Mapping) is that it speeds up development. For example, eliminating repetitive code like mapping query result fields to object members. HRM adds to this ability by automatically mapping data to hash-map entries.
The main reasons for using Hash Relational Mapping are,
1. It handles the representation of join relationships in a simple way
2. Allows for multiple records to be returned – without any additional coding.
3. Ideal intermediate data-store for Velocity templates.
4. Dynamic in nature.
As stated in point 4, the output generated is completely dynamic.
Unlike other ORM's the output of the query can be modified at run time to meet the needs of application developer and user.
Java development. Java developers have many ORM’s to choose from. Ranging from Hibernate to Spring JDBCTemplate. HRM is built to take care of the activities which usually take many configuration files to create.
Take the example below of displaying customer data to a screen based on the customer identifier and wishing to see their associated products.
The customer and product details are connected via join tables.
In order to configure that relationship in HRM we simply define the SQL and then define data hierarchy.
SELECT cc . * , pp . *
FROM Cust1 cc, CustProdJoin cj, Prod1 pp
WHERE cc.id = cj.CustomerId
AND cj.ProductId = pp.ProductId
LIMIT 0 , 30
This can be done at run-time and changed as and when required without any downtime.
So in the above scenario we can achieve this scenario
The advantages of having data represented in this format holds for all ORM’s, when compared to JDBC result-sets - It is easier to parse and use the required information.
With a JDBC result-set you need to parse duplicate data, i.e. the customer details would be duplicated for each product. Here that would not be the case. All the details contained in the hash-map structure should be unique.
Web service interface
Example 1
http://localhost:8080/HashRelMapServlet/?sqlquery=SELECT cc.*,pp.* FROM Cust1 cc, CustProdJoin cj, Prod1 pp WHERE cc.id=cj.CustomerId AND cj.ProductId = pp.ProductId&tablekey[0][0]=return ProductId;Prod1
Parent Join expression
return ProductId from Prod1
Results
<hashtoxml>
<Prod1>
<row>
<ProductName>Bread</ProductName>
<ProductId>2</ProductId>
</row>
<row>
<ProductName>ToothBrush</ProductName>
<ProductId>1</ProductId>
</row>
</Prod1>
</hashtoxml>
Example 2
http://localhost:8080/HashRelMapServlet/?sqlquery=SELECT cc.*,pp.* FROM Cust1 cc, CustProdJoin cj, Prod1 pp WHERE cc.id=cj.CustomerId AND cj.ProductId = pp.ProductId&tablekey[0][0]=return id;Cust1&tablekey[0][1]=return ProductId;Prod1
Parent Join expression
tablekey[0][0]=return id;Cust1
return id from Cust1
Child Join expression
tablekey[0][1]=return ProductId;Prod1
return ProductId from Prod1
Group Products for each related Cust1.id