[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-1124?page=c...
]
Steve Ebersole closed HHH-1124.
-------------------------------
Closing stale resolved issues
Provide factory for IoC container configuration
-----------------------------------------------
Key: HHH-1124
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-1124
Project: Hibernate Core
Issue Type: New Feature
Components: core
Reporter: Christian Bauer
Assignee: Steve Ebersole
Priority: Minor
I remember an issue back in the H2 days about this, but couldn't find it again.
We should provide an IoC configuration factory, out-of-the-box in Hibernate, very similar
to what Seam has right now:
public class HibernateFactory {
private String cfgResourceName;
private Properties cfgProperties;
private Hashtable jndiProperties;
private List<String> mappingClasses;
private List<String> mappingFiles;
private List<String> mappingJars;
private List<String> mappingPackages;
private List<String> mappingResources;
public Object buildSessionFactory() throws Exception {
AnnotationConfiguration acfg = new AnnotationConfiguration();
// Programmatic configuration
if (cfgProperties != null) {
acfg.setProperties(cfgProperties);
}
// Prefix regular JNDI properties for Hibernate
if (jndiProperties != null) {
for (Iterator it = jndiProperties.entrySet().iterator(); it.hasNext();) {
Map.Entry entry = (Map.Entry)it.next();
acfg.setProperty(Environment.JNDI_PREFIX + "." +
entry.getKey(),
(String)entry.getValue() );
}
}
// hibernate.cfg.xml configuration
if (cfgProperties == null && cfgResourceName == null) {
acfg.configure();
} else if (cfgProperties == null && cfgResourceName != null) {
acfg.configure(cfgResourceName);
}
// Mapping metadata
if (mappingClasses != null)
for(String className: mappingClasses)
acfg.addAnnotatedClass(ReflectHelper.classForName(className));
if (mappingFiles != null)
for(String fileName: mappingFiles)
acfg.addFile(fileName);
if (mappingJars != null)
for(String jarName: mappingJars)
acfg.addJar( new File(jarName) );
if (mappingPackages != null)
for(String packageName: mappingPackages)
acfg.addPackage(packageName);
if (mappingResources != null)
for(String resourceName: mappingResources)
acfg.addResource(resourceName);
return acfg.buildSessionFactory();
}
public String getCfgResourceName() {
return cfgResourceName;
}
public void setCfgResourceName(String cfgFileName) {
this.cfgResourceName = cfgFileName;
}
public Properties getCfgProperties() {
return cfgProperties;
}
public void setCfgProperties(Properties cfgProperties) {
this.cfgProperties = cfgProperties;
}
public List<String> getMappingClasses() {
return mappingClasses;
}
public void setMappingClasses(List<String> mappingClasses) {
this.mappingClasses = mappingClasses;
}
public List<String> getMappingFiles() {
return mappingFiles;
}
public void setMappingFiles(List<String> mappingFiles) {
this.mappingFiles = mappingFiles;
}
public List<String> getMappingJars() {
return mappingJars;
}
public void setMappingJars(List<String> mappingJars) {
this.mappingJars = mappingJars;
}
public List<String> getMappingPackages() {
return mappingPackages;
}
public void setMappingPackages(List<String> mappingPackages) {
this.mappingPackages = mappingPackages;
}
public List<String> getMappingResources() {
return mappingResources;
}
public void setMappingResources(List<String> mappingResources) {
this.mappingResources = mappingResources;
}
public Hashtable getJndiProperties() {
return jndiProperties;
}
public void setJndiProperties(Hashtable jndiProperties) {
this.jndiProperties = jndiProperties;
}
}
(The reason for the separate jndiProperties is simple: We inject the same properties as
for the JBoss Microcontainer, without the hibernate.* prefix.)
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira