SearchBuilder <OfferingBundleVO> searchByAmazon = createSearchBuilder();
searchByAmazon.and("CloudStackOffering", searchByAmazon.entity().getAmazonOffering() , SearchCriteria.Op.EQ);
searchByAmazon.and("AmazonEC2Offering", searchByAmazon.entity().getCloudstackOffering() , SearchCriteria.Op.EQ);
searchByAmazon.done();
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.AWSAPI_DB);
OfferingBundleVO offering = null;
try {
txn.start();
SearchCriteria<OfferingBundleVO> sc = searchByAmazon.create();
sc.setParameters("CloudStackOffering", cloudStackOffering);
sc.setParameters("AmazonEC2Offering", amazonEC2Offering);
offering = findOneBy(sc);
if (null == offering) {
offering = new OfferingBundleVO();
}
offering.setAmazonOffering(amazonEC2Offering);
offering.setCloudstackOffering(cloudStackOffering);
if (null == offering)
offering = persist(offering);
else
update(offering.getID(), offering);
txn.commit();
} finally {
txn.close();
}