summaryrefslogtreecommitdiffstats
path: root/authz-batch/src/main/java/com/att/authz/actions/ActionDAO.java
blob: 4e951f81a7eb8325f073da2888b23bc374cf7c15 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*******************************************************************************
 * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved.
 *******************************************************************************/
package com.att.authz.actions;

import java.io.IOException;

import com.att.authz.env.AuthzTrans;
import com.att.dao.CassAccess;
import com.att.dao.aaf.hl.Function;
import com.att.dao.aaf.hl.Question;
import com.att.inno.env.APIException;
import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.Session;

public abstract class ActionDAO<T,RV> implements Action<T,RV> {
	protected final Question q; 
	protected final Function f;
	private boolean clean;

	public ActionDAO(AuthzTrans trans, Cluster cluster) throws APIException, IOException {
		q = new Question(trans, cluster, CassAccess.KEYSPACE, false);
		f = new Function(trans,q);
		clean = true;
	}
	
	public ActionDAO(AuthzTrans trans, ActionDAO<?,?> predecessor) {
		q = predecessor.q;
		f = new Function(trans,q);
		clean = false;
	}
	
	public Session getSession(AuthzTrans trans) throws APIException, IOException {
		return q.historyDAO.getSession(trans);
	}

	public void close(AuthzTrans trans) {
		if(clean) {
			q.close(trans);
		}
	}

}