Source Code Cross Referenced for SessionBean.java in  » EJB-Server-JBoss-4.2.1 » testsuite » org » jboss » test » perf » ejb » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » EJB Server JBoss 4.2.1 » testsuite » org.jboss.test.perf.ejb 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * JBoss, Home of Professional Open Source.
003:         * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004:         * as indicated by the @author tags. See the copyright.txt file in the
005:         * distribution for a full listing of individual contributors.
006:         *
007:         * This is free software; you can redistribute it and/or modify it
008:         * under the terms of the GNU Lesser General Public License as
009:         * published by the Free Software Foundation; either version 2.1 of
010:         * the License, or (at your option) any later version.
011:         *
012:         * This software is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015:         * Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this software; if not, write to the Free
019:         * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021:         */
022:        package org.jboss.test.perf.ejb;
023:
024:        // SessionBean.java
025:
026:        import java.rmi.RemoteException;
027:        import java.rmi.ServerException;
028:        import java.util.Collection;
029:        import java.util.Iterator;
030:        import javax.ejb.CreateException;
031:        import javax.ejb.FinderException;
032:        import javax.ejb.RemoveException;
033:        import javax.ejb.SessionContext;
034:        import javax.naming.Context;
035:        import javax.naming.InitialContext;
036:        import javax.naming.NamingException;
037:        import javax.rmi.PortableRemoteObject;
038:
039:        import org.apache.log4j.Logger;
040:
041:        import org.jboss.test.perf.interfaces.EntityLocalHome;
042:        import org.jboss.test.perf.interfaces.EntityLocal;
043:        import org.jboss.test.perf.interfaces.EntityPK;
044:
045:        public class SessionBean implements  javax.ejb.SessionBean {
046:            private static Logger log = Logger.getLogger(SessionBean.class);
047:            private EntityLocalHome entityHome;
048:
049:            public void setSessionContext(SessionContext context) {
050:            }
051:
052:            public void ejbCreate(String entityName) throws CreateException {
053:                try {
054:                    Context context = new InitialContext();
055:                    Object ref = context.lookup("java:comp/env/" + entityName);
056:                    entityHome = (EntityLocalHome) PortableRemoteObject.narrow(
057:                            ref, EntityLocalHome.class);
058:                } catch (NamingException e) {
059:                    throw new CreateException("Cound not resolve name: " + e);
060:                }
061:            }
062:
063:            private EntityLocal findByPrimaryKey(int key)
064:                    throws FinderException {
065:                EntityPK primaryKey = new EntityPK(key);
066:                return entityHome.findByPrimaryKey(primaryKey);
067:            }
068:
069:            private Collection findInRange(int min, int max)
070:                    throws FinderException {
071:                return entityHome.findInRange(min, max);
072:            }
073:
074:            public void create(int low, int high) throws CreateException {
075:                for (int i = low; i < high; i++) {
076:                    entityHome.create(i, 0);
077:                }
078:            }
079:
080:            public void remove(int low, int high) throws RemoveException {
081:                if (low + 1 == high) {
082:                    try {
083:                        EntityLocal entity = findByPrimaryKey(low);
084:                        entity.remove();
085:                    } catch (FinderException e) {
086:                        log.error("Failed to find and remove entity", e);
087:                        throw new RemoveException(
088:                                "Failed to find and remove entity");
089:                    }
090:                } else {
091:                    //There is no find in range finder! till someone implements it...
092:                    //java.util.Enumeration elements = findInRange(low, high);
093:                    int count = 0;
094:                    for (int i = low; i < high; i++) {
095:                        try {
096:                            EntityLocal entity = findByPrimaryKey(i);
097:                            entity.remove();
098:                            count++;
099:                        } catch (Exception e) {
100:                            //ignore
101:                        } // end of try-catch
102:                    } // end of for ()
103:
104:                    if (count != (high - low)) {
105:                        throw new RemoveException("Removed " + count
106:                                + " but should remove:" + (high - low));
107:                    }
108:                }
109:            }
110:
111:            public void read(int id) throws RemoteException {
112:                try {
113:                    EntityLocal entity = findByPrimaryKey(id);
114:                    entity.read();
115:                } catch (FinderException e) {
116:                    throw new ServerException("findByPrimaryKey failed for id="
117:                            + id, e);
118:                }
119:            }
120:
121:            public void read(int low, int high) throws RemoteException {
122:                Collection elements = null;
123:                try {
124:                    elements = findInRange(low, high);
125:                } catch (FinderException e) {
126:                    throw new ServerException("findInRange failed for low="
127:                            + low + ", high=" + high, e);
128:                }
129:
130:                Iterator iter = elements.iterator();
131:                while (iter.hasNext()) {
132:                    EntityLocal entity = (EntityLocal) iter.next();
133:                    entity.read();
134:                }
135:            }
136:
137:            public void write(int id) throws RemoteException {
138:                try {
139:                    EntityLocal entity = findByPrimaryKey(id);
140:                    int value = entity.read();
141:                    entity.write(value + 1);
142:                } catch (FinderException e) {
143:                    throw new ServerException("findByPrimaryKey failed for id="
144:                            + id, e);
145:                }
146:            }
147:
148:            public void write(int low, int high) throws RemoteException {
149:                Collection elements = null;
150:                try {
151:                    elements = findInRange(low, high);
152:                } catch (FinderException e) {
153:                    throw new ServerException("findInRange failed for low="
154:                            + low + ", high=" + high, e);
155:                }
156:
157:                Iterator iter = elements.iterator();
158:                while (iter.hasNext()) {
159:                    EntityLocal entity = (EntityLocal) iter.next();
160:                    int value = entity.read();
161:                    entity.write(value + 1);
162:                }
163:            }
164:
165:            public void ejbRemove() {
166:            }
167:
168:            public void ejbActivate() {
169:            }
170:
171:            public void ejbPassivate() {
172:            }
173:
174:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.