理想的には、現実は非常に細いです、いっぱいです。
ビジネスはJava開発Influxdbクエリ機能を使用する場合、「柔軟な設定可能な」機能要件は、問題が発生した必要として、測定注釈名を動的に変更する必要があります。
私たちは、@Measurement注釈付きのコードを見て:
package org.influxdb.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.concurrent.TimeUnit;
/**
* @author fmachado
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Measurement {
String name();
String database() default "[unassigned]";
String retentionPolicy() default "autogen";
TimeUnit timeUnit() default TimeUnit.MILLISECONDS;
問題は、に変換することができます:
- > @Measurement注釈を有効にする前に、名前の値の変化が書き込まれます。
解決するためにJavaのリフレクション:によって発見さ見つけるための情報の約2日後、
APIの2つのクラスを操作するための主要な必要性を
java.lang.reflect.InvocationHandler;
java.lang.reflect.Proxy;
toPOJO方法によって最終溶液はInfluxDBResultMapperが解決継承しました。
以下のコードを投稿:
public class InfluxDBResultMapperHelper extends InfluxDBResultMapper {
public <T> List<T> toPOJO(final QueryResult queryResult, final Class<T> clazz,String name)
throws InfluxDBMapperException {
InvocationHandler handler = Proxy.getInvocationHandler(clazz.getAnnotation(Measurement.class));
Field hField = null;
try {
hField = handler.getClass().getDeclaredField(ME_VALUE);
hField.setAccessible(true);
Map memberValues = (Map) hField.get(handler);
memberValues.put(ME_NAME, name);
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return toPOJO(queryResult, clazz, TimeUnit.MILLISECONDS);
}
}