Source Code Cross Referenced for TestFieldRange2.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:         * TestFieldRange.java
003:         *
004:         * Created on October 12, 2006, 10:14 AM
005:         *
006:         * To change this template, choose Tools | Template Manager
007:         * and open the template in the editor.
008:         */
009:        /*
010:         * Licensed to the Apache Software Foundation (ASF) under one
011:         * or more contributor license agreements.  See the NOTICE file
012:         * distributed with this work for additional information
013:         * regarding copyright ownership.  The ASF licenses this file
014:         * to you under the Apache License, Version 2.0 (the
015:         * "License"); you may not use this file except in compliance
016:         * with the License.  You may obtain a copy of the License at
017:         *
018:         * http://www.apache.org/licenses/LICENSE-2.0
019:         *
020:         * Unless required by applicable law or agreed to in writing,
021:         * software distributed under the License is distributed on an
022:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
023:         * KIND, either express or implied.  See the License for the
024:         * specific language governing permissions and limitations
025:         * under the License.    
026:         */
027:        package org.apache.openjpa.persistence.kernel;
028:
029:        import java.io.Serializable;
030:        import java.math.BigDecimal;
031:        import java.math.BigInteger;
032:        import java.util.Date;
033:
034:        import org.apache.openjpa.persistence.kernel.common.apps.AllFieldTypesTest;
035:        import junit.framework.AssertionFailedError;
036:
037:        import org.apache.openjpa.persistence.OpenJPAEntityManager;
038:
039:        public class TestFieldRange2 extends BaseKernelTest {
040:
041:            protected static String RANDOM_STRING = "This is my test String with all "
042:                    + "kinds of wierd characters: "
043:                    + "!@@#$\\%^&\"*()-=\\|\"\"\"\"\"+_/?.>,<~`"
044:                    + "'''''''''''\\\\\\\\\\\\\\\\\\\\\\\\\\\\"
045:                    + "''''''''''''\\\\\\\\\\\\\\\\\\\\\\\\\\\\"
046:                    + "!@@#$\\%^&\"*()-=\\|+_/?.>,<~`";
047:
048:            /**
049:             * Creates a new instance of TestFieldRange
050:             */
051:            public TestFieldRange2() {
052:            }
053:
054:            public TestFieldRange2(String name) {
055:                super (name);
056:            }
057:
058:            public void setUp() throws Exception {
059:                super .setUp();
060:                deleteAll(AllFieldTypesTest.class);
061:            }
062:
063:            public void testSaveState() throws Exception {
064:                allFieldSaveState((int) 259645, (short) 50849,
065:                        (long) 2349847982L, (float) 43273423.0234723F,
066:                        (double) 34678.02384723D, (byte) -120, (boolean) true,
067:                        (char) '%', (Date) new Date(),
068:                        (Serializable) new StringBuffer(5000),
069:                        (String) RANDOM_STRING, randomBigInteger(),
070:                        randomBigDecimal());
071:            }
072:
073:            private void dateTest(long l) throws Exception {
074:                Date d = new Date(l);
075:
076:                allFieldSaveState((int) 10, (short) 10, (long) 10, (float) 0,
077:                        (double) 0, (byte) 10, (boolean) true, (char) 'x',
078:                        (Date) d, (Serializable) new StringBuffer(10),
079:                        (String) RANDOM_STRING, new BigInteger("0"),
080:                        new BigDecimal("0"));
081:            }
082:
083:            public void allFieldSaveState(int testint, short testshort,
084:                    long testlong, float testfloat, double testdouble,
085:                    byte testbyte, boolean testboolean, char testchar,
086:                    Date testDate, Serializable testObject, String testString,
087:                    BigInteger testBigInteger, BigDecimal testBigDecimal)
088:                    throws Exception {
089:                try {
090:                    allFieldSaveStateInternal(testint, testshort, testlong,
091:                            testfloat, testdouble, testbyte, testboolean,
092:                            testchar, testDate, testObject, testString,
093:                            testBigInteger, testBigDecimal);
094:                } finally {
095:                    try {
096:                        // make *sure* we do not leave a transaction open
097:                        rollbackTx(getPM(true, false));
098:                    } catch (Throwable t) {
099:
100:                    }
101:                }
102:            }
103:
104:            public void allFieldSaveStateInternal(int testint, short testshort,
105:                    long testlong, float testfloat, double testdouble,
106:                    byte testbyte, boolean testboolean, char testchar,
107:                    Date testDate, Serializable testObject, String testString,
108:                    BigInteger testBigInteger, BigDecimal testBigDecimal)
109:                    throws Exception {
110:                OpenJPAEntityManager pm = getPM(true, false);
111:                startTx(pm);
112:
113:                AllFieldTypesTest test = new AllFieldTypesTest();
114:                //pm.persist(test);
115:                //Object testID = pm.getObjectId(test);
116:
117:                test.setTestint(testint);
118:                test.setTestlong(testlong);
119:                test.setTestdouble(testdouble);
120:                test.setTestshort(testshort);
121:                test.setTestfloat(testfloat);
122:                test.setTestbyte(testbyte);
123:                test.setTestboolean(testboolean);
124:                test.setTestchar(testchar);
125:                test.setTestString(testString);
126:                test.setTestDate(testDate);
127:                test.setTestObject(testObject);
128:                test.setTestBigInteger(testBigInteger);
129:                test.setTestBigDecimal(testBigDecimal);
130:
131:                pm.persist(test);
132:                Object testID = pm.getObjectId(test);
133:
134:                try {
135:                    endTx(pm);
136:                } catch (Exception e) {
137:                    if (e instanceof  Exception
138:                            && ((Exception) e).getMessage().indexOf(
139:                                    "Maximum length is 8000") != -1) {
140:                        bug(5, e, "SQLServer cannot deal"
141:                                + " with numbers with more than 8000 digits");
142:                    } else {
143:                        throw e;
144:                    }
145:                }
146:
147:                endEm(pm);
148:
149:                //assertPersistent (test, true, false, false, false);
150:
151:                pm = getPM(true, false);
152:                startTx(pm);
153:
154:                AllFieldTypesTest retrievedObject = (AllFieldTypesTest) pm
155:                        .find(AllFieldTypesTest.class, testID);
156:
157:                assertEquals("Field type int", testint, retrievedObject
158:                        .getTestint());
159:                assertEquals("Field type short", testshort, retrievedObject
160:                        .getTestshort());
161:                assertEquals("Field type boolean", testboolean, retrievedObject
162:                        .getTestboolean());
163:                assertEquals("Field type char", testchar, retrievedObject
164:                        .getTestchar());
165:                assertEquals("Field type long", testlong, retrievedObject
166:                        .getTestlong());
167:
168:                assertEquals("Field type byte", testbyte, retrievedObject
169:                        .getTestbyte());
170:                assertEquals("Field type String", testString, retrievedObject
171:                        .getTestString());
172:
173:                int i1 = (int) (testDate.getTime() / 1000);
174:                int i2 = (int) (retrievedObject.getTestDate().getTime() / 1000);
175:
176:                System.out.println("i1 : " + i1 + "\ni2 : " + i2);
177:                assertEquals("Field type Date: " + testDate.getTime() + "!="
178:                        + retrievedObject.getTestDate().getTime() + "["
179:                        + new Date(testDate.getTime()) + " != "
180:                        + new Date(retrievedObject.getTestDate().getTime())
181:                        + "]", (int) (testDate.getTime() / 1000),
182:                        (int) (retrievedObject.getTestDate().getTime() / 1000));
183:                //assertEquals ("Field type Object", testObject,
184:                //retrievedObject.getTestObject ());
185:                assertEquals("Field type BigInteger", testBigInteger,
186:                        retrievedObject.getTestBigInteger());
187:
188:                try {
189:                    assertEquals("Field type BigDecimal (BigInteger part)",
190:                            testBigDecimal.toBigInteger(), retrievedObject
191:                                    .getTestBigDecimal().toBigInteger());
192:
193:                    assertEquals("Field type BigDecimal", testBigDecimal,
194:                            retrievedObject.getTestBigDecimal());
195:
196:                    assertEquals("Field type float", testfloat, retrievedObject
197:                            .getTestfloat(), 0.01f);
198:                    assertEquals("Field type double", testdouble,
199:                            retrievedObject.getTestdouble(), 0.01d);
200:                } catch (AssertionFailedError afe) {
201:                    bug(3, afe,
202:                            "Doubles and Floats lose precision in some data stores");
203:                }
204:
205:                rollbackTx(pm);
206:            }
207:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.