This commit is contained in:
Ashish Trivedi 2020-08-10 13:21:24 +05:30
parent 108532d8dd
commit 75b10ed657
4 changed files with 12 additions and 55 deletions

View File

@ -88,7 +88,7 @@ public class App {
var statement = connection.createStatement()) {
statement.execute(RoomSchemaSql.CREATE_SCHEMA_SQL);
} catch (Exception e) {
throw new SqlException(e.getMessage(), e);
throw new Exception(e.getMessage(), e);
}
}

View File

@ -74,7 +74,7 @@ public class HotelDaoImpl implements HotelDao {
}
});
} catch (Exception e) {
throw new SqlException(e.getMessage(), e);
throw new Exception(e.getMessage(), e);
}
}
@ -92,8 +92,8 @@ public class HotelDaoImpl implements HotelDao {
} else {
return Optional.empty();
}
} catch (Exception ex) {
throw new SqlException(ex.getMessage(), ex);
} catch (Exception e) {
throw new Exception(e.getMessage(), e);
} finally {
if (resultSet != null) {
resultSet.close();
@ -115,8 +115,8 @@ public class HotelDaoImpl implements HotelDao {
statement.setBoolean(4, room.isBooked());
statement.execute();
return true;
} catch (Exception ex) {
throw new SqlException(ex.getMessage(), ex);
} catch (Exception e) {
throw new Exception(e.getMessage(), e);
}
}
@ -132,8 +132,8 @@ public class HotelDaoImpl implements HotelDao {
statement.setBoolean(3, room.isBooked());
statement.setInt(4, room.getId());
return statement.executeUpdate() > 0;
} catch (Exception ex) {
throw new SqlException(ex.getMessage(), ex);
} catch (Exception e) {
throw new Exception(e.getMessage(), e);
}
}
@ -143,8 +143,8 @@ public class HotelDaoImpl implements HotelDao {
var statement = connection.prepareStatement("DELETE FROM ROOMS WHERE ID = ?")) {
statement.setInt(1, room.getId());
return statement.executeUpdate() > 0;
} catch (Exception ex) {
throw new SqlException(ex.getMessage(), ex);
} catch (Exception e) {
throw new Exception(e.getMessage(), e);
}
}
@ -159,7 +159,7 @@ public class HotelDaoImpl implements HotelDao {
statement.close();
connection.close();
} catch (Exception e) {
throw new SqlException(e.getMessage(), e);
throw new Exception(e.getMessage(), e);
}
}

View File

@ -1,43 +0,0 @@
/*
* The MIT License
* Copyright © 2014-2019 Ilkka Seppälä
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.ashishtrivedi16.transactionscript;
/**
* Custom exception.
*/
public class SqlException extends Exception {
private static final long serialVersionUID = 1L;
public SqlException() {
}
public SqlException(String message) {
super(message);
}
public SqlException(String message, Throwable cause) {
super(message, cause);
}
}

View File

@ -114,7 +114,7 @@ public class HotelTest {
var statement = connection.createStatement()) {
statement.execute(RoomSchemaSql.CREATE_SCHEMA_SQL);
} catch (Exception e) {
throw new SqlException(e.getMessage(), e);
throw new Exception(e.getMessage(), e);
}
}