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

📄 bmp4.html

📁 jdbc书
💻 HTML
📖 第 1 页 / 共 3 页
字号:
</TABLE>

<P>
<TABLE>
<TR><TD WIDTH="200"><FONT FACE="Verdana, Arial, Helvetica, sans-serif"><CODE>NEVER</CODE></FONT></TD>
<TD><FONT FACE="Verdana, Arial, Helvetica, sans-serif"><CODE>TX_NOT_SUPPORTED</CODE></FONT></TD></TR>
</TABLE>

<TABLE>
<TR><TD><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
If the code calling a method in this Bean has a transaction running, 
suspend that transaction until the method called in this Bean completes. 
No transaction context is created for this Bean.  </FONT>
</TD></TR>
</TABLE>

<P>
<TABLE>
<TR><TD WIDTH="200"><FONT FACE="Verdana, Arial, Helvetica, sans-serif"><CODE>MANDATORY</CODE></FONT></TD>
<TD><FONT FACE="Verdana, Arial, Helvetica, sans-serif"><CODE>TX_MANDATORY</CODE></FONT></TD></TR>
</TABLE>

<TABLE>
<TR><TD><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
The transaction attribute for this Bean is set when another
Bean calls one of its methods. In this case, this Bean gets
the transaction attribute of the calling Bean. If the calling
Bean has no transaction attribute, the method called in this
Bean throws a  <CODE>TransactionRequired</CODE> exception.</FONT>
</TD></TR>
</TABLE>

<A NAME="level"></A>
<STRONG>Isolation Level Descriptions</STRONG>:
An enterprise Bean uses an <EM>isolation level</EM> to
negotiate its own interaction with shared data and
the interaction of other threads with the same shared data.
As the name implies, there are various levels of isolation
with <CODE>TRANSACTION_SERIALIZABLE</CODE> providing the
highest level of data integrity.

<BLOCKQUOTE>
<HR>
<STRONG>Note:</STRONG>
Be sure to verify your database can handle the level
you choose. In the Enterprise JavaBeans 1.1 specification,
only Bean-managed persistence session Beans can set the
isolation level.

<P>
If the database cannot handle the isolation level, the Enterprise
JavaBeans server will get a failure when it tries to call the
<CODE>setTransactionIsolation</CODE> JDBC method.
<HR>
</BLOCKQUOTE>

<P>
<STRONG><CODE>TRANSACTION_SERIALIZABLE</CODE></STRONG>: This
level provides maximum data integrity. The Bean gets what amounts
to exclusive access to the data. No other transaction can read or
write this data until the serializable transaction completes.

<P>
Serializable in this context means <EM>process as a serial operation</EM>,
and should not be confused with serializing objects to preserve and
restore their states. Running transactions as a single serial operation
is the slowest setting. If performance is an issue, use another isolation
level that meets your application requirements, but provides better
performance.

<P>
<STRONG><CODE>TRANSACTION_REPEATABLE_READ</CODE></STRONG>: At
this level, data read by a transaction can be read, but not
modified, by another transaction. The data is guaranteed to have
the same value it had when first read, unless the first transaction
changes it and writes the changed value back.

<P>
<STRONG><CODE>TRANSACTION_READ_COMMITTED</CODE></STRONG>:
At this level, data read by a transaction cannot be read
by other transactions until the
frist transaction either commits or rolls back.

<P>
<STRONG><CODE>TRANSACTION_READ_UNCOMMITTED</CODE></STRONG>:
At this level, data involved in a transaction can be read by
other threads before the first transaction either completes or
rolls back. The other transactions cannot tell if
the data was finally committed or rolled back

<A NAME="bmt"></A>
<H4>Bean-Managed Example</H4>

<CODE>SellerBean</CODE> is a session Bean that uses
<CODE>RegistrationBean</CODE> to check the user ID and password when
someone posts an auction item and debit the seller's account
for a listing, and <CODE>AuctionItemBean</CODE> to add new auction 
items to the database.

<P>
The transacton begins in the <CODE>insertItem</CODE> method
with the account debit and ends when the entire 
transaction either commits or rolls back. The entire transaction including the 
50 cents debit rolls back if the auction item is <CODE>null</CODE> 
(the insertion failed), or if an exception is caught. 
If the auction item is not <CODE>null</CODE> 
and the insertion succeeds, the entire transaction including the 50 
cents debit commits. 

<P>
For this example, the isolation level is <CODE>TRANSACTION_SERIALIZABLE</CODE>, 
and the transaction attribute is <CODE>TX_BEAN_MANAGED</CODE>.
The other Beans in the transaction, <CODE>RegistrationBean</CODE>
and <CODE>AuctionItemBean</CODE>, have an isolation level of
<CODE>TRANSACTION_SERIALIZABLE</CODE> and a transaction attribute
of <CODE>REQUIRED</CODE>.

<P>
Changes to this version of <CODE>SellerBean</CODE> over the
container-managed version are flagged with comments. 

</FONT>

<PRE>
public int insertItem(String seller, 
	String password, 
	String description, 
	int auctiondays, 
	double startprice, 
	String summary) 
	throws RemoteException {

//Declare transaction context variable using the
//javax.transaction.UserTransaction class
  UserTransaction uts= null;

  try{
    Context ectx = new InitialContext(p);

//Get the transaction context
    uts=(UserTransaction)ctx.getUserTransaction();

    RegistrationHome rhome = (
	RegistrationHome)ectx.lookup("registration");
    RegistrationPK rpk=new RegistrationPK();
    rpk.theuser=seller;
    Registration newseller=
	rhome.findByPrimaryKey(rpk);

    if((newseller == null)|| 
	(!newseller.verifyPassword(password))) {
        return(Auction.INVALID_USER);
    }

//Start the transaction
    uts.begin(); 

//Deduct 50 cents from seller's account
    newseller.adjustAccount(-0.50);

    AuctionItemHome home = (
	AuctionItemHome) ectx.lookup("auctionitems");
    AuctionItem ai= home.create(seller, 
	description, 
	auctiondays, 
	startprice, 
	summary);

    if(ai == null) {
//Roll transaction back
        uts.rollback();
        return Auction.INVALID_ITEM;
    }
    else {
//Commit transaction 
        uts.commit();
        return(ai.getId());
    }

    }catch(Exception e){
        System.out.println("insert problem="+e);
//Roll transaction back if insert fails 
        uts.rollback();
        return Auction.INVALID_ITEM;
    }
}
</PRE>

<FONT FACE="Verdana, Arial, Helvetica, sans-serif">

<P ALIGN="RIGHT">
<FONT SIZE="-1">[<A HREF="#top">TOP</A>]</FONT>

</FONT>
</TD>
</TR>
</TABLE>





<!-- ================ -->
<!-- End Main Content -->
<!-- ================ -->

</TD>
</TR>
</TABLE>

<!-- Copyright Insert -->

<BR CLEAR="ALL">

<FORM ACTION="/cgi-bin/search.cgi" METHOD="POST">
<TABLE WIDTH="100%" CELLPADDING="0" BORDER="0" CELLSPACING="5">   
  <TR>
    <TD VALIGN="TOP">
	
    <P ALIGN=CENTER>
    <FONT SIZE="-1" COLOR="#999999" FACE="Verdana, Arial, Helvetica, sans-serif">
    [ This page was updated: <!-- new date --> 13-Oct-99 ]</font></P>
    </TD>
  </TR>
  
  <TR>
    <TD BGCOLOR="#CCCCCC">
    <IMG SRC="/images/pixel.gif" HEIGHT="1" WIDTH="1" ALT=""></TD>
  </TR>
  
  <TR>
    <TD>
    <CENTER>
    <FONT SIZE="-2" FACE="Verdana, Arial, Helvetica, sans-serif">
    <A HREF="http://java.sun.com/products/">Products &amp; APIs</A> | 
    <A HREF="/developer/index.html">Developer Connection</A> | 
    <A HREF="/developer/infodocs/index.shtml">Docs &amp; Training</A> | 
    <A HREF="/developer/support/index.html">Online Support</A><BR>
    <A HREF="/developer/community/index.html">Community Discussion</A> |
    <A HREF="http://java.sun.com/industry/">Industry News</A> | 
    <A HREF="http://java.sun.com/solutions">Solutions Marketplace</A> | 
    <A HREF="http://java.sun.com/casestudies">Case Studies</A>
    </FONT>
    </CENTER>
    </TD>
  </TR>
  
  <TR>
    <TD BGCOLOR="#CCCCCC">
    <IMG SRC="/images/pixel.gif" HEIGHT="1" WIDTH="1" ALT=""></TD>
  </TR>

  <TR>
    <TD ALIGN="CENTER">
    <FONT SIZE="-2" FACE="Verdana, Arial, Helvetica, sans-serif">
    <A HREF="http://java.sun.com/docs/glossary.html">Glossary</A> - 
    <A HREF="http://java.sun.com/applets/">Applets</A> - 
    <A HREF="http://java.sun.com/docs/books/tutorial/">Tutorial</A> - 
    <A HREF="http://java.sun.com/jobs/">Employment</A> - 
    <A HREF="http://java.sun.com/nav/business/">Business &amp; Licensing</A> - 
    <A HREF="http://java.sun.com/javastore/">Java Store</A> -
    <A HREF="http://java.sun.com/casestudies/">Java in the Real World</A>
    </FONT>
    </TD>
  </TR>

  <TR>
    <TD>
    <CENTER>
    <FONT SIZE="-2" FACE="Verdana, Arial, Helvetica, sans-serif">
    <a href="/siteinfo/faq.html">FAQ</a> |
    <a href="/feedback/index.html">Feedback</a> | 
    <a href="http://www.dynamicdiagrams.net/mapa/cgi-bin/help.tcl?db=javasoft&dest=http://java.sun.com/">Map</a> | 
    <A HREF="http://java.sun.com/a-z/index.html">A-Z Index</A>
    </FONT>
    </CENTER>

    </TD>
  </TR>
  
  <TR>
    <TD>

    <TABLE WIDTH="100%" CELLPADDING="0" BORDER="0" CELLSPACING="0">
      <TR>
        <TD WIDTH="50%">
        <FONT SIZE="-2" FACE="Verdana, Arial, Helvetica, sans-serif">
        For more information on Java technology<BR>
        and other software from Sun Microsystems, call:<BR>
        </FONT>
        <FONT SIZE="-1" FACE="Verdana, Arial, Helvetica, sans-serif">
        (800) 786-7638<BR></FONT>
        <FONT SIZE="-2" FACE="Verdana, Arial, Helvetica, sans-serif">
        Outside the U.S. and Canada, dial your country's 
        <A HREF="http://www.att.com/business_traveler/attdirecttollfree/">AT&amp;T&nbsp;Direct&nbsp;Access&nbsp;Number</A> first.<BR>
        </FONT>
        </TD>

        <TD ALIGN="RIGHT" WIDTH="50%">
        <A HREF="http://www.sun.com"><IMG SRC="/images/lgsun.gif" width="64" height="30" border="0" ALT="Sun Microsystems, Inc."></A><BR>
        <FONT SIZE="-2" FACE="Verdana, Arial, Helvetica, sans-serif">
        Copyright &copy; 1995-99
        <A HREF="http://www.sun.com">Sun Microsystems, Inc.</A><BR>
        All Rights Reserved. 
        <a href="http://www.sun.com/share/text/SMICopyright.html">Legal Terms</a>. 
        <A HREF="http://www.sun.com/privacy/">Privacy&nbsp;Policy</A>.
        </FONT>
        </TD>
      </TR>
    </TABLE>
	
    </TD>
  </TR> 
</TABLE>
</FORM>

<!-- End Copyright Insert -->


</BODY>
</HTML>

⌨️ 快捷键说明

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