1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.synchronoss.cpo.jdbc;
22
23 import org.synchronoss.cpo.*;
24
25 import javax.sql.DataSource;
26 import java.util.*;
27
28
29
30
31
32 public abstract class AbstractDataSourceInfo implements DataSourceInfo {
33 private DataSource dataSource = null;
34 private String dataSourceName = null;
35
36 private final Object LOCK = new Object();
37
38
39 private final String PASSWORD = "password";
40 private final String PASSWD = "passwd";
41 private final String PWD = "pwd";
42
43 public AbstractDataSourceInfo(String dataSourceName) {
44 this.dataSourceName=dataSourceName;
45 }
46
47 public AbstractDataSourceInfo(String className, SortedMap<String, String> properties) {
48 this.dataSourceName=BuildDataSourceName(className, properties);
49 }
50
51 public AbstractDataSourceInfo(String className, Properties properties) {
52 this.dataSourceName=BuildDataSourceName(className, properties);
53 }
54
55 protected abstract DataSource createDataSource() throws CpoException ;
56
57 @Override
58 public String getDataSourceName() {
59 return dataSourceName;
60 }
61
62 @Override
63 public DataSource getDataSource() throws CpoException {
64 if (dataSource == null) {
65 synchronized (LOCK) {
66 try {
67 dataSource = createDataSource();
68 } catch (Exception e) {
69 throw new CpoException("Error instantiating DataSource", e);
70 }
71 }
72 }
73
74 return dataSource;
75 }
76
77 private String BuildDataSourceName(String s, Properties properties) {
78
79
80
81 SortedMap<String, String> map = new TreeMap<String, String>();
82 for (Object key : properties.keySet()){
83 map.put((String)key, properties.getProperty((String)key));
84 }
85 return BuildDataSourceName(s, map);
86 }
87
88 private String BuildDataSourceName(String s, SortedMap<String, String> map) {
89 StringBuilder dsName = new StringBuilder(s);
90
91 for (Object obj : map.keySet()) {
92 String key = (String)obj;
93
94 if (!PASSWORD.equalsIgnoreCase(key) && !PASSWD.equalsIgnoreCase(key) && !PWD.equalsIgnoreCase(key) ) {
95 dsName.append(key);
96 dsName.append("=");
97 dsName.append(map.get(key));
98 }
99 }
100
101 return dsName.toString();
102 }
103
104 }