Skip to content

Commit

Permalink
deprecate hibernate criteria
Browse files Browse the repository at this point in the history
  • Loading branch information
mbussolotto committed Aug 23, 2024
1 parent 0012f2d commit f7f1e4b
Show file tree
Hide file tree
Showing 37 changed files with 3,112 additions and 2,707 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@

import io.prometheus.client.hibernate.HibernateStatisticsCollector;


/**
* Manages the lifecycle of Hibernate SessionFactory and associated
* thread-scoped Hibernate sessions.
Expand All @@ -54,11 +53,11 @@ abstract class AbstractConnectionManager implements ConnectionManager {
private final Set<String> packageNames;
private String unitLabelValue;


/**
* Set up the connection manager.
*
* @param packageNamesSet set of packages that will be scanned for hbm.xml files on initialization.
* @param packageNamesSet set of packages that will be scanned for hbm.xml files
* on initialization.
*/
protected AbstractConnectionManager(Set<String> packageNamesSet) {
this.LOG = LogManager.getLogger(getClass());
Expand Down Expand Up @@ -129,11 +128,9 @@ public ClassMetadata getMetadata(Object target) {
public synchronized void close() {
try {
sessionFactory.close();
}
catch (HibernateException e) {
} catch (HibernateException e) {
LOG.debug("Could not close the SessionFactory", e);
}
finally {
} finally {
sessionFactory = null;
}
}
Expand Down Expand Up @@ -182,18 +179,14 @@ protected void createSessionFactory() {
final Configuration config = new Configuration();

/*
* Let's ask the RHN Config for all properties that begin with
* hibernate.*
* Let's ask the RHN Config for all properties that begin with hibernate.*
*/
LOG.info("Adding hibernate properties to hibernate Configuration");
config.addProperties(getConfigurationProperties());

// Collect all the hbm files available in the specified packages
packageNames.stream()
.map(FinderFactory::getFinder)
.flatMap(finder -> finder.find("hbm.xml").stream())
.peek(hbmFile -> LOG.debug("Adding resource {}", hbmFile))
.forEach(config::addResource);
packageNames.stream().map(FinderFactory::getFinder).flatMap(finder -> finder.find("hbm.xml").stream())
.peek(hbmFile -> LOG.debug("Adding resource {}", hbmFile)).forEach(config::addResource);

// Invoke each configurator to add additional entries to Hibernate config
configurators.forEach(configurator -> configurator.addConfig(config));
Expand All @@ -205,8 +198,7 @@ protected void createSessionFactory() {
config.setInterceptor(new EmptyVarcharInterceptor(true));

sessionFactory = config.buildSessionFactory();
}
catch (HibernateException e) {
} catch (HibernateException e) {
LOG.error("FATAL ERROR creating HibernateFactory", e);
}
}
Expand Down Expand Up @@ -270,8 +262,7 @@ public Session getSession() {
}
info = new SessionInfo(sessionFactory.openSession());
LOG.debug("YYY Opened Hibernate session {}", info.getSession());
}
catch (HibernateException e) {
} catch (HibernateException e) {
throw new HibernateRuntimeException("couldn't open session", e);
}
sessionInfoThreadLocal.set(info);
Expand Down Expand Up @@ -308,14 +299,12 @@ public void closeSession() {
if (txn != null && txn.getStatus().isNotOneOf(COMMITTED, ROLLED_BACK)) {
try {
txn.commit();
}
catch (RuntimeException commitException) {
} catch (RuntimeException commitException) {
LOG.warn("Unable to commit transaction", commitException);

try {
txn.rollback();
}
catch (RuntimeException rollbackException) {
} catch (RuntimeException rollbackException) {
LOG.warn("Unable to rollback transaction", rollbackException);
}
}
Expand All @@ -328,11 +317,9 @@ public void closeSession() {
}
session.close();
}
}
catch (RuntimeException e) {
} catch (RuntimeException e) {
throw new HibernateRuntimeException("couldn't close session", e);
}
finally {
} finally {
sessionInfoThreadLocal.remove();
}
}
Expand Down
Loading

0 comments on commit f7f1e4b

Please sign in to comment.