KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > triactive > jdo > store > Role


1 /*
2  * Copyright 2002 (C) TJDO.
3  * All rights reserved.
4  *
5  * This software is distributed under the terms of the TJDO License version 1.0.
6  * See the terms of the TJDO License in the documentation provided with this software.
7  *
8  * $Id: Role.java,v 1.2 2002/10/17 21:00:58 pierreg0 Exp $
9  */

10
11 package com.triactive.jdo.store;
12
13
14 class Role
15 {
16     private static final int ROLE_TYPE_NONE = 0;
17     private static final int ROLE_TYPE_OWNER = 1;
18     private static final int ROLE_TYPE_ELEMENT = 2;
19     private static final int ROLE_TYPE_KEY = 3;
20     private static final int ROLE_TYPE_VALUE = 4;
21
22     public static final Role NONE = new Role(ROLE_TYPE_NONE);
23     public static final Role OWNER = new Role(ROLE_TYPE_OWNER);
24     public static final Role ELEMENT = new Role(ROLE_TYPE_ELEMENT);
25     public static final Role KEY = new Role(ROLE_TYPE_KEY);
26     public static final Role VALUE = new Role(ROLE_TYPE_VALUE);
27
28     public static final int MAX_SUFFIX_LENGTH = 4;
29
30
31     private final int type;
32
33     private Role(int type)
34     {
35         this.type = type;
36     }
37
38     public String JavaDoc getSQLIdentifierSuffix(DatabaseAdapter dba, Class JavaDoc columnType)
39     {
40         boolean isIDType = !dba.isEmbeddedType(columnType);
41
42         String JavaDoc suffix;
43
44         switch (type)
45         {
46             case ROLE_TYPE_NONE:
47             default:
48                 suffix = isIDType ? "_ID" : "";
49                 break;
50
51             case ROLE_TYPE_OWNER:
52                 suffix = isIDType ? "_OID" : "_OWN";
53                 break;
54
55             case ROLE_TYPE_ELEMENT:
56                 suffix = isIDType ? "_EID" : "_ELE";
57                 break;
58
59             case ROLE_TYPE_KEY:
60                 suffix = isIDType ? "_KID" : "_KEY";
61                 break;
62
63             case ROLE_TYPE_VALUE:
64                 suffix = isIDType ? "_VID" : "_VAL";
65                 break;
66         }
67
68         return suffix;
69     }
70 }
71
Popular Tags