In this blog, I will be putting some light on how you can run dynamic queries for all liferay plugins portlets using common service builder. For this you can easily use same service builder for all Liferay plugin portlets and can create a service builder portlet which has all entities. After that, you need to import this service builder with liferay-plugin-package.properties add Required Deployment Contexts by ui or add it last required-deployment-contexts=\ServicePortlet-portlet.
After that you are required to use dynamic queries as given below:
ClassLoader classLoader = (ClassLoader)PortletBeanLocatorUtil.locate(ClpSerializer.getServletContextName(), "portletClassLoader");
OR
ClassLoader classLoader = PortletBeanLocatorUtil.getBeanLocator(ClpSerializer.getServletContextName()).getClassLoader();
DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(charges.class,classLoader);
ClpSerializer must be of imported service builder portlet.
You can insert data like this:
long id = CounterLocalServiceUtil.increment(XXX.class.getName());
XXX xxx = XXXLocalServiceUtil.createXXX(id);
XXXLocalServiceUtil.addXXX(xxx);
0 Comment(s)