01: /*
02: * Copyright 2002 (C) TJDO.
03: * All rights reserved.
04: *
05: * This software is distributed under the terms of the TJDO License version 1.0.
06: * See the terms of the TJDO License in the documentation provided with this software.
07: *
08: * $Id: Role.java,v 1.2 2002/10/17 21:00:58 pierreg0 Exp $
09: */
10:
11: package com.triactive.jdo.store;
12:
13: class Role {
14: private static final int ROLE_TYPE_NONE = 0;
15: private static final int ROLE_TYPE_OWNER = 1;
16: private static final int ROLE_TYPE_ELEMENT = 2;
17: private static final int ROLE_TYPE_KEY = 3;
18: private static final int ROLE_TYPE_VALUE = 4;
19:
20: public static final Role NONE = new Role(ROLE_TYPE_NONE);
21: public static final Role OWNER = new Role(ROLE_TYPE_OWNER);
22: public static final Role ELEMENT = new Role(ROLE_TYPE_ELEMENT);
23: public static final Role KEY = new Role(ROLE_TYPE_KEY);
24: public static final Role VALUE = new Role(ROLE_TYPE_VALUE);
25:
26: public static final int MAX_SUFFIX_LENGTH = 4;
27:
28: private final int type;
29:
30: private Role(int type) {
31: this .type = type;
32: }
33:
34: public String getSQLIdentifierSuffix(DatabaseAdapter dba,
35: Class columnType) {
36: boolean isIDType = !dba.isEmbeddedType(columnType);
37:
38: String suffix;
39:
40: switch (type) {
41: case ROLE_TYPE_NONE:
42: default:
43: suffix = isIDType ? "_ID" : "";
44: break;
45:
46: case ROLE_TYPE_OWNER:
47: suffix = isIDType ? "_OID" : "_OWN";
48: break;
49:
50: case ROLE_TYPE_ELEMENT:
51: suffix = isIDType ? "_EID" : "_ELE";
52: break;
53:
54: case ROLE_TYPE_KEY:
55: suffix = isIDType ? "_KID" : "_KEY";
56: break;
57:
58: case ROLE_TYPE_VALUE:
59: suffix = isIDType ? "_VID" : "_VAL";
60: break;
61: }
62:
63: return suffix;
64: }
65: }
|