Search in sources :

Example 11 with FlyingModel

use of indi.mybatis.flying.models.FlyingModel in project mybatis.flying by limeng32.

the class FlyingManager method fetchFlyingFeature.

public static FlyingModel fetchFlyingFeature(String originalSql, String id) {
    if (flyingModelCache.get(id) != null) {
        return flyingModelCache.get(id);
    }
    FlyingModel ret = new FlyingModel();
    String extension = null;
    if (null != originalSql && originalSql.startsWith(FlyingKeyword.FLYING) && originalSql.indexOf(':') > -1) {
        String s1 = null;
        if (originalSql.startsWith(FlyingKeyword.FLYING_LEFTBRACKET) || originalSql.startsWith(FlyingKeyword.FLYING_QUESTIONMARK_LEFTBRACKET)) {
            s1 = originalSql.substring(0, originalSql.indexOf(':', originalSql.indexOf(')')));
        } else {
            s1 = originalSql.substring(0, originalSql.indexOf(':'));
        }
        if (FlyingKeyword.FLYING.equals(s1) || FlyingKeyword.FLYING_QUESTIONMARK.equals(s1) || s1.startsWith(FlyingKeyword.FLYING_LEFTBRACKET) || originalSql.startsWith(FlyingKeyword.FLYING_QUESTIONMARK_LEFTBRACKET)) {
            String s2 = null;
            if (s1.startsWith(FlyingKeyword.FLYING_LEFTBRACKET) || originalSql.startsWith(FlyingKeyword.FLYING_QUESTIONMARK_LEFTBRACKET)) {
                s2 = originalSql.substring(originalSql.indexOf(':', originalSql.indexOf(')')) + 1, originalSql.length());
            } else {
                s2 = originalSql.substring(originalSql.indexOf(':') + 1, originalSql.length());
            }
            String actionTypeStr = null;
            if (s2.indexOf(':') > -1) {
                actionTypeStr = s2.substring(0, s2.indexOf(':'));
            } else {
                actionTypeStr = s2;
            }
            if (actionTypeStr.endsWith(")") && actionTypeStr.indexOf('(') != -1) {
                extension = actionTypeStr.substring(actionTypeStr.lastIndexOf('(') + 1, actionTypeStr.length() - 1);
                actionTypeStr = actionTypeStr.substring(0, actionTypeStr.lastIndexOf('('));
            }
            ActionType actionType = ActionType.forValue(actionTypeStr);
            if (actionType != null) {
                ret.setHasFlyingFeature(true);
                ret.setActionType(actionType);
                if (s2.indexOf(':') > -1) {
                    String s3 = s2.substring(s2.indexOf(':') + 1, s2.length());
                    String ignoreTag = null;
                    if (s3.indexOf(':') > -1) {
                        ignoreTag = s3.substring(0, s3.indexOf(':'));
                    } else {
                        ignoreTag = s3;
                    }
                    ret.setIgnoreTag(ignoreTag);
                }
                dealKeyHandler(actionType, extension, originalSql, ret);
                flyingModelCache.put(id, ret);
                return ret;
            }
        }
    }
    ret.setHasFlyingFeature(false);
    flyingModelCache.put(id, ret);
    return ret;
}
Also used : FlyingModel(indi.mybatis.flying.models.FlyingModel) ActionType(indi.mybatis.flying.statics.ActionType)

Example 12 with FlyingModel

use of indi.mybatis.flying.models.FlyingModel in project mybatis.flying by limeng32.

the class FlyingManager method dealInnerPropertiesIteration.

private static JSONObject dealInnerPropertiesIteration(String id, JSONObject flyingJson, Configuration configuration, FlyingModel flyingModel) {
    if (flyingModel2ndCache.get(id) != null) {
        return flyingModel2ndCache.get(id);
    }
    JSONObject threshold = flyingJson.getJSONObject("properties");
    if (threshold == null || threshold.isEmpty()) {
        return flyingJson;
    }
    for (Map.Entry<String, Object> e : threshold.getInnerMap().entrySet()) {
        JSONObject json = (JSONObject) e.getValue();
        if (json.containsKey(FlyingKeyword.ID)) {
            String innerId = json.getString(FlyingKeyword.ID);
            if (innerId.indexOf('.') == -1 && id.indexOf('.') > -1) {
                innerId = new StringBuilder(id.substring(0, id.lastIndexOf('.') + 1)).append(innerId).toString();
            }
            String originalSql = configuration.getMappedStatement(innerId).getBoundSql(null).getSql();
            JSONObject innerJson = JSONObject.parseObject(originalSql);
            FlyingModel innerFlyingModel = new FlyingModel();
            buildFlyingModel(innerFlyingModel, json, originalSql, innerId, false, innerJson, flyingModel.getPrefix());
            dealInnerPropertiesIteration(innerId, innerJson, configuration, innerFlyingModel);
            flyingModel.getProperties().put(e.getKey(), innerFlyingModel);
        } else {
            FlyingModel innerFlyingModel = new FlyingModel();
            buildFlyingModel(innerFlyingModel, json, "", null, false, null, flyingModel.getPrefix());
            flyingModel.getProperties().put(e.getKey(), innerFlyingModel);
        }
    }
    return flyingJson;
}
Also used : FlyingModel(indi.mybatis.flying.models.FlyingModel) JSONObject(com.alibaba.fastjson.JSONObject) JSONObject(com.alibaba.fastjson.JSONObject) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

FlyingModel (indi.mybatis.flying.models.FlyingModel)12 Test (org.junit.Test)5 JSONObject (com.alibaba.fastjson.JSONObject)2 ActionType (indi.mybatis.flying.statics.ActionType)2 HashMap (java.util.HashMap)2 BoundSql (org.apache.ibatis.mapping.BoundSql)2 MappedStatement (org.apache.ibatis.mapping.MappedStatement)2 MetaObject (org.apache.ibatis.reflection.MetaObject)2 DatabaseSetup (com.github.springtestdbunit.annotation.DatabaseSetup)1 DatabaseTearDown (com.github.springtestdbunit.annotation.DatabaseTearDown)1 ExpectedDatabase (com.github.springtestdbunit.annotation.ExpectedDatabase)1 MilliSecondKeyHandler (indi.mybatis.flying.handlers.MilliSecondKeyHandler)1 SnowFlakeKeyHandler (indi.mybatis.flying.handlers.SnowFlakeKeyHandler)1 UuidKeyHandler (indi.mybatis.flying.handlers.UuidKeyHandler)1 UuidWithoutLineKeyHandler (indi.mybatis.flying.handlers.UuidWithoutLineKeyHandler)1 AggregateModel (indi.mybatis.flying.models.AggregateModel)1 Conditionable (indi.mybatis.flying.models.Conditionable)1 Account_ (indi.mybatis.flying.pojo.Account_)1 Permission (indi.mybatis.flying.pojo.Permission)1 KeyGeneratorType (indi.mybatis.flying.statics.KeyGeneratorType)1