1 /*******************************************************************************
2 * Copyright (c) 2012 - 2015 hangum.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the GNU Lesser Public License v2.1
5 * which accompanies this distribution, and is available at
6 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
9 * hangum - initial API and implementation
10 ******************************************************************************/
11 package com
.hangum
.tadpole
.engine
.query
.sql
;
13 import java
.sql
.SQLException
;
14 import java
.util
.ArrayList
;
15 import java
.util
.HashMap
;
16 import java
.util
.List
;
19 import com
.hangum
.tadpole
.commons
.exception
.TadpoleSQLManagerException
;
20 import com
.hangum
.tadpole
.commons
.libs
.core
.define
.PublicTadpoleDefine
;
21 import com
.hangum
.tadpole
.engine
.initialize
.TadpoleEngineUserDB
;
22 import com
.hangum
.tadpole
.engine
.manager
.TadpoleSQLManager
;
23 import com
.hangum
.tadpole
.engine
.query
.dao
.system
.TadpoleUserDbRoleDAO
;
24 import com
.hangum
.tadpole
.engine
.query
.dao
.system
.accesscontrol
.AccessCtlObjectDAO
;
25 import com
.hangum
.tadpole
.engine
.query
.dao
.system
.accesscontrol
.DBAccessControlDAO
;
26 import com
.ibatis
.sqlmap
.client
.SqlMapClient
;
36 public class TadpoleSystem_AccessControl
{
39 * To save default access control data.
42 public static DBAccessControlDAO
saveDBAccessControl(TadpoleUserDbRoleDAO roleDao
) throws TadpoleSQLManagerException
, SQLException
{
43 DBAccessControlDAO dao
= new DBAccessControlDAO();
44 dao
.setDb_role_seq(roleDao
.getSeq());
46 SqlMapClient sqlClient
= TadpoleSQLManager
.getInstance(TadpoleEngineUserDB
.getUserDB());
47 dao
= (DBAccessControlDAO
)sqlClient
.insert("saveAccessControl", dao
);
53 * Get user db access contorl data.
56 * @throws TadpoleSQLManagerException, SQLException
58 public static DBAccessControlDAO
getDBAccessControl(TadpoleUserDbRoleDAO roleDao
) throws TadpoleSQLManagerException
, SQLException
{
59 SqlMapClient sqlClient
= TadpoleSQLManager
.getInstance(TadpoleEngineUserDB
.getUserDB());
60 DBAccessControlDAO _accessCtlDao
= (DBAccessControlDAO
)sqlClient
.queryForObject("getAccessControl", roleDao
);
62 if(_accessCtlDao
.getIntDetailCnt() == 0) {
63 _accessCtlDao
.setAllAccessCtl(new ArrayList
<AccessCtlObjectDAO
>());
66 List
<AccessCtlObjectDAO
> listAccessDetail
= sqlClient
.queryForList("getAccessCtlDetail", _accessCtlDao
.getSeq());
67 _accessCtlDao
.setAllAccessCtl(listAccessDetail
);
69 Map
<String
, AccessCtlObjectDAO
> mapSelectTableAccessCtl
= new HashMap
<String
, AccessCtlObjectDAO
>();
70 Map
<String
, AccessCtlObjectDAO
> mapSelectFunctionAccessCtl
= new HashMap
<String
, AccessCtlObjectDAO
>();
71 Map
<String
, AccessCtlObjectDAO
> mapSelectProcedureAccessCtl
= new HashMap
<String
, AccessCtlObjectDAO
>();
72 for (AccessCtlObjectDAO accCtlObj
: listAccessDetail
) {
73 if(PublicTadpoleDefine
.ACCEAS_CTL_DDL_TYPE
.TABLEoVIEW
.name().equals(accCtlObj
.getType())) {
74 mapSelectTableAccessCtl
.put(String
.format("%s.%s", accCtlObj
.getObj_schema(), accCtlObj
.getObj_name()), accCtlObj
);
75 } else if(PublicTadpoleDefine
.ACCEAS_CTL_DDL_TYPE
.FUNCTION
.name().equals(accCtlObj
.getType())) {
76 mapSelectFunctionAccessCtl
.put(String
.format("%s.%s", accCtlObj
.getObj_schema(), accCtlObj
.getObj_name()), accCtlObj
);
77 } else if(PublicTadpoleDefine
.ACCEAS_CTL_DDL_TYPE
.PROCEDURE
.name().equals(accCtlObj
.getType())) {
78 mapSelectProcedureAccessCtl
.put(String
.format("%s.%s", accCtlObj
.getObj_schema(), accCtlObj
.getObj_name()), accCtlObj
);
81 _accessCtlDao
.setMapSelectTableAccessCtl(mapSelectTableAccessCtl
);
82 _accessCtlDao
.setMapSelectFunctionAccessCtl(mapSelectFunctionAccessCtl
);
83 _accessCtlDao
.setMapSelectProcedureAccessCtl(mapSelectProcedureAccessCtl
);
90 * Get user db access contorl data.
93 * @throws TadpoleSQLManagerException, SQLException
95 public static DBAccessControlDAO
getDBAccessControl(int intRoleSeq
) throws TadpoleSQLManagerException
, SQLException
{
96 TadpoleUserDbRoleDAO roleDao
= new TadpoleUserDbRoleDAO();
97 roleDao
.setSeq(intRoleSeq
);
99 return getDBAccessControl(roleDao
);
103 * update db access control
106 * @throws TadpoleSQLManagerException, SQLException
108 public static void updateDBAccessControl(DBAccessControlDAO dao
) throws TadpoleSQLManagerException
, SQLException
{
109 SqlMapClient sqlClient
= TadpoleSQLManager
.getInstance(TadpoleEngineUserDB
.getUserDB());
110 sqlClient
.update("updateAccessControl", dao
);
112 // already data remove and add data
113 sqlClient
.update("removeAccessControlDetail", dao
);
115 for(AccessCtlObjectDAO objecDao
: dao
.getAllAccessCtl()) {
116 sqlClient
.insert("insertAccessControlDetail", objecDao
);