Source Code Cross Referenced for TestBigDecimals.java in  » Database-ORM » openjpa » org » apache » openjpa » persistence » kernel » 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 » openjpa » org.apache.openjpa.persistence.kernel 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * TestBigDecimals.java
003:         *
004:         * Created on October 9, 2006, 6:07 PM
005:         *
006:         * To change this template, choose Tools | Template Manager
007:         * and open the template in the editor.
008:         */
009:
010:        /*
011:         * Licensed to the Apache Software Foundation (ASF) under one
012:         * or more contributor license agreements.  See the NOTICE file
013:         * distributed with this work for additional information
014:         * regarding copyright ownership.  The ASF licenses this file
015:         * to you under the Apache License, Version 2.0 (the
016:         * "License"); you may not use this file except in compliance
017:         * with the License.  You may obtain a copy of the License at
018:         *
019:         * http://www.apache.org/licenses/LICENSE-2.0
020:         *
021:         * Unless required by applicable law or agreed to in writing,
022:         * software distributed under the License is distributed on an
023:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
024:         * KIND, either express or implied.  See the License for the
025:         * specific language governing permissions and limitations
026:         * under the License.    
027:         */
028:        package org.apache.openjpa.persistence.kernel;
029:
030:        import java.math.BigDecimal;
031:
032:        import org.apache.openjpa.persistence.kernel.common.apps.AllFieldTypesTest;
033:        import junit.framework.AssertionFailedError;
034:
035:        import org.apache.openjpa.persistence.OpenJPAEntityManager;
036:
037:        public class TestBigDecimals extends BaseKernelTest {
038:
039:            /**
040:             * Creates a new instance of TestBigDecimals
041:             */
042:            public TestBigDecimals() {
043:            }
044:
045:            public TestBigDecimals(String name) {
046:                super (name);
047:            }
048:
049:            public void testBigDecimalDataIntegrity() throws Exception {
050:                try {
051:                    BigDecimal bd = new BigDecimal(Math.random() * 10000000
052:                            + "");
053:                    bd = bd.setScale(100);
054:                    for (int i = 0; i < 50; i++) {
055:                        bd = bd.movePointLeft(1);
056:                        bigDecimalTest(bd);
057:                    }
058:                } catch (AssertionFailedError e) {
059:                    bug(3, e, "Precision loss for BigDecimals");
060:                }
061:            }
062:
063:            //    FixMe aokeke: Passes but takes a long time --commenting for resource sake
064:            //    public void testBigBigDecimals()
065:            //        throws Exception {
066:            //        try {
067:            //            BigDecimal bd = new BigDecimal("1234567890."
068:            //                + "12345678901234567890123456789012345678901234567890"
069:            //                + "12345678901234567890123456789012345678901234567890");
070:            //
071:            //            bigDecimalTest(bd);
072:            //        } catch (AssertionFailedError e) {
073:            //            bug(3, e, "Precision loss for BigDecimals");
074:            //        }
075:            //    }
076:
077:            public void bigDecimalTest(final BigDecimal bd) {
078:                OpenJPAEntityManager pm = null, pm2 = null;
079:
080:                try {
081:                    pm = getPM();
082:                    startTx(pm);
083:                    AllFieldTypesTest aftt = new AllFieldTypesTest();
084:                    aftt.setTestBigDecimal(bd);
085:                    pm.persist(aftt);
086:                    endTx(pm);
087:                    Object id = pm.getObjectId(aftt);
088:                    pm.evict(aftt);
089:
090:                    pm2 = getPM();
091:                    startTx(pm);
092:                    AllFieldTypesTest aftt2 = (AllFieldTypesTest) pm2
093:                            .getObjectId(id);
094:
095:                    // why wouldn't they be two different objects?
096:                    assertTrue("identitcal field values", bd != aftt2
097:                            .getTestBigDecimal());
098:
099:                    // this should always succeed
100:                    assertEquals(bd, aftt2.getTestBigDecimal().setScale(
101:                            bd.scale()));
102:
103:                    // this will fail if we are losing scale
104:                    assertEquals(bd, aftt2.getTestBigDecimal());
105:
106:                    rollbackTx(pm);
107:                } catch (Throwable afe) {
108:                    bug(3, afe, "floating point precision loss");
109:                } finally {
110:                    if (pm != null) {
111:                        //if (pm.getTransaction().isActive())
112:                        //rollbackTx(pm,());
113:                        endEm(pm);
114:                    }
115:
116:                    if (pm2 != null) {
117:                        //if (pm2.getTransaction().isActive())
118:                        //rollbackTx(pm2,());
119:                        //pm2.close();
120:                        endEm(pm2);
121:                    }
122:                }
123:            }
124:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.