- 1.7.6 초기 코드
[Tadpole.git] / com.hangum.tadpole.commons.sql / src / com / hangum / tadpole / engine / query / sql / TadpoleSystem_ExtensionDB.java
blob8188c844defd9ab972cf6516b9af09603e3b57b0
1 /*******************************************************************************
2 * Copyright (c) 2017 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
7 *
8 * Contributors:
9 * hangum - initial API and implementation
10 ******************************************************************************/
11 package com.hangum.tadpole.engine.query.sql;
13 import java.sql.Connection;
14 import java.sql.SQLException;
15 import java.util.List;
17 import org.apache.log4j.Logger;
19 import com.hangum.tadpole.commons.exception.TadpoleSQLManagerException;
20 import com.hangum.tadpole.engine.initialize.TadpoleEngineUserDB;
21 import com.hangum.tadpole.engine.manager.TadpoleSQLManager;
22 import com.hangum.tadpole.engine.query.dao.gateway.ExtensionDBDAO;
23 import com.hangum.tadpole.session.manager.SessionManager;
24 import com.ibatis.sqlmap.client.SqlMapClient;
25 import com.ibatis.sqlmap.client.SqlMapSession;
27 /**
28 * 외부 확장시스템
30 * @author hangum
33 public class TadpoleSystem_ExtensionDB {
34 /**
35 * Logger for this class
37 private static final Logger logger = Logger.getLogger(TadpoleSystem_ExtensionDB.class);
39 /**
40 * get extension info
42 * @param searchKey
43 * @return
44 * @throws Exception
46 public static List<ExtensionDBDAO> getExtensionInfo(String searchKey) throws Exception {
47 SqlMapClient sqlClient = TadpoleSQLManager.getInstance(TadpoleEngineUserDB.getUserDB());
48 return sqlClient.queryForList("findExtensionDB", searchKey); //$NON-NLS-1$
51 /**
52 * 접근이 허락된 디비 리스트를 가져온다.
54 * @param userID
55 * @return
56 * @throws Exception
58 public static List<ExtensionDBDAO> getUserDBs(String userId) throws Exception {
59 SqlMapClient sqlClient = TadpoleSQLManager.getInstance(TadpoleEngineUserDB.getUserDB());
60 return sqlClient.queryForList("findUserExtensionDB", userId); //$NON-NLS-1$
63 /**
64 * 접근이 허락된 디비 리스트를 가져온다.
66 * @param userID
67 * @return
68 * @throws Exception
70 public static List<ExtensionDBDAO> getUserDBTerm(String userId) throws Exception {
71 SqlMapClient sqlClient = TadpoleSQLManager.getInstance(TadpoleEngineUserDB.getUserDB());
72 return sqlClient.queryForList("findUserExtensionDBTerm", userId); //$NON-NLS-1$
75 /**
76 * delete extension
78 * @throws TadpoleSQLManagerException
79 * @throws SQLException
81 public static void deleteExtensionDB() throws TadpoleSQLManagerException, SQLException {
82 SqlMapClient sqlClient = TadpoleSQLManager.getInstance(TadpoleEngineUserDB.getUserDB());
83 sqlClient.delete("deleteExtensionDB"); //$NON-NLS-1$
86 /**
87 * insertExtension data
89 * @param listExtensionDB
90 * @throws TadpoleSQLManagerException, SQLException
92 public static void insertExtensionDB(List<ExtensionDBDAO> listExtensionDB) throws TadpoleSQLManagerException, SQLException {
93 SqlMapClient sqlClient = TadpoleSQLManager.getInstance(TadpoleEngineUserDB.getUserDB());
94 Connection connection = sqlClient.getDataSource().getConnection();
95 connection.setAutoCommit(false);
96 SqlMapSession session = sqlClient.openSession(connection);
98 if(logger.isDebugEnabled()) logger.debug(" deleted before gateway data");
99 try {
100 session.delete("deleteExtensionDB"); //$NON-NLS-1$
101 for (ExtensionDBDAO extensionDBDAO : listExtensionDB) {
102 session.insert("saveExtensionDB", extensionDBDAO); //$NON-NLS-1$
105 connection.commit();
106 } catch(Exception sqle) {
107 logger.error("extension db list", sqle);
108 connection.rollback();
109 throw new SQLException(sqle.getMessage());
110 } finally {
111 try { if(session != null) session.close(); } catch(Exception e) {}
112 try { if(connection != null) connection.close(); } catch(Exception e) {}