public DataBaseManagement(String driver, String dbURL) { try { this.dbURL = dbURL; Class.forName(driver).newInstance(); conn = DriverManager.getConnection(dbURL); } catch (InstantiationException | IllegalAccessException | ClassNotFoundException | SQLException e) { // TODO Auto-generated catch block if (e instanceof SQLException) { SQLException sqle = (SQLException) e; if (sqle.getSQLState().equals("XJ040")) { sqle = sqle.getNextException(); if (sqle.getSQLState().equals("XSDB6")) { logger.error(sqle.getMessage() + " Please shutdown that other instance of Derby."); } } } else { CustomException.errorPrint(e); } } }
@ExceptionHandler({ InvalidEntityConstraintsException.class, InvalidIdException.class, EntityAlreadyExistsException.class, AssociationAlreadyExistsException.class }) public ResponseEntity<?> handleBadRequests(CustomException e) { return new ResponseEntity<>(e.getErrorMessage(), HttpStatus.BAD_REQUEST); }
@Override public void run() { // TODO Auto-generated method stub try { dropAllTables(); createTables(); } catch (SQLException e) { // TODO Auto-generated catch block CustomException.errorPrint(e); } }
@ExceptionHandler({EntityNotFoundException.class, AssociationNotFoundException.class}) public ResponseEntity<?> handleNotFounds(CustomException e) { return new ResponseEntity<>(e.getErrorMessage(), HttpStatus.NOT_FOUND); }