Source Code Cross Referenced for AccountImpl.java in  » Collaboration » JacORB » demo » bank » transaction » implicit » 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 » Collaboration » JacORB » demo.bank.transaction.implicit 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package demo.bank.transaction.implicit;
002:
003:        /**
004:         * Simple Transaction Service example, code taken and adapted 
005:         * from http://www.wiley.com/compbooks/vogel/ejb/code.html
006:         */
007:
008:        import org.omg.CORBA.*;
009:        import org.omg.CosTransactions.*;
010:
011:        public class AccountImpl extends AccountPOA {
012:            private float balance;
013:            private float newBalance;
014:            private float amount;
015:            private boolean credit;
016:            private ORB orb;
017:            private String name;
018:            private Lock lock;
019:
020:            private boolean nasty = false;
021:            private int nasty_count = 0;
022:
023:            public AccountImpl(ORB orb, String name, float deposit) {
024:                this (orb, name, deposit, false);
025:            }
026:
027:            public AccountImpl(ORB orb, String name, float deposit,
028:                    boolean nasty) {
029:                this .name = name;
030:                this .orb = orb;
031:                this .nasty = nasty;
032:
033:                balance = deposit;
034:                lock = new Lock();
035:            }
036:
037:            public float balance() {
038:                return balance;
039:            }
040:
041:            public synchronized void credit(float amount) {
042:                try {
043:                    if (nasty) {
044:                        switch (nasty_count++) {
045:                        case 0:
046:                            break;
047:                        case 1:
048:                            System.out.println("Step 1 nastyness: error");
049:                            throw new Error("Bank Holidays");
050:                        case 2:
051:                            System.out
052:                                    .println("Step 2 nastyness: COMM_FALIURE");
053:                            throw new org.omg.CORBA.COMM_FAILURE();
054:                        }
055:                    }
056:
057:                    // lock account
058:                    lock.lock();
059:
060:                    Control control = org.omg.CosTransactions.CurrentHelper
061:                            .narrow(
062:                                    orb
063:                                            .resolve_initial_references("TransactionCurrent"))
064:                            .get_control();
065:
066:                    // memorize current activitity
067:                    this .amount = amount;
068:                    credit = true;
069:
070:                    System.err.println("Account " + name
071:                            + "::credit: get coordinator");
072:                    Coordinator coordinator = control.get_coordinator();
073:
074:                    // register resource
075:                    System.out.println("Account " + name
076:                            + "::credit: register resource (Account) with ITS");
077:                    RecoveryCoordinator recCoordinator = coordinator
078:                            .register_resource(_this ());
079:
080:                    newBalance = balance + amount;
081:                    System.out.println(" credit $" + amount);
082:                    System.out.println(" new balance is $" + newBalance);
083:                } catch (Exception ex) {
084:                    System.err.println("Account " + name
085:                            + "::credit: exception: " + ex);
086:                    throw new org.omg.CORBA.TRANSACTION_ROLLEDBACK();
087:                }
088:                ;
089:            }
090:
091:            public synchronized void debit(float amount)
092:                    throws InsufficientFunds {
093:                try {
094:
095:                    if (nasty) {
096:                        switch (nasty_count++) {
097:                        case 0:
098:                            System.out
099:                                    .println("Step 0 nastyness: InsufficientFunds");
100:                            throw new InsufficientFunds();
101:                        case 1:
102:                            System.out.println("Step 1 nastyness: error");
103:                            throw new Error("Bank Holidays");
104:                        case 2:
105:                            System.out
106:                                    .println("Step 2 nastyness: COMM_FALIURE");
107:                            throw new org.omg.CORBA.COMM_FAILURE();
108:                        }
109:                    }
110:                    // lock account
111:                    lock.lock();
112:
113:                    Control control = org.omg.CosTransactions.CurrentHelper
114:                            .narrow(
115:                                    orb
116:                                            .resolve_initial_references("TransactionCurrent"))
117:                            .get_control();
118:
119:                    // memorize current activitity
120:                    this .amount = amount;
121:                    credit = false;
122:
123:                    System.err.println("Account " + name
124:                            + "::debit: get coordinator");
125:                    Coordinator coordinator = control.get_coordinator();
126:
127:                    // register resource
128:                    System.out.println("Account " + name
129:                            + "::debit: register resource (Account) with ITS");
130:                    RecoveryCoordinator recCoordinator = coordinator
131:                            .register_resource(_this ());
132:                    System.out.println("Account " + name
133:                            + "::debit: resource registered");
134:
135:                    if (amount > balance) {
136:                        System.out.println("no sufficient funds");
137:                        lock.unlock();
138:                        System.out.println("Resource: " + name
139:                                + " account unlocked");
140:                        throw new InsufficientFunds();
141:                    }
142:                    newBalance = balance - amount;
143:                    System.out.println(" debit $" + amount);
144:                    System.out.println(" new balance is $" + newBalance);
145:
146:                } catch (org.omg.CORBA.ORBPackage.InvalidName in) {
147:                    System.err.println("Account " + name
148:                            + "::debit: exception: " + in);
149:                    throw new org.omg.CORBA.TRANSACTION_ROLLEDBACK();
150:                } catch (Unavailable u) {
151:                    System.err.println("Account " + name
152:                            + "::debit: exception: " + u);
153:                    throw new org.omg.CORBA.TRANSACTION_ROLLEDBACK();
154:                } catch (Inactive i) {
155:                    System.err.println("Account " + name
156:                            + "::debit: exception: " + i);
157:                    throw new org.omg.CORBA.TRANSACTION_ROLLEDBACK();
158:                } catch (SystemException se) {
159:                    System.err.println("Account " + name
160:                            + "::debit: exception: " + se);
161:                    throw new org.omg.CORBA.TRANSACTION_ROLLEDBACK();
162:                }
163:            }
164:
165:            // implement methods of the Resource interface
166:
167:            public Vote prepare() {
168:                System.out.println("Resource " + name + " : prepare()");
169:                if (balance == newBalance)
170:                    return Vote.VoteReadOnly;
171:                return Vote.VoteCommit;
172:            }
173:
174:            public void rollback() {
175:                // remove data from temporary storage
176:                System.out.println("Resource " + name + " : rollback()");
177:                System.out.println("Resource " + name
178:                        + " : original balance restored: $" + balance);
179:                lock.unlock();
180:                System.out.println("Resource " + name + " account unlocked");
181:            }
182:
183:            public void commit() {
184:                // move data to final storage
185:                System.out.println("Resource " + name + " : commit()");
186:                balance = newBalance;
187:                lock.unlock();
188:                System.out.println("Resource " + name + " account unlocked");
189:            }
190:
191:            public void commit_one_phase() {
192:                // store data immediately at final destination
193:                System.out
194:                        .println("Resource " + name + " : commit_one_phase()");
195:                if (prepare() == Vote.VoteCommit) {
196:                    commit();
197:                }
198:            }
199:
200:            public void forget() {
201:                System.out.println("Resource " + name + " : forget()");
202:            }
203:
204:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.