执行到到扩展的方法了
@Service
@Transactional
public class IndiaAvnServiceImpl implements AvnService {
@Override
public void update(Avn avn) {
avnDao.updateTemplateById(avn);
}
}
public interface SaicBaseMapper extends BaseMapper {
@Override
int updateTemplateById(T entity);
}
public class SaicUpdateTemplateByIdAmi extends AbstractSaicAmi implements MapperInvoke {
public Object call(SQLManager sm, Class cls, String sqlId, Method m, Object[] args) {
nameConversion = sm.getNc();
metadataManager = sm.getMetaDataManager();
String tableName = nameConversion.getTableName(cls);
TableDesc table = metadataManager.getTable(tableName);
ClassDesc classDesc = table.getClassDesc(cls, nameConversion);
StringBuilder sql = (new StringBuilder("update ")).append(tableName).append(" set ").append(this.lineSeparator);
String condition = this.appendIdCondition(cls);
condition = this.appendVersion(condition, classDesc);
Iterator cols = classDesc.getInCols().iterator();
Iterator properties = classDesc.getAttrs().iterator();
List idCols = classDesc.getIdCols();
while(cols.hasNext() && properties.hasNext()) {
String col = (String)cols.next();
String prop = (String)properties.next();
if (!classDesc.isUpdateIgnore(prop) && !idCols.contains(col)) {
if (prop.equals(classDesc.getVersionProperty())) {
sql.append(this.getKeyWordHandler().getCol(col)).append("=").append(this.getKeyWordHandler().getCol(col)).append("+1").append(",");
} else {
sql.append(this.appendSetColumn(cls, table, col, prop));
}
}
}
StringBuilder trimSql = new StringBuilder();
trimSql.append(STATEMENT_START).append("trim(){\n").append(STATEMENT_END).append("\n").append(sql);
trimSql.append(STATEMENT_START).append("}\n").append(STATEMENT_END);
sql = this.removeComma(trimSql, condition);
if (condition == null) {
throw new BeetlSQLException(4, "无法生成sql语句,缺少主键");
} else {
return sm.execute(sql.toString(),cls,args[0]);
}
}
protected String appendSetColumn(Class> c, TableDesc table, String colName, String fieldName) {
String sql = fieldName;
AbstractDBStyle db = new MySqlStyle();
ClassDesc classDesc = table.getClassDesc(c, this.nameConversion);
AttributeBuilderHolder handler = (AttributeBuilderHolder)classDesc.getColHandlers().get(fieldName);
if (handler != null && handler.supportPersistGen()) {
AttributePersistBuilder baseAttributeBuilder = (AttributePersistBuilder)handler.getInstance();
sql = baseAttributeBuilder.toSql(db, fieldName, colName, handler.getBeanAnnotaton(), table);
}
return this.STATEMENT_START + "if(!isEmpty(" + sql + ")){" + this.STATEMENT_END + "\t" + this.getKeyWordHandler().getCol(colName) + "=" + this.HOLDER_START + sql + this.HOLDER_END + "," + this.lineSeparator + this.STATEMENT_START + "}" + this.STATEMENT_END;
}
}
报错:update tb_
0|@trim(){
1|
2|update tb_avn set
3|@if(!isEmpty(vin)){vin=#vin#,
4|@}ROW_VERSION=ROW_VERSION+1,@if(!isEmpty(lastUpdateDate)){LAST_UPDATE_DATE=#lastUpdateDate#
5|@}@}
6| where id = #id# and row_version = #rowVersion#
99668 [http-nio-8080-exec-6] ERROR org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/].[dispatcherServlet] log 175 - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.beetl.sql.core.BeetlSQLException: SQL Script Error:>>09:05:27:词法错误(TOKEN_ERROR):#v 位于3行 资源:auto.gen@trim(){
update tb_] with root cause
org.beetl.sql.core.BeetlSQLException: SQL Script Error:>>09:05:27:词法错误(TOKEN_ERROR):#v 位于3行 资源:auto.gen@trim(){
update tb_
at org.beetl.sql.core.engine.BeetlSQLTemplateExceptionHandler.processExcption(BeetlSQLTemplateExceptionHandler.java:79)
at org.beetl.core.Template.renderTo(Template.java:170)
at org.beetl.core.Template.renderTo(Template.java:91)
at org.beetl.core.Template.render(Template.java:79)
at org.beetl.sql.core.SQLScript.run(SQLScript.java:90)
at org.beetl.sql.core.SQLScript.run(SQLScript.java:64)
at org.beetl.sql.core.SQLScript.select(SQLScript.java:326)
at org.beetl.sql.core.SQLScript.select(SQLScript.java:381)
at org.beetl.sql.core.SQLManager.execute(SQLManager.java:1607)
at org.beetl.sql.core.SQLManager.execute(SQLManager.java:1587)
at com.ibeetl.admin.core.sql.mapper.internal.SaicUpdateTemplateByIdAmi.call(SaicUpdateTemplateByIdAmi.java:50)
at org.beetl.sql.core.mapper.MapperJavaProxy.invoke(MapperJavaProxy.java:168)
at org.beetl.sql.core.mapper.MapperJava8Proxy.invoke(MapperJava8Proxy.java:92)
at com.sun.proxy.$Proxy99.updateTemplateById(Unknown Source)
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.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:343)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
at com.sun.proxy.$Proxy101.updateTemplateById(Unknown Source)
at com.ibeetl.admin.console.service.avn.IndiaAvnServiceImpl.update(IndiaAvnServiceImpl.java:56)
at com.ibeetl.admin.console.service.avn.IndiaAvnServiceImpl$$FastClassBySpringCGLIB$$eb40ba9f.invoke()
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:749)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:295)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688)
at com.ibeetl.admin.console.service.avn.IndiaAvnServiceImpl$$EnhancerBySpringCGLIB$$6cb2ac6f.update()
at com.ibeetl.admin.console.web.AvnController.update(AvnController.java:93)
错误意思是sql错误,但是不知道怎么在执行之前把sql转换成需要的sql