1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.seasar.tuigwaa.database;
23
24 import java.util.Properties;
25
26 import org.hibernate.FetchMode;
27 import org.hibernate.MappingException;
28 import org.hibernate.id.PersistentIdentifierGenerator;
29 import org.hibernate.mapping.Column;
30 import org.hibernate.mapping.ManyToOne;
31 import org.hibernate.mapping.Property;
32 import org.hibernate.mapping.RootClass;
33 import org.hibernate.mapping.SimpleValue;
34 import org.hibernate.mapping.Table;
35 import org.hibernate.type.TypeFactory;
36 import org.seasar.tuigwaa.model.core.TgwAttribute;
37 import org.seasar.tuigwaa.model.core.impl.FileAttribute;
38 import org.seasar.tuigwaa.model.core.impl.FkAttribute;
39 import org.seasar.tuigwaa.system.Constants;
40 import org.seasar.tuigwaa.util.TgwUtils;
41
42
43 /***
44 * おそらく使われていない。様子見のため残している。
45 * @author nishioka
46 * @deprecated
47 */
48 class DynaBinder {
49
50 /***
51 * @deprecated
52 */
53 public static void bindColumn(RootClass root, TgwAttribute field)
54 throws MappingException {
55 String columnName = field.getName();
56 String hibernateType = TgwUtils.toHibernateType(field);
57
58
59 TypeFactory.heuristicType(hibernateType);
60
61 Table table = root.getTable();
62
63 SimpleValue value = new SimpleValue(table);
64 value.setTypeName(hibernateType);
65
66 bindColumn(table, value, columnName, hibernateType, true);
67
68
69 String propName = columnName;
70 Property prop = createProperty(propName, value, field);
71 if (propName.equals(Constants.ENTITY_BUILTIN_CREATIONDATE)
72 || field instanceof FileAttribute) {
73 prop.setUpdateable(false);
74 }
75 root.addProperty(prop);
76 }
77
78 /***
79 * @deprecated
80 */
81 public static void bindManyToOne(RootClass root, TgwAttribute field)
82 throws MappingException, ClassNotFoundException {
83 FkAttribute fk = (FkAttribute) field;
84 Table table = root.getTable();
85
86 ManyToOne value = new ManyToOne(root.getTable());
87
88 value.setReferencedEntityName(fk.getRefEntity().getJavaClassName());
89
90
91
92
93 bindColumn(table, value, field.getName(), null, true);
94
95
96
97 value.setFetchMode(FetchMode.DEFAULT);
98
99
100 value.createForeignKey();
101
102 String propName = field.getName();
103 Property prop = createProperty(propName, value, field);
104 root.addProperty(prop);
105
106 }
107
108 /***
109 * @deprecated
110 */
111 public static void bindId(RootClass root, String schema)
112 throws MappingException {
113
114 Table table = root.getTable();
115
116 SimpleValue id = new SimpleValue(table);
117 root.setIdentifier(id);
118
119 id.setTypeName("java.lang.Long");
120 id.setIdentifierGeneratorStrategy("increment");
121 id.getTable().setIdentifierValue(id);
122
123
124 bindColumn(table, id, Constants.ENTITY_BUILTIN_ID, null, true);
125
126 Properties param = new Properties();
127
128 if (schema != null) {
129 param.setProperty(PersistentIdentifierGenerator.SCHEMA, schema);
130 }
131
132 param.setProperty(PersistentIdentifierGenerator.TABLE, root.getTable()
133 .getName());
134 param.setProperty(PersistentIdentifierGenerator.PK, "id");
135
136
137 id.setIdentifierGeneratorProperties(param);
138
139 Property idProp = createProperty("Id", id, null);
140 root.setIdentifierProperty(idProp);
141
142 root.createPrimaryKey();
143 }
144
145 /***
146 * @deprecated
147 */
148 public static void bindColumn(Table table, SimpleValue value, String name,
149 String hibernateType, boolean nullable) {
150 Column contentCol = new Column();
151
152
153 contentCol.setNullable(nullable);
154 if(!Constants.ENTITY_BUILTIN_ID.equals(name)){
155 contentCol.setName(name + "_");
156 }else{
157 contentCol.setName(name);
158 }
159 table.addColumn(contentCol);
160 value.addColumn(contentCol);
161 }
162
163 /***
164 * @deprecated
165 */
166 public static Property createProperty(String propertyName,
167 SimpleValue value, TgwAttribute field) {
168 Property prop = new Property();
169 prop.setName(propertyName);
170 prop.setValue(value);
171 return prop;
172 }
173 }