Source Code Cross Referenced for FieldConversionTest.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:        import junit.framework.TestCase;
004:        import org.apache.commons.lang.builder.ToStringBuilder;
005:        import org.apache.commons.lang.builder.ToStringStyle;
006:        import org.apache.ojb.broker.accesslayer.conversions.ConversionException;
007:        import org.apache.ojb.broker.accesslayer.conversions.FieldConversion;
008:
009:        import java.io.Serializable;
010:
011:        /**
012:         * Test case to check the field conversion.
013:         *
014:         * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
015:         * @version $Id: FieldConversionTest.java,v 1.2.4.1 2005/12/13 18:18:25 arminw Exp $
016:         */
017:        public class FieldConversionTest extends TestCase {
018:            private PersistenceBroker broker;
019:
020:            public static void main(String[] args) {
021:                String[] arr = { FieldConversionTest.class.getName() };
022:                junit.textui.TestRunner.main(arr);
023:            }
024:
025:            /**
026:             * Insert the method's description here.
027:             * Creation date: (06.12.2000 21:58:53)
028:             */
029:            public void setUp() throws PBFactoryException {
030:                broker = PersistenceBrokerFactory.defaultPersistenceBroker();
031:            }
032:
033:            /**
034:             * Insert the method's description here.
035:             * Creation date: (06.12.2000 21:59:14)
036:             */
037:            public void tearDown() {
038:                try {
039:                    broker.clearCache();
040:                    broker.close();
041:                } catch (PersistenceBrokerException e) {
042:                }
043:            }
044:
045:            public void testConversion() {
046:                int id = (int) (System.currentTimeMillis() % Integer.MAX_VALUE);
047:                ConversionVO vo = new ConversionVO(null, new ConversionId(
048:                        new Integer(id)), null, new ConversionId(new Integer(
049:                        id + 1)));
050:                broker.beginTransaction();
051:                broker.store(vo);
052:                broker.commitTransaction();
053:
054:                Identity identity = new Identity(vo, broker);
055:                broker.clearCache();
056:                ConversionVO find_vo = (ConversionVO) broker
057:                        .getObjectByIdentity(identity);
058:            }
059:
060:            public static class FieldConversionConversionIdToInteger implements 
061:                    FieldConversion {
062:                public Object javaToSql(Object source)
063:                        throws ConversionException {
064:                    if (!(source instanceof  ConversionId)) {
065:                        throw new ConversionException(
066:                                "Wrong java field type when java-->sql, expected "
067:                                        + ConversionId.class.getClass()
068:                                        + ", found " + source.getClass());
069:                    }
070:                    return ((ConversionId) source).getConversionId();
071:                }
072:
073:                public Object sqlToJava(Object source)
074:                        throws ConversionException {
075:                    if (!(source instanceof  Integer)) {
076:                        throw new ConversionException(
077:                                "Wrong java field type when java-->sql, expected java.lang.Integer, found "
078:                                        + source.getClass());
079:                    }
080:                    return new ConversionId((Integer) source);
081:                }
082:            }
083:
084:            public static class FieldConversionLongToInteger implements 
085:                    FieldConversion {
086:                public Object javaToSql(Object source)
087:                        throws ConversionException {
088:                    if (source == null)
089:                        return null;
090:                    if (!(source instanceof  Long)) {
091:                        throw new ConversionException(
092:                                "Wrong java field type when java-->sql, expected java.lang.Long, found "
093:                                        + source.getClass());
094:                    }
095:                    return new Integer(((Long) source).intValue());
096:                }
097:
098:                public Object sqlToJava(Object source)
099:                        throws ConversionException {
100:                    if (source == null)
101:                        return null;
102:                    if (!(source instanceof  Integer)) {
103:                        throw new ConversionException(
104:                                "Wrong java field type when java-->sql, expected java.lang.Integer, found "
105:                                        + source.getClass());
106:                    }
107:                    return new Long(((Integer) source).longValue());
108:                }
109:            }
110:
111:            public static class ConversionId implements  Serializable {
112:                private Integer conversionId;
113:
114:                public ConversionId(Integer conversionId) {
115:                    this .conversionId = conversionId;
116:                }
117:
118:                public Integer getConversionId() {
119:                    return conversionId;
120:                }
121:
122:                public void setConversionId(Integer conversionId) {
123:                    this .conversionId = conversionId;
124:                }
125:
126:                public String toString() {
127:                    return new ToStringBuilder(this ,
128:                            ToStringStyle.DEFAULT_STYLE).append("conversionId",
129:                            conversionId).toString();
130:                }
131:            }
132:
133:            public static class ConversionVO implements  Serializable {
134:                Long pkWithAutoIncrement;
135:                ConversionId pkWithoutAutoIncrement;
136:                Long normalWithAutoIncrement;
137:                ConversionId normalWithoutAutoIncrement;
138:
139:                public ConversionVO() {
140:                }
141:
142:                public ConversionVO(Long pkWithAutoIncrement,
143:                        ConversionId pkWithoutAutoIncrement,
144:                        Long normalWithAutoIncrement,
145:                        ConversionId normalWithoutAutoIncrement) {
146:                    this .pkWithAutoIncrement = pkWithAutoIncrement;
147:                    this .pkWithoutAutoIncrement = pkWithoutAutoIncrement;
148:                    this .normalWithAutoIncrement = normalWithAutoIncrement;
149:                    this .normalWithoutAutoIncrement = normalWithoutAutoIncrement;
150:                }
151:
152:                public String toString() {
153:                    return new ToStringBuilder(this ,
154:                            ToStringStyle.MULTI_LINE_STYLE).append(
155:                            "pkWithAutoIncrement", pkWithAutoIncrement).append(
156:                            "pkWithoutAutoIncrement", pkWithoutAutoIncrement)
157:                            .append("normalWithAutoIncrement",
158:                                    normalWithAutoIncrement).append(
159:                                    "normalWithoutAutoIncrement",
160:                                    normalWithoutAutoIncrement).toString();
161:                }
162:
163:                public Long getPkWithAutoIncrement() {
164:                    return pkWithAutoIncrement;
165:                }
166:
167:                public void setPkWithAutoIncrement(Long pkWithAutoIncrement) {
168:                    this .pkWithAutoIncrement = pkWithAutoIncrement;
169:                }
170:
171:                public ConversionId getPkWithoutAutoIncrement() {
172:                    return pkWithoutAutoIncrement;
173:                }
174:
175:                public void setPkWithoutAutoIncrement(
176:                        ConversionId pkWithoutAutoIncrement) {
177:                    this .pkWithoutAutoIncrement = pkWithoutAutoIncrement;
178:                }
179:
180:                public Long getNormalWithAutoIncrement() {
181:                    return normalWithAutoIncrement;
182:                }
183:
184:                public void setNormalWithAutoIncrement(
185:                        Long normalWithAutoIncrement) {
186:                    this .normalWithAutoIncrement = normalWithAutoIncrement;
187:                }
188:
189:                public ConversionId getNormalWithoutAutoIncrement() {
190:                    return normalWithoutAutoIncrement;
191:                }
192:
193:                public void setNormalWithoutAutoIncrement(
194:                        ConversionId normalWithoutAutoIncrement) {
195:                    this.normalWithoutAutoIncrement = normalWithoutAutoIncrement;
196:                }
197:            }
198:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.