1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.jdiagnose.library.db;
17
18 import java.sql.Connection;
19 import java.sql.SQLException;
20 import java.sql.Statement;
21
22 import net.sf.hibernate.HibernateException;
23 import net.sf.hibernate.Session;
24 import net.sf.hibernate.SessionFactory;
25
26 import org.jdiagnose.DiagnosticUnit;
27
28 /***
29 * @author jmccrindle
30 */
31 public class HibernateDiagnostic extends DiagnosticUnit {
32
33 private SessionFactory sessionFactory = null;
34 private String sql;
35
36 /***
37 * Default Constructor
38 */
39 public HibernateDiagnostic() {
40 super();
41 }
42
43 /***
44 * @param name
45 */
46 public HibernateDiagnostic(String name) {
47 super(name);
48 }
49
50 public void diagnoseSql() throws HibernateException, SQLException {
51 Session session = sessionFactory.openSession();
52 Connection connection = session.connection();
53 Statement statement = connection.createStatement();
54 statement.execute(sql);
55 }
56
57 public SessionFactory getSessionFactory() {
58 return sessionFactory;
59 }
60 public void setSessionFactory(SessionFactory sessionFactory) {
61 this.sessionFactory = sessionFactory;
62 }
63 public String getSql() {
64 return sql;
65 }
66 public void setSql(String sql) {
67 this.sql = sql;
68 }
69 }