Source Code Cross Referenced for DataTypesTest.java in  » Database-ORM » SimpleORM » simpleorm » examples » 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 » SimpleORM » simpleorm.examples 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package simpleorm.examples;
002:
003:        import simpleorm.core.*;
004:
005:        /** This test class uses all data types including Dates and Times.
006:         What makes it hard is the inconsistent mapping by different
007:         database vendors to the SQL-92 data types.*/
008:        public class DataTypesTest implements  SConstants {
009:
010:            public static class DataTypes extends SRecordInstance {
011:
012:                public static final SRecordMeta meta = new SRecordMeta(
013:                        DataTypes.class, "XX_DATA_TYPES");
014:
015:                public static final SFieldString DATA_ID = new SFieldString(
016:                        meta, "DATA_ID", 20, SFD_PRIMARY_KEY, SFD_STRING_CHAR);
017:                // CHAR types typically have COBOL style trailing spaces.
018:
019:                public static final SFieldString NAME = new SFieldString(meta,
020:                        "NAME", 20);
021:
022:                public static final SFieldString EMPTYSTR = new SFieldString(
023:                        meta, "EMPTYSTR", 20);
024:
025:                public static final SFieldInteger ANINT = new SFieldInteger(
026:                        meta, "ANINT");
027:
028:                public static final SFieldLong ALONG = new SFieldLong(meta,
029:                        "ALONG");
030:
031:                public static final SFieldTimestamp TSTAMP = new SFieldTimestamp(
032:                        meta, "TSTAMP");
033:
034:                public static final SFieldDate ADATE = new SFieldDate(meta,
035:                        "ADATE");
036:
037:                public static final SFieldTime ATIME = new SFieldTime(meta,
038:                        "ATIME");
039:
040:                public static final SFieldObject TSTAMP_OBJ = new SFieldObject(
041:                        meta, "TSTAMP_OBJ", SDATA_TYPE.pvalue("TIMESTAMP"));
042:                // for Create Table
043:
044:                public static final SFieldBigDecimal ADECIMAL = new SFieldBigDecimal(
045:                        meta, "ADECIMAL", 22, 4);
046:                // ie. 123456789012345678.3333, more precission than double.
047:
048:                public static final SFieldBytes ABYTES = new SFieldBytes(meta,
049:                        "ABYTES", 100);
050:
051:                public static final SFieldBooleanCharYN YNBOOL = new SFieldBooleanCharYN(
052:                        meta, "YNBOOL");
053:
054:                public SRecordMeta getMeta() {
055:                    return meta;
056:                }; // specializes abstract method
057:            }
058:
059:            public static void main(String[] argv) throws Exception {
060:                TestUte.initializeTest(DataTypesTest.class); // Look at this code
061:                try {
062:                    testInit();
063:                    dataTest();
064:                } finally {
065:                    SConnection.detachAndClose();
066:                }
067:            }
068:
069:            /** Prepare for tests, Delete old data. */
070:            static void testInit() throws Exception {
071:                SConnection.begin();
072:                /// Delete any old data from a previous run.
073:                try {
074:                    SConnection.rawUpdateDB("DROP TABLE XX_DATA_TYPES");
075:                } catch (SException.JDBC ex) {
076:                }
077:                ; // Tables may not exist.
078:                SConnection.rawUpdateDB(DataTypes.meta.createTableSQL());
079:                SConnection.commit();
080:            }
081:
082:            static void dataTest() throws Exception {
083:                SConnection.begin();
084:
085:                SDataLoader dataDL = new SDataLoader(DataTypes.meta);
086:
087:                long now = System.currentTimeMillis();
088:                dataDL.insertRecords(new Object[][] { { "100", "Trailing  ",
089:                        "", "2000000000", "123456789012345678",
090:                        new java.sql.Timestamp(now), new java.util.Date(now),
091:                        new java.sql.Time(now), new java.sql.Timestamp(now),
092:                        "123456789012345678.3333", new byte[] { 1, 3, 5, 7 },
093:                        Boolean.TRUE } });
094:
095:                SConnection.commit();
096:                SConnection.begin();
097:
098:                DataTypes dt = (DataTypes) DataTypes.meta
099:                        .findOrCreate("100                 ");
100:                // ## Apparantly need trailing spaces for Oracle ??  Needs more investigation.
101:
102:                java.sql.Timestamp nowTS = dt.getTimestamp(DataTypes.TSTAMP);
103:                // The following is necessary because nowTS.getTime() is rounded
104:                // to 1 second.  
105:                long now2 = nowTS.getTime() / 1000 * 1000 // Sometimes (HSql) getTime is in milliseconds, not seconds.
106:                        + nowTS.getNanos() / 1000000;
107:
108:                dt.setDate(dt.ADATE, new java.util.Date()); // ie. not java.sql.Date()
109:
110:                SLog.slog.message("Retrieved Name '"
111:                        + dt.getObject(DataTypes.NAME)
112:                        + "' TStamp "
113:                        + dt
114:                        + nowTS
115:                        + "("
116:                        + nowTS.getTime()
117:                        + ", "
118:                        + nowTS.getNanos()
119:                        + "<-"
120:                        + now
121:                        + ") "
122:                        + new java.util.Date(now)
123:                        + " "
124:                        + now
125:                        + " "
126:                        + new java.util.Date(now2)
127:                        + " "
128:                        + now2
129:                        + ", Date "
130:                        + dt.getDate(DataTypes.ADATE)
131:                        + ", Time "
132:                        + dt.getTime(DataTypes.ATIME)
133:                        + ", Object "
134:                        + dt.getObject(DataTypes.TSTAMP_OBJ).getClass()
135:                                .getName() + ", BDec "
136:                        + dt.getBigDecimal(DataTypes.ADECIMAL) + ", byte "
137:                        + dt.getBytes(DataTypes.ABYTES)[2] + ", YNBool "
138:                        + dt.getBoolean(DataTypes.YNBOOL));
139:
140:                TestUte.assertTrue(dt.getObject(DataTypes.NAME).toString()
141:                        .equals("Trailing  "));
142:                TestUte.assertTrue(dt.getString(DataTypes.NAME).equals(
143:                        "Trailing")); // trimed
144:                //TestUte.assertTrue(dt.getString(DataTypes.EMPTYSTR).equals(""));
145:                TestUte.assertTrue(dt.isNull(DataTypes.EMPTYSTR) // Oracle returns null!, '' === NULL!
146:                        || dt.getString(DataTypes.EMPTYSTR).equals(""));
147:
148:                TestUte.assertEqual("" + (now2 + 50) / 100, "" + (now + 50)
149:                        / 100);
150:                // ## Postgresql seems to loose the last few digits precission!  
151:                // HSQL works exactly.  Other dbs unknown (JDBC/DB bug).
152:                TestUte.assertTrue(dt.getInt(DataTypes.ANINT) == 2000000000);
153:                TestUte
154:                        .assertTrue(dt.getLong(DataTypes.ALONG) == 123456789012345678L);
155:                TestUte.assertTrue(dt.getBigDecimal(DataTypes.ADECIMAL).equals(
156:                        new java.math.BigDecimal("123456789012345678.3333"))); // Precisely
157:                TestUte.assertEqual(dt.getBytes(DataTypes.ABYTES)[2] + "", "5");
158:
159:                TestUte.assertTrue(dt.getBoolean(DataTypes.YNBOOL));
160:                SConnection.commit();
161:            }
162:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.