JavaÊÂÎñAPI
JavaÊÂÎñAPI£¨JTA£»Java Transaction API£©ºÍËüµÄͬ°ûJavaÊÂÎñ·þÎñ(JTS£»Java TransactionService)£¬ÎªJ2EEƽ̨ÌṩÁË·Ö²¼Ê½ÊÂÎñ·þÎñ¡£Ò»¸ö·Ö²¼Ê½ÊÂÎñ£¨distributedtransaction£©°üÀ¨Ò»¸öÊÂÎñ¹ÜÀíÆ÷£¨transaction manager£©ºÍÒ»¸ö»ò¶à¸ö×ÊÔ´¹ÜÀíÆ÷(resource manager)¡£Ò»¸ö×ÊÔ´¹ÜÀíÆ÷£¨resource manager£©ÊÇÈÎÒâÀàÐ͵ij־û¯Êý¾Ý´æ´¢¡£ÊÂÎñ¹ÜÀíÆ÷£¨transaction manager£©³Ðµ£×ÅËùÓÐÊÂÎñ²ÎÓëµ¥ÔªÕßµÄÏ໥ͨѶµÄÔðÈΡ£Ï³µÕ¾ÏÔʾÁËÊÂÎñ¹ÜÀíÆ÷ºÍ×ÊÔ´¹ÜÀíµÄ¼äµÄ¹Øϵ¡£
¡¡¡¡JTAÊÂÎñ±ÈJDBCÊÂÎñ¸üÇ¿´ó¡£Ò»¸öJTAÊÂÎñ¿ÉÒÔÓжà¸ö²ÎÓëÕߣ¬¶øÒ»¸öJDBCÊÂÎñÔò±»ÏÞ¶¨ÔÚÒ»¸öµ¥Ò»µÄÊý¾Ý¿âÁ¬½Ó¡£ÏÂÁÐÈÎÒ»¸öJavaƽ̨µÄ×é¼þ¶¼¿ÉÒÔ²ÎÓëµ½Ò»¸öJTAÊÂÎñÖУº
¡¡¡¡.JDBCÁ¬½Ó
¡¡¡¡.JDO PersistenceManager ¶ÔÏó
¡¡¡¡.JMS ¶ÓÁÐ
¡¡¡¡.JMS Ö÷Ìâ
¡¡¡¡.ÆóÒµJavaBeans£¨EJB£©
¡¡¡¡.Ò»¸öÓÃJ2EE Connector Architecture ¹æ·¶±àÒëµÄ×ÊÔ´·ÖÅäÆ÷¡£
¡¡¡¡Ê¹ÓÃJTAµÄÊÂÎñ»®·Ö
¡¡¡¡ÒªÓÃJTAÀ´»®·ÖÒ»¸öÊÂÎñ£¬Ó¦ÓóÌÐòµ÷ÓÃjavax.transaction.UserTransaction½Ó¿ÚÖеķ½·¨¡£Ê¾Àý4ÏÔʾÁËÒ»¸öµäÐ͵ÄJNDIËÑË÷µÄUseTransaction¶ÔÏó¡£
import javax.transaction.*£»
import javax.naming.*£»
// ...
InitialContext ctx = new InitialContext()£»
Object txObj = ctx.lookup("java:comp/UserTransaction"£»)£»
UserTransaction utx = (UserTransaction) txObj£»
Ó¦ÓóÌÐòÓÐÁËUserTransaction¶ÔÏóµÄÒýÓÃÖ®ºó£¬¾Í¿ÉÒÔÏóʾÀý5ÄÇÑùÀ´Æð¶¯ÊÂÎñ¡£
utx.begin()£»
// ...
DataSource ds = obtainXADataSource()£»
Connection conn = ds.getConnection()£»
pstmt = conn.prepareStatement("£»UPDATE MOVIES ..."£»)£»
pstmt.setString(1£¬ "£»Spinal Tap"£»)£»
pstmt.executeUpdate()£»
// ...
utx.commit()£»
// ...
µ±Ó¦ÓóÌÐòµ÷ÓÃcommit()ʱ£¬ÊÂÎñ¹ÜÀíÆ÷ʹÓÃÁ½¶ÎÌá½»ÐÒéÀ´½áÊøÊÂÎñ¡£JTAÊÂÎñ¿ØÖƵķ½·¨£º
javax.transaction.UserTransaction½Ó¿ÚÌṩÁËÏÂÁÐÊÂÎñ¿ØÖÆ·½·¨£º
public void begin()
public void commit()
public void rollback()
public void getStatus()
public void setRollbackOnly()
public void setTransactionTimeout(int)
Ó¦ÓóÌÐòµ÷ÓÃbegin()À´Æð¶¯ÊÂÎñ£¬¼´¿Éµ÷ÓÃcommit()Ò²¿ÉÒÔµ÷ÓÃrollback()À´½áÊøÊÂÎñ¡£
¡¡¡¡Ê¹ÓÃJTAºÍJDBC
¡¡¡¡¡¡¿ª·¢ÈËÔ±¾³£Ê¹ÓÃJDBCÀ´×÷ΪDAOÀàÖеĵײãÊý¾Ý²Ù×÷¡£Èç¹û¼Æ»®Ê¹ÓÃJTAÀ´»®·ÖÊÂÎñ£¬Ä㽫ÐèÒ
Ïà¹ØÎĵµ£º
repaint ¶Ô×é¼þ½øÐÐÖػ棬±ÈÈçÒ»¸öpanel£¬µ±ÄãremoveµôpanelÀïÃæµÄÒ»¸ö×é¼þʱ£¬Äã±ØÐëµ÷ÓÃrepaint·½·¨²ÅÄܶÔpanel½øÐÐÖػ棬½øÐÐˢУ¬ÄãÏëҪɾ³ýµÄ×é¼þ²ÅÄÜÔÚ½çÃæÉÏÏûʧ¡£
revalidate ¶Ô×é¼þ½øÐÐÑéÖ¤£¬±ÈÈçÒ»¸öpanel£¬µ±ÄãremoveµôpanelÀïÃæµÄÒ»¸ö×é¼þʱ£¬µ±Äãµ÷ÓÃrevalidate·½·¨ºó£¬panelµÄ²¼ ......
1¡¢ Web.xml
1£© ÅäÖÃhibernate
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/dbConnectionContext.xml /WEB-INF/serviceContext.xml</param-value> ......
javaÖеÄʼþ»úÖƵIJÎÓëÕßÓÐ3ÖÖ½ÇÉ«£º
1.event object£º¾ÍÊÇʼþ²úÉúʱ¾ßÌåµÄ“ʼþ”£¬ÓÃÓÚlistenerµÄÏàÓ¦µÄ·½·¨Ö®ÖУ¬×÷Ϊ²ÎÊý£¬Ò»°ã´æÔÚÓëlisternerµÄ·½·¨Ö®ÖÐ
2.event source£º¾ßÌåµÄ½ÓÊÜʼþµÄʵÌ壬±ÈÈç˵£¬Äãµã»÷Ò»¸öbutton£¬ÄÇôbutton¾ÍÊÇevent source£¬ÕâÑùÄã±ØÐëʹbutton¶ÔijЩʼþ½øÐÐÏàÓ¦£¬Äã¾ÍÐè ......
/*Decryptor*/
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
/**
* Decrypt the password get form Xpress GUI
*/
public class Decryptor{
//¼ÓÃÜ
  ......