本文整理汇总了Java中org.apache.ojb.broker.OptimisticLockException类的典型用法代码示例。如果您正苦于以下问题:Java OptimisticLockException类的具体用法?Java OptimisticLockException怎么用?Java OptimisticLockException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
OptimisticLockException类属于org.apache.ojb.broker包,在下文中一共展示了OptimisticLockException类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: logOjbOptimisticLockException
import org.apache.ojb.broker.OptimisticLockException; //导入依赖的package包/类
/**
* Generates detailed log messages for OptimisticLockExceptions
*
* @param e
*/
private final void logOjbOptimisticLockException(OptimisticLockException e) {
if (LOG.isInfoEnabled()) {
StringBuilder message = new StringBuilder("caught OptimisticLockException, caused by ");
Object sourceObject = e.getSourceObject();
String infix = null;
try {
// try to add instance details
infix = sourceObject.toString();
} catch (Exception e2) {
// just use the class name
infix = sourceObject.getClass().getName();
}
message.append(infix);
if (sourceObject instanceof Versioned) {
Versioned persistableObject = (Versioned) sourceObject;
message.append(" [versionNumber = ").append(persistableObject.getVersionNumber()).append("]");
}
LOG.info(message.toString(), e);
}
}
开发者ID:kuali,项目名称:kc-rice,代码行数:28,代码来源:KualiDocumentActionBase.java
示例2: execute
import org.apache.ojb.broker.OptimisticLockException; //导入依赖的package包/类
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
ActionForward returnForward = mapping.findForward(RiceConstants.MAPPING_BASIC);
// if found methodToCall, pass control to that method
try {
returnForward = super.execute(mapping, form, request, response);
}
catch (OjbOperationException e) {
// special handling for OptimisticLockExceptions
OjbOperationException ooe = (OjbOperationException) e;
Throwable cause = ooe.getCause();
if (cause instanceof OptimisticLockException) {
OptimisticLockException ole = (OptimisticLockException) cause;
GlobalVariables.getMessageMap().putError(KFSConstants.GLOBAL_ERRORS, CabKeyConstants.DATA_EDIT_LOCK_ERROR);
}
else {
// if exceptions are from 'save'
throw e;
}
}
return returnForward;
}
开发者ID:kuali,项目名称:kfs,代码行数:25,代码来源:CabActionBase.java
示例3: logOptimisticDetails
import org.apache.ojb.broker.OptimisticLockException; //导入依赖的package包/类
/**
* Logs further details of OptimisticLockExceptions, using the given depth value to limit recursion Just In Case
*
* @param depth
* @param t
*/
private void logOptimisticDetails(int depth, Throwable t) {
if ((depth > 0) && (t != null)) {
if (t instanceof OptimisticLockException) {
OptimisticLockException o = (OptimisticLockException) t;
LOG.error("source of OptimisticLockException = " + o.getSourceObject().getClass().getName() + " ::= " + o.getSourceObject());
}
else {
Throwable cause = t.getCause();
if (cause != t) {
logOptimisticDetails(--depth, cause);
}
}
}
}
开发者ID:aapotts,项目名称:kuali_rice,代码行数:22,代码来源:PostProcessorServiceImpl.java
示例4: releaseAllLocksForUser
import org.apache.ojb.broker.OptimisticLockException; //导入依赖的package包/类
/**
* @see org.kuali.rice.krad.service.PessimisticLockService#releaseAllLocksForUser(java.util.List, org.kuali.rice.kim.api.identity.Person)
*/
public void releaseAllLocksForUser(List<PessimisticLock> locks, Person user) {
for (Iterator<PessimisticLock> iterator = locks.iterator(); iterator.hasNext();) {
PessimisticLock lock = (PessimisticLock) iterator.next();
if (lock.isOwnedByUser(user)) {
try {
delete(lock);
} catch ( RuntimeException ex ) {
if ( ex.getCause() instanceof OptimisticLockException) {
LOG.warn( "Suppressing Optimistic Lock Exception. Document Num: " + lock.getDocumentNumber());
} else {
throw ex;
}
}
}
}
}
开发者ID:aapotts,项目名称:kuali_rice,代码行数:20,代码来源:PessimisticLockServiceImpl.java
示例5: logOjbOptimisticLockException
import org.apache.ojb.broker.OptimisticLockException; //导入依赖的package包/类
/**
* Generates detailed log messages for OptimisticLockExceptions
*
* @param e
*/
private final void logOjbOptimisticLockException(OptimisticLockException e) {
if (LOG.isInfoEnabled()) {
StringBuffer message = new StringBuffer("caught OptimisticLockException, caused by ");
Object sourceObject = e.getSourceObject();
String infix = null;
try {
// try to add instance details
infix = sourceObject.toString();
} catch (Exception e2) {
// just use the class name
infix = sourceObject.getClass().getName();
}
message.append(infix);
if (sourceObject instanceof PersistableBusinessObject) {
PersistableBusinessObject persistableObject = (PersistableBusinessObject) sourceObject;
message.append(" [versionNumber = ").append(persistableObject.getVersionNumber()).append("]");
}
LOG.info(message.toString(), e);
}
}
开发者ID:aapotts,项目名称:kuali_rice,代码行数:28,代码来源:KualiDocumentActionBase.java
示例6: performDeletion
import org.apache.ojb.broker.OptimisticLockException; //导入依赖的package包/类
/**
* This method perform the delete of the specified object
* based on the {@link org.apache.ojb.broker.metadata.ClassDescriptor}.
*/
private void performDeletion(final ClassDescriptor cld, final Object obj, final Identity oid, final boolean ignoreReferences) throws PersistenceBrokerException
{
// 1. delete dependend collections
if (!ignoreReferences && cld.getCollectionDescriptors().size() > 0)
{
deleteCollections(obj, cld.getCollectionDescriptors());
}
// 2. delete object from directly mapped table
try
{
dbAccess.executeDelete(cld, obj); // use obj not oid to delete, BRJ
}
catch(OptimisticLockException e)
{
// ensure that the outdated object be removed from cache
objectCache.remove(oid);
throw e;
}
// 3. Add OID to the set of deleted objects
deletedDuringTransaction.add(oid);
// 4. delete dependend upon objects last to avoid FK violations
if (cld.getObjectReferenceDescriptors().size() > 0)
{
deleteReferences(cld, obj, oid, ignoreReferences);
}
// remove obj from the object cache:
objectCache.remove(oid);
}
开发者ID:KualiCo,项目名称:ojb,代码行数:35,代码来源:PersistenceBrokerImpl.java
示例7: saveRouteHeader
import org.apache.ojb.broker.OptimisticLockException; //导入依赖的package包/类
public void saveRouteHeader(DocumentRouteHeaderValue routeHeader) {
if ( LOG.isDebugEnabled() ) {
LOG.debug( "About to Save the route Header: " + routeHeader.getDocumentId() + " / version=" + routeHeader.getVersionNumber() );
DocumentRouteHeaderValue currHeader = findRouteHeader(routeHeader.getDocumentId());
if ( currHeader != null ) {
LOG.debug( "Current Header Version: " + currHeader.getVersionNumber() );
// for ( SearchableAttributeValue s : currHeader.get() ) {
// LOG.debug( "SA: " + s.getSearchableAttributeValueId() + " / version=" + s.get )
// }
} else {
LOG.debug( "Current Header: null" );
}
LOG.debug( ExceptionUtils.getStackTrace(new Throwable()) );
}
try {
getPersistenceBrokerTemplate().store(routeHeader);
routeHeader.getDocumentContent().setDocumentId(routeHeader.getDocumentId());
getPersistenceBrokerTemplate().store(routeHeader.getDocumentContent());
} catch ( RuntimeException ex ) {
if ( ex.getCause() instanceof OptimisticLockException ) {
LOG.error( "Optimistic Locking Exception saving document header or content. Offending object: " + ((OptimisticLockException)ex.getCause()).getSourceObject()
+ "; DocumentId = " + routeHeader.getDocumentId() + " ; Version Number = " + routeHeader.getVersionNumber());
}
LOG.error( "Unable to save document header or content. Route Header: " + routeHeader, ex );
throw ex;
}
}
开发者ID:aapotts,项目名称:kuali_rice,代码行数:28,代码来源:DocumentRouteHeaderDAOOjbImpl.java
示例8: lookupStoreSequence
import org.apache.ojb.broker.OptimisticLockException; //导入依赖的package包/类
protected HighLowSequence lookupStoreSequence(PersistenceBroker broker, FieldDescriptor field, String seqName)
{
HighLowSequence newSequence;
boolean needsInsert = false;
Identity oid = broker.serviceIdentity().buildIdentity(HighLowSequence.class, seqName);
// first we lookup sequence object in database
newSequence = (HighLowSequence) broker.getObjectByIdentity(oid);
//not in db --> we have to store a new sequence
if (newSequence == null)
{
if (log.isDebugEnabled())
{
log.debug("sequence for field " + field + " not found in db, store new HighLowSequence");
}
/*
here we lookup the max key for the given field in system
*/
// !!! here we use current broker instance to avoid deadlock !!!
long maxKey = getMaxKeyForSequence(getBrokerForClass(), field);
newSequence = newSequenceObject(seqName, field);
newSequence.setMaxKey(maxKey);
needsInsert = true;
}
// maybe property 'sequenceStart' was changed, so we check maxKey against
// current set sequence start index
if(newSequence.getMaxKey() < sequenceStart)
{
newSequence.setMaxKey(sequenceStart);
}
// set current grab size
newSequence.setGrabSize(grabSize);
//grab the next key scope
newSequence.grabNextKeySet();
//store the sequence to db
try
{
if(needsInsert) broker.store(newSequence, ObjectModification.INSERT);
else broker.store(newSequence, ObjectModification.UPDATE);
}
catch (OptimisticLockException e)
{
// we try five times to get a new sequence
if(attempts < 5)
{
log.info("OptimisticLockException was thrown, will try again to store sequence. Sequence was "+newSequence);
attempts++;
newSequence = lookupStoreSequence(broker, field, seqName);
}
else throw e;
}
return newSequence;
}
开发者ID:KualiCo,项目名称:ojb,代码行数:59,代码来源:SequenceManagerHighLowImpl.java
示例9: storeToDb
import org.apache.ojb.broker.OptimisticLockException; //导入依赖的package包/类
/**
* I pulled this out of internal store so that when doing multiple table
* inheritance, i can recurse this function.
*
* @param obj
* @param cld
* @param oid BRJ: what is it good for ???
* @param insert
* @param ignoreReferences
*/
private void storeToDb(Object obj, ClassDescriptor cld, Identity oid, boolean insert, boolean ignoreReferences)
{
// 1. link and store 1:1 references
storeReferences(obj, cld, insert, ignoreReferences);
Object[] pkValues = oid.getPrimaryKeyValues();
if (!serviceBrokerHelper().assertValidPksForStore(cld.getPkFields(), pkValues))
{
// BRJ: fk values may be part of pk, but the are not known during
// creation of Identity. so we have to get them here
pkValues = serviceBrokerHelper().getKeyValues(cld, obj);
if (!serviceBrokerHelper().assertValidPksForStore(cld.getPkFields(), pkValues))
{
String append = insert ? " on insert" : " on update" ;
throw new PersistenceBrokerException("assertValidPkFields failed for Object of type: " + cld.getClassNameOfObject() + append);
}
}
// get super class cld then store it with the object
/*
now for multiple table inheritance
1. store super classes, topmost parent first
2. go down through heirarchy until current class
3. todo: store to full extent?
// arminw: TODO: The extend-attribute feature dosn't work, should we remove this stuff?
This if-clause will go up the inheritance heirarchy to store all the super classes.
The id for the top most super class will be the id for all the subclasses too
*/
if(cld.getSuperClass() != null)
{
ClassDescriptor superCld = getDescriptorRepository().getDescriptorFor(cld.getSuperClass());
storeToDb(obj, superCld, oid, insert);
// arminw: why this?? I comment out this section
// storeCollections(obj, cld.getCollectionDescriptors(), insert);
}
// 2. store primitive typed attributes (Or is THIS step 3 ?)
// if obj not present in db use INSERT
if (insert)
{
dbAccess.executeInsert(cld, obj);
if(oid.isTransient())
{
// Create a new Identity based on the current set of primary key values.
oid = serviceIdentity().buildIdentity(cld, obj);
}
}
// else use UPDATE
else
{
try
{
dbAccess.executeUpdate(cld, obj);
}
catch(OptimisticLockException e)
{
// ensure that the outdated object be removed from cache
objectCache.remove(oid);
throw e;
}
}
// cache object for symmetry with getObjectByXXX()
// Add the object to the cache.
objectCache.doInternalCache(oid, obj, ObjectCacheInternal.TYPE_WRITE);
// 3. store 1:n and m:n associations
if(!ignoreReferences) storeCollections(obj, cld, insert);
}
开发者ID:KualiCo,项目名称:ojb,代码行数:80,代码来源:PersistenceBrokerImpl.java
注:本文中的org.apache.ojb.broker.OptimisticLockException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论