01: package simpleorm.quickstart;
02:
03: /**
04: * This is the nice name formatter used to convert the test database used by SimpleORM.<p>
05: *
06: * Normally there is a simple algrothem but is overwritten as required.<br>
07: *
08: * @author <a href="mailto:richard.schmidt@inform6.com">Richard Schmidt</a>
09: */
10: public class SimpleORMNiceNameFormatter implements INiceNameFormatter {
11: /**
12: * For most tables drop the leading XX_. Some table map to individual names.
13: *
14: * @see simpleorm.quickstart.INiceNameFormatter#niceNameForTable(String)
15: */
16: public String niceNameForTable(String table) {
17: //Map some of the funnies in simpleorg.examples
18: if (table.equalsIgnoreCase("XX_PAY_PERIOD")) {
19: return "Period";
20: }
21:
22: if (table.equalsIgnoreCase("XX_PAY_SLIP")) {
23: return "PaySlip";
24: }
25:
26: if (table.equalsIgnoreCase("XX_PSLIP_DETAIL")) {
27: return "PaySlipDetail";
28: }
29:
30: //Remove the XX_
31: String str = table.substring(3);
32: str = str.substring(0, 1).toUpperCase()
33: + str.substring(1).toLowerCase();
34:
35: return str;
36: }
37:
38: /**
39: * Normally simply convert to uppercase. But since VALUE is a reserved word in Interbase,
40: * a '_' was added to the field in the database generation scrips. So remove them!
41: *
42: * @see simpleorm.quickstart.INiceNameFormatter#niceNameForColumn(String)
43: */
44: public String niceNameForColumn(String table, String column) {
45: if ((table.equalsIgnoreCase("XX_PSLIP_DETAIL"))
46: && (column.equalsIgnoreCase("VALUE_"))) {
47: return "VALUE";
48: }
49:
50: return column.toUpperCase();
51: }
52:
53: /**
54: * Normally just return the nice name of the foreign table. but in the case of
55: * Employee that references itself, return the field as MANAGER
56: *
57: * @see simpleorm.quickstart.INiceNameFormatter#niceNameForForeignKey(String, String)
58: */
59: public String niceNameForForeignKey(String localTable,
60: String foreignTable) {
61: if (localTable.equalsIgnoreCase("XX_EMPLOYEE")
62: && foreignTable.equalsIgnoreCase("XX_EMPLOYEE")) {
63: return "MANAGER";
64: }
65:
66: return foreignTable.substring(3).toUpperCase();
67: }
68: }
|