Second type mapper is updated to use java.util.vector

Second type mapper is updated to use java.util.vector
This commit is contained in:
Amit Dixit 2016-04-04 16:35:22 +05:30
parent 59b6b817f4
commit 822ab8d9fd
2 changed files with 29 additions and 6 deletions

View File

@ -37,7 +37,8 @@ public final class App {
private static Logger log = Logger.getLogger(App.class);
private static final String DB_TYPE_FIRST = "first";
private static final String DB_TYPE_SECOND = "second";
/**
* Program entry point.
@ -46,10 +47,32 @@ public final class App {
*/
public static void main(final String... args) {
if (log.isInfoEnabled() & args.length > 0) {
log.debug("App.main(), type: " + args[0]);
}
/* Create any type of mapper at implementation which is desired */
/* final StudentDataMapper mapper = new StudentFirstDataMapper(); */
final StudentDataMapper mapper = new StudentSecondDataMapper();
StudentDataMapper mapper = null;
/* Check the desired db type from runtime arguments */
if (args.length == 0) {
/* Create default data mapper for mysql */
mapper = new StudentFirstDataMapper();
} else if (args.length > 0 && DB_TYPE_FIRST.equalsIgnoreCase(args[0])) {
/* Create new data mapper for type 'first' */
mapper = new StudentFirstDataMapper();
} else if (args.length > 0 && DB_TYPE_SECOND.equalsIgnoreCase(args[0])) {
/* Create new data mapper for type 'second' */
mapper = new StudentSecondDataMapper();
} else {
/* Don't couple any Data Mapper to java.sql.SQLException */
throw new DataMapperException("Following data mapping type(" + args[0] + ") is not supported");
}
/* Create new student */
Student student = new Student(1, "Adam", 'A');

View File

@ -18,14 +18,14 @@
*/
package com.iluwatar.datamapper;
import java.util.ArrayList;
import java.util.Vector;
import java.util.List;
import java.util.Optional;
public final class StudentSecondDataMapper implements StudentDataMapper {
/* Note: Normally this would be in the form of an actual database */
private List<Student> students = new ArrayList<>();
private List<Student> students = new Vector<>();
@Override
public Optional<Student> find(int studentId) {