Source Code Cross Referenced for JtdsXid.java in  » Database-JDBC-Connection-Pool » jTDS » net » sourceforge » jtds » jdbcx » 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 JDBC Connection Pool » jTDS » net.sourceforge.jtds.jdbcx 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        //jTDS JDBC Driver for Microsoft SQL Server and Sybase
002:        //Copyright (C) 2004 The jTDS Project
003:        //
004:        //This library is free software; you can redistribute it and/or
005:        //modify it under the terms of the GNU Lesser General Public
006:        //License as published by the Free Software Foundation; either
007:        //version 2.1 of the License, or (at your option) any later version.
008:        //
009:        //This library is distributed in the hope that it will be useful,
010:        //but WITHOUT ANY WARRANTY; without even the implied warranty of
011:        //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
012:        //Lesser General Public License for more details.
013:        //
014:        //You should have received a copy of the GNU Lesser General Public
015:        //License along with this library; if not, write to the Free Software
016:        //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
017:        //
018:        package net.sourceforge.jtds.jdbcx;
019:
020:        import javax.transaction.xa.Xid;
021:
022:        import net.sourceforge.jtds.jdbc.Support;
023:
024:        /**
025:         * jTDS implementation of the <code>Xid</code> interface.
026:         *
027:         * @version $Id: JtdsXid.java,v 1.3 2005/04/28 14:29:30 alin_sinpalean Exp $
028:         */
029:        public class JtdsXid implements  Xid {
030:            /** The size of an XID in bytes. */
031:            public static final int XID_SIZE = 140;
032:
033:            /** The global transaction ID. */
034:            private final byte gtran[];
035:            /** The branch qualifier ID. */
036:            private final byte bqual[];
037:            /** The format ID. */
038:            public final int fmtId;
039:            /** Precalculated hash value. */
040:            public int hash;
041:
042:            /**
043:             * Construct an XID using an offset into a byte buffer.
044:             *
045:             * @param buf the byte buffer
046:             * @param pos the offset
047:             */
048:            public JtdsXid(byte[] buf, int pos) {
049:                fmtId = (buf[pos] & 0xFF) | ((buf[pos + 1] & 0xFF) << 8)
050:                        | ((buf[pos + 2] & 0xFF) << 16)
051:                        | ((buf[pos + 3] & 0xFF) << 24);
052:                int t = buf[pos + 4];
053:                int b = buf[pos + 8];
054:                gtran = new byte[t];
055:                bqual = new byte[b];
056:                System.arraycopy(buf, 12 + pos, gtran, 0, t);
057:                System.arraycopy(buf, 12 + t + pos, bqual, 0, b);
058:                calculateHash();
059:            }
060:
061:            /**
062:             * Construct an XID using two byte arrays.
063:             *
064:             * @param global the global transaction id
065:             * @param branch the transaction branch
066:             */
067:            public JtdsXid(byte[] global, byte[] branch) {
068:                fmtId = 0;
069:                gtran = global;
070:                bqual = branch;
071:                calculateHash();
072:            }
073:
074:            /**
075:             * Construct an XID as a clone of another XID.
076:             */
077:            public JtdsXid(Xid xid) {
078:                fmtId = xid.getFormatId();
079:                gtran = new byte[xid.getGlobalTransactionId().length];
080:                System.arraycopy(xid.getGlobalTransactionId(), 0, gtran, 0,
081:                        gtran.length);
082:                bqual = new byte[xid.getBranchQualifier().length];
083:                System.arraycopy(xid.getBranchQualifier(), 0, bqual, 0,
084:                        bqual.length);
085:                calculateHash();
086:            }
087:
088:            private void calculateHash() {
089:                String x = Integer.toString(fmtId) + new String(gtran)
090:                        + new String(bqual);
091:                hash = x.hashCode();
092:            }
093:
094:            /**
095:             * Get the hash code for this object.
096:             *
097:             * @return the hash value of this object as a <code>int</code>
098:             */
099:            public int hashCode() {
100:                return hash;
101:            }
102:
103:            /**
104:             * Test for equality.
105:             *
106:             * @param obj the object to test for equality with this
107:             * @return <code>boolean</code> true if the parameter equals this
108:             */
109:            public boolean equals(Object obj) {
110:                if (obj == this )
111:                    return true;
112:
113:                if (obj instanceof  JtdsXid) {
114:                    JtdsXid xobj = (JtdsXid) obj;
115:
116:                    if (gtran.length + bqual.length == xobj.gtran.length
117:                            + xobj.bqual.length
118:                            && fmtId == xobj.fmtId) {
119:                        for (int i = 0; i < gtran.length; ++i) {
120:                            if (gtran[i] != xobj.gtran[i]) {
121:                                return false;
122:                            }
123:                        }
124:
125:                        for (int i = 0; i < bqual.length; ++i) {
126:                            if (bqual[i] != xobj.bqual[i]) {
127:                                return false;
128:                            }
129:                        }
130:
131:                        return true;
132:                    }
133:                }
134:                return false;
135:            }
136:
137:            //
138:            // ------------------- javax.transaction.xa.Xid interface methods -------------------
139:            //
140:
141:            public int getFormatId() {
142:                return fmtId;
143:            }
144:
145:            public byte[] getBranchQualifier() {
146:                return bqual;
147:            }
148:
149:            public byte[] getGlobalTransactionId() {
150:                return gtran;
151:            }
152:
153:            public String toString() {
154:                StringBuffer txt = new StringBuffer(256);
155:                txt.append("XID[Format=").append(fmtId).append(", Global=0x");
156:                txt.append(Support.toHex(gtran)).append(", Branch=0x");
157:                txt.append(Support.toHex(bqual)).append(']');
158:                return txt.toString();
159:            }
160:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.