Source Code Cross Referenced for TxUtils.java in  » EJB-Server-JBoss-4.2.1 » transaction » org » jboss » tm » 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 » EJB Server JBoss 4.2.1 » transaction » org.jboss.tm 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * JBoss, Home of Professional Open Source.
003:         * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004:         * as indicated by the @author tags. See the copyright.txt file in the
005:         * distribution for a full listing of individual contributors.
006:         *
007:         * This is free software; you can redistribute it and/or modify it
008:         * under the terms of the GNU Lesser General Public License as
009:         * published by the Free Software Foundation; either version 2.1 of
010:         * the License, or (at your option) any later version.
011:         *
012:         * This software is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015:         * Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this software; if not, write to the Free
019:         * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021:         */
022:        package org.jboss.tm;
023:
024:        import javax.transaction.Status;
025:        import javax.transaction.SystemException;
026:        import javax.transaction.Transaction;
027:        import javax.transaction.TransactionManager;
028:        import javax.transaction.UserTransaction;
029:        import javax.transaction.xa.XAResource;
030:
031:        import org.jboss.util.NestedRuntimeException;
032:
033:        /**
034:         * TxUtils.java has utility methods for determining transaction status
035:         * in various useful ways.
036:         *
037:         * @author <a href="mailto:d_jencks@users.sourceforge.net">David Jencks</a>
038:         * @author <a href="mailto:bill@jboss.org">Bill Burke</a>
039:         * @author <a href="mailto:dimitris@jboss.org">Dimitris Andreadis</a>
040:         * @version $Revision: 63567 $
041:         */
042:        public class TxUtils {
043:            /** Transaction Status Strings */
044:            private static final String[] TxStatusStrings = { "STATUS_ACTIVE",
045:                    "STATUS_MARKED_ROLLBACK", "STATUS_PREPARED",
046:                    "STATUS_COMMITTED", "STATUS_ROLLEDBACK", "STATUS_UNKNOWN",
047:                    "STATUS_NO_TRANSACTION", "STATUS_PREPARING",
048:                    "STATUS_COMMITTING", "STATUS_ROLLING_BACK" };
049:
050:            /**
051:             * Do now allow instances of this class
052:             */
053:            private TxUtils() {
054:
055:            }
056:
057:            public static boolean isActive(Transaction tx) {
058:                if (tx == null)
059:                    return false;
060:
061:                try {
062:                    int status = tx.getStatus();
063:                    return isActive(status);
064:                } catch (SystemException error) {
065:                    throw new NestedRuntimeException(error);
066:                }
067:            }
068:
069:            public static boolean isActive(TransactionManager tm) {
070:                try {
071:                    return isActive(tm.getTransaction());
072:                } catch (SystemException error) {
073:                    throw new NestedRuntimeException(error);
074:                }
075:            }
076:
077:            public static boolean isActive(UserTransaction ut) {
078:                try {
079:                    int status = ut.getStatus();
080:                    return isActive(status);
081:                } catch (SystemException error) {
082:                    throw new NestedRuntimeException(error);
083:                }
084:            }
085:
086:            public static boolean isActive(int status) {
087:                return status == Status.STATUS_ACTIVE;
088:            }
089:
090:            public static boolean isUncommitted(Transaction tx) {
091:                if (tx == null)
092:                    return false;
093:
094:                try {
095:                    int status = tx.getStatus();
096:                    return isUncommitted(status);
097:                } catch (SystemException error) {
098:                    throw new NestedRuntimeException(error);
099:                }
100:            }
101:
102:            public static boolean isUncommitted(TransactionManager tm) {
103:                try {
104:                    return isUncommitted(tm.getTransaction());
105:                } catch (SystemException error) {
106:                    throw new NestedRuntimeException(error);
107:                }
108:            }
109:
110:            public static boolean isUncommitted(UserTransaction ut) {
111:                try {
112:                    int status = ut.getStatus();
113:                    return isUncommitted(status);
114:
115:                } catch (SystemException error) {
116:                    throw new NestedRuntimeException(error);
117:                }
118:            }
119:
120:            public static boolean isUncommitted(int status) {
121:                return status == Status.STATUS_ACTIVE
122:                        || status == Status.STATUS_MARKED_ROLLBACK;
123:            }
124:
125:            public static boolean isCompleted(Transaction tx) {
126:                if (tx == null)
127:                    return true;
128:
129:                try {
130:                    int status = tx.getStatus();
131:                    return isCompleted(status);
132:                } catch (SystemException error) {
133:                    throw new NestedRuntimeException(error);
134:                }
135:            }
136:
137:            public static boolean isCompleted(TransactionManager tm) {
138:                try {
139:                    return isCompleted(tm.getTransaction());
140:                } catch (SystemException error) {
141:                    throw new NestedRuntimeException(error);
142:                }
143:            }
144:
145:            public static boolean isCompleted(UserTransaction ut) {
146:                try {
147:                    int status = ut.getStatus();
148:                    return isCompleted(status);
149:
150:                } catch (SystemException error) {
151:                    throw new NestedRuntimeException(error);
152:                }
153:            }
154:
155:            public static boolean isCompleted(int status) {
156:                return status == Status.STATUS_COMMITTED
157:                        || status == Status.STATUS_ROLLEDBACK
158:                        || status == Status.STATUS_NO_TRANSACTION;
159:            }
160:
161:            public static boolean isRollback(Transaction tx) {
162:                if (tx == null)
163:                    return false;
164:
165:                try {
166:                    int status = tx.getStatus();
167:                    return isRollback(status);
168:                } catch (SystemException error) {
169:                    throw new NestedRuntimeException(error);
170:                }
171:            }
172:
173:            public static boolean isRollback(TransactionManager tm) {
174:                try {
175:                    return isRollback(tm.getTransaction());
176:                } catch (SystemException error) {
177:                    throw new NestedRuntimeException(error);
178:                }
179:            }
180:
181:            public static boolean isRollback(UserTransaction ut) {
182:                try {
183:                    int status = ut.getStatus();
184:                    return isRollback(status);
185:                } catch (SystemException error) {
186:                    throw new NestedRuntimeException(error);
187:                }
188:            }
189:
190:            public static boolean isRollback(int status) {
191:                return status == Status.STATUS_MARKED_ROLLBACK
192:                        || status == Status.STATUS_ROLLING_BACK
193:                        || status == Status.STATUS_ROLLEDBACK;
194:            }
195:
196:            /**
197:             * Converts a tx Status index to a String
198:             * 
199:             * @see javax.transaction.Status
200:             * 
201:             * @param status the Status index
202:             * @return status as String or "STATUS_INVALID"
203:             */
204:            public static String getStatusAsString(int status) {
205:                if (status >= Status.STATUS_ACTIVE
206:                        && status <= Status.STATUS_ROLLING_BACK) {
207:                    return TxStatusStrings[status];
208:                } else {
209:                    return "STATUS_INVALID";
210:                }
211:            }
212:
213:            /**
214:             * Converts a XAResource flag to a String
215:             * 
216:             * @see javax.transaction.xa.XAResource
217:             * 
218:             * @param flags the flags passed in to start(), end(), recover() 
219:             * @return the flags in String form
220:             */
221:            public static String getXAResourceFlagsAsString(int flags) {
222:                if (flags == XAResource.TMNOFLAGS) {
223:                    return "|TMNOFLAGS";
224:                } else {
225:                    StringBuffer sbuf = new StringBuffer(64);
226:
227:                    if ((flags & XAResource.TMONEPHASE) != 0) {
228:                        sbuf.append("|TMONEPHASE");
229:                    }
230:                    if ((flags & XAResource.TMJOIN) != 0) {
231:                        sbuf.append("|TMJOIN");
232:                    }
233:                    if ((flags & XAResource.TMRESUME) != 0) {
234:                        sbuf.append("|TMRESUME");
235:                    }
236:                    if ((flags & XAResource.TMSUCCESS) != 0) {
237:                        sbuf.append("|TMSUCCESS");
238:                    }
239:                    if ((flags & XAResource.TMFAIL) != 0) {
240:                        sbuf.append("|TMFAIL");
241:                    }
242:                    if ((flags & XAResource.TMSUSPEND) != 0) {
243:                        sbuf.append("|TMSUSPEND");
244:                    }
245:                    if ((flags & XAResource.TMSTARTRSCAN) != 0) {
246:                        sbuf.append("|TMSTARTRSCAN");
247:                    }
248:                    if ((flags & XAResource.TMENDRSCAN) != 0) {
249:                        sbuf.append("|TMENDRSCAN");
250:                    }
251:                    return sbuf.toString();
252:                }
253:            }
254:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.