Our Code is using MySQL DB.
Now our requirement is to Migrate DB from Mysql to DB2.
and also make java code compatible for both db2 and mysql.
we are using SPring MVC and mybatis, JPA for DB work.
Kindly suggest me what would be the better design pattern to give.
How can make my code of mybatis compatible with both mysql and db2 ?
Thank,
I would suggest that you have a separate data layer.
Have this data layer declare a public interface and data types that your business logic uses.
You can then have the actual data layer instance created using a factory pattern, which creates a concrete class for connection to MySQL or DB2. By doing it this way you can change database without having to change business code (as it all refers to the interface type). You can even set it to perform this action at runtime, say based on a config setting.
e.g.
IDataLayer is your base class with methods for getting/setting data (the nitty gritty database handling is hidden within).
Then have MySQLDataLayer and DB2DataLayer child classes.
Business logic only refers to IDataLayer and never MySQLDataLayer/DB2DataLayer classes.