|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.ojb.broker.util.sequence.AbstractSequenceManager
org.apache.ojb.broker.util.sequence.SequenceManagerStoredProcedureImpl
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
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.
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:
Field Summary | |
protected static java.lang.String |
PROCEDURE_NAME
|
protected static java.lang.String |
SEQ_ID_STRING
|
protected static java.lang.String |
SEQ_NAME_STRING
|
protected static java.lang.String |
SEQ_TABLE_NAME
|
Fields inherited from class org.apache.ojb.broker.util.sequence.AbstractSequenceManager |
PROPERTY_AUTO_NAMING |
Constructor Summary | |
SequenceManagerStoredProcedureImpl(PersistenceBroker broker)
Constructor |
Method Summary | |
protected long |
buildNextSequence(PersistenceBroker broker,
ClassDescriptor cld,
java.lang.String sequenceName)
Calls the stored procedure stored procedure throws an error if it doesn't exist. |
protected void |
createSequence(PersistenceBroker broker,
FieldDescriptor field,
java.lang.String sequenceName,
long maxKey)
Creates new row in table |
protected long |
getUniqueLong(FieldDescriptor field)
Gets the actual key Will create a new row with the max key of table if it does not exist. |
protected java.lang.String |
sp_createSequenceQuery(java.lang.String sequenceName,
long maxKey)
Insert syntax for our special table |
Methods inherited from class org.apache.ojb.broker.util.sequence.AbstractSequenceManager |
afterStore, calculateSequenceName, getBrokerForClass, getConfigurationProperties, getConfigurationProperty, getPlatform, getUniqueValue, setConfigurationProperties, setConfigurationProperty, setReferenceFKs, useAutoNaming |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected static final java.lang.String PROCEDURE_NAME
protected static final java.lang.String SEQ_NAME_STRING
protected static final java.lang.String SEQ_ID_STRING
protected static final java.lang.String SEQ_TABLE_NAME
Constructor Detail |
public SequenceManagerStoredProcedureImpl(PersistenceBroker broker)
broker
- Method Detail |
protected java.lang.String sp_createSequenceQuery(java.lang.String sequenceName, long maxKey)
sequenceName
- maxKey
-
protected long getUniqueLong(FieldDescriptor field) throws SequenceManagerException
getUniqueLong
in class AbstractSequenceManager
field
-
SequenceManagerException
protected long buildNextSequence(PersistenceBroker broker, ClassDescriptor cld, java.lang.String sequenceName) throws LookupException, java.sql.SQLException, PlatformException
broker
- cld
- sequenceName
-
LookupException
java.sql.SQLException
PlatformException
protected void createSequence(PersistenceBroker broker, FieldDescriptor field, java.lang.String sequenceName, long maxKey) throws java.lang.Exception
broker
- field
- sequenceName
- maxKey
-
java.lang.Exception
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |