Ejemplo n.º 1
0
public class LockManager {

  private static final String ALIAS = FenixFramework.<JvstmOJBConfig>getConfig().getDbAlias();

  @SuppressWarnings("resource")
  public static boolean acquireDistributedLock(String lockName) {
    try {
      Connection connection = ConnectionManager.getCurrentSQLConnection();
      Statement statement = connection.createStatement();
      ResultSet resultSet =
          statement.executeQuery("SELECT GET_LOCK('" + lockName + ALIAS + "', 10)");

      boolean result = resultSet.next() && (resultSet.getInt(1) == 1);
      resultSet.close();
      statement.close();

      return result;
    } catch (SQLException e) {
      throw new Error(e);
    }
  }

  @SuppressWarnings("resource")
  public static void releaseDistributedLock(String lockName) {
    try {
      Connection connection = ConnectionManager.getCurrentSQLConnection();
      Statement statement = connection.createStatement();
      statement.executeUpdate("DO RELEASE_LOCK('" + lockName + ALIAS + "')");

      statement.close();
    } catch (SQLException e) {
      throw new Error(e);
    }
  }
}
Ejemplo n.º 2
0
 private void removeFromDeleted(DomainObject obj) {
   if (objsToDelete != null) {
     if (objsToDelete.remove(obj)) {
       if (FenixFramework.getConfig().isErrorIfChangingDeletedObject()) {
         throw new Error("Changing object after it was deleted: " + obj);
       } else {
         System.err.println("WARNING: Changing object after it was deleted: " + obj);
       }
     }
   }
 }