Created
October 17, 2015 23:31
-
-
Save mangar/8504bfb6c4fe5633dfcf to your computer and use it in GitHub Desktop.
AbstractDAO
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.List; | |
| import java.util.Map; | |
| public interface DAO { | |
| public Boolean save(Map<?, ?> param); | |
| public List<?> getAll(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class DAOFactory { | |
| static DAOFactory instance; | |
| static final String DB_TYPE_ORACLE = "oracle"; | |
| static final String DB_TYPE_MYSQL = "mysql"; | |
| static final String DB_TYPE = DB_TYPE_MYSQL; | |
| private DAOFactory() { | |
| super(); | |
| } | |
| public static DAOFactory newInstance() { | |
| if (DAOFactory.instance == null) { | |
| DAOFactory.instance = new DAOFactory(); | |
| } | |
| return DAOFactory.instance; | |
| } | |
| public DAO getDao() { | |
| if (DAOFactory.DB_TYPE.equalsIgnoreCase(DB_TYPE_MYSQL)) { | |
| return new DAOMySQL(); | |
| } else { | |
| return new DAOOracle(); | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.List; | |
| import java.util.Map; | |
| public class DAOMySQL implements DAO { | |
| @Override | |
| public Boolean save(Map<?, ?> param) { | |
| return null; | |
| } | |
| @Override | |
| public List<?> getAll() { | |
| return null; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.List; | |
| import java.util.Map; | |
| public class DAOOracle implements DAO { | |
| @Override | |
| public Boolean save(Map<?, ?> param) { | |
| return null; | |
| } | |
| @Override | |
| public List<?> getAll() { | |
| return null; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.HashMap; | |
| import java.util.List; | |
| import java.util.Map; | |
| public abstract class DAOUsage { | |
| public static void main(String args[]) { | |
| List<?> allRecords = DAOFactory.newInstance().getDao().getAll(); | |
| Map<String,String> record = new HashMap<String, String>(); | |
| record.put("id", "1"); | |
| record.put("name", "User Name"); | |
| record.put("email", "Email"); | |
| DAOFactory.newInstance().getDao().save(record); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment