Source Code Cross Referenced for BulkSequenceKeyGeneratorImpl.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.OdalPersistencyException;
013:        import com.completex.objective.components.persistency.Persistency;
014:        import com.completex.objective.components.persistency.PersistentEntry;
015:        import com.completex.objective.components.persistency.Record;
016:        import com.completex.objective.components.persistency.core.DatabasePolicy;
017:        import com.completex.objective.components.persistency.key.ComplexSequenceKeyGenerator;
018:        import com.completex.objective.components.persistency.transact.Transaction;
019:
020:        /**
021:         * Provides basic functionaly for bulk sequence generation. 
022:         * Reserves next bulkSize sequence numbers with single call to the delegateKeyGenerator.
023:         * It is assumed that delegateKeyGenerator takes the sequence from the database.
024:         * Once chosen bulkSize must not change for the life of the application since it can cause
025:         * duplicate sequences to be generated
026:         * 
027:         * @author Gennady Krizhevsky
028:         */
029:        public abstract class BulkSequenceKeyGeneratorImpl implements 
030:                ComplexSequenceKeyGenerator {
031:
032:            public static final int DEFAULT_BULK_SIZE = 100;
033:            private int bulkSize = DEFAULT_BULK_SIZE;
034:            private long cur = 0;
035:            private long offset = 0;
036:            private int count = 0;
037:            protected ComplexSequenceKeyGenerator delegateKeyGenerator;
038:
039:            public BulkSequenceKeyGeneratorImpl(
040:                    ComplexSequenceKeyGenerator delegateKeyGenerator,
041:                    DatabasePolicy databasePolicy, int bulkSize, long offset,
042:                    Log log) {
043:                this .delegateKeyGenerator = delegateKeyGenerator;
044:                setDatabasePolicy(databasePolicy);
045:                setLogger(log);
046:                this .bulkSize = bulkSize;
047:                this .offset = offset;
048:                this .count = this .bulkSize;
049:            }
050:
051:            protected BulkSequenceKeyGeneratorImpl() {
052:            }
053:
054:            /**
055:             * Get number of sequences generated between calls to a delegateKeyGenerator
056:             * 
057:             * @return number of sequences generated between calls to a delegateKeyGenerator
058:             */
059:            public int getBulkSize() {
060:                return bulkSize;
061:            }
062:
063:            /**
064:             * Set number of sequences generated between calls to a delegateKeyGenerator
065:             * 
066:             * @param bulkSize
067:             */
068:            protected void setBulkSize(int bulkSize) {
069:                this .bulkSize = bulkSize;
070:            }
071:
072:            public long getOffset() {
073:                return offset;
074:            }
075:
076:            /**
077:             * Set offset which defines the 1st sequnce number to be generated
078:             * 
079:             * @param offset
080:             */
081:            protected void setOffset(long offset) {
082:                this .offset = offset;
083:            }
084:
085:            /**
086:             * Get current sequence value
087:             * 
088:             * @return current sequence value
089:             */
090:            public long getCurrentValue() {
091:                return cur;
092:            }
093:
094:            /**
095:             * @see ComplexSequenceKeyGenerator#setSeqName(String)  
096:             */
097:            public void setSeqName(String seqName) {
098:                delegateKeyGenerator.setSeqName(seqName);
099:            }
100:
101:            /**
102:             * @see ComplexSequenceKeyGenerator#getSeqName()  
103:             */
104:            public String getSeqName() {
105:                return delegateKeyGenerator.getSeqName();
106:            }
107:
108:            /**
109:             * Get next sequence number
110:             * 
111:             * @param transaction
112:             * @param persistency
113:             * @param object
114:             * @return next sequnce number as long
115:             * @throws OdalPersistencyException
116:             */
117:            public synchronized Long getNextKeyLong(Transaction transaction,
118:                    Persistency persistency, Object object)
119:                    throws OdalPersistencyException {
120:                long seq;
121:
122:                if (count == bulkSize || count == 0) {
123:                    seq = ((Long) delegateKeyGenerator.getNextKeyPlain(
124:                            transaction, persistency, (String) object))
125:                            .longValue();
126:                    cur = (seq - 1) * bulkSize + 1 + offset;
127:                    count = 0;
128:                } else {
129:                    cur++;
130:                }
131:                count++;
132:                return new Long(cur);
133:            }
134:
135:            /**
136:             * Get next sequence number
137:             * 
138:             * @param transaction
139:             * @param persistency
140:             * @return next key as Long
141:             * @throws OdalPersistencyException
142:             */
143:            public synchronized Long getNextKeyLong(Transaction transaction,
144:                    Persistency persistency) throws OdalPersistencyException {
145:                return getNextKeyLong(transaction, persistency,
146:                        delegateKeyGenerator.getSeqName());
147:            }
148:
149:            /**
150:             * @see com.completex.objective.components.persistency.key.KeyGenerator#getNextKey(Transaction transaction, Persistency persistency, Record record)
151:             */
152:            public Object getNextKey(Transaction transaction,
153:                    Persistency persistency, Record record)
154:                    throws OdalPersistencyException {
155:                return getNextKeyLong(transaction, persistency);
156:            }
157:
158:            /**
159:             * @see com.completex.objective.components.persistency.key.AutoKeyGenerator#getStaticParameters() 
160:             */
161:            public Object getStaticParameters() {
162:                return delegateKeyGenerator.getStaticParameters();
163:            }
164:
165:            /**
166:             * @see com.completex.objective.components.persistency.key.AutoKeyGenerator#setLogger(com.completex.objective.components.log.Log)  
167:             */
168:            public void setLogger(Log log) {
169:                delegateKeyGenerator.setLogger(log);
170:            }
171:
172:            /**
173:             * @see com.completex.objective.components.persistency.key.AutoKeyGenerator#setDatabasePolicy(com.completex.objective.components.persistency.core.DatabasePolicy)   
174:             */
175:            public void setDatabasePolicy(DatabasePolicy databasePolicy) {
176:                delegateKeyGenerator.setDatabasePolicy(databasePolicy);
177:            }
178:
179:            /**
180:             * @see com.completex.objective.components.persistency.key.ComplexSequenceKeyGenerator#getNextKeyPlain(Transaction transaction, Persistency persistency, String objectName)   
181:             */
182:            public Object getNextKeyPlain(Transaction transaction,
183:                    Persistency persistency, String objectName)
184:                    throws OdalPersistencyException {
185:                return delegateKeyGenerator.getNextKeyPlain(transaction,
186:                        persistency, objectName);
187:            }
188:
189:            /**
190:             * @see com.completex.objective.components.persistency.key.KeyGenerator#getNextKey(Transaction transaction, Persistency persistency, Record record, Object dynamicParameters)   
191:             */
192:            public Object getNextKey(Transaction transaction,
193:                    Persistency persistency, Record record,
194:                    Object dynamicParameters) throws OdalPersistencyException {
195:                return getNextKeyLong(transaction, persistency, record);
196:            }
197:
198:            /**
199:             * @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)    
200:             */
201:            public void insertValue(Transaction transaction,
202:                    Persistency persistency, PersistentEntry persistentEntry)
203:                    throws OdalPersistencyException {
204:                delegateKeyGenerator.insertValue(transaction, persistency,
205:                        persistentEntry);
206:            }
207:
208:            /**
209:             * @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)     
210:             */
211:            public void updateValue(Transaction transaction,
212:                    Persistency persistency, PersistentEntry persistentEntry,
213:                    boolean complexDirty) throws OdalPersistencyException {
214:                delegateKeyGenerator.updateValue(transaction, persistency,
215:                        persistentEntry, complexDirty);
216:            }
217:
218:            /**
219:             * @see com.completex.objective.components.persistency.key.AutoKeyGenerator#setStaticParameters(Object)      
220:             */
221:            public void setStaticParameters(Object staticParameters) {
222:                delegateKeyGenerator.setStaticParameters(staticParameters);
223:            }
224:        }
www_.ja___va2___s__.___com_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.