⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 using the j2ee connector architecture common client interface.htm

📁 本人收集的关于Java Connector Architecture的资料
💻 HTM
📖 第 1 页 / 共 4 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title>Using the J2EE Connector Architecture Common Client Interface</title><meta name="keywords" content="CCI" /><meta name="description" content="Learn how to use the different interfaces and classes defined by the J2EE Connector architecture's Common Client Interface (CCI) API." /><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/><meta name="revision" content="@(#)index2.src1.2 04/02/01  JDC"/><meta name="archiveFlag" content="false"/><meta name="date" content="2003-03-22" /><link rel="stylesheet" href="/css/default_developer.css" /><script type='text/JavaScript' src='/js/popUp.js'></script></head><!--stopindex--><body leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" rightmargin="0" bgcolor="#ffffff"><a name="top"></a><!-- BEGIN GENERIC MASTHEAD --><!-- BEGIN VNV1 MASTHEAD COMPONENT, thinner variation for content pages --><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td><table border="0" cellpadding="0" cellspacing="0" width="100%" height="25" class="topnav"><form name="formsearch" action="http://developer.sun.com/dispatcher.jsp" method="post"><tr><td><a href="#mast"><img src="/im/a.gif" width="10" height="1" border="0" alt="Skip Masthead Links" /></a></td><td><a href="http://developers.sun.com">developers.sun.com</a></td><td width="100%">&nbsp;</td> <td nowrap="nowrap"><span class="rightarrowblue">&raquo;</span>&nbsp;<a href="http://developers.sun.com/dispatcher.jsp?uid=6910020">search tips</a>&nbsp;&nbsp;|&nbsp;&nbsp;<b>Search:</b>&nbsp;</td><td><input name="qt" class="medium" size="7" value="" /></td><td>&nbsp;</td><td class="selectcell"><select class="globalsearch" name="uid"><option value="6910018" selected>in Developers' Site</option><option value="6910019">in Sun.com</option></select></td><td>&nbsp;</td><td valign="middle" align="left"><input type="submit" border="0" class="buttonred" value="&nbsp;&raquo;&nbsp;" onmouseover="this.style.color='#fbe249';" onmouseout="this.style.color='#FFF';" /></td><td><img src="/im/a.gif" width="10" height="1" alt=" " /></td></tr></form></table><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td><img src="/im/a.gif" width="10" height="1" border="0" alt=" " /></td><td valign="top" class="grey3"><a href="http://java.sun.com"><img src="/im/logo_java_grey.gif" width="180" height="53" border="0" alt=" " /></a></td><td><img src="/im/a.gif" width="10" height="1" border="0" alt=" " /></td><td class="sunblue" valign="top" nowrap="nowrap"><div class="pad6"><a href="http://developers.sun.com"><img src="/im/masthead_the_source.gif" width="262" height="25" border="0" alt="The Source for Developers" /></a><br /><a href="http://developers.sun.com/dispatcher.jsp?uid=6910022"><img src="/im/masthead_sdn_site.gif" width="169" height="15" border="0" alt="A Sun Developer Network Site" /></a></div></td><td class="sunblue"><img src="/im/a.gif" width="10" height="1" border="0" alt=" " /></td><td class="sunblue"><div class="pad6"><a href="http://developers.sun.com/dispatcher.jsp?uid=6910023"><img src="/im/masthead_prod_and_tech.gif" width="158" height="15" border="0" alt="Products and Technologies" /></a><br /><a href="http://developers.sun.com/dispatcher.jsp?uid=6910024"><img src="/im/masthead_tech_topics.gif" width="105" height="15" border="0" alt="Technical Topics" /></a></div><img src="/im/a.gif" width="196" height="1" border="0" alt=" " /></td><td class="sunblue" width="100%" valign="top" align="right"><div class="pad10"><a href="http://www.sun.com"><img src="/im/logo_sun.gif" width="72" height="33" border="0" alt="Sun Microsystems" /></a></div></td><td><a name="mast"></a><a href="#skip2content"><img src="/im/a.gif" width="10" height="1" border="0" alt=" " /></a></td></tr></table></td></tr></table><span class="sp5">&nbsp;</span><br /><!-- END VNV1 MASTHEAD COMPONENT, thinner variation for content pages -->   <!-- END GENERIC MASTHEAD --><!-- BEGIN BREADCRUMB --><table border="0" cellpadding="0" cellspacing="0" width="100%" class="vatop"><tr><td>      <div class="breadcrumb"><a href="http://developers.sun.com/index.html">Developers Home</a> &gt; <a href="http://developers.sun.com/prodtech/index.html">Products & Technologies</a> &gt; <a href="http://java.sun.com/index.jsp">Java Technology</a> &gt; <a href="http://java.sun.com/j2ee/index.jsp">J2EE</a> &gt; <a href="http://java.sun.com/j2ee/reference/index.html">Reference</a> &gt; <a href="http://java.sun.com/j2ee/reference/techart/index.html">Technical Articles and Tips</a> &gt; <a href="http://java.sun.com/developer/technicalArticles/J2EE/index.html">Java 2 Enterprise Edition</a> &gt;</div></td><td align="right" nowrap="nowrap"><div class="breadcrumb"><b><a href="http://developers.sun.com/dispatcher.jsp?uid=6910021">Join a Sun Developer Network Community</a></b><br /><a href="http://developers.sun.com/user_registration/index.html">Profile and Registration</a> | <a href="http://developers.sun.com/user_registration/whyregister.html">Why Register?</a></div></td></tr><tr><td colspan="2"><img src="/im/a.gif" width="770" height="1" border="0" alt=" " /></td></tr></table><span class="sp5">&nbsp;</span><br />     <!-- END BREADCRUMB --><!-- BEGIN PAGETITLE --><div class="pagetitle2">Article</div><div class="pagetitle">Using the J2EE Connector Architecture Common Client Interface</div><!-- END PAGETITLE --><!-- BEGIN WRAPPER TABLE, 2 COLUMN, MAIN/RIGHT --><table border="0" cellpadding="10" cellspacing="0" width="100%"><tr><td width="100%" valign="top"><!-- BEGIN CENTRAL COLUMN COMPONENTS --><!--startindex--><!-- ============ --><!-- MAIN CONTENT --><!-- ============ --><a name="skip2content"></a><!--  BEGIN VCD4 BYLINE AND TOOLS  --><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td class="smaller" valign="top"><em></em></td><td width="10">&nbsp;</td><td align="right" valign="bottom"><div class="sitelinks" style="padding:0px;"><table border="0" cellpadding="0" cellspacing="0"><tr><td valign="bottom" align="right">&nbsp;</td><td valign="bottom" class="smaller" nowrap="nowrap"><a href="/jsp_utils/PrintPage.jsp" target="printFriendlyView" onclick="openPopup('','printFriendlyView',710,650,'no',1,1,0,0,0,0); return true;"><img src="/im/ic_print.gif" width="14" height="12" alt="Print-friendly Version" border="0" hspace="4" />Print-friendly Version</a></td></tr></table></div></td></tr></table><!--  END VCD4 BYLINE AND TOOLS  --><!--  BEGIN VCD4 BYLINE AND TOOLS  --><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td class="smaller" valign="top"><em></em></td><td width="10">&nbsp;</td><td align="right" valign="bottom"><div class="sitelinks" style="padding:0px;"></div></td></tr></table><div class="contentdivider"><table border="0" cellpadding="0" cellspacing="0" width="100%" class="grey4"><tr><td><img src="/im/a.gif" width="1" height="4" border="0" alt=" " /></td></tr></table></div><!--  END VCD4 BYLINE AND TOOLS  --><!-- ================== --><!-- Start Main Content --><!-- ================== --><span class="byline"><A HREF="/developer/technicalArticles/">Articles Index</A></span><p><br><span class="byline"><!-- <b>Sub</b><br> -->By Beth Stearns<br>(April 2001)</span></p><p>This article describes the J2EE Connector architecture Common ClientInterface (CCI) API. The CCI provides the access from J2EE clients, such asenterprise beans, JavaServer Pages (JSP) technology, and servlets, to an underlying enterpriseinformation system (EIS). The J2EE Connector architecture, and the CCI API,are currently available as a beta release. </p><p>The CCI simplifiesthe problem of writing code  to connect a client to an underlying EIS's datastore. This problem exists for both application developers and for EISvendors. The EIS vendor can use the CCI to write a generic interface to itsdatabase product.  With this one interface, their product will work withclients on any compliant J2EE platform.  Likewise, application developersonly need to learn and use one set of API calls to connect their client toany underlying EIS, rather than having to learn a different API for eachEIS.  In addition, even if an enterprise changes its underlying EIS, itsapplication code will not have to be changed to maintain this connectivity.</p><h2>Introduction to the CCI</h2><p>To access an EIS from a J2EE client, you need to first establish and definea connection to the EIS. The term EIS refers to a data store or database, orother mechanism that stores data on an enterprise scale. (For simplicity,this article uses the term database to refer to any kind of data store.) Foreach operation you want to perform on the data store or database, you establish and define an interaction. You also create a record fortransferring data into or out of the database. Rather than directly accessthe EIS, clients use the CCI to interact with a resource adapter, which is asoftware component provided by an EIS vendor for a specific EIS.</p><p>By designing resource adapters that comply with the specifications of the Connector architecture, EIS vendors make it possible for developers to write transportable code for accessing EISs without having to know the underlying semantics of the resource manager that handles the EIS.</p><h3>CCI Elements</h3><p>These are the Java classes defined in the CCI and some of the more important methods for performing database operations. </p><ul><li><code>ConnectionFactory</code>Establishes a connection instance with EIS<ul><li><code>getConnection</code> creates a <code>Connection instance</code> (managed by either a container or a component)</li><li><code>getRecordFactory</code> creates a <code>RecordFactory</code> instance</li></ul></li><li><code>Connection</code>Represents a connection (using the resource adapter) to an EIS<ul><li><code>createInteraction</code> creates an <code>Interaction</code> object so that database operations can be performed</li><li><code>getLocalTransaction</code> creates a <code>LocalTransaction</code> object</li><li><code>close</code> closes a connection to EIS</li></ul></li><li><code>ConnectionSpec</code>Defines user name, password, and other properties in a connection request; serves as properties parameter</li><li><code>Interaction</code>Creates an interaction with the connected EIS<ul><li><code>execute</code>invokes procedures stored in an EIS for performing database operations</li></ul></li><li><code>InteractionSpec</code>Defines an interaction with the connected EIS, including schema, catalog, and stored function names </li><li><code>RecordFactory</code>Creates <code>Record</code> object<ul><li><code>createIndexedRecord</code> creates an ordered collection of <code>Record</code> instances</li><li><code>createMappedRecord</code>  creates a collection of Record instances ordered by key-value pairs</li><li><code>createResultSet</code> creates a collection of Record instances as a result set of tabular data</li></ul></li><li><code>Record</code>Superclass for <code>Record</code> instances<ul><li><code>add</code> adds data to input record</li></ul></li><li><code>LocalTransaction</code>Establishes a context for a local transaction <ul><li><code>begin</code>  starts a database transaction</li><li><code>commit</code>  completes an atomic database transaction</li><li><code>rollback</code>  cancels transaction, returning database to initial state</li></ul></li></ul><p>There is a prescribed manner that a client or application component must follow to use the CCI to interact with an underlying EIS. The component must establish a connection to the EIS's resource manager using the <code> ConnectionFactory.</code> The <code>Connection</code> object represents the actual connection to the EIS and is used for subsequent interactions with the EIS. The <code>ConnectionSpec</code> object defines the connection request information, that is, the user name, password, and any other needed properties. </p><p>The component performs its interactions with the EIS, such as accessing data from a specific table, using an <code>Interaction</code> object. The <code>InteractionSpec</code> object defines the <code>Interaction</code> object, specifying the database schema and catalog and any predefined database operations stored in the database. When the application component reads data from the EIS (such as from database tables) or writes to those tables, it uses a <code>Record</code> instance, (a <code>MappedRecord</code>, <code>IndexedRecord</code>, or <code>ResultSet</code> instance) instantiated by the <code>RecordFactory</code> object. </p><p>An application component uses the <code>LocalTransaction</code> object only when it manages its own transaction and persistence. For example, an enterprise bean can choose to use bean-managed persistence (BMP), in which case it manages its own transactions. However, if the bean uses container-managed persistence (CMP), then the bean lets the container completely handle the transaction and it has no need to use the <code>LocalTransaction</code> object. The <code>LocalTransaction</code> object enables the data access to be conducted as an all-or-nothing transaction.</p><h3>Steps in Using a Connector</h3><p>The basic programming steps in using the CCI API and a connector to access a database or data store are:</p><ul><li>Establish a JNDI context for your session. User name and password are required to access the EIS.</li><li>Use the JNDI <code>lookup</code> method to locate the <code>ConnectionFactory</code> for the resource adapter. </li><li>Use the <code>ConnectionFactory</code> method <code>getConnection</code> to open the connection.</li><li>Use the Connection method <code>createInteraction</code> to create a new <code>Interaction</code> instance. All operations on the underlying EIS are done through an <code>Interaction</code> object.</li><li>Instantiate an object representing the <code>InteractionSpec</code> interface. </li><li>Use the <code>ConnectionFactory<code> method </code>getRecordFactory</code> to get a reference to the <code>RecordFactory.</code></li><li>Create <code>Record</code> instances as necessary using the appropriate <code>RecordFactory</code> create method, such as <code>createIndexedRecord</code>. Be sure to establish whether the record is for input, output, or both input and output (inout).</li><li>If you are managing your own transaction and persistence, begin a transaction so that you can recover if a problem occurs. </li><li>Perform the desired operation on the data store. The example in this article uses database stored procedures to operate on the database. Note that the elements in the <code>Record</code> instances need to map to the appropriate parameters in the stored procedures.</li><li>If you manage your own transaction, commit the transaction or rollback if there are errors.</li><li>Close the connection to the EIS.</li></ul><h2>Overview of the Example of a Session Bean Using a Resource Adapter</h2><p>This example shows how a session bean uses a resource adapter to add and read records in a 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -