Upgrade to latest oparent
[aaf/authz.git] / authz-batch / src / main / java / com / att / authz / actions / ActionDAO.java
1 /*******************************************************************************
2  * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved.
3  *******************************************************************************/
4 package com.att.authz.actions;
5
6 import java.io.IOException;
7
8 import com.att.authz.env.AuthzTrans;
9 import com.att.dao.CassAccess;
10 import com.att.dao.aaf.hl.Function;
11 import com.att.dao.aaf.hl.Question;
12 import org.onap.aaf.inno.env.APIException;
13 import com.datastax.driver.core.Cluster;
14 import com.datastax.driver.core.Session;
15
16 public abstract class ActionDAO<T,RV> implements Action<T,RV> {
17         protected final Question q; 
18         protected final Function f;
19         private boolean clean;
20
21         public ActionDAO(AuthzTrans trans, Cluster cluster) throws APIException, IOException {
22                 q = new Question(trans, cluster, CassAccess.KEYSPACE, false);
23                 f = new Function(trans,q);
24                 clean = true;
25         }
26         
27         public ActionDAO(AuthzTrans trans, ActionDAO<?,?> predecessor) {
28                 q = predecessor.q;
29                 f = new Function(trans,q);
30                 clean = false;
31         }
32         
33         public Session getSession(AuthzTrans trans) throws APIException, IOException {
34                 return q.historyDAO.getSession(trans);
35         }
36
37         public void close(AuthzTrans trans) {
38                 if(clean) {
39                         q.close(trans);
40                 }
41         }
42
43 }