Source Code Cross Referenced for PropertyFactory.java in  » Database-ORM » hibernate » org » hibernate » tuple » 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 » hibernate » org.hibernate.tuple 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // $Id: PropertyFactory.java 10119 2006-07-14 00:09:19Z steve.ebersole@jboss.com $
002:        package org.hibernate.tuple;
003:
004:        import java.lang.reflect.Constructor;
005:
006:        import org.hibernate.EntityMode;
007:        import org.hibernate.mapping.PropertyGeneration;
008:        import org.hibernate.engine.IdentifierValue;
009:        import org.hibernate.engine.UnsavedValueFactory;
010:        import org.hibernate.engine.VersionValue;
011:        import org.hibernate.id.IdentifierGenerator;
012:        import org.hibernate.mapping.KeyValue;
013:        import org.hibernate.mapping.PersistentClass;
014:        import org.hibernate.mapping.Property;
015:        import org.hibernate.property.Getter;
016:        import org.hibernate.property.PropertyAccessor;
017:        import org.hibernate.property.PropertyAccessorFactory;
018:        import org.hibernate.type.AssociationType;
019:        import org.hibernate.type.Type;
020:        import org.hibernate.type.VersionType;
021:        import org.hibernate.util.ReflectHelper;
022:
023:        /**
024:         * Responsible for generation of runtime metamodel {@link Property} representations.
025:         * Makes distinction between identifier, version, and other (standard) properties.
026:         *
027:         * @author Steve Ebersole
028:         */
029:        public class PropertyFactory {
030:
031:            /**
032:             * Generates an IdentifierProperty representation of the for a given entity mapping.
033:             *
034:             * @param mappedEntity The mapping definition of the entity.
035:             * @param generator The identifier value generator to use for this identifier.
036:             * @return The appropriate IdentifierProperty definition.
037:             */
038:            public static IdentifierProperty buildIdentifierProperty(
039:                    PersistentClass mappedEntity, IdentifierGenerator generator) {
040:
041:                String mappedUnsavedValue = mappedEntity.getIdentifier()
042:                        .getNullValue();
043:                Type type = mappedEntity.getIdentifier().getType();
044:                Property property = mappedEntity.getIdentifierProperty();
045:
046:                IdentifierValue unsavedValue = UnsavedValueFactory
047:                        .getUnsavedIdentifierValue(mappedUnsavedValue,
048:                                getGetter(property), type,
049:                                getConstructor(mappedEntity));
050:
051:                if (property == null) {
052:                    // this is a virtual id property...
053:                    return new IdentifierProperty(type, mappedEntity
054:                            .hasEmbeddedIdentifier(), mappedEntity
055:                            .hasIdentifierMapper(), unsavedValue, generator);
056:                } else {
057:                    return new IdentifierProperty(property.getName(), property
058:                            .getNodeName(), type, mappedEntity
059:                            .hasEmbeddedIdentifier(), unsavedValue, generator);
060:                }
061:            }
062:
063:            /**
064:             * Generates a VersionProperty representation for an entity mapping given its
065:             * version mapping Property.
066:             *
067:             * @param property The version mapping Property.
068:             * @param lazyAvailable Is property lazy loading currently available.
069:             * @return The appropriate VersionProperty definition.
070:             */
071:            public static VersionProperty buildVersionProperty(
072:                    Property property, boolean lazyAvailable) {
073:                String mappedUnsavedValue = ((KeyValue) property.getValue())
074:                        .getNullValue();
075:
076:                VersionValue unsavedValue = UnsavedValueFactory
077:                        .getUnsavedVersionValue(mappedUnsavedValue,
078:                                getGetter(property), (VersionType) property
079:                                        .getType(), getConstructor(property
080:                                        .getPersistentClass()));
081:
082:                boolean lazy = lazyAvailable && property.isLazy();
083:
084:                return new VersionProperty(
085:                        property.getName(),
086:                        property.getNodeName(),
087:                        property.getValue().getType(),
088:                        lazy,
089:                        property.isInsertable(),
090:                        property.isUpdateable(),
091:                        property.getGeneration() == PropertyGeneration.INSERT
092:                                || property.getGeneration() == PropertyGeneration.ALWAYS,
093:                        property.getGeneration() == PropertyGeneration.ALWAYS,
094:                        property.isOptional(),
095:                        property.isUpdateable() && !lazy, property
096:                                .isOptimisticLocked(), property
097:                                .getCascadeStyle(), unsavedValue);
098:            }
099:
100:            /**
101:             * Generate a "standard" (i.e., non-identifier and non-version) based on the given
102:             * mapped property.
103:             *
104:             * @param property The mapped property.
105:             * @param lazyAvailable Is property lazy loading currently available.
106:             * @return The appropriate StandardProperty definition.
107:             */
108:            public static StandardProperty buildStandardProperty(
109:                    Property property, boolean lazyAvailable) {
110:
111:                final Type type = property.getValue().getType();
112:
113:                // we need to dirty check collections, since they can cause an owner
114:                // version number increment
115:
116:                // we need to dirty check many-to-ones with not-found="ignore" in order 
117:                // to update the cache (not the database), since in this case a null
118:                // entity reference can lose information
119:
120:                boolean alwaysDirtyCheck = type.isAssociationType()
121:                        && ((AssociationType) type).isAlwaysDirtyChecked();
122:
123:                return new StandardProperty(
124:                        property.getName(),
125:                        property.getNodeName(),
126:                        type,
127:                        lazyAvailable && property.isLazy(),
128:                        property.isInsertable(),
129:                        property.isUpdateable(),
130:                        property.getGeneration() == PropertyGeneration.INSERT
131:                                || property.getGeneration() == PropertyGeneration.ALWAYS,
132:                        property.getGeneration() == PropertyGeneration.ALWAYS,
133:                        property.isOptional(), alwaysDirtyCheck
134:                                || property.isUpdateable(), property
135:                                .isOptimisticLocked(), property
136:                                .getCascadeStyle(), property.getValue()
137:                                .getFetchMode());
138:            }
139:
140:            private static Constructor getConstructor(
141:                    PersistentClass persistentClass) {
142:                if (persistentClass == null
143:                        || !persistentClass.hasPojoRepresentation()) {
144:                    return null;
145:                }
146:
147:                try {
148:                    return ReflectHelper.getDefaultConstructor(persistentClass
149:                            .getMappedClass());
150:                } catch (Throwable t) {
151:                    return null;
152:                }
153:            }
154:
155:            private static Getter getGetter(Property mappingProperty) {
156:                if (mappingProperty == null
157:                        || !mappingProperty.getPersistentClass()
158:                                .hasPojoRepresentation()) {
159:                    return null;
160:                }
161:
162:                PropertyAccessor pa = PropertyAccessorFactory
163:                        .getPropertyAccessor(mappingProperty, EntityMode.POJO);
164:                return pa.getGetter(mappingProperty.getPersistentClass()
165:                        .getMappedClass(), mappingProperty.getName());
166:            }
167:
168:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.