Replacing ORMs Like JPA Or Hibernate After Java 8

Posted By : Rahul Singh | 31-May-2018

Alternate of ORMs after Java 8 

 

Civil arguments about the value of ORM (Object-Relational Mapping) have been continuing for the most recent decade. While numerous individuals would concur that Hibernate and JPA take care of a ton of issues extremely well (generally the tirelessness of complex question diagrams), others may assert that the mapping multifaceted nature is for the most part pointless excess for information-driven applications. JPA takes care of mapping issues by setting up institutionalized, decisive mapping rules through hard-wired comments on the accepting target composes. We guarantee that numerous information-driven issues ought not to be restricted by the limited extent of these comments, however, be understood in a significantly more practical way. Java 8, and the new Streams API at long last enable us to do this in an exceptionally brief way! We should begin with a basic case, where we're utilizing H2?sINFORMATION_SCHEMA to gather all tables and their sections. We'll need to create a specially appointed information structure of the sort Map> to contain this data. For effortlessness of SQL collaboration, we'll utilize jOOQ (as usual, a stunner on this blog). Here's the manner by which we set up this:

 

public static void main(String[] args)
throws Exception {
    Class.forName("org.h2.Driver");
    try (Connection c = getConnection(
            "jdbc:h2:~/sql-goodies-with-mapping", 
            "sa", "")) {
  
        // This SQL statement produces all table
        // names and column names in the H2 schema
        String sql =
            "select table_name, column_name " +
            "from information_schema.columns " +
            "order by " +
                "table_catalog, " +
                "table_schema, " +
                "table_name, " +
                "ordinal_position";
  
        // This is jOOQ's way of executing the above
        // statement. Result implements List, which
        // makes subsequent steps much easier
        Result result =
        DSL.using(c)
           .fetch(sql)
    }
}

 

Now that we’ve set up this query, let’s see how we can produce theMap> from the jOOQ Result:

 

DSL.using(c)
   .fetch(sql)
   .stream()
   .collect(groupingBy(
       r -> r.getValue("TABLE_NAME"),
       mapping(
           r -> r.getValue("COLUMN_NAME"),
           toList()
       )
   ))
   .forEach(
       (table, columns) -> 
           System.out.println(table + ": " + columns)
   );

 

The above illustration delivers the accompanying yield: FUNCTION_COLUMNS: [ALIAS_CATALOG, ALIAS_SCHEMA, ...] CONSTANTS: [CONSTANT_CATALOG, CONSTANT_SCHEMA, ...] SEQUENCES: [SEQUENCE_CATALOG, SEQUENCE_SCHEMA, ...]

 

Exciting? The ORM concept may have alternate just now This is a solid proclamation. The ORM time may have finished. Why? Since utilizing useful articulations to change informational indexes is a standout amongst the most effective ideas in programming building. Utilitarian writing computer programs are exceptionally expressive and extremely adaptable. It is at the centre of information and information streams handling. We Java designers definitely know existing useful dialects. Everybody has utilized SQL previously, for example. Consider it. With SQL, you articulate table sources, wander/transform them onto new tuple streams, and manage them either as gathered tables to other, bigger sum SQL verbalizations or to your Java program. In case you're utilizing XML, you can announce XML change utilizing XSLT and bolster results to other XML preparing elements, e.g. another XSL template, utilizing XProc pipelining. Java 8?s Streams are nothing else. Utilizing SQL and the Streams API is a standout amongst the most capable ideas for information preparing. On the off chance that you add jOOQ to the stack, you can benefit from typesafe access to your database records and inquiry APIs. Envision composing the past articulation utilizing jOOQ's familiar API, rather than utilizing SQL strings.

 

---------------------

---Thanks--

---------------------

About Author

Author Image
Rahul Singh

Rahul singh is a Java Developer and having experience in developing Applications. He is a quick learner.

Request for Proposal

Name is required

Comment is required

Sending message..