Skip to content

Commit 822ab8d

Browse files
committed
Second type mapper is updated to use java.util.vector
Second type mapper is updated to use java.util.vector
1 parent 59b6b81 commit 822ab8d

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

data-mapper/src/main/java/com/iluwatar/datamapper/App.java

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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');

data-mapper/src/main/java/com/iluwatar/datamapper/StudentSecondDataMapper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
*/
1919
package com.iluwatar.datamapper;
2020

21-
import java.util.ArrayList;
21+
import java.util.Vector;
2222
import java.util.List;
2323
import java.util.Optional;
2424

2525
public final class StudentSecondDataMapper implements StudentDataMapper {
2626

2727
/* Note: Normally this would be in the form of an actual database */
28-
private List<Student> students = new ArrayList<>();
28+
private List<Student> students = new Vector<>();
2929

3030
@Override
3131
public Optional<Student> find(int studentId) {

0 commit comments

Comments
 (0)