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


001:        package org.apache.ojb.broker;
002:
003:        /* Copyright 2002-2005 The Apache Software Foundation
004:         *
005:         * Licensed under the Apache License, Version 2.0 (the "License");
006:         * you may not use this file except in compliance with the License.
007:         * You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:
018:        import org.apache.ojb.junit.PBTestCase;
019:
020:        import java.io.Serializable;
021:
022:        /**
023:         * Test case for java.lang.Character/java.lang.String to CHAR/VARCHAR mappings.
024:         *
025:         * @author <a href="mailto:mkalen@apache.org">Martin Kal&eacute;n</a>
026:         * @version $Id: CharacterTest.java,v 1.1.2.3 2005/12/21 22:31:23 tomdz Exp $
027:         * @since 1.0.2
028:         */
029:        public class CharacterTest extends PBTestCase {
030:
031:            public void testJavaCharacterToJdbcCharMapping() {
032:                final Character x = new Character('x');
033:
034:                ObjectWithCharField obj = new ObjectWithCharField();
035:                obj.setCharacterCharField(x);
036:                pbPersist(obj);
037:
038:                broker.clearCache();
039:
040:                Identity oid = new Identity(obj, broker);
041:                ObjectWithCharField dbObj;
042:                assertNotNull(dbObj = (ObjectWithCharField) broker
043:                        .getObjectByIdentity(oid));
044:                assertEquals(obj, dbObj);
045:            }
046:
047:            public void testJavaCharacterToJdbcVarcharMapping() {
048:                final Character x = new Character('x');
049:
050:                ObjectWithCharField obj = new ObjectWithCharField();
051:                obj.setCharacterVarcharField(x);
052:                pbPersist(obj);
053:
054:                broker.clearCache();
055:
056:                Identity oid = new Identity(obj, broker);
057:                ObjectWithCharField dbObj;
058:                assertNotNull(dbObj = (ObjectWithCharField) broker
059:                        .getObjectByIdentity(oid));
060:                assertEquals(obj, dbObj);
061:            }
062:
063:            public void testJavaStringToJdbcCharMapping() {
064:                final String strIn = "12345";
065:
066:                ObjectWithCharField obj = new ObjectWithCharField();
067:                obj.setStringCharField(strIn);
068:                pbPersist(obj);
069:
070:                broker.clearCache();
071:
072:                Identity oid = new Identity(obj, broker);
073:                ObjectWithCharField dbObj;
074:                assertNotNull(dbObj = (ObjectWithCharField) broker
075:                        .getObjectByIdentity(oid));
076:                assertEquals(obj.getId(), dbObj.getId());
077:
078:                // mkalen: different JDBC-drivers do readback of CHAR(x) => java.lang.String differently,
079:                //          Oracle pads String with spaces to exactly x characters
080:                //          hsqldb clears trailing spaces
081:                //          PostgreSQL keeps some(v7)/all(v8) spaces
082:                // We can't assert much here, other than that the start of string is not mutated.
083:                final String strOut;
084:                assertNotNull(strOut = dbObj.getStringCharField());
085:                assertTrue(strOut, strOut.startsWith(strIn));
086:            }
087:
088:            public void testJavaStringToJdbcVarcharMapping() {
089:                final String str = "12345";
090:
091:                ObjectWithCharField obj = new ObjectWithCharField();
092:                obj.setStringVarcharField(str);
093:                pbPersist(obj);
094:
095:                broker.clearCache();
096:
097:                Identity oid = new Identity(obj, broker);
098:                ObjectWithCharField dbObj;
099:                assertNotNull(dbObj = (ObjectWithCharField) broker
100:                        .getObjectByIdentity(oid));
101:                assertEquals(obj, dbObj);
102:            }
103:
104:            public static void main(String[] args) {
105:                String[] testClasses = new String[] { CharacterTest.class
106:                        .getName() };
107:                junit.textui.TestRunner.main(testClasses);
108:            }
109:
110:            public static class ObjectWithCharField implements  Serializable {
111:                private int id;
112:                private Object characterCharField;
113:                private Object characterVarcharField;
114:                private String stringCharField;
115:                private String stringVarcharField;
116:
117:                public ObjectWithCharField() {
118:                }
119:
120:                public int getId() {
121:                    return id;
122:                }
123:
124:                public void setId(int id) {
125:                    this .id = id;
126:                }
127:
128:                public Object getCharacterCharField() {
129:                    return characterCharField;
130:                }
131:
132:                public void setCharacterCharField(Object characterCharField) {
133:                    this .characterCharField = characterCharField;
134:                }
135:
136:                public void setCharacterCharField(Character characterCharField) {
137:                    this .characterCharField = characterCharField;
138:                }
139:
140:                public Object getCharacterVarcharField() {
141:                    return characterVarcharField;
142:                }
143:
144:                public void setCharacterVarcharField(
145:                        Object characterVarcharField) {
146:                    this .characterVarcharField = characterVarcharField;
147:                }
148:
149:                public void setCharacterVarcharField(
150:                        Character characterVarcharField) {
151:                    this .characterVarcharField = characterVarcharField;
152:                }
153:
154:                public String getStringCharField() {
155:                    return stringCharField;
156:                }
157:
158:                public void setStringCharField(String stringCharField) {
159:                    this .stringCharField = stringCharField;
160:                }
161:
162:                public String getStringVarcharField() {
163:                    return stringVarcharField;
164:                }
165:
166:                public void setStringVarcharField(String stringVarcharField) {
167:                    this .stringVarcharField = stringVarcharField;
168:                }
169:
170:                public boolean equals(Object o) {
171:                    if (this  == o)
172:                        return true;
173:                    if (!(o instanceof  ObjectWithCharField))
174:                        return false;
175:
176:                    final ObjectWithCharField objectWithCharField = (ObjectWithCharField) o;
177:
178:                    if (id != objectWithCharField.id)
179:                        return false;
180:                    if (stringCharField != null ? !stringCharField
181:                            .equals(objectWithCharField.stringCharField)
182:                            : objectWithCharField.stringCharField != null)
183:                        return false;
184:                    if (stringVarcharField != null ? !stringVarcharField
185:                            .equals(objectWithCharField.stringVarcharField)
186:                            : objectWithCharField.stringVarcharField != null)
187:                        return false;
188:                    // Special comparison for the Object fields; use toString-representations if != null:
189:                    final String myCharacterCharField = characterCharField != null ? characterCharField
190:                            .toString()
191:                            : null;
192:                    final String myCharacterVarcharField = characterVarcharField != null ? characterVarcharField
193:                            .toString()
194:                            : null;
195:                    final String otherCharacterCharField = objectWithCharField.characterCharField != null ? objectWithCharField.characterCharField
196:                            .toString()
197:                            : null;
198:                    final String otherCharacterVarcharField = objectWithCharField.characterVarcharField != null ? objectWithCharField.characterVarcharField
199:                            .toString()
200:                            : null;
201:                    if (myCharacterCharField != null ? !myCharacterCharField
202:                            .equals(otherCharacterCharField)
203:                            : otherCharacterCharField != null)
204:                        return false;
205:                    if (myCharacterVarcharField != null ? !myCharacterVarcharField
206:                            .equals(otherCharacterVarcharField)
207:                            : otherCharacterVarcharField != null)
208:                        return false;
209:
210:                    return true;
211:                }
212:
213:                public int hashCode() {
214:                    int result;
215:                    result = id;
216:                    result = 29
217:                            * result
218:                            + (characterCharField != null ? characterCharField
219:                                    .hashCode() : 0);
220:                    result = 29
221:                            * result
222:                            + (characterVarcharField != null ? characterVarcharField
223:                                    .hashCode()
224:                                    : 0);
225:                    result = 29
226:                            * result
227:                            + (stringCharField != null ? stringCharField
228:                                    .hashCode() : 0);
229:                    result = 29
230:                            * result
231:                            + (stringVarcharField != null ? stringVarcharField
232:                                    .hashCode() : 0);
233:                    return result;
234:                }
235:
236:                public String toString() {
237:                    return "CharacterTest$ObjectWithCharField (id=" + id
238:                            + ", characterCharField=[" + characterCharField
239:                            + "], characterVarcharField=["
240:                            + characterVarcharField + "], stringCharField=["
241:                            + stringCharField + "], stringVarcharField=["
242:                            + stringVarcharField + "])";
243:                }
244:
245:            }
246:
247:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.