Skip to content

Commit

Permalink
fix: revert useSession returning boolean in HibernateUtil.java
Browse files Browse the repository at this point in the history
  • Loading branch information
Panzer1119 committed Aug 3, 2021
1 parent 4b2aa61 commit 375b3f0
Showing 1 changed file with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,25 +71,23 @@ public static SessionFactory createSessionFactory(Metadata metadata) {
return metadata.buildSessionFactory();
}

public static boolean useSession(DatabaseConnector databaseConnector, ToughPredicate<Session> sessionConsumer) {
return useSession(databaseConnector, sessionConsumer, false);
public static void useSession(DatabaseConnector databaseConnector, ToughConsumer<Session> sessionConsumer) {
useSession(databaseConnector, sessionConsumer, false);
}

public static boolean useSession(DatabaseConnector databaseConnector, ToughPredicate<Session> sessionConsumer, boolean silent) {
public static void useSession(DatabaseConnector databaseConnector, ToughConsumer<Session> sessionConsumer, boolean silent) {
Objects.requireNonNull(databaseConnector);
Objects.requireNonNull(sessionConsumer);
final Session session = databaseConnector.getOrOpenSession();
synchronized (databaseConnector.getLock()) {
final Transaction transaction = session.beginTransaction();
try {
final Boolean result = sessionConsumer.test(session);
sessionConsumer.accept(session);
transaction.commit();
return result;
} catch (Exception e) {
if (!silent) {
logger.error("Error while using Session", e);
}
return false;
} finally {
transaction.rollback();
}
Expand Down

0 comments on commit 375b3f0

Please sign in to comment.