Fórum
Counter Service for auto increment
Nirav Prajapati, modificado 6 Anos atrás.
Counter Service for auto increment
Regular Member Postagens: 133 Data de Entrada: 25/06/15 Postagens Recentes
Hello Friends,
I am using liferay 6.2 CE-GA6 with service builder.
For ID Auto-increment i am using long id = CounterLocalServiceUtil.increment(MyClass.class.getName());
But here Counter is start from 1.
I want to set counter start from 10000000 to 19999999 on portlet level not portal.
Means counter Start from 10000000 and it will Stop on 19999999.
Please help me to fix it.
I am using liferay 6.2 CE-GA6 with service builder.
For ID Auto-increment i am using long id = CounterLocalServiceUtil.increment(MyClass.class.getName());
But here Counter is start from 1.
I want to set counter start from 10000000 to 19999999 on portlet level not portal.
Means counter Start from 10000000 and it will Stop on 19999999.
Please help me to fix it.
Jorge Díaz, modificado 6 Anos atrás.
RE: Counter Service for auto increment (Resposta)
Liferay Master Postagens: 753 Data de Entrada: 09/01/14 Postagens Recentes
You can change the start value to 10000000 but it is not possible to set up a stop value.
In order to get values starting from 10000000, you have to update your counter MyClass.class.getName().
The counter is stored in counter_ table, but don't directly update it, use Liferay API instead.
You have to call:
You can execute that code from a custom portlet or from groovy script console
In order to get values starting from 10000000, you have to update your counter MyClass.class.getName().
The counter is stored in counter_ table, but don't directly update it, use Liferay API instead.
You have to call:
- Get counter calling CounterLocalServiceUtil.getCounter method: com/liferay/counter/service/base/CounterLocalServiceBaseImpl.java#L214-L216
- Set the counter to the desired value with setCurrentId
- Update counter value calling CounterLocalServiceUtil.updateCounter method: com/liferay/counter/service/base/CounterLocalServiceBaseImpl.java#L267-L269
You can execute that code from a custom portlet or from groovy script console
Nirav Prajapati, modificado 6 Anos atrás.
RE: Counter Service for auto increment
Regular Member Postagens: 133 Data de Entrada: 25/06/15 Postagens Recentes
Thank You