/** * Assign the generated id value to {@link LitePalSupport#baseObjId}. This * value will be used as identify of this model for system use. * * @param baseObj * The class of base object. * @param id * The value of id. */ protected void giveBaseObjIdValue(LitePalSupport baseObj, long id) throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException { if (id > 0) { DynamicExecutor.set(baseObj, "baseObjId", id, LitePalSupport.class); } }
/** * This method use java reflect API to set field value dynamically. Most * importantly, it could access fields with private modifier to break * encapsulation. * * @param object * The object to access. * @param fieldName * The field name to access. * @param value * Assign this value to field. * @param objectClass * The class of object. * @throws SecurityException * @throws IllegalArgumentException * @throws IllegalAccessException */ static void setField(Object object, String fieldName, Object value, Class<?> objectClass) throws SecurityException, IllegalArgumentException, IllegalAccessException { if (objectClass == LitePalSupport.class || objectClass == Object.class) { throw new LitePalSupportException(LitePalSupportException.noSuchFieldExceptioin( objectClass.getSimpleName(), fieldName)); } try { set(object, fieldName, value, objectClass); } catch (NoSuchFieldException e) { setField(object, fieldName, value, objectClass.getSuperclass()); } }