1
|
package eu.dnetlib.data.mapreduce.hbase.statsExport.drivers;
|
2
|
|
3
|
import org.apache.log4j.Logger;
|
4
|
|
5
|
import eu.dnetlib.data.mapreduce.hbase.statsExport.daos.SqlDAO;
|
6
|
import eu.dnetlib.data.mapreduce.hbase.statsExport.daos.SqlStore;
|
7
|
|
8
|
public class DBDriver {
|
9
|
|
10
|
private Logger log = Logger.getLogger(this.getClass());
|
11
|
|
12
|
private SqlDAO statsDao;
|
13
|
private SqlStore statsStore;
|
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 dbName, String dbDriver) {
|
22
|
|
23
|
statsStore = new SqlStore(dbUrl, dbUser, dbPassword, dbName, dbDriver);
|
24
|
statsDao = new SqlDAO();
|
25
|
statsDao.setStore(statsStore);
|
26
|
|
27
|
}
|
28
|
|
29
|
public DBDriver() {
|
30
|
}
|
31
|
|
32
|
public void prepareDB(String user) throws Exception {
|
33
|
try {
|
34
|
|
35
|
statsDao.setSearchPathDB(user);
|
36
|
statsDao.createSchema();
|
37
|
|
38
|
} catch (Exception e) {
|
39
|
log.error("Error Preparing Schema for DB import. ", e);
|
40
|
throw new Exception("Error Preparing Schema for DB import.", e);
|
41
|
}
|
42
|
}
|
43
|
|
44
|
public void finalizedDB() throws Exception {
|
45
|
|
46
|
try {
|
47
|
statsDao.insertContexts();
|
48
|
statsDao.buildViews();
|
49
|
statsDao.executeExtraInserts();
|
50
|
statsDao.buildIndexes();
|
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
|
|
60
|
try {
|
61
|
statsDao.renameSchema();
|
62
|
|
63
|
} catch (Exception e) {
|
64
|
log.error("Error while renaming database schema", e);
|
65
|
throw new Exception("Error while renaming database schema", e);
|
66
|
}
|
67
|
}
|
68
|
|
69
|
public Logger getLog() {
|
70
|
return log;
|
71
|
}
|
72
|
|
73
|
public void setLog(Logger log) {
|
74
|
this.log = log;
|
75
|
}
|
76
|
|
77
|
public SqlDAO getStatsDao() {
|
78
|
return statsDao;
|
79
|
}
|
80
|
|
81
|
public void setStatsDao(SqlDAO statsDao) {
|
82
|
this.statsDao = statsDao;
|
83
|
}
|
84
|
|
85
|
}
|