Statistical mechanical theory of solubility