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.createChartIndexes();
|
49
|
|
50
|
} catch (Exception e) {
|
51
|
log.error("Error while finalizing SQL DB", e);
|
52
|
throw new Exception("Error while finalizing SQL DB", e);
|
53
|
}
|
54
|
}
|
55
|
|
56
|
public void renameSchema() throws Exception {
|
57
|
try {
|
58
|
statsDao.renameSchema();
|
59
|
|
60
|
} catch (Exception e) {
|
61
|
log.error("Error while renaming database schema", e);
|
62
|
throw new Exception("Error while renaming database schema", e);
|
63
|
}
|
64
|
}
|
65
|
|
66
|
|
67
|
public StatsDAO getStatsDao() {
|
68
|
return statsDao;
|
69
|
}
|
70
|
|
71
|
public void setStatsDao(StatsDAO statsDao) {
|
72
|
this.statsDao = statsDao;
|
73
|
}
|
74
|
}
|