question about source code reading: why not use facoty pattern on MapperMethod?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

question about source code reading: why not use facoty pattern on MapperMethod?

yue yan
Hi~

I read mybatis-3.2.8.jar source code, I just don't understand, why we need factory to product MapperProxy, but we don't use factory to product MapperMethod.

notice: mybatis-bind.png descript the class diagram of binding package.

for convenience, here is the part of source code of MapperRegistry.java and MapperProxy.java.

// MapperRegistry.java
public <T> void addMapper(Class<T> type) {
if (type.isInterface()) {
if (hasMapper(type)) {
throw new BindingException("Type " + type + " is already known to the MapperRegistry.");
}
boolean loadCompleted = false;
try {
knownMappers.put(type, new MapperProxyFactory<T>(type));
// It's important that the type is added before the parser is run
// otherwise the binding may automatically be attempted by the
// mapper parser. If the type is already known, it won't try.
MapperAnnotationBuilder parser = new MapperAnnotationBuilder(config, type);
parser.parse();
loadCompleted = true;
} finally {
if (!loadCompleted) {
knownMappers.remove(type);
}
}
}
}

// MapperProxy.java 
private MapperMethod cachedMapperMethod(Method method) {
MapperMethod mapperMethod = methodCache.get(method);
if (mapperMethod == null) {
mapperMethod = new MapperMethod(mapperInterface, method, sqlSession.getConfiguration());
methodCache.put(method, mapperMethod);
}
return mapperMethod;
}


I catch exceotion in red line ,since right -left =-1 and string out of range, and my sql  string is 

INSERT INTO Queue (instanceId, queueId, queueName, createTime, status, policy, ttl, vhost, updateTime, isDelete)  VALUES(#{list[1,000].instanceId}, #{list[1,000].queueId}, #{list[1,000].queueName}, #{list[1,000]..createTime}, #{list[1,000]..status}, #{list[1,000]..policy}, #{list[1,000].ttl}, #{list[1,000].vhost}, #{list[1,000].updateTime}, #{list[1,000].isDelete});

I want to know what the "expression" is  in static method expression, as I see its should be couples of key-values like 

instanceId=#{list[1,000].instanceId},queueId=#{list[1,000].queueId}, …… ,isDelete=#{list[1,000].isDelete} ,  so when it parsed to the last key-value "isDelete=#{list[1,000].isDelete}"

the red line would throw a outOfRangeException, but..why mybatis throw " caused by "#{list[1,000].instanceId}" ? 

so I suspect the "expression" is  in static method expression is just "instanceId=#{list[1,000].instanceId}" , but why it should use a recursion in option method just in purple line?

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

mybatis-bind.png (48K) Download Attachment