@ -25,18 +25,21 @@ public class Main {
|
|||||||
*/
|
*/
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
_orm = new ORM();
|
_orm = new ORM();
|
||||||
|
System.out.println("Begin Extract process..");
|
||||||
extract();
|
extract();
|
||||||
load();
|
load();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void extract()
|
private static void extract()
|
||||||
{
|
{
|
||||||
|
System.out.println("Load product dimension data from database..");
|
||||||
_articles = _orm.getArticles();
|
_articles = _orm.getArticles();
|
||||||
Map<String, Integer> articleNames = new HashMap<>();
|
Map<String, Integer> articleNames = new HashMap<>();
|
||||||
for (Article article : _articles) {
|
for (Article article : _articles) {
|
||||||
articleNames.put(article.get_name(), article.get_articleID());
|
articleNames.put(article.get_name(), article.get_articleID());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
System.out.println("Load location dimension data from database..");
|
||||||
_shops = _orm.getShops();
|
_shops = _orm.getShops();
|
||||||
Map<String, Integer> shopNames = new HashMap<>();
|
Map<String, Integer> shopNames = new HashMap<>();
|
||||||
for (Shop shop : _shops) {
|
for (Shop shop : _shops) {
|
||||||
@ -44,8 +47,14 @@ public class Main {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
System.out.println("Scan the CSV file..");
|
||||||
List<List<String>> csvEntries = CSVScanner.scan("sales.csv");
|
List<List<String>> csvEntries = CSVScanner.scan("sales.csv");
|
||||||
|
System.out.println("Finish Extract process");
|
||||||
List<Sale> sales = new ArrayList<>();
|
List<Sale> sales = new ArrayList<>();
|
||||||
|
System.out.println("Begin Transform process..");
|
||||||
|
System.out.println("Transform each CSV row into one Sale object..");
|
||||||
|
System.out.println("..and create one Date object for each date (multiple Sale objects share one such " +
|
||||||
|
"object)..");
|
||||||
for (List<String> row : csvEntries) {
|
for (List<String> row : csvEntries) {
|
||||||
Sale sale = new Sale();
|
Sale sale = new Sale();
|
||||||
String date = row.get(0);
|
String date = row.get(0);
|
||||||
@ -62,21 +71,29 @@ public class Main {
|
|||||||
sales.add(sale);
|
sales.add(sale);
|
||||||
}
|
}
|
||||||
_sales = sales;
|
_sales = sales;
|
||||||
|
System.out.println("Finish Transform process.");
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
System.out.println("Retrieve all Date objects which were created during Transform");
|
||||||
_dates = Date.getDates();
|
_dates = Date.getDates();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void load()
|
private static void load()
|
||||||
{
|
{
|
||||||
|
System.out.println("Begin Load process..");
|
||||||
_orm.setAutoCommit(false);
|
_orm.setAutoCommit(false);
|
||||||
|
System.out.println("Write product dimension data to database..");
|
||||||
_orm.createArticles(_articles);
|
_orm.createArticles(_articles);
|
||||||
|
System.out.println("Write date dimension data to database..");
|
||||||
_orm.createDates(_dates);
|
_orm.createDates(_dates);
|
||||||
|
System.out.println("Write location dimension data to database..");
|
||||||
_orm.createShops(_shops);
|
_orm.createShops(_shops);
|
||||||
|
System.out.println("Write sales (fact) data to database..");
|
||||||
_orm.createSales(_sales);
|
_orm.createSales(_sales);
|
||||||
_orm.commit();
|
_orm.commit();
|
||||||
_orm.setAutoCommit(true);
|
_orm.setAutoCommit(true);
|
||||||
|
System.out.println("Finish Load process");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user