private static final Logger log = LoggerFactory.getLogger(NoSqlPlugin.class);
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public Object bind(RootParamNode rootParamNode, String name, Class clazz, java.lang.reflect.Type type, Annotation[] annotations) {
NoSqlEntityManager em = NoSql.em();
MetaLayer metaLayer = em.getMeta();
if(!metaLayer.isManagedEntity(clazz))
return null;
ParamNode paramNode = rootParamNode.getChild(name, true);
String keyFieldName = metaLayer.getKeyFieldName(clazz);
ParamNode id = paramNode.getChild(keyFieldName);
String idStr = NoSqlModel.retrieveValue(id);
if(idStr == null)
return NoSqlModel.create(rootParamNode, name, clazz, annotations);
Object theId = metaLayer.convertIdFromString(clazz, idStr);
//Read the entity in so that this entity is used instead...
Object o = em.find(clazz, theId);
if(o == null)
throw new RowNotFoundException("Row with rowkey="+theId+" was not found, but your page posted this id to lookup the row of class type="+clazz.getSimpleName());
return NoSqlModel.edit(rootParamNode, name, o, annotations);
}