All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mageddo.db.ConnectionUtils Maven / Gradle / Ivy

There is a newer version: 2.1.6-alpha
Show newest version
package com.mageddo.db;

import java.sql.Connection;
import java.sql.SQLException;

import com.mageddo.tobby.UncheckedSQLException;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class ConnectionUtils {
  public static void useTransaction(Connection con, Runnable runnable) {
    try {
      runnable.run();
      con.commit();
    } catch (SQLException e) {
      try {
        con.rollback();
        throw new UncheckedSQLException(e);
      } catch (SQLException e2) {
        throw new UncheckedSQLException(e2);
      }
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy