Dbutils (i)

Source: Internet
Author: User

Transfer from http://www.cnblogs.com/myit/p/4269165.html

I feel that the most dbutils used is the processing of the query result set, starting with this to understand the Dbutils library.

Viewing the conversion of the source code discovery result set is primarily used for the Query,insert,insertbatch method.

Just list the relevant code for the Queryrunner class, others skip//-----------Source 1 Query method------------------    stmt = this.preparestatement (conn, SQL) ;    This.fillstatement (stmt, params);    rs = This.wrap (Stmt.executequery ());    result = Rsh.handle (RS); Processing result set//-----------Source 2 Insert Method------------------    stmt = conn.preparestatement (sql, tatement. Return_generated_keys);

    This.fillstatement (stmt, params);    Stmt.executeupdate ();    ResultSet ResultSet = Stmt.getgeneratedkeys ();    Generatedkeys = Rsh.handle (ResultSet); Process result set//-----------Source 3 Insertbatch Method------------------    ResultSet rs = Stmt.getgeneratedkeys ();    Generatedkeys = Rsh.handle (RS); Working with result sets

The conversion of the resultset is mainly carried out around two interfaces (resultsethandler<t> and rowprocessor).

1,resultsethandler<t>, the diagram is as follows:

Interface Resultsethandler There is only one method that needs to be implemented handle (ResultSet RS), my understanding of this method is to deal with the result set of a portal, each result set transformation class in its own handle method to handle their own things, this can be from the previous source 1, 2, 3 to see, are called to implement the handle method of the class, and then return the results.

The Resultsethandler implementation class (The result set transformation Class) implements the processing of the result set in the handle method, most of which involves another interface Rowprocessor and its implementation class Basicrowprocessor.

2,rowprocessor, the diagram is as follows:

The Rowprocessor interface has 4 methods that need to be implemented, and the specific use can be visualized from the method name. These methods are called in the handle method of the result transformation class. Note that if you need to convert the result set to a bean, it also involves the use of a class beanprocessor.

3 . The relationship between Resultsethandler and Rowprocessor

Although the figure is a bit chaotic, can see clearly. Most of the result sets hold a reference to a rowprocessor interface. It is important to note that this class is arrayhandler, because references to other class rowprocessor are obtained from this class, and this class establishes the object that Rowprocessor implements the class Basicrowprocessor.

Note that 3 of these abstract classes (Abstractkeyedhandler, Abstractlisthandler, Baseresultsethandler), whose derived classes are the result conversion classes that you can use. According to the documentation, you can implement your own result set transformation class by inheriting Baseresultsethandler if none of the officially provided conversion classes meet your requirements.

Dbutils (i)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.