java中po代码示例_Java PO.saveEx方法代码示例

import org.compiere.model.PO; //导入方法依赖的package包/类

@Override

public void copyRecord(final PO po, final String trxName)

{

final PO fromPO;

if (getFromPO_ID() > 0)

{

fromPO = TableModelLoader.instance.getPO(getCtx(), po.get_TableName(), getFromPO_ID(), trxName);

}

else

{

fromPO = po;

}

//

// Copy this level

setBase(true);

final PO toPO;

if (getParentKeyColumn() != null && getParentID() > 0)

{

toPO = TableModelLoader.instance.newPO(getCtx(), fromPO.get_TableName(), trxName);

toPO.setDynAttribute(PO.DYNATTR_CopyRecordSupport, this); // need this for getting defaultValues at copy in PO

PO.copyValues(fromPO, toPO, true);

// reset for avoiding copy same object twice

toPO.setDynAttribute(PO.DYNATTR_CopyRecordSupport, null);

setBase(false);

// Parent link:

toPO.set_CustomColumn(getParentKeyColumn(), getParentID());

// needs refresh

// not sure if this is still needed

for (final String columnName : toPO.get_KeyColumns())

{

toPO.set_CustomColumn(columnName, toPO.get_Value(columnName));

}

// needs to set IsActive because is not copied

if (toPO.get_ColumnIndex(COLUMNNAME_IsActive) >= 0)

{

toPO.set_CustomColumn(COLUMNNAME_IsActive, fromPO.get_Value(COLUMNNAME_IsActive));

}

// Make sure the columns which are required to be unique they have unique values.

updateSpecialColumnsName(toPO);

// Notify listeners

fireOnRecordCopied(toPO, fromPO);

//

toPO.setDynAttribute(PO.DYNATTR_CopyRecordSupport_OldValue, fromPO.get_ID()); // need this for changelog

toPO.saveEx(trxName);

// setParentPO(toPO); // TODO: remove it, not needed

}

else

{

toPO = getParentPO();

}

//

// Copy children

for (final TableInfoVO childTableInfo : getSuggestedChildren(fromPO, getSuggestedChildrenToCopy()))

{

for (final Iterator extends PO> it = retrieveChildPOsForParent(childTableInfo.getTableName(), fromPO); it.hasNext();)

{

final PO childPO = it.next();

final CopyRecordSupport childCRS = CopyRecordFactory.getCopyRecordSupport(childTableInfo.getTableName());

childCRS.setParentKeyColumn(childTableInfo.getLinkColumnName());

childCRS.setAD_Window_ID(getAD_Window_ID());

childCRS.setParentPO(toPO);

childCRS.copyRecord(childPO, trxName);

log.info("Copied {}", childPO);

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值