01: /*
02: * Copyright 2006 Davide Deidda
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: /*
18: * MapField.java
19: *
20: * Created on 15 October 2005, 16:22
21: *
22: * To change this template, choose Tools | Template Manager
23: * and open the template in the editor.
24: */
25:
26: package it.biobytes.ammentos;
27:
28: import it.biobytes.ammentos.query.Query;
29: import java.util.*;
30: import it.biobytes.ammentos.query.*;
31: import it.biobytes.ammentos.util.*;
32: import java.util.logging.*;
33:
34: /**
35: *
36: * @author davide
37: */
38: public class MapField extends CollectionField {
39: private String m_keyFieldName; // Field used as map key (name)
40: private Field m_keyField; // Field used as map key
41:
42: /**
43: * Creates a new instance of MapField
44: */
45: public MapField(Class mappedClass,
46: java.lang.reflect.Field classMember, String strQuery) {
47: super (mappedClass, classMember, strQuery);
48: }
49:
50: protected EntityCollection createEntityCollection(
51: Class mappedClass, Query query, Object parentCollection,
52: boolean deleteOnRemove) {
53: // Getting old map
54: Map map = (Map) parentCollection;
55: // Copying elements to the new EntityMap
56: return new EntityMap(mappedClass, getKeyField(), query, map,
57: deleteOnRemove);
58: }
59:
60: public Field getKeyField() {
61: if (m_keyField == null) {
62:
63: try {
64: if (m_keyFieldName == null) {
65: m_keyField = Ammentos
66: .getPrimaryKeyField(getMappedClass());
67: } else {
68: m_keyField = Ammentos.getMetadata(getMappedClass())
69: .getField(m_keyFieldName);
70: }
71: } catch (Exception e) {
72: }
73: }
74: return m_keyField;
75: }
76:
77: public void setKeyFieldName(String keyFieldName) {
78: m_keyFieldName = keyFieldName;
79: }
80:
81: }
|