Source Code Cross Referenced for DefaultNaturalKeyFactory.java in  » Database-ORM » ODAL » com » completex » objective » components » persistency » key » impl » 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 » ODAL » com.completex.objective.components.persistency.key.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         *  Objective Database Abstraction Layer (ODAL)
003:         *  Copyright (c) 2004, The ODAL Development Group
004:         *  All rights reserved.
005:         *  For definition of the ODAL Development Group please refer to LICENCE.txt file
006:         *
007:         *  Distributable under LGPL license.
008:         *  See terms of license at gnu.org.
009:         */package com.completex.objective.components.persistency.key.impl;
010:
011:        import com.completex.objective.components.persistency.AbstractPersistentObject;
012:        import com.completex.objective.components.persistency.CompoundPersistentObject;
013:        import com.completex.objective.components.persistency.MetaTable;
014:        import com.completex.objective.components.persistency.OdalRuntimePersistencyException;
015:        import com.completex.objective.components.persistency.PersistentObject;
016:        import com.completex.objective.components.persistency.Record;
017:        import com.completex.objective.components.persistency.key.SimpleNaturalKeyFactory;
018:        import com.completex.objective.components.persistency.key.SimpleNaturalKey;
019:
020:        /**
021:         * Default Natural Key Factory, used in AbstractPersistentObject and its descendants to create keys
022:         *
023:         * @author Gennady Krizhevsky
024:         */
025:        public class DefaultNaturalKeyFactory {
026:
027:            private static final SimpleNaturalKeyFactory DEFAULT_SIMPLE_NATURAL_KEY_FACTORY = new SimpleNaturalKeyFactoryImpl();
028:
029:            private DefaultNaturalKeyFactory() {
030:            }
031:
032:            /**
033:             * @param abstractPersistent
034:             * @param className
035:             * @param values
036:             * @return new natural key
037:             */
038:            public static Object naturalKey(
039:                    AbstractPersistentObject abstractPersistent,
040:                    String className, Object[] values) {
041:                return naturalKey(abstractPersistent,
042:                        DEFAULT_SIMPLE_NATURAL_KEY_FACTORY, className, values);
043:            }
044:
045:            /**
046:             * @param abstractPersistent
047:             * @return new natural key
048:             */
049:            public static Object naturalKey(
050:                    AbstractPersistentObject abstractPersistent) {
051:                return naturalKey(abstractPersistent, null);
052:            }
053:
054:            /**
055:             * @param abstractPersistent
056:             * @param keyIndeces
057:             * @return new natural key
058:             */
059:            public static Object naturalKey(
060:                    AbstractPersistentObject abstractPersistent,
061:                    int[] keyIndeces) {
062:                return naturalKey(abstractPersistent,
063:                        DEFAULT_SIMPLE_NATURAL_KEY_FACTORY, keyIndeces);
064:            }
065:
066:            /**
067:             * @param abstractPersistent
068:             * @param simpleNaturalKeyFactory
069:             * @param keyIndeces
070:             * @return new natural key
071:             */
072:            public static Object naturalKey(
073:                    AbstractPersistentObject abstractPersistent,
074:                    SimpleNaturalKeyFactory simpleNaturalKeyFactory,
075:                    int[] keyIndeces) {
076:                Object naturalKey;
077:                if (abstractPersistent.compound()) {
078:                    naturalKey = compoundNaturalKey(abstractPersistent,
079:                            simpleNaturalKeyFactory, keyIndeces);
080:                } else if (abstractPersistent instanceof  PersistentObject) {
081:                    naturalKey = simpleNaturalKey(simpleNaturalKeyFactory,
082:                            abstractPersistent, keyIndeces);
083:                } else {
084:                    throw new OdalRuntimePersistencyException(
085:                            "Unsupported natural key type "
086:                                    + abstractPersistent);
087:                }
088:                return naturalKey;
089:            }
090:
091:            private static Object compoundNaturalKey(
092:                    AbstractPersistentObject abstractPersistent,
093:                    SimpleNaturalKeyFactory simpleNaturalKeyFactory,
094:                    int[] keyIndeces) {
095:                Object naturalKey;
096:                SimpleNaturalKey firstKey = null;
097:                if (abstractPersistent instanceof  PersistentObject) {
098:                    firstKey = simpleNaturalKey(simpleNaturalKeyFactory,
099:                            abstractPersistent, keyIndeces);
100:                }
101:                naturalKey = new CompoundNaturalKeyImpl(abstractPersistent
102:                        .getClass(), firstKey, abstractPersistent
103:                        .compoundEntries());
104:                return naturalKey;
105:            }
106:
107:            private static Object compoundNaturalKey(
108:                    AbstractPersistentObject abstractPersistent,
109:                    String className,
110:                    SimpleNaturalKeyFactory simpleNaturalKeyFactory,
111:                    Object[] values) {
112:                Object naturalKey;
113:                SimpleNaturalKey firstKey = null;
114:                if (abstractPersistent instanceof  PersistentObject) {
115:                    firstKey = simpleNaturalKeyFactory.newSimpleNaturalKey(
116:                            className, values);
117:                }
118:                naturalKey = new CompoundNaturalKeyImpl(abstractPersistent
119:                        .getClass(), firstKey, abstractPersistent
120:                        .compoundEntries());
121:                return naturalKey;
122:            }
123:
124:            public static SimpleNaturalKey simpleNaturalKey(
125:                    SimpleNaturalKeyFactory simpleNaturalKeyFactory,
126:                    AbstractPersistentObject abstractPersistent,
127:                    int[] keyIndeces) {
128:                return simpleNaturalKeyFactory.newSimpleNaturalKey(
129:                        (PersistentObject) abstractPersistent, keyIndeces);
130:            }
131:
132:            /**
133:             * @param abstractPersistent
134:             * @param simpleNaturalKeyFactory
135:             * @param className
136:             * @param values
137:             * @return new natural key
138:             */
139:            public static Object naturalKey(
140:                    AbstractPersistentObject abstractPersistent,
141:                    SimpleNaturalKeyFactory simpleNaturalKeyFactory,
142:                    String className, Object[] values) {
143:                Object naturalKey;
144:                if (abstractPersistent.compound()) {
145:                    naturalKey = compoundNaturalKey(abstractPersistent,
146:                            className, simpleNaturalKeyFactory, values);
147:                } else if (abstractPersistent instanceof  PersistentObject) {
148:                    naturalKey = simpleNaturalKeyFactory.newSimpleNaturalKey(
149:                            className, values);
150:                } else {
151:                    throw new OdalRuntimePersistencyException(
152:                            "Unsupported natural key type "
153:                                    + abstractPersistent);
154:                }
155:                return naturalKey;
156:            }
157:
158:            public static void main(String[] args) {
159:                CompoundPersistentObject compound = new CompoundPersistentObject(
160:                        new PersistentObject[0]);
161:                PersistentObject persistent = new PersistentObject(new Record(
162:                        new MetaTable("test", "test")));
163:
164:                Object naturalKey;
165:                naturalKey = DefaultNaturalKeyFactory.naturalKey(compound);
166:                System.out.println("naturalKey = " + naturalKey);
167:                naturalKey = DefaultNaturalKeyFactory.naturalKey(persistent);
168:                System.out.println("naturalKey = " + naturalKey);
169:            }
170:        }
ww_w___.ja__v_a__2_s_.___c_o__m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.