Source Code Cross Referenced for DiscriminatorMapping.java in  » Database-ORM » JPOX » org » jpox » store » mapping » 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 » JPOX » org.jpox.store.mapping 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**********************************************************************
002:        Copyright (c) 2004 Andy Jefferson and others. All rights reserved. 
003:        Licensed under the Apache License, Version 2.0 (the "License");
004:        you may not use this file except in compliance with the License.
005:        You may obtain a copy of the License at
006:
007:            http://www.apache.org/licenses/LICENSE-2.0
008:
009:        Unless required by applicable law or agreed to in writing, software
010:        distributed under the License is distributed on an "AS IS" BASIS,
011:        WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012:        See the License for the specific language governing permissions and
013:        limitations under the License. 
014:
015:
016:        Contributors:
017:        2005 Andy Jefferson - added capability to have String or long type discriminators
018:            ...
019:         **********************************************************************/package org.jpox.store.mapping;
020:
021:        import org.jpox.ClassLoaderResolver;
022:        import org.jpox.ClassNameConstants;
023:        import org.jpox.ObjectManager;
024:        import org.jpox.metadata.ColumnMetaData;
025:        import org.jpox.metadata.DiscriminatorMetaData;
026:        import org.jpox.store.DatastoreContainerObject;
027:        import org.jpox.store.DatastoreField;
028:        import org.jpox.store.DatastoreAdapter;
029:        import org.jpox.store.DatastoreIdentifier;
030:        import org.jpox.store.IdentifierFactory;
031:        import org.jpox.store.expression.QueryExpression;
032:        import org.jpox.store.expression.ScalarExpression;
033:        import org.jpox.store.expression.LogicSetExpression;
034:
035:        /**
036:         * Mapping for a discriminator column in a table used in inheritance.
037:         * The discriminator column is, by default, a String type, typically VARCHAR.
038:         * It can however be "long" based if the user specifies INTEGER, BIGINT, or NUMERIC as the jdbc-type. 
039:         * In the latter case we make the necessary conversions between value types in this mapping class.
040:         * 
041:         * This class is for internal use only. It should not be used in user mappings nor extended. 
042:         * 
043:         * @version $Revision: 1.34 $
044:         */
045:        public final class DiscriminatorMapping extends SingleFieldMapping {
046:            private final JavaTypeMapping delegate;
047:
048:            /**
049:             * Constructor.
050:             * @param dba Datastore Adapter
051:             * @param datastoreContainer Datastore table
052:             * @param delegate The JavaTypeMapping to delegate storage
053:             */
054:            public DiscriminatorMapping(DatastoreAdapter dba,
055:                    DatastoreContainerObject datastoreContainer,
056:                    JavaTypeMapping delegate) {
057:                initialize(dba, delegate.getType());
058:                this .delegate = delegate;
059:
060:                DiscriminatorMetaData dismd = datastoreContainer
061:                        .getDiscriminatorMetaData();
062:                IdentifierFactory idFactory = datastoreContainer
063:                        .getStoreManager().getIdentifierFactory();
064:                DatastoreIdentifier id = null;
065:                if (dismd.getColumnMetaData() == null) {
066:                    // No column name so generate a default
067:                    id = idFactory.newDiscriminatorFieldIdentifier();
068:                    ColumnMetaData colmd = new ColumnMetaData(dismd, id
069:                            .getIdentifier());
070:                    dismd.setColumnMetaData(colmd);
071:                } else {
072:                    // Column name defined
073:                    ColumnMetaData colmd = dismd.getColumnMetaData();
074:                    id = idFactory.newDatastoreFieldIdentifier(colmd.getName());
075:                }
076:
077:                DatastoreField column = datastoreContainer.addDatastoreField(
078:                        getType(), id, this , dismd.getColumnMetaData());
079:                datastoreContainer.getStoreManager().getMappingManager()
080:                        .createDatastoreMapping(delegate,
081:                                datastoreContainer.getStoreManager(), column,
082:                                getType());
083:            }
084:
085:            /**
086:             * Accessor for the type represented here, returning the class itself
087:             * @return This class.
088:             */
089:            public Class getJavaType() {
090:                return DiscriminatorMapping.class;
091:            }
092:
093:            /**
094:             * Accessor for a sample value for this type.
095:             * @return Sample value
096:             */
097:            public Object getSampleValue(ClassLoaderResolver clr) {
098:                return delegate.getSampleValue(clr);
099:            }
100:
101:            /**
102:             * Accessor for a new literal for this mapping.
103:             * @param qs The QueryStatement
104:             * @param value The value of the object
105:             * @return The new literal
106:             */
107:            public ScalarExpression newLiteral(QueryExpression qs, Object value) {
108:                Object valueObj = value;
109:                if (value instanceof  java.lang.String
110:                        && (getType().equals(ClassNameConstants.LONG) || getType()
111:                                .equals(ClassNameConstants.JAVA_LANG_LONG))) {
112:                    valueObj = new Long((String) value);
113:                }
114:                return delegate.newLiteral(qs, valueObj);
115:            }
116:
117:            /**
118:             * Accessor for a new scalar expression including this mapping.
119:             * @param qs The QueryStatement
120:             * @param te The table Expression
121:             * @return The new scalar expression
122:             */
123:            public ScalarExpression newScalarExpression(QueryExpression qs,
124:                    LogicSetExpression te) {
125:                return delegate.newScalarExpression(qs, te);
126:            }
127:
128:            /**
129:             * Mutator for the object in this column
130:             * @param om The Object Manager
131:             * @param preparedStatement The statement
132:             * @param exprIndex The indexes
133:             * @param value The value to set it to
134:             */
135:            public void setObject(ObjectManager om, Object preparedStatement,
136:                    int[] exprIndex, Object value) {
137:                Object valueObj = value;
138:                if (value instanceof  java.lang.String) {
139:                    if (getType().equals(ClassNameConstants.LONG)
140:                            || getType().equals(
141:                                    ClassNameConstants.JAVA_LANG_LONG)) {
142:                        valueObj = new Long((String) value);
143:                    }
144:                }
145:                delegate.setObject(om, preparedStatement, exprIndex, valueObj);
146:            }
147:
148:            /**
149:             * Accessor for the object in this column
150:             * @param om The ObjectManager
151:             * @param resultSet The ResultSet to get the value from
152:             * @param exprIndex The indexes
153:             * @return The object
154:             */
155:            public Object getObject(ObjectManager om, Object resultSet,
156:                    int[] exprIndex) {
157:                Object value = delegate.getObject(om, resultSet, exprIndex);
158:                Object valueObj = value;
159:                if (value instanceof  java.lang.String) {
160:                    if (getType().equals(ClassNameConstants.LONG)
161:                            || getType().equals(
162:                                    ClassNameConstants.JAVA_LANG_LONG)) {
163:                        valueObj = new Long((String) value);
164:                    }
165:                }
166:                return valueObj;
167:            }
168:
169:            /**
170:             * Accessor for the number of datastore fields.
171:             * @return Number of datastore fields
172:             */
173:            public int getNumberOfDatastoreFields() {
174:                return delegate.getNumberOfDatastoreFields();
175:            }
176:
177:            /**
178:             * Accessor for a datastore mapping
179:             * @param index Index of the mapping
180:             * @return The datastore mapping.
181:             */
182:            public DatastoreMapping getDataStoreMapping(int index) {
183:                return delegate.getDataStoreMapping(index);
184:            }
185:
186:            /**
187:             * Mutator to add a datastore mapping
188:             * @param datastoreMapping Datastore mapping
189:             */
190:            public void addDataStoreMapping(DatastoreMapping datastoreMapping) {
191:                delegate.addDataStoreMapping(datastoreMapping);
192:            }
193:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.