Source Code Cross Referenced for ManacEC.java in  » J2EE » JOnAS-4.8.6 » lb » 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 » J2EE » JOnAS 4.8.6 » lb 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * JOnAS: Java(TM) Open Application Server
003:         * Copyright (C) 1999-2004 Bull S.A.
004:         * Contact: jonas-team@objectweb.org
005:         *
006:         * This library is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation; either
009:         * version 2.1 of the License, or any later version.
010:         *
011:         * This library is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         * Lesser General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU Lesser General Public
017:         * License along with this library; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
019:         * USA
020:         *
021:         * --------------------------------------------------------------------------
022:         * $Id: ManacEC.java 4618 2004-04-19 06:39:30Z benoitf $
023:         * --------------------------------------------------------------------------
024:         */package lb;
025:
026:        import javax.ejb.CreateException;
027:        import javax.ejb.DuplicateKeyException;
028:        import javax.ejb.EJBException;
029:        import javax.ejb.EntityBean;
030:        import javax.ejb.EntityContext;
031:        import javax.ejb.RemoveException;
032:
033:        /**
034:         * Manac Implementation
035:         * @author Philippe Durieux
036:         */
037:        public class ManacEC implements  EntityBean {
038:
039:            EntityContext ejbContext;
040:
041:            // ------------------------------------------------------------------
042:            // State of the bean.
043:            // They must be public for Container Managed Persistance.
044:            // ------------------------------------------------------------------
045:            public String name;
046:
047:            public int num;
048:
049:            public int balance;
050:
051:            // ------------------------------------------------------------------
052:            // EntityBean implementation
053:            // ------------------------------------------------------------------
054:
055:            /**
056:             * Set the associated entity context. The container invokes this method on
057:             * an instance after the instance has been created. This method is called in
058:             * an unspecified transaction context.
059:             * @param ctx - An EntityContext interface for the instance. The instance
060:             *        should store the reference to the context in an instance variable.
061:             * @throws EJBException Thrown by the method to indicate a failure caused by
062:             *         a system-level error.
063:             */
064:            public void setEntityContext(EntityContext ctx) {
065:                ejbContext = ctx;
066:            }
067:
068:            /**
069:             * Unset the associated entity context. The container calls this method
070:             * before removing the instance. This is the last method that the container
071:             * invokes on the instance. The Java garbage collector will eventually
072:             * invoke the finalize() method on the instance. This method is called in an
073:             * unspecified transaction context.
074:             * @throws EJBException Thrown by the method to indicate a failure caused by
075:             *         a system-level error.
076:             */
077:            public void unsetEntityContext() {
078:                ejbContext = null;
079:            }
080:
081:            /**
082:             * A container invokes this method before it removes the EJB object that is
083:             * currently associated with the instance. This method is invoked when a
084:             * client invokes a remove operation on the enterprise Bean's home interface
085:             * or the EJB object's remote interface. This method transitions the
086:             * instance from the ready state to the pool of available instances. This
087:             * method is called in the transaction context of the remove operation.
088:             * @throws RemoveException The enterprise Bean does not allow destruction of
089:             *         the object.
090:             * @throws EJBException - Thrown by the method to indicate a failure caused
091:             *         by a system-level error.
092:             */
093:            public void ejbRemove() throws RemoveException {
094:            }
095:
096:            /**
097:             * A container invokes this method to instruct the instance to synchronize
098:             * its state by loading it state from the underlying database. This method
099:             * always executes in the proper transaction context.
100:             * @throws EJBException Thrown by the method to indicate a failure caused by
101:             *         a system-level error.
102:             */
103:            public void ejbLoad() {
104:                if (balance < 0) {
105:                    System.out.println(name + " : Bad balance loaded");
106:                    throw new EJBException("ejbLoad: Balance " + name
107:                            + " was negative =" + balance);
108:                }
109:            }
110:
111:            /**
112:             * A container invokes this method to instruct the instance to synchronize
113:             * its state by storing it to the underlying database. This method always
114:             * executes in the proper transaction context.
115:             * @throws EJBException Thrown by the method to indicate a failure caused by
116:             *         a system-level error.
117:             */
118:            public void ejbStore() {
119:                if (balance < 0) {
120:                    System.out.println(name + " : Bad balance stored");
121:                    throw new EJBException("ejbStore: Balance " + name
122:                            + " was negative =" + balance);
123:                }
124:            }
125:
126:            /**
127:             * The Entity bean can define 0 or more ejbCreate methods.
128:             * @throws CreateException Failure to create an entity EJB object.
129:             * @throws DuplicateKeyException An object with the same key already exists.
130:             */
131:            public java.lang.String ejbCreate(int num, String name, int ib)
132:                    throws CreateException, DuplicateKeyException {
133:
134:                // Init here the bean fields
135:                this .num = num;
136:                this .name = new String(name);
137:                this .balance = ib;
138:
139:                // In CMP, should return null.
140:                return null;
141:            }
142:
143:            /**
144:             * There must be an ejbPostCreate per ejbCreate method
145:             * @throws CreateException Failure to create an entity EJB object.
146:             */
147:            public void ejbPostCreate(int num, String name, int ib)
148:                    throws CreateException {
149:            }
150:
151:            /**
152:             * The Entity bean can define 0 or more ejbCreate methods.
153:             * @throws CreateException Failure to create an entity EJB object.
154:             * @throws DuplicateKeyException An object with the same key already exists.
155:             */
156:            public java.lang.String ejbCreateWithDefaultName(int num, int ib)
157:                    throws CreateException, DuplicateKeyException {
158:
159:                // Init here the bean fields
160:                this .num = num;
161:                this .name = "M" + (new Integer(num)).toString();
162:                this .balance = ib;
163:
164:                // In CMP, should return null.
165:                return null;
166:            }
167:
168:            /**
169:             * There must be an ejbPostCreate per ejbCreate method
170:             * @throws CreateException Failure to create an entity EJB object.
171:             */
172:            public void ejbPostCreateWithDefaultName(int num, int ib)
173:                    throws CreateException {
174:            }
175:
176:            /**
177:             * A container invokes this method on an instance before the instance
178:             * becomes disassociated with a specific EJB object.
179:             */
180:            public void ejbPassivate() {
181:                // balance may be wrong in case of rollback.
182:                // Anyway, this instance is being released now, so no problem!
183:                balance = -80000;
184:            }
185:
186:            /**
187:             * A container invokes this method when the instance is taken out of the
188:             * pool of available instances to become associated with a specific EJB
189:             * object.
190:             */
191:            public void ejbActivate() {
192:            }
193:
194:            // ------------------------------------------------------------------
195:            // Manac implementation
196:            // ------------------------------------------------------------------
197:
198:            /**
199:             * getBalance
200:             */
201:            public int getBalance() {
202:                return balance;
203:            }
204:
205:            /**
206:             * credit
207:             */
208:            public void credit(int v) {
209:                balance += v;
210:            }
211:
212:            /**
213:             * debit
214:             */
215:            public void debit(int v) {
216:                balance -= v;
217:                if (balance < 0) {
218:                    System.out.println(name + " : set rollback only.");
219:                    ejbContext.setRollbackOnly();
220:                    balance = -90000; // put it a very bad balance to check rollback is
221:                    // OK
222:                }
223:            }
224:
225:            public String getName() {
226:                return name;
227:            }
228:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.