Source Code Cross Referenced for AbstractSequenceManager.java in  » Database-ORM » db-ojb » org » apache » ojb » broker » util » sequence » 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 » db ojb » org.apache.ojb.broker.util.sequence 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.apache.ojb.broker.util.sequence;
002:
003:        /* Copyright 2002-2005 The Apache Software Foundation
004:         *
005:         * Licensed under the Apache License, Version 2.0 (the "License");
006:         * you may not use this file except in compliance with the License.
007:         * You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:
018:        import java.util.Properties;
019:
020:        import org.apache.ojb.broker.PersistenceBroker;
021:        import org.apache.ojb.broker.accesslayer.JdbcAccess;
022:        import org.apache.ojb.broker.metadata.ClassDescriptor;
023:        import org.apache.ojb.broker.metadata.FieldDescriptor;
024:        import org.apache.ojb.broker.metadata.SequenceDescriptor;
025:        import org.apache.ojb.broker.platforms.Platform;
026:
027:        /**
028:         * A base class for sequence manager implementations.
029:         * <br/>
030:         * All sequence manager implementations need a constructor
031:         * with a PersistenceBroker argument used by the
032:         * {@link org.apache.ojb.broker.util.sequence.SequenceManagerFactory}.
033:         *
034:         * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
035:         * @version $Id: AbstractSequenceManager.java,v 1.17.2.3 2005/12/21 22:28:41 tomdz Exp $
036:         */
037:        public abstract class AbstractSequenceManager implements 
038:                SequenceManager {
039:            // private Logger log = LoggerFactory.getLogger(AbstractSequenceManager.class);
040:            public static final String PROPERTY_AUTO_NAMING = "autoNaming";
041:            protected static final String GLOBAL_SEQUENCE_NAME = "ojb.global.sequence";
042:
043:            private PersistenceBroker brokerForClass;
044:            private Platform platform;
045:            private Properties configurationProperties;
046:
047:            /**
048:             * Constructor used by
049:             * {@link org.apache.ojb.broker.util.sequence.SequenceManagerFactory}
050:             *
051:             * @param broker  PB instance to perform the
052:             * id generation.
053:             */
054:            public AbstractSequenceManager(PersistenceBroker broker) {
055:                this .brokerForClass = broker;
056:                this .configurationProperties = new Properties();
057:                this .platform = brokerForClass.serviceConnectionManager()
058:                        .getSupportedPlatform();
059:                SequenceDescriptor sd = brokerForClass
060:                        .serviceConnectionManager().getConnectionDescriptor()
061:                        .getSequenceDescriptor();
062:                if (sd != null) {
063:                    this .configurationProperties.putAll(sd
064:                            .getConfigurationProperties());
065:                }
066:            }
067:
068:            /**
069:             * returns a unique long value for field.
070:             * the returned number is unique accross all tables in the extent of clazz.
071:             */
072:            abstract protected long getUniqueLong(FieldDescriptor field)
073:                    throws SequenceManagerException;
074:
075:            public Platform getPlatform() {
076:                return platform;
077:            }
078:
079:            public PersistenceBroker getBrokerForClass() {
080:                return brokerForClass;
081:            }
082:
083:            public Properties getConfigurationProperties() {
084:                return this .configurationProperties;
085:            }
086:
087:            public void setConfigurationProperties(Properties prop) {
088:                this .configurationProperties.putAll(prop);
089:            }
090:
091:            public String getConfigurationProperty(String key,
092:                    String defaultValue) {
093:                String result = this .configurationProperties.getProperty(key);
094:                return result != null ? result : defaultValue;
095:            }
096:
097:            public void setConfigurationProperty(String key, String value) {
098:                this .configurationProperties.setProperty(key, value);
099:            }
100:
101:            public boolean useAutoNaming() {
102:                return (Boolean.valueOf(getConfigurationProperty(
103:                        PROPERTY_AUTO_NAMING, "true"))).booleanValue();
104:            }
105:
106:            public String calculateSequenceName(FieldDescriptor field)
107:                    throws SequenceManagerException {
108:                String seqName;
109:                seqName = field.getSequenceName();
110:                /*
111:                if we found no sequence name for the given field, we try to
112:                assign a automatic generated sequence name.
113:                 */
114:                if (seqName == null) {
115:                    seqName = SequenceManagerHelper.buildSequenceName(
116:                            getBrokerForClass(), field, useAutoNaming());
117:                    // already done in method above
118:                    // if(useAutoNaming()) field.setSequenceName(seqName);
119:                }
120:                return seqName;
121:            }
122:
123:            //****************************************************************
124:            // method implementations of SequenceManager interface
125:            //****************************************************************
126:            /**
127:             * Returns a unique object for the given field attribute.
128:             * The returned value takes in account the jdbc-type
129:             * and the FieldConversion.sql2java() conversion defined for <code>field</code>.
130:             * The returned object is unique accross all tables in the extent
131:             * of class the field belongs to.
132:             */
133:            public Object getUniqueValue(FieldDescriptor field)
134:                    throws SequenceManagerException {
135:                Object result = field.getJdbcType().sequenceKeyConversion(
136:                        new Long(getUniqueLong(field)));
137:                // perform a sql to java conversion here, so that clients do
138:                // not see any db specific values
139:                result = field.getFieldConversion().sqlToJava(result);
140:                return result;
141:            }
142:
143:            /**
144:             * noop
145:             */
146:            public void afterStore(JdbcAccess dbAccess, ClassDescriptor cld,
147:                    Object obj) throws SequenceManagerException {
148:                // do nothing
149:            }
150:
151:            /**
152:             * noop
153:             */
154:            public void setReferenceFKs(Object obj, ClassDescriptor cld)
155:                    throws SequenceManagerException {
156:                // do nothing
157:            }
158:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.