web server - Borland Technical Publications
web server - Borland Technical Publications web server - Borland Technical Publications
Connecting to JDBC Resources from J2EE Application Components Armed with this information, let's complete our datasource definition for the Oracle datasource we started above. In order to be thorough, let's first reproduce the XML we started above: datasources/Oracle datasources/OracleDriver False connectionType Enumerated Direct ... Note the driver datasource JNDI name in bold. Now we'll add the following: datasources/OracleDriver oracle.jdbc.pool.OracleConnectionPoolDataSource user String MisterKittles password String Mittens ... // other properties as needed ... Now the JDBC datasource is fully defined. Once you've packaged the XML file as a DAR, you can deploy it to a Partition. Doing so registers the datasource with the Naming Service and makes it available for lookup. Connecting to JDBC Resources from J2EE Application Components In Borland proprietary deployment descriptors, such as ejb-borland.xml for EJB components, the element is used to map a datasource logical name to actual JNDI location of a JDBC datasource definition. Mapping of the logical name to its location occurs when a JNDI lookup is performed for a desired datasource in the application component. You use the element within your individual component definitions. For example, a for an entity bean must be found within the tags. Let's look at the DTD representation of the element of Borland deployment descriptors: Chapter 22: Using JDBC 207
Connecting to JDBC Resources from J2EE Application Components In this element you specify the following: ■ ■ res-ref-name: this is the logical name for the resource, the same logical name you use in the element of the standard ejb-jar.xml descriptor file. This is the name your application components use to look up the datasource. jndi-name: this is the JNDI name of the datasource that will be bound to its logical name. It must match the value of the corresponding element of the element deployed with the DAR. ■ cmp-resource: this is an optional boolean element that is relevant to entity beans only. If set to True, the container's CMP engine will monitor this datasource. Let's look at an example entity bean that uses the Oracle datasource we defined above: entity_bean ... jdbc/MyDataSource datasources/Oracle True ... As you can see, we used the identical JNDI name from the element from the datasource definition. Now let's see how we obtain a datasource object reference. To do so, the application performs a lookup of the value of the deployed components and the object references are retrieved from the remote CosNaming provider. For example: javax.sql.DataSource ds1; try { javax.naming.Context ctx = (javax.naming.Context) new javax.naming.InitialContext(); ds1 = (DataSource)ctx.lookup("java:comp/env/jdbc/MyDataSource"); } catch (javax.naming.NamingException exp) { exp.printStackTrace(); } A database java.sql.Connection can now be obtained from ds1. 208 BES Developer’s Guide
- Page 167 and 168: Support for ORDER BY Support for OR
- Page 169 and 170: Overriding SQL generated from EJB-Q
- Page 171 and 172: Container-managed data access suppo
- Page 173 and 174: 162 BES Developer’s Guide
- Page 175 and 176: Generating primary keys from a cust
- Page 177 and 178: Implementing primary key generation
- Page 179 and 180: Transaction manager services Consis
- Page 181 and 182: Transaction manager services When t
- Page 183 and 184: Transaction manager services Follow
- Page 185 and 186: Declarative transaction management
- Page 187 and 188: Declarative transaction management
- Page 189 and 190: JDBC API Modifications JDBC API Mod
- Page 191 and 192: Handling of EJB exceptions Applicat
- Page 193 and 194: 182 BES Developer’s Guide
- Page 195 and 196: Client View of an MDB Client View o
- Page 197 and 198: Clustering of MDBs This is yet anot
- Page 199 and 200: Error Recovery Redelivered messages
- Page 201 and 202: 190 BES Developer’s Guide
- Page 203 and 204: JNDI Definitions Module Important s
- Page 205 and 206: Disabling and Enabling a Deployed D
- Page 207 and 208: Configuring JDBC Datasources In the
- Page 209 and 210: Configuring JDBC Datasources To add
- Page 211 and 212: Defining the Connection Pool Proper
- Page 213 and 214: Defining the Connection Pool Proper
- Page 215 and 216: Descriptions of Borland Enterprise
- Page 217: Advanced Topics for Defining JDBC D
- Page 221 and 222: Configuring JMS Connection Factorie
- Page 223 and 224: Defining Connection Pool Properties
- Page 225 and 226: Obtaining JMS Connection Factories
- Page 227 and 228: JMS and Transactions and its accomp
- Page 229 and 230: JMS and Transactions For instance:
- Page 231 and 232: 220 BES Developer’s Guide
- Page 233 and 234: Configuring JMS administered object
- Page 235 and 236: Tibco Creating Clustered JMS Servic
- Page 237 and 238: Sonic serverUrl String localhost:72
- Page 239 and 240: Sonic Creating Clustered JMS Servic
- Page 241 and 242: OpenJMS Even though OpenJMS can be
- Page 243 and 244: OpenJMS Important If you use OpenJM
- Page 245 and 246: OpenJMS openjms.clean_messages_on_s
- Page 247 and 248: OpenJMS Table 24.1 Property Name De
- Page 249 and 250: Other JMS providers The following a
- Page 251 and 252: 240 BES Developer’s Guide
- Page 253 and 254: Creating the Interceptor Class For
- Page 255 and 256: Creating the JAR file Creating the
- Page 257 and 258: Components Components The Connector
- Page 259 and 260: System Contracts Connection Managem
- Page 261 and 262: System Contracts Security Managemen
- Page 263 and 264: Common Client Interface (CCI) Conne
- Page 265 and 266: Packaging and Deployment Figure 26.
- Page 267 and 268: Resource Adapters Resource Adapters
Connecting to JDBC Resources from J2EE Application Components<br />
Armed with this information, let's complete our datasource definition for the Oracle<br />
datasource we started above. In order to be thorough, let's first reproduce the XML we<br />
started above:<br />
<br />
<br />
datasources/Oracle<br />
datasources/OracleDriver<br />
False<br />
<br />
connectionType<br />
Enumerated<br />
Direct<br />
<br />
<br />
...<br />
Note the driver datasource JNDI name in bold. Now we'll add the following:<br />
<br />
datasources/OracleDriver<br />
oracle.jdbc.pool.OracleConnectionPoolDataSource<br />
<br />
user<br />
String<br />
MisterKittles<br />
<br />
<br />
password<br />
String<br />
Mittens<br />
<br />
...<br />
// other properties as needed<br />
...<br />
<br />
<br />
Now the JDBC datasource is fully defined. Once you've packaged the XML file as a<br />
DAR, you can deploy it to a Partition. Doing so registers the datasource with the<br />
Naming Service and makes it available for lookup.<br />
Connecting to JDBC Resources from J2EE Application Components<br />
In <strong>Borland</strong> proprietary deployment descriptors, such as ejb-borland.xml for EJB<br />
components, the element is used to map a datasource logical name to<br />
actual JNDI location of a JDBC datasource definition. Mapping of the logical name to<br />
its location occurs when a JNDI lookup is performed for a desired datasource in the<br />
application component. You use the element within your individual component<br />
definitions. For example, a for an entity bean must be found within the<br />
tags. Let's look at the DTD representation of the element of<br />
<strong>Borland</strong> deployment descriptors:<br />
<br />
Chapter 22: Using JDBC 207