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 org.apache.ojb.broker.accesslayer.JdbcAccess;
019    import org.apache.ojb.broker.metadata.ClassDescriptor;
020    import org.apache.ojb.broker.metadata.FieldDescriptor;
021    
022    /**
023     * SequenceManagers are responsible for creating new unique
024     * ID's - unique accross all "extent" object declarations in OJB metadata.
025     * There are some standard sequence manager implementations in
026     * this package.
027     * <p/>
028     * SequenceManager objects are obtained from a factory class called
029     * {@link SequenceManagerFactory}.
030     * This Factory can be configured to provide instances of user defined
031     * implementors of this interface.
032     * <p/>
033     * NOTE: SequenceManagers should be aware of "extents" ("extent" is an OJB inheritance feature),
034     * that is: if you ask for an uid for an Interface (more exact for one implementor class)
035     * with several implementor classes, or a baseclass with several subclasses the returned uid
036     * should be unique accross all tables representing objects of the extent in question.
037     *
038     * @version $Id: SequenceManager.java,v 1.1 2007-08-24 22:17:29 ewestfal Exp $
039     */
040    public interface SequenceManager
041    {
042        /**
043         * This method is called to get an unique value <strong>before</strong> the object
044         * is written to persistent storage.
045         * <br/>
046         * Returns a unique object for the given field attribute.
047         * The returned value takes in account the jdbc-type
048         * and the FieldConversion.sql2java() conversion defined for <code>field</code>.
049         * The returned object is unique accross all tables of "extent" classes the
050         * field belongs to.
051         * <br/>
052         * Implementations using native identity columns should return a unique
053         * incremented counter object for temporary use by OJB.
054         */
055        public Object getUniqueValue(FieldDescriptor field) throws SequenceManagerException;
056    
057        /**
058         * This method is called <strong>after</strong> the object was written to the persistent storage.
059         * <br/>
060         * This is to support native Identity columns (auto_increment columns) on the db side.
061         * Other implementations may ignore this method.
062         * @param dbAccess Current used {@link org.apache.ojb.broker.accesslayer.JdbcAccess} instance
063         * @param cld Descriptor for specified object
064         * @param obj The object to associate with identity value
065         */
066        public void afterStore(JdbcAccess dbAccess, ClassDescriptor cld, Object obj) throws SequenceManagerException;
067    }