Foren

Book Liferay In Action: why to clone Product object?

thumbnail
Kravchenko Dmitry, geändert vor 12 Jahren.

Book Liferay In Action: why to clone Product object?

Regular Member Beiträge: 139 Beitrittsdatum: 04.10.10 Neueste Beiträge
In the book Liferay In Action, the sample function of adding a product looks follows:


public class PRProductLocalServiceImpl extends PRProductLocalServiceBaseImpl {
	public PRProduct addProduct(PRProduct newProduct, long userId)
			throws SystemException, PortalException {
		
		PRProduct product = prProductPersistence.create(counterLocalService
				.increment(PRProduct.class.getName()));
		
		resourceLocalService.addResources(newProduct.getCompanyId(),
				newProduct.getGroupId(), userId, PRProduct.class.getName(),
				product.getPrimaryKey(), false, true, true);
		
		product.setProductName(newProduct.getProductName());
		product.setSerialNumber(newProduct.getSerialNumber());
		product.setCompanyId(newProduct.getCompanyId());
		product.setGroupId(newProduct.getGroupId());
		
		return prProductPersistence.update(product, false);
	}
}


What for should I create another object PRProduct product while I already have one PRProduct newProduct, passed as method argument?
thumbnail
Sandeep Nair, geändert vor 12 Jahren.

RE: Book Liferay In Action: why to clone Product object?

Liferay Legend Beiträge: 1744 Beitrittsdatum: 06.11.08 Neueste Beiträge
In the example prProductPersistence.create(counterLocalService .increment(PRProduct.class.getName())); creates a new product with primary key which is not created in database yet. You can also use newProduct and set its primary key like newProduct.setProductId(counterLocalService .increment(PRProduct.class.getName())) and then finally use addProduct method of the api which would add teh product object in database.

Regards,
Sandeep
thumbnail
Kravchenko Dmitry, geändert vor 12 Jahren.

RE: Book Liferay In Action: why to clone Product object?

Regular Member Beiträge: 139 Beitrittsdatum: 04.10.10 Neueste Beiträge
How can one know if one specific instance of PRProduct is created or not?

Why the Builder-generated code is follows:


public PRProduct addPRProduct(PRProduct prProduct)
		throws SystemException {
		prProduct.setNew(true);

		return prProductPersistence.update(prProduct, false);
	}


Whye builder doesn't do operations Sezov does?