-
Notifications
You must be signed in to change notification settings - Fork 35
/
DataSourceDefinition.java
313 lines (292 loc) · 9.7 KB
/
DataSourceDefinition.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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
/*
* Copyright (c) 2009, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package jakarta.annotation.sql;
import java.lang.annotation.*;
import java.lang.annotation.Target;
import java.lang.annotation.Retention;
import java.lang.annotation.ElementType;
import java.lang.annotation.RetentionPolicy;
/**
* Annotation used to define a container <code>DataSource</code> to
* be registered with JNDI. The <code>DataSource</code> may be configured by
* setting the annotation elements for commonly used <code>DataSource</code>
* properties. Additional standard and vendor-specific properties may be
* specified using the <code>properties</code> element.
* <p>
*
* The data source will be registered under the name specified in the
* <code>name</code> element. It may be defined to be in any valid
* Jakarta EE namespace, which will determine the accessibility of
* the data source from other components.
* <p>
* A JDBC driver implementation class of the appropriate type, either
* <code>DataSource</code>, <code>ConnectionPoolDataSource</code>, or
* <code>XADataSource</code>, must be indicated by the <code>className</code>
* element. The availability of the driver class will be assumed at runtime.
*<p>
* DataSource properties should not be specified more than once. If
* the url annotation element contains a DataSource property that was also
* specified using the corresponding annotation element or was specified in
* the properties annotation element, the precedence order is undefined
* and implementation specific:
* <p>
* <pre>
* @DataSourceDefinition(name="java:global/MyApp/MyDataSource",
* className="org.apache.derby.jdbc.ClientDataSource",
* url="jdbc:derby://localhost:1527/myDB;user=bill",
* user="lance",
* password="secret",
* databaseName="testDB",
* serverName="luckydog"
* )// DO NOT DO THIS!!!
* </pre>
* <p>
* In the above example, the <code>databaseName</code>, <code>user</code>
* and <code>serverName</code> properties were specified as part of the
* <code>url</code> property and using the corresponding
* annotation elements. This should be avoided.
* <p>
* If the <code>properties</code> annotation element is used and contains a
* DataSource property that was also specified using the corresponding
* annotation element, the annotation element value takes precedence.
* For example:
* <p>
* <pre>
* @DataSourceDefinition(name="java:global/MyApp/MyDataSource",
* className="org.apache.derby.jdbc.ClientDataSource",
* user="lance",
* password="secret",
* databaseName="testDB",
* serverName="luckydog",
* properties= {"databaseName=myDB", "databaseProp=doThis"}
* )// DO NOT DO THIS!!!
* </pre>
* <p>
* This would result in the following values being used when configuring
* the DataSource:
* <ul>
* <li>serverName=luckydog</li>
* <li>portNumber=1527</li>
* <li>databaseName=testDB</li>
* <li>user=lance</li>
* <li>password=secret</li>
* <li>databaseProp=doThis</li>
* </ul>
* <p>
* Vendors are not required to support properties that do not normally
* apply to a specific data source type. For example, specifying the
* <code>transactional</code> property to be <code>true</code> but supplying
* a value for <code>className</code> that implements a data source class
* other than <code>XADataSource</code> may not be supported.
* <p>
* Vendor-specific properties may be combined with or used to
* override standard data source properties defined using this annotation.
* <p>
* <code>DataSource</code> properties that are specified and are not supported
* in a given configuration or cannot be mapped to a vendor specific
* configuration property may be ignored.
* <p>
* Examples:
* <br>
* <pre>
* @DataSourceDefinition(name="java:global/MyApp/MyDataSource",
* className="com.foobar.MyDataSource",
* portNumber=6689,
* serverName="myserver.com",
* user="lance",
* password="secret"
* )
*
* </pre>
* <p>
* Using a <code>URL</code>:
* <br>
* <pre>
* @DataSourceDefinition(name="java:global/MyApp/MyDataSource",
* className="org.apache.derby.jdbc.ClientDataSource",
* url="jdbc:derby://localhost:1527/myDB",
* user="lance",
* password="secret"
* )
* </pre>
* <p>
* An example lookup of the DataSource from an Jakarta Enterprise Beans:
* <pre>
* @Stateless
* public class MyStatelessEJB {
* @Resource(lookup="java:global/MyApp/myDataSource")
* DataSource myDB;
* ...
* }
* </pre>
* <p>
* @see javax.sql.DataSource
* @see javax.sql.XADataSource
* @see javax.sql.ConnectionPoolDataSource
* @since Common Annotations 1.1
*/
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Repeatable(DataSourceDefinitions.class)
public @interface DataSourceDefinition {
/**
* JNDI name by which the data source will be registered.
* @since 1.1
*/
String name();
/**
* Name of a DataSource class that implements
* <code>javax.sql.DataSource</code> or <code>javax.sql.XADataSource</code>
* or <code>javax.sql.ConnectionPoolDataSource</code>.
* @since 1.1
*/
String className();
/**
* Description of this data source
* @since 1.1
*/
String description() default "";
/**
* A JDBC URL. If the <code>url</code> annotation element contains a
* DataSource property that was also specified using the corresponding
* annotation element, the precedence order is undefined and
* implementation specific.
* @since 1.1
*/
String url() default "";
/**
* User name to use for connection authentication.
* @since 1.1
*/
String user() default "";
/**
* Password to use for connection authentication.
* @since 1.1
*/
String password() default "";
/**
* Name of a database on a server.
* @since 1.1
*/
String databaseName() default "";
/**
* Port number where a server is listening for requests.
* @since 1.1
*/
int portNumber() default -1;
/**
* Database server name.
* @since 1.1
*/
String serverName() default "localhost";
/**
* Isolation level for connections. The Isolation level
* must be one of the following:
* <p>
* <ul>
* <li>Connection.TRANSACTION_NONE,
* <li>Connection.TRANSACTION_READ_ UNCOMMITTED,
* <li>Connection.TRANSACTION_READ_COMMITTED,
* <li>Connection.TRANSACTION_REPEATABLE_READ,
* <li>Connection.TRANSACTION_SERIALIZABLE
*</ul>
* <p>
* Default is vendor-specific.
* @since 1.1
*/
int isolationLevel() default -1;
/**
* Set to <code>false</code> if connections should not participate
* in transactions.
* <p>
* Default is to enlist in a transaction when one is active or becomes
* active.
* @since 1.1
*/
boolean transactional() default true;
/**
* Number of connections that should be created when a connection pool
* is initialized.
* <p>
* Default is vendor-specific
* @since 1.1
*/
int initialPoolSize() default -1;
/**
* Maximum number of connections that should be concurrently allocated for a
* connection pool.
* <p>
* Default is vendor-specific.
* @since 1.1
*/
int maxPoolSize() default -1;
/**
* Minimum number of connections that should be allocated for a
* connection pool.
* <p>
* Default is vendor-specific.
* @since 1.1
*/
int minPoolSize() default -1;
/**
* The number of seconds that a physical connection
* should remain unused in the pool before the
* connection is closed for a connection pool.
* <p>
* Default is vendor-specific
* @since 1.1
*/
int maxIdleTime() default -1;
/**
* The total number of statements that a connection pool should keep open.
* A value of 0 indicates that the caching of statements is disabled for
* a connection pool.
* <p>
* Default is vendor-specific
* @since 1.1
*/
int maxStatements() default -1;
/**
* Used to specify vendor-specific properties and less commonly
* used <code>DataSource</code> properties such as:
* <p>
* <ul>
* <li>dataSourceName
* <li>networkProtocol
* <li>propertyCycle
* <li>roleName
* </ul>
* <p>
* Properties are specified using the format:
* <i>propertyName=propertyValue</i> with one property per array element.
* <p>
* If a DataSource property is specified in the <code>properties</code>
* element and the annotation element for the property is also
* specified, the annotation element value takes precedence.
* @since 1.1
*/
String[] properties() default {};
/**
* Sets the maximum time in seconds that this data source will wait while
* attempting to connect to a database. A value of zero specifies that
* the timeout is the default system timeout if there is one; otherwise,
* it specifies that there is no timeout.
* <p>
* Default is vendor-specific.
* @since 1.1
*/
int loginTimeout() default 0;
}