probably an unpopular opinion
I have a three year old daughter, whom my boxer Maggie loves dearly. I have watched the interaction between the two of them and I want to stress that I am not an expert but just trying to help.
Perhaps, the best way to handle this situation is to make freinds between the dog and the 2&1/2 year old and get them used to each other. Perhaps have them meet in a nuetral area like the front yard. The two year old is too young to have any idea that what he/she is doing is disruptive to the dog. Yes the Mother should be supervising her child, but a child will find the most ordinary things facinating at that age. The sound a stick makes when scrapped against the fence, a rock thrown across the yard, a shell, a bug, whatever. The two year old is too young to understand that this bothers your dog, the child may have just wanted to touch the dog and couldn't reach.
I know that this will not apply if the child is older, and has some level of understanding, but at two a child does not purposefully hurt anything.
Building a fence will not acclimate your dog to see the child as not a threat to his yard or himself, getting to know the child as a playmate will take away the fear that the dog is displaying.
My Maggie is very patient with my three year old, and seems to respect her as we had her train the dog commands as well as everyone else in the family.