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: MapTable.java,v 1.3 2004/01/25 20:44:33 jackknifebarber Exp $
09: */
10:
11: package com.triactive.jdo.store;
12:
13: import com.triactive.jdo.model.FieldMetaData;
14: import com.triactive.jdo.model.MapMetaData;
15: import javax.jdo.JDOUserException;
16:
17: public class MapTable extends FieldTable {
18: private ColumnMapping ownerMapping;
19: private ColumnMapping keyMapping;
20: private ColumnMapping valueMapping;
21:
22: protected MapTable(TableMetadata tmd, FieldMetaData fmd,
23: StoreManager storeMgr) {
24: super (tmd, fmd, storeMgr);
25: }
26:
27: public void initialize() {
28: assertIsUninitialized();
29:
30: MapMetaData mmd = fmd.getMapMetaData();
31: if (mmd == null)
32: throw new JDOUserException("No map metadata found in "
33: + fmd);
34:
35: Class keyType = mmd.getKeyType();
36: Class valueType = mmd.getValueType();
37:
38: SQLIdentifier ownerColumnName = getBaseColumnNameForType(ownerType);
39: SQLIdentifier keyColumnName = getBaseColumnNameForType(keyType);
40: SQLIdentifier valueColumnName = getBaseColumnNameForType(valueType);
41:
42: Column ownerColumn = newColumn(ownerType, ownerColumnName,
43: Role.OWNER).setPrimaryKeyPart();
44: Column keyColumn = newColumn(keyType, keyColumnName, Role.KEY)
45: .setPrimaryKeyPart();
46: Column valueColumn = newColumn(valueType, valueColumnName,
47: Role.VALUE);
48:
49: keyColumn.setOptions(mmd.getKeyColumnOptions());
50: valueColumn.setOptions(mmd.getValueColumnOptions());
51:
52: if (mmd.allowsNullValues())
53: valueColumn.setNullable();
54:
55: ownerMapping = dba.getMapping(ownerColumn);
56: keyMapping = dba.getMapping(keyColumn);
57: valueMapping = dba.getMapping(valueColumn);
58:
59: state = TABLE_STATE_INITIALIZED;
60: }
61:
62: public ColumnMapping getOwnerMapping() {
63: assertIsInitialized();
64:
65: return ownerMapping;
66: }
67:
68: public ColumnMapping getKeyMapping() {
69: assertIsInitialized();
70:
71: return keyMapping;
72: }
73:
74: public ColumnMapping getValueMapping() {
75: assertIsInitialized();
76:
77: return valueMapping;
78: }
79: }
|