[jboss-cvs] jboss-seam/src/main/org/jboss/seam/microcontainer ...
Gavin King
gavin.king at jboss.com
Sat Oct 14 14:21:44 EDT 2006
User: gavin
Date: 06/10/14 14:21:44
Modified: src/main/org/jboss/seam/microcontainer
HibernateFactory.java
Log:
reformat
Revision Changes Path
1.10 +204 -162 jboss-seam/src/main/org/jboss/seam/microcontainer/HibernateFactory.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: HibernateFactory.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/microcontainer/HibernateFactory.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -b -r1.9 -r1.10
--- HibernateFactory.java 15 Apr 2006 05:40:27 -0000 1.9
+++ HibernateFactory.java 14 Oct 2006 18:21:44 -0000 1.10
@@ -1,4 +1,4 @@
-//$Id: HibernateFactory.java,v 1.9 2006/04/15 05:40:27 gavin Exp $
+//$Id: HibernateFactory.java,v 1.10 2006/10/14 18:21:44 gavin Exp $
package org.jboss.seam.microcontainer;
import java.io.File;
@@ -7,6 +7,7 @@
import java.util.Map;
import java.util.Properties;
+import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Environment;
import org.hibernate.util.ReflectHelper;
@@ -21,10 +22,9 @@
* <li>cfgResourceName as location of a cfg.xml file
* <li>factory-suplied cfgProperties options
* <p>
- * Note that this factory only supports cfg.xml files <b>or</b>
- * programmatic <tt>cfgProperties</tt> supplied to the factory.
- * Any <tt>hibernate.properties</tt> are always loaded from the
- * classpath.
+ * Note that this factory only supports cfg.xml files <b>or</b> programmatic
+ * <tt>cfgProperties</tt> supplied to the factory. Any
+ * <tt>hibernate.properties</tt> are always loaded from the classpath.
* <p>
* Mapping metadata can be supplied through:
* <li>mappingClasses: equivalent to <mapping class="..."/>
@@ -35,127 +35,169 @@
* <p>
* or through cfg.xml files.
* <p>
- * The <tt>jndiProperties</tt> are convenience, the factory will
- * automatically prefix regular JNDI properties for use as Hibernate
- * configuration properties.
+ * The <tt>jndiProperties</tt> are convenience, the factory will automatically
+ * prefix regular JNDI properties for use as Hibernate configuration properties.
*
* @author Gavin King
* @author Christian Bauer
*/
-public class HibernateFactory {
+public class HibernateFactory
+{
private String cfgResourceName;
private Properties cfgProperties;
-
private List<String> mappingClasses;
private List<String> mappingFiles;
private List<String> mappingJars;
private List<String> mappingPackages;
private List<String> mappingResources;
- public Object getSessionFactory() throws Exception {
- AnnotationConfiguration acfg = new AnnotationConfiguration();
+ public SessionFactory getSessionFactory() throws Exception
+ {
+ return createSessionFactory();
+ }
+
+ protected SessionFactory createSessionFactory() throws ClassNotFoundException
+ {
+ AnnotationConfiguration configuration = new AnnotationConfiguration();
// Programmatic configuration
- if (cfgProperties != null) {
- acfg.setProperties(cfgProperties);
+ if (cfgProperties != null)
+ {
+ configuration.setProperties(cfgProperties);
}
- if ( Naming.getInitialContextProperties()!=null )
+ if (Naming.getInitialContextProperties() != null)
{
// Prefix regular JNDI properties for Hibernate
Hashtable<String, String> hash = Naming.getInitialContextProperties();
- for (Map.Entry<String, String> entry: hash.entrySet() )
+ for (Map.Entry<String, String> entry : hash.entrySet())
{
- acfg.setProperty( Environment.JNDI_PREFIX + "." + entry.getKey(), entry.getValue() );
+ configuration.setProperty( Environment.JNDI_PREFIX + "." + entry.getKey(), entry.getValue() );
}
}
// hibernate.cfg.xml configuration
- if (cfgProperties == null && cfgResourceName == null) {
- acfg.configure();
+ if (cfgProperties==null && cfgResourceName==null)
+ {
+ configuration.configure();
}
- else if (cfgProperties == null && cfgResourceName != null) {
- acfg.configure(cfgResourceName);
+ else if (cfgProperties==null && cfgResourceName!=null)
+ {
+ configuration.configure(cfgResourceName);
}
// Mapping metadata
- if (mappingClasses != null)
- for(String className: mappingClasses)
- acfg.addAnnotatedClass(ReflectHelper.classForName(className));
+ if (mappingClasses!=null)
+ {
+ for (String className: mappingClasses)
+ {
+ configuration.addAnnotatedClass(ReflectHelper.classForName(className));
+ }
+ }
- if (mappingFiles != null)
- for(String fileName: mappingFiles)
- acfg.addFile(fileName);
+ if (mappingFiles!=null)
+ {
+ for (String fileName: mappingFiles)
+ {
+ configuration.addFile(fileName);
+ }
+ }
- if (mappingJars != null)
- for(String jarName: mappingJars)
- acfg.addJar( new File(jarName) );
+ if (mappingJars!=null)
+ {
+ for (String jarName: mappingJars)
+ {
+ configuration.addJar(new File(jarName));
+ }
+ }
- if (mappingPackages != null)
- for(String packageName: mappingPackages)
- acfg.addPackage(packageName);
+ if (mappingPackages!= null)
+ {
+ for (String packageName: mappingPackages)
+ {
+ configuration.addPackage(packageName);
+ }
+ }
- if (mappingResources != null)
- for(String resourceName: mappingResources)
- acfg.addResource(resourceName);
+ if (mappingResources!= null)
+ {
+ for (String resourceName : mappingResources)
+ {
+ configuration.addResource(resourceName);
+ }
+ }
- return acfg.buildSessionFactory();
+ return configuration.buildSessionFactory();
}
- public String getCfgResourceName() {
+ public String getCfgResourceName()
+ {
return cfgResourceName;
}
- public void setCfgResourceName(String cfgFileName) {
+ public void setCfgResourceName(String cfgFileName)
+ {
this.cfgResourceName = cfgFileName;
}
- public Properties getCfgProperties() {
+ public Properties getCfgProperties()
+ {
return cfgProperties;
}
- public void setCfgProperties(Properties cfgProperties) {
+ public void setCfgProperties(Properties cfgProperties)
+ {
this.cfgProperties = cfgProperties;
}
- public List<String> getMappingClasses() {
+ public List<String> getMappingClasses()
+ {
return mappingClasses;
}
- public void setMappingClasses(List<String> mappingClasses) {
+ public void setMappingClasses(List<String> mappingClasses)
+ {
this.mappingClasses = mappingClasses;
}
- public List<String> getMappingFiles() {
+ public List<String> getMappingFiles()
+ {
return mappingFiles;
}
- public void setMappingFiles(List<String> mappingFiles) {
+ public void setMappingFiles(List<String> mappingFiles)
+ {
this.mappingFiles = mappingFiles;
}
- public List<String> getMappingJars() {
+ public List<String> getMappingJars()
+ {
return mappingJars;
}
- public void setMappingJars(List<String> mappingJars) {
+ public void setMappingJars(List<String> mappingJars)
+ {
this.mappingJars = mappingJars;
}
- public List<String> getMappingPackages() {
+ public List<String> getMappingPackages()
+ {
return mappingPackages;
}
- public void setMappingPackages(List<String> mappingPackages) {
+ public void setMappingPackages(List<String> mappingPackages)
+ {
this.mappingPackages = mappingPackages;
}
- public List<String> getMappingResources() {
+ public List<String> getMappingResources()
+ {
return mappingResources;
}
- public void setMappingResources(List<String> mappingResources) {
+ public void setMappingResources(List<String> mappingResources)
+ {
this.mappingResources = mappingResources;
}
More information about the jboss-cvs-commits
mailing list