Project

General

Profile

1
package eu.dnetlib.data.mapreduce.hbase.statsExport.drivers;
2

    
3
import eu.dnetlib.data.mapreduce.hbase.statsExport.daos.*;
4
import org.apache.log4j.Logger;
5

    
6
public class DBDriver {
7
    
8

    
9
    private Logger log = Logger.getLogger(this.getClass());
10
    private StatsDAO statsDao;
11

    
12
    /**
13
     * Prepares shadow schema in the database that will be used to import data
14
     *
15
     * @throws Exception
16
     */
17

    
18
    public DBDriver(String dbUrl, String dbUser, String dbPassword, String dbDriver) {
19

    
20
        statsDao = new StatsDAO(dbUrl, dbUser, dbPassword, dbDriver);
21
    }
22

    
23

    
24
    public void prepareDB(String user) throws Exception {
25
        try {
26

    
27
            statsDao.setSearchPathDB(user);
28
            statsDao.createSchema();
29

    
30
        } catch (Exception e) {
31
            log.error("Error Preparing Schema for DB import. ", e);
32
            throw new Exception("Error Preparing Schema for DB import.", e);
33
        }
34
    }
35

    
36

    
37

    
38

    
39
    public void finalizedDB() throws Exception {
40

    
41
        try {
42
            statsDao.cleanTables();
43
            statsDao.addArrayColumns();
44
            statsDao.buildIndexes();
45
            statsDao.buildViews();
46
            statsDao.executeExtraInserts();
47
            statsDao.createCharts();
48
            statsDao.insertCountries();
49
            statsDao.backwardsCompatibility();
50
            statsDao.createChartIndexes();
51

    
52
        } catch (Exception e) {
53
            log.error("Error while finalizing SQL DB", e);
54
            throw new Exception("Error while finalizing SQL DB", e);
55
        }
56
    }
57

    
58
    public void renameSchema() throws Exception {
59
        try {
60
            statsDao.renameSchema();
61

    
62
        } catch (Exception e) {
63
            log.error("Error while renaming database schema", e);
64
            throw new Exception("Error while renaming database schema", e);
65
        }
66
    }
67

    
68

    
69
    public StatsDAO getStatsDao() {
70
        return statsDao;
71
    }
72

    
73
    public void setStatsDao(StatsDAO statsDao) {
74
        this.statsDao = statsDao;
75
    }
76
}
(1-1/2)