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
    public void prepareDB(String user) throws Exception {
24
        try {
25

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

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

    
35
    public void finalizedDB() throws Exception {
36

    
37
        try {
38
            statsDao.cleanTables();
39
            statsDao.addArrayColumns();
40
            statsDao.buildIndexes();
41
            statsDao.buildViews();
42
            statsDao.executeExtraInserts();
43
            statsDao.createCharts();
44
            statsDao.insertCountries();
45
            statsDao.backwardsCompatibility();
46
            statsDao.createChartIndexes();
47
            statsDao.copyUsageStats();
48

    
49
        } catch (Exception e) {
50
            log.error("Error while finalizing SQL DB", e);
51
            throw new Exception("Error while finalizing SQL DB", e);
52
        }
53
    }
54

    
55
    public void renameSchema() throws Exception {
56
        try {
57
            statsDao.renameSchema();
58

    
59
        } catch (Exception e) {
60
            log.error("Error while renaming database schema", e);
61
            throw new Exception("Error while renaming database schema", e);
62
        }
63
    }
64

    
65
    public StatsDAO getStatsDao() {
66
        return statsDao;
67
    }
68

    
69
    public void setStatsDao(StatsDAO statsDao) {
70
        this.statsDao = statsDao;
71
    }
72
}
(1-1/2)