Methods Summary |
---|
protected void | acquireLock(java.lang.String seqName)
ConcurrencyManager manager;
synchronized (getLocks()) {
manager = (ConcurrencyManager)getLocks().get(seqName);
if (manager == null) {
manager = new ConcurrencyManager();
getLocks().put(seqName, manager);
}
}
manager.acquire();
|
protected void | clearPreallocationHandler()
preallocationHandler = null;
|
protected void | clearStates()
states = null;
|
protected void | createConnectionHandler()
boolean isServerSession = getOwnerSession().isServerSession();
if (getLogin() == null) {
Login login;
if (isServerSession) {
login = ((ServerSession)getOwnerSession()).getReadConnectionPool().getLogin();
} else {
login = getOwnerSession().getDatasourceLogin();
}
setLogin((Login)login.clone());
}
if (getLogin() != null) {
if (getLogin().shouldUseExternalTransactionController()) {
throw ValidationException.invalidSequencingLogin();
}
}
if (isServerSession) {
ConnectionPool pool = null;
if (getLogin().shouldUseExternalConnectionPooling()) {
pool = new ExternalConnectionPool("sequencing", getLogin(), (ServerSession)getOwnerSession());
} else {
if ((getMinPoolSize() == 0) && (getMaxPoolSize() == 0)) {
setMinPoolSize(2);
setMaxPoolSize(2);
}
pool = new ConnectionPool("sequencing", getLogin(), getMinPoolSize(), getMaxPoolSize(), (ServerSession)getOwnerSession());
}
setConnectionHandler(new ServerSessionConnectionHandler(pool));
} else {
setConnectionHandler(new DatabaseSessionConnectionHandler(getOwnerSession(), getLogin()));
}
|
protected void | createPreallocationHandler()
preallocationHandler = new PreallocationHandler();
|
protected void | createSequencingCallback()
Vector callbackVector = new Vector();
for (int i = 0; i < NUMBER_OF_STATES; i++) {
if (states[i] != null) {
SequencingCallback callback = states[i].getSequencingCallback();
if (callback != null) {
callbackVector.addElement(callback);
}
}
}
if (callbackVector.isEmpty()) {
setSequencingCallback(null);
} else if (callbackVector.size() == 1) {
setSequencingCallback((SequencingCallback)callbackVector.firstElement());
} else {
setSequencingCallback(new SequencingCallbackContainer(callbackVector));
}
|
protected void | createState(boolean shouldUsePreallocation, boolean shouldUseTransaction)
if (!shouldUsePreallocation) {
// Non-Oracle native sequencing uses this state
states[NOPREALLOCATION] = new NoPreallocation_State();
} else if (!shouldUseTransaction) {
// Oracle native sequencing uses this state
states[PREALLOCATION_NOTRANSACTION] = new Preallocation_NoTransaction_State();
} else if (getConnectionHandler() == null) {
// TableSequence and UnaryTableSequence in case there is no separate connection(s) available use this state
states[PREALLOCATION_TRANSACTION_NOACCESSOR] = new Preallocation_Transaction_NoAccessor_State();
} else/*if(getConnectionHandler()!=null)*/
{
// TableSequence and UnaryTableSequence in case there is separate connection(s) available use this state
states[PREALLOCATION_TRANSACTION_ACCESSOR] = new Preallocation_Transaction_Accessor_State();
}
|
protected oracle.toplink.essentials.internal.sequencing.SequencingConnectionHandler | getConnectionHandler()
return connectionHandler;
|
protected oracle.toplink.essentials.sequencing.Sequence | getDefaultSequence()
return getOwnerSession().getDatasourcePlatform().getDefaultSequence();
|
public int | getInitialValue()
return getDefaultSequence().getInitialValue();
|
protected java.util.Hashtable | getLocks()
return locks;
|
public oracle.toplink.essentials.sessions.Login | getLogin()
return login;
|
public int | getMaxPoolSize()
return maxPoolSize;
|
public int | getMinPoolSize()
return minPoolSize;
|
public java.lang.Object | getNextValue(java.lang.Class cls)
return getNextValue(getOwnerSession(), cls);
|
public java.lang.Object | getNextValue(oracle.toplink.essentials.internal.sessions.AbstractSession writeSession, java.lang.Class cls)
Sequence sequence = getSequence(cls);
State state = getState(sequence.shouldUsePreallocation(), sequence.shouldUseTransaction());
return state.getNextValue(sequence, writeSession);
|
protected oracle.toplink.essentials.internal.sessions.DatabaseSessionImpl | getOwnerSession()
return ownerSession;
|
protected oracle.toplink.essentials.internal.sequencing.PreallocationHandler | getPreallocationHandler()
return preallocationHandler;
|
public int | getPreallocationSize()
return getDefaultSequence().getPreallocationSize();
|
protected oracle.toplink.essentials.sequencing.Sequence | getSequence(java.lang.Class cls)
//** should check here that sequencing is used?
String seqName = getOwnerSession().getDescriptor(cls).getSequenceNumberName();
return getSequence(seqName);
|
protected oracle.toplink.essentials.sequencing.Sequence | getSequence(java.lang.String seqName)
return getOwnerSession().getDatasourcePlatform().getSequence(seqName);
|
public oracle.toplink.essentials.internal.sequencing.Sequencing | getSequencing()
return seq;
|
public oracle.toplink.essentials.internal.sequencing.SequencingCallback | getSequencingCallback()
return callback;
|
public oracle.toplink.essentials.sequencing.SequencingControl | getSequencingControl()
return this;
|
public oracle.toplink.essentials.internal.sequencing.SequencingServer | getSequencingServer()
return server;
|
protected oracle.toplink.essentials.internal.sequencing.SequencingManager$State | getState(boolean shouldUsePreallocation, boolean shouldUseTransaction)
return states[getStateId(shouldUsePreallocation, shouldUseTransaction)];
|
protected int | getStateId(boolean shouldUsePreallocation, boolean shouldUseTransaction)
if (!shouldUsePreallocation) {
// Non-Oracle native sequencing uses this state
return NOPREALLOCATION;
} else if (!shouldUseTransaction) {
// Oracle native sequencing uses this state
return PREALLOCATION_NOTRANSACTION;
} else if (getConnectionHandler() == null) {
// TableSequence and UnaryTableSequence in case there is no separate connection(s) available use this state
return PREALLOCATION_TRANSACTION_NOACCESSOR;
} else/*if(getConnectionHandler()!=null)*/
{
// TableSequence and UnaryTableSequence in case there is separate connection(s) available use this state
return PREALLOCATION_TRANSACTION_ACCESSOR;
}
|
public void | initializePreallocated()
if (getPreallocationHandler() != null) {
getPreallocationHandler().initializePreallocated();
}
|
public void | initializePreallocated(java.lang.String seqName)
if (getPreallocationHandler() != null) {
getPreallocationHandler().initializePreallocated(seqName);
}
|
protected void | initializeStates()
states = new State[NUMBER_OF_STATES];
Iterator itConnectedSequences = connectedSequences.iterator();
while (itConnectedSequences.hasNext()) {
Sequence sequence = (Sequence)itConnectedSequences.next();
State state = getState(sequence.shouldUsePreallocation(), sequence.shouldUseTransaction());
if (state == null) {
createState(sequence.shouldUsePreallocation(), sequence.shouldUseTransaction());
}
}
|
public boolean | isConnected()
return states != null;
|
public boolean | isConnectedUsingSeparateConnection()
return isConnected() && (getConnectionHandler() != null);
|
protected void | logDebugLocalPreallocation(oracle.toplink.essentials.internal.sessions.AbstractSession writeSession, java.lang.String seqName, java.util.Vector sequences, oracle.toplink.essentials.internal.databaseaccess.Accessor accessor)
if (writeSession.shouldLog(SessionLog.FINEST, SessionLog.SEQUENCING)) {
Object[] args = { seqName, new Integer(sequences.size()), sequences.firstElement(), sequences.lastElement() };
writeSession.log(SessionLog.FINEST, SessionLog.SEQUENCING, "sequencing_localPreallocation", args, accessor);
}
|
protected void | logDebugPreallocation(java.lang.String seqName, java.util.Vector sequences)
if (getOwnerSession().shouldLog(SessionLog.FINEST, SessionLog.SEQUENCING)) {
Object[] args = { seqName, new Integer(sequences.size()), sequences.firstElement(), sequences.lastElement() };
getOwnerSession().log(SessionLog.FINEST, SessionLog.SEQUENCING, "sequencing_preallocation", args);
}
|
protected void | logDebugSequencingConnected()
Vector[] sequenceVectors = new Vector[NUMBER_OF_STATES];
Iterator itConnectedSequences = connectedSequences.iterator();
while (itConnectedSequences.hasNext()) {
Sequence sequence = (Sequence)itConnectedSequences.next();
int stateId = getStateId(sequence.shouldUsePreallocation(), sequence.shouldUseTransaction());
Vector v = sequenceVectors[stateId];
if (v == null) {
v = new Vector();
sequenceVectors[stateId] = v;
}
v.addElement(sequence);
}
for (int i = 0; i < NUMBER_OF_STATES; i++) {
Vector v = sequenceVectors[i];
if (v != null) {
getOwnerSession().log(SessionLog.FINEST, SessionLog.SEQUENCING, "sequencing_connected", states[i]);
for (int j = 1; j < v.size(); j++) {
Sequence sequence = (Sequence)v.elementAt(j);
Object[] args = { sequence.getName(), Integer.toString(sequence.getPreallocationSize()),
Integer.toString(sequence.getInitialValue())};
getOwnerSession().log(SessionLog.FINEST, SessionLog.SEQUENCING, "sequence_without_state", args);
}
}
}
|
public void | onConnect()
if (isConnected()) {
return;
}
if (!getOwnerSession().getProject().usesSequencing()) {
return;
}
getOwnerSession().getDatasourcePlatform().platformSpecificSequencingInitialization(getOwnerSession());
onConnectAllSequences();
boolean onExceptionDisconnectPreallocationHandler = false;
boolean onExceptionDisconnectConnectionHandler = false;
try {
if (!shouldUseSeparateConnection()) {
setConnectionHandler(null);
} else if (atLeastOneSequenceShouldUseTransaction) {
if (getConnectionHandler() == null) {
createConnectionHandler();
}
if (getConnectionHandler() != null) {
getConnectionHandler().onConnect();
onExceptionDisconnectConnectionHandler = true;
}
}
if (atLeastOneSequenceShouldUsePreallocation) {
if (getPreallocationHandler() == null) {
createPreallocationHandler();
}
getPreallocationHandler().onConnect();
onExceptionDisconnectPreallocationHandler = true;
}
initializeStates();
} catch (RuntimeException ex) {
onDisconnectAllSequences();
if (getConnectionHandler() != null) {
if (onExceptionDisconnectConnectionHandler) {
getConnectionHandler().onDisconnect();
}
setConnectionHandler(null);
}
if (getPreallocationHandler() != null) {
if (onExceptionDisconnectPreallocationHandler) {
getPreallocationHandler().onDisconnect();
}
clearPreallocationHandler();
}
throw ex;
}
if (atLeastOneSequenceShouldUsePreallocation) {
setLocks(new Hashtable(20));
}
createSequencingCallback();
if (getOwnerSession().isServerSession()) {
setSequencingServer(this);
}
setSequencing(this);
logDebugSequencingConnected();
|
protected void | onConnectAllSequences()
connectedSequences = new Vector();
boolean shouldUseTransaction = false;
boolean shouldUsePreallocation = false;
boolean shouldAcquireValueAfterInsert = false;
Iterator descriptors = getOwnerSession().getDescriptors().values().iterator();
while (descriptors.hasNext()) {
ClassDescriptor descriptor = (ClassDescriptor)descriptors.next();
if (!descriptor.usesSequenceNumbers()) {
continue;
}
String seqName = descriptor.getSequenceNumberName();
Sequence sequence = getSequence(seqName);
if (sequence == null) {
sequence = new DefaultSequence(seqName);
getOwnerSession().getDatasourcePlatform().addSequence(sequence);
}
if (connectedSequences.contains(sequence)) {
continue;
}
try {
if (sequence instanceof DefaultSequence && !connectedSequences.contains(getDefaultSequence())) {
getDefaultSequence().onConnect(getOwnerSession().getDatasourcePlatform());
connectedSequences.add(0, getDefaultSequence());
shouldUseTransaction |= getDefaultSequence().shouldUseTransaction();
shouldUsePreallocation |= getDefaultSequence().shouldUsePreallocation();
shouldAcquireValueAfterInsert |= getDefaultSequence().shouldAcquireValueAfterInsert();
}
sequence.onConnect(getOwnerSession().getDatasourcePlatform());
connectedSequences.addElement(sequence);
shouldUseTransaction |= sequence.shouldUseTransaction();
shouldUsePreallocation |= sequence.shouldUsePreallocation();
shouldAcquireValueAfterInsert |= sequence.shouldAcquireValueAfterInsert();
} catch (RuntimeException ex) {
// defaultSequence has to disconnect the last
for (int i = connectedSequences.size() - 1; i >= 0; i--) {
try {
Sequence sequenceToDisconnect = (Sequence)connectedSequences.elementAt(i);
sequenceToDisconnect.onDisconnect(getOwnerSession().getDatasourcePlatform());
} catch (RuntimeException ex2) {
//ignore
}
}
connectedSequences = null;
throw ex;
}
}
if (shouldAcquireValueAfterInsert && !shouldUsePreallocation) {
whenShouldAcquireValueForAll = AFTER_INSERT;
} else if (!shouldAcquireValueAfterInsert && shouldUsePreallocation) {
whenShouldAcquireValueForAll = BEFORE_INSERT;
}
atLeastOneSequenceShouldUseTransaction = shouldUseTransaction;
atLeastOneSequenceShouldUsePreallocation = shouldUsePreallocation;
|
public void | onDisconnect()
if (!isConnected()) {
return;
}
setSequencing(null);
setSequencingServer(null);
setSequencingCallback(null);
setLocks(null);
clearStates();
if (getConnectionHandler() != null) {
getConnectionHandler().onDisconnect();
setConnectionHandler(null);
}
if (getPreallocationHandler() != null) {
getPreallocationHandler().onDisconnect();
clearPreallocationHandler();
}
onDisconnectAllSequences();
getOwnerSession().log(SessionLog.FINEST, SessionLog.SEQUENCING, "sequencing_disconnected");
|
protected void | onDisconnectAllSequences()
RuntimeException exception = null;
// defaultSequence has to disconnect the last
for (int i = connectedSequences.size() - 1; i >= 0; i--) {
try {
Sequence sequenceToDisconnect = (Sequence)connectedSequences.elementAt(i);
sequenceToDisconnect.onDisconnect(getOwnerSession().getDatasourcePlatform());
} catch (RuntimeException ex) {
if (exception == null) {
exception = ex;
}
}
}
connectedSequences = null;
whenShouldAcquireValueForAll = UNDEFINED;
atLeastOneSequenceShouldUseTransaction = false;
atLeastOneSequenceShouldUsePreallocation = false;
if (exception != null) {
throw exception;
}
|
protected void | releaseLock(java.lang.String seqName)
ConcurrencyManager manager = (ConcurrencyManager)locks.get(seqName);
manager.release();
|
public void | resetSequencing()
if (isConnected()) {
onDisconnect();
onConnect();
}
|
protected void | setConnectionHandler(oracle.toplink.essentials.internal.sequencing.SequencingConnectionHandler handler)
this.connectionHandler = handler;
|
protected void | setLocks(java.util.Hashtable locks)
this.locks = locks;
|
public void | setLogin(oracle.toplink.essentials.sessions.Login login)
this.login = login;
|
public void | setMaxPoolSize(int size)
this.maxPoolSize = size;
|
public void | setMinPoolSize(int size)
this.minPoolSize = size;
|
protected void | setSequencing(oracle.toplink.essentials.internal.sequencing.Sequencing sequencing)
this.seq = sequencing;
|
protected void | setSequencingCallback(oracle.toplink.essentials.internal.sequencing.SequencingCallback callback)
this.callback = callback;
|
protected void | setSequencingServer(oracle.toplink.essentials.internal.sequencing.SequencingServer server)
this.server = server;
|
public void | setShouldUseSeparateConnection(boolean shouldUseSeparateConnection)
this.shouldUseSeparateConnection = shouldUseSeparateConnection;
|
public boolean | shouldAcquireValueAfterInsert(java.lang.Class cls)
return getSequence(cls).shouldAcquireValueAfterInsert();
|
public boolean | shouldOverrideExistingValue(java.lang.Class cls, java.lang.Object existingValue)
return getSequence(cls).shouldOverrideExistingValue(existingValue);
|
public boolean | shouldUseSeparateConnection()
return shouldUseSeparateConnection;
|
public int | whenShouldAcquireValueForAll()
return whenShouldAcquireValueForAll;
|