public Entity(Class entityClass) { this.entityClass = entityClass; FieldUtils.getAllFields(entityClass) .stream().filter(f -> !Modifier.isStatic(f.getModifiers()) && !Modifier.isTransient(f.getModifiers())) .forEach(f -> { fields.put(f.getName(), f); f.setAccessible(true); }); }
public static boolean hasField(String name, Class clazz) { return getField(name, clazz) != null; }
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; }
private void collectAfterRunnable(Flow flow) { List<Field> ad = FieldUtils.getAnnotatedFieldsOnThisClass(AfterDone.class, flow.getClass()); for (Field f : ad) { List lst = FieldUtils.getFieldValue(f.getName(), flow); if (lst != null) { afterDone.add(lst); } } ad = FieldUtils.getAnnotatedFieldsOnThisClass(AfterError.class, flow.getClass()); for (Field f : ad) { List lst = FieldUtils.getFieldValue(f.getName(), flow); if (lst != null) { afterError.add(lst); } } ad = FieldUtils.getAnnotatedFieldsOnThisClass(AfterFinal.class, flow.getClass()); for (Field f : ad) { List lst = FieldUtils.getFieldValue(f.getName(), flow); if (lst != null) { afterFinal.add(lst); } } }
private void collectIndex(Class entity) { List<Field> fs; Class superClass = entity.getSuperclass(); if (superClass.isAnnotationPresent(Entity.class) || entity.isAnnotationPresent(EO.class)) { // parent class or EO class is also an entity, it will take care of its foreign key, // so we only do our own foreign keys; fs = FieldUtils.getAnnotatedFieldsOnThisClass(Index.class, entity); } else { fs = FieldUtils.getAnnotatedFields(Index.class, entity); } List<IndexInfo> keyInfos = indexMap.get(entity); if (keyInfos == null) { keyInfos = new ArrayList<IndexInfo>(); indexMap.put(entity, keyInfos); } for (Field f : fs) { keyInfos.add(new IndexInfo(entity, f)); } } }
entityPrimaryKeyField = FieldUtils.getAnnotatedField(Id.class, entityClass); primaryKey = entityPrimaryKeyField.getName(); entityPrimaryKeyField.setAccessible(true); inventoryPrimaryKeyField = FieldUtils.getField(primaryKey, inventoryClass); if (inventoryPrimaryKeyField != null) { inventoryPrimaryKeyField.setAccessible(true); inventoryTypeField = FieldUtils.getAnnotatedFieldOfThisClass(TypeField.class, invClass); if (inventoryTypeField != null) { inventoryTypeField.setAccessible(true); entityTypeField = FieldUtils.getField(inventoryTypeField.getName(), entityClass); DebugUtils.Assert(entityTypeField != null, String.format("the type field[%s] of inventory class[%s] is not on entity class[%s]", inventoryTypeField.getName(), inventoryClass.getName(), entityClass.getName())); entityTypeField.setAccessible(true); List<Field> allFields = FieldUtils.getAllFields(inventoryClass); for (Field f : allFields) { f.setAccessible(true);
private void build(Object o, Stack<String> paths) throws IllegalAccessException { List<Field> fields = FieldUtils.getAllFields(o.getClass()); Collection c = (Collection) value; Class gtype = FieldUtils.getGenericType(f); Class gtype = FieldUtils.getGenericType(f);
List<Field> fields = FieldUtils.getAllFields(clz); if (at != null) { for (OverriddenApiParam atp : at.value()) { Field f = FieldUtils.getField(atp.field(), clz); if (f == null) { throw new CloudRuntimeException(String.format("cannot find the field[%s] specified in @OverriddenApiParam of class[%s]",
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(); }
String toJpql() { String entityName = inventoryClass.getSimpleName().toLowerCase(); attrValueName = entityName + "_" + attr + "_" + "value" + index; Field inventoryField = FieldUtils.getField(attr, inventoryClass); Field metaField = FieldUtils.getField(attr, info.jpaMetaClass); if (metaField == null) { throw new OperationFailureException(argerr("entity meta class[%s] has no field[%s]", entityField = FieldUtils.getField(attr, info.entityClass); DebugUtils.Assert(entityField != null, String.format("mismatching between inventory[%s] and entity[%s], field[%s] is not present on entity", inventoryClass.getName(), info.entityClass.getName(), attr)); DebugUtils.Assert(mappingInvAt != null, String.format("Mapping inventory class[%s] of inventory class[%s] is not annotated by @Inventory", mappingInvClass.getName(), inventoryClass.getName())); Class foreignVOClass = mappingInvAt.mappingVOClass(); DebugUtils.Assert(FieldUtils.hasField(refName, foreignVOClass), String.format("referencedColumnName of JoinColumn of field[%s] on inventory class[%s] is invalid, class[%s] doesn't have field[%s]", inventoryField.getName(), inventoryClass.getName(), foreignVOClass.getName(), refName)); DebugUtils.Assert(FieldUtils.hasField(foreignKey, foreignVOClass), String.format("name of JoinColumn of field[%s] on inventory class[%s] is invalid, class[%s] doesn't have field[%s]", inventoryField.getName(), inventoryClass.getName(), foreignVOClass.getName(), foreignKey));
RecoveryAwareAMQConnection delegate = FieldUtils.getFieldValue("delegate", conn); DebugUtils.Assert(delegate != null, "cannot get RecoveryAwareAMQConnection"); Field _missedHeartbeats = FieldUtils.getField("_missedHeartbeats", RecoveryAwareAMQConnection.class); DebugUtils.Assert(_missedHeartbeats!=null, "cannot find _missedHeartbeats"); _missedHeartbeats.setAccessible(true);
private Class getEntityFieldType() { if (Collection.class.isAssignableFrom(entityField.getType())) { return FieldUtils.getGenericType(entityField); } else if (Map.class.isAssignableFrom(entityField.getType())) { throw new CloudRuntimeException(String.format("query cannot support Map type. %s.%s", entityField.getDeclaringClass(), entityField.getName())); } else { return entityField.getType(); } }
static String getResourceUuid(Object entity) { if (entity instanceof ResourceVO) { return ((ResourceVO) entity).getUuid(); } return FieldUtils.getFieldValue("uuid", entity); } }
@Override public String validate(Object obj) { List<Field> fs = FieldUtils.getAnnotatedFields(Validation.class, obj.getClass()); for (Field f : fs) { String err = validate(obj, f); if (err != null) { return err; } } return null; } }
List<Field> fs = FieldUtils.getAllFields(apiClass); fs = fs.stream().filter(f -> !f.isAnnotationPresent(APINoSee.class) && !Modifier.isStatic(f.getModifiers())).collect(Collectors.toList()); for (Field f : fs) { Class gtype = FieldUtils.getGenericType(f);
private void buildApiParams(ApiMessageDescriptor desc) { Class msgClz = desc.getClazz(); List<Field> fields = FieldUtils.getAllFields(msgClz); if (at != null) { for (OverriddenApiParam atp : at.value()) { Field f = FieldUtils.getField(atp.field(), msgClz); if (f == null) { throw new CloudRuntimeException(String.format("cannot find the field[%s] specified in @OverriddenApiParam of class[%s]",
fs = FieldUtils.getAnnotatedFieldsOnThisClass(ForeignKey.class, entity); } else { fs = FieldUtils.getAnnotatedFields(ForeignKey.class, entity);
Object queryParameterToApiFieldValue(String name, String[] vals) throws RestException { Field f = allApiClassFields.get(name); if (f == null) { return null; } if (Collection.class.isAssignableFrom(f.getType())) { Class gtype = FieldUtils.getGenericType(f); List lst = new ArrayList(); for (String v : vals) { lst.add(TypeUtils.stringToValue(v, gtype)); } return lst; } else { if (vals.length > 1) { throw new RestException(HttpStatus.BAD_REQUEST.value(), String.format("Invalid query parameter[%s], only one value is allowed for the parameter but" + " multiple values found", name)); } return TypeUtils.stringToValue(vals[0], f.getType()); } } }
private String getFlowName(Flow flow) { String name = FieldUtils.getFieldValue("__name__", flow); if (name == null) { name = flow.getClass().getSimpleName(); if (name.equals("")) { name = flow.getClass().getName(); } } if (logger.isTraceEnabled()) { String className = flow.getClass().getName(); String[] ff = className.split("\\."); String filename = ff[ff.length-1]; if (filename.contains("$")) { int index = filename.indexOf("$"); filename = filename.substring(0, index); } name = String.format("%s.java:%s", filename, name); } return name; }
private void produceDefaultColumnConsumer(){ List<String> cols = Arrays.asList(columns); for (Field field : FieldUtils.getAllFields(clz)) { if (columnConsumer.keySet().contains(field.getName()) || !cols.contains(field.getName())) { continue; } Consumer<T> setter = getDefaultSetter(field); Optional.ofNullable(setter).ifPresent(it -> columnConsumer.put(field.getName(), it)); } }