use of javax.persistence.TableGenerator in project CloudStack-archive by CloudStack-extras.
the class SqlGenerator method buildAttributes.
protected void buildAttributes(Class<?> clazz, String tableName, AttributeOverride[] overrides, boolean embedded, boolean isId) {
if (!embedded && clazz.getAnnotation(Entity.class) == null) {
return;
}
Class<?> parent = clazz.getSuperclass();
if (parent != null) {
buildAttributes(parent, DbUtil.getTableName(parent), DbUtil.getAttributeOverrides(parent), false, false);
}
if (!embedded) {
_tables.add(clazz);
_ids.put(tableName, new ArrayList<Attribute>());
}
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
field.setAccessible(true);
TableGenerator tg = field.getAnnotation(TableGenerator.class);
if (tg != null) {
_generators.put(field.getName(), tg);
}
if (!DbUtil.isPersistable(field)) {
continue;
}
if (field.getAnnotation(Embedded.class) != null) {
_embeddeds.add(field);
Class<?> embeddedClass = field.getType();
assert (embeddedClass.getAnnotation(Embeddable.class) != null) : "Class is not annotated with Embeddable: " + embeddedClass.getName();
buildAttributes(embeddedClass, tableName, DbUtil.getAttributeOverrides(field), true, false);
continue;
}
if (field.getAnnotation(EmbeddedId.class) != null) {
_embeddeds.add(field);
Class<?> embeddedClass = field.getType();
assert (embeddedClass.getAnnotation(Embeddable.class) != null) : "Class is not annotated with Embeddable: " + embeddedClass.getName();
buildAttributes(embeddedClass, tableName, DbUtil.getAttributeOverrides(field), true, true);
continue;
}
Attribute attr = new Attribute(clazz, overrides, field, tableName, embedded, isId);
if (attr.getColumnName().equals(GenericDao.REMOVED_COLUMN)) {
attr.setColumnName(GenericDao.REMOVED);
attr.setTrue(Attribute.Flag.DaoGenerated);
attr.setFalse(Attribute.Flag.Insertable);
attr.setFalse(Attribute.Flag.Updatable);
attr.setTrue(Attribute.Flag.TimeStamp);
attr.setFalse(Attribute.Flag.Time);
attr.setFalse(Attribute.Flag.Date);
attr.setTrue(Attribute.Flag.Nullable);
attr.setTrue(Attribute.Flag.Removed);
}
if (attr.isId()) {
List<Attribute> attrs = _ids.get(tableName);
attrs.add(attr);
}
_attributes.add(attr);
}
}
Aggregations