| java.lang.Object org.apache.ojb.broker.util.sequence.AbstractSequenceManager org.apache.ojb.broker.util.sequence.SequenceManagerStoredProcedureImpl
SequenceManagerStoredProcedureImpl | public class SequenceManagerStoredProcedureImpl extends AbstractSequenceManager (Code) | | This solution will give those seeking an oracle-style
sequence generator a final answer (Identity columns really suck).
The SequenceManagerStoredProcedureImpl implementation enabled database
sequence key generation for all databases (e.g. MSSQL, MySQL, DB2, ...)
with a JDBC 2.0 compliant driver.
First add a new table OJB_NEXTVAL_SEQ to
your database.
CREATE TABLE OJB_NEXTVAL_SEQ
(
SEQ_NAME VARCHAR(150) NOT NULL,
MAX_KEY BIGINT,
CONSTRAINT SYS_PK_OJB_NEXTVAL_SEQ PRIMARY KEY(SEQ_NAME)
)
You will also need the stored procedure OJB_NEXTVAL
will will take care of giving you a guaranteed unique
sequence number, in multi server environments.
CREATE PROCEDURE ojb_nextval_proc @SEQ_NAME varchar(100)
AS
declare @MAX_KEY BIGINT
-- return an error if sequence does not exist
-- so we will know if someone truncates the table
set @MAX_KEY = 0
UPDATE OJB_NEXTVAL_SEQ
SET @MAX_KEY = MAX_KEY = MAX_KEY + 1
WHERE SEQ_NAME = @SEQ_NAME
if @MAX_KEY = 0
select 1/0
else
select @MAX_KEY
RETURN @MAX_KEY
It is possible to define a sequence-name
field-descriptor attribute in the repository file. If
such an attribute was not found, the implementation build
an extent aware sequence name by its own.
Keep in mind when define a sequence name, that you are responsible
to be aware of extents, that is: if you ask for an uid for an
interface with several
implementor classes, or a baseclass with several subclasses the returned
uid have to be unique accross all tables representing objects of the
extent in question. Thus you have to use the same sequence-name
for all extents.
Implementation configuration properties:
Property Key |
Property Values |
autoNaming |
Default was 'true'. If set 'true' OJB try to build a
sequence name automatic if none found in field-descriptor
and set this generated name as sequence-name
in field-descriptor. If set 'false' OJB throws an exception
if none sequence name was found in field-descriptor.
|
Limitations:
- do not use when other application use the native key generation ditto
author: Ryan Vanderwerf author: Edson Carlos Ericksson Richter author: Rajeev Kaul author: Thomas Mahler author: Armin Waibel version: $Id: SequenceManagerStoredProcedureImpl.java,v 1.11.2.2 2005/12/21 22:28:41 tomdz Exp $ |
PROCEDURE_NAME | final protected static String PROCEDURE_NAME(Code) | | |
SEQ_ID_STRING | final protected static String SEQ_ID_STRING(Code) | | |
SEQ_NAME_STRING | final protected static String SEQ_NAME_STRING(Code) | | |
SEQ_TABLE_NAME | final protected static String SEQ_TABLE_NAME(Code) | | |
SequenceManagerStoredProcedureImpl | public SequenceManagerStoredProcedureImpl(PersistenceBroker broker)(Code) | | Constructor
Parameters: broker - |
sp_createSequenceQuery | protected String sp_createSequenceQuery(String sequenceName, long maxKey)(Code) | | Insert syntax for our special table
Parameters: sequenceName - Parameters: maxKey - sequence insert statement |
|
|