Source Code Cross Referenced for SpreadsheetFactory.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:        import java.math.BigDecimal;
007:
008:        public class SpreadsheetFactory extends org.julp.DomainObjectFactory
009:                implements  java.io.Serializable, Cloneable {
010:
011:            public SpreadsheetFactory() {
012:                this .setRequestor(Spreadsheet.class);
013:                /* IT IS NOT NECESSARY TO LOAD MAPPINGS THIS WAY, COULD BE ANYTHING: XML, JNDI, DATABASE, ETC... */
014:                setMapping(loadMappings("Spreadsheet.properties"));
015:                sqlMap = loadMappings("Spreadsheet.sql");
016:            }
017:
018:            protected Properties sqlMap = null;
019:
020:            public Properties loadMappings(String path) {
021:                java.io.InputStream inStream = null;
022:                Properties props = new Properties();
023:                try {
024:                    inStream = this .getClass().getResourceAsStream(path);
025:                    props.load(inStream);
026:                } catch (java.io.IOException ioe) {
027:                    throw new RuntimeException(ioe);
028:                } finally {
029:                    try {
030:                        inStream.close();
031:                    } catch (java.io.IOException ioe) {
032:                        throw new RuntimeException(ioe);
033:                    }
034:                }
035:                return props;
036:            }
037:
038:            public int findAllCustomerInvoices() {
039:                int records = 0;
040:                try {
041:                    Collection arg = new ArrayList(1);
042:                    //arg.add(new Integer(4));
043:                    //records = this.load(this.dbServices.getResultSet(sqlMap.getProperty("findAll"), arg));
044:                    records = this .load(this .dbServices.getResultSet(sqlMap
045:                            .getProperty("findAll")));
046:                    printSpreadsheet();
047:                } catch (SQLException sqle) {
048:                    throw new RuntimeException(sqle);
049:                }
050:                return records;
051:            }
052:
053:            public void modifyInvoices() {
054:                // if another user/process UPDATEd or DELETEd rows in database then throw exception
055:                this .setOptimisticLock(this .KEY_AND_UPDATEBLE_COLUMNS);
056:                this .setThrowOptimisticLockDeleteException(true);
057:                this .setThrowOptimisticLockUpdateException(true);
058:                Map invoiceTotalMap = new HashMap();
059:                Collection arg = new ArrayList(1);
060:                arg.add(new Integer(4));
061:                try {
062:                    this .dbServices.setDebug(true);
063:                    this .dbServices.setCacheStatements(true);
064:                    this .load(this .dbServices.getResultSet(sqlMap
065:                            .getProperty("findAllCustomerInvoices"), arg));
066:                } catch (SQLException sqle) {
067:                    throw new RuntimeException(sqle);
068:                }
069:
070:                // remove some records
071:                ListIterator li1 = this .objectList.listIterator();
072:                while (li1.hasNext()) {
073:                    Spreadsheet record = (Spreadsheet) li1.next();
074:                    Integer invoiceId = record.getInvoiceId();
075:                    BigDecimal cost = record.getCost();
076:                    if (cost.doubleValue() > 30.0) {
077:                        record.remove();
078:                    } else {
079:                        BigDecimal invoiceTotal = (BigDecimal) invoiceTotalMap
080:                                .get(invoiceId);
081:                        if (invoiceTotal == null) {
082:                            invoiceTotal = new BigDecimal(0.0);
083:                        }
084:                        invoiceTotal = invoiceTotal.add(cost);
085:                        invoiceTotalMap.put(invoiceId, invoiceTotal);
086:                    }
087:                }
088:
089:                System.out
090:                        .println("\n======================= invoiceTotalMap: \n"
091:                                + invoiceTotalMap);
092:
093:                //System.out.println("\n======================= this is after data modifications ===========================\n");
094:                //printSpreadsheet();
095:
096:                try {
097:                    // since Spreadsheet can modify more then one table
098:                    // we need to specify table name
099:                    this .setTable("ITEM");
100:                    this .dbServices.beginTran();
101:                    boolean success1 = this .writeData();
102:                    Throwable t1 = this .getWhatIsWrong();
103:                    if (t1 != null) {
104:                        throw t1;
105:                    }
106:
107:                    // update INVOICE table            
108:                    //update invoices total
109:                    ListIterator li2 = this .objectList.listIterator();
110:                    while (li2.hasNext()) {
111:                        Spreadsheet record = (Spreadsheet) li2.next();
112:                        Integer invoiceId = record.getInvoiceId();
113:                        Object total = invoiceTotalMap.get(invoiceId);
114:                        BigDecimal invoiceTotal = null;
115:                        if (total == null) {
116:                            invoiceTotal = new BigDecimal(0);
117:                        } else {
118:                            invoiceTotal = (BigDecimal) total;
119:                        }
120:                        record.setTotal(invoiceTotal);
121:                        record.store();
122:                    }
123:                    this .setTable("INVOICE");
124:                    // do not DELETE invoice
125:                    char[] updateOnly = new char[1];
126:                    updateOnly[0] = this .DATA_MODIFICATION_SEQUENCE_UPDATE;
127:                    this .setDataModificationSequence(updateOnly);
128:                    boolean success2 = this .writeData();
129:                    Throwable t2 = this .getWhatIsWrong();
130:                    if (t2 != null) {
131:                        throw t2;
132:                    }
133:                    if (success1 == true && success2 == true) {
134:                        this .dbServices.commitTran();
135:                    } else {
136:                        throw new SQLException("Data modification: failed");
137:                    }
138:                    this .synchronizePersistentState();
139:                } catch (Throwable t) {
140:                    try {
141:                        this .dbServices.rollbackTran();
142:                    } catch (SQLException sqle) {
143:                        sqle.printStackTrace();
144:                        throw new RuntimeException(sqle);
145:                    }
146:                    t.printStackTrace();
147:                } finally {
148:                    try {
149:                        this .dbServices.release(true);
150:                    } catch (SQLException sqle) {
151:                        sqle.printStackTrace();
152:                        throw new RuntimeException(sqle);
153:                    }
154:                }
155:
156:                System.out
157:                        .println("\n======================= this is after COMMIT & synchronizePersistentState() or after ROLLBACK ===========================\n");
158:                //printSpreadsheet();
159:            }
160:
161:            protected void printSpreadsheet() {
162:                List rows = this .getObjectList();
163:                Iterator iter = rows.iterator();
164:                while (iter.hasNext()) {
165:                    Spreadsheet row = (Spreadsheet) iter.next();
166:                    System.out.println(row);
167:                }
168:            }
169:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.