use of org.hibernate.connection.ConnectionProvider in project xwiki-platform by xwiki.
the class HibernateStore method shutdownHibernate.
/**
* Allows to shut down the hibernate configuration Closing all pools and connections.
*/
public void shutdownHibernate() {
Session session = getCurrentSession();
closeSession(session);
// Close all connections
if (getSessionFactory() != null) {
// Note that we need to do the cast because this is how Hibernate suggests to get the Connection Provider.
// See http://bit.ly/QAJXlr
ConnectionProvider connectionProvider = ((SessionFactoryImplementor) getSessionFactory()).getConnectionProvider();
connectionProvider.close();
}
}
use of org.hibernate.connection.ConnectionProvider in project xwiki-platform by xwiki.
the class HibernateStore method getDatabaseMetaData.
/**
* Retrieve metadata about the database used (name, version, etc).
* <p>
* Note that the database metadata is not cached and it's retrieved at each call. If all you need is the database
* product name you should use {@link #getDatabaseProductName()} instead, which is cached.
* </p>
*
* @return the database meta data or null if an error occurred
* @since 6.1M1
*/
public DatabaseMetaData getDatabaseMetaData() {
DatabaseMetaData result;
Connection connection = null;
// Note that we need to do the cast because this is how Hibernate suggests to get the Connection Provider.
// See http://bit.ly/QAJXlr
ConnectionProvider connectionProvider = ((SessionFactoryImplementor) getSessionFactory()).getConnectionProvider();
try {
connection = connectionProvider.getConnection();
result = connection.getMetaData();
} catch (SQLException ignored) {
result = null;
} finally {
if (connection != null) {
try {
connectionProvider.closeConnection(connection);
} catch (SQLException ignored) {
// Ignore
}
}
}
return result;
}
use of org.hibernate.connection.ConnectionProvider in project xwiki-platform by xwiki.
the class XWikiHibernateStore method injectInSessionFactory.
private SessionFactory injectInSessionFactory(Configuration config) throws XWikiException {
SessionFactoryImpl sfactory = (SessionFactoryImpl) config.buildSessionFactory();
Settings settings = sfactory.getSettings();
ConnectionProvider provider = ((SessionFactoryImpl) getSessionFactory()).getSettings().getConnectionProvider();
Field field = null;
try {
field = settings.getClass().getDeclaredField("connectionProvider");
field.setAccessible(true);
field.set(settings, provider);
} catch (Exception e) {
throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_MAPPING_INJECTION_FAILED, "Mapping injection failed", e);
}
return sfactory;
}
use of org.hibernate.connection.ConnectionProvider in project xwiki-platform by xwiki.
the class XWikiHibernateStore method injectCustomMappingsInSessionFactory.
private SessionFactory injectCustomMappingsInSessionFactory(XWikiDocument doc, XWikiContext context) throws XWikiException {
// If we haven't turned of dynamic custom mappings we should not inject them
if (!context.getWiki().hasDynamicCustomMappings()) {
return getSessionFactory();
}
boolean result = injectCustomMappings(doc, context);
if (!result) {
return getSessionFactory();
}
Configuration config = getConfiguration();
SessionFactoryImpl sfactory = (SessionFactoryImpl) config.buildSessionFactory();
Settings settings = sfactory.getSettings();
ConnectionProvider provider = ((SessionFactoryImpl) getSessionFactory()).getSettings().getConnectionProvider();
Field field = null;
try {
field = settings.getClass().getDeclaredField("connectionProvider");
field.setAccessible(true);
field.set(settings, provider);
} catch (Exception e) {
throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_MAPPING_INJECTION_FAILED, "Mapping injection failed", e);
}
return sfactory;
}
Aggregations