Source Code Cross Referenced for A_manyops.java in  » J2EE » JOnAS-4.8.6 » org » objectweb » jonas » stests » manyops » 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 » J2EE » JOnAS 4.8.6 » org.objectweb.jonas.stests.manyops 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.objectweb.jonas.stests.manyops;
002:
003:        import java.rmi.RemoteException;
004:
005:        import javax.naming.NamingException;
006:        import javax.rmi.PortableRemoteObject;
007:
008:        import org.objectweb.jonas.stests.util.JTestCase;
009:
010:        public abstract class A_manyops extends JTestCase {
011:
012:            // Product's number initially created in the database table
013:            private static final int NB_PRODUCTS = 2500;
014:            // Create operation number done for one "many-create" operation
015:            private static final int NB_CREATE = 20;
016:
017:            //
018:            protected static InitDBHome idbHome = null;
019:            protected static InitDB idb = null;
020:            protected static ProductHome pHome = null;
021:            protected static boolean initialized = false;
022:
023:            public A_manyops(String name) {
024:                super (name);
025:            }
026:
027:            protected void setUp() throws Exception {
028:                super .setUp();
029:                if (idbHome == null) {
030:                    useBeans("manyops");
031:                    idbHome = (InitDBHome) PortableRemoteObject.narrow(ictx
032:                            .lookup("manyopsInitDBHome"), InitDBHome.class);
033:                }
034:                if (idb == null) {
035:                    idb = idbHome.create();
036:                }
037:                if (pHome == null) {
038:                    pHome = getProductHome();
039:                }
040:                if (!initialized) {
041:                    // The first time, create the database tables needed, and insert NB_PRODUCTS lines
042:                    idb.createTable();
043:                    for (int i = 1; i <= NB_PRODUCTS; i++) {
044:                        pHome.create("p" + i, i, 0);
045:                    }
046:                    initialized = true;
047:                }
048:            }
049:
050:            /**
051:             * return a Product Home
052:             */
053:            abstract ProductHome getProductHome() throws NamingException;
054:
055:            protected void tearDown() throws Exception {
056:                super .tearDown();
057:            }
058:
059:            /**
060:             * Allows to do 'opNb' times of the 'opType' operation on a Product bean.
061:             * The 'opType' may be:
062:             * - 'create',
063:             * - 'createmany' (ie one operation is N create operation)
064:             * - 'delete'
065:             * - 'get'
066:             * - 'set'
067:             * - 'findByPk'
068:             * - 'findByNumber'
069:             */
070:            public void manyops(int opNb, String opType) throws Exception {
071:                if (opNb > NB_PRODUCTS) {
072:                    throw new Exception(
073:                            "Operation number must be less than the initial product number");
074:                }
075:                // Do 'opNb' times the 'opType' operation
076:                for (int i = 1; i <= opNb; i++) {
077:                    Product bean;
078:                    int p;
079:                    if ("create".equals(opType)) {
080:                        int ipk = NB_PRODUCTS + i;
081:                        String spk = "p" + ipk;
082:                        bean = pHome.create(spk, ipk, 1);
083:                    } else if ("createmany".equals(opType)) {
084:                        for (int ii = 1; ii <= NB_CREATE; ii++) {
085:                            int iipk = NB_PRODUCTS + ii;
086:                            bean = pHome.create("p" + iipk, iipk, 1);
087:                        }
088:                        for (int ii = 1; ii <= NB_CREATE; ii++) {
089:                            int iipk = NB_PRODUCTS + ii;
090:                            pHome.remove("p" + iipk);
091:                        }
092:                    } else if ("delete".equals(opType)) {
093:                        String spk = "p" + i;
094:                        pHome.remove(spk);
095:                    } else {
096:                        // Choose randomly the bean on which the operation is done
097:                        int ipk = random(NB_PRODUCTS) + 1;
098:                        String spk = "p" + ipk;
099:                        if ("get".equals(opType)) {
100:                            bean = pHome.findByPrimaryKey(spk);
101:                            p = bean.getPrice();
102:                        } else if ("set".equals(opType)) {
103:                            bean = pHome.findByPrimaryKey(spk);
104:                            bean.setPrice(2);
105:                        } else if ("findByPk".equals(opType)) {
106:                            bean = pHome.findByPrimaryKey(spk);
107:                        } else if ("findByNumber".equals(opType)) {
108:                            bean = pHome.findByNumber(ipk);
109:                        } else {
110:                            throw new Exception("Invalid operation name ("
111:                                    + opType + ")");
112:                        }
113:                    }
114:                }
115:                // Undo
116:                for (int i = 1; i <= opNb; i++) {
117:                    if ("create".equals(opType)) {
118:                        int ipk = NB_PRODUCTS + i;
119:                        String spk = "p" + ipk;
120:                        pHome.remove(spk);
121:                    } else if ("createmany".equals(opType)) {
122:                        // Nothing to undo
123:                    } else if ("get".equals(opType)) {
124:                        // Nothing to undo
125:                    } else if ("set".equals(opType)) {
126:                        // Nothing to undo
127:                    } else if ("findByPk".equals(opType)) {
128:                        // Nothing to undo
129:                    } else if ("delete".equals(opType)) {
130:                        String spk = "p" + i;
131:                        pHome.create(spk, i, 0);
132:                    }
133:                }
134:            }
135:
136:            /**
137:             * random returns an integer between 0 and max-1
138:             */
139:            private int random(int max) throws RemoteException {
140:                double d = Math.random();
141:                int ret = (int) (max * d);
142:                return ret;
143:            }
144:
145:            public void test_100_create() throws Exception {
146:                manyops(100, "create");
147:            }
148:
149:            public void test_100_get() throws Exception {
150:                manyops(100, "get");
151:            }
152:
153:            public void test_100_set() throws Exception {
154:                manyops(100, "set");
155:            }
156:
157:            public void test_100_findByPk() throws Exception {
158:                manyops(100, "findByPk");
159:            }
160:
161:            public void test_100_findByNumber() throws Exception {
162:                manyops(100, "findByNumber");
163:            }
164:
165:            public void test_100_delete() throws Exception {
166:                manyops(100, "delete");
167:            }
168:
169:            public void test_100_createmany() throws Exception {
170:                manyops(100, "createmany");
171:            }
172:
173:            public void test_250_create() throws Exception {
174:                manyops(250, "create");
175:            }
176:
177:            public void test_250_get() throws Exception {
178:                manyops(250, "get");
179:            }
180:
181:            public void test_250_set() throws Exception {
182:                manyops(250, "set");
183:            }
184:
185:            public void test_250_findByPk() throws Exception {
186:                manyops(250, "findByPk");
187:            }
188:
189:            public void test_250_findByNumber() throws Exception {
190:                manyops(250, "findByNumber");
191:            }
192:
193:            public void test_250_delete() throws Exception {
194:                manyops(100, "delete");
195:            }
196:
197:            public void test_250_createmany() throws Exception {
198:                manyops(250, "createmany");
199:            }
200:
201:            public void test_500_create() throws Exception {
202:                manyops(500, "create");
203:            }
204:
205:            public void test_500_get() throws Exception {
206:                manyops(500, "get");
207:            }
208:
209:            public void test_500_set() throws Exception {
210:                manyops(500, "set");
211:            }
212:
213:            public void test_500_findByPk() throws Exception {
214:                manyops(500, "findByPk");
215:            }
216:
217:            public void test_500_findByNumber() throws Exception {
218:                manyops(500, "findByNumber");
219:            }
220:
221:            public void test_500_delete() throws Exception {
222:                manyops(100, "delete");
223:            }
224:
225:            public void test_500_createmany() throws Exception {
226:                manyops(500, "createmany");
227:            }
228:
229:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.