How to Create a Preferences Model

Extensibility covers the mechanisms by which you, as the user or developer, can extend the functionality of the Teradata Database, for example with the use of User Defined Functions, or UDFs.
Teradata Employee

How to Create a Preferences Model

In your application, you want to create a java class that will hold all of your preferences. This java class can be any POJO object. This class will be the command object (or backing class) for your form. You should design this class so that it is easy to access the preferences from the preference form.

The Framework will take care of saving your preferences to the database. In order to help the Framework know what to do, you need to mark the fields to save in your preference class. You do this using two new annotations:

  • @Preference - Marks a field as a preference.
  • @PreferenceReference - Marks a field as a reference to class that contains preferences.

If you have a particularly complex set of preferences, you may want to create a child preference class that contains a related set of preferences. For example, you might create a class for all of the preferences that are displayed on one of the tabs in your form. The @PreferenceReference annotation allows you to reference the child class from the main preferences class.

Here are three example preferences model classes:

public class QueryMonitorPreferences extends PreferencesModel
public static final String[] ALL_COLUMNS = {
"systemName", "hostId", "sessionNo", "ampState", "requestAmpCPU", "deltaCPU",
"requestAmpIO", "deltaIO", "cpuSkew", "diskSkew", "pji", "requestStartTime",
"elapsedTime", "userName", "userAccount", "workloadName", "partition",
"timeInState", /* "cost", */ "blockedTime", "requestAmpSpool", "tempSpace"
private static final String[] queryMonitorDefaultSummaryColumns = {
"sessionNo", "ampState", "deltaCPU", "cpuSkew",
"deltaIO", "pji", "elapsedTime", "userName" };
private static final String[] queryMonitorDefaultSummaryMaximizedColumns = {
"sessionNo", "ampState", "requestAmpCPU", "deltaCPU", "cpuSkew",
"requestAmpIO", "deltaIO", "diskSkew", "pji", "elapsedTime", "userName" };
/** criteria to use to determine which queries will be displayed */
@PreferenceReference private CriteriaPreferences criteria;
/** systems that are monitored */
@Preference private Map<String, Boolean> systems;
/** prefered summary columns */
@Preference private String[] summaryColumns;
/** prefered summary columns in maximized state */
@Preference private String[] maximizedSummaryColumns;
/** maximum rows to display in summary view */
@Preference private int maxDisplayedQueries;
/** sql preferences */
@PreferenceReference private SqlPreferences sql;

public QueryMonitorPreferences()
criteria = new CriteriaPreferences();
sql = new SqlPreferences();
systems = new HashMap<String, Boolean>();
summaryColumns = queryMonitorDefaultSummaryColumns;
maximizedSummaryColumns = queryMonitorDefaultSummaryMaximizedColumns;
... getters and setters

The QueryMonitorPreferences model has references to two child preferences models. Here is the SqlPreferences child model:

public class SqlPreferences extends PreferencesModel
/** seralization UID */
private static final long serialVersionUID = 8296039411740952193L;
/** is SQL formatted? */
@Preference private boolean sqlFormatted;
/** is SQL highlighted? */
@Preference private boolean sqlHighlighted;

public boolean isSqlFormatted()
return sqlFormatted;

public void setSqlFormatted(boolean sqlFormatted)
this.sqlFormatted = sqlFormatted;

public boolean isSqlHighlighted()
return sqlHighlighted;

public void setSqlHighlighted(boolean sqlHighlighted)
this.sqlHighlighted = sqlHighlighted;

Here is the CriteriaPreferences child model:

public class CriteriaPreferences extends PreferencesModel
/** serial UID */
private static final long serialVersionUID = 7087768216047115257L;
@Preference private boolean requestAmpCPUEnabled;
@Preference private boolean deltaCPUEnabled;
@Preference private boolean requestAmpIOEnabled;
@Preference private boolean deltaIOEnabled;
@Preference private boolean cpuSkewEnabled;
@Preference private boolean diskSkewEnabled;
@Preference private boolean pjiEnabled;
@Preference private boolean elapsedTimeEnabled;
@Preference private boolean ampStateEnabled;
@Preference private boolean blockedTimeEnabled;
@Preference private boolean requestAmpSpoolEnabled;
@Preference private boolean tempSpaceEnabled;
@Preference private boolean skewSysEnabled;

@Preference private String requestAmpCPU;
@Preference private String deltaCPU;
@Preference private String requestAmpIO;
@Preference private String deltaIO;
@Preference private String cpuSkew;
@Preference private String diskSkew;
@Preference private String pji;
@Preference private String elapsedTime;
@Preference private String ampState;
@Preference private String blockedTime;
@Preference private String requestAmpSpool;
@Preference private String tempSpace;
@Preference private String skewSys;
... getters and setters

Using Your Preferences Model

There are two ways to load and save user preferences. If you are using the Teradata Viewpoint controller classes, you have access to built-in load and save methods. See the Adding a Preferences Form tutorial page for examples of how to load and save preferences and also how to modify the preferences in a form.

You can also load and save preferences using the PreferencesDAO class. The methods are documented in the javadocs for this class.

Tags (3)