forked from jenkinsci/audit2db-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#JENKINS-21058 - Reuse SessionFactory and load hibernate properties u…
…sing hibernate prefix.
- Loading branch information
1 parent
3929d64
commit 8d659b4
Showing
2 changed files
with
22 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,8 @@ | |
public class HibernateUtil { | ||
private final static Logger LOGGER = Logger.getLogger(HibernateUtil.class.getName()); | ||
|
||
private static SessionFactory factory = null; | ||
|
||
private static Configuration getConfig(final Properties extraProperties) throws HibernateException { | ||
LOGGER.log(Level.INFO, Messages.HibernateUtil_LoadConfig()); | ||
final Configuration config = new AnnotationConfiguration().configure(); | ||
|
@@ -38,19 +40,20 @@ private static Configuration getConfig(final Properties extraProperties) throws | |
} | ||
|
||
public static SessionFactory getSessionFactory(final Properties extraProperties) { | ||
SessionFactory retval = null; | ||
|
||
try { | ||
// Load base configuration from hibernate.cfg.xml | ||
final Configuration config = getConfig(extraProperties); | ||
retval = config.buildSessionFactory(); | ||
} catch (final Exception e) { | ||
// Make sure you log the exception, as it might be swallowed | ||
LOGGER.log(Level.SEVERE, Messages.HibernateUtil_FailedSessionFactory(), e); | ||
throw new RuntimeException(e); | ||
|
||
if (factory == null){ | ||
try { | ||
// Load base configuration from hibernate.cfg.xml | ||
final Configuration config = getConfig(extraProperties); | ||
factory = config.buildSessionFactory(); | ||
} catch (final Exception e) { | ||
// Make sure you log the exception, as it might be swallowed | ||
LOGGER.log(Level.SEVERE, Messages.HibernateUtil_FailedSessionFactory(), e); | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
return factory; | ||
|
||
return retval; | ||
} | ||
|
||
public static SessionFactory getSessionFactory() { | ||
|
@@ -86,7 +89,7 @@ public static String getSchemaDdl( | |
|
||
final Configuration config = getConfig(props); | ||
final SchemaExport generator = new SchemaExport(config); | ||
final File tempDdlFile = File.createTempFile("jenkins_audit2db", ".ddl"); | ||
final File tempDdlFile = new File("jenkins_audit2db.ddl"); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
ricardogarfe
Author
Owner
|
||
generator.setOutputFile(tempDdlFile.getPath()); | ||
generator.setFormat(true); | ||
generator.execute(true, false, false, true); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Hi Ricardo,
What's the purpose for this change?