This website uses cookies for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information

--Considering Check Constraints from the Database

Documents for the development of and with JVx.

--Considering Check Constraints from the Database

Postby Development@SIB » Fri Sep 17, 2010 10:51 am



This article is outdated - please use our new system at

https://doc.sibvisions.com




In addition to the use of Default Values the restriction to "allowed values" is another advantage of JVx.

The "allowed values"for columns are usually defined in the database using check constraints. These are evaluated by JVx and assumed as so called allowed values.

The constraints directly impact the user interface, as the user is only offered the allowed values in the form of Choice Cell Editors.


Example

Based on the example for Default Values, we define the following check constraints (Oracle Syntax):

Code: Select all
alter table USERS
  add constraint USER_ACTIVE_CHECK
  check (active IN ('Y', 'N'));

alter table USERS
  add constraint USER_CHANGE_PASSWORD_CHECK
  check (CHANGE_PASSWORD IN ('Y', 'N'));

Therefore the fields "ACTIVE" and "CHANGE_PASSWORD" can only contain "Y" or "N".

So that in the user interface the correct Choice Cell Editor is used, this must be defined. This is done globally by calling:

Code: Select all
UIChoiceCellEditor.addDefaultChoiceCellEditor(editor);


A Choice Cell Editor from the ApplicationUtil has already defined for the values "Y" and "N".

The following methods can be used to disable the check constraints detection:

Code: Select all
//per instance
users.setAllowedValues(false);

//for all instances (static)
DBStorage.setDefaultAllowedValues(false);


If no check constrains are used in the database, the allowed values can be set via the API:

Code: Select all
users.open();

//sets allowed/possible values
users.getMetaData().getColumnMetaData("ACTIVE").setAllowedValues(new Object[] {"Y", "N"});
User avatar
Development@SIB
 
Posts: 325
Joined: Mon Sep 28, 2009 1:54 pm

Return to Documentation