01: /*
02: * Created by IntelliJ IDEA.
03: * User: mrettig
04: * Date: Jun 25, 2002
05: * Time: 11:19:49 AM
06: */
07: package net.sourceforge.jaxor;
08:
09: import net.sourceforge.jaxor.api.Mapper;
10: import net.sourceforge.jaxor.util.ObjectUtils;
11: import net.sourceforge.jaxor.util.SystemException;
12:
13: /**
14: * This class must be immutable so that we can cache the generated sql. See MetaParser and MetaRow.
15: */
16: public class MetaField implements java.io.Serializable {
17:
18: private final String _column;
19: private String _property;
20: private final boolean _canBeNull;
21: private final boolean _primaryKey;
22: private final boolean _matchOnUpdate;
23: private final boolean _isAutoAssign;
24: private final Class _mapperClass;
25:
26: public MetaField(String name, String property, boolean canBeNull,
27: boolean primaryKey, boolean matchOnUpdate,
28: boolean isAutoAssign, Class mapperClass) {
29: _column = name;
30: _property = property;
31: _canBeNull = canBeNull;
32: _primaryKey = primaryKey;
33: _matchOnUpdate = matchOnUpdate;
34: _isAutoAssign = isAutoAssign;
35: _mapperClass = mapperClass;
36: }
37:
38: public MetaField(String name, boolean canBeNull, Class mapper) {
39: this (name, null, canBeNull, false, false, false, mapper);
40: }
41:
42: public boolean isMatchOnUpdate() {
43: if (isPrimaryKey())
44: return true;
45: return _matchOnUpdate;
46: }
47:
48: public boolean isPrimaryKey() {
49: return _primaryKey;
50: }
51:
52: public String getColumn() {
53: return _column;
54: }
55:
56: public String getProperty() {
57: return _property;
58: }
59:
60: public boolean canBeNull() {
61: return _canBeNull;
62: }
63:
64: public Mapper getMapperInstance() {
65: try {
66: return (Mapper) _mapperClass.newInstance();
67: } catch (InstantiationException e) {
68: throw new SystemException(e);
69: } catch (IllegalAccessException e) {
70: throw new SystemException(e);
71: }
72: }
73:
74: public int hashCode() {
75: return _column.hashCode();
76: }
77:
78: public boolean equals(Object obj) {
79: if (obj instanceof MetaField)
80: return equals((MetaField) obj);
81: return false;
82: }
83:
84: public boolean equals(MetaField field) {
85: if (!getColumn().equals(field.getColumn()))
86: return false;
87: if (canBeNull() != field.canBeNull())
88: return false;
89: if (!ObjectUtils.equals(getProperty(), field.getProperty()))
90: return false;
91: return true;
92: }
93:
94: public boolean isAutoAssign() {
95: return _isAutoAssign;
96: }
97:
98: }
|