Chapter 10 Snippets

p. 308

Step 3, top of page:

boolean returnVal;
if (value.toString().length() < getMaxLength())
{
  returnVal = true;
}
else
{
  returnVal = false;
}
return returnVal;

Step 2:

throw new ValidationException(getDescription());

p. 311

Step 4:

int length = mData.length();
char currentChar;
for (int i = 0; i < length; i++)
{
  currentChar = mData.charAt(i);
  if (
    (i == 2 && currentChar != '_') ||
    (i != 2 && (currentChar < 'A' || currentChar > 'Z')) )
  {
    throw new JboException(
      "Job IDs must have the format XX_XXXXXX.");
  }
}

p. 313

Step 8:

String jobIdString = (String) getJobId().getData();

if (
  jobIdString.endsWith("VP") ||
  jobIdString.endsWith("PRES") )
{
  if (getSalary().intValue() < 15000)
  {
    throw new JboException(
      "Executives must have a salary of at least 15,000.");
  }
}

else
{
  if (getSalary().intValue() > 14999)
  {
    throw new JboException(
      "Non-executives cannot have a salary over 14,999.");
  }
}

p. 322

Step 4, near bottom of page:

Date currentDate = new Date(Date.getCurrentDate());
setHireDate(currentDate);

Step 5, bottom of page:

SequenceImpl empSeq = new SequenceImpl(
  "EMPLOYEES_SEQ", getDBTransaction() );
setEmployeeId(empSeq.getSequenceNumber());

p. 324

Step 3, top of page:

(NVL(SALARY, 0) *
  (12 + (NVL(COMMISSION_PCT, 0) * .6)))

Step 2:

private void calculateYearlyPay(Number sal, Number commPct)
{
  int salValue = 0;
  double commPctValue = 0;
  if (sal != null)
  {
    salValue = sal.intValue();
  }
  if (commPct != null)
  {
    commPctValue = commPct.doubleValue();
  }
  int yearlyPayValue =
    (int) (salValue * (12 + (commPctValue * .6)));
  setYearlyPay(new Number(yearlyPayValue));
}

p. 325

Step 4, top of page:

calculateYearlyPay(value, getCommissionPct());

Step 6, near top of page:

calculateYearlyPay(getSalary(), value);

p. 326

Step 11, top of page:

return getEmployees().getYearlyPay();

p. 327

Top of page:

boolean ok = true;
EmployeesImpl manager = getManager();
if (manager != null)
{
  if (manager.getSalary().intValue() < value.intValue())
  {
    ok = false;
  }
}

Step 3:

if (ok)
{
  setAttributeInternal(SALARY, value);
}
else
{
  throw new JboException(
    "Managers' salaries cannot be lower than their employees'." );
}

Step 1:

RowIterator reports = getReports();
EmployeesImpl current;
while (reports.hasNext())
{
  current = (EmployeesImpl) reports.next();
  if (current.getSalary().intValue() > value.intValue())
  {
    ok = false;
  }
}