@@ -37,7 +37,8 @@ public final class App {
3737
3838 private static Logger log = Logger .getLogger (App .class );
3939
40-
40+ private static final String DB_TYPE_FIRST = "first" ;
41+ private static final String DB_TYPE_SECOND = "second" ;
4142
4243 /**
4344 * Program entry point.
@@ -46,10 +47,32 @@ public final class App {
4647 */
4748 public static void main (final String ... args ) {
4849
50+ if (log .isInfoEnabled () & args .length > 0 ) {
51+ log .debug ("App.main(), type: " + args [0 ]);
52+ }
53+
54+ StudentDataMapper mapper = null ;
55+
56+ /* Check the desired db type from runtime arguments */
57+ if (args .length == 0 ) {
58+
59+ /* Create default data mapper for mysql */
60+ mapper = new StudentFirstDataMapper ();
4961
50- /* Create any type of mapper at implementation which is desired */
51- /* final StudentDataMapper mapper = new StudentFirstDataMapper(); */
52- final StudentDataMapper mapper = new StudentSecondDataMapper ();
62+ } else if (args .length > 0 && DB_TYPE_FIRST .equalsIgnoreCase (args [0 ])) {
63+
64+ /* Create new data mapper for type 'first' */
65+ mapper = new StudentFirstDataMapper ();
66+
67+ } else if (args .length > 0 && DB_TYPE_SECOND .equalsIgnoreCase (args [0 ])) {
68+
69+ /* Create new data mapper for type 'second' */
70+ mapper = new StudentSecondDataMapper ();
71+ } else {
72+
73+ /* Don't couple any Data Mapper to java.sql.SQLException */
74+ throw new DataMapperException ("Following data mapping type(" + args [0 ] + ") is not supported" );
75+ }
5376
5477 /* Create new student */
5578 Student student = new Student (1 , "Adam" , 'A' );
0 commit comments