当前位置: 首页>>代码示例>>Java>>正文


Java EntityLockedException类代码示例

本文整理汇总了Java中org.ofbiz.entity.EntityLockedException的典型用法代码示例。如果您正苦于以下问题:Java EntityLockedException类的具体用法?Java EntityLockedException怎么用?Java EntityLockedException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


EntityLockedException类属于org.ofbiz.entity包,在下文中一共展示了EntityLockedException类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: singleUpdate

import org.ofbiz.entity.EntityLockedException; //导入依赖的package包/类
private int singleUpdate(GenericEntity entity, ModelEntity modelEntity, List<ModelField> fieldsToSave, SQLProcessor sqlP) throws GenericEntityException {
    if (modelEntity instanceof ModelViewEntity) {
        return singleUpdateView(entity, (ModelViewEntity) modelEntity, fieldsToSave, sqlP);
    }

    // no non-primaryKey fields, update doesn't make sense, so don't do it
    if (fieldsToSave.size() <= 0) {
        if (Debug.verboseOn()) Debug.logVerbose("Trying to do an update on an entity with no non-PK fields, returning having done nothing; entity=" + entity, module);
        // returning one because it was effectively updated, ie the same thing, so don't trigger any errors elsewhere
        return 1;
    }

    if (modelEntity.lock()) {
        GenericEntity entityCopy = GenericEntity.createGenericEntity(entity);

        select(entityCopy, sqlP);
        Object stampField = entity.get(ModelEntity.STAMP_FIELD);

        if ((stampField != null) && (!stampField.equals(entityCopy.get(ModelEntity.STAMP_FIELD)))) {
            String lockedTime = entityCopy.getTimestamp(ModelEntity.STAMP_FIELD).toString();

            throw new EntityLockedException("You tried to update an old version of this data. Version locked: (" + lockedTime + ")");
        }
    }

    // if we have a STAMP_TX_FIELD then set it with NOW, always do this before the STAMP_FIELD
    // NOTE: these fairly complicated if statements have a few objectives:
    //   1. don't run the TransationUtil.getTransaction*Stamp() methods when we don't need to
    //   2. don't set the stamp values if it is from an EntitySync (ie maintain original values), unless the stamps are null then set it anyway, ie even if it was from an EntitySync (also used for imports and such)
    if (modelEntity.isField(ModelEntity.STAMP_TX_FIELD) && (!entity.getIsFromEntitySync() || entity.get(ModelEntity.STAMP_TX_FIELD) == null)) {
        entity.set(ModelEntity.STAMP_TX_FIELD, TransactionUtil.getTransactionStartStamp());
        addFieldIfMissing(fieldsToSave, ModelEntity.STAMP_TX_FIELD, modelEntity);
    }

    // if we have a STAMP_FIELD then update it with NOW.
    if (modelEntity.isField(ModelEntity.STAMP_FIELD) && (!entity.getIsFromEntitySync() || entity.get(ModelEntity.STAMP_FIELD) == null)) {
        entity.set(ModelEntity.STAMP_FIELD, TransactionUtil.getTransactionUniqueNowStamp());
        addFieldIfMissing(fieldsToSave, ModelEntity.STAMP_FIELD, modelEntity);
    }

    StringBuilder sql = new StringBuilder().append("UPDATE ").append(modelEntity.getTableName(datasource)).append(" SET ");
    modelEntity.colNameString(fieldsToSave, sql, "", "=?, ", "=?", false);
    sql.append(" WHERE ");
    SqlJdbcUtil.makeWhereStringFromFields(sql, modelEntity.getPkFieldsUnmodifiable(), entity, "AND");

    int retVal = 0;

    try {
        sqlP.prepareStatement(sql.toString());
        SqlJdbcUtil.setValues(sqlP, fieldsToSave, entity, modelFieldTypeReader);
        SqlJdbcUtil.setPkValues(sqlP, modelEntity, entity, modelFieldTypeReader);
        retVal = sqlP.executeUpdate();
        entity.synchronizedWithDatasource();
    } catch (GenericEntityException e) {
        throw new GenericEntityException("Error while updating: " + entity.toString(), e);
    } finally {
        sqlP.close();
    }

    if (retVal == 0) {
        throw new GenericEntityNotFoundException("Tried to update an entity that does not exist, entity: " + entity.toString());
    }
    return retVal;
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:65,代码来源:GenericDAO.java


注:本文中的org.ofbiz.entity.EntityLockedException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。