@Override
	public void insertOrderFromShoppingBasket(List<ShoppingBasket> orderLine, WarehouseRepository wr) throws StorageException {
		ResultSet rs = null;
	    Connection conn = null;
	    PreparedStatement pstmt = null;
	    
	    try {
			conn = Database.getConnection();
			conn.setAutoCommit(false);
			
			String query = "INSERT INTO orders VALUES (null, now());";
			pstmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS);
			pstmt.executeUpdate();
			
			rs = pstmt.getGeneratedKeys();
			rs.next();
			
			int autoGeneratedOrderId = rs.getInt(1);
			
			pstmt.close();
			
			query = "INSERT INTO orderlines VALUES (null, ?, ?, ?, ?);";
			pstmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS);
			
			for(ShoppingBasket sb : orderLine) {
				pstmt.setInt(1, sb.getQuantity());
				pstmt.setInt(2, autoGeneratedOrderId);
				pstmt.setInt(3, sb.getUserId());
				pstmt.setInt(4, sb.getProductId());
				pstmt.executeUpdate();
			}
			
			query = "UPDATE warehouse "
				  + "SET warehouse.stock = ?, "
				  + "warehouse.products_id = ? "
				  + "WHERE warehouse.products_id = ?;";
			
			pstmt = conn.prepareStatement(query);
			
			for(ShoppingBasket sb : orderLine) {
				int updatedStock = wr.getWarehouseOnProductId(sb.getProductId()).get(0).getStock() - sb.getQuantity();
				pstmt.setInt(1, updatedStock);
				pstmt.setInt(2, sb.getProductId());
				pstmt.setInt(3, sb.getProductId());
				pstmt.executeUpdate();
			}
			
			query = "DELETE FROM shoppingbasket WHERE users_id = ?";
			pstmt = conn.prepareStatement(query);
			pstmt.setInt(1, orderLine.get(0).getUserId());
			pstmt.executeUpdate();
			
			conn.commit();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
			throw new StorageException(e.getMessage());
		} catch (SQLException e) {
			try {
				conn.rollback();
			} catch (SQLException e1) {
				e1.printStackTrace();
				throw new StorageException(e1.getMessage());
			}
			e.printStackTrace();
			throw new StorageException(e.getMessage());
		} finally {
			try {
				if(rs != null) {
					rs.close();
				}
				if(pstmt != null) {
					pstmt.close();
				}
				if(conn != null) {
					conn.close();
				}
			} catch (SQLException e) {
				e.printStackTrace();
				throw new StorageException(e.getMessage());
			}
		}
	}