Source Code Cross Referenced for Tutorial1.java in  » Database-ORM » jaxor-3.5 » net » sourceforge » jaxor » example » tutorial » 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 » jaxor 3.5 » net.sourceforge.jaxor.example.tutorial 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Created on 18/08/2003
003:         *
004:         */
005:        package net.sourceforge.jaxor.example.tutorial;
006:
007:        import net.sourceforge.jaxor.EntityNotFoundException;
008:        import net.sourceforge.jaxor.JaxorSession;
009:        import net.sourceforge.jaxor.QueryParams;
010:        import net.sourceforge.jaxor.db.SingleConnectionTransaction;
011:        import net.sourceforge.jaxor.example.Money;
012:
013:        import java.sql.Timestamp;
014:        import java.util.Calendar;
015:
016:        public class Tutorial1 {
017:
018:            public static void main(String[] args) {
019:                System.out
020:                        .println("===========================================================================");
021:                System.out
022:                        .println("                            START OF TUTORIAL ONE");
023:                System.out
024:                        .println("===========================================================================");
025:                prepare();
026:
027:                insertWiggleEmployees();
028:
029:                selectWiggleEmployees();
030:
031:                editWiggleEmployees();
032:
033:                selectWiggleEmployees();
034:
035:                deleteWiggleEmployees();
036:
037:                try {
038:                    selectWiggleEmployees();
039:                } catch (EntityNotFoundException e) {
040:                    System.out
041:                            .println("Oops! We've deleted Jeff so he no longer turns up in unique queries and therefore we get an EntityNotFound exception");
042:                }
043:
044:                PretendPooledHyperDb.INSTANCE.close();
045:
046:                System.out
047:                        .println("===========================================================================");
048:                System.out
049:                        .println("                             END OF TUTORIAL ONE");
050:                System.out
051:                        .println("===========================================================================");
052:            }
053:
054:            /**
055:             *
056:             */
057:            private static void prepare() {
058:                PretendPooledHyperDb.resetDb("hyperdb/simpledb");
059:            }
060:
061:            /**
062:             *
063:             */
064:            private static void insertWiggleEmployees() {
065:                JaxorSession.begin(new SingleConnectionTransaction(
066:                        PretendPooledHyperDb.INSTANCE));
067:                EmployeeEntity greg = EmployeeFinder.newInstance(new Long(1));
068:                greg.setFirstName("Greg");
069:                greg.setLastName("Wiggle");
070:                greg.setSalary(new net.sourceforge.jaxor.example.Money(
071:                        "100000.00"));
072:                greg.setBirthDate(Tutorial1.getTimestamp(16, 1, 1964));
073:
074:                EmployeeEntity anthony = EmployeeFinder
075:                        .newInstance(new Long(2));
076:                anthony.setFirstName("Anthony");
077:                anthony.setLastName("Wiggle");
078:                anthony.setSalary(new net.sourceforge.jaxor.example.Money(
079:                        "200000.00"));
080:                anthony.setBirthDate(Tutorial1.getTimestamp(8, 5, 1964));
081:
082:                EmployeeEntity murray = EmployeeFinder.newInstance(new Long(3));
083:                murray.setFirstName("Murray");
084:                murray.setLastName("Wiggle");
085:                murray.setSalary(new Money("300000.00"));
086:                murray.setBirthDate(Tutorial1.getTimestamp(30, 6, 1964));
087:
088:                EmployeeEntity jeff = EmployeeFinder.newInstance(new Long(4));
089:                jeff.setFirstName("Jeff");
090:                jeff.setLastName("Wiggle");
091:                jeff.setSalary(new Money("400000.00"));
092:                jeff.setBirthDate(Tutorial1.getTimestamp(21, 7, 1964));
093:
094:                JaxorSession.commit();
095:
096:            }
097:
098:            /**
099:             *
100:             */
101:            private static void selectWiggleEmployees() {
102:                /**
103:                 * Shows how to use the queryUnique method. This method is used when you *know* that
104:                 * the query you are executing will return one and only one record.
105:                 */
106:                seperator();
107:                System.out.println("Jeff's employee details\n");
108:
109:                EmployeeEntity jeff = EmployeeFinder.selectByFirstName("Jeff");
110:
111:                /**
112:                 * .. or you could have selected Jeff as such...
113:                 */
114:                jeff = EmployeeFinder.selectByPrimaryKey(jeff.getId());
115:
116:                System.out.println(jeff);
117:                seperator();
118:
119:                /**
120:                 * Shows how to query a list of employees and iterate through the list.
121:                 *
122:                 */
123:                seperator();
124:                System.out.println("The Big Earners\n");
125:
126:                QueryParams bigEarnersParams = new QueryParams();
127:                bigEarnersParams.addLong(new Long(200000));
128:                EmployeeList bigEarners = EmployeeFinder.find(
129:                        "where salary > ?", bigEarnersParams);
130:                for (EmployeeIterator iter = bigEarners.iterator(); iter
131:                        .hasNext();) {
132:                    EmployeeEntity currentEmployee = iter.next();
133:                    System.out.println(currentEmployee.getFirstName()
134:                            + "\t\t\t" + currentEmployee.getSalary());
135:                }
136:                seperator();
137:            }
138:
139:            /**
140:             *
141:             */
142:            private static void editWiggleEmployees() {
143:                JaxorSession.begin(new SingleConnectionTransaction(
144:                        PretendPooledHyperDb.INSTANCE));
145:
146:                System.out.println("Jeff's employee details\n");
147:                EmployeeEntity jeff = EmployeeFinder.selectByFirstName("Jeff");
148:                jeff.setSalary(new Money("100000.00"));
149:
150:                JaxorSession.commit();
151:            }
152:
153:            /**
154:             *
155:             */
156:            private static void deleteWiggleEmployees() {
157:                JaxorSession.begin(new SingleConnectionTransaction(
158:                        PretendPooledHyperDb.INSTANCE));
159:
160:                EmployeeEntity jeff = EmployeeFinder.selectByFirstName("Jeff");
161:                jeff.registerDelete();
162:
163:                JaxorSession.commit();
164:            }
165:
166:            /**
167:             *
168:             */
169:            private static void seperator() {
170:                System.out
171:                        .println("-----------------------------------------------------");
172:            }
173:
174:            private static Timestamp getTimestamp(int date, int month, int year) {
175:                Calendar c = Calendar.getInstance();
176:                c.clear();
177:                c.set(Calendar.DATE, date);
178:                c.set(Calendar.MONTH, month - 1);
179:                c.set(Calendar.YEAR, year);
180:                return new Timestamp(c.getTime().getTime());
181:            }
182:
183:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.