Source Code Cross Referenced for XATestUtil.java in  » Database-DBMS » db-derby-10.2 » org » apache » derbyTesting » functionTests » util » 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 DBMS » db derby 10.2 » org.apache.derbyTesting.functionTests.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:
003:           Derby - Class org.apache.derby.impl.services.bytecode.CodeChunk
004:
005:           Licensed to the Apache Software Foundation (ASF) under one or more
006:           contributor license agreements.  See the NOTICE file distributed with
007:           this work for additional information regarding copyright ownership.
008:           The ASF licenses this file to You under the Apache License, Version 2.0
009:           (the "License"); you may not use this file except in compliance with
010:           the License.  You may obtain a copy of the License at
011:
012:              http://www.apache.org/licenses/LICENSE-2.0
013:
014:           Unless required by applicable law or agreed to in writing, software
015:           distributed under the License is distributed on an "AS IS" BASIS,
016:           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017:           See the License for the specific language governing permissions and
018:           limitations under the License.
019:
020:         */
021:
022:        package org.apache.derbyTesting.functionTests.util;
023:
024:        import java.io.Serializable;
025:        import java.sql.Connection;
026:        import java.sql.ResultSet;
027:        import java.sql.SQLException;
028:        import java.sql.Statement;
029:
030:        import javax.transaction.xa.XAException;
031:        import javax.transaction.xa.Xid;
032:
033:        import org.apache.derby.tools.JDBCDisplayUtil;
034:
035:        public class XATestUtil {
036:
037:            /**
038:             * Return a new Xid for testing.
039:             */
040:            public static Xid getXid(int xid, int b1, int b2) {
041:                return new utilXid(xid, b1, b2);
042:            }
043:
044:            /**
045:             * Dump an unexpected XAException.
046:             * @param tag Useful info to print
047:             * @param xae The exception
048:             */
049:            public static void dumpXAException(String tag, XAException xae) {
050:
051:                System.out.println(tag + " : XAException - " + xae.getMessage()
052:                        + " errorCode " + errorCode(xae));
053:                xae.printStackTrace(System.out);
054:            }
055:
056:            /**
057:             * Create a view that allows useful inspection of the active
058:             * global transactions.
059:             */
060:            public static void createXATransactionView(Connection conn)
061:                    throws SQLException {
062:                Statement s = conn.createStatement();
063:                s
064:                        .execute("create view XATESTUTIL.global_xactTable as "
065:                                + "select  cast(global_xid as char(2)) as gxid,"
066:                                + " status, "
067:                                + " CAST (case when first_instant is NULL then 'NULL' else 'false' end AS VARCHAR(8)) as readOnly, "
068:                                + " cast (username as char(10)) as username, type "
069:                                + " from syscs_diag.transaction_table");
070:                s.close();
071:            }
072:
073:            /**
074:             * Display the active global transactions.
075:             * @param conn
076:             * @throws SQLException
077:             */
078:            public static void showXATransactionView(Connection conn)
079:                    throws SQLException {
080:                Statement s = conn.createStatement();
081:                ResultSet rs = s
082:                        .executeQuery("select * from XATESTUTIL.global_xactTable where gxid is not null order by gxid");
083:                JDBCDisplayUtil.DisplayResults(System.out, rs, conn);
084:                rs.close();
085:            }
086:
087:            /**
088:             * Return a string for the error code of the XAException.
089:             */
090:            public static String errorCode(XAException e) {
091:                String error;
092:                switch (e.errorCode) {
093:                case XAException.XA_HEURCOM:
094:                    error = "XA_HEURCOM ";
095:                    break;
096:                case XAException.XA_HEURHAZ:
097:                    error = "XA_HEURHAZ";
098:                    break;
099:                case XAException.XA_HEURMIX:
100:                    error = "XA_HEURMIX";
101:                    break;
102:                case XAException.XA_HEURRB:
103:                    error = "XA_HEURRB ";
104:                    break;
105:                case XAException.XA_NOMIGRATE:
106:                    error = "XA_NOMIGRATE ";
107:                    break;
108:                case XAException.XA_RBCOMMFAIL:
109:                    error = "XA_RBCOMMFAIL ";
110:                    break;
111:                case XAException.XA_RBDEADLOCK:
112:                    error = "XA_RBDEADLOCK ";
113:                    break;
114:                case XAException.XA_RBINTEGRITY:
115:                    error = "XA_RBINTEGRITY ";
116:                    break;
117:                case XAException.XA_RBOTHER:
118:                    error = "XA_RBOTHER ";
119:                    break;
120:                case XAException.XA_RBPROTO:
121:                    error = "XA_RBPROTO ";
122:                    break;
123:                case XAException.XA_RBROLLBACK:
124:                    error = "XA_RBROLLBACK ";
125:                    break;
126:                case XAException.XA_RBTIMEOUT:
127:                    error = "XA_RBTIMEOUT ";
128:                    break;
129:                case XAException.XA_RBTRANSIENT:
130:                    error = "XA_RBTRANSIENT ";
131:                    break;
132:                case XAException.XA_RDONLY:
133:                    error = "XA_RDONLY ";
134:                    break;
135:                case XAException.XA_RETRY:
136:                    error = "XA_RETRY ";
137:                    break;
138:                case XAException.XAER_ASYNC:
139:                    error = "XAER_ASYNC ";
140:                    break;
141:                case XAException.XAER_DUPID:
142:                    error = "XAER_DUPID ";
143:                    break;
144:                case XAException.XAER_INVAL:
145:                    error = "XAER_INVAL ";
146:                    break;
147:                case XAException.XAER_NOTA:
148:                    error = "XAER_NOTA ";
149:                    break;
150:                case XAException.XAER_OUTSIDE:
151:                    error = "XAER_OUTSIDE ";
152:                    break;
153:                case XAException.XAER_PROTO:
154:                    error = "XAER_PROTO ";
155:                    break;
156:                case XAException.XAER_RMERR:
157:                    error = "XAER_RMERR ";
158:                    break;
159:                case XAException.XAER_RMFAIL:
160:                    error = "XAER_RMFAIL ";
161:                    break;
162:                default:
163:                    error = Integer.toString(e.errorCode);
164:                    break;
165:                }
166:                return error;
167:            }
168:
169:        }
170:
171:        /**
172:         * Simple utility class implementation of Xid for tests.
173:         *
174:         */
175:        class utilXid implements  Xid, Serializable {
176:            private static final long serialVersionUID = 64467338100036L;
177:
178:            private final int format_id;
179:
180:            private byte[] global_id;
181:
182:            private byte[] branch_id;
183:
184:            utilXid(int xid, int b1, int b2) {
185:                format_id = xid;
186:                global_id = new byte[Xid.MAXGTRIDSIZE];
187:                branch_id = new byte[Xid.MAXBQUALSIZE];
188:
189:                for (int i = 0; i < global_id.length; i++) {
190:                    global_id[i] = (byte) (b1 + i);
191:                }
192:
193:                for (int i = 0; i < branch_id.length; i++) {
194:                    branch_id[i] = (byte) (b2 + i);
195:                }
196:            }
197:
198:            /**
199:             * Obtain the format id part of the Xid.
200:             * <p>
201:             *
202:             * @return Format identifier. O means the OSI CCR format.
203:             **/
204:            public int getFormatId() {
205:                return (format_id);
206:            }
207:
208:            /**
209:             * Obtain the global transaction identifier part of XID as an array of 
210:             * bytes.
211:             * <p>
212:             *
213:             * @return A byte array containing the global transaction identifier.
214:             **/
215:            public byte[] getGlobalTransactionId() {
216:                return (global_id);
217:            }
218:
219:            /**
220:             * Obtain the transaction branch qualifier part of the Xid in a byte array.
221:             * <p>
222:             *
223:             * @return A byte array containing the branch qualifier of the transaction.
224:             **/
225:            public byte[] getBranchQualifier() {
226:                return (branch_id);
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.