Source Code Cross Referenced for TypeMapping.java in  » Database-ORM » MMBase » org » mmbase » storage » 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 ORM » MMBase » org.mmbase.storage.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:
003:        This software is OSI Certified Open Source Software.
004:        OSI Certified is a certification mark of the Open Source Initiative.
005:
006:        The license (Mozilla version 1.0) can be read at the MMBase site.
007:        See http://www.MMBase.org/license
008:
009:         */
010:        package org.mmbase.storage.util;
011:
012:        import java.text.MessageFormat;
013:
014:        /**
015:         * The TypeMapping class helps translating MMBase types to storage-specific type descriptions.
016:         * Examples of type mappings are mappings that convert to database field types.
017:         * I.e., a STRING with size 0-255 could be configured to translate to 'varchar({0})', '{0}, in this case,.
018:         * being the size of the actual field.
019:         * <br />
020:         * TypeMapping is a comparable class, which allows it to be used in a sorted map, set or list.
021:         * However, Typemapping needs fuzzy matching so it is easy to locate the appropriate type-mapping for a field.
022:         * As such, it's natural ordering is NOT consistent with equals. A typemapping may be considered 'equal' while still having
023:         * a different ordering position in the class.
024:         * This allows for an easy search on a sorted list of TypeMappings: By using 'IndexOf' you can quickly find a TypeMapping in a list,
025:         * even if the min or max sizes for the type do not completely match.
026:         * You typically use this if you searxh for a TypeMapping whose size you set with 'getSize()', rather than setting a specific range
027:         * (using the minSize/maxSize properties).
028:         *
029:         * @author Pierre van Rooden
030:         * @version $Id: TypeMapping.java,v 1.10 2008/02/03 17:33:57 nklasens Exp $
031:         * @since MMBase-1.7
032:         */
033:        public class TypeMapping implements  Comparable<TypeMapping> {
034:
035:            /**
036:             * The expression this type should translate to.
037:             * You can access this property directly, but you can use {@link #getType(int)} to obtain an expanded expression.
038:             */
039:            public String type;
040:            /**
041:             * The name of the MMBase type to map
042:             */
043:            public String name;
044:            /**
045:             * The minimum size of the MMBase type to map.
046:             * A value of -1 indicates no mimimum.
047:             */
048:            public long minSize;
049:            /**
050:             * The maximum size of the MMBase type to map.
051:             * A value of -1 indicates no maximum.
052:             */
053:            public long maxSize;
054:
055:            public TypeMapping() {
056:            }
057:
058:            /**
059:             * Sets a fixed size for this TypeMapping.
060:             * Effectively, this sets the minimimum and maximum size of the type mapping to the specified value, ensuring this TypeMapping object
061:             * is equal to all TypeMappings whos minimum size is equal to or smaller than the size, and teh maximum size is equal to or greater
062:             * that this size.
063:             * @param size the size to set
064:             */
065:            public void setFixedSize(long size) {
066:                minSize = size;
067:                maxSize = size;
068:            }
069:
070:            // javadoc inherited
071:            public int compareTo(TypeMapping o) {
072:                TypeMapping t = o;
073:                if (!name.equals(t.name)) {
074:                    return name.compareTo(t.name);
075:                } else if (minSize != t.minSize) {
076:                    long diff = t.minSize - minSize;
077:                    if (diff == 0)
078:                        return 0;
079:                    return diff < 0 ? -1 : 1;
080:                } else if (maxSize == -1) {
081:                    if (t.maxSize == -1) {
082:                        return 0;
083:                    } else {
084:                        return -1;
085:                    }
086:                } else {
087:                    long diff = t.maxSize - maxSize;
088:                    if (diff == 0)
089:                        return 0;
090:                    return diff < 0 ? -1 : 1;
091:                }
092:            }
093:
094:            // javadoc inherited
095:            public boolean equals(Object o) {
096:                if (o == null)
097:                    return false;
098:                if (o instanceof  TypeMapping) {
099:                    TypeMapping tm = (TypeMapping) o;
100:                    // A typemapping equals another type-mapping when the one contains the other.
101:                    // Because of this the 'fixed' size type-mappings (created DatabaseStorageManager) are found by indexOf of the typeMappings Collection of DatabaseStorageManager.
102:                    // In this typeMappings Collection there are normally only 'ranged' of sizes (as defined in th XML)
103:                    return (name == null ? tm.name == null : name
104:                            .equals(tm.name))
105:                            && (((minSize >= tm.minSize || (tm.minSize <= 0)) && (maxSize <= tm.maxSize || (tm.maxSize <= 0))) // contained by.
106:                            || ((tm.minSize >= minSize || (minSize <= 0)) && (tm.maxSize <= maxSize || (maxSize <= 0))) // containing
107:                            );
108:                } else {
109:                    return false;
110:                }
111:            }
112:
113:            // javadoc inherited
114:            public int hashCode() {
115:                // because of the complicated equals implementation minSize and maxSize cannot be present in hashCode
116:                return name == null ? 0 : name.hashCode();
117:            }
118:
119:            /**
120:             * Returns the mappings type.
121:             */
122:            public String getType(long size) {
123:                return MessageFormat.format(type, new Object[] { Long
124:                        .valueOf(size) });
125:            }
126:
127:            // javadoc inherited
128:            public String toString() {
129:                return name + " (" + minSize + "," + maxSize + ")+>" + type;
130:            }
131:
132:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.