Finite-codimensional invariant subspaces of Bergman spaces