Source Code Cross Referenced for VersionSequenceKeyGeneratorImpl.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.log.Log;
012:        import com.completex.objective.components.persistency.ColumnType;
013:        import com.completex.objective.components.persistency.OdalPersistencyException;
014:        import com.completex.objective.components.persistency.Persistency;
015:        import com.completex.objective.components.persistency.PersistentEntry;
016:        import com.completex.objective.components.persistency.Record;
017:        import com.completex.objective.components.persistency.core.DatabasePolicy;
018:        import com.completex.objective.components.persistency.key.ComplexSequenceKeyGenerator;
019:        import com.completex.objective.components.persistency.transact.Transaction;
020:        import com.completex.objective.util.PropertyMap;
021:
022:        import java.util.Map;
023:
024:        /**
025:         * Sequence based version generator - decorator for ComplexSequenceKeyGenerator
026:         * <p/>
027:         * Example of key generator section:
028:         * <p/>
029:         * <br> 
030:         * <PRE>
031:         * keyGenerator = {
032:         *    class = com.completex.objective.components.persistency.key.impl.VersionSequenceKeyGeneratorImpl
033:         *    staticAttributes = {
034:         *       name = CONTACT_SEQ
035:         *       alwaysGenerate = TRUE # or FALSE
036:         *    }
037:         * }
038:         * </PRE>
039:         *
040:         * @author Gennady Krizhevsky
041:         */
042:        public class VersionSequenceKeyGeneratorImpl implements 
043:                ComplexSequenceKeyGenerator {
044:            public static final String TAG_ALWAYS_GENERATE = "alwaysGenerate";
045:
046:            protected boolean alwaysGenerate;
047:
048:            protected ComplexSequenceKeyGenerator delegateKeyGenerator;
049:
050:            /**
051:             * @param delegateKeyGenerator
052:             * @param databasePolicy
053:             * @param seqName
054:             * @param logger
055:             */
056:            public VersionSequenceKeyGeneratorImpl(
057:                    ComplexSequenceKeyGenerator delegateKeyGenerator,
058:                    DatabasePolicy databasePolicy, String seqName, Log logger) {
059:                this .delegateKeyGenerator = delegateKeyGenerator;
060:                this .delegateKeyGenerator.setDatabasePolicy(databasePolicy);
061:                this .delegateKeyGenerator.setSeqName(seqName);
062:                this .delegateKeyGenerator.setLogger(logger);
063:            }
064:
065:            public VersionSequenceKeyGeneratorImpl() {
066:            }
067:
068:            /**
069:             * @see ComplexSequenceKeyGenerator#getSeqName()
070:             */
071:            public String getSeqName() {
072:                return delegateKeyGenerator.getSeqName();
073:            }
074:
075:            /**
076:             * @see ComplexSequenceKeyGenerator#getNextKeyPlain(Transaction transaction, Persistency persistency, String objectName)
077:             */
078:            public Object getNextKeyPlain(Transaction transaction,
079:                    Persistency persistency, String objectName)
080:                    throws OdalPersistencyException {
081:                return delegateKeyGenerator.getNextKeyPlain(transaction,
082:                        persistency, objectName);
083:            }
084:
085:            /**
086:             * Populates value if (persistentEntry.getValue() == null || ((Number) persistentEntry.getValue()).longValue() <= 0)
087:             *
088:             * @see com.completex.objective.components.persistency.key.AutoKeyGenerator#insertValue(com.completex.objective.components.persistency.transact.Transaction, com.completex.objective.components.persistency.Persistency, com.completex.objective.components.persistency.PersistentEntry)
089:             */
090:            public void insertValue(Transaction transaction,
091:                    Persistency persistency, PersistentEntry persistentEntry)
092:                    throws OdalPersistencyException {
093:                if (isInsertConditionSatisfied0(persistentEntry)) {
094:                    Object nextKey = getNextKey(transaction, persistency,
095:                            persistentEntry.getRecord());
096:                    persistentEntry.setValue(AbstractKeyGenerator
097:                            .toConventional(persistentEntry, nextKey));
098:                }
099:            }
100:
101:            protected boolean isInsertConditionSatisfied0(
102:                    PersistentEntry persistentEntry) {
103:                return AbstractSequenceKeyGenerator
104:                        .isInsertConditionSatisfied(persistentEntry);
105:            }
106:
107:            /**
108:             * Populates value when the condition (persistentEntry.getRecord().isDirty() || isAlwaysGenerate()) is true
109:             * and the condition (persistentEntry.getValue() == null or not persistentEntry.isDirty()) is true.
110:             *
111:             * @see com.completex.objective.components.persistency.key.AutoKeyGenerator#updateValue(com.completex.objective.components.persistency.transact.Transaction, com.completex.objective.components.persistency.Persistency, com.completex.objective.components.persistency.PersistentEntry, boolean)
112:             */
113:            public void updateValue(Transaction transaction,
114:                    Persistency persistency, PersistentEntry persistentEntry,
115:                    boolean complexDirty) throws OdalPersistencyException {
116:                if (persistentEntry.getRecord() != null
117:                        && (persistentEntry.getRecord().isDirty() || alwaysGenerate)) {
118:                    if (persistentEntry.getValue() == null
119:                            || !persistentEntry.isDirty()
120:                            || (ColumnType.isNumeric(persistentEntry
121:                                    .getColumn().getType()) && ((Number) persistentEntry
122:                                    .getValue()).longValue() <= 0)) {
123:                        persistentEntry.setValue(getNextKey(transaction,
124:                                persistency, persistentEntry.getRecord()));
125:                    }
126:                }
127:            }
128:
129:            //
130:            // Delegate:
131:            //
132:
133:            /**
134:             * @see com.completex.objective.components.persistency.key.KeyGenerator#getNextKey(Transaction transaction, Persistency persistency, Record record)
135:             */
136:            public Object getNextKey(Transaction transaction,
137:                    Persistency persistency, Record record)
138:                    throws OdalPersistencyException {
139:                return delegateKeyGenerator.getNextKey(transaction,
140:                        persistency, record);
141:            }
142:
143:            /**
144:             * @see com.completex.objective.components.persistency.key.KeyGenerator#getNextKey(Transaction transaction, Persistency persistency, Record record, Object dynamicParameters)
145:             */
146:            public Object getNextKey(Transaction transaction,
147:                    Persistency persistency, Record record,
148:                    Object dynamicParameters) throws OdalPersistencyException {
149:                return delegateKeyGenerator.getNextKey(transaction,
150:                        persistency, record, dynamicParameters);
151:            }
152:
153:            /**
154:             * @see com.completex.objective.components.persistency.key.AutoKeyGenerator#setStaticParameters(Object staticParameters)
155:             */
156:            public void setStaticParameters(Object staticParameters) {
157:                delegateKeyGenerator.setStaticParameters(staticParameters);
158:                if (staticParameters != null) {
159:                    Map parameters = (Map) staticParameters;
160:                    PropertyMap propertyMap = PropertyMap
161:                            .toPropertyMap(parameters);
162:                    alwaysGenerate = propertyMap
163:                            .getBoolean(TAG_ALWAYS_GENERATE);
164:                }
165:            }
166:
167:            /**
168:             * @see com.completex.objective.components.persistency.key.AutoKeyGenerator#getStaticParameters()
169:             */
170:            public Object getStaticParameters() {
171:                return delegateKeyGenerator.getStaticParameters();
172:            }
173:
174:            /**
175:             * @see com.completex.objective.components.persistency.key.AutoKeyGenerator#setDatabasePolicy(com.completex.objective.components.persistency.core.DatabasePolicy)
176:             */
177:            public void setDatabasePolicy(DatabasePolicy databasePolicy) {
178:                delegateKeyGenerator.setDatabasePolicy(databasePolicy);
179:            }
180:
181:            /**
182:             * @see com.completex.objective.components.persistency.key.AutoKeyGenerator#setLogger(com.completex.objective.components.log.Log)
183:             */
184:            public void setLogger(Log log) {
185:                delegateKeyGenerator.setLogger(log);
186:            }
187:
188:            /**
189:             * @see ComplexSequenceKeyGenerator#setSeqName(String)
190:             */
191:            public void setSeqName(String seqName) {
192:                delegateKeyGenerator.setSeqName(seqName);
193:            }
194:
195:            /**
196:             * Returns true if the version value has to be populated even if Record is not dirty
197:             *
198:             * @return true if the version value has to be populated even if Record is not dirty
199:             */
200:            public boolean isAlwaysGenerate() {
201:                return alwaysGenerate;
202:            }
203:
204:            /**
205:             * Set true if the version value has to be populated even if Record is not dirty
206:             *
207:             * @param alwaysGenerate true if the version value has to be populated even if Record is not dirty
208:             */
209:            public void setAlwaysGenerate(boolean alwaysGenerate) {
210:                this.alwaysGenerate = alwaysGenerate;
211:            }
212:        }
w__ww_._j___ava_2___s._com___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.