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

📄 sequencegeneratorbean.java~10~

📁 大型EJB项目的代码,上传让大家看看,希望得到会员的资格,可以下到好的代码来学习,
💻 JAVA~10~
字号:
package shiponline;import javax.ejb.*;public class SequenceGeneratorBean implements SessionBean {  SessionContext sessionContext;  private class Entry {   Sequence sequence;   int first = 0;   int last = Integer.MAX_VALUE; }; private java.util.Hashtable entries = new java.util.Hashtable(); private int blockSize; private int retryCount; private SequenceHome sequenceHome; public void ejbCreate() throws CreateException {    /**@todo Complete this method*/  }  public void ejbRemove() {    /**@todo Complete this method*/  }  public void ejbActivate() {    /**@todo Complete this method*/  }  public void ejbPassivate() {    /**@todo Complete this method*/  }  public void setSessionContext(SessionContext sessionContext) {    try {     javax.naming.Context context = new javax.naming.InitialContext();     blockSize = ((Integer) context.lookup("java:comp/env/blockSize")).intValue();     retryCount = ((Integer) context.lookup("java:comp/env/retryCount")).intValue();     sequenceHome = (SequenceHome) context.lookup("java:comp/env/Sequence");   }   catch(javax.naming.NamingException e) {     throw new javax.ejb.EJBException(e);   }  }  public int nextSequenceNumber(String name) {    try {         Entry entry = (Entry) entries.get(name);         if(entry == null) {           // add an entry to the sequence table           entry = new Entry();           try {             entry.sequence = sequenceHome.findByPrimaryKey(name);           }           catch(javax.ejb.FinderException e) {             // if we couldn't find it, then create it...             entry.sequence = sequenceHome.create(name);           }           entries.put(name, entry);         }         if(entry.last > entry.first + blockSize) {           for(int retry = 0; true; retry++) {             try {               entry.first = entry.sequence.seqValueBeforeIncrementingBy(blockSize);               entry.last = entry.first;               break;             }             catch(Exception e) {               if(retry < retryCount) {                 // we hit a concurrency exception, so try again...                 continue;               }               else {                 // we tried too many times, so fail...                 throw new javax.ejb.EJBException(e);               }             }           }         }         return entry.last++;       }       catch(javax.ejb.CreateException e) {         throw new javax.ejb.EJBException(e);       }       catch(Exception e) {         throw new javax.ejb.EJBException(e);       }  }}

⌨️ 快捷键说明

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