method.invoke运用

本文介绍了一个用于统计的数据对象模型——StatisticsDO,该模型利用反射机制实现了动态字段的更新与存储,能够灵活地处理不同类型的数据统计需求。

 

 

package com.sitechasia.ebiz.publics.model;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.lang.StringUtils;

public class StatisticsDO {
	private Integer id;
	private int vpCount1;
	private int vpCount2;
	
	private transient Map<String, Integer> vpCount = new HashMap<String, Integer>();
	
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public int getVpCount1() {
		return vpCount1;
	}
	public void setVpCount1(int vpCount1) {
		this.vpCount1 = vpCount1;
		vpCount.put("vpCount1", vpCount1);
	}
	public int getVpCount2() {
		return vpCount2;
	}
	public void setVpCount2(int vpCount2) {
		this.vpCount2 = vpCount2;
		vpCount.put("vpCount2", vpCount2);
	}
	public int getVpCount(String type) {
		return vpCount.get(type);
	}
	public void setVpCount(String field, int value) {
		try {
			if (StringUtils.isNotBlank(field) && field.startsWith("vpCount")) {
				String methodName = "set" + field.replaceFirst("v", "V");
				Class<Integer> argType = int.class;
				Method method = this.getClass().getMethod(methodName, argType);
				method.invoke(this, (Object) value);
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

 

java.lang.ClassCastException: class java.lang.String cannot be cast to class java.lang.Integer (java.lang.String and java.lang.Integer are in module java.base of loader 'bootstrap') at jdk.proxy2/jdk.proxy2.$Proxy122.getHardWareByVid(Unknown Source) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.base/java.lang.reflect.Method.invoke(Unknown Source) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:360) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:196) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:138) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184) at com.baomidou.dynamic.datasource.aop.DynamicDataSourceAnnotationInterceptor.invoke(DynamicDataSourceAnnotationInterceptor.java:56) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:223) at jdk.proxy2/jdk.proxy2.$Proxy123.getHardWareByVid(Unknown Source) at com.huawei.driveinsight.monitor.service.impl.DataPullServiceImpl.verifyUpdateStatus(DataPullServiceImpl.java:1200) at com.huawei.driveinsight.monitor.service.impl.DataPullServiceImpl.verifyAndUpdateTaskStatusByTransactionId(DataPullServiceImpl.java:1192) at com.huawei.driveinsight.monitor.service.impl.DataPullServiceImpl.dataPullCancel(DataPullServiceImpl.java:1166) at com.huawei.driveinsight.monitor.controller.DataPullController.dataPullCancel(DataPullController.java:275) DataPullServiceImpl.java:1200:Integer aicBChipCount = dwsMdcRecordDao.getHardWareByVid(po.getVid()); <select id="getHardWareByVid" resultType="java.lang.String"> SELECT aic_b_chip_count AS aicBChipCount FROM "cfg"."dwi_base_vehicle_info" WHERE vid = #{vid} ORDER BY create_time DESC LIMIT 1 </select>
11-08
hive> 1.select `exchange`,`symbol`,`ymd`,price_close,price_open,price_close-price_open as `diff` > 2.from > 3.( > 4. select * > 5. from stocks > 6. order by price_close-price_open desc > 7. limit 1 > 8.)t; NoViableAltException(367@[]) at org.apache.hadoop.hive.ql.parse.HiveParser.statement(HiveParser.java:1387) at org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:220) at org.apache.hadoop.hive.ql.parse.ParseUtils.parse(ParseUtils.java:74) at org.apache.hadoop.hive.ql.parse.ParseUtils.parse(ParseUtils.java:67) at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:616) at org.apache.hadoop.hive.ql.Driver.compileInternal(Driver.java:1826) at org.apache.hadoop.hive.ql.Driver.compileAndRespond(Driver.java:1773) at org.apache.hadoop.hive.ql.Driver.compileAndRespond(Driver.java:1768) at org.apache.hadoop.hive.ql.reexec.ReExecDriver.compileAndRespond(ReExecDriver.java:126) at org.apache.hadoop.hive.ql.reexec.ReExecDriver.run(ReExecDriver.java:214) at org.apache.hadoop.hive.cli.CliDriver.processLocalCmd(CliDriver.java:239) at org.apache.hadoop.hive.cli.CliDriver.processCmd(CliDriver.java:188) at org.apache.hadoop.hive.cli.CliDriver.processLine(CliDriver.java:402) at org.apache.hadoop.hive.cli.CliDriver.executeDriver(CliDriver.java:821) at org.apache.hadoop.hive.cli.CliDriver.run(CliDriver.java:759) at org.apache.hadoop.hive.cli.CliDriver.main(CliDriver.java:683) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.hadoop.util.RunJar.run(RunJar.java:328) at org.apache.hadoop.util.RunJar.main(RunJar.java:241) FAILED: ParseException line 1:0 cannot recognize input near '1.' 'select' 'exchange'
05-20
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值