/** * Get admin by id * * @param wrapperConnection wrapper connection regarding to which prepared statement might be * created * @param id admin id * @return prepared statement * @throws SQLException */ @Override protected DBEntity getEntityById(WrapperConnectionProxy wrapperConnection, int id) throws SQLException { PreparedStatement ps = wrapperConnection.prepareStatement(SQL_FOR_ADMIN_BY_ID); ps.setInt(1, id); ResultSet rs = ps.executeQuery(); if (rs.next()) { return getAdmin(rs); } return null; }
/** * Insert entity into the data base from the object oriented entity * * @param wrapperConnection wrapper connection from the connection pool * @param entity entity might be inserting into the data base * @throws SQLException */ @Override protected void insertEntity(WrapperConnectionProxy wrapperConnection, DBEntity entity) throws SQLException { Admin admin = (Admin) entity; PreparedStatement ps = wrapperConnection.prepareStatement(SQL_FOR_ADMIN_INSERTING); ps.setString(1, admin.getFirstName()); ps.setString(2, admin.getLastName()); ps.setString(3, admin.getAdminType().toString()); ps.setString(4, admin.getEmail()); ps.setString(5, admin.getLogin()); ps.setString(6, admin.getPassword()); ps.executeUpdate(); }
/** * Delete entity from the data base by id * * @param wrapperConnection wrapper conection * @param id entity id * @throws SQLException */ @Override protected void deleteById(WrapperConnectionProxy wrapperConnection, int id) throws SQLException { PreparedStatement ps = wrapperConnection.prepareStatement(SQL_FOR_DELETING_BY_ID); ps.setInt(1, id); ps.executeUpdate(); }