Source Code Cross Referenced for PerformancePBTest.java in  » Database-ORM » db-ojb » org » apache » ojb » compare » 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 » Database ORM » db ojb » org.apache.ojb.compare 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.apache.ojb.compare;
002:
003:        import java.util.Iterator;
004:
005:        import org.apache.ojb.broker.Identity;
006:        import org.apache.ojb.broker.PersistenceBrokerException;
007:        import org.apache.ojb.broker.query.Criteria;
008:        import org.apache.ojb.broker.query.Query;
009:        import org.apache.ojb.broker.query.QueryByCriteria;
010:        import org.apache.ojb.broker.util.ObjectModification;
011:
012:        /**
013:         * This TestCase contains the OJB single-threaded performance benchmarks for the
014:         * PersistenceBroker-API.
015:         *
016:         * @author Thomas Mahler
017:         */
018:        public class PerformancePBTest extends PerformanceBaseTest {
019:            public PerformancePBTest(String name) {
020:                super (name);
021:                setNameOfTest("Test for PB-api");
022:            }
023:
024:            /**
025:             * launches the TestCase.
026:             * The number of Objects to work with and the number of iterations
027:             * to be performed can be adjusted by setting them as commandline parameters.
028:             *
029:             * @param args the String[] holding the commandline parameters.
030:             */
031:            public static void main(String[] args) {
032:                if (args.length > 0) {
033:                    articleCount = Integer.parseInt(args[0]);
034:                }
035:                if (args.length > 1) {
036:                    iterations = Integer.parseInt(args[1]);
037:                }
038:
039:                String[] arr = { PerformancePBTest.class.getName() };
040:                junit.textui.TestRunner.main(arr);
041:            }
042:
043:            public void testBenchmark() throws Exception {
044:                super .testBenchmark();
045:            }
046:
047:            /**
048:             * deletes all PerformanceArticle created by <code>insertNewArticles</code>.
049:             */
050:            protected void deleteArticles() throws PersistenceBrokerException {
051:                long start = System.currentTimeMillis();
052:                broker.beginTransaction();
053:                for (int i = 0; i < articleCount; i++) {
054:                    broker.delete(arr[i]);
055:                }
056:                broker.commitTransaction();
057:                long stop = System.currentTimeMillis();
058:                logger.info("deleting " + articleCount + " Objects: "
059:                        + (stop - start) + " msec");
060:            }
061:
062:            /**
063:             * create new PerformanceArticle objects and insert them into the RDBMS.
064:             * The number of objects to create is defined by <code>articleCount</code>.
065:             */
066:            protected void insertNewArticles()
067:                    throws PersistenceBrokerException {
068:                long start = System.currentTimeMillis();
069:                broker.beginTransaction();
070:                for (int i = 0; i < articleCount; i++) {
071:                    broker.store(arr[i], ObjectModification.INSERT);
072:                }
073:                broker.commitTransaction();
074:                long stop = System.currentTimeMillis();
075:                logger.info("inserting " + articleCount + " Objects: "
076:                        + (stop - start) + " msec");
077:
078:            }
079:
080:            /**
081:             * read in all the PerformanceArticles from the RDBMS that have
082:             * been inserted by <code>insertNewArticles()</code>.
083:             * The lookup is done one by one, that is: a primary key based lookup is used.
084:             */
085:            protected void readArticles() throws PersistenceBrokerException {
086:                long start = System.currentTimeMillis();
087:                broker.beginTransaction();
088:                for (int i = 0; i < articleCount; i++) {
089:                    Identity oid = broker.serviceIdentity().buildIdentity(
090:                            PerformanceArticle.class, arr[i].getArticleId());
091:                    broker.getObjectByIdentity(oid);
092:                }
093:                broker.commitTransaction();
094:                long stop = System.currentTimeMillis();
095:                logger.info("querying " + articleCount + " Objects: "
096:                        + (stop - start) + " msec");
097:
098:            }
099:
100:            /**
101:             * read in all the PerformanceArticles from the RDBMS that have
102:             * been inserted by <code>insertNewArticles()</code>.
103:             * The lookup is done with a cursor fetch,
104:             * that is: a between Statement is used to select all inserted PerformanceArticles
105:             * and Objects are read in by fetching from the cursor (JDBC ResultSet).
106:             */
107:            protected void readArticlesByCursor()
108:                    throws PersistenceBrokerException
109:
110:            {
111:                broker.clearCache();
112:                Criteria c = new Criteria();
113:                c.addBetween("articleId", new Integer(offsetId), new Integer(
114:                        offsetId + articleCount));
115:                Query q = new QueryByCriteria(PerformanceArticle.class, c);
116:
117:                long start = System.currentTimeMillis();
118:                Iterator iter = broker.getIteratorByQuery(q);
119:                int fetchCount = 0;
120:                while (iter.hasNext()) {
121:                    fetchCount++;
122:                    iter.next();
123:                }
124:                long stop = System.currentTimeMillis();
125:                logger.info("fetching " + fetchCount + " Objects: "
126:                        + (stop - start) + " msec");
127:
128:            }
129:
130:            /**
131:             * updates all PerformanceArticles inserted by <code>insertNewArticles()</code>.
132:             * All objects are modified and changes are written to the RDBMS with an UPDATE.
133:             */
134:            protected void updateExistingArticles()
135:                    throws PersistenceBrokerException {
136:                // update all objects
137:                for (int i = 0; i < articleCount; i++) {
138:                    arr[i].setPrice(arr[i].getPrice() * 1.95583);
139:                }
140:
141:                long start = System.currentTimeMillis();
142:                broker.beginTransaction();
143:                for (int i = 0; i < articleCount; i++) {
144:                    broker.store(arr[i], ObjectModification.UPDATE);
145:                }
146:                broker.commitTransaction();
147:                long stop = System.currentTimeMillis();
148:                logger.info("updating " + articleCount + " Objects: "
149:                        + (stop - start) + " msec");
150:            }
151:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.