1 5 package org.hibernate.eclipse.console.actions; 6 7 import java.sql.DriverManager ; 8 import java.util.Iterator ; 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 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 40 protected void doRun() { 41 for (Iterator 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 config.build(); 51 config.initSessionFactory(); 52 } 53 updateState(config); 54 } 55 56 viewer.refresh(node); } catch(HibernateConsoleRuntimeException he) { 58 HibernateConsolePlugin.getDefault().showError(viewer.getControl().getShell(), "Exception while connecting/starting Hibernate",he); 59 } catch(UnsupportedClassVersionError 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 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 |