- execute?command 클래스리 팩키지 팩토링
[Tadpole.git] / com.hangum.tadpole.commons.sql / src / com / hangum / tadpole / engine / utils / MakeJDBCConnectionStringUtil.java
blobe6ae03ceeafad506018b708d27f70e96ca8ceb10
1 /*******************************************************************************
2 * All rights reserved. This program and the accompanying materials
3 * are made available under the terms of the GNU Lesser Public License v2.1
4 * which accompanies this distribution, and is available at
5 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
6 *
7 * Contributors:
8 * hangum - initial API and implementation
9 ******************************************************************************/
10 package com.hangum.tadpole.engine.utils;
12 import org.apache.commons.lang.StringUtils;
14 import com.hangum.tadpole.commons.libs.core.define.PublicTadpoleDefine;
15 import com.hangum.tadpole.engine.define.DBDefine;
16 import com.hangum.tadpole.engine.query.dao.system.UserDBDAO;
18 /**
19 * make jdbc connection string tuils
21 * @author hangum
24 public class MakeJDBCConnectionStringUtil {
26 /**
27 * make connection url
29 * @param userDB
30 * @return
32 public static String makeConnectionUrl(final UserDBDAO userDB) {
33 String dbUrl = "";
35 if(userDB.getDBDefine() == DBDefine.MYSQL_DEFAULT) {
36 String selectLocale = StringUtils.trimToEmpty(userDB.getLocale());
37 if(selectLocale.equals("") || DBLocaleUtils.NONE_TXT.equals(selectLocale)) {
38 dbUrl = getPueURL(userDB.getDBDefine().getDB_URL_INFO(), userDB);
39 if(!"".equals(userDB.getUrl_user_parameter())) {
40 dbUrl += "?" + userDB.getUrl_user_parameter();
43 } else {
44 dbUrl = getPueURL(userDB.getDBDefine().getDB_URL_INFO(), userDB) + "?useUnicode=false&characterEncoding=" + selectLocale;
45 if(!"".equals(userDB.getUrl_user_parameter())) {
46 dbUrl += "&" + userDB.getUrl_user_parameter();
49 } else if(userDB.getDBDefine() == DBDefine.ORACLE_DEFAULT) {
50 if(userDB.getExt1().equals("SID")) {
51 // return "jdbc:oracle:thin:@%s:%s:%s";
52 dbUrl = getPueURL(userDB.getDBDefine().getDB_URL_INFO(), userDB);
53 } else if(userDB.getExt1().equals("Service Name")) {
54 dbUrl = getPueURL("jdbc:oracle:thin:@//%s:%s/%s", userDB);
57 if(!"".equals(userDB.getUrl_user_parameter())) {
58 dbUrl += "?" + userDB.getUrl_user_parameter();
60 } else if(userDB.getDBDefine() == DBDefine.MONGODB_DEFAULT) {
61 dbUrl = getPueURL(userDB.getDBDefine().getDB_URL_INFO(), userDB);
62 if(!"".equals(userDB.getUrl_user_parameter())) {
63 dbUrl += "/?" + userDB.getUrl_user_parameter();
65 } else if(userDB.getDBDefine() == DBDefine.ALTIBASE_DEFAULT) {
66 String selectLocale = StringUtils.trimToEmpty(userDB.getLocale());
68 if(selectLocale.equals("") || DBLocaleUtils.NONE_TXT.equals(selectLocale)) {
69 dbUrl = getPueURL(userDB.getDBDefine().getDB_URL_INFO(), userDB);
71 if(!"".equals(userDB.getUrl_user_parameter())) {
72 dbUrl += "?" + userDB.getUrl_user_parameter();
74 } else {
75 dbUrl = getPueURL(userDB.getDBDefine().getDB_URL_INFO(), userDB) + "?charset=" + selectLocale;
77 if(!"".equals(userDB.getUrl_user_parameter())) {
78 dbUrl += "&" + userDB.getUrl_user_parameter();
81 } else if(userDB.getDBDefine() == DBDefine.POSTGRE_DEFAULT) {
82 dbUrl = getPueURL(userDB.getDBDefine().getDB_URL_INFO(), userDB);
83 if(PublicTadpoleDefine.YES_NO.YES.name().equals(userDB.getExt1())) {
84 dbUrl += "?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory"; //$NON-NLS-1$
86 if(!"".equals(userDB.getUrl_user_parameter())) { //$NON-NLS-1$
87 dbUrl += "&" + userDB.getUrl_user_parameter(); //$NON-NLS-1$
89 } else {
90 if(!"".equals(userDB.getUrl_user_parameter())) { //$NON-NLS-1$
91 dbUrl += "?" + userDB.getUrl_user_parameter(); //$NON-NLS-1$
97 return dbUrl;
100 private static String getPueURL(String strTempURL, final UserDBDAO userDB) {
101 return String.format(
102 strTempURL,
103 StringUtils.trimToEmpty(userDB.getHost()),
104 StringUtils.trimToEmpty(userDB.getPort()),
105 StringUtils.trimToEmpty(userDB.getDb())