I have read the article written by James Carman, Write once, persist anywhere, and I have found an useful framework when implementing our own DML, that is using lexer parser provided by SableCC Framework.
By using SableCC, you can just provide a grammar definition, and using SableCC generator tool to generate some classes, then you implement the classes based on your needs. To learn more, visit here for its thesis.