Source Code Cross Referenced for AbstractKeyGenerator.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.ColumnType;
017:        import com.completex.objective.components.persistency.core.DatabasePolicy;
018:        import com.completex.objective.components.persistency.key.ComplexKeyGenerator;
019:        import com.completex.objective.components.persistency.transact.Transaction;
020:
021:        import java.sql.PreparedStatement;
022:        import java.sql.ResultSet;
023:        import java.sql.SQLException;
024:
025:        /**
026:         * @author Gennady Krizhevsky
027:         */
028:        public abstract class AbstractKeyGenerator implements 
029:                ComplexKeyGenerator {
030:            //
031:            // Keys for default sequence generators
032:            //
033:            public static final String SEQ_KEY = "name";
034:            public static final String SEQ_TABLE_KEY = "table";
035:            public static final String SEQ_SAME_TRANSACTION_KEY = "sameTransaction";
036:
037:            private Object staticParameters;
038:            private DatabasePolicy databasePolicy;
039:            private Log log = Log.NULL_LOGGER;
040:            protected final Object lock = new Object();
041:            private String seqName;
042:
043:            public Object getStaticParameters() {
044:                return staticParameters;
045:            }
046:
047:            /**
048:             * Set staticParameters once
049:             *
050:             * @param staticParameters
051:             */
052:            public void setStaticParameters(Object staticParameters) {
053:                if (this .staticParameters == null && staticParameters != null) {
054:                    this .staticParameters = staticParameters;
055:                }
056:            }
057:
058:            public Log getLogger() {
059:                return log;
060:            }
061:
062:            public void setLogger(Log log) {
063:                if (this .log == null && log != null) {
064:                    this .log = log;
065:                }
066:            }
067:
068:            public DatabasePolicy getDatabasePolicy() {
069:                return databasePolicy;
070:            }
071:
072:            public void setDatabasePolicy(DatabasePolicy databasePolicy) {
073:                if (this .databasePolicy == null && databasePolicy != null) {
074:                    this .databasePolicy = databasePolicy;
075:                }
076:            }
077:
078:            /**
079:             * Closes result set if not null, releases statement
080:             * 
081:             * @param transaction
082:             * @param resultSet
083:             * @param stmt
084:             * @throws OdalPersistencyException
085:             */
086:            protected void closeAll(Transaction transaction,
087:                    ResultSet resultSet, PreparedStatement stmt)
088:                    throws OdalPersistencyException {
089:                if (resultSet != null) {
090:                    try {
091:                        resultSet.close();
092:                    } catch (SQLException e) {
093:                        log.error("Cannot close result set.", e);
094:                    }
095:                }
096:                if (stmt != null) {
097:                    try {
098:                        releaseStatement(transaction, stmt);
099:                    } catch (SQLException e) {
100:                        throw new OdalPersistencyException(e);
101:                    }
102:                }
103:            }
104:
105:            /**
106:             * Prepares statement in transaction
107:             * @see Transaction#prepareStatement(String)
108:             * 
109:             * @param transaction
110:             * @param sql
111:             * @return PreparedStatement
112:             * @throws SQLException
113:             */
114:            protected PreparedStatement prepareStatement(
115:                    Transaction transaction, String sql) throws SQLException {
116:                validate(transaction);
117:                return transaction.prepareStatement(sql);
118:            }
119:
120:            /**
121:             * Releases statement from the transaction
122:             * @see Transaction#releaseStatement(java.sql.PreparedStatement)
123:             * 
124:             * @param transaction
125:             * @param statement
126:             * @throws SQLException
127:             */
128:            protected void releaseStatement(Transaction transaction,
129:                    PreparedStatement statement) throws SQLException {
130:                validate(transaction);
131:                transaction.releaseStatement(statement);
132:            }
133:
134:            protected void validate(Transaction transaction) {
135:
136:            }
137:
138:            /**
139:             * @see com.completex.objective.components.persistency.key.KeyGenerator#getNextKey(Transaction transaction, Persistency persistency, Record record)
140:             */
141:            public abstract Object getNextKey(Transaction transaction,
142:                    Persistency persistency, Record record)
143:                    throws OdalPersistencyException;
144:
145:            /**
146:             * @see com.completex.objective.components.persistency.key.KeyGenerator#getNextKey(Transaction transaction, Persistency persistency, Record record, Object dynamicParameters)
147:             */
148:            public abstract Object getNextKey(Transaction transaction,
149:                    Persistency persistency, Record record,
150:                    Object dynamicParameters) throws OdalPersistencyException;
151:
152:            /**
153:             * @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)
154:             */
155:            public abstract void insertValue(Transaction transaction,
156:                    Persistency persistency, PersistentEntry persistentEntry)
157:                    throws OdalPersistencyException;
158:
159:            /**
160:             * @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)
161:             */
162:            public abstract void updateValue(Transaction transaction,
163:                    Persistency persistency, PersistentEntry persistentEntry,
164:                    boolean complexDirty) throws OdalPersistencyException;
165:
166:            /**
167:             * @see com.completex.objective.components.persistency.key.ComplexSequenceKeyGenerator#getNextKeyPlain(com.completex.objective.components.persistency.transact.Transaction, com.completex.objective.components.persistency.Persistency, String)
168:             */
169:            public abstract Object getNextKeyPlain(Transaction transaction,
170:                    Persistency persistency, String objectName)
171:                    throws OdalPersistencyException;
172:
173:            public void setSeqName(String seqName) {
174:                this .seqName = seqName;
175:            }
176:
177:            public String getSeqName() {
178:                return seqName;
179:            }
180:
181:            public static Object toConventional(
182:                    PersistentEntry persistentEntry, Object value) {
183:                if (value != null
184:                        && ColumnType.isString(persistentEntry.getColumn()
185:                                .getType()) && !(value instanceof  String)) {
186:                    value = value.toString();
187:                }
188:                return value;
189:            }
190:        }
w___ww.___j__a_v__a2__s__._c__om | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.