001: /*
002: * Copyright (C) 2005 - 2008 JasperSoft Corporation. All rights reserved.
003: * http://www.jaspersoft.com.
004: *
005: * Unless you have purchased a commercial license agreement from JasperSoft,
006: * the following license terms apply:
007: *
008: * This program is free software; you can redistribute it and/or modify
009: * it under the terms of the GNU General Public License version 2 as published by
010: * the Free Software Foundation.
011: *
012: * This program is distributed WITHOUT ANY WARRANTY; and without the
013: * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
014: * See the GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
018: * or write to:
019: *
020: * Free Software Foundation, Inc.,
021: * 59 Temple Place - Suite 330,
022: * Boston, MA USA 02111-1307
023: *
024: *
025: *
026: *
027: * JRHibernateConnection.java
028: *
029: * Created on 4 giugno 2003, 18.15
030: *
031: */
032:
033: package it.businesslogic.ireport.connection;
034:
035: import it.businesslogic.ireport.IReportConnectionEditor;
036: import it.businesslogic.ireport.connection.gui.JRHibernateConnectionEditor;
037: import it.businesslogic.ireport.gui.MainFrame;
038: import it.businesslogic.ireport.util.I18n;
039: import javax.swing.JOptionPane;
040: import javax.swing.SwingUtilities;
041: import org.hibernate.SessionFactory;
042: import org.hibernate.cfg.Configuration;
043: import org.hibernate.classic.Session;
044:
045: /**
046: *
047: * @author Administrator
048: */
049: public class JRHibernateConnection extends
050: it.businesslogic.ireport.IReportConnection {
051:
052: private String name;
053:
054: /** Creates a new instance of JRHibernateConnection */
055: public JRHibernateConnection() {
056: }
057:
058: /** This method return an instanced connection to the database.
059: * If isJDBCConnection() return false => getConnection() return null
060: *
061: */
062: public java.sql.Connection getConnection() {
063: return null;
064: }
065:
066: public boolean isJDBCConnection() {
067: return false;
068: }
069:
070: public boolean isJRDataSource() {
071: return false;
072: }
073:
074: /*
075: * This method return all properties used by this connection
076: */
077: public java.util.HashMap getProperties() {
078: java.util.HashMap map = new java.util.HashMap();
079: return map;
080: }
081:
082: public void loadProperties(java.util.HashMap map) {
083: }
084:
085: /**
086: * Getter for property name.
087: * @return Value of property name.
088: */
089: public java.lang.String getName() {
090: return name;
091: }
092:
093: /**
094: * Setter for property name.
095: * @param name New value of property name.
096: */
097: public void setName(java.lang.String name) {
098: this .name = name;
099: }
100:
101: /**
102: * This method return an instanced JRDataDource to the database.
103: * If isJDBCConnection() return true => getJRDataSource() return false
104: */
105: public net.sf.jasperreports.engine.JRDataSource getJRDataSource() {
106: return null;
107: }
108:
109: public Session createSession()
110: throws org.hibernate.HibernateException {
111: return getSessionFactory().openSession();
112: }
113:
114: public SessionFactory getSessionFactory()
115: throws org.hibernate.HibernateException {
116:
117: return new Configuration().configure().buildSessionFactory();
118: }
119:
120: public String getDescription() {
121: return I18n.getString("connectionType.hibernate",
122: "Hibernate connection");
123: }
124:
125: public IReportConnectionEditor getIReportConnectionEditor() {
126: return new JRHibernateConnectionEditor();
127: }
128:
129: public void test() throws Exception {
130: try {
131: SwingUtilities.invokeLater(new Runnable() {
132: public void run() {
133: Thread.currentThread().setContextClassLoader(
134: MainFrame.getMainInstance()
135: .getReportClassLoader());
136: SessionFactory hb_sessionFactory = null;
137: try {
138:
139: hb_sessionFactory = new Configuration()
140: .configure().buildSessionFactory();
141:
142: JOptionPane
143: .showMessageDialog(
144: MainFrame.getMainInstance(),
145: I18n
146: .getString(
147: "messages.connectionDialog.connectionTestSuccessful",
148: "Connection test successful!"),
149: "",
150: JOptionPane.INFORMATION_MESSAGE);
151:
152: } catch (Exception ex) {
153: ex.printStackTrace();
154: JOptionPane.showMessageDialog(MainFrame
155: .getMainInstance(), ex.getMessage(),
156: I18n.getString("message.title.error",
157: "Error"),
158: JOptionPane.ERROR_MESSAGE);
159: return;
160: } finally {
161:
162: }
163: }
164: });
165: } catch (Exception ex) {
166: }
167: }
168: }
|