Project

General

Profile

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

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

    
7
import java.text.SimpleDateFormat;
8
import java.util.Date;
9

    
10
public class DBDriver {
11

    
12
    private Logger log = Logger.getLogger(this.getClass());
13
    private StatsDAO statsDao;
14

    
15
    /**
16
     * Prepares shadow schema in the database that will be used to import data
17
     *
18
     * @throws Exception
19
     */
20

    
21
    public DBDriver(String dbUrl, String dbUser, String dbPassword, String dbDriver) {
22

    
23
        statsDao = new StatsDAO(dbUrl, dbUser, dbPassword, dbDriver);
24
    }
25

    
26

    
27
    public void prepareDB(String user) throws Exception {
28
        try {
29

    
30
            statsDao.setSearchPathDB(user);
31
            statsDao.createSchema();
32

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

    
39

    
40

    
41

    
42
    public void finalizedDB() throws Exception {
43

    
44
        try {
45
            statsDao.buildIndexes();
46
            statsDao.buildViews();
47
            statsDao.executeExtraInserts();
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

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

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