View Javadoc

1   /*
2    * Copyright 2001-2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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  }