Project

General

Profile

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(
24
				dbUrl, 
25
				dbUser, 
26
				dbPassword, 
27
				dbName, 
28
				dbDriver);
29
		statsDao = new SqlDAO();
30
		statsDao.setStore(statsStore);
31

    
32
	}
33

    
34
	public DBDriver() {
35
	}
36

    
37
	public void prepareDB(String user) throws Exception {
38
		try {
39

    
40
			statsDao.setSearchPathDB(user);
41
			statsDao.createSchema();
42

    
43
		} catch (Exception e) {
44
			log.error("Error Preparing Schema for DB import. ", e);
45
			throw new Exception("Error Preparing Schema for DB import.", e);
46
		}
47
	}
48

    
49
	public void finalizedDB() throws Exception {
50

    
51
		try {
52
			statsDao.insertContexts();
53
			statsDao.buildViews();
54
			statsDao.executeExtraInserts();
55
			statsDao.buildIndexes();
56

    
57
		} catch (Exception e) {
58
			log.error("Error while finalizing SQL DB", e);
59
			throw new Exception("Error while finalizing SQL DB", e);
60
		}
61
	}
62

    
63
	public void renameSchema() throws Exception {
64

    
65
		try {
66
			statsDao.renameSchema();
67

    
68
		} catch (Exception e) {
69
			log.error("Error while renaming database schema", e);
70
			throw new Exception("Error while renaming database schema", e);
71
		}
72
	}
73

    
74
	public Logger getLog() {
75
		return log;
76
	}
77

    
78
	public void setLog(Logger log) {
79
		this.log = log;
80
	}
81

    
82
	public SqlDAO getStatsDao() {
83
		return statsDao;
84
	}
85

    
86
	public void setStatsDao(SqlDAO statsDao) {
87
		this.statsDao = statsDao;
88
	}
89

    
90
}
(1-1/3)