KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > eclipse > console > actions > BuildSessionFactoryAction


1 /*
2  * Created on 2004-10-29 by max
3  *
4  */

5 package org.hibernate.eclipse.console.actions;
6
7 import java.sql.DriverManager JavaDoc;
8 import java.util.Iterator JavaDoc;
9
10 import org.eclipse.core.runtime.IStatus;
11 import org.eclipse.core.runtime.Status;
12 import org.eclipse.jface.dialogs.ErrorDialog;
13 import org.eclipse.jface.viewers.StructuredViewer;
14 import org.hibernate.HibernateException;
15 import org.hibernate.console.ConsoleConfiguration;
16 import org.hibernate.console.HibernateConsoleRuntimeException;
17 import org.hibernate.eclipse.console.HibernateConsolePlugin;
18 import org.hibernate.console.node.BaseNode;
19 import org.hibernate.console.node.ConfigurationNode;
20
21 /**
22  * @author max
23  *
24  */

25 public class BuildSessionFactoryAction extends ConsoleConfigurationBasedAction {
26
27     private final StructuredViewer viewer;
28
29     public BuildSessionFactoryAction(StructuredViewer viewer) {
30         super("Build SessionFactory");
31         this.viewer = viewer;
32         setEnabledWhenNoSessionFactory(true);
33     }
34     
35     
36
37     /**
38      *
39      */

40     protected void doRun() {
41         for (Iterator JavaDoc i = getSelectedNonResources().iterator(); i.hasNext();) {
42             try {
43             BaseNode node = ((BaseNode) i.next());
44             if(node instanceof ConfigurationNode) {
45                 ConsoleConfiguration config = node.getConsoleConfiguration();
46                 if(config.isSessionFactoryCreated()) {
47                     config.reset();
48                 } else {
49                     //DriverManager.setLogStream(System.out);
50
config.build();
51                     config.initSessionFactory();
52                 }
53                 updateState(config);
54             }
55             
56             viewer.refresh(node); // todo: should we do it here or should the view just react to config being build ?
57
} catch(HibernateConsoleRuntimeException he) {
58                  HibernateConsolePlugin.getDefault().showError(viewer.getControl().getShell(), "Exception while connecting/starting Hibernate",he);
59             } catch(UnsupportedClassVersionError JavaDoc ucve) {
60                  HibernateConsolePlugin.getDefault().showError(viewer.getControl().getShell(), "Starting Hibernate resulted in a UnsupportedClassVersionError.\nThis can occur if you are running eclipse with JDK 1.4 and your domain classes require JDK 1.5. \n\nResolution: Run eclipse with JDK 1.5.",ucve);
61             }
62         }
63     }
64
65     /**
66      * @param config
67      */

68     protected boolean updateState(ConsoleConfiguration config) {
69         setEnabledWhenNoSessionFactory(!config.isSessionFactoryCreated());
70         if(enabledWhenNoSessionFactory) {
71             setText("Create SessionFactory");
72         } else {
73             setText("Close SessionFactory");
74         }
75         return super.updateState(config);
76     }
77 }
78
Popular Tags