-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: patch to pretty print show_sql
PostPosted: Tue Oct 19, 2004 7:01 pm 
Newbie

Joined: Fri Aug 20, 2004 1:13 pm
Posts: 10
Hibernate version:2.1.6

I have a minor patch to BatcherImpl that will pretty up the sql displayed on the console running hibernate with show_sql. Should I submit it thru the JIRA? Does anyone even want it?


Index: BatcherImpl.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/impl/BatcherImpl.java,v
retrieving revision 1.16
diff -u -r1.16 BatcherImpl.java
--- BatcherImpl.java 7 Aug 2004 14:05:39 -0000 1.16
+++ BatcherImpl.java 19 Oct 2004 22:59:44 -0000
@@ -7,6 +7,8 @@
import java.sql.SQLException;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -224,9 +226,25 @@

private void log(String sql) {
sqlLog.debug(sql);
- if ( factory.isShowSqlEnabled() ) System.out.println("Hibernate: " + sql);
+ if ( factory.isShowSqlEnabled() ) System.out.println("Hibernate: " + format(sql));
}
-
+
+ private String format(String sql) {
+ String out = sql;
+ Pattern p = Pattern.compile(" (left|right|)\\s*(inner|outer|)\\s*join ");
+ Matcher matcher = p.matcher(out);
+ if (matcher.find()) {
+ out = matcher.replaceAll("\n" + matcher.group());
+ }
+ p = Pattern.compile(" from ");
+ matcher = p.matcher(out);
+ out = matcher.replaceAll("\n from ");
+ p = Pattern.compile(" where ");
+ matcher = p.matcher(out);
+ out = matcher.replaceAll("\n where ");
+ return out;
+ }
+
private PreparedStatement getPreparedStatement(final Connection conn, final String sql, boolean scrollable)
throws SQLException {
return getPreparedStatement(conn, sql, scrollable, false);

_________________
-alan


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 19, 2004 7:31 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
I would submit it to JIRA and see what Gavin thinks.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.