static find Method Design Pattern
Each table with a key should have a static find method. The method is used to find a record that fulfills the specified key.
The find method must:
-
Be static because it is used to find a record amongst all the objects of the table class.
-
Return an object of the type of the table (or null if not found).
-
Be named find.
-
Have a parameter of the same type as the key of the table or a list of parameters if the key consists of more than one field. If there is a list of parameters, they must be in the same order that the key fields are listed in the index that supports the key of the table.
-
Have a Boolean parameter with a default value of false. If true, the record should be selected for update.
-
Have an optional parameter to enable the default Concurrency Model behavior specified on the table to overruled. The default value for the parameter should be ConcurrencyModel::Auto.
-
Make the most effective select operation for the single record from the table and return it. Use an index that matches the required field, and use the firstOnly keyword (see the following example).
-
Run on both the client and the server. This is the default behavior. You can also make it explicit by putting "client server" in the declaration, but do not specify a single tier in the declaration (either the client or the server).
The method must be used whenever a record is selected by its key from the database.
Note |
|---|
|
Declare find methods as public. If you don't, a best practices warning appears if the method is not used in the application. (The warning suggests that you declare the method as private because this is the most restrictive level of access.) |
static CustInterestJour find(
InterestNote _interestNote,
boolean _forUpdate = false,
ConcurrencyModel _concurrencyModel = ConcurrencyModel::Auto)
{
CustInterestJour custInterestJour;
if (_interestNote)
{
if (_forUpdate)
{
custInterestJour.selectForUpdate(_forUpdate);
if (_concurrencyModel != ConcurrencyModel::Auto)
{
custInterestJour.concurrencyModel(_concurrencyModel);
}
}
select firstonly custInterestJour
index hint InterestIdx
where custInterestJour.InterestNote == _interestNote;
}
return custInterestJour;
}
Note