protected void populateKeys(TableInfo tableInfo, MetaObject metaObject, Object entity) {
IdType idType = tableInfo.getIdType();
String keyProperty = tableInfo.getKeyProperty();
if (StringUtils.isNotBlank(keyProperty) && null != idType && idType.getKey() >= 3) {
IdentifierGenerator identifierGenerator = GlobalConfigUtils.getGlobalConfig(this.configuration).getIdentifierGenerator();
Object idValue = metaObject.getValue(keyProperty);
if (identifierGenerator.assignId(idValue)) {
if (idType.getKey() == IdType.ASSIGN_ID.getKey()) {
Class<?> keyType = tableInfo.getKeyType();
if (Number.class.isAssignableFrom(keyType)) {
Number id = identifierGenerator.nextId(entity);
if (keyType == id.getClass()) {
metaObject.setValue(keyProperty, id);
} else if (Integer.class == keyType) {
metaObject.setValue(keyProperty, id.intValue());
} else if (Long.class == keyType) {
metaObject.setValue(keyProperty, id.longValue());
} else if (BigDecimal.class.isAssignableFrom(keyType)) {
metaObject.setValue(keyProperty, new BigDecimal(id.longValue()));
} else {
if (!BigInteger.class.isAssignableFrom(keyType)) {
throw new MybatisPlusException(“Key type '” + keyType + “’ not supported”);
}
metaObject.setValue(keyProperty, new BigInteger(id.toString()));
}
} else if (String.class.isAssignableFrom(keyType)) {
metaObject.setValue(keyProperty, identifierGenerator.nextId(entity).toString());
} else {
metaObject.setValue(keyProperty, identifierGenerator.nextId(entity));
}
} else if (idType.getKey() == IdType.ASSIGN_UUID.getKey()) {
metaObject.setValue(keyProperty, identifierGenerator.nextUUID(entity));
}
}
}
}