List of usage examples for org.apache.ibatis.reflection MetaObject getOriginalObject
public Object getOriginalObject()
From source file:com.baomidou.mybatisplus.MybatisDefaultParameterHandler.java
License:Apache License
/** * <p>/*from www . j a v a 2 s.c o m*/ * * </p> * * @param metaObjectHandler ?? * @param tableInfo ???? * @param ms MappedStatement * @param parameterObject ?? * @return Object */ protected static Object populateKeys(MetaObjectHandler metaObjectHandler, TableInfo tableInfo, MappedStatement ms, Object parameterObject) { if (null == tableInfo || StringUtils.isEmpty(tableInfo.getKeyProperty()) || null == tableInfo.getIdType()) { /* ?? */ return parameterObject; } /* */ MetaObject metaObject = ms.getConfiguration().newMetaObject(parameterObject); if (ms.getSqlCommandType() == SqlCommandType.INSERT) { if (tableInfo.getIdType().getKey() >= 2) { Object idValue = metaObject.getValue(tableInfo.getKeyProperty()); /* ID */ if (StringUtils.checkValNull(idValue)) { if (tableInfo.getIdType() == IdType.ID_WORKER) { metaObject.setValue(tableInfo.getKeyProperty(), IdWorker.getId()); } else if (tableInfo.getIdType() == IdType.UUID) { metaObject.setValue(tableInfo.getKeyProperty(), IdWorker.get32UUID()); } } } // ? if (metaObjectHandler.openInsertFill()) { metaObjectHandler.insertFill(metaObject); } } else if (ms.getSqlCommandType() == SqlCommandType.UPDATE && metaObjectHandler.openUpdateFill()) { // metaObjectHandler.updateFill(metaObject); } return metaObject.getOriginalObject(); }
From source file:com.mybatisX.core.MybatisDefaultParameterHandler.java
License:Apache License
/** * <p>/*from w w w . j a v a2s . c om*/ * ID * </p> * * @param tableInfo * @param ms * @param parameterObject * ?? * @return */ protected static Object populateKeys(TableInfo tableInfo, MappedStatement ms, Object parameterObject) { if (null != tableInfo && null != tableInfo.getIdType() && tableInfo.getIdType().getKey() >= 2) { MetaObject metaObject = ms.getConfiguration().newMetaObject(parameterObject); Object idValue = metaObject.getValue(tableInfo.getKeyProperty()); /* ID */ if (StringUtils.checkValNull(idValue)) { if (tableInfo.getIdType() == IdType.ID_WORKER) { metaObject.setValue(tableInfo.getKeyProperty(), IdWorker.getId()); } else if (tableInfo.getIdType() == IdType.UUID) { metaObject.setValue(tableInfo.getKeyProperty(), get32UUID()); } } /* */ IMetaObjectHandler metaObjectHandler = MybatisConfiguration.META_OBJECT_HANDLER; if (null != metaObjectHandler) { metaObjectHandler.insertFill(metaObject); } return metaObject.getOriginalObject(); } /* * ?? */ return parameterObject; }
From source file:com.sinotopia.mybatis.mapper.mapperhelper.SelectKeyGenerator.java
License:Apache License
private void setValue(MetaObject metaParam, String property, Object value) { if (metaParam.hasSetter(property)) { if (metaParam.hasGetter(property)) { Object defaultValue = metaParam.getValue(property); if (defaultValue != null) { return; }//from w w w .jav a 2s . co m } metaParam.setValue(property, value); } else { throw new ExecutorException("No setter found for the keyProperty '" + property + "' in " + metaParam.getOriginalObject().getClass().getName() + "."); } }
From source file:com.tj.mybatisplus.MybatisDefaultParameterHandler.java
License:Apache License
/** * <p>//w w w . j a v a 2 s . co m * ID * </p> * * @param ms * @param parameterObject * ?? * @return */ protected static Object populateKeys(MappedStatement ms, Object parameterObject) { if (ms.getSqlCommandType() == SqlCommandType.INSERT) { TableInfo tableInfo = TableInfoHelper.getTableInfo(parameterObject.getClass()); if (tableInfo != null && tableInfo.getIdType().getKey() >= 2) { MetaObject metaParam = ms.getConfiguration().newMetaObject(parameterObject); Object idValue = metaParam.getValue(tableInfo.getKeyProperty()); /* ID */ if (idValue == null) { if (tableInfo.getIdType() == IdType.ID_WORKER) { metaParam.setValue(tableInfo.getKeyProperty(), IdWorker.getId()); } else if (tableInfo.getIdType() == IdType.UUID) { metaParam.setValue(tableInfo.getKeyProperty(), get32UUID()); } } return metaParam.getOriginalObject(); } } return parameterObject; }