Source Code Cross Referenced for ObjectId.java in  » J2EE » Enhydra-Application-Framework » com » lutris » appserver » server » sql » 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 » Enhydra Application Framework » com.lutris.appserver.server.sql 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Enhydra Java Application Server Project
003:         * 
004:         * The contents of this file are subject to the Enhydra Public License
005:         * Version 1.1 (the "License"); you may not use this file except in
006:         * compliance with the License. You may obtain a copy of the License on
007:         * the Enhydra web site ( http://www.enhydra.org/ ).
008:         * 
009:         * Software distributed under the License is distributed on an "AS IS"
010:         * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 
011:         * the License for the specific terms governing rights and limitations
012:         * under the License.
013:         * 
014:         * The Initial Developer of the Enhydra Application Server is Lutris
015:         * Technologies, Inc. The Enhydra Application Server and portions created
016:         * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
017:         * All Rights Reserved.
018:         * 
019:         * Contributor(s):
020:         * 
021:         * $Id: ObjectId.java,v 1.1 2007-01-24 16:59:09 sinisa Exp $
022:         */
023:        package com.lutris.appserver.server.sql;
024:
025:        import java.io.Serializable;
026:        import java.math.BigDecimal;
027:        import java.math.BigInteger;
028:
029:        /**
030:         * Represents an object id used by LBS data objects. The object id
031:         * must be unique. The combination of database URL and object id
032:         * constitutes a GUID. The maximum value of an object id is
033:         * DECIMAL(19,0)
034:         *
035:         * @version	$Revision: 1.1 $
036:         * @author	Kyle Clark
037:         * @since	LBS1.7
038:         * @see		ObjectIdAllocator
039:         */
040:        public class ObjectId implements  Serializable {
041:
042:            /**
043:             * The value associated with this object id.
044:             */
045:            private BigDecimal value;
046:
047:            /**
048:             * The value of one.
049:             */
050:            static final public BigDecimal ONE = new BigDecimal("1");
051:
052:            /**
053:             * The maximum value that can be associated with an object
054:             * id in LBS - DECIMAL(19,0).
055:             */
056:            static final public BigDecimal MAX = new BigDecimal(
057:                    "9999999999999999999");
058:
059:            /**
060:             * Translates a string containing one or more integers
061:             * of the specified radix into an ObjectID.  The string
062:             * may not represet a negative number.
063:             *
064:             * @param val
065:             *   The string representation of the number.
066:             *   The character to digit mapping is provided by
067:             *   Character.digit()
068:             * @param radix
069:             *   Must be between Character.MIN_RADIX(2) and
070:             *   Character.MAX_RADIX(36).
071:             * @exception java.lang.NumberFormatException
072:             *   If the string representation contains invalid characters.
073:             * @exception ObjectIdException
074:             *   If val represents a negative number.
075:             */
076:            public ObjectId(String val, int radix) throws ObjectIdException,
077:                    NumberFormatException {
078:                value = new BigDecimal(new BigInteger(val, radix), 0);
079:                //        if (value.signum() < 0) {
080:                //            throw new ObjectIdException("Object IDs cannot be negative.");
081:                //        }
082:                if (value.compareTo(MAX) > 0) {
083:                    throw new ObjectIdException("Object IDs cannot exceed "
084:                            + MAX.toString());
085:                }
086:            }
087:
088:            /**
089:             * Translates a string containing one or more decimal digits
090:             * into an ObjectID.  
091:             *
092:             * @param val
093:             *   The string representation of the decimal number that
094:             *   
095:             *   The character to digit mapping is provided by
096:             *   Character.digit()
097:             * @exception java.lang.NumberFormatException
098:             *   If the string representation contains invalid characters.
099:             * @exception ObjectIdException
100:             *   If val represents a negative number.
101:             */
102:            public ObjectId(String val) throws ObjectIdException,
103:                    NumberFormatException {
104:                value = new BigDecimal(new BigInteger(val), 0);
105:                //        if (value.signum() < 0) {
106:                //            throw new ObjectIdException("Object IDs cannot be negative.");
107:                //        }
108:                if (value.compareTo(MAX) > 0) {
109:                    throw new ObjectIdException("Object IDs cannot exceed "
110:                            + MAX.toString());
111:                }
112:            }
113:
114:            /**
115:             * Translates a long into an ObjectID.  
116:             *
117:             * @param val
118:             *   The value to assign to the object id.
119:             * @exception ObjectIdException
120:             *   If val is a negative number.
121:             */
122:            public ObjectId(long val) throws ObjectIdException {
123:                //        if (val < 0) {
124:                //            throw new ObjectIdException("Object IDs cannot be negative.");
125:                //        }
126:                value = BigDecimal.valueOf(val);
127:                if (value.compareTo(MAX) > 0) {
128:                    throw new ObjectIdException("Object IDs cannot exceed "
129:                            + MAX.toString());
130:                }
131:            }
132:
133:            /**
134:             * Creates and object id whose value is the same as val.
135:             *
136:             * @param val
137:             *   The value to assign to the object id.
138:             * @exception ObjectIdException
139:             *   If val is a negative number or the scale of val
140:             *   is greater than zero.
141:             */
142:            public ObjectId(BigDecimal val) throws ObjectIdException {
143:                //        if (val.signum() < 0) {
144:                //            throw new ObjectIdException("Object IDs cannot be negative.");
145:                //        }
146:                if (val.scale() > 0) {
147:                    throw new ObjectIdException(
148:                            "Object IDs cannot have a scale "
149:                                    + "greater than zero.");
150:                }
151:                if (val.compareTo(MAX) > 0) {
152:                    throw new ObjectIdException("Object IDs cannot exceed "
153:                            + MAX.toString());
154:                }
155:                value = val;
156:            }
157:
158:            /**
159:             * Returns an object id whose value is (this+val).
160:             *
161:             * @param val
162:             *   The value to add to this object.
163:             * @exception ObjectIdException
164:             *   If the result of the addition would result
165:             *   in an object id that exceeds the
166:             *   <a href=#MAX>maximum</a> object id
167:             *   size.
168:             */
169:            public ObjectId add(ObjectId val) throws ObjectIdException {
170:                return new ObjectId(value.add(val.toBigDecimal()));
171:            }
172:
173:            /**
174:             * Returns an object id whose value is (this+val).
175:             *
176:             * @param val
177:             *   The value to add to this object.
178:             * @exception ObjectIdException
179:             *   If the result of the addition would result
180:             *   in an object id that exceeds the
181:             *   <a href=#MAX>maximum</a> object id
182:             *   size.
183:             */
184:            public ObjectId add(long val) throws ObjectIdException {
185:                return new ObjectId(value.add(BigDecimal.valueOf(val)));
186:            }
187:
188:            /**
189:             * Returns an object id whose value is (this+1)
190:             *
191:             * @exception ObjectIdException
192:             *   If the result of the addition would result
193:             *   in an object id that exceeds the
194:             *   <a href=#MAX>maximum</a> object id
195:             *   size.
196:             */
197:            public ObjectId increment() throws ObjectIdException {
198:                return new ObjectId(value.add(ONE));
199:            }
200:
201:            /**
202:             * Returns a big decimal representation of the object id.
203:             */
204:            public BigDecimal toBigDecimal() {
205:                return value;
206:            }
207:
208:            /**
209:             * Test if this object id is equal to another object id.
210:             */
211:            public boolean equals(ObjectId oid) {
212:                return (oid.toBigDecimal().compareTo(value) == 0);
213:            }
214:
215:            /**
216:             * Returns a hash code for this object id. 
217:             * 
218:             * @return a hash code for this object id. 
219:             */
220:            public int hashCode() {
221:                return toString().hashCode();
222:            }
223:
224:            /**
225:             * String representation of this object id.
226:             */
227:            public String toString() {
228:                return value.toString();
229:            }
230:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.