Unique index constraint message with multiple languages

Hi all,
what if I have more than one language?
Do I have an index for every collation and a different message for each language?

---- 30.createdb.sql ----  UK/IT
-----
Postgres & Collations
https://www.postgresql.org/docs/9.1/indexes-collations.html
-----

-- create unique index IDX_CONTACTS_CONTACT_<B>UK</B>_WORK_PHONE_P on CONTACTS_CONTACT (WORK_PHONE,DTYPE) where DTYPE='P' and DELETE_TS is null ^
create unique index IDX_CONTACTS_CONTACT_<B>IT</B>_WORK_PHONE_P on CONTACTS_CONTACT (WORK_PHONE,DTYPE) where DTYPE='P' and DELETE_TS is null ^
-- create unique index IDX_CONTACTS_CONTACT_UK_WORK_CELL_PHONE_P on CONTACTS_CONTACT (WORK_CELL_PHONE,DTYPE) where DTYPE='P' and DELETE_TS is null ^
create unique index IDX_CONTACTS_CONTACT_IT_WORK_CELL_PHONE_P on CONTACTS_CONTACT (WORK_CELL_PHONE,DTYPE) where DTYPE='P' and DELETE_TS is null ^
-- create unique index IDX_CONTACTS_CONTACT_UK_WORK_FAX_P on CONTACTS_CONTACT (WORK_FAX,DTYPE) where DTYPE='P' and DELETE_TS is null ^
create unique index IDX_CONTACTS_CONTACT_IT_WORK_FAX_P on CONTACTS_CONTACT (WORK_FAX,DTYPE) where DTYPE='P' and DELETE_TS is null ^
---- 30.createdb.sql ----

messages.properties (main pack in web module)
IDX_CONTACTS_CONTACT_<B>UK</B>_WORK_CELL_PHONE_P = Work cell-phone  for Individual already exists
IDX_CONTACTS_CONTACT_UK_WORK_FAX_P = Work fax for Individual already exists
IDX_CONTACTS_CONTACT_UK_HOME_PHONE_P = Private phone for Individual already exists
IDX_CONTACTS_CONTACT_UK_HOME_CELL_PHONE_P = Private cell-phone for Individual already exists
IDX_CONTACTS_CONTACT_UK_HOME_FAX_P = Private fax for Individual already exists

 messages_it.proerties (main pack in web module)
IDX_CONTACTS_CONTACT_<B>IT</B>_HOME_CELL_PHONE_C = Il cellulare privato per l'azienda esiste già
IDX_CONTACTS_CONTACT_IT_HOME_FAX_C = Il fax privato per l'azienda esiste già
IDX_CONTACTS_CONTACT_IT_WORK_PHONE_P = Il telefono di lavoro per la persona esiste già
IDX_CONTACTS_CONTACT_IT_WORK_CELL_PHONE_P = Il cellulare di lavoro per la persona esiste già
IDX_CONTACTS_CONTACT_IT_WORK_FAX_P = Il fax di lavoro per la persona esiste già
IDX_CONTACTS_CONTACT_IT_HOME_PHONE_P = Il telefono privato per la persona esiste già
IDX_CONTACTS_CONTACT_IT_HOME_CELL_PHONE_P = Il cellulare privato per la persona esiste già
IDX_CONTACTS_CONTACT_IT_HOME_FAX_P = Il fax privato per la persona esiste già

How can I stop further execution after message display. Do I have to specialize UniqueConstraintViolationHandler ?

Thanks in Advance
Fabrizio

Hi Fabrizio,

Probably yes. What’s wrong with it?

Every exception breaks the execution, e.g. saving a record. What execution needs to be stopped in your case?

Regards,
Konstantin

Nothing wrong, I suppose I have to specify collation in sql command for index creation I did not think it could be automatic with selected language, it is a database command.

Ok I apologize description of problem was too generic. I have this situation:

Person <1–n> Address
In Person entity email and at least one address (child entity) are required.
I postvalidate and catch exception for @NotNull if user did not specify email, otherwise I procceed with Address creation and insert it in collection and then I save all in initial transaction (initial screen/dscontext for Person).
If User insert same email (just saved in another persisted Person), I get error display (using Index), but execution go on. I suppose Default Handler which display message consume exception.
Just some code:

 @Override
    protected void postValidate(ValidationErrors errors) {
        try {
            this.validate(); // this manage @NotNull
        } catch (ValidationException e) {
            log.debug("PersonEdit.postvalidate");
            return;
        } /*catch  e) {

        // Stop Execution in case of Unique Cosntraints Exception
        // Validation occurs with standard UniqueConstraintViolationHandler end message.properties, but 
execution of code goes on anyway 
        }
        */
// Otherwise: Address Creation
        if (( getItem().getAddresses() == null) || (getItem().getAddresses().isEmpty()) ) {
            showMessageDialog(messages.getMessage(getClass(),  "requestedAddressTitle"), messages.getMessage(getClass(),  "requestedAddress"), MessageType.CONFIRMATION.modal(true).closeOnClickOutside(true));
// Address Creation, etc.
            Address address = metadata.create(Address.class);
            address.setContact(getItem());
            openEditor(address, WindowManager.OpenType.DIALOG,ParamsMap.of("cou......... & go on

I hope my explanation could be clearer than before.
Thank you in advance for your reply.
Fabrizio

I think the problem has nothing to do with exception handler.
If the exception occurs in Address editor which is invoked from postValidate(), it cannot influence execution of postValidate() in any way. In fact, at the moment the editor is opened the postValidate() method is already completed.
You simply cannot interact with user in lifecycle methods like postValidate().

Thank you for your hint, Konstantin, probably difference in behaviour between @not null constraint (emailaddress) and uniqueness (emailaddress) is due to the fact that @not null is checked against values in Person Screen fields (say in memory),so when user click ok screen controller pre-checks requiremnts and throw exception (I’m still in Person Controller), instead uniqueness is checked via database interaction, so it try to commit (fields are ok), but due unique index it fails if value is not compatible, throw exception when postvalidate is positively competed but low level tier catch error and trow exception which stops closing screen and displays message in tray. Probably this not abort database transaction, because if I modify email address to be unique it goes on and saves person without street address. It does not exist a @not null equivalent database constraint that impose “at least one child with this property”, foreign keys protect the structure of relation not contents. The question about i18n whas about: "can framework impose to database usage of specific index (via a database hint [oracle] or similar mechanism) based on language selected (and so different messages connected via convention to index names)? if so when i create index via a script, an external tool integrated with studio do I have to specify collation or other parameters to instruct database I want an index for that specific language?
Thank you for your time and patience,
Fabrizio

The framework doesn’t impose any constraints on indexes you create in the database. It just provides means for showing specific messages to users in response to exception thrown from lower levels. In particular, cuba.uniqueConstraintViolationPattern property allows you to define how the original exception message from your database looks like, and use simple INDEX_NAME = Message to user properties in the main message pack.

Thank you, that’s clear, regexp permit to treat also different low level error message from different database type (mysql,postgres,etc.) I suppose, and associates via index name a different message (in Messages and messages_xx.properties) so I have errors in different languages because I have an index for each language (with country code in index name). Probably index chosen depend from ORM language parameters in connection set at user login when he/she choose application language. So i think I have to specify collation or other language parameters to guide database sytem at index creation for a specific language.
Thank you for claryfing some inner aspects of Cuba framework.
Have a nice day,
Fabrizio

You are welcome!

Regards,
Konstantin

Thank you