Use hibernate to intercept execution of SQL statements and output SQL statements to get SQL statements

Source: Internet
Author: User

Rebuild Package Name

Org.hibernate.type.descriptor.sql

Rebuilding class Basicbinder

The code is as follows

Package Org.hibernate.type.descriptor.sql;import Java.sql.preparedstatement;import Java.sql.sqlexception;import Org.hibernate.internal.corelogging;import Org.hibernate.type.descriptor.jdbctypenamemapper;import Org.hibernate.type.descriptor.valuebinder;import Org.hibernate.type.descriptor.wrapperoptions;import Org.hibernate.type.descriptor.java.javatypedescriptor;import Org.jboss.logging.logger;public Abstract class Basicbinder<j> implements valuebinder<j>{private static final Logger log = Corelogging.logger (basicbinder    . Class);    private static final String bind_msg_template = "binding parameter [%s] as [%s]-[%s]"; private static final String null_bind_msg_template = "binding parameter [%s] as [%s]-[NULL]";p rivate final JAVATYPEDESCR Iptor<j> javadescriptor;private final Sqltypedescriptor sqldescriptor;public javatypedescriptor<j> Getjavadescriptor () {return javadescriptor;} Public Sqltypedescriptor Getsqldescriptor () {return sqldescriptor;} Public BasIcbinder (javatypedescriptor<j> javadescriptor, Sqltypedescriptor sqldescriptor) {this.javaDescriptor = Javadescriptor;this.sqldescriptor = Sqldescriptor;}        @Overridepublic final void bind (PreparedStatement st, J value, int index, wrapperoptions options) throws SQLException {              Final Boolean traceenabled = log.istraceenabled (); if (value = = null) {if (traceenabled) {log.trace (String.Format (Null_bind_msg_template,inde            X,jdbctypenamemapper.gettypename (Getsqldescriptor (). Getsqltype ()));        } st.setnull (Index, Sqldescriptor.getsqltype ()); } else {if (traceenabled) {log.trace (String.Format (Bind_msg_template,index,jdbctypena            Memapper.gettypename (Sqldescriptor.getsqltype ()), Getjavadescriptor (). Extractloggablerepresentation (value));        } dobind (St, value, index, options); } System.out.println (St.tostring ());} /** * PerfORM the binding. Safe to assume this value is not NULL. * * @param st The prepared statement * @param value the value to bind (not null). * @param index the index at which to bind * @param options The binding options * * @throws SQLException indicates a proble M binding to the prepared statement. */protected abstract void Dobind (PreparedStatement st, J value, int index, wrapperoptions options) throws SQLException;}

Because in the hibernate mechanism, this class is the class that executes the update INSERT SQL statement, which is overridden here to overwrite

Use hibernate to intercept execution of SQL statements and output SQL statements to get SQL statements

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.