Summary of OO hierarchy inheritance mapping strategies

1. Pre-requisites Should read first there types of mapping below: Single-table strategy Joined-tables strategy Table-per-class strategy 2. Summary mapping strategies Table 1: Summary of OO hierarchy inheritance mapping strategies (source: EJB3 in Action) References: D. Pan, R. Rahman, R. Cuprak, M. Remijan, “Mapping inheritance”, In EJB3 in Action,pp.292-293, Manning, Second Edition, 2014

Table-per-class strategy for mapping inheritance with JPA

1. Table-per-class strategy Table-per-class strategy is similar to  joined-tables strategy because each entity in domain model gets its own table. One significant difference is no relationship between the tables, which doesn’t take advantage of power of relational database at all. Following the stock market example in join-table-strategy and single-table-strategy , we are there different tables namely product, bonds, shares but product_code, description, version… Read More »

Joined-tables strategy for mapping inheritance with JPA

1. Joined-tables strategy Follow up the Single-table strategy for mapping inheritance with JPA, this strategy stores all financial products in a single table. In contrast, the joined table strategy creates separate tables for each entity in the domain model. This means that the financial product is the parent table and it holds common data for… Read More »

Single-table strategy for mapping inheritance with JPA

1. Stock Market Example Get started on our real market example with investors who want to buy or sell shares on the marketplace of which they are participants. Actually, stockbrokers (brokers) will do trading on behalf of their clients. But, there are different financial products: shares, loan, option, bond, hibrid, future, and so on. So… Read More »

Factory Pattern

Factory Pattern is to create object through a common interface/ abstract class. It belongs to Creational Pattern group. 1. Real-life example Suppose that we have two different types of instruments in capital market – one with an Equities and another with a Dept. A company want to use an instrument to raise capital, and represents… Read More »

Remove duplicated elements from a collection

1. Using LinkedHashSet from a given list Remove duplicated elements by using LinkedHashSet because it contains unique element and in the same order as the List Output in console: 2. Lambda Stream on arbitrary key Output in console:

Heap’s algorithm for Permutations

Problem: Find the biggest number from the array [3, 1, 2] (n = 3). For example: 321 is largest number in comparison with all possible numbers from the array. Solving: We need to resolve 2 things. Final all possible Permutations from the array. So possible permutation is n! = 3! = 6 cases. Find a maximum number from… Read More »

Quick Sort Algorithm

Quick sort discovered by C.A.R Hoare in 1962. It is a fast algorithm for internal or in-memory sorting except for sorting data in disk files. Figure 1: Time and Space complexity of quick sort. There are three basic steps: Partition the array or sub-array into left (smaller keys) and right (larger keys) groups. Call ourselves to sort… Read More »