public static String getPrimaryKeyNameFromEntityClass(Class entityClass) { String priKey = primaryKeys.get(entityClass); if (priKey == null) { Field f = FieldUtils.getAnnotatedField(Id.class, entityClass); priKey = f.getName(); primaryKeys.put(entityClass, priKey); } return priKey; }
entityPrimaryKeyField = FieldUtils.getAnnotatedField(Id.class, entityClass); primaryKey = entityPrimaryKeyField.getName(); entityPrimaryKeyField.setAccessible(true);
ForeignKeyInfo(Class childEntity) { Class superClass = childEntity.getSuperclass(); EO eo = (EO) superClass.getAnnotation(EO.class); if (eo != null) { superClass = eo.EOClazz(); } Field priKeyField = FieldUtils.getAnnotatedField(Id.class, superClass); parentClass = superClass; entity = childEntity; parentKey = priKeyField.getName(); childKey = priKeyField.getName(); onUpdateAction = ReferenceOption.RESTRICT; onDeleteAction = ReferenceOption.CASCADE; fullName = String.format("%s.%s", superClass.getSimpleName(), parentKey); }
EntityInfo(Class voClazz) { voClass = voClazz; voPrimaryKeyField = FieldUtils.getAnnotatedField(Id.class, voClass); DebugUtils.Assert(voPrimaryKeyField != null, String.format("%s has no primary key", voClass)); voPrimaryKeyField.setAccessible(true); EO at = (EO) voClazz.getAnnotation(EO.class); if (at != null) { eoClass = at.EOClazz(); DebugUtils.Assert(eoClass != null, String.format("cannot find EO entity specified by VO entity[%s]", voClazz.getName())); eoPrimaryKeyField = FieldUtils.getAnnotatedField(Id.class, eoClass); DebugUtils.Assert(eoPrimaryKeyField != null, String.format("cannot find primary key field(@Id annotated) in EO entity[%s]", eoClass.getName())); eoPrimaryKeyField.setAccessible(true); eoSoftDeleteColumn = FieldUtils.getField(at.softDeletedColumn(), eoClass); DebugUtils.Assert(eoSoftDeleteColumn != null, String.format("cannot find soft delete column[%s] in EO entity[%s]", at.softDeletedColumn(), eoClass.getName())); eoSoftDeleteColumn.setAccessible(true); } buildInheritanceDeletionExtension(); buildSoftDeletionCascade(); }
ForeignKeyInfo(Class entity, Field f) { ForeignKey annotation = f.getAnnotation(ForeignKey.class); if ("".equals(annotation.parentKey())) { Field parentKeyField = FieldUtils.getAnnotatedField(Id.class, annotation.parentEntityClass()); parentKey = parentKeyField.getName(); } else { parentKey = annotation.parentKey(); } parentClass = annotation.parentEntityClass(); onDeleteAction = annotation.onDeleteAction(); onUpdateAction = annotation.onUpdateAction(); fullName = String.format("%s.%s", annotation.parentEntityClass().getSimpleName(), parentKey); childKey = f.getName(); this.entity = entity; }