Map<String,String> partyMap = UtilMisc.toMap("partyTypeId","PERSON",
"description","测试Party",
"statusId","PARTY_ENABLED"
);
GenericValue party = delegator.makeValue("Party");
party.setNonPKFields(partyMap);
String partyId = delegator.getNextSeqId("Party");
party.setPKFields(UtilMisc.toMap("partyId", partyId));
GenericValue createdParty = delegator.create(party);
Assert.assertEquals(partyId, createdParty.getPkShortValueString());
//创建个人
Map<String, String>personMap = UtilMisc.toMap("firstName","zhao",
"lastName","penghui",
"partyId",partyId);
GenericValue person= delegator.makeValidValue("Person",personMap);
GenericValue createPerson = delegator.create(person);
Assert.assertEquals(partyId, createdParty.getPkShortValueString());
//更新个人
createPerson.put("firstName","zhao");
int updated = delegator.store(createPerson);
Assert.assertEquals(1, updated);
GenericValue partyById=delegator.findOne("party", UtilMisc.toMap("partyId", partyId),false);
Assert.assertNotNull(partyById);
List<GenericValue> partyByAnd = delegator.findByAnd("party", UtilMisc.toMap("statusId","PARTY_ENABLED"),null,false);
Assert.assertNotNull(partyByAnd);
Assert.assertEquals(true, partyByAnd.size()>0);
Set<String> fieldsToSelect = FastSet.newInstance();
fieldsToSelect.add("statusId");
fieldsToSelect.add("partyId");
EntityCondition mainCond = EntityCondition.makeCondition("statusId",EntityOperator.EQUALS,"PARTY_ENABLED");
List<GenericValue> partyByCond = delegator.findList("party", mainCond, fieldsToSelect, null, null, false);
Assert.assertNotNull(partyByCond);
Assert.assertEquals(true,partyByCond.size()>0);
try {
TransactionUtil.begin();
EntityListIterator productElt = delegator.find("Product", null, null, null, null, null);
Assert.assertNotNull(productElt);
GenericValue nextProduct = null;
while ((nextProduct=productElt.next())!=null) {
Debug.log(""+nextProduct.get("productId"));
}
productElt.close();
TransactionUtil.commit();
} catch (GenericEntityException e) {
// TODO: handle exception
Debug.logError(e,getName());
TransactionUtil.rollback(e);
}//find API中在测试例子中没有包含在事物中需要手动包含,用ofbiz中的TransactionUtil类实现
"description","测试Party",
"statusId","PARTY_ENABLED"
);
GenericValue party = delegator.makeValue("Party");
party.setNonPKFields(partyMap);
String partyId = delegator.getNextSeqId("Party");
party.setPKFields(UtilMisc.toMap("partyId", partyId));
GenericValue createdParty = delegator.create(party);
Assert.assertEquals(partyId, createdParty.getPkShortValueString());
//创建个人
Map<String, String>personMap = UtilMisc.toMap("firstName","zhao",
"lastName","penghui",
"partyId",partyId);
GenericValue person= delegator.makeValidValue("Person",personMap);
GenericValue createPerson = delegator.create(person);
Assert.assertEquals(partyId, createdParty.getPkShortValueString());
//更新个人
createPerson.put("firstName","zhao");
int updated = delegator.store(createPerson);
Assert.assertEquals(1, updated);
GenericValue partyById=delegator.findOne("party", UtilMisc.toMap("partyId", partyId),false);
Assert.assertNotNull(partyById);
List<GenericValue> partyByAnd = delegator.findByAnd("party", UtilMisc.toMap("statusId","PARTY_ENABLED"),null,false);
Assert.assertNotNull(partyByAnd);
Assert.assertEquals(true, partyByAnd.size()>0);
Set<String> fieldsToSelect = FastSet.newInstance();
fieldsToSelect.add("statusId");
fieldsToSelect.add("partyId");
EntityCondition mainCond = EntityCondition.makeCondition("statusId",EntityOperator.EQUALS,"PARTY_ENABLED");
List<GenericValue> partyByCond = delegator.findList("party", mainCond, fieldsToSelect, null, null, false);
Assert.assertNotNull(partyByCond);
Assert.assertEquals(true,partyByCond.size()>0);
try {
TransactionUtil.begin();
EntityListIterator productElt = delegator.find("Product", null, null, null, null, null);
Assert.assertNotNull(productElt);
GenericValue nextProduct = null;
while ((nextProduct=productElt.next())!=null) {
Debug.log(""+nextProduct.get("productId"));
}
productElt.close();
TransactionUtil.commit();
} catch (GenericEntityException e) {
// TODO: handle exception
Debug.logError(e,getName());
TransactionUtil.rollback(e);
}//find API中在测试例子中没有包含在事物中需要手动包含,用ofbiz中的TransactionUtil类实现