Search in sources :

Example 1 with RedisIdGenerator

use of org.sagacity.sqltoy.plugins.id.impl.RedisIdGenerator in project sagacity-sqltoy by chenrenfei.

the class EntityManager method processIdGenerator.

/**
 * @todo 处理id生成器
 * @param sqlToyContext
 * @param entityMeta
 * @param idGenerator
 * @throws Exception
 */
private void processIdGenerator(SqlToyContext sqlToyContext, EntityMeta entityMeta, String idGenerator) throws Exception {
    // 已经存在跳过处理
    if (idGenerators.containsKey(idGenerator)) {
        return;
    }
    // 自定义springbean 模式,用法在quickvo中配置@bean(beanName)
    if (idGenerator.toLowerCase().startsWith("@bean(")) {
        String beanName = idGenerator.substring(idGenerator.indexOf("(") + 1, idGenerator.indexOf(")")).replaceAll("\"|\'", "").trim();
        idGenerators.put(idGenerator, (IdGenerator) sqlToyContext.getBean(beanName));
    } else {
        String generator = IdGenerators.get(idGenerator.toLowerCase());
        generator = (generator != null) ? IdGeneratorPackage.concat(generator) : idGenerator;
        // redis 情况特殊,依赖redisTemplate,小心修改
        if (generator.endsWith("RedisIdGenerator")) {
            RedisIdGenerator redis = (RedisIdGenerator) RedisIdGenerator.getInstance(sqlToyContext);
            if (redis == null || !redis.hasRedisTemplate()) {
                logger.error("POJO Class={} 的redisIdGenerator 未能被正确实例化,可能的原因是未定义RedisTemplate!", entityMeta.getEntityClass().getName());
            }
            idGenerators.put(idGenerator, redis);
        } else {
            // 自定义(不依赖spring模式),用法在quickvo中配置例如:com.xxxx..CustomIdGenerator
            idGenerators.put(idGenerator, (IdGenerator) Class.forName(generator).getDeclaredConstructor().newInstance());
        }
    }
}
Also used : RedisIdGenerator(org.sagacity.sqltoy.plugins.id.impl.RedisIdGenerator)

Aggregations

RedisIdGenerator (org.sagacity.sqltoy.plugins.id.impl.RedisIdGenerator)1