Source Code Cross Referenced for ProductFactory.java in  » Database-ORM » ProjectJulp » org » julp » 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 » ProjectJulp » org.julp.examples 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.julp.examples;
002:
003:        import java.util.*;
004:        import org.julp.*;
005:        import java.sql.*;
006:
007:        public class ProductFactory extends org.julp.DomainObjectFactory
008:                implements  java.io.Serializable, Cloneable {
009:
010:            public ProductFactory() {
011:                this .setRequestor(Product.class);
012:                /* IT IS NOT NESSESARY TO LOAD MAPPINGS THIS WAY, COULD BE ANYTHING: XML, JNDI, DATABASE, ETC... */
013:                setMapping(loadMappings("Product.properties"));
014:                sqlMap = loadMappings("Product.sql");
015:            }
016:
017:            protected Properties sqlMap = null;
018:
019:            public Properties loadMappings(String path) {
020:                java.io.InputStream inStream = null;
021:                Properties props = new Properties();
022:                try {
023:                    inStream = this .getClass().getResourceAsStream(path);
024:                    props.load(inStream);
025:                } catch (java.io.IOException ioe) {
026:                    throw new RuntimeException(ioe);
027:                } finally {
028:                    try {
029:                        inStream.close();
030:                    } catch (java.io.IOException ioe) {
031:                        throw new RuntimeException(ioe);
032:                    }
033:                }
034:                return props;
035:            }
036:
037:            public int findAllProducts() {
038:                int records = 0;
039:                try {
040:                    records = this .load(this .dbServices.getResultSet(sqlMap
041:                            .getProperty("findAllProducts")));
042:                    printAllProducts();
043:                } catch (SQLException sqle) {
044:                    throw new RuntimeException(sqle);
045:                }
046:                return records;
047:            }
048:
049:            public void createAndStoreProductsLater() {
050:                this .setGenerateSQLOnly(true);
051:                int records = findAllProducts();
052:                Product product = new Product();
053:                product.setProductId(new Integer(records + 1)); // this is NOT proper way to genarate id !!!
054:                product.setName("Zaurus SL-5600");
055:                product.setPrice(299.98);
056:                product.setComments("Good deal!");
057:                this .create(product);
058:                System.out.println("\n=============== Created product: "
059:                        + product + "\n");
060:
061:                /*       another way:
062:                 product.create();
063:                 product.setObjectId(this.getNextObjectId());
064:                 this.getObjectList().add(product);
065:                 or:
066:                 product.create();
067:                 this.setObject(product);
068:                 */
069:
070:                /*        
071:                 Product productToRemove = (Product) this.objectList.get(0);        
072:                 this.remove(productToRemove);
073:                 System.out.println("\nRemoved objects: " + this.getRemovedObjects() + "\n");                
074:                 // another way:        
075:                 //((Product) this.objectList.get(0)).remove();   
076:                 */
077:                java.text.NumberFormat nf = java.text.NumberFormat
078:                        .getInstance();
079:                nf.setMaximumFractionDigits(2);
080:                ListIterator li = this .objectList.listIterator();
081:                while (li.hasNext()) {
082:                    Product productToUpdate = (Product) li.next();
083:                    double currentPrice = productToUpdate.getPrice();
084:                    if (currentPrice < 10) {
085:                        double newPrice = currentPrice * 1.1;
086:                        productToUpdate.setPrice(Double.parseDouble(nf
087:                                .format(newPrice)));
088:                        productToUpdate.store();
089:                    }
090:                }
091:
092:                //System.out.println("\n======================= this is after data modifications ===========================\n");
093:                //printAllProducts(); 
094:                /*       
095:                       try{
096:                           this.dbServices.beginTran();
097:                           boolean success = this.writeData();
098:                           Throwable t = this.getWhatIsWrong();
099:                           if (t != null){
100:                               throw t;
101:                           }
102:                           if (success){
103:                               this.dbServices.commitTran();
104:                           }else{
105:                               throw new SQLException("Data modification: failed");
106:                           }            
107:                           this.synchronizePersistentState()
108:                       }catch (Throwable t){
109:                           try{
110:                               this.dbServices.rollbackTran();
111:                           }catch (SQLException sqle){
112:                               sqle.printStackTrace();
113:                               throw new RuntimeException(sqle);
114:                           }    
115:                           t.printStackTrace();            
116:                       }finally{
117:                           try{
118:                               this.dbServices.release(true);
119:                           }catch (SQLException sqle){
120:                               sqle.printStackTrace();
121:                               throw new RuntimeException(sqle);
122:                           }
123:                       }
124:                 */
125:
126:                String generatedSQLasXML = null;
127:                List generatedSQL = null;
128:                try {
129:                    boolean success = this .writeData();
130:                    Throwable t = this .getWhatIsWrong();
131:                    if (t != null) {
132:                        throw t;
133:                    }
134:                    if (!success) {
135:                        throw new SQLException("Data modification: failed");
136:                    }
137:                    // make sure you get this values BEFORE synchronizePersistentState()
138:                    generatedSQLasXML = this .getGeneratedSQLasXML();
139:                    generatedSQL = this .getGeneratedSQL();
140:                    this .synchronizePersistentState();
141:                } catch (Throwable t) {
142:                    t.printStackTrace();
143:                } finally {
144:                    try {
145:                        this .dbServices.release(true);
146:                    } catch (SQLException sqle) {
147:                        sqle.printStackTrace();
148:                        throw new RuntimeException(sqle);
149:                    }
150:                }
151:
152:                System.out
153:                        .println("\n======================= this generated XML which can be sent to another Application/ApplicationServer to update database ===========================\n");
154:                System.out.println(generatedSQLasXML);
155:                System.out
156:                        .println("\n======================= this generated stetements and parameters which can be sent to another Application/ApplicationServer to update database ===========================\n");
157:                Iterator it = generatedSQL.iterator();
158:                while (it.hasNext()) {
159:                    Object[] obj = (Object[]) it.next();
160:                    Object[] params = (Object[]) obj[1];
161:                    System.out.println("sql: " + obj[0] + " params: "
162:                            + Arrays.asList(params));
163:                }
164:            }
165:
166:            public void getProductPages() {
167:                System.out
168:                        .println("\n======================= this is all products ===========================\n");
169:                findAllProducts();
170:                this .setPageSize(10);
171:                PageHolder page = this .getPage(1);
172:                System.out.println("\n=============== Total records: "
173:                        + page.getObjectsTotal() + ", Page "
174:                        + page.getPageNumber() + " of " + page.getPagesTotal()
175:                        + " ===============\n");
176:                Iterator iter1 = page.getPage().iterator();
177:                while (iter1.hasNext()) {
178:                    Product product = (Product) iter1.next();
179:                    System.out.println(product);
180:                }
181:
182:                PageHolder thirdPage = this .getPage(3);
183:                System.out.println("\n=============== Total records: "
184:                        + thirdPage.getObjectsTotal() + ", Page "
185:                        + thirdPage.getPageNumber() + " of "
186:                        + thirdPage.getPagesTotal() + " ===============\n");
187:                Iterator iter2 = thirdPage.getPage().iterator();
188:                while (iter2.hasNext()) {
189:                    Product product = (Product) iter2.next();
190:                    System.out.println(product);
191:                }
192:            }
193:
194:            protected void printAllProducts() {
195:                List products = this .getObjectList();
196:                Iterator productsIter = products.iterator();
197:                while (productsIter.hasNext()) {
198:                    Product product = (Product) productsIter.next();
199:                    System.out.println(product);
200:                }
201:            }
202:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.