Extending PostgresSequenceSupport

Hello everyone,

Is there a way to extend the class com.haulmont.cuba.core.sys.persistence.PostgresSequenceSupport ?

I would like to use the possibility to define min and max values for a sequence as well as the cycle (as defined here: PostgreSQL: Documentation: 9.5: CREATE SEQUENCE)

Thank you,
Samy

Hi.

Classes related to database support extends according to following template <dbmsType><dbmsVersion><InterfaceName>.
So you have to create Postgres<dbmsVersion>SequenceSupport class where <dbmsVersion> is some string constant. After that set the cuba.dbmsVersion property value to <dbmsVersion>.

If it becomes necessary to debug check com.haulmont.cuba.core.sys.persistence.DbmsSpecificFactory#create(java.lang.Class<T>, java.lang.String, java.lang.String) method.

Regards,
Natalia.

Thanks Natalia for the help.

In order to use MAXVALUE of Postgres sequence, I would need to extend the class Sequence of Cuba to include th MAXVALUE. However the class is not extendable because of private constructor.

It looks like I need to implement various classes in order to be able to use the features of Postgres sequences. Do you know a better efficient approach to do it?

Thanks,
Samy

Hi,
You can implement your own Spring bean and service if you need custom logic.
Why do you need to override the logic of SequenceSupport from the platform?

Thanks Alexander for your response.

Basically I want to override the method createSequenceSql of the PostgresSequenceSupport class to be able to use full functionality of Postgres sequence (PostgreSQL: Documentation: 13: CREATE SEQUENCE).

The idea is to be able to define minvalue, maxvalue as well as the cycle.

Is there any reason that you need to override the platform logic instead of creating your own Spring bean alongside existing UniqueNumbersService functionality?

I thought even with my Spring Bean I would need to implement the same logic as the platform. I thought it would be simpler to extend the platform implementation.

So if I understand well you are suggesting to create a new CustomUniqueNumbersService that defines a method such getNextNumber(String seqName, long min, long max, long incr, bool cycle) and then I have to implement the SQL statements in the CustomUniqueNumbersServiceBean?

Yes, something like this.
Writing custom code will be easier in this case (because the method signature is different).

Extending platform code is often harder for classes where the possibility of extension wasn’t intended by the author.

1 Like