-
Notifications
You must be signed in to change notification settings - Fork 229
/
SalesForceManagedConnectionFactory.java
183 lines (151 loc) · 5.13 KB
/
SalesForceManagedConnectionFactory.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*
* Copyright Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags and
* the COPYRIGHT.txt file distributed with this work.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teiid.resource.adapter.salesforce;
import javax.resource.ResourceException;
import org.teiid.core.TeiidRuntimeException;
import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;
import org.teiid.resource.spi.BasicConnectionFactory;
import org.teiid.resource.spi.BasicManagedConnectionFactory;
import org.teiid.translator.salesforce.SalesForcePlugin;
import com.sforce.soap.partner.Connector;
public class SalesForceManagedConnectionFactory extends BasicManagedConnectionFactory {
private static final long serialVersionUID = 5298591275313314698L;
private String username;
private String password;
private String url; //sf url
private Long requestTimeout;
private Long connectTimeout;
private String proxyUsername;
private String proxyPassword;
private String proxyUrl;
private String configProperties;
private String configFile; // path to the "jbossws-cxf.xml" file
private boolean warned;
public String getUsername() {
return username;
}
public void setUsername(String username) {
if (username.trim().length() == 0) {
throw new TeiidRuntimeException("Name can not be null"); //$NON-NLS-1$
}
this.username = username;
}
public String getPassword() {
return this.password;
}
public void setPassword(String password) {
this.password = password;
}
public String getURL() {
return this.url;
}
public void setURL(String uRL) {
this.url = uRL;
}
public Long getConnectTimeout() {
return connectTimeout;
}
public void setConnectTimeout(Long connectTimeout) {
this.connectTimeout = connectTimeout;
}
public Long getRequestTimeout() {
return requestTimeout;
}
public void setRequestTimeout(Long requestTimeout) {
this.requestTimeout = requestTimeout;
}
@Override
public BasicConnectionFactory<SalesforceConnectionImpl> createConnectionFactory() throws ResourceException {
return new BasicConnectionFactory<SalesforceConnectionImpl>() {
private static final long serialVersionUID = 5028356110047329135L;
@Override
public SalesforceConnectionImpl getConnection() throws ResourceException {
return new SalesforceConnectionImpl(SalesForceManagedConnectionFactory.this);
}
};
}
public String getProxyUsername() {
return proxyUsername;
}
public void setProxyUsername(String proxyUsername) {
this.proxyUsername = proxyUsername;
}
public String getProxyPassword() {
return proxyPassword;
}
public void setProxyPassword(String proxyPassword) {
this.proxyPassword = proxyPassword;
}
public String getProxyURL() {
return proxyUrl;
}
public void setProxyURL(String proxyUrl) {
this.proxyUrl = proxyUrl;
}
public String getConfigProperties() {
return configProperties;
}
public void setConfigProperties(String configProperties) {
this.configProperties = configProperties;
}
public String getConfigFile() {
return this.configFile;
}
public void setConfigFile(String config) {
this.configFile = config;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((url == null) ? 0 : url.hashCode());
result = prime * result + ((password == null) ? 0 : password.hashCode());
result = prime * result + ((username == null) ? 0 : username.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
SalesForceManagedConnectionFactory other = (SalesForceManagedConnectionFactory) obj;
if (!checkEquals(this.url, other.url)) {
return false;
}
if (!checkEquals(this.password, other.password)) {
return false;
}
if (!checkEquals(this.username, other.username)) {
return false;
}
return checkEquals(this.proxyUrl, other.proxyUrl)
&& checkEquals(this.proxyUsername, other.proxyUsername)
&& checkEquals(this.proxyPassword, other.proxyPassword)
&& checkEquals(this.configProperties, other.configProperties);
}
public void checkVersion(String apiVersion) {
if (!warned) {
warned = true;
String javaApiVersion = Connector.END_POINT.substring(Connector.END_POINT.lastIndexOf('/') + 1, Connector.END_POINT.length());
if (!javaApiVersion.equals(apiVersion)) {
LogManager.logWarning(LogConstants.CTX_CONNECTOR, SalesForcePlugin.Util.gs(SalesForcePlugin.Event.TEIID13009, apiVersion, javaApiVersion));
}
}
}
}